forked from M-Labs/nac3
nac3artiq: add compile_method_to_mem
This commit is contained in:
parent
597857ccd0
commit
204baabfd2
@ -110,7 +110,7 @@ class Core:
|
|||||||
obj = method
|
obj = method
|
||||||
name = ""
|
name = ""
|
||||||
|
|
||||||
compiler.compile_method(obj, name, args)
|
compiler.compile_method_to_file(obj, name, args, "module.elf")
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def reset(self):
|
def reset(self):
|
||||||
|
@ -317,11 +317,12 @@ impl Nac3 {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_method(
|
fn compile_method_to_file(
|
||||||
&mut self,
|
&mut self,
|
||||||
obj: &PyAny,
|
obj: &PyAny,
|
||||||
method_name: String,
|
method_name: &str,
|
||||||
args: Vec<&PyAny>,
|
args: Vec<&PyAny>,
|
||||||
|
filename: &str,
|
||||||
py: Python,
|
py: Python,
|
||||||
) -> PyResult<()> {
|
) -> PyResult<()> {
|
||||||
let id_fun = PyModule::import(py, "builtins")?.getattr("id")?;
|
let id_fun = PyModule::import(py, "builtins")?.getattr("id")?;
|
||||||
@ -464,7 +465,7 @@ impl Nac3 {
|
|||||||
"--eh-frame-hdr".to_string(),
|
"--eh-frame-hdr".to_string(),
|
||||||
"-x".to_string(),
|
"-x".to_string(),
|
||||||
"-o".to_string(),
|
"-o".to_string(),
|
||||||
"module.elf".to_string(),
|
filename.to_string(),
|
||||||
];
|
];
|
||||||
if isa != Isa::Host {
|
if isa != Isa::Host {
|
||||||
linker_args.push("-T".to_string() + self.working_directory.path().join("kernel.ld").to_str().unwrap());
|
linker_args.push("-T".to_string() + self.working_directory.path().join("kernel.ld").to_str().unwrap());
|
||||||
@ -484,6 +485,19 @@ impl Nac3 {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compile_method_to_mem(
|
||||||
|
&mut self,
|
||||||
|
obj: &PyAny,
|
||||||
|
method_name: &str,
|
||||||
|
args: Vec<&PyAny>,
|
||||||
|
py: Python,
|
||||||
|
) -> PyResult<Vec<u8>> {
|
||||||
|
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]
|
#[pymodule]
|
||||||
|
Loading…
Reference in New Issue
Block a user