aboutsummaryrefslogtreecommitdiffhomepage
path: root/compiler
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2023-03-04 22:39:40 +0100
committerAyke <[email protected]>2023-03-05 07:50:42 -0800
commit1d86b3f425c8b83df221b039c530afd9bec3fef2 (patch)
treefdccca3ce5b3798cd15024fbec329ff2f67dc9f4 /compiler
parentf9b6f8339b61158eb880e6a5da4c5b829494f046 (diff)
downloadtinygo-1d86b3f425c8b83df221b039c530afd9bec3fef2.tar.gz
tinygo-1d86b3f425c8b83df221b039c530afd9bec3fef2.zip
compiler: add debug info to []embed.files backing array
Diffstat (limited to 'compiler')
-rw-r--r--compiler/compiler.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/compiler/compiler.go b/compiler/compiler.go
index 264dfdc5c..c02dcdc3b 100644
--- a/compiler/compiler.go
+++ b/compiler/compiler.go
@@ -1010,10 +1010,11 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu
})
// Make the backing array for the []files slice. This is a LLVM global.
- embedFileStructType := c.getLLVMType(typ.Field(0).Type().(*types.Pointer).Elem().(*types.Slice).Elem())
+ embedFileStructType := typ.Field(0).Type().(*types.Pointer).Elem().(*types.Slice).Elem()
+ llvmEmbedFileStructType := c.getLLVMType(embedFileStructType)
var fileStructs []llvm.Value
for _, file := range allFiles {
- fileStruct := llvm.ConstNull(embedFileStructType)
+ fileStruct := llvm.ConstNull(llvmEmbedFileStructType)
name := c.createConst(ssa.NewConst(constant.MakeString(file.Name), types.Typ[types.String]))
fileStruct = c.builder.CreateInsertValue(fileStruct, name, 0, "") // "name" field
if file.Hash != "" {
@@ -1022,13 +1023,25 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu
}
fileStructs = append(fileStructs, fileStruct)
}
- sliceDataInitializer := llvm.ConstArray(embedFileStructType, fileStructs)
+ sliceDataInitializer := llvm.ConstArray(llvmEmbedFileStructType, fileStructs)
sliceDataGlobal := llvm.AddGlobal(c.mod, sliceDataInitializer.Type(), c.pkg.Path()+"$embedfsfiles")
sliceDataGlobal.SetInitializer(sliceDataInitializer)
sliceDataGlobal.SetLinkage(llvm.InternalLinkage)
sliceDataGlobal.SetGlobalConstant(true)
sliceDataGlobal.SetUnnamedAddr(true)
sliceDataGlobal.SetAlignment(c.targetData.ABITypeAlignment(sliceDataInitializer.Type()))
+ if c.Debug {
+ // Add debug information for code size attribution (among others).
+ position := c.program.Fset.Position(member.Pos())
+ diglobal := c.dibuilder.CreateGlobalVariableExpression(llvm.Metadata{}, llvm.DIGlobalVariableExpression{
+ File: c.getDIFile(position.Filename),
+ Line: position.Line,
+ Type: c.getDIType(types.NewArray(embedFileStructType, int64(len(allFiles)))),
+ LocalToUnit: true,
+ Expr: c.dibuilder.CreateExpression(nil),
+ })
+ sliceDataGlobal.AddMetadata(0, diglobal)
+ }
// Create the slice object itself.
// Because embed.FS refers to it as *[]embed.file instead of a plain