compiler: refactor and add tests

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.
This commit is contained in:
Ayke van Laethem
2021-01-13 17:22:13 +01:00
committed by Ron Evans
parent dbc438b2ae
commit a848d720db
12 changed files with 610 additions and 100 deletions
+8
View File
@@ -16,3 +16,11 @@ func (p *Program) LoadSSA() *ssa.Program {
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)
}