mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-17 03:03:27 +00:00
compiler: move math aliases from the runtime to the compiler
This makes them more flexible, especially with Go 1.17 making the situation more complicated (see https://github.com/golang/go/commit/1d20a362d0ca4898d77865e314ef6f73582daef0). It also makes it possible to do the same for many other functions, such as assembly implementations of cryptographich functions which are similarly dependent on the architecture.
This commit is contained in:
committed by
Ron Evans
parent
58565b42cc
commit
a3c4421f39
+24
-1
@@ -23,7 +23,7 @@ import (
|
||||
// Version of the compiler pacakge. Must be incremented each time the compiler
|
||||
// package changes in a way that affects the generated LLVM module.
|
||||
// This version is independent of the TinyGo version number.
|
||||
const Version = 13 // last change: implement LLVM math builtins in the compiler
|
||||
const Version = 14 // last change: add math assembly aliases
|
||||
|
||||
func init() {
|
||||
llvm.InitializeAllTargets()
|
||||
@@ -768,6 +768,29 @@ func (c *compilerContext) createPackage(irbuilder llvm.Builder, pkg *ssa.Package
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add forwarding functions for functions that would otherwise be
|
||||
// implemented in assembly.
|
||||
for _, name := range members {
|
||||
member := pkg.Members[name]
|
||||
switch member := member.(type) {
|
||||
case *ssa.Function:
|
||||
if member.Blocks != nil {
|
||||
continue // external function
|
||||
}
|
||||
info := c.getFunctionInfo(member)
|
||||
if aliasName, ok := stdlibAliases[info.linkName]; ok {
|
||||
alias := c.mod.NamedFunction(aliasName)
|
||||
if alias.IsNil() {
|
||||
// Shouldn't happen, but perhaps best to just ignore.
|
||||
// The error will be a link error, if there is an error.
|
||||
continue
|
||||
}
|
||||
b := newBuilder(c, irbuilder, member)
|
||||
b.createAlias(alias)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// createFunction builds the LLVM IR implementation for this function. The
|
||||
|
||||
Reference in New Issue
Block a user