Stream: general

Topic: main function in IR


view this post on Zulip Nils Martel (Jun 18 2020 at 20:29):

Hello there.
I'm a complete noob, hope you don't mind.
I want to learn IR by programming in it directly. Is this possible?

For example, how would reproduce this exact c programm in IR?

int main() { return 1; }

and how would one compile it?

view this post on Zulip Andrew Brown (Jun 18 2020 at 20:39):

Maybe:

function %main() -> i32 {
 block0:
 v0 = iconst.i32 1
 return v0
}

view this post on Zulip Andrew Brown (Jun 18 2020 at 20:41):

If you stick that in a test run filetest you should be able to run that with clif-util: https://github.com/bytecodealliance/wasmtime/blob/master/cranelift/docs/testing.md#test-run

Standalone JIT-style runtime for WebAssembly, using Cranelift - bytecodealliance/wasmtime

view this post on Zulip Andrew Brown (Jun 18 2020 at 20:42):

The easiest way to run that is likely: cargo run -p cranelift-tools -- run [options, see --help] scratch.clif

view this post on Zulip Andrew Brown (Jun 18 2020 at 20:43):

Oh, and you asked how to compile it: cargo run -p cranelift-tools -- compile [options, see --help] scratch.clif

view this post on Zulip Nils Martel (Jun 19 2020 at 06:32):

@Andrew Brown your reply came insanely fast and it's perfect. Thanks a dozen!

view this post on Zulip Nils Martel (Jun 19 2020 at 08:20):

Do you happen to know in which directory of the wasmtime repo I have to be in, to issue this command?

view this post on Zulip Joey Gouly (Jun 19 2020 at 09:24):

Just the main directory

view this post on Zulip Nils Martel (Jun 19 2020 at 11:06):

I see. While I've tried to get this to work, I ran into the error message

error: failed to read `/Users/nilsmartel/Development/Repositories/wasmtime/crates/wasi-common/WASI/tools/witx/Cargo.toml`

Caused by:
  No such file or directory (os error 2)

Which seems to be strange, since I have the current master pulled. Do you happen to know a way to circumvent this?

(command issued was just cargo run -p cranelift-tools)

view this post on Zulip Joey Gouly (Jun 19 2020 at 12:02):

git submodule update --init

view this post on Zulip Nils Martel (Jun 19 2020 at 14:06):

that was awesome, thank you Joey!


Last updated: Dec 23 2024 at 12:05 UTC