diff options
author | Ayke van Laethem <[email protected]> | 2019-11-13 20:14:39 +0100 |
---|---|---|
committer | Ayke <[email protected]> | 2019-11-15 23:37:17 +0100 |
commit | e20af665fadb62cfda7c5b174ffed4d7b73c94b3 (patch) | |
tree | f51aa99049bbdbc9e7dd2b79e4b2c906a0f30d86 /compiler/llvm.go | |
parent | 36d119811534752904dad8a369e5587d5750442f (diff) | |
download | tinygo-e20af665fadb62cfda7c5b174ffed4d7b73c94b3.tar.gz tinygo-e20af665fadb62cfda7c5b174ffed4d7b73c94b3.zip |
compiler,transform: move interface lowering to transform package
Diffstat (limited to 'compiler/llvm.go')
-rw-r--r-- | compiler/llvm.go | 39 |
1 files changed, 4 insertions, 35 deletions
diff --git a/compiler/llvm.go b/compiler/llvm.go index 3bd9eeee1..078956657 100644 --- a/compiler/llvm.go +++ b/compiler/llvm.go @@ -1,8 +1,6 @@ package compiler import ( - "reflect" - "github.com/tinygo-org/tinygo/compiler/llvmutil" "tinygo.org/x/go-llvm" ) @@ -130,43 +128,14 @@ func (c *Compiler) splitBasicBlock(afterInst llvm.Value, insertAfter llvm.BasicB // contents, and returns the global. // Note that it is left with the default linkage etc., you should set // linkage/constant/etc properties yourself. -func (c *Compiler) makeGlobalArray(bufItf interface{}, name string, elementType llvm.Type) llvm.Value { - buf := reflect.ValueOf(bufItf) - globalType := llvm.ArrayType(elementType, buf.Len()) +func (c *Compiler) makeGlobalArray(buf []byte, name string, elementType llvm.Type) llvm.Value { + globalType := llvm.ArrayType(elementType, len(buf)) global := llvm.AddGlobal(c.mod, globalType, name) value := llvm.Undef(globalType) - for i := 0; i < buf.Len(); i++ { - ch := buf.Index(i).Uint() + for i := 0; i < len(buf); i++ { + ch := uint64(buf[i]) value = llvm.ConstInsertValue(value, llvm.ConstInt(elementType, ch, false), []uint32{uint32(i)}) } global.SetInitializer(value) return global } - -// getGlobalBytes returns the slice contained in the array of the provided -// global. It can recover the bytes originally created using makeGlobalArray, if -// makeGlobalArray was given a byte slice. -func getGlobalBytes(global llvm.Value) []byte { - value := global.Initializer() - buf := make([]byte, value.Type().ArrayLength()) - for i := range buf { - buf[i] = byte(llvm.ConstExtractValue(value, []uint32{uint32(i)}).ZExtValue()) - } - return buf -} - -// replaceGlobalByteWithArray replaces a global integer type in the module with -// an integer array, using a GEP to make the types match. It is a convenience -// function used for creating reflection sidetables, for example. -func (c *Compiler) replaceGlobalIntWithArray(name string, buf interface{}) llvm.Value { - oldGlobal := c.mod.NamedGlobal(name) - global := c.makeGlobalArray(buf, name+".tmp", oldGlobal.Type().ElementType()) - gep := llvm.ConstGEP(global, []llvm.Value{ - llvm.ConstInt(c.ctx.Int32Type(), 0, false), - llvm.ConstInt(c.ctx.Int32Type(), 0, false), - }) - oldGlobal.ReplaceAllUsesWith(gep) - oldGlobal.EraseFromParentAsGlobal() - global.SetName(name) - return global -} |