mirror of
https://github.com/fluencelabs/wasmer
synced 2025-07-18 17:11:56 +00:00
Merge branch 'master' into feature/debug-prototype2
This commit is contained in:
@@ -37,7 +37,7 @@ use wasmer_runtime_core::{
|
||||
codegen::*,
|
||||
memory::MemoryType,
|
||||
module::{ModuleInfo, ModuleInner},
|
||||
parse::wp_type_to_type,
|
||||
parse::{wp_type_to_type, LoadError},
|
||||
structures::{Map, TypedIndex},
|
||||
types::{
|
||||
FuncIndex, FuncSig, GlobalIndex, LocalOrImport, MemoryIndex, SigIndex, TableIndex, Type,
|
||||
@@ -670,7 +670,7 @@ fn resolve_memory_ptr<'ctx>(
|
||||
memarg: &MemoryImmediate,
|
||||
ptr_ty: PointerType<'ctx>,
|
||||
value_size: usize,
|
||||
) -> Result<PointerValue<'ctx>, BinaryReaderError> {
|
||||
) -> Result<PointerValue<'ctx>, CodegenError> {
|
||||
// Look up the memory base (as pointer) and bounds (as unsigned integer).
|
||||
let memory_cache = ctx.memory(MemoryIndex::new(0), intrinsics, module.clone());
|
||||
let (mem_base, mem_bound, minimum, _maximum) = match memory_cache {
|
||||
@@ -958,7 +958,6 @@ pub struct LLVMModuleCodeGenerator<'ctx> {
|
||||
intrinsics: Option<Intrinsics<'ctx>>,
|
||||
functions: Vec<LLVMFunctionCodeGenerator<'ctx>>,
|
||||
signatures: Map<SigIndex, FunctionType<'ctx>>,
|
||||
signatures_raw: Map<SigIndex, FuncSig>,
|
||||
function_signatures: Option<Arc<Map<FuncIndex, SigIndex>>>,
|
||||
llvm_functions: Rc<RefCell<HashMap<FuncIndex, FunctionValue<'ctx>>>>,
|
||||
func_import_count: usize,
|
||||
@@ -1206,9 +1205,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
|
||||
* https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#control-flow-instructions
|
||||
***************************/
|
||||
Operator::Block { ty } => {
|
||||
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
|
||||
message: "not currently in a block",
|
||||
offset: -1isize as usize,
|
||||
let current_block = builder.get_insert_block().ok_or(CodegenError {
|
||||
message: "not currently in a block".to_string(),
|
||||
})?;
|
||||
|
||||
let end_block = context.append_basic_block(function, "end");
|
||||
@@ -1282,9 +1280,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
|
||||
Operator::Br { relative_depth } => {
|
||||
let frame = state.frame_at_depth(relative_depth)?;
|
||||
|
||||
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
|
||||
message: "not currently in a block",
|
||||
offset: -1isize as usize,
|
||||
let current_block = builder.get_insert_block().ok_or(CodegenError {
|
||||
message: "not currently in a block".to_string(),
|
||||
})?;
|
||||
|
||||
let value_len = if frame.is_loop() {
|
||||
@@ -1314,9 +1311,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
|
||||
let cond = state.pop1()?;
|
||||
let frame = state.frame_at_depth(relative_depth)?;
|
||||
|
||||
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
|
||||
message: "not currently in a block",
|
||||
offset: -1isize as usize,
|
||||
let current_block = builder.get_insert_block().ok_or(CodegenError {
|
||||
message: "not currently in a block".to_string(),
|
||||
})?;
|
||||
|
||||
let value_len = if frame.is_loop() {
|
||||
@@ -1346,9 +1342,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
|
||||
builder.position_at_end(&else_block);
|
||||
}
|
||||
Operator::BrTable { ref table } => {
|
||||
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
|
||||
message: "not currently in a block",
|
||||
offset: -1isize as usize,
|
||||
let current_block = builder.get_insert_block().ok_or(CodegenError {
|
||||
message: "not currently in a block".to_string(),
|
||||
})?;
|
||||
|
||||
let (label_depths, default_depth) = table.read_table()?;
|
||||
@@ -1372,7 +1367,7 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(case_index, &depth)| {
|
||||
let frame_result: Result<&ControlFrame, BinaryReaderError> =
|
||||
let frame_result: Result<&ControlFrame, CodegenError> =
|
||||
state.frame_at_depth(depth);
|
||||
let frame = match frame_result {
|
||||
Ok(v) => v,
|
||||
@@ -1396,9 +1391,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
|
||||
state.reachable = false;
|
||||
}
|
||||
Operator::If { ty } => {
|
||||
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
|
||||
message: "not currently in a block",
|
||||
offset: -1isize as usize,
|
||||
let current_block = builder.get_insert_block().ok_or(CodegenError {
|
||||
message: "not currently in a block".to_string(),
|
||||
})?;
|
||||
let if_then_block = context.append_basic_block(function, "if_then");
|
||||
let if_else_block = context.append_basic_block(function, "if_else");
|
||||
@@ -1437,9 +1431,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
|
||||
Operator::Else => {
|
||||
if state.reachable {
|
||||
let frame = state.frame_at_depth(0)?;
|
||||
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
|
||||
message: "not currently in a block",
|
||||
offset: -1isize as usize,
|
||||
let current_block = builder.get_insert_block().ok_or(CodegenError {
|
||||
message: "not currently in a block".to_string(),
|
||||
})?;
|
||||
|
||||
for phi in frame.phis().to_vec().iter().rev() {
|
||||
@@ -1471,9 +1464,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
|
||||
|
||||
Operator::End => {
|
||||
let frame = state.pop_frame()?;
|
||||
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
|
||||
message: "not currently in a block",
|
||||
offset: -1isize as usize,
|
||||
let current_block = builder.get_insert_block().ok_or(CodegenError {
|
||||
message: "not currently in a block".to_string(),
|
||||
})?;
|
||||
|
||||
if state.reachable {
|
||||
@@ -1530,9 +1522,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
|
||||
}
|
||||
}
|
||||
Operator::Return => {
|
||||
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
|
||||
message: "not currently in a block",
|
||||
offset: -1isize as usize,
|
||||
let current_block = builder.get_insert_block().ok_or(CodegenError {
|
||||
message: "not currently in a block".to_string(),
|
||||
})?;
|
||||
|
||||
let frame = state.outermost_frame()?;
|
||||
@@ -8617,6 +8608,14 @@ impl From<BinaryReaderError> for CodegenError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LoadError> for CodegenError {
|
||||
fn from(other: LoadError) -> CodegenError {
|
||||
CodegenError {
|
||||
message: format!("{:?}", other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for LLVMModuleCodeGenerator<'_> {
|
||||
fn drop(&mut self) {
|
||||
// Ensure that all members of the context are dropped before we drop the context.
|
||||
@@ -8716,7 +8715,6 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
||||
module: ManuallyDrop::new(Rc::new(RefCell::new(module))),
|
||||
functions: vec![],
|
||||
signatures: Map::new(),
|
||||
signatures_raw: Map::new(),
|
||||
function_signatures: None,
|
||||
llvm_functions: Rc::new(RefCell::new(HashMap::new())),
|
||||
func_import_count: 0,
|
||||
@@ -8738,7 +8736,7 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
||||
|
||||
fn next_function(
|
||||
&mut self,
|
||||
_module_info: Arc<RwLock<ModuleInfo>>,
|
||||
module_info: Arc<RwLock<ModuleInfo>>,
|
||||
_loc: WasmSpan,
|
||||
) -> Result<&mut LLVMFunctionCodeGenerator<'ctx>, CodegenError> {
|
||||
// Creates a new function and returns the function-scope code generator for it.
|
||||
@@ -8757,7 +8755,7 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
||||
|
||||
let func_index = FuncIndex::new(self.func_import_count + self.functions.len());
|
||||
let sig_id = self.function_signatures.as_ref().unwrap()[func_index];
|
||||
let func_sig = self.signatures_raw[sig_id].clone();
|
||||
let func_sig = module_info.read().unwrap().signatures[sig_id].clone();
|
||||
|
||||
let function = &self.llvm_functions.borrow_mut()[&func_index];
|
||||
function.set_personality_function(*self.personality_func);
|
||||
@@ -8965,7 +8963,6 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
self.signatures_raw = signatures.clone();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user