• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..04-Jun-2020-

bforest/H04-Jun-2020-3,8412,748

codegen/H04-Jun-2020-98,87274,046

docs/H03-May-2022-2,0161,510

entity/H04-Jun-2020-3,0982,232

faerie/H04-Jun-2020-829669

filetests/H04-Jun-2020-33,48028,450

frontend/H04-Jun-2020-3,7002,575

interpreter/H04-Jun-2020-844678

media/H03-May-2022-

module/H04-Jun-2020-1,5381,136

native/H04-Jun-2020-394330

object/H04-Jun-2020-899754

peepmatic/H04-Jun-2020-12,7869,538

preopt/H04-Jun-2020-557464

reader/H04-Jun-2020-5,8274,552

serde/H04-Jun-2020-1,3061,200

simplejit/H04-Jun-2020-1,5431,216

src/H04-Jun-2020-2,5902,150

tests/H04-Jun-2020-1,9981,820

umbrella/H04-Jun-2020-301246

wasm/H04-Jun-2020-5,8824,527

wasmtests/H03-May-2022-67,53167,458

Cargo.tomlH A D04-Jun-20201.9 KiB5248

README.mdH A D04-Jun-20206 KiB169125

rustc.mdH A D04-Jun-20204.1 KiB7466

spidermonkey.mdH A D04-Jun-20201.7 KiB4130

README.md

1Cranelift Code Generator
2========================
3
4**A [Bytecode Alliance][BA] project**
5
6Cranelift is a low-level retargetable code generator. It translates a
7[target-independent intermediate representation](docs/ir.md)
8into executable machine code.
9
10[BA]: https://bytecodealliance.org/
11[![Build Status](https://github.com/bytecodealliance/wasmtime/workflows/CI/badge.svg)](https://github.com/bytecodealliance/wasmtime/actions)
12[![Fuzzit Status](https://app.fuzzit.dev/badge?org_id=bytecodealliance)](https://app.fuzzit.dev/orgs/bytecodealliance/dashboard)
13[![Chat](https://img.shields.io/badge/chat-zulip-brightgreen.svg)](https://bytecodealliance.zulipchat.com/#narrow/stream/217117-cranelift/topic/general)
14![Minimum rustc 1.37](https://img.shields.io/badge/rustc-1.37+-green.svg)
15[![Documentation Status](https://docs.rs/cranelift/badge.svg)](https://docs.rs/cranelift)
16
17For more information, see [the documentation](docs/index.md).
18
19For an example of how to use the JIT, see the [SimpleJIT Demo], which
20implements a toy language.
21
22[SimpleJIT Demo]: https://github.com/bytecodealliance/simplejit-demo
23
24For an example of how to use Cranelift to run WebAssembly code, see
25[Wasmtime], which implements a standalone, embeddable, VM using Cranelift.
26
27[Wasmtime]: https://github.com/bytecodealliance/wasmtime
28
29Status
30------
31
32Cranelift currently supports enough functionality to run a wide variety
33of programs, including all the functionality needed to execute
34WebAssembly MVP functions, although it needs to be used within an
35external WebAssembly embedding to be part of a complete WebAssembly
36implementation.
37
38The x86-64 backend is currently the most complete and stable; other
39architectures are in various stages of development. Cranelift currently
40supports both the System V AMD64 ABI calling convention used on many
41platforms and the Windows x64 calling convention. The performance
42of code produced by Cranelift is not yet impressive, though we have plans
43to fix that.
44
45The core codegen crates have minimal dependencies, support no\_std mode
46(see below), and do not require any host floating-point support, and
47do not use callstack recursion.
48
49Cranelift does not yet perform mitigations for Spectre or related
50security issues, though it may do so in the future. It does not
51currently make any security-relevant instruction timing guarantees. It
52has seen a fair amount of testing and fuzzing, although more work is
53needed before it would be ready for a production use case.
54
55Cranelift's APIs are not yet stable.
56
57Cranelift currently requires Rust 1.37 or later to build.
58
59Contributing
60------------
61
62If you're interested in contributing to Cranelift: thank you! We have a
63[contributing guide] which will help you getting involved in the Cranelift
64project.
65
66[contributing guide](https://bytecodealliance.github.io/wasmtime/contributing.html)
67
68Planned uses
69------------
70
71Cranelift is designed to be a code generator for WebAssembly, but it is
72general enough to be useful elsewhere too. The initial planned uses that
73affected its design are:
74
75 - [WebAssembly compiler for the SpiderMonkey engine in
76    Firefox](spidermonkey.md#phase-1-webassembly).
77 - [Backend for the IonMonkey JavaScript JIT compiler in
78    Firefox](spidermonkey.md#phase-2-ionmonkey).
79 - [Debug build backend for the Rust compiler](rustc.md).
80 - [Wasmtime non-Web wasm engine](https://github.com/bytecodealliance/wasmtime).
81
82Building Cranelift
83------------------
84
85Cranelift uses a [conventional Cargo build
86process](https://doc.rust-lang.org/cargo/guide/working-on-an-existing-project.html).
87
88Cranelift consists of a collection of crates, and uses a [Cargo
89Workspace](https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html),
90so for some cargo commands, such as `cargo test`, the `--all` is needed
91to tell cargo to visit all of the crates.
92
93`test-all.sh` at the top level is a script which runs all the cargo
94tests and also performs code format, lint, and documentation checks.
95
96<details>
97<summary>Building with no_std</summary>
98
99The following crates support \`no\_std\`, although they do depend on liballoc:
100 - cranelift-entity
101 - cranelift-bforest
102 - cranelift-codegen
103 - cranelift-frontend
104 - cranelift-native
105 - cranelift-wasm
106 - cranelift-module
107 - cranelift-preopt
108 - cranelift
109
110To use no\_std mode, disable the std feature and enable the core
111feature. This currently requires nightly rust.
112
113For example, to build \`cranelift-codegen\`:
114
115``` {.sourceCode .sh}
116cd cranelift-codegen
117cargo build --no-default-features --features core
118```
119
120Or, when using cranelift-codegen as a dependency (in Cargo.toml):
121
122``` {.sourceCode .}
123[dependency.cranelift-codegen]
124...
125default-features = false
126features = ["core"]
127```
128
129no\_std support is currently "best effort". We won't try to break it,
130and we'll accept patches fixing problems, however we don't expect all
131developers to build and test no\_std when submitting patches.
132Accordingly, the ./test-all.sh script does not test no\_std.
133
134There is a separate ./test-no\_std.sh script that tests the no\_std
135support in packages which support it.
136
137It's important to note that cranelift still needs liballoc to compile.
138Thus, whatever environment is used must implement an allocator.
139
140Also, to allow the use of HashMaps with no\_std, an external crate
141called hashmap\_core is pulled in (via the core feature). This is mostly
142the same as std::collections::HashMap, except that it doesn't have DOS
143protection. Just something to think about.
144
145</details>
146
147<details>
148<summary>Log configuration</summary>
149
150Cranelift uses the `log` crate to log messages at various levels. It doesn't
151specify any maximal logging level, so embedders can choose what it should be;
152however, this can have an impact of Cranelift's code size. You can use `log`
153features to reduce the maximum logging level. For instance if you want to limit
154the level of logging to `warn` messages and above in release mode:
155
156```
157[dependency.log]
158...
159features = ["release_max_level_warn"]
160```
161</details>
162
163Editor Support
164--------------
165
166Editor support for working with Cranelift IR (clif) files:
167
168 - Vim: https://github.com/bytecodealliance/cranelift.vim
169