bytecodealliance / bytecodealliance/wasmtime

[Proposal] Create a DSL for conveniently creating a function in the tests

Open
#3,263 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

Now we have such creation of a function in [unreachable_node test in dominator_tree.rs](https://github.com/bytecodealliance/wasmtime/blob/main/cranelift/codegen/src/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)
}
}

?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.