MCPcopy
hub / github.com/tinygo-org/tinygo / testCompilePackage

Function testCompilePackage

compiler/compiler_test.go:217–261  ·  view source on GitHub ↗

Build a package given a number of compiler options and a file.

(t *testing.T, options *compileopts.Options, file string)

Source from the content-addressed store, hash-verified

215
216// Build a package given a number of compiler options and a file.
217func testCompilePackage(t *testing.T, options *compileopts.Options, file string) (llvm.Module, []error) {
218 target, err := compileopts.LoadTarget(options)
219 if err != nil {
220 t.Fatal("failed to load target:", err)
221 }
222 config := &compileopts.Config{
223 Options: options,
224 Target: target,
225 }
226 compilerConfig := &Config{
227 Triple: config.Triple(),
228 Features: config.Features(),
229 ABI: config.ABI(),
230 GOOS: config.GOOS(),
231 GOARCH: config.GOARCH(),
232 CodeModel: config.CodeModel(),
233 RelocationModel: config.RelocationModel(),
234 Scheduler: config.Scheduler(),
235 AutomaticStackSize: config.AutomaticStackSize(),
236 DefaultStackSize: config.StackSize(),
237 NeedsStackObjects: config.NeedsStackObjects(),
238 }
239 machine, err := NewTargetMachine(compilerConfig)
240 if err != nil {
241 t.Fatal("failed to create target machine:", err)
242 }
243 defer machine.Dispose()
244
245 // Load entire program AST into memory.
246 lprogram, err := loader.Load(config, "./testdata/"+file, types.Config{
247 Sizes: Sizes(machine),
248 })
249 if err != nil {
250 t.Fatal("failed to create target machine:", err)
251 }
252 err = lprogram.Parse()
253 if err != nil {
254 t.Fatalf("could not parse test case %s: %s", file, err)
255 }
256
257 // Compile AST to IR.
258 program := lprogram.LoadSSA()
259 pkg := lprogram.MainPkg()
260 return CompilePackage(file, pkg, program.Package(pkg.Pkg), machine, compilerConfig, false)
261}

Callers 2

TestCompilerFunction · 0.85
TestCompilerErrorsFunction · 0.85

Calls 15

TripleMethod · 0.95
FeaturesMethod · 0.95
ABIMethod · 0.95
GOOSMethod · 0.95
GOARCHMethod · 0.95
CodeModelMethod · 0.95
RelocationModelMethod · 0.95
SchedulerMethod · 0.95
AutomaticStackSizeMethod · 0.95
StackSizeMethod · 0.95
NeedsStackObjectsMethod · 0.95
LoadTargetFunction · 0.92

Tested by

no test coverage detected