Skip to content

Commit

Permalink
fix: fix warning
Browse files Browse the repository at this point in the history
Signed-off-by: NZH <[email protected]>
  • Loading branch information
MRNIU committed Oct 27, 2023
1 parent 058545d commit 709a598
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/codegen/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ void CodeGen::Generate(std::string &_code) {
_code += "\tneg " + lhs + ", " + var1 + "\n";
}
} else {
int llidx = lhs.find("[");
int rlidx = var1.find("[");
auto llidx = lhs.find("[");
auto rlidx = var1.find("[");
if (llidx == std::string::npos && rlidx == std::string::npos) {
if (!(var1[0] >= 'a' && var1[0] <= 'z')) {
_code += "\tli " + lhs + ", " + var1 + "\n";
Expand Down
40 changes: 20 additions & 20 deletions src/include/irast.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class DeclIR : public BaseIR {
DeclIR(VarType _type, int _size, std::string _name, int _line)
: BaseIR(_line), varType(_type), size(_size), name(std::move(_name)) {}

const VarType getType() const { return varType; }
const int getSize() const { return size; }
const std::string getName() const { return name; }
VarType getType() const { return varType; }
int getSize() const { return size; }
const std::string &getName() const { return name; }

virtual std::string Generate(LowIRGenerator &_generator, std::string &_code);
};
Expand All @@ -69,10 +69,10 @@ class InitIR : public BaseIR {
: BaseIR(_line), varType(_type), name(std::move(_name)), pos(_p),
val(_v) {}

const VarType getType() const { return varType; }
const int getPos() const { return pos; }
const int getVal() const { return val; }
const std::string getName() const { return name; }
VarType getType() const { return varType; }
int getPos() const { return pos; }
int getVal() const { return val; }
const std::string &getName() const { return name; }

virtual std::string Generate(LowIRGenerator &_generator, std::string &_code);
};
Expand All @@ -87,8 +87,8 @@ class FuncDefIR : public BaseIR {
: BaseIR(_line), name(std::move(_name)), paramNum(_param),
body(std::move(_body)) {}

const std::string getName() const { return name; }
const int getParamNum() const { return paramNum; }
const std::string &getName() const { return name; }
int getParamNum() const { return paramNum; }
const IRPtr &getBody() const { return body; }

virtual std::string Generate(LowIRGenerator &generator, std::string &code);
Expand Down Expand Up @@ -117,7 +117,7 @@ class BinaryExpIR : public BaseIR {

const IRPtr &getLHS() const { return lhs; }
const IRPtr &getRHS() const { return rhs; }
const Operator getOp() const { return op; }
const Operator &getOp() const { return op; }

virtual std::string Generate(LowIRGenerator &_generator, std::string &_code);
};
Expand All @@ -128,7 +128,7 @@ class UnaryExpIR : public BaseIR {

public:
UnaryExpIR(IRPtr _exp, Operator _op, int _line)
: BaseIR(_line), exp(std::move(_exp)), op(_op) {}
: BaseIR(_line), op(_op), exp(std::move(_exp)) {}

const IRPtr &getExp() const { return exp; }
const Operator &getOp() const { return op; }
Expand Down Expand Up @@ -159,7 +159,7 @@ class CondGotoIR : public BaseIR {
: BaseIR(_line), cond(std::move(_cond)), labelNum(_num) {}

const IRPtr &getCond() const { return cond; }
const int getLabel() const { return labelNum; }
int getLabel() const { return labelNum; }

virtual std::string Generate(LowIRGenerator &_generator, std::string &_code);
};
Expand All @@ -173,9 +173,9 @@ class LValIR : public BaseIR {
LValIR(VarType _var, std::string _n, int _line, IRPtr _p = nullptr)
: BaseIR(_line), varType(_var), name(std::move(_n)), pos(std::move(_p)) {}

const VarType getType() const { return varType; }
VarType getType() const { return varType; }
const IRPtr &getPos() const { return pos; }
const std::string getName() const { return name; }
const std::string &getName() const { return name; }

virtual std::string Generate(LowIRGenerator &_generator, std::string &_code);
};
Expand All @@ -186,7 +186,7 @@ class GotoIR : public BaseIR {
public:
GotoIR(int _l, int _line) : BaseIR(_line), label(_l) {}

const int getLabel() const { return label; }
int getLabel() const { return label; }

virtual std::string Generate(LowIRGenerator &_generator, std::string &_code);
};
Expand All @@ -197,7 +197,7 @@ class Label : public BaseIR {
public:
Label(int _n, int _line) : BaseIR(_line), num(_n) {}

const int getNum() const { return num; }
int getNum() const { return num; }

virtual std::string Generate(LowIRGenerator &_generator, std::string &_code);
};
Expand All @@ -220,7 +220,7 @@ class FuncCallIR : public BaseIR {
FuncCallIR(std::string _name, int _line)
: BaseIR(_line), funcName(std::move(_name)) {}

const std::string getName() const { return funcName; }
const std::string &getName() const { return funcName; }

virtual std::string Generate(LowIRGenerator &_generator, std::string &_code);
};
Expand All @@ -247,9 +247,9 @@ class RightValIR : public BaseIR {
RightValIR(IRToken _t, int val, int line)
: BaseIR(line), type(_t), value(val) {}

const IRToken getType() const { return type; }
const int getVal() const { return value; }
const std::string getName() const { return name; }
const IRToken &getType() const { return type; }
int getVal() const { return value; }
const std::string &getName() const { return name; }

virtual std::string Generate(LowIRGenerator &_generator, std::string &_code);
};
Expand Down
2 changes: 1 addition & 1 deletion src/include/lowirgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class LowIRGenerator {
std::string func;
StackVar() {}
StackVar(int _p_min, int _p_max, std::string _f, VarType _t)
: pos_min(_p_min), pos_max(_p_max), func(std::move(_f)), type(_t) {}
: pos_min(_p_min), pos_max(_p_max), type(_t), func(std::move(_f)) {}
};

std::map<std::string, Variable> globalVars;
Expand Down
14 changes: 9 additions & 5 deletions src/ir/irgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ std::string IRGenerator::GenBinaryExp(BinaryAST &_exp, std::string &_code) {
return res;
}

std::string IRGenerator::GenNumber(NumAST &_num, std::string &_code) {
std::string IRGenerator::GenNumber(NumAST &_num,
[[maybe_unused]] std::string &_code) {
return std::to_string(_num.getVal());
}

Expand Down Expand Up @@ -232,7 +233,8 @@ std::string IRGenerator::GenVarDef(VarDefAST &_varDef, std::string &_code) {
return {};
}

std::string IRGenerator::GenId(ProcessedIdAST &_id, std::string &_code) {
std::string IRGenerator::GenId(ProcessedIdAST &_id,
[[maybe_unused]] std::string &_code) {
std::map<std::string, GenVar>::iterator iter;
int tmpCurrentBlock = currentBlock;
while (tmpCurrentBlock != -1) {
Expand Down Expand Up @@ -419,7 +421,7 @@ std::string IRGenerator::GenLVal(LValAST &_lval, std::string &_code) {
}
_code += ("t" + std::to_string(t_num) + " = " + var + " * " +
std::to_string(dim[i + 1]) + "\n");
for (int k = i + 2; k < _lval.getPosition().size(); k++) {
for (size_t k = i + 2; k < _lval.getPosition().size(); k++) {
for (int j = 0; j < currentDepth; j++) {
_code += "\t";
}
Expand Down Expand Up @@ -728,7 +730,8 @@ std::string NumAST::GenerateIR(IRGenerator &_gen, std::string &_code) {
return _gen.GenNumber(*this, _code);
}

std::string IdAST::GenerateIR(IRGenerator &_gen, std::string &_code) {
std::string IdAST::GenerateIR([[maybe_unused]] IRGenerator &_gen,
[[maybe_unused]] std::string &_code) {
return this->getName();
}

Expand Down Expand Up @@ -775,7 +778,8 @@ std::string InitValAST::GenerateIR(IRGenerator &_gen, std::string &_code) {
return _gen.GenInitVal(*this, _code);
}

std::string EmptyAST::GenerateIR(IRGenerator &_gen, std::string &_code) {
std::string EmptyAST::GenerateIR([[maybe_unused]] IRGenerator &_gen,
[[maybe_unused]] std::string &_code) {
return {};
}

Expand Down
3 changes: 3 additions & 0 deletions src/ir/irparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ir.h"
#include "irast.h"
#include "irparser.h"
#include "log.h"

void IRParser::NextIRToken() { current = lexer.NextIRToken(); }

Expand Down Expand Up @@ -422,6 +423,8 @@ IRPtr IRParser::ParseAssign() {
return std::make_unique<AssignIR>(std::move(lhs), std::move(rhs),
lexer.getLineno() - 1);
}
SPDLOG_LOGGER_WARN(SCLOG, "NOT HANDLE");
return {};
}

/*
Expand Down
45 changes: 32 additions & 13 deletions src/ir/lowirgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,54 @@ std::string LowIRGenerator::op2char(Operator _op) {
case Operator::sub_op:
c = "-";
break;
case Operator::mul_op:
c = "*";
break;
case Operator::div_op:
c = "/";
break;
case Operator::mod_op:
c = "%";
break;
case Operator::mul_op:
c = "*";
case Operator::orbit_op:
c = "|";
break;
case Operator::equ_op:
c = "==";
case Operator::andbit_op:
c = "&";
break;
case Operator::eorbit_op:
c = "^";
break;
case Operator::and_op:
c = "&&";
break;
case Operator::or_op:
c = "||";
break;
case Operator::not_op:
c = "!";
break;
case Operator::gt_op:
c = ">";
break;
case Operator::ge_op:
c = ">=";
break;
case Operator::nequ_op:
c = "!=";

case Operator::lt_op:
c = "<";
break;
case Operator::le_op:
c = "<=";
break;
case Operator::lt_op:
c = "<";
case Operator::equ_op:
c = "==";
break;
case Operator::gt_op:
c = ">";
case Operator::nequ_op:
c = "!=";
break;
case NOT:
c = "!";
case ERROR:
c = "";
break;
}
return c;
Expand Down Expand Up @@ -433,7 +452,7 @@ std::string LowIRGenerator::GenReturn(ReturnIR &_ret, std::string &_code) {

std::string LowIRGenerator::GenParamList(ParamListIR &_params,
std::string &_code) {
for (int i = 0; i < _params.getParams().size(); i++) {
for (size_t i = 0; i < _params.getParams().size(); i++) {
std::string param = _params.getParams()[i]->Generate(*this, _code);
_code += "\ta" + std::to_string(i) + " = " + param + "\n";
}
Expand Down

0 comments on commit 709a598

Please sign in to comment.