Skip to content

Commit cd517a3

Browse files
aykevldeadprogram
authored andcommitted
transform: split interface and reflect lowering
These two passes are related, but can definitely work independently. Which is what this change does: it splits the two passes. This should make it easier to change these two new passes in the future. This change now also enables slightly better testing by testing these two passes independently. In particular, the reflect lowering pass got some actual tests: it was barely unit-tested before. I have verified that this doesn't really change code size, at least not on the microbit target. Two tests do change, but in a very minor way (and in opposite direction).
1 parent 52d8655 commit cd517a3

File tree

10 files changed

+395
-280
lines changed

10 files changed

+395
-280
lines changed

transform/allocs_test.go

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package transform_test
22

33
import (
44
"go/token"
5-
"go/types"
65
"io/ioutil"
76
"path/filepath"
87
"regexp"
@@ -11,9 +10,6 @@ import (
1110
"strings"
1211
"testing"
1312

14-
"github.com/tinygo-org/tinygo/compileopts"
15-
"github.com/tinygo-org/tinygo/compiler"
16-
"github.com/tinygo-org/tinygo/loader"
1713
"github.com/tinygo-org/tinygo/transform"
1814
"tinygo.org/x/go-llvm"
1915
)
@@ -39,52 +35,7 @@ func (out allocsTestOutput) String() string {
3935
func TestAllocs2(t *testing.T) {
4036
t.Parallel()
4137

42-
target, err := compileopts.LoadTarget("i686--linux")
43-
if err != nil {
44-
t.Fatal("failed to load target:", err)
45-
}
46-
config := &compileopts.Config{
47-
Options: &compileopts.Options{},
48-
Target: target,
49-
}
50-
compilerConfig := &compiler.Config{
51-
Triple: config.Triple(),
52-
GOOS: config.GOOS(),
53-
GOARCH: config.GOARCH(),
54-
CodeModel: config.CodeModel(),
55-
RelocationModel: config.RelocationModel(),
56-
Scheduler: config.Scheduler(),
57-
FuncImplementation: config.FuncImplementation(),
58-
AutomaticStackSize: config.AutomaticStackSize(),
59-
Debug: true,
60-
}
61-
machine, err := compiler.NewTargetMachine(compilerConfig)
62-
if err != nil {
63-
t.Fatal("failed to create target machine:", err)
64-
}
65-
66-
// Load entire program AST into memory.
67-
lprogram, err := loader.Load(config, []string{"./testdata/allocs2.go"}, config.ClangHeaders, types.Config{
68-
Sizes: compiler.Sizes(machine),
69-
})
70-
if err != nil {
71-
t.Fatal("failed to create target machine:", err)
72-
}
73-
err = lprogram.Parse()
74-
if err != nil {
75-
t.Fatal("could not parse", err)
76-
}
77-
78-
// Compile AST to IR.
79-
program := lprogram.LoadSSA()
80-
pkg := lprogram.MainPkg()
81-
mod, errs := compiler.CompilePackage("allocs2.go", pkg, program.Package(pkg.Pkg), machine, compilerConfig, false)
82-
if errs != nil {
83-
for _, err := range errs {
84-
t.Error(err)
85-
}
86-
return
87-
}
38+
mod := compileGoFileForTesting(t, "./testdata/allocs2.go")
8839

8940
// Run functionattrs pass, which is necessary for escape analysis.
9041
pm := llvm.NewPassManager()

0 commit comments

Comments
 (0)