pub struct CodeSection(/* private fields */);Expand description
Section with function bodies of the module.
Implementations§
Source§impl CodeSection
impl CodeSection
Sourcepub fn with_bodies(bodies: Vec<FuncBody>) -> Self
pub fn with_bodies(bodies: Vec<FuncBody>) -> Self
New code section with specified function bodies
Sourcepub fn bodies_mut(&mut self) -> &mut Vec<FuncBody>
pub fn bodies_mut(&mut self) -> &mut Vec<FuncBody>
All function bodies in the section, mutable.
Examples found in repository?
examples/inject.rs (line 40)
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§
Source§impl Clone for CodeSection
impl Clone for CodeSection
Source§fn clone(&self) -> CodeSection
fn clone(&self) -> CodeSection
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for CodeSection
impl Default for CodeSection
Source§fn default() -> CodeSection
fn default() -> CodeSection
Returns the “default value” for a type. Read more
Source§impl Deserialize for CodeSection
impl Deserialize for CodeSection
Auto Trait Implementations§
impl Freeze for CodeSection
impl RefUnwindSafe for CodeSection
impl Send for CodeSection
impl Sync for CodeSection
impl Unpin for CodeSection
impl UnwindSafe for CodeSection
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