From 33792bea0d3e7b828ecbdc7d4dd6484eacb6b511 Mon Sep 17 00:00:00 2001 From: David Mak Date: Tue, 13 Aug 2024 16:24:17 +0800 Subject: [PATCH] [artiq] Fix LLVM representation of strings Should be `%str` rather than `[N x i8]`. --- nac3artiq/demo/str_abi.py | 26 ++++++++++++++++++++++++++ nac3artiq/src/symbol_resolver.rs | 4 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 nac3artiq/demo/str_abi.py diff --git a/nac3artiq/demo/str_abi.py b/nac3artiq/demo/str_abi.py new file mode 100644 index 00000000..2edfbf96 --- /dev/null +++ b/nac3artiq/demo/str_abi.py @@ -0,0 +1,26 @@ +from min_artiq import * +from numpy import ndarray, zeros as np_zeros + + +@nac3 +class StrFail: + core: KernelInvariant[Core] + + def __init__(self): + self.core = Core() + + @kernel + def hello(self, arg: str): + pass + + @kernel + def consume_ndarray(self, arg: ndarray[str, 1]): + pass + + def run(self): + self.hello("world") + self.consume_ndarray(np_zeros([10], dtype=str)) + + +if __name__ == "__main__": + StrFail().run() diff --git a/nac3artiq/src/symbol_resolver.rs b/nac3artiq/src/symbol_resolver.rs index 31d0864c..d38c460d 100644 --- a/nac3artiq/src/symbol_resolver.rs +++ b/nac3artiq/src/symbol_resolver.rs @@ -163,7 +163,7 @@ impl StaticValue for PythonValue { PrimitiveValue::Bool(val) => { ctx.ctx.i8_type().const_int(u64::from(*val), false).into() } - PrimitiveValue::Str(val) => ctx.ctx.const_string(val.as_bytes(), true).into(), + PrimitiveValue::Str(val) => ctx.gen_string(generator, val).into(), }); } if let Some(global) = ctx.module.get_global(&self.id.to_string()) { @@ -977,7 +977,7 @@ impl InnerResolver { } else if ty_id == self.primitive_ids.string || ty_id == self.primitive_ids.np_str_ { let val: String = obj.extract().unwrap(); self.id_to_primitive.write().insert(id, PrimitiveValue::Str(val.clone())); - Ok(Some(ctx.ctx.const_string(val.as_bytes(), true).into())) + Ok(Some(ctx.gen_string(generator, val).into())) } else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 { let val: f64 = obj.extract().unwrap(); self.id_to_primitive.write().insert(id, PrimitiveValue::F64(val)); -- 2.44.2