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

Function NewTargetMachine

compiler/compiler.go:223–258  ·  view source on GitHub ↗

NewTargetMachine returns a new llvm.TargetMachine based on the passed-in configuration. It is used by the compiler and is needed for machine code emission.

(config *Config)

Source from the content-addressed store, hash-verified

221// configuration. It is used by the compiler and is needed for machine code
222// emission.
223func NewTargetMachine(config *Config) (llvm.TargetMachine, error) {
224 target, err := llvm.GetTargetFromTriple(config.Triple)
225 if err != nil {
226 return llvm.TargetMachine{}, err
227 }
228
229 var codeModel llvm.CodeModel
230 var relocationModel llvm.RelocMode
231
232 switch config.CodeModel {
233 case "default":
234 codeModel = llvm.CodeModelDefault
235 case "tiny":
236 codeModel = llvm.CodeModelTiny
237 case "small":
238 codeModel = llvm.CodeModelSmall
239 case "kernel":
240 codeModel = llvm.CodeModelKernel
241 case "medium":
242 codeModel = llvm.CodeModelMedium
243 case "large":
244 codeModel = llvm.CodeModelLarge
245 }
246
247 switch config.RelocationModel {
248 case "static":
249 relocationModel = llvm.RelocStatic
250 case "pic":
251 relocationModel = llvm.RelocPIC
252 case "dynamicnopic":
253 relocationModel = llvm.RelocDynamicNoPic
254 }
255
256 machine := target.CreateTargetMachine(config.Triple, config.CPU, config.Features, llvm.CodeGenLevelDefault, relocationModel, codeModel)
257 return machine, nil
258}
259
260// Sizes returns a types.Sizes appropriate for the given target machine. It
261// includes the correct int size and alignment as is necessary for the Go

Callers 4

BuildFunction · 0.92
createEmbedObjectFileFunction · 0.92
compileGoFileForTestingFunction · 0.92
testCompilePackageFunction · 0.85

Calls

no outgoing calls

Tested by 2

compileGoFileForTestingFunction · 0.74
testCompilePackageFunction · 0.68