Skip to content

Commit

Permalink
log_runtime_error working
Browse files Browse the repository at this point in the history
Signed-off-by: salaheldinsoliman <salaheldin_sameh@aucegypt.edu>
  • Loading branch information
salaheldinsoliman committed Jul 13, 2024
1 parent c24c78d commit e398828
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/emit/soroban/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use inkwell::values::{
AnyValue, ArrayValue, AsValueRef, BasicMetadataValueEnum, BasicValue, BasicValueEnum, FunctionValue, IntValue, PointerValue
};

use inkwell::AddressSpace;
use solang_parser::pt::Loc;

use std::collections::HashMap;
Expand Down Expand Up @@ -239,44 +240,62 @@ impl<'a> TargetRuntime<'a> for SorobanTarget {



/* let mut toprint;
let mut toprint;
unsafe {
toprint = string.as_value_ref().offset(0);
println!( "TO PRINT! {:?}", toprint);
}
//println!("print called with string: {:?} ", string.as_value_ref());
println!("msg_pos: {:?}", string);
println!("length: {:?}", length);
println!("=============================================================");*/

let msg_pos = bin.builder.build_ptr_to_int(string, bin.context.i64_type(), "msg_pos").unwrap();

let msg_pos = msg_pos.const_cast(bin.context.i64_type(), false);



let length = bin.context.i64_type().const_int(1024, false);
println!("msg_pos extracted: {:?}", msg_pos);
println!("=============================================================");


let msg_pos = bin.context.i64_type().const_int(0, false);



//let length = bin.context.i64_type().const_int(1024, false);

let length = length.const_cast(bin.context.i64_type(), false);


let eight = bin.context.i64_type().const_int(8, false);
let four = bin.context.i64_type().const_int(4, false);
let zero = bin.context.i64_type().const_int(0, false);
let thirty_two = bin.context.i64_type().const_int(32, false);

// encode msg_pos and length
let msg_pos_encoded = bin.builder.build_left_shift(msg_pos, eight, "temp").unwrap();
let msg_pos_encoded = bin.builder.build_left_shift(msg_pos, thirty_two, "temp").unwrap();
let msg_pos_encoded = bin.builder.build_int_add(msg_pos_encoded, four, "msg_pos_encoded").unwrap();



let length_encoded = bin.builder.build_left_shift(length, eight, "temp").unwrap();
let length_encoded = bin.builder.build_left_shift(length, thirty_two, "temp").unwrap();
let length_encoded = bin.builder.build_int_add(length_encoded, four, "length_encoded").unwrap();


let zero_encoded = bin.builder.build_left_shift(zero, eight, "temp").unwrap();


let eight_encoded = bin.builder.build_left_shift(eight, eight, "temp").unwrap();
let eight_encoded = bin.builder.build_int_add(eight_encoded, four, "eight_encoded").unwrap();




let call_res = bin.builder.build_call(
bin.module.get_function(LOG_FROM_LINEAR_MEMORY).unwrap(),
&[
msg_pos_encoded.into(),
length_encoded.into(),
four.into(),
msg_pos_encoded.into(),
four.into(),
],
"log",
Expand Down

0 comments on commit e398828

Please sign in to comment.