near / wasmtime

Standalone JIT-style runtime for WebAssembly, using Cranelift
https://wasmtime.dev/
Apache License 2.0
3 stars 4 forks source link

Rework `put_string`-based codegen #204

Open aborg-dev opened 8 months ago

aborg-dev commented 8 months ago

We currently generate most of zkAsm code using put_string function: https://github.com/near/wasmtime/blob/20945d99a984c11328d8a544f2925ff0b2b79b0d/cranelift/codegen/src/isa/zkasm/inst/emit.rs#L370

There are a few things that we can improve here:

MCJOHN974 commented 7 months ago

In continue to today discussion, I agree that better way to do this will be iteratively add functions like

fn emit_assign32(sink, reg, val) {
   sink.put_string(...)
}

But once majority of such functions will be implemented I still for introducing ZkasmSink struct, which will be wrapper on top of old sink, and once we will need some new functionality of old sink we will be able to easily do something

impl ZkasmSink {
    fn new_sink_feature(...) {
        self.sink.new_sink_feature()
    }
}

So we wouldn't really deviate codestyle much, we will just enrich a bit functionality of sink.

And this will help to fully avoid direct put_string usage, and made code more consistent, which will be better I think