Allow a PC to map to multiple source lines
MODIFY
src/assembler/assembler.h
src/assembler/assembler.h
@@ -370,7 +370,7 @@ protected:
std::shared_ptr<_Instruction> assembledWith;
runOperation(machineCode, _InstrRes, assembleInstruction, line, assembledWith);
assert(assembledWith && "Expected the assembler instruction to be set");
- program.sourceMapping[addr_offset] = line.sourceLine;
+ program.sourceMapping[addr_offset].insert(line.sourceLine);
if (!machineCode.linksWithSymbol.symbol.isEmpty()) {
LinkRequest req;

MODIFY
src/assembler/program.h
src/assembler/program.h
#include <QMetaType>
#include <QString>
#include <optional>
+#include <set>
#include <vector>
#include "ripes_types.h"
@@ -100,8 +101,8 @@ private:
*/
class Program {
public:
- // A source mapping is a mapping from {instruction address : source code line}
- using SourceMapping = std::map<VInt, unsigned>;
+ // A source mapping is a mapping from {instruction address : source code lines}
+ using SourceMapping = std::map<VInt, std::set<unsigned>>;
AInt entryPoint = 0;
std::map<QString, ProgramSection> sections;

MODIFY
src/editor/codeeditor.cpp
src/editor/codeeditor.cpp
@@ -419,15 +419,17 @@ void CodeEditor::updateHighlighting() {
for (unsigned sid = 0; sid < stages; sid++) {
const auto stageInfo = proc->stageInfo(sid);
+ QColor stageColor = colorGenerator();
if (stageInfo.stage_valid) {
- auto sourceLine = sourceMapping.find(stageInfo.pc);
- if (sourceLine == sourceMapping.end()) {
+ auto mappingIt = sourceMapping.find(stageInfo.pc);
+ if (mappingIt == sourceMapping.end()) {
// No source line registerred for this PC.
continue;
}
+ for (auto sourceLine : mappingIt->second) {
// Find block
- QTextBlock block = document()->findBlockByLineNumber(sourceLine->second);
+ QTextBlock block = document()->findBlockByLineNumber(sourceLine);
if (!block.isValid())
continue;
@@ -435,7 +437,8 @@ void CodeEditor::updateHighlighting() {
QString stageString = ProcessorHandler::getProcessor()->stageName(sid);
if (!stageInfo.namedState.isEmpty())
stageString += " (" + stageInfo.namedState + ")";
- highlightBlock(block, colorGenerator(), stageString);
+ highlightBlock(block, stageColor, stageString);
+ }
}
}
}

MODIFY
src/edittab.cpp
src/edittab.cpp
@@ -454,8 +454,7 @@ bool EditTab::loadElfFile(Program& program, QFile& file) {
}
if (editorSrcFile != filePath)
continue;
- qDebug() << "Mapping " << line.address << " to " << line.line;
- program.sourceMapping[line.address] = line.line;
+ program.sourceMapping[line.address].insert(line.line - 1);
}
}

Allow a PC to map to multiple source lines