compileGoFileForTesting compiles the given Go file to run tests against. Only the given Go file is compiled (no dependencies) and no optimizations are run. If there are any errors, they are reported via the *testing.T instance.
(t *testing.T, filename string)
| 120 | // run. |
| 121 | // If there are any errors, they are reported via the *testing.T instance. |
| 122 | func compileGoFileForTesting(t *testing.T, filename string) llvm.Module { |
| 123 | target, err := compileopts.LoadTarget(&compileopts.Options{GOOS: "linux", GOARCH: "386"}) |
| 124 | if err != nil { |
| 125 | t.Fatal("failed to load target:", err) |
| 126 | } |
| 127 | config := &compileopts.Config{ |
| 128 | Options: &compileopts.Options{}, |
| 129 | Target: target, |
| 130 | } |
| 131 | compilerConfig := &compiler.Config{ |
| 132 | Triple: config.Triple(), |
| 133 | GOOS: config.GOOS(), |
| 134 | GOARCH: config.GOARCH(), |
| 135 | CodeModel: config.CodeModel(), |
| 136 | RelocationModel: config.RelocationModel(), |
| 137 | Scheduler: config.Scheduler(), |
| 138 | AutomaticStackSize: config.AutomaticStackSize(), |
| 139 | Debug: true, |
| 140 | PanicStrategy: config.PanicStrategy(), |
| 141 | } |
| 142 | machine, err := compiler.NewTargetMachine(compilerConfig) |
| 143 | if err != nil { |
| 144 | t.Fatal("failed to create target machine:", err) |
| 145 | } |
| 146 | defer machine.Dispose() |
| 147 | |
| 148 | // Load entire program AST into memory. |
| 149 | lprogram, err := loader.Load(config, filename, types.Config{ |
| 150 | Sizes: compiler.Sizes(machine), |
| 151 | }) |
| 152 | if err != nil { |
| 153 | t.Fatal("failed to create target machine:", err) |
| 154 | } |
| 155 | err = lprogram.Parse() |
| 156 | if err != nil { |
| 157 | t.Fatal("could not parse", err) |
| 158 | } |
| 159 | |
| 160 | // Compile AST to IR. |
| 161 | program := lprogram.LoadSSA() |
| 162 | pkg := lprogram.MainPkg() |
| 163 | mod, errs := compiler.CompilePackage(filename, pkg, program.Package(pkg.Pkg), machine, compilerConfig, false) |
| 164 | if errs != nil { |
| 165 | for _, err := range errs { |
| 166 | t.Error(err) |
| 167 | } |
| 168 | t.FailNow() |
| 169 | } |
| 170 | return mod |
| 171 | } |
| 172 | |
| 173 | // getPosition returns the position information for the given value, as far as |
| 174 | // it is available. |
no test coverage detected