Build a package given a number of compiler options and a file.
(t *testing.T, options *compileopts.Options, file string)
| 215 | |
| 216 | // Build a package given a number of compiler options and a file. |
| 217 | func 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 | } |
no test coverage detected