More options for asc

This commit is contained in:
dcodeIO
2017-12-04 19:26:50 +01:00
parent 0e6bfa45f8
commit df3e34f2aa
17 changed files with 565 additions and 32 deletions

View File

@ -0,0 +1,13 @@
var binaryen = require("binaryen");
// "unexpected false: module function exports must be found"
var mod = new binaryen.Module();
var funcType = mod.addFunctionType("v", binaryen.none, []);
var func = mod.addImport("test", "env", "test", funcType);
mod.addExport("test", "test");
console.log(mod.emitText());
if (!mod.validate())
console.log("-> does not validate");

View File

@ -11,17 +11,6 @@ import { Module } from "../src/module";
import { Parser } from "../src/parser";
import { diff } from "./util/diff";
// TODO: implement properly in module.ts
import * as binaryen from "binaryen";
Module.prototype.toText = function(): string {
let old: any = (<any>binaryen)["print"];
let ret: string = "";
(<any>binaryen)["print"] = function(x: string): void { ret += x + "\n" };
_BinaryenModulePrint(this.ref);
(<any>binaryen)["print"] = old;
return ret;
}
const isCreate = process.argv[2] === "--create";
const filter = process.argv.length > 2 && !isCreate ? "*" + process.argv[2] + "*.ts" : "*.ts";

View File

@ -177,13 +177,40 @@
)
(set_global $builtins/i
(i32.load
(i32.const 4)
(i32.const 8)
)
)
(i32.store
(i32.const 4)
(i32.const 8)
(get_global $builtins/i)
)
(set_global $builtins/I
(i64.load
(i32.const 8)
)
)
(i64.store
(i32.const 8)
(get_global $builtins/I)
)
(set_global $builtins/f
(f32.load
(i32.const 8)
)
)
(f32.store
(i32.const 8)
(get_global $builtins/f)
)
(set_global $builtins/F
(f64.load
(i32.const 8)
)
)
(f64.store
(i32.const 8)
(get_global $builtins/F)
)
(if
(f32.eq
(tee_local $0

View File

@ -119,8 +119,14 @@ sizeof<isize>();
sizeof<f32>();
sizeof<f64>();
i = load<i32>(4);
store<i32>(4, i);
i = load<i32>(8);
store<i32>(8, i);
I = load<i64>(8);
store<i64>(8, I);
f = load<f32>(8);
store<f32>(8, f);
F = load<f64>(8);
store<f64>(8, F);
if (NaN == NaN)
unreachable();

View File

@ -520,13 +520,40 @@
)
(set_global $builtins/i
(i32.load
(i32.const 4)
(i32.const 8)
)
)
(i32.store
(i32.const 4)
(i32.const 8)
(get_global $builtins/i)
)
(set_global $builtins/I
(i64.load
(i32.const 8)
)
)
(i64.store
(i32.const 8)
(get_global $builtins/I)
)
(set_global $builtins/f
(f32.load
(i32.const 8)
)
)
(f32.store
(i32.const 8)
(get_global $builtins/f)
)
(set_global $builtins/F
(f64.load
(i32.const 8)
)
)
(f64.store
(i32.const 8)
(get_global $builtins/F)
)
(if
(f64.eq
(f64.const nan:0x8000000000000)

View File

@ -0,0 +1,5 @@
(module
(memory $0 1)
(data (i32.const 4) "\08")
(export "memory" (memory $0))
)

View File

@ -0,0 +1,4 @@
declare function external(): void;
// FIXME: "unexpected false: module function exports must be found"
export { external };

View File

@ -0,0 +1,37 @@
(module
(type $v (func))
(import "env" "external" (func $declare/external))
(memory $0 1)
(data (i32.const 4) "\08\00\00\00")
(export "external" (func $declare/external))
(export "memory" (memory $0))
)
(;
[program.elements]
clz
ctz
popcnt
rotl
rotr
abs
ceil
copysign
floor
max
min
nearest
sqrt
trunc
current_memory
grow_memory
unreachable
isNaN
isFinite
assert
sizeof
load
store
declare/external
[program.exports]
declare/external
;)

View File

@ -1,5 +1,9 @@
(module
(type $v (func))
(global $logical/i (mut i32) (i32.const 0))
(global $logical/I (mut i64) (i64.const 0))
(global $logical/f (mut f32) (f32.const 0))
(global $logical/F (mut f64) (f64.const 0))
(memory $0 1)
(data (i32.const 4) "\08")
(export "memory" (memory $0))
@ -7,6 +11,8 @@
(func $start (; 0 ;) (type $v)
(local $0 i32)
(local $1 f64)
(local $2 i64)
(local $3 f32)
(if
(tee_local $0
(i32.const 0)
@ -71,5 +77,151 @@
)
(unreachable)
)
(set_global $logical/i
(if (result i32)
(tee_local $0
(i32.const 1)
)
(i32.const 2)
(get_local $0)
)
)
(if
(i32.ne
(get_global $logical/i)
(i32.const 2)
)
(unreachable)
)
(set_global $logical/i
(if (result i32)
(tee_local $0
(i32.const 0)
)
(get_local $0)
(i32.const 1)
)
)
(if
(i32.ne
(get_global $logical/i)
(i32.const 1)
)
(unreachable)
)
(set_global $logical/I
(if (result i64)
(i64.ne
(tee_local $2
(i64.const 1)
)
(i64.const 0)
)
(i64.const 2)
(get_local $2)
)
)
(if
(i64.ne
(get_global $logical/I)
(i64.const 2)
)
(unreachable)
)
(set_global $logical/I
(if (result i64)
(i64.ne
(tee_local $2
(i64.const 0)
)
(i64.const 0)
)
(get_local $2)
(i64.const 1)
)
)
(if
(i64.ne
(get_global $logical/I)
(i64.const 1)
)
(unreachable)
)
(set_global $logical/f
(if (result f32)
(f32.ne
(tee_local $3
(f32.const 1)
)
(f32.const 0)
)
(f32.const 2)
(get_local $3)
)
)
(if
(f32.ne
(get_global $logical/f)
(f32.const 2)
)
(unreachable)
)
(set_global $logical/f
(if (result f32)
(f32.ne
(tee_local $3
(f32.const 0)
)
(f32.const 0)
)
(get_local $3)
(f32.const 1)
)
)
(if
(f32.ne
(get_global $logical/f)
(f32.const 1)
)
(unreachable)
)
(set_global $logical/F
(if (result f64)
(f64.ne
(tee_local $1
(f64.const 1)
)
(f64.const 0)
)
(f64.const 2)
(get_local $1)
)
)
(if
(f64.ne
(get_global $logical/F)
(f64.const 2)
)
(unreachable)
)
(set_global $logical/F
(if (result f64)
(f64.ne
(tee_local $1
(f64.const 0)
)
(f64.const 0)
)
(get_local $1)
(f64.const 1)
)
)
(if
(f64.ne
(get_global $logical/F)
(f64.const 1)
)
(unreachable)
)
)
)

View File

@ -5,3 +5,43 @@
1 && 2 || unreachable();
1.0 && 2.0 || unreachable();
let i: i32;
i = 1 && 2;
if (i != 2)
unreachable();
i = 0 || 1;
if (i != 1)
unreachable();
let I: i64;
I = 1 && 2;
if (I != 2)
unreachable();
I = 0 || 1;
if (I != 1)
unreachable();
let f: f32;
f = 1.0 && 2.0;
if (f != 2.0)
unreachable();
f = 0.0 || 1.0;
if (f != 1.0)
unreachable();
let F: f64;
F = 1.0 && 2.0;
if (F != 2.0)
unreachable();
F = 0.0 || 1.0;
if (F != 1.0)
unreachable();

View File

@ -1,5 +1,9 @@
(module
(type $v (func))
(global $logical/i (mut i32) (i32.const 0))
(global $logical/I (mut i64) (i64.const 0))
(global $logical/f (mut f32) (f32.const 0))
(global $logical/F (mut f64) (f64.const 0))
(memory $0 1)
(data (i32.const 4) "\08\00\00\00")
(export "memory" (memory $0))
@ -13,6 +17,14 @@
(local $5 i32)
(local $6 f64)
(local $7 f64)
(local $8 i32)
(local $9 i32)
(local $10 i64)
(local $11 i64)
(local $12 f32)
(local $13 f32)
(local $14 f64)
(local $15 f64)
(drop
(if (result i32)
(tee_local $0
@ -91,6 +103,152 @@
(unreachable)
)
)
(set_global $logical/i
(if (result i32)
(tee_local $8
(i32.const 1)
)
(i32.const 2)
(get_local $8)
)
)
(if
(i32.ne
(get_global $logical/i)
(i32.const 2)
)
(unreachable)
)
(set_global $logical/i
(if (result i32)
(tee_local $9
(i32.const 0)
)
(get_local $9)
(i32.const 1)
)
)
(if
(i32.ne
(get_global $logical/i)
(i32.const 1)
)
(unreachable)
)
(set_global $logical/I
(if (result i64)
(i64.ne
(tee_local $10
(i64.const 1)
)
(i64.const 0)
)
(i64.const 2)
(get_local $10)
)
)
(if
(i64.ne
(get_global $logical/I)
(i64.const 2)
)
(unreachable)
)
(set_global $logical/I
(if (result i64)
(i64.ne
(tee_local $11
(i64.const 0)
)
(i64.const 0)
)
(get_local $11)
(i64.const 1)
)
)
(if
(i64.ne
(get_global $logical/I)
(i64.const 1)
)
(unreachable)
)
(set_global $logical/f
(if (result f32)
(f32.ne
(tee_local $12
(f32.const 1)
)
(f32.const 0)
)
(f32.const 2)
(get_local $12)
)
)
(if
(f32.ne
(get_global $logical/f)
(f32.const 2)
)
(unreachable)
)
(set_global $logical/f
(if (result f32)
(f32.ne
(tee_local $13
(f32.const 0)
)
(f32.const 0)
)
(get_local $13)
(f32.const 1)
)
)
(if
(f32.ne
(get_global $logical/f)
(f32.const 1)
)
(unreachable)
)
(set_global $logical/F
(if (result f64)
(f64.ne
(tee_local $14
(f64.const 1)
)
(f64.const 0)
)
(f64.const 2)
(get_local $14)
)
)
(if
(f64.ne
(get_global $logical/F)
(f64.const 2)
)
(unreachable)
)
(set_global $logical/F
(if (result f64)
(f64.ne
(tee_local $15
(f64.const 0)
)
(f64.const 0)
)
(get_local $15)
(f64.const 1)
)
)
(if
(f64.ne
(get_global $logical/F)
(f64.const 1)
)
(unreachable)
)
)
)
(;
@ -118,6 +276,10 @@
sizeof
load
store
logical/i
logical/I
logical/f
logical/F
[program.exports]
;)