generate OpLine before OpFunction

This commit is contained in:
Qingyuan Zheng
2022-05-23 23:05:43 -07:00
parent 86ff4bca1d
commit 279c28e70a
13 changed files with 42 additions and 1 deletions

View File

@@ -2783,6 +2783,10 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
} else {
handleFunctionEntry(node);
}
if (options.generateDebugInfo) {
const auto& loc = node->getLoc();
currentFunction->setDebugLineInfo(builder.getSourceFile(), loc.line, loc.column);
}
} else {
if (inEntryPoint)
entryPointTerminated = true;

View File

@@ -99,6 +99,10 @@ public:
stringIds[file_c_str] = strId;
return strId;
}
spv::Id getSourceFile() const
{
return sourceFileStringId;
}
void setSourceFile(const std::string& file)
{
sourceFileStringId = getStringId(file);

View File

@@ -357,6 +357,14 @@ public:
Decoration getReturnPrecision() const
{ return reducedPrecisionReturn ? DecorationRelaxedPrecision : NoPrecision; }
void setDebugLineInfo(Id fileName, int line, int column) {
lineInstruction = Instruction(OpLine);
lineInstruction.addIdOperand(fileName);
lineInstruction.addImmediateOperand(line);
lineInstruction.addImmediateOperand(column);
}
bool hasDebugLineInfo() const { return lineInstruction.getOpCode() == OpLine; }
void setImplicitThis() { implicitThis = true; }
bool hasImplicitThis() const { return implicitThis; }
@@ -373,6 +381,11 @@ public:
void dump(std::vector<unsigned int>& out) const
{
// OpLine
if (hasDebugLineInfo()) {
lineInstruction.dump(out);
}
// OpFunction
functionInstruction.dump(out);
@@ -391,6 +404,7 @@ protected:
Function& operator=(Function&);
Module& parent;
Instruction lineInstruction;
Instruction functionInstruction;
std::vector<Instruction*> parameterInstructions;
std::vector<Block*> blocks;
@@ -457,7 +471,8 @@ protected:
// - the OpFunction instruction
// - all the OpFunctionParameter instructions
__inline Function::Function(Id id, Id resultType, Id functionType, Id firstParamId, Module& parent)
: parent(parent), functionInstruction(id, resultType, OpFunction), implicitThis(false),
: parent(parent), lineInstruction(OpNop),
functionInstruction(id, resultType, OpFunction), implicitThis(false),
reducedPrecisionReturn(false)
{
// OpFunction