Stream: git-wasmtime

Topic: wasmtime / issue #3263 [Proposal] Create a DSL for conven...


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

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)
    }
}

?

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

abrown commented on issue #3263:

What about parsing the CLIF text format?

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

antonromanov1 commented on issue #3263:

@abrown okay, why isn't this used in the tests ?

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

abrown commented on issue #3263:

Hm, not sure for the test you link to: probably because adding cranelift-reader (the CLIF parser) as a test dependency would add a circular dependency? In other places, e.g., in the interpreter, this is not an issue. I believe the circular dependency could be resolved by factoring out several key structures from cranelift-codegen into a separate cranelift-ir crate that both cranelift-codegen and cranelift-reader could depend on--but this might be a bit tricky?

I don't want to discourage you from creating a DSL if you are interested in that, just pointing out that there are other options.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 31 2021 at 16:34):

gabriel-fallen commented on issue #3263:

@antonromanov1 if you're OK with referring target blocks for jumps by _indexes_ (which is error-prone and refactoring-unfriendly) I don't see why do you need a macros-based DSL while you can just put the necessary code into functions. Akin to

let block0 = create_block(instrs0);
let block1 = create_block(instrs1);
let block2 = create_block(instrs2);

let fun = create_function(vec![block0, block1, block2]);


Last updated: Dec 23 2024 at 12:05 UTC