Assorted fixes:

Fix creation of the target machine. Fix CPU features, architecture and target name.

Function names are not mandatory. Support unnamed functions.

Include parameters and local variables in the list of local variables for LLVMFunctionCodeGenerator.

Run the tests single-threaded, using a Mutex in the rayon code. This means that only the first error is real, subsequent errors are just picking up the panic across threads.

Add TODOs about attributes on vmctx.
This commit is contained in:
Nick Lewycky
2020-04-23 23:23:21 -07:00
parent 7951e9bc79
commit 56fe08ad00
4 changed files with 38 additions and 21 deletions

View File

@ -30,7 +30,7 @@ use smallvec::SmallVec;
use std::any::Any;
use crate::config::LLVMConfig;
use wasm_common::entity::{PrimaryMap, SecondaryMap};
use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap};
use wasm_common::{
FuncIndex, FuncType, GlobalIndex, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex, Type,
};
@ -94,7 +94,10 @@ impl FuncTranslator {
table_plans: &PrimaryMap<TableIndex, TablePlan>,
) -> Result<CompiledFunction, CompileError> {
let func_index = wasm_module.func_index(*func_index);
let func_name = wasm_module.func_names.get(&func_index).unwrap().as_str();
let func_name = match wasm_module.func_names.get(&func_index) {
None => format!("fn{}", func_index.index()).to_string(),
Some(func_name) => func_name.clone(),
};
let module_name = match wasm_module.name.as_ref() {
None => format!("<anonymous module> function {}", func_name),
Some(module_name) => format!("module {} function {}", module_name, func_name),
@ -113,8 +116,12 @@ impl FuncTranslator {
let intrinsics = Intrinsics::declare(&module, &self.ctx);
let func_type = func_type_to_llvm(&self.ctx, &intrinsics, wasm_fn_type);
let func = module.add_function(func_name, func_type, Some(Linkage::External));
let func = module.add_function(&func_name, func_type, Some(Linkage::External));
// TODO: mark vmctx align 16
// TODO: figure out how many bytes long vmctx is, and mark it dereferenceable. (no need to mark it nonnull once we do this.)
// TODO: mark vmctx nofree
func.set_personality_function(intrinsics.personality);
let entry = self.ctx.append_basic_block(func, "entry");
let start_of_code = self.ctx.append_basic_block(func, "start_of_code");
let return_ = self.ctx.append_basic_block(func, "return");
@ -136,20 +143,6 @@ impl FuncTranslator {
state.push_block(return_, phis);
builder.position_at_end(start_of_code);
let mut fcg = LLVMFunctionCodeGenerator {
context: &self.ctx,
builder,
intrinsics: &intrinsics,
state,
function: func,
locals: vec![],
ctx: CtxType::new(wasm_module, &func, &cache_builder),
unreachable_depth: 0,
memory_plans,
table_plans,
module: &module,
};
let mut reader =
BinaryReader::new_with_offset(function_body.data, function_body.module_offset);
@ -179,6 +172,23 @@ impl FuncTranslator {
locals.push(alloca);
}
let mut params_locals = params.clone();
params_locals.extend(locals.iter().cloned());
let mut fcg = LLVMFunctionCodeGenerator {
context: &self.ctx,
builder,
intrinsics: &intrinsics,
state,
function: func,
locals: params_locals,
ctx: CtxType::new(wasm_module, &func, &cache_builder),
unreachable_depth: 0,
memory_plans,
table_plans,
module: &module,
};
while fcg.state.has_control_frames() {
let pos = reader.current_position() as u32;
let op = reader.read_operator().map_err(to_wasm_error)?;