Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions include/BasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@ using std::set;
class Function;
class Instruction;

class BaseBlock
class BaseBlock :public Value
{
public:
enum BlockType
{
Basic,
If,
While,
While
};

const map<BlockType, const char*> name =
{
{Basic,"Basic"},
{If,"If"},
{While,"While"}
};

void addInst(Instruction* inst) { insrList.push_back(inst); };
Expand All @@ -32,9 +39,9 @@ class BaseBlock
std::vector<Instruction*> insrList;
std::vector<BaseBlock*> pre_bbs_;
std::vector<BaseBlock*> succ_bbs_;
void debugPrint() {};
void debugPrint();

BaseBlock()
BaseBlock():Value(voidType)
{
parent = nullptr;
}
Expand Down
6 changes: 3 additions & 3 deletions include/ConstantValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ class ConstantValue:public Value
typeInt,
typeArray,
};
constantValueType type;
constantValueType ctype;
};


class ConstantInt :public ConstantValue
{
public:
ConstantInt(int val) :value(val) { type = typeInt; };
ConstantInt(int val) :value(val) { ctype = typeInt; type = new Type(intType); isConstant = true; }
int value;
};


class ConstantArray : public ConstantValue
{
public:
ConstantArray(vector<int> val) :value(val) { type = typeArray; };
ConstantArray(vector<int> val) :value(val) { ctype = typeArray; type = new Type(arrayType); isConstant = true;}
vector<int> value;
};
19 changes: 8 additions & 11 deletions include/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ class Instruction;
class Function :public User
{
public:
void addBasicBlock(BaseBlock* p);

void removeBasicBlock(BaseBlock* p);

void getFromStatment(NStmtList stmtList);

void getFromBlock(NBlockStmt* block);
Expand All @@ -30,17 +26,19 @@ class Function :public User

void getFromIf(NIfStmt* ifstmt);

static void addSymbol(string name, Value* val) { symbolTable.insert(make_pair(name, val)); }
void addSymbol(string name, Value* val);

Value* findValue(string name, BaseBlock* p) { return (symbolTable.find(name))->second; }
Value* findValue(string name);

Instruction* getInstFromExp(NExp* p);

Function(Type* type) :User(type) {};
Function(Type* type);

static Function* makeFunction(Type* returnVal, vector<Type*>arg, vector<std::string> paraName);

static Function* makeFunction(Type* returnVal, vector<Type*>arg, vector<std::string> paraName);

//block结束,将recoverTable中的符号重新写回symbolTable中
void RecoverSymBol();

void debugPrint();

Expand All @@ -54,11 +52,10 @@ class Function :public User
this->parent = p;
}

static map<string, Value*> symbolTable;
static map<string, Value*> recoverTable;
map<string, Value*> symbolTable;
map<string, Value*> recoverTable;
string name;
BaseBlock* entry;
BaseBlock* last;
Module* parent;

};
Loading