diff --git a/examples/aot.rs b/examples/aot.rs index 168b2e789..07137acb5 100644 --- a/examples/aot.rs +++ b/examples/aot.rs @@ -14,7 +14,7 @@ struct SyscallHandler; pub fn main() -> Result<(), Box> { let path = Path::new("programs/examples/hello_starknet.cairo"); - let libpath = Path::new("aot.so"); + let libpath = Path::new("./aot.so"); let contract = compile_path( path, diff --git a/src/aot.rs b/src/aot.rs index 03d534b5d..d0fe92c53 100644 --- a/src/aot.rs +++ b/src/aot.rs @@ -70,15 +70,15 @@ pub fn call_contract_library( syscall_handler: &mut T, reg: &ProgramRegistry, ) -> Result<(), Box> { - dbg!(&entry_point.signature); + // dbg!(&entry_point.signature); let symbol: &str = entry_point.id.debug_name.as_deref().unwrap(); // todo: verify signature matches that of a contract, so unsafe is "safe" - let felt = Felt252Abi([1; 32]); - let payload = (addr_of!(felt), 1, 1); + //let felt = Felt252Abi([1; 32]); + //let payload = (addr_of!(felt), 1, 1); - let calldata = Calldata { calldata: payload }; + //let calldata = Calldata { calldata: payload }; unsafe { let lib = libloading::Library::new(path)?; @@ -90,15 +90,21 @@ pub fn call_contract_library( let arena = Bump::new(); let ty = &entry_point.params[3].ty; - dbg!(ty); + // dbg!(ty); let calldata = JITValue::Struct { - fields: vec![JITValue::Array(vec![JITValue::Felt252(1.into())])], + fields: vec![JITValue::Array(vec![ + JITValue::Felt252(1.into()), + JITValue::Felt252(1.into()), + JITValue::Felt252(1.into()), + ])], debug_name: None, } .to_jit(&arena, reg, ty) .unwrap(); + dbg!(&calldata); + let syscall_handler_meta = SyscallHandlerMeta::new(syscall_handler); let syscall_addr = syscall_handler_meta.as_ptr().as_ptr() as *const () as usize; @@ -119,7 +125,12 @@ pub fn call_contract_library( let gas: u128 = u64::MAX.into(); let range_check = arena.alloc_layout(Layout::new::<()>()).as_ptr().cast(); - let result = func(range_check, gas_ptr, syscall_alloc.cast(), calldata.as_ptr().cast()); + let result = func( + range_check, + gas_ptr, + syscall_alloc.cast(), + calldata.as_ptr().cast(), + ); // fix tag, because in llvm we use tag as a i1, the padding bytes may have garbage diff --git a/src/ffi.rs b/src/ffi.rs index a916f1249..e29f05b04 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -104,7 +104,7 @@ pub fn module_to_object(module: &Module<'_>) -> Result, LLVMCompileError target_triple.cast(), target_cpu.cast(), target_cpu_features.cast(), - LLVMCodeGenOptLevel::LLVMCodeGenLevelAggressive, + LLVMCodeGenOptLevel::LLVMCodeGenLevelNone, LLVMRelocMode::LLVMRelocDynamicNoPic, LLVMCodeModel::LLVMCodeModelDefault, ); @@ -161,7 +161,7 @@ pub fn object_to_shared_lib(object: &[u8], output_filename: &Path) -> Result<(), "-dylib", "-L/usr/local/lib", "-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib", - "-L/Users/edgar/Documents/cairo_sierra_to_mlir/target/debug/", + "-L/Users/edgar/Documents/cairo_sierra_to_mlir/target/debug/", // change me &file.display().to_string(), "-o", &output_filename.display().to_string(), @@ -175,11 +175,15 @@ pub fn object_to_shared_lib(object: &[u8], output_filename: &Path) -> Result<(), "--hash-style=gnu", "--eh-frame-hdr", "-shared", - "-o", - &output_filename.display().to_string(), + "-L/data2/edgar/work/native/target/debug", // change me + "-rpath=/data2/edgar/work/native/target/debug", // change me + "-rpath-link=/data2/edgar/work/native/target/debug", // change me "-L/lib/../lib64", "-L/usr/lib/../lib64", + "-o", + &output_filename.display().to_string(), "-lc", + "-lcairo_native_runtime", &file.display().to_string(), ] } diff --git a/src/libfuncs/array.rs b/src/libfuncs/array.rs index 46ca5c581..a94631b67 100644 --- a/src/libfuncs/array.rs +++ b/src/libfuncs/array.rs @@ -686,6 +686,11 @@ where let new_elem_ptr = op.result(0)?.into(); + metadata + .get_mut::() + .unwrap() + .debug_breakpoint_trap(block_not_empty, location)?; + let op = block_not_empty.append_operation(llvm::load( context, elem_ptr, @@ -698,6 +703,11 @@ where )); let elem_value = op.result(0)?.into(); + metadata + .get_mut::() + .unwrap() + .debug_breakpoint_trap(block_not_empty, location)?; + block_not_empty.append_operation(llvm::store( context, elem_value, @@ -709,6 +719,11 @@ where ))), )); + metadata + .get_mut::() + .unwrap() + .debug_breakpoint_trap(block_not_empty, location)?; + let op = block_not_empty.append_operation(arith::constant( context, IntegerAttribute::new(1, len.r#type()).into(), diff --git a/src/metadata/debug_utils.rs b/src/metadata/debug_utils.rs index 65773bafc..c14f9f04a 100644 --- a/src/metadata/debug_utils.rs +++ b/src/metadata/debug_utils.rs @@ -93,6 +93,7 @@ use melior::{ dialect::{func, llvm}, ir::{ attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute}, + operation::OperationBuilder, r#type::{FunctionType, IntegerType}, Block, Identifier, Location, Module, Region, Value, }, @@ -148,6 +149,18 @@ impl DebugUtils { Ok(()) } + pub fn debug_breakpoint_trap<'c, 'a>( + &mut self, + block: &'a Block<'c>, + location: Location<'c>, + ) -> Result<()> + where + 'c: 'a, + { + block.append_operation(OperationBuilder::new("llvm.intr.debugtrap", location).build()?); + Ok(()) + } + pub fn print_pointer<'c, 'a>( &mut self, context: &'c Context, diff --git a/src/values.rs b/src/values.rs index ee7535e7f..f862b9ee5 100644 --- a/src/values.rs +++ b/src/values.rs @@ -204,6 +204,7 @@ impl JITValue { .unwrap() .cast() .as_mut() = cap; + dbg!(&target); target.cast() } else { Err(ErrorImpl::UnexpectedValue(format!(