pub struct FuncBody { /* private fields */ }Expand description
Function body definition.
Implementations§
Source§impl FuncBody
impl FuncBody
Sourcepub fn new(locals: Vec<Local>, opcodes: Opcodes) -> Self
pub fn new(locals: Vec<Local>, opcodes: Opcodes) -> Self
New function body with given locals and opcodes
Sourcepub fn code(&self) -> &Opcodes
pub fn code(&self) -> &Opcodes
Opcode sequence of the function body. Minimal opcode sequence
is just &[Opcode::End]
Sourcepub fn locals_mut(&mut self) -> &mut Vec<Local>
pub fn locals_mut(&mut self) -> &mut Vec<Local>
Locals declared in function body (mutable).
Sourcepub fn code_mut(&mut self) -> &mut Opcodes
pub fn code_mut(&mut self) -> &mut Opcodes
Opcode sequence of the function body (mutable).
Examples found in repository?
examples/inject.rs (line 41)
28fn main() {
29 let args = env::args().collect::<Vec<_>>();
30 if args.len() != 3 {
31 println!("Usage: {} input_file.wasm output_file.wasm", args[0]);
32 return;
33 }
34
35 let mut module = sophon_wasm::deserialize_file(&args[1]).unwrap();
36
37 for section in module.sections_mut() {
38 match section {
39 &mut elements::Section::Code(ref mut code_section) => {
40 for ref mut func_body in code_section.bodies_mut() {
41 inject_nop(func_body.code_mut());
42 }
43 },
44 _ => { }
45 }
46 }
47
48 let mut build = builder::from_module(module);
49 let import_sig = build.push_signature(
50 builder::signature()
51 .param().i32()
52 .param().i32()
53 .return_type().i32()
54 .build_sig()
55 );
56 let build = build.import()
57 .module("env")
58 .field("log")
59 .external().func(import_sig)
60 .build();
61
62 sophon_wasm::serialize_to_file(&args[2], build.build()).unwrap();
63}Trait Implementations§
Auto Trait Implementations§
impl Freeze for FuncBody
impl RefUnwindSafe for FuncBody
impl Send for FuncBody
impl Sync for FuncBody
impl Unpin for FuncBody
impl UnwindSafe for FuncBody
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more