Stopped the extra pop on get/set global. Fixes #2.

This commit is contained in:
Chad Retz 2017-04-23 03:35:03 -05:00
parent e2996212e9
commit febb07b8b2
2 changed files with 25 additions and 3 deletions

View File

@ -196,8 +196,8 @@ open class InsnReworker {
is Node.Instr.GetLocal -> PUSH_RESULT is Node.Instr.GetLocal -> PUSH_RESULT
is Node.Instr.SetLocal -> POP_PARAM is Node.Instr.SetLocal -> POP_PARAM
is Node.Instr.TeeLocal -> POP_PARAM + PUSH_RESULT is Node.Instr.TeeLocal -> POP_PARAM + PUSH_RESULT
is Node.Instr.GetGlobal -> POP_THIS + PUSH_RESULT is Node.Instr.GetGlobal -> PUSH_RESULT
is Node.Instr.SetGlobal -> POP_THIS + POP_PARAM is Node.Instr.SetGlobal -> POP_PARAM
is Node.Instr.I32Load, is Node.Instr.I64Load, is Node.Instr.F32Load, is Node.Instr.F64Load, is Node.Instr.I32Load, is Node.Instr.I64Load, is Node.Instr.F32Load, is Node.Instr.F64Load,
is Node.Instr.I32Load8S, is Node.Instr.I32Load8U, is Node.Instr.I32Load16U, is Node.Instr.I32Load16S, is Node.Instr.I32Load8S, is Node.Instr.I32Load8U, is Node.Instr.I32Load16U, is Node.Instr.I32Load16S,
is Node.Instr.I64Load8S, is Node.Instr.I64Load8U, is Node.Instr.I64Load16U, is Node.Instr.I64Load16S, is Node.Instr.I64Load8S, is Node.Instr.I64Load8U, is Node.Instr.I64Load16U, is Node.Instr.I64Load16S,
@ -266,7 +266,6 @@ open class InsnReworker {
}.let { (count, _) -> count } }.let { (count, _) -> count }
companion object : InsnReworker() { companion object : InsnReworker() {
const val POP_THIS = -1
const val POP_PARAM = -1 const val POP_PARAM = -1
const val PUSH_RESULT = 1 const val PUSH_RESULT = 1
const val NOP = 0 const val NOP = 0

View File

@ -0,0 +1,23 @@
;; This was breaking because stack diff was wrong for get_global and set_global
(module
(global $foo (mut i32) (i32.const 20))
(func (export "test") (param $p i32) (result i32)
(local i32)
(get_global $foo)
(set_local 1)
(get_global $foo)
(get_local $p)
(i32.add)
(set_global $foo)
(get_global $foo)
(i32.const 15)
(i32.add)
(i32.const -16)
(i32.and)
(set_global $foo)
(get_global $foo)
)
)
(assert_return (invoke "test" (i32.const 7)) (i32.const 32))