lib/wasm works with no_std
This commit is contained in:
committed by
Dan Gohman
parent
299e8a9737
commit
66a150e67a
@@ -34,6 +34,9 @@ use std::collections::{HashMap, hash_map};
|
||||
use environ::{FuncEnvironment, GlobalValue};
|
||||
use std::{i32, u32};
|
||||
|
||||
// this is for no_std builds, but has no affect on regular builds
|
||||
use std::vec::Vec;
|
||||
|
||||
/// Translates wasm operators into Cretonne IL instructions. Returns `true` if it inserted
|
||||
/// a return.
|
||||
pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
|
||||
@@ -11,6 +11,10 @@ use cretonne::settings;
|
||||
use wasmparser;
|
||||
use std::error::Error;
|
||||
|
||||
// this is for no_std builds, but has no affect on regular builds
|
||||
use std::vec::Vec;
|
||||
use std::string::String;
|
||||
|
||||
/// Compute a `ir::ExternalName` for a given wasm function index.
|
||||
fn get_func_name(func_index: FunctionIndex) -> ir::ExternalName {
|
||||
ir::ExternalName::user(0, func_index as u32)
|
||||
|
||||
@@ -6,6 +6,10 @@ use cretonne::settings::Flags;
|
||||
use translation_utils::{SignatureIndex, FunctionIndex, TableIndex, GlobalIndex, MemoryIndex,
|
||||
Global, Table, Memory};
|
||||
|
||||
// this is for no_std builds, but has no affect on regular builds
|
||||
use std::vec::Vec;
|
||||
use std::string::String;
|
||||
|
||||
/// The value of a WebAssembly global variable.
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum GlobalValue {
|
||||
|
||||
@@ -9,8 +9,20 @@
|
||||
//!
|
||||
//! The main function of this module is [`translate_module`](fn.translate_module.html).
|
||||
|
||||
#![cfg_attr(feature = "no_std", no_std)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#![cfg_attr(feature = "no_std", feature(alloc))]
|
||||
|
||||
#[cfg(feature = "no_std")]
|
||||
#[macro_use]
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(feature = "no_std")]
|
||||
extern crate hashmap_core;
|
||||
#[cfg(feature = "no_std")]
|
||||
extern crate error_core;
|
||||
|
||||
extern crate wasmparser;
|
||||
extern crate cton_frontend;
|
||||
#[macro_use(dbg)]
|
||||
@@ -29,3 +41,16 @@ pub use module_translator::translate_module;
|
||||
pub use environ::{FuncEnvironment, ModuleEnvironment, DummyEnvironment, GlobalValue};
|
||||
pub use translation_utils::{FunctionIndex, GlobalIndex, TableIndex, MemoryIndex, SignatureIndex,
|
||||
Global, GlobalInit, Table, Memory};
|
||||
|
||||
#[cfg(feature = "no_std")]
|
||||
mod std {
|
||||
pub use alloc::vec;
|
||||
pub use alloc::string;
|
||||
pub use core::{u32, i32, str, cmp};
|
||||
pub mod collections {
|
||||
pub use hashmap_core::{HashMap, map as hash_map};
|
||||
}
|
||||
pub mod error {
|
||||
pub use error_core::Error;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,9 @@ use sections_translator::{SectionParsingError, parse_function_signatures, parse_
|
||||
parse_elements_section, parse_data_section};
|
||||
use environ::ModuleEnvironment;
|
||||
|
||||
// this is for no_std builds, but has no affect on regular builds
|
||||
use std::string::String;
|
||||
|
||||
/// Translate a sequence of bytes forming a valid Wasm binary into a list of valid Cretonne IL
|
||||
/// [`Function`](../cretonne/ir/function/struct.Function.html).
|
||||
/// Returns the functions and also the mappings for imported functions and signature between the
|
||||
|
||||
@@ -17,6 +17,10 @@ use wasmparser;
|
||||
use std::str::from_utf8;
|
||||
use environ::ModuleEnvironment;
|
||||
|
||||
// this is for no_std builds, but has no affect on regular builds
|
||||
use std::vec::Vec;
|
||||
use std::string::String;
|
||||
|
||||
pub enum SectionParsingError {
|
||||
WrongSectionContent(String),
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ use environ::{FuncEnvironment, GlobalValue};
|
||||
use std::collections::HashMap;
|
||||
use translation_utils::{GlobalIndex, MemoryIndex, SignatureIndex, FunctionIndex};
|
||||
|
||||
// this is for no_std builds, but has no affect on regular builds
|
||||
use std::vec::Vec;
|
||||
|
||||
/// A control stack frame can be an `if`, a `block` or a `loop`, each one having the following
|
||||
/// fields:
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user