Skip to content

Commit

Permalink
add some debug prints
Browse files Browse the repository at this point in the history
Signed-off-by: salaheldinsoliman <[email protected]>
  • Loading branch information
salaheldinsoliman committed Jul 29, 2024
1 parent 2bbba8e commit c656939
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/codegen/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ pub fn expression(
..
} => {
if opt.log_prints {
println!("args in codegen {:?}", args);
let expr = expression(&args[0], cfg, contract_no, func, ns, vartab, opt);

let to_print = if ns.target.is_polkadot() {
Expand Down
41 changes: 41 additions & 0 deletions src/emit/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,8 @@ pub(super) fn expression<'a, T: TargetRuntime<'a> + ?Sized>(
initializer,
..
} => {

println!("testing filename: {:?}", bin.name);
println!("alloc dynamic bytes");
println!("TYYY {:?}", ty);
println!("SIZE {:?}", size);
Expand Down Expand Up @@ -1569,6 +1571,11 @@ pub(super) fn expression<'a, T: TargetRuntime<'a> + ?Sized>(

println!("size is number literal");
println!("ty {:?}", ty);
println!("value {:?}", value);

if let Some(init) = initializer {



let init = initializer.as_ref().unwrap();

Expand Down Expand Up @@ -1601,6 +1608,40 @@ pub(super) fn expression<'a, T: TargetRuntime<'a> + ?Sized>(
.into(),
])
.into()
} else {

let typee = BasicTypeEnum::StructType(
bin.context.struct_type(
&[
bin.llvm_type(ty, ns)
.ptr_type(AddressSpace::default())
.into(),
bin.context
.custom_width_int_type(ns.target.ptr_size().into())
.into(),
],
false,
),
).into_struct_type();

println!("typee {:?}", typee);


let null = bin.context.custom_width_int_type(ns.target.ptr_size().into()).ptr_type(AddressSpace::default()).const_null();


let nones = typee.const_named_struct(&[
null.into(),
bin.context
.custom_width_int_type(ns.target.ptr_size().into())
.const_int(0_u64, false)
.into(),
])
;

null.into()
}


}
else {
Expand Down
3 changes: 3 additions & 0 deletions src/emit/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
target.assert_failure(bin, vector_bytes, len);
}
Instr::Print { expr } => {

println!("KIND OF EXPR BEFORE{:?}", expr);
let expr = expression(target, bin, expr, &w.vars, function, ns);
println!("KIND OF EXPR AFTER{:?}", expr);

target.print(bin, bin.vector_bytes(expr), bin.vector_len(expr));
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Target {

/// Size of a pointer in bits
pub fn ptr_size(&self) -> u16 {
if *self == Target::Solana {
if *self == Target::Solana || *self == Target::Soroban {
// Solana is BPF, which is 64 bit
64
} else {
Expand Down
13 changes: 11 additions & 2 deletions src/sema/expression/literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ pub(super) fn string_literal(
diagnostics: &mut Diagnostics,
resolve_to: ResolveTo,
) -> Expression {


println!("string_literal: {:?}", v);
println!("resolve_to: {:?}", resolve_to);


// Concatenate the strings
let mut result = Vec::new();
let mut loc = v[0].loc;
Expand All @@ -37,7 +43,7 @@ pub(super) fn string_literal(

let length = result.len();

match resolve_to {
let ret = match resolve_to {
ResolveTo::Type(Type::String) => Expression::AllocDynamicBytes {
loc,
ty: Type::String,
Expand Down Expand Up @@ -65,7 +71,10 @@ pub(super) fn string_literal(
ty: Type::Bytes(length as u8),
value: result,
},
}
};

println!("ret: {:?}", ret);
ret
}

pub(super) fn hex_literal(
Expand Down
4 changes: 4 additions & 0 deletions tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ fn solana_contracts() -> io::Result<()> {

#[test]
fn polkadot_contracts() -> io::Result<()> {

println!("polkadot_contracts heeeeeere");
contract_tests(
"tests/contract_testcases/polkadot",
Target::default_polkadot(),
Expand Down Expand Up @@ -68,6 +70,8 @@ fn parse_file(path: PathBuf, target: Target) -> io::Result<()> {

let filename = add_file(&mut cache, &path, target)?;

println!("Parsing {}", filename);

let mut ns = parse_and_resolve(OsStr::new(&filename), &mut cache, target);

if !ns.diagnostics.any_errors() {
Expand Down

0 comments on commit c656939

Please sign in to comment.