-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPCode.cpp
More file actions
46 lines (40 loc) · 826 Bytes
/
PCode.cpp
File metadata and controls
46 lines (40 loc) · 826 Bytes
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
#include "PCode.h"
#include "PL0.h"
#include <iomanip>
#include <iostream>
using namespace std;
vector<PCode> PCodeList::code_list;
wstring op_map[P_CODE_CNT] = {
L"LIT",
L"OPR",
L"LOD",
L"STO",
L"CAL",
L"INT",
L"JMP",
L"JPC",
L"RED",
L"WRT"
};
int PCodeList::emit(Operation op, int L, int a)
{
code_list.push_back(PCode(op, L, a));
return code_list.size() - 1;
}
void PCodeList::backpatch(size_t target, size_t addr)
{
if (addr == -1)
return;
else
code_list[target].a = addr;
}
void PCodeList::printCode()
{
for (size_t i = 0; i < code_list.size(); i++) {
wcout << setw(4) << i << L" " << op_map[code_list[i].op] << L", " << code_list[i].L << L", " << code_list[i].a << endl;
}
}
void PCodeList::clear()
{
code_list.clear();
}