From 204baabfd21b9bf0c482bcfd7a2935cdfa447e8b Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 6 Nov 2021 14:14:53 +0800 Subject: [PATCH] nac3artiq: add compile_method_to_mem --- nac3artiq/demo/min_artiq.py | 2 +- nac3artiq/src/lib.rs | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/nac3artiq/demo/min_artiq.py b/nac3artiq/demo/min_artiq.py index 6bc4f114c..06c3640d6 100644 --- a/nac3artiq/demo/min_artiq.py +++ b/nac3artiq/demo/min_artiq.py @@ -110,7 +110,7 @@ class Core: obj = method name = "" - compiler.compile_method(obj, name, args) + compiler.compile_method_to_file(obj, name, args, "module.elf") @kernel def reset(self): diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index 8bd191095..b39369241 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -317,11 +317,12 @@ impl Nac3 { Ok(()) } - fn compile_method( + fn compile_method_to_file( &mut self, obj: &PyAny, - method_name: String, + method_name: &str, args: Vec<&PyAny>, + filename: &str, py: Python, ) -> PyResult<()> { let id_fun = PyModule::import(py, "builtins")?.getattr("id")?; @@ -464,7 +465,7 @@ impl Nac3 { "--eh-frame-hdr".to_string(), "-x".to_string(), "-o".to_string(), - "module.elf".to_string(), + filename.to_string(), ]; if isa != Isa::Host { linker_args.push("-T".to_string() + self.working_directory.path().join("kernel.ld").to_str().unwrap()); @@ -484,6 +485,19 @@ impl Nac3 { Ok(()) } + + fn compile_method_to_mem( + &mut self, + obj: &PyAny, + method_name: &str, + args: Vec<&PyAny>, + py: Python, + ) -> PyResult> { + let filename_path = self.working_directory.path().join("module.elf"); + let filename = filename_path.to_str().unwrap(); + self.compile_method_to_file(obj, method_name, args, filename, py)?; + Ok(fs::read(filename).unwrap()) + } } #[pymodule]