Skip to main content

oxilean_codegen/wasm_backend/
wasminstr_traits.rs

1//! # WasmInstr - Trait Implementations
2//!
3//! This module contains trait implementations for `WasmInstr`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Display`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use crate::lcnf::*;
12
13use super::types::WasmInstr;
14use std::fmt;
15
16impl fmt::Display for WasmInstr {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            WasmInstr::LocalGet(name) => write!(f, "local.get ${}", name),
20            WasmInstr::LocalSet(name) => write!(f, "local.set ${}", name),
21            WasmInstr::I32Const(n) => write!(f, "i32.const {}", n),
22            WasmInstr::I64Const(n) => write!(f, "i64.const {}", n),
23            WasmInstr::F64Const(n) => write!(f, "f64.const {}", n),
24            WasmInstr::Call(name) => write!(f, "call ${}", name),
25            WasmInstr::CallIndirect => write!(f, "call_indirect"),
26            WasmInstr::Return => write!(f, "return"),
27            WasmInstr::Drop => write!(f, "drop"),
28            WasmInstr::BrIf(label) => write!(f, "br_if {}", label),
29            WasmInstr::Block => write!(f, "block"),
30            WasmInstr::Loop => write!(f, "loop"),
31            WasmInstr::End => write!(f, "end"),
32            WasmInstr::Nop => write!(f, "nop"),
33            WasmInstr::Unreachable => write!(f, "unreachable"),
34            WasmInstr::Select => write!(f, "select"),
35            WasmInstr::I32Add => write!(f, "i32.add"),
36            WasmInstr::I32Sub => write!(f, "i32.sub"),
37            WasmInstr::I32Mul => write!(f, "i32.mul"),
38            WasmInstr::I32DivS => write!(f, "i32.div_s"),
39            WasmInstr::I64Add => write!(f, "i64.add"),
40            WasmInstr::I64Mul => write!(f, "i64.mul"),
41            WasmInstr::F64Add => write!(f, "f64.add"),
42            WasmInstr::F64Mul => write!(f, "f64.mul"),
43            WasmInstr::F64Div => write!(f, "f64.div"),
44            WasmInstr::F64Sqrt => write!(f, "f64.sqrt"),
45            WasmInstr::MemLoad(align) => write!(f, "i32.load align={}", align),
46            WasmInstr::MemStore(align) => write!(f, "i32.store align={}", align),
47            WasmInstr::I32Eqz => write!(f, "i32.eqz"),
48            WasmInstr::I32Eq => write!(f, "i32.eq"),
49            WasmInstr::I32Ne => write!(f, "i32.ne"),
50            WasmInstr::I32LtS => write!(f, "i32.lt_s"),
51            WasmInstr::I32GtS => write!(f, "i32.gt_s"),
52            WasmInstr::I32LeS => write!(f, "i32.le_s"),
53            WasmInstr::I32GeS => write!(f, "i32.ge_s"),
54            WasmInstr::RefNull => write!(f, "ref.null funcref"),
55            WasmInstr::RefIsNull => write!(f, "ref.is_null"),
56            WasmInstr::TableGet(idx) => write!(f, "table.get {}", idx),
57            WasmInstr::TableSet(idx) => write!(f, "table.set {}", idx),
58        }
59    }
60}