Also create optimized & inlined wasts for comparison

This commit is contained in:
dcodeIO 2017-12-06 23:54:16 +01:00
parent 9ae3328e58
commit d9ad42ed2e
5 changed files with 365 additions and 2 deletions

View File

@ -18,7 +18,7 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
if (filename.charAt(0) == "_" || filename.endsWith(".fixture.ts"))
return;
console.log("Testing compiler/" + filename);
console.log(chalk.default.whiteBright("Testing compiler/" + filename));
const parser = new Parser();
const sourceText = fs.readFileSync(__dirname + "/compiler/" + filename, { encoding: "utf8" });
@ -37,6 +37,7 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
const module = Compiler.compile(program);
const actual = module.toText() + "(;\n[program.elements]\n " + iterate(program.elements.keys()).join("\n ") + "\n[program.exports]\n " + iterate(program.exports.keys()).join("\n ") + "\n;)\n";
let actualOptimized: string | null = null;
let actualInlined: string | null = null;
const fixture = path.basename(filename, ".ts") + ".wast";
if (module.validate()) {
@ -50,6 +51,8 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
}
module.optimize();
actualOptimized = module.toText();
module.runPasses([ "inlining" ]);
actualInlined = module.toText();
} else {
process.exitCode = 1;
console.log(chalk.default.red("validate ERROR"));
@ -62,6 +65,17 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
fs.writeFileSync(__dirname + "/compiler/" + path.basename(filename, ".ts") + ".optimized.wast", actualOptimized, { encoding: "utf8" });
console.log("Created optimized");
}
if (actualInlined != null) {
if (actualInlined != actualOptimized) {
fs.writeFileSync(__dirname + "/compiler/" + path.basename(filename, ".ts") + ".optimized-inlined.wast", actualInlined, { encoding: "utf8" });
console.log("Created optimized & inlined");
} else {
try {
fs.unlinkSync(__dirname + "/compiler/" + path.basename(filename, ".ts") + ".optimized-inlined.wast");
console.log("Deleted optimized & inlined");
} catch (e) {}
}
}
} else {
const expected = fs.readFileSync(__dirname + "/compiler/" + fixture, { encoding: "utf8" });
const diffs = diff("compiler/" + fixture, expected, actual);

View File

@ -0,0 +1,25 @@
(module
(type $i (func (result i32)))
(type $v (func))
(global $enum/NonConstant.ZERO (mut i32) (i32.const 0))
(global $enum/NonConstant.ONE (mut i32) (i32.const 0))
(memory $0 1)
(data (i32.const 4) "\08")
(export "memory" (memory $0))
(start $start)
(func $start (; 0 ;) (type $v)
(set_global $enum/NonConstant.ZERO
(block (result i32)
(block $__inlined_func$enum/getZero (result i32)
(i32.const 0)
)
)
)
(set_global $enum/NonConstant.ONE
(i32.add
(get_global $enum/NonConstant.ZERO)
(i32.const 1)
)
)
)
)

View File

@ -0,0 +1,46 @@
(module
(type $iii (func (param i32 i32) (result i32)))
(type $v (func))
(memory $0 1)
(data (i32.const 4) "\08")
(export "memory" (memory $0))
(start $start)
(func $start (; 0 ;) (type $v)
(local $0 i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(drop
(i32.add
(block (result i32)
(block $__inlined_func$export/add (result i32)
(set_local $0
(i32.const 1)
)
(set_local $1
(i32.const 2)
)
(i32.add
(get_local $0)
(get_local $1)
)
)
)
(block (result i32)
(block $__inlined_func$export/sub (result i32)
(set_local $2
(i32.const 2)
)
(set_local $3
(i32.const 1)
)
(i32.sub
(get_local $2)
(get_local $3)
)
)
)
)
)
)
)

View File

@ -0,0 +1,278 @@
(module
(type $ii (func (param i32) (result i32)))
(type $iiv (func (param i32 i32)))
(type $iiiv (func (param i32 i32 i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $iv (func (param i32)))
(type $v (func))
(memory $0 1)
(data (i32.const 4) "\08")
(export "control_construct" (func $tlsf/control_construct))
(export "memory" (memory $0))
(start $start)
(func $tlsf/fls (; 0 ;) (type $ii) (param $0 i32) (result i32)
(if (result i32)
(get_local $0)
(i32.sub
(i32.const 31)
(i32.clz
(get_local $0)
)
)
(i32.const -1)
)
)
(func $tlsf/ffs (; 1 ;) (type $ii) (param $0 i32) (result i32)
(if (result i32)
(get_local $0)
(i32.ctz
(get_local $0)
)
(i32.const -1)
)
)
(func $tlsf/control_set_block (; 2 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(if
(i32.ge_s
(get_local $1)
(i32.const 23)
)
(unreachable)
)
(if
(i32.ge_s
(get_local $2)
(i32.const 32)
)
(unreachable)
)
(i32.store
(i32.add
(i32.add
(get_local $0)
(i32.const 112)
)
(i32.mul
(i32.add
(i32.mul
(get_local $1)
(i32.const 32)
)
(get_local $2)
)
(i32.const 4)
)
)
(get_local $3)
)
)
(func $tlsf/control_construct (; 3 ;) (type $iv) (param $0 i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
(local $7 i32)
(local $8 i32)
(local $9 i32)
(local $10 i32)
(local $11 i32)
(block
(block $__inlined_func$tlsf/block_set_next_free
(set_local $3
(get_local $0)
)
(set_local $4
(get_local $0)
)
(i32.store
(i32.add
(get_local $3)
(i32.const 8)
)
(get_local $4)
)
)
)
(block
(block $__inlined_func$tlsf/block_set_prev_free
(set_local $5
(get_local $0)
)
(set_local $6
(get_local $0)
)
(i32.store
(i32.add
(get_local $5)
(i32.const 12)
)
(get_local $6)
)
)
)
(block
(block $__inlined_func$tlsf/control_set_fl
(set_local $7
(get_local $0)
)
(set_local $8
(i32.const 0)
)
(i32.store
(i32.add
(get_local $7)
(i32.const 16)
)
(get_local $8)
)
)
)
(set_local $1
(i32.const 0)
)
(loop $continue|1.1
(if
(i32.lt_s
(get_local $1)
(i32.const 23)
)
(block
(block
(block $__inlined_func$tlsf/control_set_sl
(set_local $9
(get_local $0)
)
(set_local $10
(get_local $1)
)
(set_local $11
(i32.const 0)
)
(block
(if
(i32.ge_s
(get_local $10)
(i32.const 23)
)
(unreachable)
)
(i32.store
(i32.add
(i32.add
(get_local $9)
(i32.const 20)
)
(i32.mul
(get_local $10)
(i32.const 4)
)
)
(get_local $11)
)
)
)
)
(set_local $2
(i32.const 0)
)
(loop $continue|1.2
(if
(i32.lt_s
(get_local $2)
(i32.const 32)
)
(block
(call $tlsf/control_set_block
(get_local $0)
(get_local $1)
(get_local $2)
(get_local $0)
)
(set_local $2
(i32.add
(get_local $2)
(i32.const 1)
)
)
(br $continue|1.2)
)
)
)
(set_local $1
(i32.add
(get_local $1)
(i32.const 1)
)
)
(br $continue|1.1)
)
)
)
)
(func $start (; 4 ;) (type $v)
(if
(i32.ne
(call $tlsf/fls
(i32.const 0)
)
(i32.const -1)
)
(unreachable)
)
(if
(call $tlsf/fls
(i32.const 1)
)
(unreachable)
)
(if
(i32.ne
(call $tlsf/fls
(i32.const -2147483640)
)
(i32.const 31)
)
(unreachable)
)
(if
(i32.ne
(call $tlsf/fls
(i32.const 2147483647)
)
(i32.const 30)
)
(unreachable)
)
(if
(i32.ne
(call $tlsf/ffs
(i32.const 0)
)
(i32.const -1)
)
(unreachable)
)
(if
(call $tlsf/ffs
(i32.const 1)
)
(unreachable)
)
(if
(i32.ne
(call $tlsf/ffs
(i32.const -2147483648)
)
(i32.const 31)
)
(unreachable)
)
(call $tlsf/control_construct
(i32.load
(i32.const 4)
)
)
)
)

View File

@ -13,7 +13,7 @@ glob.sync(filter, { cwd: __dirname + "/parser" }).forEach(filename => {
if (filename.charAt(0) == "_" || filename.endsWith(".fixture.ts"))
return;
console.log("Testing parser/" + filename);
console.log(chalk.default.whiteBright("Testing parser/" + filename));
const parser = new Parser();
const sourceText = fs.readFileSync(__dirname + "/parser/" + filename, { encoding: "utf8" }).replace(/\r?\n/g, "\n").replace(/^\/\/.*\r?\n/mg, "");