-
Notifications
You must be signed in to change notification settings - Fork 2
/
mainwindow.cpp
161 lines (152 loc) · 5.13 KB
/
mainwindow.cpp
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setFixedSize(this->width(), this->height());
ui->textBrowser->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->textBrowser->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::decode);
}
void MainWindow::decode(){
bool valid = false;
QString raw = ui->lineEdit->text();
qint64 val = raw.toLongLong(&valid, 16);
if(valid == false){
QMessageBox::critical(
this,
"错误",
"不是合法的十六进制数",
QMessageBox::Ok,
QMessageBox::Ok
);
return;
}
if(raw.length() == 8){
handle32(val);
}
else{
QMessageBox::critical(
this,
"错误",
"不是预期的riscv指令",
QMessageBox::Ok,
QMessageBox::Ok
);
}
}
void MainWindow::handle32(qint64 val){
QString ins = QString("%1").arg(val, 32, 2, QLatin1Char('0'));
ui->textBrowser->setText(ins + "\n");
QString opcode = ins.mid(25, -1);
if(opcode == "0110011" or opcode == "0111011"){
ui->textBrowser->setText(
"bin:" + ins + "\n" +
"funct7:" + ins.mid(0, 7) + "\n" +
"funct3:" + ins.mid(17, 3) + "\n" +
"rs1:" + ins.mid(12, 5) + "\n" +
"rs2:" + ins.mid(7, 5) + "\n" +
"rd:" + ins.mid(20, 5) + "\n" +
"opcode:" + opcode
);
}
else if(opcode == "1100011"){
ui->textBrowser->setText(
"bin:" + ins + "\n" +
"funct3:" + ins.mid(17, 3) + "\n" +
"rs1:" + ins.mid(12, 5) + "\n" +
"rs2:" + ins.mid(7, 5) + "\n" +
"imm:" + ins.mid(0, 1) + ins.mid(24,1) + ins.mid(1,6) + ins.mid(20,4) + "\n" +
"opcode:" + opcode
);
}
else if(opcode == "0000011"){
ui->textBrowser->setText(
"bin:" + ins + "\n" +
"funct3:" + ins.mid(17, 3) + "\n" +
"rs1:" + ins.mid(12, 5) + "\n" +
"rd:" + ins.mid(20, 5) + "\n" +
"imm:" + ins.mid(0, 12) + "\n" +
"opcode:" + opcode
);
}
else if(opcode == "0100011"){
ui->textBrowser->setText(
"bin:" + ins + "\n" +
"funct3:" + ins.mid(17, 3) + "\n" +
"rs1:" + ins.mid(12, 5) + "\n" +
"rs2:" + ins.mid(7, 5) + "\n" +
"imm:" + ins.mid(0, 7) + ins.mid(20, 5) + "\n" +
"opcode:" + opcode
);
}
else if(opcode == "0010011" or opcode == "0011011"){
QString funct3 =ins.mid(17, 3);
if(funct3 == "001" or funct3 == "101"){
if(ui->comboBox->currentText() == "RV64I"){
ui->textBrowser->setText(
"bin:" + ins + "\n" +
"funct6:" + ins.mid(0, 6) + "\n" +
"funct3:" + ins.mid(17, 3) + "\n" +
"rs1:" + ins.mid(12, 5) + "\n" +
"shamt:" + ins.mid(6, 6) + "\n" +
"rd:" + ins.mid(20, 5) + "\n" +
"opcode:" + opcode
);
}
else{
ui->textBrowser->setText(
"bin:" + ins + "\n" +
"funct6:" + ins.mid(0, 7) + "\n" +
"funct3:" + ins.mid(17, 3) + "\n" +
"rs1:" + ins.mid(12, 5) + "\n" +
"shamt:" + ins.mid(7, 5) + "\n" +
"rd:" + ins.mid(20, 5) + "\n" +
"opcode:" + opcode
);
}
}
else {
ui->textBrowser->setText(
"bin:" + ins + "\n" +
"funct3:" + ins.mid(17, 3) + "\n" +
"rs1:" + ins.mid(12, 5) + "\n" +
"rd:" + ins.mid(20, 5) + "\n" +
"imm:" + ins.mid(0, 12) + "\n" +
"opcode:" + opcode
);
}
}
else if(opcode == "0010111" or opcode == "0110111"){
ui->textBrowser->setText(
"bin:" + ins + "\n" +
"rd:" + ins.mid(20, 5) + "\n" +
"imm:" + ins.mid(0, 20) + "\n" +
"opcode:" + opcode
);
}
else if(opcode == "1101111"){
ui->textBrowser->setText(
"bin:" + ins + "\n" +
"rd:" + ins.mid(20, 5) + "\n" +
"imm:" + ins.mid(0, 1) + ins.mid(12, 8) + ins.mid(11, 1) + ins.mid(1, 10) + "\n" +
"opcode:" + opcode
);
}
else if(opcode == "1100111"){
ui->textBrowser->setText(
"bin:" + ins + "\n" +
"funct3:" + ins.mid(17, 3) + "\n" +
"rs1:" + ins.mid(12, 5) + "\n" +
"rd:" + ins.mid(20, 5) + "\n" +
"imm:" + ins.mid(0, 12) + "\n" +
"opcode:" + opcode
);
}
}
MainWindow::~MainWindow()
{
delete ui;
}