Skip to content

Remove ignores #1258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/compilation_walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ LLVM_InitializeAllAsmParsers();
After that we create a LLVM context, and pass it along the module to the
`mlirTranslateModuleToLLVMIR` method:

```rust ,ignore
```rust,ignore
let llvm_module = mlirTranslateModuleToLLVMIR(mlir_module_op, llvm_context);
```

Expand Down
93 changes: 50 additions & 43 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,41 +151,48 @@ lowering to LLVM.
compiled sierra programs from an entrypoint. Programs and JIT states can be
cached in contexts where their execution will be done multiple times.

```rust,ignore
```rust
use cairo_native::{
context::NativeContext, executor::JitNativeExecutor, utils::cairo_to_sierra, Value,
};
use starknet_types_core::felt::Felt;
use cairo_native::context::NativeContext;
use cairo_native::executor::JitNativeExecutor;
use cairo_native::values::JitValue;
use std::path::Path;

let program_path = Path::new("programs/examples/hello.cairo");
// Compile the cairo program to sierra.
let sierra_program = cairo_native::utils::cairo_to_sierra(program_path);
fn main() {
let program_path = Path::new("programs/examples/hello.cairo");

// Instantiate a Cairo Native MLIR context. This data structure is responsible for the MLIR
// initialization and compilation of sierra programs into a MLIR module.
let native_context = NativeContext::new();

// Instantiate a Cairo Native MLIR context. This data structure is responsible for the MLIR
// initialization and compilation of sierra programs into a MLIR module.
let native_context = NativeContext::new();
// Compile the cairo program to sierra.
let sierra_program = cairo_to_sierra(program_path).unwrap();

// Compile the sierra program into a MLIR module.
let native_program = native_context.compile(&sierra_program, None).unwrap();
// Compile the sierra program into a MLIR module.
let native_program = native_context
.compile(&sierra_program, false, Some(Default::default()), None)
.unwrap();

// The parameters of the entry point.
let params = &[JitValue::Felt252(Felt::from_bytes_be_slice(b"user"))];
// The parameters of the entry point.
let params = &[Value::Felt252(Felt::from_bytes_be_slice(b"user"))];

// Find the entry point id by its name.
let entry_point = "hello::hello::greet";
let entry_point_id = cairo_native::utils::find_function_id(&sierra_program, entry_point);
// Find the entry point id by its name.
let entry_point = "hello::hello::greet";
let entry_point_id = cairo_native::utils::find_function_id(&sierra_program, entry_point)
.expect("entry point not found");

// Instantiate the executor.
let native_executor = JitNativeExecutor::from_native_module(native_program, Default::default());
// Instantiate the executor.
let native_executor =
JitNativeExecutor::from_native_module(native_program, Default::default()).unwrap();

// Execute the program.
let result = native_executor
.invoke_dynamic(entry_point_id, params, None)
.unwrap();
// Execute the program.
let result = native_executor
.invoke_dynamic(entry_point_id, params, None)
.unwrap();

println!("Cairo program was compiled and executed successfully.");
println!("{:?}", result);
println!("Cairo program was compiled and executed successfully.");
println!("{:?}", result);
}
```

## Running a Cairo program
Expand All @@ -196,42 +203,42 @@ execute a program using the JIT.

Example code to run a program:

```rust,ignore
use starknet_types_core::felt::Felt;
use cairo_native::context::NativeContext;
use cairo_native::executor::NativeExecutor;
use cairo_native::values::JitValue;
```rust
use cairo_native::{
context::NativeContext, executor::JitNativeExecutor, utils::find_entry_point, Value,
};
use std::path::Path;
use tracing_subscriber::{EnvFilter, FmtSubscriber};

fn main() {
let program_path = Path::new("programs/examples/hello.cairo");
let program_path = Path::new("programs/echo.cairo");

// Compile the cairo program to sierra.
let sierra_program = cairo_native::utils::cairo_to_sierra(program_path);
let sierra_program = cairo_native::utils::cairo_to_sierra(program_path).unwrap();

// Instantiate a Cairo Native MLIR context. This data structure is responsible for the MLIR
// initialization and compilation of sierra programs into a MLIR module.
let native_context = NativeContext::new();

// Compile the sierra program into a MLIR module.
let native_program = native_context.compile(&sierra_program).unwrap();

// The parameters of the entry point.
let params = &[JitValue::Felt252(Felt::from_bytes_be_slice(b"user"))];
let native_program = native_context
.compile(&sierra_program, false, Some(Default::default()), None)
.unwrap();

// Find the entry point id by its name.
let entry_point = "hello::hello::greet";
let entry_point_id = cairo_native::utils::find_function_id(&sierra_program, entry_point);
let entry_point_fn = find_entry_point(&sierra_program, "echo::echo::main").unwrap();
let fn_id = &entry_point_fn.id;

// Instantiate the executor.
let native_executor = NativeExecutor::new(native_program);
let native_executor =
JitNativeExecutor::from_native_module(native_program, Default::default()).unwrap();

// Execute the program.
let result = native_executor
.execute(entry_point_id, params, None)
.unwrap();
let output = native_executor.invoke_dynamic(fn_id, &[Value::Felt252(1.into())], None);

println!();
println!("Cairo program was compiled and executed successfully.");
println!("{:?}", result);
println!("{output:#?}");
}
```

Expand Down
Loading