Skip to content

Commit

Permalink
improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Apr 16, 2024
1 parent 45d4a60 commit c6d3334
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -801,3 +801,41 @@ cairo-native-test ./cairo-tests/
```
This will run all the tests (functions marked with the `#[test]` attribute).
## Debugging Tips
### Useful environment variables
These 2 env vars will dump the generated MLIR code from any compilation on the current working directory as:
- `dump.mlir`: The MLIR code after passes without locations.
- `dump-debug.mlir`: The MLIR code after passes with locations.
- `dump-prepass.mlir`: The MLIR code before without locations.
- `dump-prepass-debug.mlir`: The MLIR code before passes with locations.
Do note that the MLIR with locations is in pretty form and thus not suitable to pass to `mlir-opt`.
```bash
export NATIVE_DEBUG_DUMP_PREPASS=1
export NATIVE_DEBUG_DUMP=1
```
Enable logging to see the compilation process:
```bash
export RUST_LOG="cairo_native=trace"
```
Other tips:
- Try to find the minimal program to reproduce an issue, the more isolated the easier to test.
- Use the `debug_utils` print utilities, more info [here](https://lambdaclass.github.io/cairo_native/cairo_native/metadata/debug_utils/struct.DebugUtils.html):
```rust
#[cfg(feature = "with-debug-utils")]
{
metadata.get_mut::<DebugUtils>()
.unwrap()
.print_pointer(context, helper, entry, ptr, location)?;
}
```
35 changes: 27 additions & 8 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,36 @@ impl NativeContext {
debug_locations.as_ref(),
)?;

std::fs::write(
"out.mlir",
module
.as_operation()
.to_string_with_flags(OperationPrintingFlags::new().enable_debug_info(true, false))
.unwrap(),
)
.unwrap();
if let Ok(x) = std::env::var("NATIVE_DEBUG_DUMP_PREPASS") {
if x == "1" || x == "true" {
std::fs::write("dump-prepass.mlir", module.as_operation().to_string())
.expect("should work");
std::fs::write(
"dump-prepass-debug.mlir",
module.as_operation().to_string_with_flags(
OperationPrintingFlags::new().enable_debug_info(true, true),
)?,
)
.expect("should work");
}
}

run_pass_manager(&self.context, &mut module)?;

if let Ok(x) = std::env::var("NATIVE_DEBUG_DUMP") {
if x == "1" || x == "true" {
std::fs::write("dump.mlir", module.as_operation().to_string())
.expect("should work");
std::fs::write(
"dump-debug.mlir",
module.as_operation().to_string_with_flags(
OperationPrintingFlags::new().enable_debug_info(true, true),
)?,
)
.expect("should work");
}
}

// The func to llvm pass has a bug where it sets the data layout string to ""
// This works around it by setting it again.
{
Expand Down

0 comments on commit c6d3334

Please sign in to comment.