-
Notifications
You must be signed in to change notification settings - Fork 0
/
Decoder.h
95 lines (69 loc) · 2.08 KB
/
Decoder.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
#ifndef DECODER_H
#define DECODER_H
/* ****************************************************************
RISC-V Instruction Set Simulator
Class for instruction decoder
**************************************************************** */
#include <cstdint>
#include <vector>
#include <string>
#include "Instruction.h"
using namespace std;
using namespace RV64I;
class Decoder {
private:
// verbose
bool verbose;
// instruction parts
uint32_t ins;
uint8_t opcode;
uint8_t rd;
uint8_t rs1;
uint8_t rs2;
uint8_t funct3;
uint8_t funct7;
uint32_t imm;
// instruction properties
Ins code;
char type;
vector<string> insNames;
public:
// Consructor
Decoder(bool verbose);
// decode current instruction and store parts into variables
void decodeIns(uint32_t ins);
// decode current instruction according to type
void decodeRType();
void decodeIType();
void decodeSType();
void decodeBType();
void decodeUType();
void decodeJType();
// reset instructions and parts
void resetIns();
// return current instruction
uint32_t getIns();
// return current opcode
uint8_t getOpcode();
// return current dest register
uint8_t getRd();
// return current source register 1
uint8_t getRs1();
// return current source register 1
uint8_t getRs2();
// return current funct3
uint8_t getFunct3();
// return current funct7
uint8_t getFunct7();
// return current immediate
uint32_t getImm();
// return current instruction code
Ins getInsCode();
// return current instruction name string
string getInsName();
// return current instruction type (capital letter)
char getInsType();
// destructor
~Decoder();
};
#endif