Add support for anonymous translation
This commit is contained in:
parent
830727d8d4
commit
f02070a1b3
@ -1,6 +1,6 @@
|
|||||||
pub static RUNTIME: &str = include_str!("../runtime/runtime.lua");
|
pub static RUNTIME: &str = include_str!("../runtime/runtime.lua");
|
||||||
|
|
||||||
pub use translator::translate;
|
pub use translator::{from_inst_list, from_module};
|
||||||
|
|
||||||
mod analyzer;
|
mod analyzer;
|
||||||
mod backend;
|
mod backend;
|
||||||
|
@ -321,7 +321,15 @@ fn write_module_start(
|
|||||||
|
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// Returns `Err` if writing to `Write` failed.
|
/// Returns `Err` if writing to `Write` failed.
|
||||||
pub fn translate(wasm: &Module, type_info: &TypeInfo, w: &mut dyn Write) -> Result<()> {
|
pub fn from_inst_list(code: &[Instruction], type_info: &TypeInfo, w: &mut dyn Write) -> Result<()> {
|
||||||
|
Builder::new(type_info)
|
||||||
|
.with_anon(code)
|
||||||
|
.write(&mut Manager::default(), w)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns `Err` if writing to `Write` failed.
|
||||||
|
pub fn from_module(wasm: &Module, type_info: &TypeInfo, w: &mut dyn Write) -> Result<()> {
|
||||||
let func_list = build_func_list(wasm, type_info);
|
let func_list = build_func_list(wasm, type_info);
|
||||||
|
|
||||||
write_localize_used(&func_list, w)?;
|
write_localize_used(&func_list, w)?;
|
||||||
|
@ -5,7 +5,7 @@ pub static RUNTIME: &str = concat!(
|
|||||||
include_str!("../runtime/runtime.lua")
|
include_str!("../runtime/runtime.lua")
|
||||||
);
|
);
|
||||||
|
|
||||||
pub use translator::translate;
|
pub use translator::{from_inst_list, from_module};
|
||||||
|
|
||||||
mod analyzer;
|
mod analyzer;
|
||||||
mod backend;
|
mod backend;
|
||||||
|
@ -321,7 +321,15 @@ fn write_module_start(
|
|||||||
|
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// Returns `Err` if writing to `Write` failed.
|
/// Returns `Err` if writing to `Write` failed.
|
||||||
pub fn translate(wasm: &Module, type_info: &TypeInfo, w: &mut dyn Write) -> Result<()> {
|
pub fn from_inst_list(code: &[Instruction], type_info: &TypeInfo, w: &mut dyn Write) -> Result<()> {
|
||||||
|
Builder::new(type_info)
|
||||||
|
.with_anon(code)
|
||||||
|
.write(&mut Manager::default(), w)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns `Err` if writing to `Write` failed.
|
||||||
|
pub fn from_module(wasm: &Module, type_info: &TypeInfo, w: &mut dyn Write) -> Result<()> {
|
||||||
let func_list = build_func_list(wasm, type_info);
|
let func_list = build_func_list(wasm, type_info);
|
||||||
|
|
||||||
write_localize_used(&func_list, w)?;
|
write_localize_used(&func_list, w)?;
|
||||||
|
@ -14,5 +14,5 @@ libfuzzer_sys::fuzz_target!(|module: Module| {
|
|||||||
let type_info = TypeInfo::from_module(&wasm);
|
let type_info = TypeInfo::from_module(&wasm);
|
||||||
let sink = &mut std::io::sink();
|
let sink = &mut std::io::sink();
|
||||||
|
|
||||||
codegen_luajit::translate(&wasm, &type_info, sink).expect("LuaJIT should succeed");
|
codegen_luajit::from_module(&wasm, &type_info, sink).expect("LuaJIT should succeed");
|
||||||
});
|
});
|
||||||
|
@ -14,5 +14,5 @@ libfuzzer_sys::fuzz_target!(|module: Module| {
|
|||||||
let type_info = TypeInfo::from_module(&wasm);
|
let type_info = TypeInfo::from_module(&wasm);
|
||||||
let sink = &mut std::io::sink();
|
let sink = &mut std::io::sink();
|
||||||
|
|
||||||
codegen_luau::translate(&wasm, &type_info, sink).expect("Luau should succeed");
|
codegen_luau::from_module(&wasm, &type_info, sink).expect("Luau should succeed");
|
||||||
});
|
});
|
||||||
|
@ -23,8 +23,8 @@ fn run_translator(wasm: &Module, runtime: &str, translate: Translate) -> Result<
|
|||||||
fn do_translate(name: &str, file: &str) {
|
fn do_translate(name: &str, file: &str) {
|
||||||
let wasm = &parse_module(file);
|
let wasm = &parse_module(file);
|
||||||
let result = match name.to_lowercase().as_str() {
|
let result = match name.to_lowercase().as_str() {
|
||||||
"luajit" => run_translator(wasm, codegen_luajit::RUNTIME, codegen_luajit::translate),
|
"luajit" => run_translator(wasm, codegen_luajit::RUNTIME, codegen_luajit::from_module),
|
||||||
"luau" => run_translator(wasm, codegen_luau::RUNTIME, codegen_luau::translate),
|
"luau" => run_translator(wasm, codegen_luau::RUNTIME, codegen_luau::from_module),
|
||||||
_ => panic!("Bad language: {name}"),
|
_ => panic!("Bad language: {name}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user