-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstruction.cpp
44 lines (34 loc) · 1.12 KB
/
instruction.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
// See LICENSE for details.
#include "instruction.hpp"
#include "fmt/format.h"
#include "iassert.hpp"
std::string Instruction::opcode2Name(Opcode op) { return fmt::format("{}", op); }
void Instruction::dump() const { fmt::print("{}", get_asm()); }
std::string Instruction::get_asm() const {
if (dst2 != RegType::LREG_InvalidOutput) {
if (src2 == RegType::LREG_R0) {
return fmt::format("r{}, r{} = {} r{}", dst1, dst2, opcode, src1);
}
return fmt::format("r{}, r{} = {} r{} r{}", dst1, dst2, opcode, src1, src2);
}
if (src2 == RegType::LREG_R0) {
return fmt::format("r{} = {} r{}", dst1, opcode, src1);
}
return fmt::format("r{} = {} r{} r{}", dst1, opcode, src1, src2);
}
void Instruction::set(Opcode opcode_, RegType src1_, RegType src2_, RegType dst1_, RegType dst2_) {
I(opcode_ != Opcode::iOpInvalid);
opcode = opcode_;
src1 = src1_;
src2 = src2_;
if (dst1_ == RegType::LREG_NoDependence) {
dst1 = RegType::LREG_InvalidOutput;
} else {
dst1 = dst1_;
}
if (dst2_ == RegType::LREG_NoDependence) {
dst2 = RegType::LREG_InvalidOutput;
} else {
dst2 = dst2_;
}
}