Create separate OpSource for each included file

This commit is contained in:
Greg Fischer
2018-12-06 11:13:15 -07:00
parent 9ed38739b9
commit d445bb2867
6 changed files with 131 additions and 104 deletions

View File

@@ -114,20 +114,8 @@ void Builder::setLine(int lineNum, const char* filename)
currentLine = lineNum;
currentFile = filename;
if (emitOpLines) {
// If filename previously seen, use its id, else create a string
// and put it in the map.
auto sItr = stringIds.find(filename);
if (sItr != stringIds.end()) {
addLine(sItr->second, currentLine, 0);
} else {
Instruction* fileString =
new Instruction(getUniqueId(), NoType, OpString);
fileString->addStringOperand(filename);
spv::Id stringId = fileString->getResultId();
strings.push_back(std::unique_ptr<Instruction>(fileString));
addLine(stringId, currentLine, 0);
stringIds[filename] = stringId;
}
spv::Id strId = getStringId(filename);
addLine(strId, currentLine, 0);
}
}
}
@@ -2843,7 +2831,8 @@ void Builder::createConditionalBranch(Id condition, Block* thenBlock, Block* els
// OpSource
// [OpSourceContinued]
// ...
void Builder::dumpSourceInstructions(std::vector<unsigned int>& out) const
void Builder::dumpSourceInstructions(const spv::Id fileId, const std::string& text,
std::vector<unsigned int>& out) const
{
const int maxWordCount = 0xFFFF;
const int opSourceWordCount = 4;
@@ -2855,14 +2844,14 @@ void Builder::dumpSourceInstructions(std::vector<unsigned int>& out) const
sourceInst.addImmediateOperand(source);
sourceInst.addImmediateOperand(sourceVersion);
// File operand
if (sourceFileStringId != NoResult) {
sourceInst.addIdOperand(sourceFileStringId);
if (fileId != NoResult) {
sourceInst.addIdOperand(fileId);
// Source operand
if (sourceText.size() > 0) {
if (text.size() > 0) {
int nextByte = 0;
std::string subString;
while ((int)sourceText.size() - nextByte > 0) {
subString = sourceText.substr(nextByte, nonNullBytesPerInstruction);
while ((int)text.size() - nextByte > 0) {
subString = text.substr(nextByte, nonNullBytesPerInstruction);
if (nextByte == 0) {
// OpSource
sourceInst.addStringOperand(subString.c_str());
@@ -2882,6 +2871,14 @@ void Builder::dumpSourceInstructions(std::vector<unsigned int>& out) const
}
}
// Dump an OpSource[Continued] sequence for the source and every include file
void Builder::dumpSourceInstructions(std::vector<unsigned int>& out) const
{
dumpSourceInstructions(sourceFileStringId, sourceText, out);
for (auto iItr = includeFiles.begin(); iItr != includeFiles.end(); ++iItr)
dumpSourceInstructions(iItr->first, *iItr->second, out);
}
void Builder::dumpInstructions(std::vector<unsigned int>& out, const std::vector<std::unique_ptr<Instruction> >& instructions) const
{
for (int i = 0; i < (int)instructions.size(); ++i) {