WIP10 - Runtime debug

This commit is contained in:
David Mak 2024-08-12 15:30:49 +08:00
parent 89d52b310c
commit e18dbf904b
1 changed files with 10 additions and 0 deletions

View File

@ -748,6 +748,9 @@ fn polymorphic_print<'ctx>(
generator: &mut dyn CodeGenerator,
fmt: String,
args: Vec<BasicValueEnum<'ctx>>| {
assert!(!fmt.is_empty());
assert_eq!(fmt.as_bytes().last().unwrap(), &0u8);
let fn_name = if as_rtio { "rtio_log" } else { "core_log" };
let print_fn = ctx.module.get_function(fn_name).unwrap_or_else(|| {
let llvm_pi8 = ctx.ctx.i8_type().ptr_type(AddressSpace::default());
@ -763,8 +766,15 @@ fn polymorphic_print<'ctx>(
println!("printf({fmt}, [{}])", args.iter().map(|arg| arg.to_string()).join(", "));
let fmt_val = ctx.gen_string(generator, "hi :)\0");
let fmt_val = unsafe { fmt_val.get_field_at_index_unchecked(0) }.into_pointer_value();
println!("fmt_val: {}", fmt_val);
ctx.builder.build_call(print_fn, &[fmt_val.into()], "").unwrap();
let fmt = ctx.gen_string(generator, fmt);
let fmt = unsafe { fmt.get_field_at_index_unchecked(0) }.into_pointer_value();
println!("fmt: {}", fmt);
ctx.builder
.build_call(