Merge branch 'master' into feature/vm_refactor

This commit is contained in:
Lachlan Sneff 2018-12-17 21:51:03 -05:00
commit 0847c950a4
12 changed files with 208 additions and 143 deletions

88
Cargo.lock generated
View File

@ -63,6 +63,11 @@ name = "byteorder"
version = "1.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cast"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cc"
version = "1.0.25"
@ -132,18 +137,20 @@ dependencies = [
[[package]]
name = "cranelift-bforest"
version = "0.23.0"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cranelift-entity 0.23.0",
"cranelift-entity 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cranelift-codegen"
version = "0.23.0"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cranelift-bforest 0.23.0",
"cranelift-codegen-meta 0.23.0",
"cranelift-entity 0.23.0",
"cranelift-bforest 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cranelift-codegen-meta 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cranelift-entity 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -152,44 +159,50 @@ dependencies = [
[[package]]
name = "cranelift-codegen-meta"
version = "0.23.0"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cranelift-entity 0.23.0",
"cranelift-entity 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cranelift-entity"
version = "0.23.0"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cranelift-frontend"
version = "0.23.0"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cranelift-codegen 0.23.0",
"cranelift-codegen 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cranelift-native"
version = "0.23.0"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cranelift-codegen 0.23.0",
"cranelift-codegen 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cranelift-wasm"
version = "0.23.0"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cranelift-codegen 0.23.0",
"cranelift-entity 0.23.0",
"cranelift-frontend 0.23.0",
"cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cranelift-codegen 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cranelift-entity 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cranelift-frontend 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmparser 0.21.10 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmparser 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -306,6 +319,11 @@ name = "gcc"
version = "0.3.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "glob"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "indicatif"
version = "0.10.3"
@ -838,22 +856,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "wabt"
version = "0.7.1"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt-sys 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wabt-sys"
version = "0.5.1"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -862,10 +881,10 @@ version = "0.1.3"
dependencies = [
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"console 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cranelift-codegen 0.23.0",
"cranelift-entity 0.23.0",
"cranelift-native 0.23.0",
"cranelift-wasm 0.23.0",
"cranelift-codegen 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cranelift-entity 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cranelift-native 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cranelift-wasm 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"docopt 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -880,7 +899,7 @@ dependencies = [
"structopt 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmparser 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -892,7 +911,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "wasmparser"
version = "0.21.10"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -923,6 +942,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d"
"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427"
"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
@ -930,6 +950,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "6ec65ee4f9c9d16f335091d23693457ed4928657ba4982289d7fafee03bc614a"
"checksum console 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ba5561f4d4d89e0f246d4dd83846d96f617e886b96c7aee36e68791c98f89ce"
"checksum cranelift-bforest 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "40f8ff24e9a6c89b8a846b14df9a34d2cac17cea7bdb5c81ed6b4744ee0e38bf"
"checksum cranelift-codegen 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "42f5b809bd885c368e01aeec8fe04f21dcb07569834b907d75b4a7bed8d067eb"
"checksum cranelift-codegen-meta 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "014c23ed3ebdc8377d41540af638245207dd169f421df042dfccc867465734ed"
"checksum cranelift-entity 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4df40e26c0cf7b4d86919cb995bb412ee3001cc18e4f3c83a903f30b7007d8b"
"checksum cranelift-frontend 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "789907218eeebebcea8122c2053d71affac91c96ce72cea35ebfdbbf547e82af"
"checksum cranelift-native 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "474bee81d620a473bf43411a3d6f10ffbf7965141dc5e5b76d8d2151dde3285d"
"checksum cranelift-wasm 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49723365dab9a48b354bdc24cb6d9d5719bc1d3b858ffd2ea179d0d7d885804a"
"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3"
"checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150"
"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
@ -943,6 +970,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum indicatif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "40ecd1e2ee08e6c255ce890f5a99d17000850e664e7acf119fb03b25b0575bfe"
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
@ -1010,10 +1038,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum wabt 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5b24b2494bd6077dff717f41523f6e3e0161d58f578198589a6a6c8b314cb763"
"checksum wabt-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "122aefe1d22c067cce1dc5d20d89d1ca47ce0eb10120246a3e2340863f9e6ddd"
"checksum wabt 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff1f0f87e467255240c1faf5cf13a04410723407840d7733e75967224e191a5"
"checksum wabt-sys 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0cc8982bfe0a923f152e96d991e50a6f97fe73ca4af6d9d84d76634f03051fa2"
"checksum wasmparser 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2a75e0c3fe9a4d4fd91901348a5be05ba4791e29dda89e8596bfe87900ba7edc"
"checksum wasmparser 0.21.10 (registry+https://github.com/rust-lang/crates.io-index)" = "48b8ebfeb364ff50e0ff043f491c270f58a7563aa3dc97402a0e813bfeb6df6f"
"checksum wasmparser 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f46e666ecb4a406483a59a49f9d0c17f327e70da53a128eccddae2eadb95865c"
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@ -20,14 +20,14 @@ include = [
]
[dependencies]
# cranelift-native = "0.23.0"
cranelift-native = { path = "cranelift/lib/native" }
# cranelift-codegen = "0.23.0"
cranelift-codegen = { path = "cranelift/lib/codegen" }
# cranelift-entity = "0.23.0"
cranelift-entity = { path = "cranelift/lib/entity" }
# cranelift-wasm = "0.23.0"
cranelift-wasm = { path = "cranelift/lib/wasm" }
cranelift-native = "0.26.0"
# cranelift-native = { path = "cranelift/lib/native" }
cranelift-codegen = "0.26.0"
# cranelift-codegen = { path = "cranelift/lib/codegen" }
cranelift-entity = "0.26.0"
# cranelift-entity = { path = "cranelift/lib/entity" }
cranelift-wasm = "0.26.0"
# cranelift-wasm = { path = "cranelift/lib/wasm" }
docopt = "1.0.0"
serde = "1.0.55"
serde_derive = "1.0.55"
@ -35,7 +35,7 @@ tempdir = "0.3.7"
error-chain = "0.12.0"
errno = "0.2.4"
structopt = "0.2.11"
wabt = "0.7.1"
wabt = "0.7.2"
wasmparser = "0.20.0"
winapi = "0.3.6"
region = "0.3.0"
@ -51,8 +51,7 @@ indicatif = "0.10"
console = "0.7.1"
[build-dependencies]
wabt = "0.7.1"
wabt = "0.7.2"
# [dev-dependencies]
# libffi = "0.6.4"
# maplit = "1.0.1"

View File

@ -8,7 +8,7 @@
#include <stdio.h>
#include <math.h>
int main( int argc, char * argv [] ) {
int main() {
int x;
printf("ab%gc%nd\n", 1.23f, &x);
printf("n=%d\n", x);
@ -27,19 +27,19 @@ int main( int argc, char * argv [] ) {
printf("Width trick: %*d\n", 5, 10);
printf("%s %%\n", "A string");
printf("Null string: %7s\n", NULL);
// printf("Null pointer: %p\n", NULL);
// printf("%lf\n", INFINITY);
// printf("%lF\n", INFINITY);
// printf("%lf\n", -INFINITY);
// printf("%lF\n", -INFINITY);
// printf("%lf\n", NAN);
// printf("%lF\n", NAN);
// printf("%10f\n", NAN);
// printf("%-10f\n", NAN);
// printf("%010.2f\n", NAN);
// printf("%-010.2f\n", NAN);
// printf("%10.f\n", INFINITY);
// printf("%-10.f\n", -INFINITY);
// printf("Null pointer: %p\n", NULL);
printf("%lf\n", INFINITY);
printf("%lF\n", INFINITY);
printf("%lf\n", -INFINITY);
printf("%lF\n", -INFINITY);
printf("%lf\n", NAN);
printf("%lF\n", NAN);
printf("%10f\n", NAN);
printf("%-10f\n", NAN);
printf("%010.2f\n", NAN);
printf("%-010.2f\n", NAN);
printf("%10.f\n", INFINITY);
printf("%-10.f\n", -INFINITY);
// printf("--rest--\n");
// printf("in%%3.5valid\n", 0);
// printf("%.f\n", 0.0f);

View File

@ -15,3 +15,15 @@ Force sign or space: 3.14 -3.14 3.14 -3.14
Width trick: 10
A string %
Null string: (null)
inf
INF
-inf
-INF
nan
NAN
nan
nan
nan
nan
inf
-inf

Binary file not shown.

View File

@ -1,3 +1,4 @@
ignore = [
"src/spectests",
"src/emtests",
]

View File

@ -91,6 +91,16 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
"DYNAMICTOP_PTR",
ImportValue::Global(dynamictop_ptr(STATIC_BUMP) as _),
);
import_object.set(
"global",
"Infinity",
ImportValue::Global(std::f64::INFINITY.to_bits() as _),
);
import_object.set(
"global",
"NaN",
ImportValue::Global(std::f64::NAN.to_bits() as _),
);
import_object.set("env", "tableBase", ImportValue::Global(0));
// Print functions
import_object.set("env", "printf", ImportValue::Func(io::printf as _));

View File

@ -383,8 +383,8 @@ impl Instance {
GlobalInit::I64Const(n) => n,
GlobalInit::F32Const(f) => f as _, // unsafe { mem::transmute(f as f64) },
GlobalInit::F64Const(f) => f as _, // unsafe { mem::transmute(f) },
GlobalInit::GlobalRef(global_index) => globals_data[global_index.index()],
GlobalInit::Import() => {
GlobalInit::GetGlobal(global_index) => globals_data[global_index.index()],
GlobalInit::Import => {
let (module_name, field_name) = import_name
.as_ref()
.expect("Expected a import name for the global import");
@ -394,6 +394,10 @@ impl Instance {
Some(ImportValue::Global(value)) => *value,
None => {
if options.mock_missing_globals {
debug!(
"The Imported global {}.{} is not provided, therefore will be mocked.",
module_name, field_name
);
0
} else {
panic!(
@ -430,7 +434,11 @@ impl Instance {
Some(ImportValue::Table(t)) => t.to_vec(),
None => {
if options.mock_missing_tables {
let len = table.entity.size;
debug!(
"The Imported table {}.{} is not provided, therefore will be mocked.",
module_name, field_name
);
let len = table.entity.minimum as usize;
let mut v = Vec::with_capacity(len);
v.resize(len, 0);
v
@ -448,7 +456,7 @@ impl Instance {
}
}
None => {
let len = table.entity.size;
let len = table.entity.minimum as usize;
let mut v = Vec::with_capacity(len);
v.resize(len, 0);
v
@ -490,15 +498,15 @@ impl Instance {
// If we use emscripten, we set a fixed initial and maximum
debug!(
"Instance - init memory ({}, {:?})",
memory.pages_count, memory.maximum
memory.minimum, memory.maximum
);
let memory = if options.abi == InstanceABI::Emscripten {
// We use MAX_PAGES, so at the end the result is:
// (initial * LinearMemory::PAGE_SIZE) == LinearMemory::DEFAULT_HEAP_SIZE
// However, it should be: (initial * LinearMemory::PAGE_SIZE) == 16777216
LinearMemory::new(LinearMemory::MAX_PAGES as u32, None)
LinearMemory::new(LinearMemory::MAX_PAGES, None)
} else {
LinearMemory::new(memory.pages_count as u32, memory.maximum.map(|m| m as u32))
LinearMemory::new(memory.minimum, memory.maximum.map(|m| m as u32))
};
memories.push(memory);
}

View File

@ -6,13 +6,13 @@ pub mod memory;
pub mod module;
pub mod relocation;
pub mod utils;
pub mod vmcontext;
pub mod vmoffsets;
pub mod vm;
use cranelift_codegen::{
isa,
settings::{self, Configurable},
};
use cranelift_wasm::ModuleEnvironment;
use std::panic;
use std::str::FromStr;
use target_lexicon;
@ -133,7 +133,7 @@ pub fn validate_or_error(bytes: &[u8]) -> Result<(), ErrorKind> {
return Err(ErrorKind::CompileError(format!(
"Validation error: {}",
err.message
)))
)));
}
_ => (),
}
@ -228,11 +228,26 @@ pub fn start_instance(
_ => panic!("_main emscripten function not found"),
};
let main: extern "C" fn(u32, u32, &Instance) = get_instance_function!(instance, func_index);
let (argc, argv) = store_module_arguments(path, args, instance);
call_protected!(main(argc, argv, &instance)).map_err(|err| format!("{}", err))
let sig_index = module.get_func_type(func_index);
let signature = module.get_signature(sig_index);
let num_params = signature.params.len();
match num_params {
2 => {
let main: extern "C" fn(u32, u32, &Instance) =
get_instance_function!(instance, func_index);
let (argc, argv) = store_module_arguments(path, args, instance);
call_protected!(main(argc, argv, &instance))
}
0 => {
let main: extern "C" fn(&Instance) = get_instance_function!(instance, func_index);
call_protected!(main(&instance))
}
_ => panic!(
"The emscripten main function has received an incorrect number of params {}",
num_params
),
}
.map_err(|err| format!("{}", err))
// TODO: We should implement emscripten __ATEXIT__
} else {
let func_index =

View File

@ -6,7 +6,7 @@ use std::string::String;
use std::vec::Vec;
use cranelift_codegen::cursor::FuncCursor;
use cranelift_codegen::ir::immediates::{Imm64, Offset32};
use cranelift_codegen::ir::immediates::{Imm64, Offset32, Uimm64};
use cranelift_codegen::ir::types::*;
use cranelift_codegen::ir::{
self, AbiParam, ArgumentPurpose, ExtFuncData, ExternalName, FuncRef, InstBuilder, Signature,
@ -392,9 +392,9 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
// Create table based on the data above
func.create_table(ir::TableData {
base_gv,
min_size: Imm64::new(0),
min_size: Uimm64::new(0),
bound_gv,
element_size: Imm64::new(i64::from(self.pointer_bytes())),
element_size: Uimm64::new(u64::from(self.pointer_bytes())),
index_type: I64,
})
}
@ -434,9 +434,9 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
func.create_heap(ir::HeapData {
base: heap_base,
min_size: 0.into(),
guard_size: (LinearMemory::DEFAULT_GUARD_SIZE as i64).into(),
offset_guard_size: Uimm64::new(LinearMemory::DEFAULT_GUARD_SIZE as u64),
style: ir::HeapStyle::Static {
bound: (LinearMemory::DEFAULT_HEAP_SIZE as i64).into(),
bound: Uimm64::new(LinearMemory::DEFAULT_HEAP_SIZE as u64),
},
index_type: I32,
})
@ -458,15 +458,16 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
readonly: false,
});
let offset = global_index.index() as i64 * ptr_size as i64;
let iadd = func.create_global_value(ir::GlobalValueData::IAddImm {
base: globals_base_addr,
offset: Imm64::new(offset),
global_type: native_pointer_type(),
});
let offset = global_index.index() * ptr_size as usize;
// let iadd = func.create_global_value(ir::GlobalValueData::IAddImm {
// base: globals_base_addr,
// offset: Imm64::new(offset),
// global_type: native_pointer_type(),
// });
GlobalVariable::Memory {
gv: iadd,
gv: globals_base_addr,
offset: (offset as i32).into(),
ty: self.mod_info.globals[global_index.index()].entity.ty,
}
}
@ -664,12 +665,8 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
}
impl<'data> ModuleEnvironment<'data> for Module {
fn target_config(&self) -> &TargetFrontendConfig {
&self.info.config
}
fn get_func_name(&self, func_index: FuncIndex) -> ir::ExternalName {
get_func_name(func_index)
fn target_config(&self) -> TargetFrontendConfig {
self.info.config
}
fn declare_signature(&mut self, sig: &ir::Signature) {

View File

@ -4,15 +4,14 @@ use cranelift_wasm::{
DefinedTableIndex, DefinedFuncIndex, DefinedMemoryIndex, DefinedGlobalIndex,
SignatureIndex,
};
use crate::webassembly::vmoffsets::VMOffsets;
#[repr(C)]
pub struct VMContext {
pub struct VmCtx {
/// A pointer to an array of imported functions, indexed by `FuncIndex`.
imported_functions: *const *const VMFunctionBody,
imported_funcs: *const *const Function,
/// A pointer to an array of imported tables, indexed by `TableIndex`.
imported_tables: *mut VMTableImport,
imported_tables: *mut ImportedTable,
/// A pointer to an array of imported memories, indexed by `MemoryIndex,
imported_memories: *mut VMMemoryImport,
@ -33,121 +32,129 @@ pub struct VMContext {
signature_ids: *mut VMSharedSigIndex,
}
/// Used to provide type safety for passing around function pointers.
/// The typesystem ensures this cannot be dereferenced.
pub enum VMFunctionBody { }
/// Used to provide type safety (ish) for passing around function pointers.
/// The typesystem ensures this cannot be dereferenced since an
/// empty enum cannot actually exist.
pub enum Function { }
/// Definition of a table used by the VM. (obviously)
#[repr(C)]
pub struct VMTableDefinition {
pub struct LocalTable {
/// pointer to the elements in the table.
pub base: *mut u8,
/// Number of elements in the table (NOT necessarily the size of the table in bytes!).
pub current_elements: usize,
}
impl VMTableDefinition {
pub fn offset_base(offsets: &VMOffsets) -> u8 {
impl LocalTable {
pub fn offset_base(offsets: &Offsets) -> u8 {
0 * offsets.ptr_size
}
pub fn offset_current_elements(offsets: &VMOffsets) -> u8 {
pub fn offset_current_elements(offsets: &Offsets) -> u8 {
1 * offsets.ptr_size
}
}
#[repr(C)]
pub struct VMTableImport {
pub struct ImportedTable {
/// A pointer to the table definition.
pub table: *mut VMTableDefinition,
pub table: *mut LocalTable,
/// A pointer to the vmcontext that owns this table definition.
pub vmctx: *mut VMContext,
pub vmctx: *mut VmCtx,
}
impl VMTableImport {
pub fn offset_table(offsets: &VMOffsets) -> u8 {
impl ImportedTable {
pub fn offset_table(offsets: &Offsets) -> u8 {
0 * offsets.ptr_size
}
pub fn offset_vmctx(offsets: &VMOffsets) -> u8 {
pub fn offset_vmctx(offsets: &Offsets) -> u8 {
1 * offsets.ptr_size
}
}
/// Definition of a memory used by the VM.
#[repr(C)]
pub struct VMMemoryDefinition {
pub struct LocalMemory {
/// Pointer to the bottom of linear memory.
pub base: *mut u8,
/// Current logical size of this linear memory in bytes.
pub size: usize,
}
impl VMMemoryDefinition {
pub fn offset_base(offsets: &VMOffsets) -> u8 {
impl LocalMemory {
pub fn offset_base(offsets: &Offsets) -> u8 {
0 * offsets.ptr_size
}
pub fn offset_size(offsets: &VMOffsets) -> u8 {
pub fn offset_size(offsets: &Offsets) -> u8 {
1 * offsets.ptr_size
}
}
#[repr(C)]
pub struct VMMemoryImport {
pub struct ImportedMemory {
/// A pointer to the memory definition.
pub memory: *mut VMMemoryDefinition,
/// A pointer to the vmcontext that owns this memory definition.
pub vmctx: *mut VMContext,
pub memory: *mut LocalMemory,
}
impl VMMemoryImport {
pub fn offset_memory(offsets: &VMOffsets) -> u8 {
impl ImportedMemory {
pub fn offset_memory(offsets: &Offsets) -> u8 {
0 * offsets.ptr_size
}
pub fn offset_vmctx(offsets: &VMOffsets) -> u8 {
1 * offsets.ptr_size
}
}
/// Definition of a global used by the VM.
#[repr(C, align(8))]
pub struct VMGlobalDefinition {
pub struct LocalGlobal {
pub data: [u8; 8],
}
#[repr(C)]
pub struct VMGlobalImport {
pub globals: *mut VMGlobalDefinition,
pub struct ImportedGlobal {
pub globals: *mut LocalGlobal,
}
impl VMGlobalImport {
pub fn offset_globals(offsets: &VMOffsets) -> u8 {
impl ImportedGlobal {
pub fn offset_globals(offsets: &Offsets) -> u8 {
0 * offsets.ptr_size
}
}
#[repr(C)]
pub struct VMSharedSigIndex(u32);
pub struct SigId(u32);
#[repr(C)]
pub struct VMCallerCheckedAnyfunc {
pub struct CallerCheckedAnyfunc {
pub func: *const VMFunctionBody,
pub type_index: VMSharedSigIndex,
pub vmctx: *mut VMContext,
pub sig: SigId,
pub vmctx: *mut VmCtx,
}
impl VMCallerCheckedAnyfunc {
pub fn offset_func(offsets: &VMOffsets) -> u8 {
pub fn offset_func(offsets: &Offsets) -> u8 {
0 * offsets.ptr_size
}
pub fn offset_type_index(offsets: &VMOffsets) -> u8 {
pub fn offset_type_index(offsets: &Offsets) -> u8 {
1 * offsets.ptr_size
}
pub fn offset_vmctx(offsets: &VMOffsets) -> u8 {
pub fn offset_vmctx(offsets: &Offsets) -> u8 {
2 * offsets.ptr_size
}
}
#[derive(Copy, Clone, )]
pub struct Offsets {
ptr_size: u8,
}
impl Offsets {
pub fn new(ptr_size: u8) -> Self {
Self {
ptr_size,
}
}
}

View File

@ -1,12 +0,0 @@
pub struct VMOffsets {
pub(in crate::webassembly) ptr_size: u8,
}
impl VMOffsets {
pub fn new(ptr_size: u8) -> Self {
Self {
ptr_size,
}
}
}