compiler: add debug info to []embed.files backing array
Этот коммит содержится в:
родитель
f9b6f8339b
коммит
1d86b3f425
2 изменённых файлов: 17 добавлений и 4 удалений
|
@ -117,7 +117,7 @@ var (
|
||||||
// alloc: heap allocations during init interpretation
|
// alloc: heap allocations during init interpretation
|
||||||
// pack: data created when storing a constant in an interface for example
|
// pack: data created when storing a constant in an interface for example
|
||||||
// string: buffer behind strings
|
// string: buffer behind strings
|
||||||
packageSymbolRegexp = regexp.MustCompile(`\$(alloc|embedfsfiles|embedfsslice|embedslice|pack|string)(\.[0-9]+)?$`)
|
packageSymbolRegexp = regexp.MustCompile(`\$(alloc|embedfsslice|embedslice|pack|string)(\.[0-9]+)?$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// readProgramSizeFromDWARF reads the source location for each line of code and
|
// readProgramSizeFromDWARF reads the source location for each line of code and
|
||||||
|
|
|
@ -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.
|
// 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
|
var fileStructs []llvm.Value
|
||||||
for _, file := range allFiles {
|
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]))
|
name := c.createConst(ssa.NewConst(constant.MakeString(file.Name), types.Typ[types.String]))
|
||||||
fileStruct = c.builder.CreateInsertValue(fileStruct, name, 0, "") // "name" field
|
fileStruct = c.builder.CreateInsertValue(fileStruct, name, 0, "") // "name" field
|
||||||
if file.Hash != "" {
|
if file.Hash != "" {
|
||||||
|
@ -1022,13 +1023,25 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu
|
||||||
}
|
}
|
||||||
fileStructs = append(fileStructs, fileStruct)
|
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 := llvm.AddGlobal(c.mod, sliceDataInitializer.Type(), c.pkg.Path()+"$embedfsfiles")
|
||||||
sliceDataGlobal.SetInitializer(sliceDataInitializer)
|
sliceDataGlobal.SetInitializer(sliceDataInitializer)
|
||||||
sliceDataGlobal.SetLinkage(llvm.InternalLinkage)
|
sliceDataGlobal.SetLinkage(llvm.InternalLinkage)
|
||||||
sliceDataGlobal.SetGlobalConstant(true)
|
sliceDataGlobal.SetGlobalConstant(true)
|
||||||
sliceDataGlobal.SetUnnamedAddr(true)
|
sliceDataGlobal.SetUnnamedAddr(true)
|
||||||
sliceDataGlobal.SetAlignment(c.targetData.ABITypeAlignment(sliceDataInitializer.Type()))
|
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.
|
// Create the slice object itself.
|
||||||
// Because embed.FS refers to it as *[]embed.file instead of a plain
|
// Because embed.FS refers to it as *[]embed.file instead of a plain
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче