-
Notifications
You must be signed in to change notification settings - Fork 0
/
ByteCode.H
64 lines (60 loc) · 996 Bytes
/
ByteCode.H
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef BYTECODE_HEADER
#define BYTECODE_HEADER
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <vector>
#include <fstream>
const std::string instructionTable[] = {"0",
"ADD",
"SUB",
"DIV",
"MUL",
"NEW",
"PUSHID",
"PUSHINT",
"STORE",
"CALL",
"RET",
"CLT",
"CGT",
"CEQ",
"CNEQ",
"CJMP",
"BJMP",
"ID",
"INT",
"CHAR",
"DOUBLE",
"STRING",
"MCALL",
"PUSHDOUBLE",
"PUSHSTRING",
"ClassName",
"ClassParent",
"DFUN",
"FJMP",
"SIZE",
"<BEGIN CLASS>",
"<END CLASS>",
"<BEGIN FUN>",
"<END FUN>",
"<CLASSES>"};//next = 0x23
class Bytecode{
private:
int counter;
std::vector<unsigned char> bc;
public:
//for while and if
void zeroCounter(){counter = 0;}
int getCounter(){return counter;}
void changeByte(int pos, unsigned char b){bc[pos] = b;}
void changeIntByte(int pos, int b);
void addByte(unsigned char b);
void addInt(int b);
unsigned int size(){return bc.size();};
void writeToFile(std::ofstream &file);
};
#endif