-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRISCVMOperand.cpp
More file actions
97 lines (92 loc) · 3.17 KB
/
Copy pathRISCVMOperand.cpp
File metadata and controls
97 lines (92 loc) · 3.17 KB
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
/**
* @file RISCVMOperand.cpp
* @brief RISC-V 操作数类的实现文件
* @details 本文件实现了 RISCVMOperand 类及其子类 Imm 的方法,用于管理和操作 RISC-V 架构中的各种操作数。
* 包括常量操作数的创建、获取和打印功能。
*/
#include "../include/backend/RISCVMOperand.hpp"
#include "../include/backend/RISCVFrameContext.hpp"
#include "../include/backend/RISCVMIR.hpp"
#include "../include/backend/RISCVRegister.hpp"
#include <map>
// bool RISCVMOperand::isReg(){
// return false;
// }
// RISCVType RISCVMOperand::GetType(){
// return tp;
// }
// RISCVMOperand::RISCVMOperand(){}
// bool RISCVMOperand::ignoreLA() {
// if (dynamic_cast<Imm *>(this))
// return true;
// // reutrn nullptr;
// else if (PhyRegister *preg = dynamic_cast<PhyRegister *>(this)) {
// PhyRegister::PhyReg regenum = preg->Getregenum();
// using PhyReg = PhyRegister::PhyReg;
// if (regenum == PhyReg::zero || regenum == PhyReg::ra ||
// regenum == PhyReg::sp || regenum == PhyReg::gp ||
// regenum == PhyReg::tp || regenum == PhyReg::s0)
// return true;
// else
// return false;
// } else if (LARegister *lareg = dynamic_cast<LARegister *>(this))
// return true;
// else if (StackRegister *sreg = dynamic_cast<StackRegister *>(this))
// return true;
// else if (dynamic_cast<RISCVFrameObject *>(this))
// return true;
// else if(dynamic_cast<RISCVBasicBlock*>(this))
// return true;
// else if(dynamic_cast<RISCVGlobalObject*>(this))
// return true;
// else
// return false;
// }
Register* RISCVMOperand::ignoreLA() {
if (dynamic_cast<Imm *>(this))
return nullptr;
else if (PhyRegister *preg = dynamic_cast<PhyRegister *>(this)) {
PhyRegister::PhyReg regenum = preg->Getregenum();
using PhyReg = PhyRegister::PhyReg;
if (regenum == PhyReg::zero || regenum == PhyReg::ra ||
regenum == PhyReg::sp || regenum == PhyReg::gp ||
regenum == PhyReg::tp || regenum == PhyReg::s0 ||
regenum == PhyReg::_NULL)
return nullptr;
else
return preg;
} else if (LARegister *lareg = dynamic_cast<LARegister *>(this)) {
return lareg->GetVreg();
}
else if (StackRegister *sreg = dynamic_cast<StackRegister *>(this)) {
return sreg->GetVreg();
}
else if (dynamic_cast<RISCVFrameObject *>(this))
return nullptr;
else if(dynamic_cast<RISCVBasicBlock*>(this))
return nullptr;
else if(dynamic_cast<RISCVMIR*>(this))
return nullptr;
else if(dynamic_cast<RISCVGlobalObject*>(this))
return nullptr;
else if(auto reg = dynamic_cast<Register*>(this))
return reg;
else
return nullptr;
}
Imm::Imm(ConstantData *_data)
: RISCVMOperand(RISCVTyper(_data->GetType())), data(_data) {
} // RISCVTyper(_data->GetType())),data(_data
ConstantData *Imm::Getdata() { return data; }
Imm *Imm::GetImm(ConstantData *_data) {
using Manager = std::unique_ptr<Imm>;
static std::map<ConstantData *, Manager> mapping;
if (mapping.find(_data) == mapping.end())
mapping[_data] = std::make_unique<Imm>(_data);
return mapping[_data].get();
}
void Imm::print() {
// data->GetType()->print();
// std::cout<<" ";
data->print();
}