Move Compiler.program to Program.program
Этот коммит содержится в:
родитель
e18fd6da16
коммит
3146cc86d4
2 изменённых файлов: 13 добавлений и 12 удалений
18
compiler.go
18
compiler.go
|
@ -46,8 +46,6 @@ type Compiler struct {
|
|||
coroSuspendFunc llvm.Value
|
||||
coroEndFunc llvm.Value
|
||||
coroFreeFunc llvm.Value
|
||||
program *ssa.Program
|
||||
mainPkg *ssa.Package
|
||||
initFuncs []llvm.Value
|
||||
ir *Program
|
||||
}
|
||||
|
@ -73,7 +71,6 @@ func NewCompiler(pkgName, triple string, dumpSSA bool) (*Compiler, error) {
|
|||
c := &Compiler{
|
||||
dumpSSA: dumpSSA,
|
||||
triple: triple,
|
||||
ir: NewProgram(),
|
||||
}
|
||||
|
||||
target, err := llvm.GetTargetFromTriple(triple)
|
||||
|
@ -160,10 +157,9 @@ func (c *Compiler) Parse(mainPath string, buildTags []string) error {
|
|||
}
|
||||
}
|
||||
|
||||
c.program = ssautil.CreateProgram(lprogram, ssa.SanityCheckFunctions|ssa.BareInits)
|
||||
c.program.Build()
|
||||
|
||||
c.mainPkg = c.program.ImportedPackage(mainPath)
|
||||
program := ssautil.CreateProgram(lprogram, ssa.SanityCheckFunctions|ssa.BareInits)
|
||||
program.Build()
|
||||
c.ir = NewProgram(program, mainPath)
|
||||
|
||||
// Make a list of packages in import order.
|
||||
packageList := []*ssa.Package{}
|
||||
|
@ -171,7 +167,7 @@ func (c *Compiler) Parse(mainPath string, buildTags []string) error {
|
|||
worklist := []string{"runtime", mainPath}
|
||||
for len(worklist) != 0 {
|
||||
pkgPath := worklist[0]
|
||||
pkg := c.program.ImportedPackage(pkgPath)
|
||||
pkg := program.ImportedPackage(pkgPath)
|
||||
if pkg == nil {
|
||||
// Non-SSA package (e.g. cgo).
|
||||
packageSet[pkgPath] = struct{}{}
|
||||
|
@ -322,12 +318,12 @@ func (c *Compiler) Parse(mainPath string, buildTags []string) error {
|
|||
|
||||
// Adjust main function.
|
||||
main := c.mod.NamedFunction("main.main")
|
||||
realMain := c.mod.NamedFunction(c.mainPkg.Pkg.Path() + ".main")
|
||||
realMain := c.mod.NamedFunction(c.ir.mainPkg.Pkg.Path() + ".main")
|
||||
if !realMain.IsNil() {
|
||||
main.ReplaceAllUsesWith(realMain)
|
||||
}
|
||||
mainAsync := c.mod.NamedFunction("main.main$async")
|
||||
realMainAsync := c.mod.NamedFunction(c.mainPkg.Pkg.Path() + ".main$async")
|
||||
realMainAsync := c.mod.NamedFunction(c.ir.mainPkg.Pkg.Path() + ".main$async")
|
||||
if !realMainAsync.IsNil() {
|
||||
mainAsync.ReplaceAllUsesWith(realMainAsync)
|
||||
}
|
||||
|
@ -361,7 +357,7 @@ func (c *Compiler) Parse(mainPath string, buildTags []string) error {
|
|||
tuple := llvm.ConstNamedStruct(tupleType, tupleValues)
|
||||
tuples = append(tuples, tuple)
|
||||
for _, method := range meta.Methods {
|
||||
f := c.ir.GetFunction(c.program.MethodValue(method))
|
||||
f := c.ir.GetFunction(program.MethodValue(method))
|
||||
if f.llvmFn.IsNil() {
|
||||
return errors.New("cannot find function: " + f.Name(false))
|
||||
}
|
||||
|
|
7
ir.go
7
ir.go
|
@ -12,6 +12,8 @@ import (
|
|||
// View on all functions, types, and globals in a program, with analysis
|
||||
// results.
|
||||
type Program struct {
|
||||
program *ssa.Program
|
||||
mainPkg *ssa.Package
|
||||
Functions []*Function
|
||||
functionMap map[*ssa.Function]*Function
|
||||
Globals []*Global
|
||||
|
@ -52,8 +54,11 @@ type InterfaceType struct {
|
|||
Methods map[string]*types.Selection
|
||||
}
|
||||
|
||||
func NewProgram() *Program {
|
||||
// Create and intialize a new *Program from a *ssa.Program.
|
||||
func NewProgram(program *ssa.Program, mainPath string) *Program {
|
||||
return &Program{
|
||||
program: program,
|
||||
mainPkg: program.ImportedPackage(mainPath),
|
||||
functionMap: make(map[*ssa.Function]*Function),
|
||||
globalMap: make(map[*ssa.Global]*Global),
|
||||
methodSignatureNames: make(map[string]int),
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче