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

henrythasler / rust-tiny-wasm / 27492556297

14 Jun 2026 07:57AM UTC coverage: 92.969% (-1.2%) from 94.121%
27492556297

Pull #6

github

web-flow
Merge b6c98ccdf into df49d44a8
Pull Request #6: Feature/floats

533 of 584 new or added lines in 19 files covered. (91.27%)

5 existing lines in 3 files now uncovered.

2023 of 2176 relevant lines covered (92.97%)

62.72 hits per line

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

96.51
/src/compiler/stack.rs
1
use crate::assembler::aarch64::*;
2
use wasmparser::ValType;
3

4
pub fn valtype_to_usize(valtype: &ValType) -> usize {
364✔
5
    match valtype {
364✔
6
        ValType::I32 => INT32_SIZE,
192✔
7
        ValType::I64 => INT64_SIZE,
156✔
8
        ValType::F32 => FLOAT32_SIZE,
8✔
9
        ValType::F64 => FLOAT64_SIZE,
8✔
10
        ValType::V128 => 16,
×
11
        _ => panic!("valtype not supported"),
×
12
    }
13
}
364✔
14

15
#[derive(Debug)]
16
pub struct LocalVar {
17
    pub offset: usize,
18
    pub valtype: ValType,
19
}
20

21
pub fn get_aligned_stack_size(
161✔
22
    func_type: &wasmparser::FuncType,
161✔
23
    locals: &[(u32, ValType)],
161✔
24
) -> (usize, usize) {
161✔
25
    let mut variables_size: usize = 0;
161✔
26
    for item in func_type.params() {
161✔
27
        let size = valtype_to_usize(item);
150✔
28
        // insert padding depending on size of type
150✔
29
        variables_size = variables_size.div_ceil(size) * size;
150✔
30
        variables_size += size;
150✔
31
    }
150✔
32

33
    for (count, valtype) in locals {
161✔
34
        let size = valtype_to_usize(valtype);
32✔
35
        variables_size = variables_size.div_ceil(size) * size;
32✔
36
        variables_size += *count as usize * size;
32✔
37
    }
32✔
38

39
    // let mut variables_size = func_type
40
    //     .params()
41
    //     .iter()
42
    //     .fold(0, |acc, x| acc + valtype_to_usize(x));
43
    // variables_size += locals
44
    //     .iter()
45
    //     .fold(0, |acc, x| acc + x.0 as usize * valtype_to_usize(&x.1));
46
    let stack_size = variables_size.div_ceil(STACK_ALIGNMENT) * STACK_ALIGNMENT;
161✔
47
    assert!(
161✔
48
        stack_size.is_multiple_of(STACK_ALIGNMENT),
161✔
49
        "stack size not aligned properly: {}",
50
        stack_size
51
    );
52
    (variables_size, stack_size)
161✔
53
}
161✔
54

55
pub fn save_locals_to_stack(
16✔
56
    offset: &mut usize,
16✔
57
    locals: &[(u32, ValType)],
16✔
58
    machinecode: &mut Vec<u32>,
16✔
59
) -> Vec<LocalVar> {
16✔
60
    let mut variables = vec![];
16✔
61

62
    for (count, valtype) in locals {
32✔
63
        let size = valtype_to_usize(valtype);
32✔
64
        *offset = offset.div_ceil(size) * size;
32✔
65
        for _ in 0..*count {
70✔
66
            variables.push(LocalVar {
70✔
67
                offset: *offset,
70✔
68
                valtype: *valtype,
70✔
69
            });
70✔
70

70✔
71
            machinecode.push(memory::str_imm_unsigned_offset(
70✔
72
                IReg::XZR,
70✔
73
                IReg::SP,
70✔
74
                *offset as u32,
70✔
75
                map_valtype_to_memsize(valtype),
70✔
76
                map_valtype_to_regsize(valtype),
70✔
77
            ));
70✔
78
            *offset += size;
70✔
79
        }
70✔
80
    }
81
    variables
16✔
82
}
16✔
83

84
pub fn save_parameters_to_stack(
90✔
85
    offset: &mut usize,
90✔
86
    values: &[ValType],
90✔
87
    machinecode: &mut Vec<u32>,
90✔
88
) -> Vec<LocalVar> {
90✔
89
    let mut variables = vec![];
90✔
90
    for (i, valtype) in values.iter().enumerate() {
150✔
91
        let size = valtype_to_usize(valtype);
150✔
92
        *offset = offset.div_ceil(size) * size;
150✔
93
        variables.push(LocalVar {
150✔
94
            offset: *offset,
150✔
95
            valtype: *valtype,
150✔
96
        });
150✔
97
        let src_reg = match valtype {
150✔
98
            ValType::I32 | ValType::I64 => Reg::IReg(IReg::try_from(i as u32).unwrap()),
142✔
99
            ValType::F32 | ValType::F64 => Reg::FReg(FReg::try_from(i as u32).unwrap()),
8✔
NEW
100
            _ => panic!("valtype not supported"),
×
101
        };
102

103
        match src_reg {
150✔
104
            Reg::IReg(reg) => machinecode.push(memory::str_imm_unsigned_offset(
142✔
105
                reg,
142✔
106
                IReg::SP,
107
                *offset as u32,
142✔
108
                map_valtype_to_memsize(valtype),
142✔
109
                map_valtype_to_regsize(valtype),
142✔
110
            )),
111

112
            Reg::FReg(reg) => machinecode.push(fp_memory::str_imm_unsigned_offset(
8✔
113
                reg,
8✔
114
                IReg::SP,
115
                *offset as u32,
8✔
116
                map_valtype_to_regsize(valtype),
8✔
117
            )),
118
        }
119
        *offset += size;
150✔
120
    }
121
    variables
90✔
122
}
90✔
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