New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage as a library #21
Comments
There could absolutely have a more convenient function for this use-case, but as of now, if you take a look at the webasm interface, it shows a way you can do it. Then, you may use |
I indeed saw this method, but sadly it's unsafe and I'm working in a crate that forbids any |
You can remove the unsafe parts; maybe something like the following? I haven't tested it, though: fn assemble(src: &str) -> Vec<u8>
{
let mut fileserver = FileServerMock::new();
fileserver.add("asm", src.clone());
let assemble = |report: RcReport, fileserver: &FileServerMock, filename: &str| -> Result<Vec<u8>, ()>
{
let mut asm = AssemblerState::new();
asm.process_file(report.clone(), fileserver, filename)?;
asm.wrapup(report.clone())?;
let output = asm.get_binary_output();
Ok(output.generate_binary(0, output.len()))
};
let report = RcReport::new();
match assemble(report.clone(), &fileserver, "asm")
{
Ok(output) => output,
Err(_) => panic!("error assembling")
}
} |
I've added a new function, so you can now do: customasm::assemble_str_to_binary("your string") You can retrieve the byte array by doing: let bytes = customasm::assemble_str_to_binary("your string").0.unwrap(); |
Sorry for the late answer I just received for notification. |
Hi,
I'm currently developping a virtual machine library that uses custom instructions, which means a custom assembly language.
I've used CustomASM for a while now using the CLI and I really enjoy the possibility of the projects (alignment, labels, arithmetic, etc.), but I'd like to integrate it to my library. Sadly, when I looked at your files, it doesn't seem you expose enough functions to enable concrete usage as a library :/
Do you have any plan to enable such usage? It'd be really great to be able to do something like:
Thanks in advance for your answer :)
The text was updated successfully, but these errors were encountered: