From bf160d096bbf3ff8420c63960da7277f37cece8b Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 29 Aug 2018 20:48:56 +0200 Subject: [PATCH] Move lenType definition to runtime (partially) --- compiler.go | 2 +- main.go | 8 ++++++-- src/runtime/arch_amd64.go | 8 ++++++++ src/runtime/arch_wasm.go | 8 ++++++++ src/runtime/hashmap.go | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 src/runtime/arch_amd64.go create mode 100644 src/runtime/arch_wasm.go diff --git a/compiler.go b/compiler.go index 3ea277b6..a01d8d41 100644 --- a/compiler.go +++ b/compiler.go @@ -88,7 +88,7 @@ func NewCompiler(pkgName, triple string, dumpSSA bool) (*Compiler, error) { // Depends on platform (32bit or 64bit), but fix it here for now. c.intType = llvm.Int32Type() - c.lenType = llvm.Int32Type() + c.lenType = llvm.Int32Type() // also defined as runtime.lenType c.uintptrType = c.targetData.IntPtrType() c.i8ptrType = llvm.PointerType(llvm.Int8Type(), 0) diff --git a/main.go b/main.go index 0e0ad398..e2a9a137 100644 --- a/main.go +++ b/main.go @@ -13,11 +13,15 @@ func Compile(pkgName, runtimePath, outpath, target string, printIR, dumpSSA bool var buildTags []string // TODO: put this somewhere else if target == "pca10040" { - buildTags = append(buildTags, "nrf", "nrf52", "nrf52832") + // Pretend to be a WASM target, not ARM (for standard library support). + buildTags = append(buildTags, "nrf", "nrf52", "nrf52832", "js", "wasm") target = "armv7m-none-eabi" } else if target == "arduino" { - buildTags = append(buildTags, "avr", "avr8", "atmega", "atmega328p") + // Pretend to be a WASM target, not AVR (for standard library support). + buildTags = append(buildTags, "avr", "avr8", "atmega", "atmega328p", "js", "wasm") target = "avr--" + } else { + buildTags = append(buildTags, "linux", "amd64") } c, err := NewCompiler(pkgName, target, dumpSSA) diff --git a/src/runtime/arch_amd64.go b/src/runtime/arch_amd64.go new file mode 100644 index 00000000..7ca7e6c4 --- /dev/null +++ b/src/runtime/arch_amd64.go @@ -0,0 +1,8 @@ +// +build amd64 + +package runtime + +const GOARCH = "amd64" + +// The length type used inside strings and slices. +type lenType uint32 diff --git a/src/runtime/arch_wasm.go b/src/runtime/arch_wasm.go new file mode 100644 index 00000000..3a0557fd --- /dev/null +++ b/src/runtime/arch_wasm.go @@ -0,0 +1,8 @@ +// +build wasm + +package runtime + +const GOARCH = "wasm" + +// The length type used inside strings and slices. +type lenType uint32 diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index 3ab97cd3..cbdb5ede 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -13,7 +13,7 @@ import ( type hashmap struct { next *hashmap // hashmap after evacuate (for iterators) buckets unsafe.Pointer // pointer to array of buckets - count uint + count lenType keySize uint8 // maybe this can store the key type as well? E.g. keysize == 5 means string? valueSize uint8 bucketBits uint8