From 42cddd3260893cdfb36a71129aff61980e969c3d Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 2 Sep 2018 16:00:31 +0200 Subject: [PATCH] Move runtime.TargetBits out of the compiler --- compiler.go | 22 ++++------------------ src/runtime/arch_amd64.go | 3 +++ src/runtime/arch_wasm.go | 3 +++ src/runtime/runtime.go | 3 --- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/compiler.go b/compiler.go index 3d61bf53..31e5de10 100644 --- a/compiler.go +++ b/compiler.go @@ -254,25 +254,11 @@ func (c *Compiler) Parse(mainPath string, buildTags []string) error { g.llvmGlobal = global if !strings.HasPrefix(g.LinkName(), "_extern_") { global.SetLinkage(llvm.InternalLinkage) - if g.LinkName() == "runtime.TargetBits" { - bitness := c.targetData.PointerSize() * 8 - if bitness < 32 { - // Only 8 and 32+ architectures supported at the moment. - // On 8 bit architectures, pointers are normally bigger - // than 8 bits to do anything meaningful. - // TODO: clean up this hack to support 16-bit - // architectures. - bitness = 8 - } - global.SetInitializer(llvm.ConstInt(llvm.Int8Type(), uint64(bitness), false)) - global.SetGlobalConstant(true) - } else { - initializer, err := getZeroValue(llvmType) - if err != nil { - return err - } - global.SetInitializer(initializer) + initializer, err := getZeroValue(llvmType) + if err != nil { + return err } + global.SetInitializer(initializer) } } diff --git a/src/runtime/arch_amd64.go b/src/runtime/arch_amd64.go index 7ca7e6c4..3cf88368 100644 --- a/src/runtime/arch_amd64.go +++ b/src/runtime/arch_amd64.go @@ -6,3 +6,6 @@ const GOARCH = "amd64" // The length type used inside strings and slices. type lenType uint32 + +// The bitness of the CPU (e.g. 8, 32, 64). +const TargetBits = 64 diff --git a/src/runtime/arch_wasm.go b/src/runtime/arch_wasm.go index 3a0557fd..4918df6a 100644 --- a/src/runtime/arch_wasm.go +++ b/src/runtime/arch_wasm.go @@ -6,3 +6,6 @@ const GOARCH = "wasm" // The length type used inside strings and slices. type lenType uint32 + +// The bitness of the CPU (e.g. 8, 32, 64). +const TargetBits = 32 diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go index ea59c60b..07cf049c 100644 --- a/src/runtime/runtime.go +++ b/src/runtime/runtime.go @@ -6,9 +6,6 @@ import ( const Compiler = "tgo" -// The bitness of the CPU (e.g. 8, 32, 64). Set by the compiler as a constant. -var TargetBits uint8 - func Sleep(d Duration) { // This function is treated specially by the compiler: when goroutines are // used, it is transformed into a llvm.coro.suspend() call.