mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
a848d720db
This commit finally introduces unit tests for the compiler, to check whether input Go code is converted to the expected output IR. To make this necessary, a few refactors were needed. Hopefully these refactors (to compile a program package by package instead of all at once) will eventually become standard, so that packages can all be compiled separate from each other and be cached between compiles.
27 lines
777 B
Go
27 lines
777 B
Go
package loader
|
|
|
|
import (
|
|
"golang.org/x/tools/go/ssa"
|
|
)
|
|
|
|
// LoadSSA constructs the SSA form of the loaded packages.
|
|
//
|
|
// The program must already be parsed and type-checked with the .Parse() method.
|
|
func (p *Program) LoadSSA() *ssa.Program {
|
|
prog := ssa.NewProgram(p.fset, ssa.SanityCheckFunctions|ssa.BareInits|ssa.GlobalDebug)
|
|
|
|
for _, pkg := range p.sorted {
|
|
prog.CreatePackage(pkg.Pkg, pkg.Files, &pkg.info, true)
|
|
}
|
|
|
|
return prog
|
|
}
|
|
|
|
// LoadSSA constructs the SSA form of this package.
|
|
//
|
|
// The program must already be parsed and type-checked with the .Parse() method.
|
|
func (p *Package) LoadSSA() *ssa.Package {
|
|
prog := ssa.NewProgram(p.program.fset, ssa.SanityCheckFunctions|ssa.BareInits|ssa.GlobalDebug)
|
|
return prog.CreatePackage(p.Pkg, p.Files, &p.info, true)
|
|
}
|