An error occurred while loading the file. Please try again.
-
Hans Zhang 1911512 authoredc893e646
#ifndef __INSTRUCTION_H__
#define __INSTRUCTION_H__
#include "Operand.h"
#include <vector>
#include <map>
class BasicBlock;
class Instruction
{
public:
Instruction(unsigned instType, BasicBlock *insert_bb = nullptr);
virtual ~Instruction();
BasicBlock *getParent();
bool isUncond() const {return instType == UNCOND;};
bool isCond() const {return instType == COND;};
void setParent(BasicBlock *);
void setNext(Instruction *);
void setPrev(Instruction *);
Instruction *getNext();
Instruction *getPrev();
virtual void output() const = 0;
protected:
unsigned instType;
unsigned opcode;
Instruction *prev;
Instruction *next;
BasicBlock *parent;
std::vector<Operand*> operands;
enum {BINARY, COND, UNCOND, RET, LOAD, STORE, CMP, ALLOCA, CALL, EXT};
};
// meaningless instruction, used as the head node of the instruction list.
class DummyInstruction : public Instruction
{
public:
DummyInstruction() : Instruction(-1, nullptr) {};
void output() const {};
};
class AllocaInstruction : public Instruction
{
public:
AllocaInstruction(Operand *dst, SymbolEntry *se, BasicBlock *insert_bb = nullptr);
~AllocaInstruction();
void output() const;
private:
SymbolEntry *se;
};
class LoadInstruction : public Instruction
{
public:
LoadInstruction(Operand *dst, Operand *src_addr, BasicBlock *insert_bb = nullptr);
~LoadInstruction();
void output() const;
};
class StoreInstruction : public Instruction
{
public:
StoreInstruction(Operand *dst_addr, Operand *src, BasicBlock *insert_bb = nullptr);
~StoreInstruction();
void output() const;
};
class BinaryInstruction : public Instruction
{
public:
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
BinaryInstruction(unsigned opcode, Operand *dst, Operand *src1, Operand *src2, BasicBlock *insert_bb = nullptr);
~BinaryInstruction();
void output() const;
enum {SUB, ADD, MUL, DIV, MOD, XOR};
};
class ExtInstruction : public Instruction
{
public:
ExtInstruction(Operand *dst, Operand *src, BasicBlock *insert_bb = nullptr);
void output() const;
};
class CmpInstruction : public Instruction
{
public:
CmpInstruction(unsigned opcode, Operand *dst, Operand *src1, Operand *src2, BasicBlock *insert_bb = nullptr);
~CmpInstruction();
void output() const;
enum {EQ, NE, L, GE, G, LE};
};
// unconditional branch
class UncondBrInstruction : public Instruction
{
public:
UncondBrInstruction(BasicBlock*, BasicBlock *insert_bb = nullptr);
void output() const;
void setBranch(BasicBlock *);
BasicBlock *getBranch();
BasicBlock **patchBranch() {return &branch;};
protected:
BasicBlock *branch;
};
// conditional branch
class CondBrInstruction : public Instruction
{
public:
CondBrInstruction(BasicBlock*, BasicBlock*, Operand *, BasicBlock *insert_bb = nullptr);
~CondBrInstruction();
void output() const;
void setTrueBranch(BasicBlock*);
BasicBlock* getTrueBranch();
void setFalseBranch(BasicBlock*);
BasicBlock* getFalseBranch();
BasicBlock **truePatchBranch() {return &true_branch;};
BasicBlock **falsePatchBranch() {return &false_branch;};
protected:
BasicBlock* true_branch;
BasicBlock* false_branch;
};
class RetInstruction : public Instruction
{
public:
RetInstruction(Operand *src, BasicBlock *insert_bb = nullptr);
~RetInstruction();
void output() const;
};
class CallInstruction : public Instruction
{
private:
SymbolEntry *se;
public:
CallInstruction(Operand *dst, std::vector<Operand*> &operands, SymbolEntry*se, BasicBlock *insert_bb = nullptr);
~CallInstruction();
void output() const;
};
141142
#endif