Stream: git-wasmtime

Topic: wasmtime / issue #3263 [Cranelift] Create a DSL for conve...


view this post on Zulip Wasmtime GitHub notifications bot (Aug 30 2021 at 14:35):

antonromanov1 edited issue #3263:

Now we have such creation of a function in unreachable_node test in dominator_tree.rs:

let mut func = Function::new();
let block0 = func.dfg.make_block();
let v0 = func.dfg.append_block_param(block0, I32);
let block1 = func.dfg.make_block();
let block2 = func.dfg.make_block();

let mut cur = FuncCursor::new(&mut func);

cur.insert_block(block0);
cur.ins().brnz(v0, block2, &[]);
cur.ins().trap(TrapCode::User(0));

cur.insert_block(block1);
let v1 = cur.ins().iconst(I32, 1);
let v2 = cur.ins().iadd(v0, v1);
cur.ins().jump(block0, &[v2]);

cur.insert_block(block2);
cur.ins().return_(&[v0]);

This is not very readable. Can we write a DSL with approximately such usage:

Function {
    Block(0, p0: I32) {
        INST(0, Opcode::Brnz).Args(p0).Target(2, &[])
        INST(1, Opcode::Trap).User(0)
    }
    Block(1) {
        INST(2, Opcode::Iconst).Value(1)
        INST(3, Opcode::Iadd).Args(p0, 2)
        INST(4, Opcode::Jump).Target(0, &[3])
    }
    Block(2) {
        INST(5, Opcode::Return).Args(p0)
    }
}

?


Last updated: Dec 23 2024 at 12:05 UTC