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)
| 221 | // configuration. It is used by the compiler and is needed for machine code |
| 222 | // emission. |
| 223 | func 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 |
no outgoing calls