• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

henrythasler / rust-tiny-wasm / 22778012801

06 Mar 2026 07:08PM UTC coverage: 33.486% (+3.2%) from 30.248%
22778012801

push

github

henrythasler
use simplified module structure

47 of 86 new or added lines in 2 files covered. (54.65%)

2 existing lines in 1 file now uncovered.

586 of 1750 relevant lines covered (33.49%)

1.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.71
/src/loader.rs
1
use kaitai::{BytesReader, KStruct, OptRc};
2
use std::fs;
3

4
mod vlq_base128_le;
5
pub mod webassembly;
6
use webassembly::{Webassembly, Webassembly_ValTypes};
7

8
pub struct Local {
9
    count: i32,
10
    r#type: Webassembly_ValTypes,
11
}
12

13
pub struct Code {
14
    locals: Vec<Local>,
15
    code: Vec<u8>,
16
}
17

18
impl Code {
NEW
19
    pub fn get_code(&self) -> &[u8] {
×
NEW
20
        &self.code
×
NEW
21
    }
×
NEW
22
    pub fn get_locals(&self) -> &[Local] {
×
NEW
23
        &self.locals
×
NEW
24
    }
×
25
}
26

27
pub struct CodeSection {
28
    pub entries: Vec<Code>,
29
}
30

31
impl CodeSection {
NEW
32
    pub fn name(&self) -> String {
×
NEW
33
        String::from("code_section")
×
NEW
34
    }
×
35
}
36

37
pub struct Export {
38
    pub name: String,
39
    r#type: i32,
40
    index: i32,
41
}
42

43
pub struct ExportSection {
44
    pub exports: Vec<Export>,
45
}
46

47
impl ExportSection {
NEW
48
    pub fn name(&self) -> String {
×
NEW
49
        String::from("export_section")
×
NEW
50
    }
×
51
}
52

53
pub enum Sections {
54
    Export(ExportSection),
55
    Code(CodeSection),
56
}
57

58
pub struct WasmModule {
59
    pub file_path: String,
60
    pub sections: Vec<Sections>,
61
}
62

63
fn kaitai_parse_module(file_path: &str) -> Result<OptRc<Webassembly>, String> {
1✔
64
    let bytes = fs::read(file_path).expect("Should have been able to read the file");
1✔
65
    let io = BytesReader::from(bytes);
1✔
66
    let parsed = Webassembly::read_into::<BytesReader, Webassembly>(&io, None, None)
1✔
67
        .expect("Failed to parse WebAssembly module");
1✔
68
    Ok(parsed)
1✔
69
}
1✔
70

71
pub fn load_wasm_module(file_path: &str) -> WasmModule {
1✔
72
    let wasm = kaitai_parse_module(file_path).expect("Error parsing WebAssembly module");
1✔
73

74
    // we simplify the rather complex parser result and move the content to our own structure
75
    let mut wasm_module = WasmModule {
1✔
76
        file_path: String::from(file_path),
1✔
77
        sections: Vec::new(),
1✔
78
    };
1✔
79

80
    for section in wasm.sections().iter() {
4✔
81
        let content_ref = section.content();
4✔
82
        let content = content_ref.as_ref();
4✔
83

84
        match content {
4✔
85
            Some(webassembly::Webassembly_Section_Content::Webassembly_ExportSection(section)) => {
1✔
86
                let export_section = section.get();
1✔
87
                let mut new_export_section = ExportSection {
1✔
88
                    exports: Vec::new(),
1✔
89
                };
1✔
90

91
                let exports = export_section.exports();
1✔
92
                for export in exports.iter() {
2✔
93
                    let export_name = export.name();
2✔
94
                    let export_name_str = export_name.value();
2✔
95
                    new_export_section.exports.push(Export {
2✔
96
                        name: export_name_str.clone(),
2✔
97
                        r#type: 0,
2✔
98
                        index: 0,
2✔
99
                    });
2✔
100
                }
2✔
101
                wasm_module
1✔
102
                    .sections
1✔
103
                    .push(Sections::Export(new_export_section));
1✔
104
            }
105
            Some(webassembly::Webassembly_Section_Content::Webassembly_CodeSection(section)) => {
1✔
106
                let code_section = section.get();
1✔
107
                let mut new_code_section = CodeSection {
1✔
108
                    entries: Vec::new(),
1✔
109
                };
1✔
110

111
                for entry in code_section.entries().iter() {
2✔
112
                    let func = entry.func();
2✔
113
                    let locals = func.locals();
2✔
114

115
                    let mut new_locals: Vec<Local> = Vec::new();
2✔
116

117
                    for local in locals.iter() {
2✔
NEW
118
                        new_locals.push(Local {
×
NEW
119
                            count: *local.num_valtype().value().unwrap(),
×
NEW
120
                            r#type: local.valtype().clone(),
×
NEW
121
                        });
×
NEW
122
                    }
×
123

124
                    new_code_section.entries.push(Code {
2✔
125
                        locals: new_locals,
2✔
126
                        code: func.expr().clone(),
2✔
127
                    });
2✔
128
                }
129

130
                wasm_module.sections.push(Sections::Code(new_code_section));
1✔
131
            }
132
            _ => (),
2✔
133
        }
134
    }
135
    wasm_module
1✔
136
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc