mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 21:58:20 +00:00
Connect trampoline code to trampoline module. Still unimplemented.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#![allow(unused_imports, dead_code)]
|
||||
|
||||
use crate::config::LLVMConfig;
|
||||
use crate::trampoline::FuncTrampoline;
|
||||
use crate::translator::FuncTranslator;
|
||||
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
||||
use wasm_common::entity::{EntityRef, PrimaryMap};
|
||||
@@ -85,11 +86,13 @@ impl Compiler for LLVMCompiler {
|
||||
|
||||
fn compile_wasm_trampolines(
|
||||
&self,
|
||||
_signatures: &[FuncType],
|
||||
signatures: &[FuncType],
|
||||
) -> Result<Vec<CompiledFunction>, CompileError> {
|
||||
// TODO: implement this
|
||||
Err(CompileError::Codegen(
|
||||
"Trampoline compilation not yet implemented.".to_string(),
|
||||
))
|
||||
signatures
|
||||
.par_iter()
|
||||
.map_init(FuncTrampoline::new, |func_trampoline, sig| {
|
||||
func_trampoline.trampoline(sig)
|
||||
})
|
||||
.collect::<Result<Vec<_>, CompileError>>()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,8 @@
|
||||
|
||||
mod compiler;
|
||||
mod config;
|
||||
mod trampoline;
|
||||
mod translator;
|
||||
// mod structs;
|
||||
// mod trampoline;
|
||||
|
||||
pub use crate::compiler::LLVMCompiler;
|
||||
pub use crate::config::{InkwellMemoryBuffer, InkwellModule, LLVMCallbacks, LLVMConfig};
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
mod wasm;
|
||||
|
||||
pub use self::wasm::FuncTrampoline;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::intrinsics::Intrinsics;
|
||||
use inkwell::{
|
||||
context::Context,
|
||||
module::{Linkage, Module},
|
||||
@@ -6,12 +5,29 @@ use inkwell::{
|
||||
values::FunctionValue,
|
||||
AddressSpace,
|
||||
};
|
||||
use wasmer_runtime_core::{
|
||||
module::ModuleInfo,
|
||||
structures::{SliceMap, TypedIndex},
|
||||
types::{FuncSig, SigIndex, Type},
|
||||
};
|
||||
use wasm_common::FuncType;
|
||||
use wasmer_compiler::{Compilation, CompileError, CompiledFunction, Compiler};
|
||||
|
||||
pub struct FuncTrampoline {
|
||||
ctx: Context,
|
||||
}
|
||||
|
||||
impl FuncTrampoline {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
ctx: Context::create(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn trampoline(&mut self, ty: &FuncType) -> Result<CompiledFunction, CompileError> {
|
||||
// TODO: implement this
|
||||
Err(CompileError::Codegen(
|
||||
"Trampoline compilation not yet implemented.".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn generate_trampolines<'ctx>(
|
||||
info: &ModuleInfo,
|
||||
signatures: &SliceMap<SigIndex, FunctionType<'ctx>>,
|
||||
@@ -117,3 +133,4 @@ fn generate_trampoline<'ctx>(
|
||||
builder.build_return(None);
|
||||
Ok(())
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -45,6 +45,10 @@ use wasmer_runtime::Module as WasmerCompilerModule;
|
||||
use wasmer_runtime::{MemoryPlan, MemoryStyle, TablePlan};
|
||||
use wasmparser::{BinaryReader, MemoryImmediate, Operator};
|
||||
|
||||
// TODO: debugging
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
|
||||
// TODO
|
||||
fn wptype_to_type(ty: wasmparser::Type) -> WasmResult<Type> {
|
||||
match ty {
|
||||
@@ -222,6 +226,9 @@ impl FuncTranslator {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: debugging
|
||||
//module.print_to_stderr();
|
||||
|
||||
// TODO: llvm-callbacks pre-opt-ir
|
||||
let pass_manager = PassManager::create(());
|
||||
|
||||
@@ -268,6 +275,13 @@ impl FuncTranslator {
|
||||
.write_to_memory_buffer(&mut module, FileType::Object)
|
||||
.unwrap();
|
||||
|
||||
let mem_buf_slice = memory_buffer.as_slice();
|
||||
let mut file = fs::File::create("/home/nicholas/x.o").unwrap();
|
||||
let mut pos = 0;
|
||||
while pos < mem_buf_slice.len() {
|
||||
pos += file.write(&mem_buf_slice[pos..]).unwrap();
|
||||
}
|
||||
|
||||
let object = memory_buffer.create_object_file().map_err(|()| {
|
||||
CompileError::Codegen("failed to create object file from llvm ir".to_string())
|
||||
})?;
|
||||
|
||||
Reference in New Issue
Block a user