Use the target-lexicon crate.
This switches from a custom list of architectures to use the target-lexicon crate. - "set is_64bit=1; isa x86" is replaced with "target x86_64", and similar for other architectures, and the `is_64bit` flag is removed entirely. - The `is_compressed` flag is removed too; it's no longer being used to control REX prefixes on x86-64, ARM and Thumb are separate architectures in target-lexicon, and we can figure out how to select RISC-V compressed encodings when we're ready.
This commit is contained in:
@@ -8,6 +8,7 @@ use environ::{FuncEnvironment, GlobalValue, ModuleEnvironment, WasmResult};
|
||||
use func_translator::FuncTranslator;
|
||||
use std::string::String;
|
||||
use std::vec::Vec;
|
||||
use target_lexicon::Triple;
|
||||
use translation_utils::{FunctionIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex,
|
||||
Table, TableIndex};
|
||||
use wasmparser;
|
||||
@@ -39,6 +40,9 @@ impl<T> Exportable<T> {
|
||||
/// `DummyEnvironment` to allow it to be borrowed separately from the
|
||||
/// `FuncTranslator` field.
|
||||
pub struct DummyModuleInfo {
|
||||
/// Target description.
|
||||
pub triple: Triple,
|
||||
|
||||
/// Compilation setting flags.
|
||||
pub flags: settings::Flags,
|
||||
|
||||
@@ -69,8 +73,9 @@ pub struct DummyModuleInfo {
|
||||
|
||||
impl DummyModuleInfo {
|
||||
/// Allocates the data structures with the given flags.
|
||||
pub fn with_flags(flags: settings::Flags) -> Self {
|
||||
pub fn with_triple_flags(triple: Triple, flags: settings::Flags) -> Self {
|
||||
Self {
|
||||
triple,
|
||||
flags,
|
||||
signatures: Vec::new(),
|
||||
imported_funcs: Vec::new(),
|
||||
@@ -100,14 +105,14 @@ pub struct DummyEnvironment {
|
||||
|
||||
impl DummyEnvironment {
|
||||
/// Allocates the data structures with default flags.
|
||||
pub fn default() -> Self {
|
||||
Self::with_flags(settings::Flags::new(settings::builder()))
|
||||
pub fn with_triple(triple: Triple) -> Self {
|
||||
Self::with_triple_flags(triple, settings::Flags::new(settings::builder()))
|
||||
}
|
||||
|
||||
/// Allocates the data structures with the given flags.
|
||||
pub fn with_flags(flags: settings::Flags) -> Self {
|
||||
pub fn with_triple_flags(triple: Triple, flags: settings::Flags) -> Self {
|
||||
Self {
|
||||
info: DummyModuleInfo::with_flags(flags),
|
||||
info: DummyModuleInfo::with_triple_flags(triple, flags),
|
||||
trans: FuncTranslator::new(),
|
||||
func_bytecode_sizes: Vec::new(),
|
||||
}
|
||||
@@ -143,6 +148,10 @@ impl<'dummy_environment> DummyFuncEnvironment<'dummy_environment> {
|
||||
}
|
||||
|
||||
impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environment> {
|
||||
fn triple(&self) -> &Triple {
|
||||
&self.mod_info.triple
|
||||
}
|
||||
|
||||
fn flags(&self) -> &settings::Flags {
|
||||
&self.mod_info.flags
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use cretonne_codegen::cursor::FuncCursor;
|
||||
use cretonne_codegen::ir::{self, InstBuilder};
|
||||
use cretonne_codegen::settings::Flags;
|
||||
use std::vec::Vec;
|
||||
use target_lexicon::Triple;
|
||||
use translation_utils::{FunctionIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex,
|
||||
Table, TableIndex};
|
||||
use wasmparser::BinaryReaderError;
|
||||
@@ -74,6 +75,9 @@ pub type WasmResult<T> = Result<T, WasmError>;
|
||||
/// IR. The function environment provides information about the WebAssembly module as well as the
|
||||
/// runtime environment.
|
||||
pub trait FuncEnvironment {
|
||||
/// Get the triple for the current compilation.
|
||||
fn triple(&self) -> &Triple;
|
||||
|
||||
/// Get the flags for the current compilation.
|
||||
fn flags(&self) -> &Flags;
|
||||
|
||||
@@ -81,11 +85,7 @@ pub trait FuncEnvironment {
|
||||
///
|
||||
/// This returns `I64` for 64-bit architectures and `I32` for 32-bit architectures.
|
||||
fn native_pointer(&self) -> ir::Type {
|
||||
if self.flags().is_64bit() {
|
||||
ir::types::I64
|
||||
} else {
|
||||
ir::types::I32
|
||||
}
|
||||
ir::Type::int(u16::from(self.triple().pointer_width().unwrap().bits())).unwrap()
|
||||
}
|
||||
|
||||
/// Set up the necessary preamble definitions in `func` to access the global variable
|
||||
|
||||
@@ -237,6 +237,7 @@ mod tests {
|
||||
use cretonne_codegen::ir::types::I32;
|
||||
use cretonne_codegen::{ir, Context};
|
||||
use environ::{DummyEnvironment, FuncEnvironment};
|
||||
use target_lexicon::Triple;
|
||||
|
||||
#[test]
|
||||
fn small1() {
|
||||
@@ -256,7 +257,7 @@ mod tests {
|
||||
];
|
||||
|
||||
let mut trans = FuncTranslator::new();
|
||||
let runtime = DummyEnvironment::default();
|
||||
let runtime = DummyEnvironment::with_triple(Triple::default());
|
||||
let mut ctx = Context::new();
|
||||
|
||||
ctx.func.name = ir::ExternalName::testcase("small1");
|
||||
@@ -289,7 +290,7 @@ mod tests {
|
||||
];
|
||||
|
||||
let mut trans = FuncTranslator::new();
|
||||
let runtime = DummyEnvironment::default();
|
||||
let runtime = DummyEnvironment::with_triple(Triple::default());
|
||||
let mut ctx = Context::new();
|
||||
|
||||
ctx.func.name = ir::ExternalName::testcase("small2");
|
||||
@@ -335,7 +336,7 @@ mod tests {
|
||||
];
|
||||
|
||||
let mut trans = FuncTranslator::new();
|
||||
let runtime = DummyEnvironment::default();
|
||||
let runtime = DummyEnvironment::with_triple(Triple::default());
|
||||
let mut ctx = Context::new();
|
||||
|
||||
ctx.func.name = ir::ExternalName::testcase("infloop");
|
||||
|
||||
@@ -34,6 +34,7 @@ extern crate hashmap_core;
|
||||
#[macro_use(dbg)]
|
||||
extern crate cretonne_codegen;
|
||||
extern crate cretonne_frontend;
|
||||
extern crate target_lexicon;
|
||||
extern crate wasmparser;
|
||||
|
||||
extern crate failure;
|
||||
|
||||
Reference in New Issue
Block a user