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

Function Sizes

compiler/compiler.go:263–288  ·  view source on GitHub ↗

Sizes returns a types.Sizes appropriate for the given target machine. It includes the correct int size and alignment as is necessary for the Go typechecker.

(machine llvm.TargetMachine)

Source from the content-addressed store, hash-verified

261// includes the correct int size and alignment as is necessary for the Go
262// typechecker.
263func Sizes(machine llvm.TargetMachine) types.Sizes {
264 targetData := machine.CreateTargetData()
265 defer targetData.Dispose()
266
267 var intWidth int
268 if targetData.PointerSize() <= 4 {
269 // 8, 16, 32 bits targets
270 intWidth = 32
271 } else if targetData.PointerSize() == 8 {
272 // 64 bits target
273 intWidth = 64
274 } else {
275 panic("unknown pointer size")
276 }
277
278 // Construct a complex128 type because that's likely the type with the
279 // biggest alignment on most/all ABIs.
280 ctx := llvm.NewContext()
281 defer ctx.Dispose()
282 complex128Type := ctx.StructType([]llvm.Type{ctx.DoubleType(), ctx.DoubleType()}, false)
283 return &stdSizes{
284 IntSize: int64(intWidth / 8),
285 PtrSize: int64(targetData.PointerSize()),
286 MaxAlign: int64(targetData.ABITypeAlignment(complex128Type)),
287 }
288}
289
290// CompilePackage compiles a single package to a LLVM module.
291func CompilePackage(moduleName string, pkg *loader.Package, ssaPkg *ssa.Package, machine llvm.TargetMachine, config *Config, dumpSSA bool) (llvm.Module, []error) {

Callers 3

BuildFunction · 0.92
compileGoFileForTestingFunction · 0.92
testCompilePackageFunction · 0.85

Calls

no outgoing calls

Tested by 2

compileGoFileForTestingFunction · 0.74
testCompilePackageFunction · 0.68