Initial commit for support of custom sections.

This commit is contained in:
Nick Lewycky
2020-05-01 15:46:45 -07:00
parent 393f17ba29
commit 1227d50e9b
2 changed files with 78 additions and 21 deletions

View File

@ -39,14 +39,13 @@ use wasm_common::{
};
use wasmer_compiler::wasmparser::{self, BinaryReader, MemoryImmediate, Operator};
use wasmer_compiler::{
to_wasm_error, wasm_unsupported, CompileError, CompiledFunction, WasmResult,
};
use wasmer_compiler::{
CompiledFunctionUnwindInfo, FunctionAddressMap, FunctionBodyData, Relocation, RelocationKind,
RelocationTarget, SourceLoc,
to_wasm_error, wasm_unsupported, Addend, CodeOffset, CompileError, CompiledFunction,
CompiledFunctionUnwindInfo, CustomSection, FunctionAddressMap, FunctionBodyData, Relocation,
RelocationKind, RelocationTarget, SourceLoc, WasmResult,
};
use wasmer_runtime::libcalls::LibCall;
use wasmer_runtime::Module as WasmerCompilerModule;
use wasmer_runtime::{libcalls::LibCall, MemoryPlan, MemoryStyle, TablePlan};
use wasmer_runtime::{MemoryPlan, MemoryStyle, TablePlan};
// TODO: debugging
use std::fs;
@ -84,6 +83,14 @@ fn const_zero<'ctx>(ty: BasicTypeEnum<'ctx>) -> BasicValueEnum<'ctx> {
}
}
// Relocation against a per-function section.
pub struct LocalRelocation {
pub kind: RelocationKind,
pub local_section_index: u32,
pub offset: CodeOffset,
pub addend: Addend,
}
impl FuncTranslator {
pub fn new() -> Self {
Self {
@ -100,7 +107,7 @@ impl FuncTranslator {
memory_plans: &PrimaryMap<MemoryIndex, MemoryPlan>,
table_plans: &PrimaryMap<TableIndex, TablePlan>,
func_names: &SecondaryMap<FuncIndex, String>,
) -> Result<CompiledFunction, CompileError> {
) -> Result<(CompiledFunction, Vec<LocalRelocation>, Vec<CustomSection>), CompileError> {
let func_index = wasm_module.func_index(*func_index);
let func_name = func_names.get(func_index).unwrap();
let module_name = match wasm_module.name.as_ref() {
@ -363,14 +370,18 @@ impl FuncTranslator {
body_len: 0, // TODO
};
Ok(CompiledFunction {
address_map,
body: bytes,
jt_offsets: SecondaryMap::new(),
unwind_info: CompiledFunctionUnwindInfo::None,
relocations,
traps: vec![],
})
Ok((
CompiledFunction {
address_map,
body: bytes,
jt_offsets: SecondaryMap::new(),
unwind_info: CompiledFunctionUnwindInfo::None,
relocations,
traps: vec![],
},
vec![],
vec![],
))
}
}