Skip to content

Commit

Permalink
update cranelift to current master (0.46.1)
Browse files Browse the repository at this point in the history
This is in preparation for adding an interface to customize machine-dependent features in
cranelift's codegen
  • Loading branch information
acfoltzer committed Oct 30, 2019
1 parent 927d21d commit 1337ed6
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 69 deletions.
88 changes: 44 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cranelift
2 changes: 1 addition & 1 deletion lucet-module/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = ["Lucet team <[email protected]>"]
edition = "2018"

[dependencies]
cranelift-entity = { path = "../cranelift/cranelift-entity", version = "0.44.0" }
cranelift-entity = { path = "../cranelift/cranelift-entity", version = "0.46.1" }
failure = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion lucet-validate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ path = "src/main.rs"
clap = "2"
failure = "0.1"
witx = { path = "../wasi/tools/witx", version = "0.3.0" }
cranelift-entity = { path = "../cranelift/cranelift-entity", version = "0.44.0" }
cranelift-entity = { path = "../cranelift/cranelift-entity", version = "0.46.1" }
wasmparser = "0.39.1"

[dev-dependencies]
Expand Down
14 changes: 7 additions & 7 deletions lucetc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ path = "src/main.rs"

[dependencies]
bincode = "1.1.4"
cranelift-codegen = { path = "../cranelift/cranelift-codegen", version = "0.44.0" }
cranelift-entity = { path = "../cranelift/cranelift-entity", version = "0.44.0" }
cranelift-native = { path = "../cranelift/cranelift-native", version = "0.44.0" }
cranelift-frontend = { path = "../cranelift/cranelift-frontend", version = "0.44.0" }
cranelift-module = { path = "../cranelift/cranelift-module", version = "0.44.0" }
cranelift-faerie = { path = "../cranelift/cranelift-faerie", version = "0.44.0" }
cranelift-wasm = { path = "../cranelift/cranelift-wasm", version = "0.44.0" }
cranelift-codegen = { path = "../cranelift/cranelift-codegen", version = "0.46.1" }
cranelift-entity = { path = "../cranelift/cranelift-entity", version = "0.46.1" }
cranelift-native = { path = "../cranelift/cranelift-native", version = "0.46.1" }
cranelift-frontend = { path = "../cranelift/cranelift-frontend", version = "0.46.1" }
cranelift-module = { path = "../cranelift/cranelift-module", version = "0.46.1" }
cranelift-faerie = { path = "../cranelift/cranelift-faerie", version = "0.46.1" }
cranelift-wasm = { path = "../cranelift/cranelift-wasm", version = "0.46.1" }
target-lexicon = "0.8.0"
lucet-module = { path = "../lucet-module", version = "0.3.1" }
lucet-validate = { path = "../lucet-validate", version = "0.3.1" }
Expand Down
35 changes: 26 additions & 9 deletions lucetc/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use cranelift_codegen::{
use cranelift_faerie::{FaerieBackend, FaerieBuilder, FaerieTrapCollection};
use cranelift_module::{Backend as ClifBackend, Module as ClifModule};
use cranelift_native;
use cranelift_wasm::{translate_module, FuncTranslator, WasmError};
use cranelift_wasm::{translate_module, FuncTranslator, ModuleTranslationState, WasmError};
use failure::{format_err, Fail, ResultExt};
use lucet_module::bindings::Bindings;
use lucet_module::{FunctionSpec, ModuleData, MODULE_DATA_SYM};
Expand Down Expand Up @@ -50,6 +50,7 @@ pub struct Compiler<'a> {
clif_module: ClifModule<FaerieBackend>,
opt_level: OptLevel,
count_instructions: bool,
module_translation_state: ModuleTranslationState,
}

impl<'a> Compiler<'a> {
Expand Down Expand Up @@ -84,12 +85,15 @@ impl<'a> Compiler<'a> {
.context(LucetcErrorKind::Validation)?;
}

translate_module(wasm_binary, &mut module_info).map_err(|e| match e {
WasmError::User(_) => e.context(LucetcErrorKind::Input),
WasmError::InvalidWebAssembly { .. } => e.context(LucetcErrorKind::Validation), // This will trigger once cranelift-wasm upgrades to a validating wasm parser.
WasmError::Unsupported { .. } => e.context(LucetcErrorKind::Unsupported),
WasmError::ImplLimitExceeded { .. } => e.context(LucetcErrorKind::TranslatingModule),
})?;
let module_translation_state =
translate_module(wasm_binary, &mut module_info).map_err(|e| match e {
WasmError::User(_) => e.context(LucetcErrorKind::Input),
WasmError::InvalidWebAssembly { .. } => e.context(LucetcErrorKind::Validation), // This will trigger once cranelift-wasm upgrades to a validating wasm parser.
WasmError::Unsupported { .. } => e.context(LucetcErrorKind::Unsupported),
WasmError::ImplLimitExceeded { .. } => {
e.context(LucetcErrorKind::TranslatingModule)
}
})?;

let libcalls = Box::new(move |libcall| match libcall {
ir::LibCall::Probestack => stack_probe::STACK_PROBE_SYM.to_owned(),
Expand Down Expand Up @@ -120,6 +124,7 @@ impl<'a> Compiler<'a> {
clif_module,
opt_level,
count_instructions,
module_translation_state,
})
}

Expand All @@ -137,7 +142,13 @@ impl<'a> Compiler<'a> {
clif_context.func.signature = func.signature.clone();

func_translator
.translate(code, *code_offset, &mut clif_context.func, &mut func_info)
.translate(
&self.module_translation_state,
code,
*code_offset,
&mut clif_context.func,
&mut func_info,
)
.map_err(|e| format_err!("in {}: {:?}", func.name.symbol(), e))
.context(LucetcErrorKind::FunctionTranslation)?;

Expand Down Expand Up @@ -192,7 +203,13 @@ impl<'a> Compiler<'a> {
clif_context.func.signature = func.signature.clone();

func_translator
.translate(code, *code_offset, &mut clif_context.func, &mut func_info)
.translate(
&self.module_translation_state,
code,
*code_offset,
&mut clif_context.func,
&mut func_info,
)
.map_err(|e| format_err!("in {}: {:?}", func.name.symbol(), e))
.context(LucetcErrorKind::FunctionTranslation)?;

Expand Down
6 changes: 3 additions & 3 deletions lucetc/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use cranelift_codegen::ir::{self, InstBuilder};
use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_frontend::FunctionBuilder;
use cranelift_wasm::{
FuncEnvironment, FuncIndex, GlobalIndex, GlobalVariable, MemoryIndex, SignatureIndex,
TableIndex, VisibleTranslationState, WasmError, WasmResult,
FuncEnvironment, FuncIndex, FuncTranslationState, GlobalIndex, GlobalVariable, MemoryIndex,
SignatureIndex, TableIndex, WasmError, WasmResult,
};
use lucet_module::InstanceRuntimeData;
use memoffset::offset_of;
Expand Down Expand Up @@ -496,7 +496,7 @@ impl<'a> FuncEnvironment for FuncInfo<'a> {
&mut self,
op: &Operator,
builder: &mut FunctionBuilder,
state: &VisibleTranslationState,
state: &FuncTranslationState,
) -> WasmResult<()> {
if self.count_instructions {
self.update_instruction_count_instrumentation(op, builder, state.reachable())?;
Expand Down
11 changes: 8 additions & 3 deletions lucetc/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use cranelift_codegen::entity::{entity_impl, EntityRef, PrimaryMap};
use cranelift_codegen::ir;
use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_wasm::{
FuncIndex, Global, GlobalIndex, Memory, MemoryIndex, ModuleEnvironment, SignatureIndex, Table,
TableElementType, TableIndex, WasmResult,
FuncIndex, Global, GlobalIndex, Memory, MemoryIndex, ModuleEnvironment, ModuleTranslationState,
SignatureIndex, Table, TableElementType, TableIndex, WasmResult,
};
use failure::ResultExt;
use lucet_module::UniqueSignatureIndex;
Expand Down Expand Up @@ -327,7 +327,12 @@ impl<'a> ModuleEnvironment<'a> for ModuleInfo<'a> {
Ok(())
}

fn define_function_body(&mut self, body_bytes: &'a [u8], body_offset: usize) -> WasmResult<()> {
fn define_function_body(
&mut self,
_module_translation_state: &ModuleTranslationState,
body_bytes: &'a [u8],
body_offset: usize,
) -> WasmResult<()> {
let func_index =
UniqueFuncIndex::new(self.imported_funcs.len() + self.function_bodies.len());
self.function_bodies
Expand Down

0 comments on commit 1337ed6

Please sign in to comment.