-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make wasmtime-cranelift::Builder
public
#6681
Comments
Can you say more what you're wanting to do with this API?
|
I'm writing a project compiling wasm into EVM bytecode, wanna the 100% features of I'm using the winch API instead now but it would be best if I can use the API provided in |
OK, it's still not totally clear to me how the pieces fit together there. You are compiling Wasm to some target: does that mean that you have ported all of Wasmtime? Or instead are you mostly using the Cranelift pipeline (is this what you mean by "wanna the 100% features of cranelift"?) and getting at it via Wasmtime APIs? What is "EVM bytecode"? Have you ported Cranelift to this as well? (Out-of-tree Cranelift backends are another somewhat unsupported case, though we've had discussions about this one before at least.) The standard and supported way to use Cranelift to compile Wasm is to use |
Thank you for your support! just started to learn cranelift yesterday and feeling it is really helpful for expanding the usages of WASM!
hmmm, as I learnt from the code, I want to translate wasm to the binary code of a virtual machine, if it is possible to use cranelift to make it high quality and efficient? From the docs of
I'm confused why it just does the in-memory form job but not to cranelift IR directly? From my intuition,
nope, I just need the part wasm -> cranelift IR with optimization
for example, the stack limit check in wasmtime-cranelift
nope, I don't need wasmtime API and don't need to run the wasm in wasmtime or any other wasm runtimes
Just the binary format for a virtual machine
I'm using |
OK, I see the confusion here: Instead,
Maybe; it depends what sort of translation you want. Cranelift is an optimizing compiler, so if you want the Wasm -> custom bytecode translation to do optimizations, you'll for sure get that. However it also makes a bunch of assumptions about the target architecture: it's really meant for "real hardware" ISAs like x86 or aarch64, and porting it to emit a custom bytecode may or may not be easy, depending on the bytecode's design. For example, Cranelift uses a register allocator and assumes that the target ISA has a fixed number of physical registers. If your bytecode is stack-based rather than register-based, that may be a problem. Porting Cranelift is also not easy (no compiler is really super-easy to retarget; "real ISAs" tend to be large). The initial PR to add support for RISC-V, our latest addition (#4271), was 21k lines of code.
OK, yeah, given the above, using I'll make a note on terminology here too: you need some "runtime" for the Wasm specifically, on top of your custom bytecode VM's runtime. In this context, "runtime" means support for Wasm semantics and state: for example, handling Wasm memories and tables. It could be a very simple mapping, but somehow you need to decide what a "memory load" or "table set" op becomes, and this is what you provide in your "hooks" to
I'm not sure I understand what you're doing here: |
yeah, this is what I want! and the compiler time doesn't matter to my project!
Sadly it's stack-based...but while my target vm's instructions are super easy, I'll find it out if it is possible and necessary soon!
got you now, so what I can do is learning from the implementation of
I just implemented the thank you for your patient explanation @cfallin, I'm closing this issue since ur right and now I know what to do next! |
@cfallin ur totally correct xD, I have to write my compiler on my own now since my target vm is stack-based... but btw if there is any public methods in cranelift that I can re-use for building an optimizing compiler for wasm like cranelift but to stack-based vm target implementation, I'd be really grateful if you can point me out ; ) |
Feature
wasmtime-cranelift only has 1 public function
builder()
which is really strange...https://docs.rs/wasmtime-cranelift/latest/wasmtime_cranelift
at least make
wasmtime-cranelift::Builder
publicBenefit
developers can use customized Isa to work with
wasmtime-cranelift
Implementation
based on https://github.com/bytecodealliance/wasmtime/blob/main/crates/cranelift/src/builder.rs#L17
The text was updated successfully, but these errors were encountered: