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