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

henrythasler / rust-tiny-wasm / 23025473083

12 Mar 2026 09:47PM UTC coverage: 55.385% (-6.3%) from 61.644%
23025473083

push

github

henrythasler
implement control instruction compilation

0 of 50 new or added lines in 4 files covered. (0.0%)

3 existing lines in 2 files now uncovered.

180 of 325 relevant lines covered (55.38%)

1.33 hits per line

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

0.0
/src/compiler/function.rs
1
use crate::assembler::aarch64::*;
2
use crate::assembler::{emit_epilogue, emit_prologue};
3
use crate::compiler::control_instructions::{compile_end, compile_return};
4
use crate::loader::Code;
5
use crate::loader::webassembly::Webassembly_ValTypes;
6

7
#[derive(Debug)]
8
pub enum Opcode {
9
    Func,
10
    Block,
11
    Loop,
12
    If,
13
    Else,
14
}
15

16
#[derive(Debug)]
17
pub enum Instruction {
18
    Br,
19
}
20

21
#[derive(Debug)]
22
pub struct Patch {
23
    pub location: usize,
24
    pub instruction: Instruction,
25
}
26

27
#[derive(Debug)]
28
pub struct ControlFrame {
29
    pub opcode: Opcode,
30
    start_types: Vec<Webassembly_ValTypes>,
31
    pub end_types: Vec<Webassembly_ValTypes>,
32
    pub stack_height: usize,
33
    pub patches: Vec<Patch>,
34
}
35

36
pub struct StackElement {
37
    location: Reg,
38
    val_type: Webassembly_ValTypes,
39
}
40

41
pub fn compile_function(entry: &Code, machinecode: &mut Vec<u32>) {
×
42
    // every functions starts with an epilogue to save the initial state and create a new stack frame
43
    emit_prologue(machinecode);
×
44

45
    // Control stack is initialized with the (implicit) outer func-block
46
    let mut control_stack: Vec<ControlFrame> = vec![ControlFrame {
×
47
        opcode: Opcode::Func,
×
48
        start_types: vec![], // FIXME: insert function parameters
×
49
        end_types: vec![],   // FIXME: insert result types
×
50
        stack_height: 0,
×
NEW
51
        patches: vec![],
×
UNCOV
52
    }];
×
53

54
    // Value stack starts empty
55
    let mut value_stack: Vec<StackElement> = vec![];
×
56

57
    // iterate over WebAssembly opcodes and emit machinecode instructions
58
    let mut iter = entry.code.iter();
×
59
    'expression: while let Some(&opcode) = iter.next() {
×
60
        if opcode == 0x0f {
×
NEW
61
            compile_return(machinecode, &mut control_stack);
×
NEW
62
        } else if opcode == 0x0b && compile_end(machinecode, &mut control_stack, &mut value_stack) {
×
NEW
63
            break 'expression;
×
UNCOV
64
        }
×
65
    }
66
    println!();
×
67

68
    // FIXME: move result to r0
69

70
    // restore initial state before returning to the caller
71
    emit_epilogue(machinecode);
×
72
}
×
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