-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphFiller.cpp
More file actions
47 lines (40 loc) · 1.36 KB
/
graphFiller.cpp
File metadata and controls
47 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "graphFiller.h"
#include <list>
#include <string>
#include <utility>
#include "asmline.h"
#include "parser.h"
void Graphfiller::restart() {
referenciasColgadas.clear();
referenciasReconocidas.clear();
aristaACortar.clear();
opGraph.clear();
}
void Graphfiller::addInstructionToGraph(std::string line, int lineNumber) {
if (line.size() == 0) return;
Asmline instruction = std::move(parser.parseInstruction(std::move(line)));
opGraph.addVertex(lineNumber);
if (lineNumber != 1) opGraph.connectLast(lineNumber);
std::list<std::string> labelsToJump(instruction.getLabelsToJumpTo());
if (instruction.esCortante()) aristaACortar.push_front(lineNumber);
if (instruction.getLabel().size() != 0)
referenciasReconocidas[std::move(instruction.getLabel())] = lineNumber;
if (labelsToJump.size() != 0) {
for (auto s : labelsToJump) {
referenciasColgadas[s].push_back(lineNumber);
}
}
}
bool Graphfiller::hasCycle() { return opGraph.isCyclic(); }
bool Graphfiller::hasUnusedInstruction() {
return opGraph.hasUnusedInstructions();
}
void Graphfiller::connectLostTags() {
for (int i : aristaACortar) opGraph.disconnectNext(std::move(i));
for (auto& it : referenciasColgadas) {
for (int lineNumber : it.second) {
opGraph.connect(std::move(lineNumber),
std::move(referenciasReconocidas[it.first]));
}
}
}