Skip to content

Commit 3b137dd

Browse files
neelancebradfitz
authored andcommitted
cmd/compile: add wasm architecture
This commit adds the wasm architecture to the compile command. A later commit will contain the corresponding linker changes. Design doc: https://docs.google.com/document/d/131vjr4DH6JFnb-blm_uRdaC0_Nv3OUwjEY5qVCxCup4 The following files are generated: - src/cmd/compile/internal/ssa/opGen.go - src/cmd/compile/internal/ssa/rewriteWasm.go - src/cmd/internal/obj/wasm/anames.go Updates golang#18892 Change-Id: Ifb4a96a3e427aac2362a1c97967d5667450fba3b Reviewed-on: https://go-review.googlesource.com/103295 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
1 parent a9fc375 commit 3b137dd

File tree

25 files changed

+9976
-101
lines changed

25 files changed

+9976
-101
lines changed

src/cmd/asm/internal/arch/arch.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"cmd/internal/obj/mips"
1212
"cmd/internal/obj/ppc64"
1313
"cmd/internal/obj/s390x"
14+
"cmd/internal/obj/wasm"
1415
"cmd/internal/obj/x86"
1516
"fmt"
1617
"strings"
@@ -87,6 +88,8 @@ func Set(GOARCH string) *Arch {
8788
a := archS390x()
8889
a.LinkArch = &s390x.Links390x
8990
return a
91+
case "wasm":
92+
return archWasm()
9093
}
9194
return nil
9295
}
@@ -95,6 +98,10 @@ func jumpX86(word string) bool {
9598
return word[0] == 'J' || word == "CALL" || strings.HasPrefix(word, "LOOP") || word == "XBEGIN"
9699
}
97100

101+
func jumpWasm(word string) bool {
102+
return word == "JMP" || word == "CALL" || word == "Call" || word == "Br" || word == "BrIf"
103+
}
104+
98105
func archX86(linkArch *obj.LinkArch) *Arch {
99106
register := make(map[string]int16)
100107
// Create maps for easy lookup of instruction names etc.
@@ -577,3 +584,24 @@ func archS390x() *Arch {
577584
IsJump: jumpS390x,
578585
}
579586
}
587+
588+
func archWasm() *Arch {
589+
instructions := make(map[string]obj.As)
590+
for i, s := range obj.Anames {
591+
instructions[s] = obj.As(i)
592+
}
593+
for i, s := range wasm.Anames {
594+
if obj.As(i) >= obj.A_ARCHSPECIFIC {
595+
instructions[s] = obj.As(i) + obj.ABaseWasm
596+
}
597+
}
598+
599+
return &Arch{
600+
LinkArch: &wasm.Linkwasm,
601+
Instructions: instructions,
602+
Register: wasm.Register,
603+
RegisterPrefix: nil,
604+
RegisterNumber: nilRegisterNumber,
605+
IsJump: jumpWasm,
606+
}
607+
}

src/cmd/asm/internal/asm/asm.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,13 @@ func (p *Parser) asmJump(op obj.As, cond string, a []obj.Addr) {
343343
As: op,
344344
}
345345
switch len(a) {
346+
case 0:
347+
if p.arch.Family == sys.Wasm {
348+
target = &obj.Addr{Type: obj.TYPE_NONE}
349+
break
350+
}
351+
p.errorf("wrong number of arguments to %s instruction", op)
352+
return
346353
case 1:
347354
target = &a[0]
348355
case 2:
@@ -445,6 +452,8 @@ func (p *Parser) asmJump(op obj.As, cond string, a []obj.Addr) {
445452
case target.Type == obj.TYPE_CONST:
446453
// JMP $4
447454
prog.To = a[0]
455+
case target.Type == obj.TYPE_NONE:
456+
// JMP
448457
default:
449458
p.errorf("cannot assemble jump %+v", target)
450459
return

src/cmd/compile/internal/gc/go.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,12 @@ var (
311311
// GO386=387
312312
ControlWord64trunc,
313313
ControlWord32 *obj.LSym
314+
315+
// Wasm
316+
WasmMove,
317+
WasmZero,
318+
WasmDiv,
319+
WasmTruncS,
320+
WasmTruncU,
321+
SigPanic *obj.LSym
314322
)

src/cmd/compile/internal/gc/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func Main(archInit func(*Arch)) {
180180
gopkg = types.NewPkg("go", "")
181181

182182
Nacl = objabi.GOOS == "nacl"
183+
Wasm := objabi.GOARCH == "wasm"
183184

184185
flag.BoolVar(&compiling_runtime, "+", false, "compiling runtime")
185186
flag.BoolVar(&compiling_std, "std", false, "compiling standard library")
@@ -200,7 +201,7 @@ func Main(archInit func(*Arch)) {
200201
flag.IntVar(&nBackendWorkers, "c", 1, "concurrency during compilation, 1 means no concurrency")
201202
flag.BoolVar(&pure_go, "complete", false, "compiling complete package (no C or assembly)")
202203
flag.StringVar(&debugstr, "d", "", "print debug information about items in `list`; try -d help")
203-
flag.BoolVar(&flagDWARF, "dwarf", true, "generate DWARF symbols")
204+
flag.BoolVar(&flagDWARF, "dwarf", !Wasm, "generate DWARF symbols")
204205
flag.BoolVar(&Ctxt.Flag_locationlists, "dwarflocationlists", true, "add location lists to DWARF in optimized mode")
205206
flag.IntVar(&genDwarfInline, "gendwarfinl", 2, "generate DWARF inline info records")
206207
objabi.Flagcount("e", "no limit on number of errors reported", &Debug['e'])
@@ -265,6 +266,7 @@ func Main(archInit func(*Arch)) {
265266
} else {
266267
// turn off inline generation if no dwarf at all
267268
genDwarfInline = 0
269+
Ctxt.Flag_locationlists = false
268270
}
269271

270272
if flag.NArg() < 1 && debugstr != "help" && debugstr != "ssa/help" {

src/cmd/compile/internal/gc/ssa.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ func initssaconfig() {
8787
// GO386=387 runtime functions
8888
ControlWord64trunc = sysfunc("controlWord64trunc")
8989
ControlWord32 = sysfunc("controlWord32")
90+
91+
// Wasm
92+
WasmMove = sysfunc("wasmMove")
93+
WasmZero = sysfunc("wasmZero")
94+
WasmDiv = sysfunc("wasmDiv")
95+
WasmTruncS = sysfunc("wasmTruncS")
96+
WasmTruncU = sysfunc("wasmTruncU")
97+
SigPanic = sysfunc("sigpanic")
9098
}
9199

92100
// buildssa builds an SSA function for fn.
@@ -1794,7 +1802,7 @@ func (s *state) expr(n *Node) *ssa.Value {
17941802
conv = conv1
17951803
}
17961804
}
1797-
if thearch.LinkArch.Family == sys.ARM64 || s.softFloat {
1805+
if thearch.LinkArch.Family == sys.ARM64 || thearch.LinkArch.Family == sys.Wasm || s.softFloat {
17981806
if conv1, ok1 := uint64fpConvOpToSSA[twoTypes{s.concreteEtype(ft), s.concreteEtype(tt)}]; ok1 {
17991807
conv = conv1
18001808
}
@@ -5222,7 +5230,7 @@ func (s *SSAGenState) Call(v *ssa.Value) *obj.Prog {
52225230
} else {
52235231
// TODO(mdempsky): Can these differences be eliminated?
52245232
switch thearch.LinkArch.Family {
5225-
case sys.AMD64, sys.I386, sys.PPC64, sys.S390X:
5233+
case sys.AMD64, sys.I386, sys.PPC64, sys.S390X, sys.Wasm:
52265234
p.To.Type = obj.TYPE_REG
52275235
case sys.ARM, sys.ARM64, sys.MIPS, sys.MIPS64:
52285236
p.To.Type = obj.TYPE_MEM

src/cmd/compile/internal/ssa/config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,20 @@ func NewConfig(arch string, types Types, ctxt *obj.Link, optimize bool) *Config
311311
c.LinkReg = linkRegMIPS
312312
c.hasGReg = true
313313
c.noDuffDevice = true
314+
case "wasm":
315+
c.PtrSize = 8
316+
c.RegSize = 8
317+
c.lowerBlock = rewriteBlockWasm
318+
c.lowerValue = rewriteValueWasm
319+
c.registers = registersWasm[:]
320+
c.gpRegMask = gpRegMaskWasm
321+
c.fpRegMask = fpRegMaskWasm
322+
c.FPReg = framepointerRegWasm
323+
c.LinkReg = linkRegWasm
324+
c.hasGReg = true
325+
c.noDuffDevice = true
326+
c.useAvg = false
327+
c.useHmul = false
314328
default:
315329
ctxt.Diag("arch %s not implemented", arch)
316330
}

0 commit comments

Comments
 (0)