Skip to content

Commit

Permalink
feat: !=不等于
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingtous committed Feb 16, 2021
1 parent ec44323 commit c4b696e
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 324 deletions.
2 changes: 1 addition & 1 deletion Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/// 状态字
#define OK 0
#define ERR -1
//#define DEBUG_FLAG 1
#define DEBUG_FLAG 1
//#define CGUI 1

/// 初始化数字
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LLVM框架语言:LLVM 12.0.0 编译环境:cmake 3.13 + clion 2020.2 + macOS
- 参数
- 二元表达式
- &&、||
- +、-、*、/、%
- +、-、*、/、%、!=
- 函数调用
- 条件分支关键字
- if
Expand Down
8 changes: 6 additions & 2 deletions ast/NodeAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ llvm::Value *BinaryExprAST::codegen() {
return Builder.CreateICmpSGE(L, R, "greater_equ");
case BinaryType::less_equ:
return Builder.CreateICmpSLE(L, R, "less_equ");
case BinaryType::n_equ:
return Builder.CreateICmpNE(L, R, "not_equ");
// case BinaryType::AND:
// auto boolL = Builder.CreateICmpNE(L,ConstantInt::get(getTypeFromStr("bool"),0));
// auto boolR = Builder.CreateICmpNE(R,ConstantInt::get(getTypeFromStr("bool"),0));
Expand Down Expand Up @@ -98,6 +100,8 @@ llvm::Value *BinaryExprAST::codegen() {
return Builder.CreateFCmpOGE(L, R, "greater_equ");
case BinaryType::less_equ:
return Builder.CreateFCmpOLE(L, R, "less_equ");
case BinaryType::n_equ:
return Builder.CreateFCmpONE(L, R, "not_equ");
default:
return LogErrorV(("invalid binary operator"));
}
Expand Down Expand Up @@ -787,9 +791,9 @@ vector<Constant *> *VariableArrDeclarationAST::genGlobalExprs() {
return arr_index_value_vector;
}

void *VariableArrDeclarationAST::genLocalStoreExprs(Value *mem) {
void VariableArrDeclarationAST::genLocalStoreExprs(Value *mem) {
if (exprs == NIL && exprs->empty()) {
return NIL;
return;
}
vector<uint64_t> vmaxindex = getIndexVal();
vector<uint64_t> vindex(vmaxindex.size(), 0);
Expand Down
5 changes: 3 additions & 2 deletions ast/NodeAST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum BinaryType {
greater,
greater_equ,
equ,
n_equ,
AND,
OR
};
Expand Down Expand Up @@ -78,7 +79,7 @@ class ReturnStmtAST : public StatementAST {
};

/// 块结点,一个块含有多种声明,也可作为一个程序的入口点
class BlockAST : public NodeAST {
class BlockAST : public StatementAST {
public:
vector<StatementAST *> statements;

Expand Down Expand Up @@ -171,7 +172,7 @@ class VariableArrDeclarationAST : public VariableDeclarationAST {
/**
* 对于函数内,初始化使用CreateGEP完成初始化
*/
void *genLocalStoreExprs(Value *mem);
void genLocalStoreExprs(Value *mem);

/**
* 递增index
Expand Down
7 changes: 6 additions & 1 deletion parser/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ int Lexer::_getNextToken() {
return T_GREATER;
}
} else if (LastChar == '!') {
if (seek() == '=') {
getchar();
LastChar = getchar();
return T_N_EQU;
}
LastChar = getchar();
return T_REVERSE;
}
Expand Down Expand Up @@ -212,7 +217,7 @@ char Lexer::seek() {
}

unsigned int Lexer::getCLineNumber() {
return reader.getLineNo();
return reader.getLineNo() + 1;
}

unsigned int Lexer::getCCol() {
Expand Down
Loading

0 comments on commit c4b696e

Please sign in to comment.