compiler: only calculate functionInfo once

This is a small change that's not really important in itself, but it
avoids duplicate errors in a future commit that adds error messages to
//go:wasmimport.
Этот коммит содержится в:
Ayke van Laethem 2023-05-19 15:24:28 +02:00 коммит произвёл Ron Evans
родитель b336a1561f
коммит 6dba16f28e
2 изменённых файлов: 13 добавлений и 7 удалений

Просмотреть файл

@ -82,6 +82,7 @@ type compilerContext struct {
uintptrType llvm.Type uintptrType llvm.Type
program *ssa.Program program *ssa.Program
diagnostics []error diagnostics []error
functionInfos map[*ssa.Function]functionInfo
astComments map[string]*ast.CommentGroup astComments map[string]*ast.CommentGroup
embedGlobals map[string][]*loader.EmbedFile embedGlobals map[string][]*loader.EmbedFile
pkg *types.Package pkg *types.Package
@ -93,13 +94,14 @@ type compilerContext struct {
// importantly with a newly created LLVM context and module. // importantly with a newly created LLVM context and module.
func newCompilerContext(moduleName string, machine llvm.TargetMachine, config *Config, dumpSSA bool) *compilerContext { func newCompilerContext(moduleName string, machine llvm.TargetMachine, config *Config, dumpSSA bool) *compilerContext {
c := &compilerContext{ c := &compilerContext{
Config: config, Config: config,
DumpSSA: dumpSSA, DumpSSA: dumpSSA,
difiles: make(map[string]llvm.Metadata), difiles: make(map[string]llvm.Metadata),
ditypes: make(map[types.Type]llvm.Metadata), ditypes: make(map[types.Type]llvm.Metadata),
machine: machine, machine: machine,
targetData: machine.CreateTargetData(), targetData: machine.CreateTargetData(),
astComments: map[string]*ast.CommentGroup{}, functionInfos: map[*ssa.Function]functionInfo{},
astComments: map[string]*ast.CommentGroup{},
} }
c.ctx = llvm.NewContext() c.ctx = llvm.NewContext()

Просмотреть файл

@ -239,12 +239,16 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
// present in *ssa.Function, such as the link name and whether it should be // present in *ssa.Function, such as the link name and whether it should be
// exported. // exported.
func (c *compilerContext) getFunctionInfo(f *ssa.Function) functionInfo { func (c *compilerContext) getFunctionInfo(f *ssa.Function) functionInfo {
if info, ok := c.functionInfos[f]; ok {
return info
}
info := functionInfo{ info := functionInfo{
// Pick the default linkName. // Pick the default linkName.
linkName: f.RelString(nil), linkName: f.RelString(nil),
} }
// Check for //go: pragmas, which may change the link name (among others). // Check for //go: pragmas, which may change the link name (among others).
info.parsePragmas(f) info.parsePragmas(f)
c.functionInfos[f] = info
return info return info
} }