-
yas authored73ebfd0a
Forked from
汪汪队立大功队 / wwdldg
#ifndef _LIR_H_
#define _LIR_H_
#include <cassert>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <memory>
#include <stdexcept>
#include "../IR/llvm.h"
class LIROperand;
class LIRConstant;
class LIRVirtReg;
class LIRPhysReg;
class LIRInstruction;
class LIRIntInst;
class LIRFloatInst;
class LIRVmrsInst;
class LIRLdrInst;
class LIRVldrInst;
class LIRStrInst;
class LIRVstrInst;
class LIRBInst;
class LIRBlInst;
class LIRPushInst;
class LIRPopInst;
class LIRDataDef;
class LIRLabel;
class LIRGlobalVariable;
class LIRBasicBlock;
class LIRFunction;
struct LIRUse {
LIRInstruction* val_;
int arg_no_;
LIRUse(LIRInstruction* val, int no) : val_(val), arg_no_(no) {}
};
class LIRDataDef {
public:
enum LIRDataDefTy { LWordTy, LZeroTy };
explicit LIRDataDef(LIRDataDefTy tid, unsigned expr) : tid_(tid), expr_(expr) {}
~LIRDataDef() = default;
std::string print();
LIRDataDefTy tid_;
unsigned expr_;
};
class LIROperand {
public:
enum LIROprTy {
LOVirtRegTy,LOVirtFRegTy,LOPhysRegTy,LOPhysFRegTy,LOConstantTy,LOShiftTy,LFunctionTy,LBasicBlockTy,LGlobalVariableTy
};
LIROprTy tid_;
std::list<LIRUse> use_list_;
explicit LIROperand(LIROprTy tid) : tid_(tid) {}
~LIROperand() = default;
virtual std::string print() = 0;
std::list<LIRUse>::iterator add_use(LIRInstruction* val, int arg_no) {
use_list_.emplace_back(val, arg_no);
std::list<LIRUse>::iterator re = use_list_.end();
return --re;
}
void remove_use(std::list<LIRUse>::iterator it) {
use_list_.erase(it);
}
};
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
class LIRConstant : public LIROperand {
public:
int value_;
LIRConstant(int val) : LIROperand(LOConstantTy), value_(val) {}
~LIRConstant() = default;
virtual std::string print() override;
};
class LIRShift : public LIROperand {
public:
enum LIRShiftTy { LSAsrTy, LSLslTy, LSLsrTy, LSRorTy };
LIRShift(LIRShiftTy tid, int amount) : LIROperand(LOShiftTy), tid_(tid), amount_(amount) {}
~LIRShift() = default;
const static std::map<LIRShiftTy, std::string> name_;
virtual std::string print() override;
LIRShiftTy tid_;
int amount_;
};
class LIRVirtReg : public LIROperand {
public:
LIRVirtReg(int rid) : LIROperand(LOVirtRegTy), rid_(rid) {}
~LIRVirtReg() = default;
virtual std::string print() override;
int rid_;
};
class LIRPhysReg : public LIROperand {
public:
LIRPhysReg(int rid) : LIROperand(LOPhysRegTy), rid_(rid) {}
~LIRPhysReg() = default;
const static std::map<int, std::string> name_;
virtual std::string print() override;
int rid_;
};
class LIRVirtFReg : public LIROperand {
public:
LIRVirtFReg(int frid) : LIROperand(LOVirtFRegTy), frid_(frid) {}
~LIRVirtFReg() = default;
virtual std::string print() override;
int frid_;
};
class LIRPhysFReg : public LIROperand {
public:
LIRPhysFReg(int frid) : LIROperand(LOPhysFRegTy), frid_(frid) {}
~LIRPhysFReg() = default;
const static std::map<int, std::string> name_;
virtual std::string print() override;
int frid_;
};
class LIRModule {
public:
explicit LIRModule() {
total_rid_ = 0;
total_frid_ = 0;
}
~LIRModule() {}
virtual std::string print();
void add_global_variable(LIRGlobalVariable* g) { global_list_.push_back(g); }
void add_function(LIRFunction* f) { function_list_.push_back(f); }
LIRConstant* get_LIRConstant(int val) ;
LIRVirtReg* get_LIRVirtReg(int rid) ;
LIRVirtReg* get_LIRVirtReg() ;
LIRPhysReg* get_LIRPhysReg(int rid) ;
LIRVirtFReg* get_LIRVirtFReg(int frid) ;
LIRVirtFReg* get_LIRVirtFReg() ;
LIRPhysFReg* get_LIRPhysFReg(int frid) ;
LIRDataDef* get_LIRDataDef(LIRDataDef::LIRDataDefTy tid, int expr) ;
LIRShift* get_LIRShift(LIRShift::LIRShiftTy tid, int amount) ;