-
Notifications
You must be signed in to change notification settings - Fork 1
/
Instruction.h
119 lines (91 loc) · 2.3 KB
/
Instruction.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* vim: tabstop=4:softtabstop=4:shiftwidth=4:expandtab
*/
#ifndef INSTRUCTION_H
#define INSTRUCTION_H
#include <string>
#include <cassert>
#include "Reg.h"
#include "Value.h"
using namespace std;
class Instruction;
class Instruction {
public:
enum Mnemonic {
ADD, SUB, DIV, MUL, MOD, AND, OR, XOR,
FADD, FSUB, FDIV, FMUL,
NEG, FNEG,
UGT, UGE, GT, GE, EQ, NE,
FGT, FGE, FEQ, FNE,
PRTS, PRTI, PRTF,
JMP, JMPC, JMPI, JMPCI,
MOVL, MOVS, MOVI, MOVF,
MOVIF, MOVFI,
STI, STF,
LDI, LDF,
IN, INI, INF,
ERROR, LABEL, INVALID
};
enum OpType {
IMM = REG_TYPE_COUNT,
NIL,
OP_TYPE_COUNT
};
class Operand {
public:
Operand() {
type = NIL;
}
const Value * immediate(void) {
return imm;
};
int reg;
const Value * imm;
int type; // can be one of OpType or RegType enums
};
class Label {
public:
static int label_num_;
Label() {};
~Label() {};
static int get_label(void);
};
Instruction() {
opcode_ = Mnemonic::INVALID;
label_function_ = 0;
rel_ = Mnemonic::ERROR;
};
Instruction(Mnemonic opcode) {
opcode_ = opcode;
label_function_ = 0;
rel_ = Mnemonic::ERROR;
};
~Instruction() {};
void operand_src1(int reg, const Value * imm, int type);
Operand * operand_src1(void);
void operand_src2(int reg, const Value * imm, int type);
Operand * operand_src2(void);
void operand_dest(int reg, const Value * imm, int type);
Operand * operand_dest(void);
void opcode(Mnemonic opcode);
Mnemonic opcode(void);
void label(int label);
int label(void);
void funLabel(string label_name);
string funLabel(void);
int isFunLabel(void);
void relational_op(Mnemonic rel);
Mnemonic relational_op(void);
const string name(Mnemonic opcode);
static Mnemonic typedMnemonic(bool isInt, Mnemonic intOpcode);
static int isFloating(Mnemonic intOpcode);
private:
Mnemonic opcode_;
Operand src1_;
Operand src2_;
Operand dest_;
int label_;
int label_function_; //Use funLabel_ instead of default label_
string funLabel_;
Mnemonic rel_; //Only for Conditional JMPs
};
#endif // INSTRUCTION_H