compiler: move SSA construction to ir.go
Этот коммит содержится в:
родитель
2496ae9967
коммит
2ca2220e44
2 изменённых файлов: 9 добавлений и 7 удалений
|
@ -17,7 +17,6 @@ import (
|
|||
"go/parser"
|
||||
"golang.org/x/tools/go/loader"
|
||||
"golang.org/x/tools/go/ssa"
|
||||
"golang.org/x/tools/go/ssa/ssautil"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -179,9 +178,7 @@ func (c *Compiler) Parse(mainPath string, buildTags []string) error {
|
|||
}
|
||||
}
|
||||
|
||||
program := ssautil.CreateProgram(lprogram, ssa.SanityCheckFunctions|ssa.BareInits|ssa.GlobalDebug)
|
||||
program.Build()
|
||||
c.ir = NewProgram(program, mainPath)
|
||||
c.ir = NewProgram(lprogram, mainPath)
|
||||
|
||||
// Make a list of packages in import order.
|
||||
packageList := []*ssa.Package{}
|
||||
|
@ -189,7 +186,7 @@ func (c *Compiler) Parse(mainPath string, buildTags []string) error {
|
|||
worklist := []string{"runtime", mainPath}
|
||||
for len(worklist) != 0 {
|
||||
pkgPath := worklist[0]
|
||||
pkg := program.ImportedPackage(pkgPath)
|
||||
pkg := c.ir.program.ImportedPackage(pkgPath)
|
||||
if pkg == nil {
|
||||
// Non-SSA package (e.g. cgo).
|
||||
packageSet[pkgPath] = struct{}{}
|
||||
|
@ -444,7 +441,7 @@ func (c *Compiler) Parse(mainPath string, buildTags []string) error {
|
|||
}
|
||||
c.ir.SortMethods(methods)
|
||||
for _, method := range methods {
|
||||
f := c.ir.GetFunction(program.MethodValue(method))
|
||||
f := c.ir.GetFunction(c.ir.program.MethodValue(method))
|
||||
if f.llvmFn.IsNil() {
|
||||
return errors.New("cannot find function: " + f.LinkName())
|
||||
}
|
||||
|
|
7
ir.go
7
ir.go
|
@ -7,7 +7,9 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/aykevl/llvm/bindings/go/llvm"
|
||||
"golang.org/x/tools/go/loader"
|
||||
"golang.org/x/tools/go/ssa"
|
||||
"golang.org/x/tools/go/ssa/ssautil"
|
||||
)
|
||||
|
||||
// This file provides a wrapper around go/ssa values and adds extra
|
||||
|
@ -74,7 +76,10 @@ type Interface struct {
|
|||
}
|
||||
|
||||
// Create and intialize a new *Program from a *ssa.Program.
|
||||
func NewProgram(program *ssa.Program, mainPath string) *Program {
|
||||
func NewProgram(lprogram *loader.Program, mainPath string) *Program {
|
||||
program := ssautil.CreateProgram(lprogram, ssa.SanityCheckFunctions|ssa.BareInits|ssa.GlobalDebug)
|
||||
program.Build()
|
||||
|
||||
return &Program{
|
||||
program: program,
|
||||
mainPkg: program.ImportedPackage(mainPath),
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче