1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

wasm: remove dependency on thirdparty/binaryen, webassembly backend rewrite (#18120)

This commit is contained in:
l-m
2023-07-12 12:24:38 +00:00
committed by GitHub
parent 1c7df29bed
commit c422919481
40 changed files with 2895 additions and 6166 deletions

View File

@@ -861,6 +861,17 @@ pub fn (mut func Function) cast_trapping(a NumType, is_signed bool, b NumType) {
func.cast(a, is_signed, b)
}
// reinterpret returns a value which has the same bit-pattern as its operand value, in its result type.
// WebAssembly instruction: `f32.reinterpret_i32`, `i32.reinterpret_f32`, `f64.reinterpret_i64`, `i64.reinterpret_f64`.
pub fn (mut func Function) reinterpret(a NumType) {
match a {
.f32_t { func.code << 0xBC } // i32.reinterpret_f32
.i32_t { func.code << 0xBE } // f32.reinterpret_i32
.f64_t { func.code << 0xBD } // i64.reinterpret_f64
.i64_t { func.code << 0xBF } // f64.reinterpret_i64
}
}
// unreachable denotes a point in code that should not be reachable, it is an unconditional trap.
// WebAssembly instruction: `unreachable`.
pub fn (mut func Function) unreachable() {
@@ -919,7 +930,7 @@ pub fn (mut func Function) c_return() {
func.code << 0x0F // return
}
// c_end ends the block or loop with the label passed in at `label`.
// c_end ends the block, loop or if expression with the label passed in at `label`.
pub fn (mut func Function) c_end(label LabelIndex) {
assert func.label == label, 'c_end: called with an invalid label ${label}'
func.label--
@@ -945,11 +956,6 @@ pub fn (mut func Function) c_br_if(label LabelIndex) {
func.u32(u32(v))
}
// c_end_if closes the current if expression.
pub fn (mut func Function) c_end_if() {
func.code << 0x0B // END expression opcode
}
// call calls a locally defined function.
// If this function does not exist when calling `compile` on the module, it will panic.
// WebAssembly instruction: `call`.