Remove structopt dependency from LLVM

This commit is contained in:
Syrus
2019-08-08 19:42:41 -07:00
parent 27d8506a46
commit d39d4b5f6d
3 changed files with 35 additions and 16 deletions

View File

@ -11,9 +11,7 @@ wasmparser = "0.35.1"
smallvec = "0.6.10" smallvec = "0.6.10"
goblin = "0.0.24" goblin = "0.0.24"
libc = "0.2.60" libc = "0.2.60"
nix = "0.14.1"
capstone = { version = "0.6.0", optional = true } capstone = { version = "0.6.0", optional = true }
structopt = "0.2.18"
[dependencies.inkwell] [dependencies.inkwell]
git = "https://github.com/wasmerio/inkwell" git = "https://github.com/wasmerio/inkwell"
@ -21,6 +19,9 @@ branch = "llvm8-0"
default-features = false default-features = false
features = ["llvm8-0", "target-x86"] features = ["llvm8-0", "target-x86"]
[target.'cfg(unix)'.dependencies]
nix = "0.14.1"
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.7", features = ["memoryapi"] } winapi = { version = "0.3.7", features = ["memoryapi"] }

View File

@ -17,7 +17,6 @@ mod structs;
mod trampolines; mod trampolines;
use std::path::PathBuf; use std::path::PathBuf;
use structopt::StructOpt;
pub use code::LLVMFunctionCodeGenerator as FunctionCodeGenerator; pub use code::LLVMFunctionCodeGenerator as FunctionCodeGenerator;
pub use code::LLVMModuleCodeGenerator as ModuleCodeGenerator; pub use code::LLVMModuleCodeGenerator as ModuleCodeGenerator;
@ -31,23 +30,20 @@ pub type LLVMCompiler = SimpleStreamingCompilerGen<
code::CodegenError, code::CodegenError,
>; >;
#[derive(Debug, StructOpt, Clone)] #[derive(Debug, Clone)]
/// LLVM backend flags. /// LLVM backend flags.
pub struct CLIOptions { pub struct LLVMOptions {
/// Emit LLVM IR before optimization pipeline. /// Emit LLVM IR before optimization pipeline.
#[structopt(long = "backend-llvm-pre-opt-ir", parse(from_os_str))] pub pre_opt_ir: Option<PathBuf>,
pre_opt_ir: Option<PathBuf>,
/// Emit LLVM IR after optimization pipeline. /// Emit LLVM IR after optimization pipeline.
#[structopt(long = "backend-llvm-post-opt-ir", parse(from_os_str))] pub post_opt_ir: Option<PathBuf>,
post_opt_ir: Option<PathBuf>,
/// Emit LLVM generated native code object file. /// Emit LLVM generated native code object file.
#[structopt(long = "backend-llvm-object-file", parse(from_os_str))] pub obj_file: Option<PathBuf>,
obj_file: Option<PathBuf>,
} }
pub static mut GLOBAL_OPTIONS: CLIOptions = CLIOptions { pub static mut GLOBAL_OPTIONS: LLVMOptions = LLVMOptions {
pre_opt_ir: None, pre_opt_ir: None,
post_opt_ir: None, post_opt_ir: None,
obj_file: None, obj_file: None,

View File

@ -21,7 +21,7 @@ use structopt::StructOpt;
use wasmer::*; use wasmer::*;
use wasmer_clif_backend::CraneliftCompiler; use wasmer_clif_backend::CraneliftCompiler;
#[cfg(feature = "backend-llvm")] #[cfg(feature = "backend-llvm")]
use wasmer_llvm_backend::LLVMCompiler; use wasmer_llvm_backend::{LLVMCompiler, LLVMOptions};
use wasmer_runtime::{ use wasmer_runtime::{
cache::{Cache as BaseCache, FileSystemCache, WasmHash}, cache::{Cache as BaseCache, FileSystemCache, WasmHash},
Func, Value, VERSION, Func, Value, VERSION,
@ -88,6 +88,23 @@ struct PrestandardFeatures {
all: bool, all: bool,
} }
#[cfg(feature = "backend-llvm")]
#[derive(Debug, StructOpt, Clone)]
/// LLVM backend flags.
pub struct LLVMCLIOptions {
/// Emit LLVM IR before optimization pipeline.
#[structopt(long = "llvm-pre-opt-ir", parse(from_os_str))]
pre_opt_ir: Option<PathBuf>,
/// Emit LLVM IR after optimization pipeline.
#[structopt(long = "llvm-post-opt-ir", parse(from_os_str))]
post_opt_ir: Option<PathBuf>,
/// Emit LLVM generated native code object file.
#[structopt(long = "backend-llvm-object-file", parse(from_os_str))]
obj_file: Option<PathBuf>,
}
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
struct Run { struct Run {
// Disable the cache // Disable the cache
@ -157,7 +174,7 @@ struct Run {
#[cfg(feature = "backend-llvm")] #[cfg(feature = "backend-llvm")]
#[structopt(flatten)] #[structopt(flatten)]
backend_llvm_options: wasmer_llvm_backend::CLIOptions, backend_llvm_options: LLVMCLIOptions,
#[structopt(flatten)] #[structopt(flatten)]
features: PrestandardFeatures, features: PrestandardFeatures,
@ -363,8 +380,13 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
#[cfg(feature = "backend-llvm")] #[cfg(feature = "backend-llvm")]
{ {
if options.backend == Backend::LLVM { if options.backend == Backend::LLVM {
let options = options.backend_llvm_options.clone();
unsafe { unsafe {
wasmer_llvm_backend::GLOBAL_OPTIONS = options.backend_llvm_options.clone(); wasmer_llvm_backend::GLOBAL_OPTIONS = LLVMOptions {
pre_opt_ir: options.pre_opt_ir,
post_opt_ir: options.post_opt_ir,
obj_file: options.obj_file,
}
} }
} }
} }
@ -501,7 +523,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
let index = instance let index = instance
.resolve_func("_start") .resolve_func("_start")
.expect("The loader requires a _start function to be present in the module"); .expect("The loader requires a _start function to be present in the module");
let mut ins: Box<LoadedInstance<Error = String>> = match loader { let mut ins: Box<dyn LoadedInstance<Error = String>> = match loader {
LoaderName::Local => Box::new( LoaderName::Local => Box::new(
instance instance
.load(LocalLoader) .load(LocalLoader)