Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wagon and utilize wagon's validation pkg. #89

Merged
merged 4 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions compiler/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package compiler
import (
"bytes"
"encoding/binary"
//"fmt"
"strings"

"github.com/go-interpreter/wagon/disasm"
"github.com/go-interpreter/wagon/wasm"
//"github.com/go-interpreter/wagon/validate"
"github.com/go-interpreter/wagon/wasm/leb128"

"github.com/perlin-network/life/compiler/opcodes"
"github.com/perlin-network/life/utils"
"strings"
)

type Module struct {
Expand Down Expand Up @@ -144,11 +144,15 @@ func (m *Module) CompileWithNGen(gp GasPolicy, numGlobals uint64) (out string, r

for i, f := range m.Base.FunctionIndexSpace {
//fmt.Printf("Compiling function %d (%+v) with %d locals\n", i, f.Sig, len(f.Body.Locals))
d, err := disasm.Disassemble(f, m.Base)
instrs, err := disasm.Disassemble(f.Body.Code)
if err != nil {
panic(err)
}
compiler := NewSSAFunctionCompiler(m.Base, d)
d := disasm.Disassembly{
Code: instrs,
MaxDepth: 512,
}
compiler := NewSSAFunctionCompiler(m.Base, &d)
compiler.CallIndexOffset = numFuncImports
compiler.Compile(importTypeIDs)
if m.DisableFloatingPoint {
Expand Down Expand Up @@ -220,11 +224,15 @@ func (m *Module) CompileForInterpreter(gp GasPolicy) (_retCode []InterpreterCode

for i, f := range m.Base.FunctionIndexSpace {
//fmt.Printf("Compiling function %d (%+v) with %d locals\n", i, f.Sig, len(f.Body.Locals))
d, err := disasm.Disassemble(f, m.Base)
instrs, err := disasm.Disassemble(f.Body.Code)
if err != nil {
panic(err)
}
compiler := NewSSAFunctionCompiler(m.Base, d)
d := disasm.Disassembly{
Code: instrs,
MaxDepth: 512,
}
compiler := NewSSAFunctionCompiler(m.Base, &d)
compiler.CallIndexOffset = numFuncImports
compiler.Compile(importTypeIDs)
if m.DisableFloatingPoint {
Expand Down
4 changes: 2 additions & 2 deletions compiler/ngen.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,13 @@ func (c *SSAFunctionCompiler) NGen(selfID uint64, numParams uint64, numLocals ui
case "i64.store", "f64.store":
writeMemStore(body, ins, "uint64_t")

case "current_memory":
case "memory.size":
bSprintf(body,
"%s%d.vu64 = vm->mem_size / 65536;",
NGEN_VALUE_PREFIX, ins.Target,
)

case "grow_memory":
case "memory.grow":
bSprintf(body,
"%s%d.vu64 = vm->mem_size / 65536; vm->grow_memory(vm, %s%d.vu32 * 65536);",
NGEN_VALUE_PREFIX, ins.Target,
Expand Down
4 changes: 2 additions & 2 deletions compiler/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,10 @@ func (c *SSAFunctionCompiler) Serialize() []byte {
binary.Write(buf, binary.LittleEndian, uint32(v))
}

case "current_memory":
case "memory.size":
binary.Write(buf, binary.LittleEndian, opcodes.CurrentMemory)

case "grow_memory":
case "memory.grow":
binary.Write(buf, binary.LittleEndian, opcodes.GrowMemory)
binary.Write(buf, binary.LittleEndian, uint32(ins.Values[0]))

Expand Down
13 changes: 6 additions & 7 deletions compiler/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package compiler

import (
"fmt"

"math"
"strings"

"github.com/go-interpreter/wagon/disasm"
"github.com/go-interpreter/wagon/wasm"
"strings"
)

type TyValueID uint64
Expand Down Expand Up @@ -267,14 +266,14 @@ func (c *SSAFunctionCompiler) Compile(importTypeIDs []int) {
c.Locations = append(c.Locations, &Location{
CodePos: len(c.Code),
StackDepth: len(c.Stack),
PreserveTop: ins.Block.Signature != wasm.BlockTypeEmpty,
PreserveTop: ins.Block != nil && ins.Block.Signature != wasm.BlockTypeEmpty,
})

case "loop":
c.Locations = append(c.Locations, &Location{
CodePos: len(c.Code),
StackDepth: len(c.Stack),
LoopPreserveTop: ins.Block.Signature != wasm.BlockTypeEmpty,
LoopPreserveTop: ins.Block != nil && ins.Block.Signature != wasm.BlockTypeEmpty,
BrHead: true,
})

Expand All @@ -284,7 +283,7 @@ func (c *SSAFunctionCompiler) Compile(importTypeIDs []int) {
c.Locations = append(c.Locations, &Location{
CodePos: len(c.Code),
StackDepth: len(c.Stack),
PreserveTop: ins.Block.Signature != wasm.BlockTypeEmpty,
PreserveTop: ins.Block != nil && ins.Block.Signature != wasm.BlockTypeEmpty,
IfBlock: true,
})

Expand Down Expand Up @@ -442,12 +441,12 @@ func (c *SSAFunctionCompiler) Compile(importTypeIDs []int) {
c.PushStack(targetValueID)
}

case "current_memory":
case "memory.size":
retID := c.NextValueID()
c.Code = append(c.Code, buildInstr(retID, ins.Op.Name, nil, nil))
c.PushStack(retID)

case "grow_memory":
case "memory.grow":
retID := c.NextValueID()
c.Code = append(c.Code, buildInstr(retID, ins.Op.Name, nil, c.PopStack(1)))
c.PushStack(retID)
Expand Down
Loading