From c6569397a496ba4b8fb98b7320085e944bec776e Mon Sep 17 00:00:00 2001 From: salaheldinsoliman Date: Mon, 29 Jul 2024 23:02:51 +0200 Subject: [PATCH] add some debug prints Signed-off-by: salaheldinsoliman --- src/codegen/expression.rs | 1 + src/emit/expression.rs | 41 +++++++++++++++++++++++++++++++++ src/emit/instructions.rs | 3 +++ src/lib.rs | 2 +- src/sema/expression/literals.rs | 13 +++++++++-- tests/contract.rs | 4 ++++ 6 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/codegen/expression.rs b/src/codegen/expression.rs index c70818301..4b4bcb27c 100644 --- a/src/codegen/expression.rs +++ b/src/codegen/expression.rs @@ -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() { diff --git a/src/emit/expression.rs b/src/emit/expression.rs index 1dab66c73..a3b3a02db 100644 --- a/src/emit/expression.rs +++ b/src/emit/expression.rs @@ -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); @@ -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(); @@ -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 { diff --git a/src/emit/instructions.rs b/src/emit/instructions.rs index c36b266b3..8f8208440 100644 --- a/src/emit/instructions.rs +++ b/src/emit/instructions.rs @@ -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)); } diff --git a/src/lib.rs b/src/lib.rs index 46abbf7e3..4cafbbd01 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { diff --git a/src/sema/expression/literals.rs b/src/sema/expression/literals.rs index 418d537e9..86fb049e7 100644 --- a/src/sema/expression/literals.rs +++ b/src/sema/expression/literals.rs @@ -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; @@ -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, @@ -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( diff --git a/tests/contract.rs b/tests/contract.rs index 65c2ccb65..2dd0da378 100644 --- a/tests/contract.rs +++ b/tests/contract.rs @@ -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(), @@ -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() {