mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 07:23:39 +00:00
compiler: refactor some code for the next commit
This is a pure refactor, it doesn't change the behavior of anything. It's separate from the next commit so that the actual changes are easier to read.
This commit is contained in:
committed by
Ron Evans
parent
783c6a813a
commit
5c622cfc43
@@ -195,3 +195,22 @@ func SplitBasicBlock(builder llvm.Builder, afterInst llvm.Value, insertAfter llv
|
||||
|
||||
return newBlock
|
||||
}
|
||||
|
||||
// Append the given values to the llvm.used array. The values can be any pointer
|
||||
// type, they will be bitcast to i8*.
|
||||
func AppendToUsedGlobals(mod llvm.Module, values ...llvm.Value) {
|
||||
if !mod.NamedGlobal("llvm.used").IsNil() {
|
||||
// Sanity check. TODO: we don't emit such a global at the moment, but
|
||||
// when we do we should append to it instead.
|
||||
panic("todo: append to existing llvm.used")
|
||||
}
|
||||
i8ptrType := llvm.PointerType(mod.Context().Int8Type(), 0)
|
||||
var castValues []llvm.Value
|
||||
for _, value := range values {
|
||||
castValues = append(castValues, llvm.ConstBitCast(value, i8ptrType))
|
||||
}
|
||||
usedInitializer := llvm.ConstArray(i8ptrType, castValues)
|
||||
used := llvm.AddGlobal(mod, usedInitializer.Type(), "llvm.used")
|
||||
used.SetInitializer(usedInitializer)
|
||||
used.SetLinkage(llvm.AppendingLinkage)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user