diff --git a/src/SysYFIR/GlobalVariable.cpp b/src/SysYFIR/GlobalVariable.cpp index 3838146..7b5a74f 100644 --- a/src/SysYFIR/GlobalVariable.cpp +++ b/src/SysYFIR/GlobalVariable.cpp @@ -27,7 +27,6 @@ Ptr GlobalVariable::create(std::string name, Ptr m, Ptr< std::string GlobalVariable::print() { - std::cout << "globalval0" <get_init()->print(); return global_val_ir; - std::cout << "globalval0" <global_list_) { - std::cout << "global0" <print(); module_ir += "\n"; - std::cout << "global1" <function_list_) { - std::cout << "func" <print(); module_ir += "\n"; } diff --git a/src/SysYFIRBuilder/IRBuilder.cpp b/src/SysYFIRBuilder/IRBuilder.cpp index 2397048..0cf482d 100644 --- a/src/SysYFIRBuilder/IRBuilder.cpp +++ b/src/SysYFIRBuilder/IRBuilder.cpp @@ -115,11 +115,9 @@ void IRBuilder::BinaryExprGen(Ptr lhs, Ptr rhs, SyntaxTree::BinOp } } else { if (dynamic_pointer_cast(lhs) == nullptr && lhs->get_type()->is_pointer_type()) { - std::cout << 2<create_load(lhs); } if (dynamic_pointer_cast(rhs) == nullptr && rhs->get_type()->is_pointer_type()) { - std::cout << 3<create_load(rhs); } auto lhsFloat = (dynamic_pointer_cast(lhs) == nullptr && lhs->get_type()->is_float_type()) || dynamic_pointer_cast(lhs); @@ -134,9 +132,7 @@ void IRBuilder::BinaryExprGen(Ptr lhs, Ptr rhs, SyntaxTree::BinOp switch (op) { case SyntaxTree::BinOp::PLUS: if (isFloat) { - std::cout << 1<create_fadd(lhs, rhs); - std::cout << 2 <create_iadd(lhs, rhs); } @@ -241,12 +237,9 @@ void IRBuilder::BinaryCondExprGen(Ptr lhs, Ptr rhs, SyntaxTree::Bi if (dynamic_pointer_cast(lhs) == nullptr &&lhs->get_type()->is_pointer_type()) { lhs = builder->create_load(lhs); } - std::cout << (dynamic_pointer_cast(rhs)) <(rhs) == nullptr && rhs->get_type()->is_pointer_type()) { rhs = builder->create_load(rhs); } - std::cout << 2<(lhs) == nullptr && lhs->get_type()->is_float_type()) || dynamic_pointer_cast(lhs); auto rhsFloat = (dynamic_pointer_cast(rhs) == nullptr && rhs->get_type()->is_float_type()) || dynamic_pointer_cast(rhs); if (lhsFloat && !rhsFloat) { @@ -442,7 +435,7 @@ void IRBuilder::visit(SyntaxTree::FuncFParamList &node) { // FINISH void IRBuilder::visit(SyntaxTree::FuncParam &node) { - auto tmpType = GetParamType(node.param_type, node.array_index.empty()); + auto tmpType = GetParamType(node.param_type, !node.array_index.empty()); funcFParam.push_back(tmpType); } @@ -475,19 +468,17 @@ void IRBuilder::visit(SyntaxTree::VarDef &node) { TypeConvert(tmpInst, varType); varInit.push_back(dynamic_pointer_cast(tmpInst)); } - auto otherLen = arrayType->get_num_of_elements() - node.initializers->elementList.size(); + auto arrayLen = arrayType->get_num_of_elements(); + auto otherLen = arrayLen - node.initializers->elementList.size(); auto tmpZero = CONST_INT(0); TypeConvert(tmpZero, varType); for (int i = 0; i < otherLen; i++) { varInit.push_back(dynamic_pointer_cast(tmpInst)); } - auto zeroInit = ConstantZero::create(varType, module); - auto tmpInit = ConstantArray::create(static_pointer_cast(varType), varInit); - identAlloca = GlobalVariable::create(node.name, module, varType, node.is_constant, tmpInit); - //std::cout <<"VarDef1"<get_array_type(varType, arrayLen), varInit); + identAlloca = GlobalVariable::create(node.name, module, arrayType, node.is_constant, arrayInit); } else { - //std::cout <<"VarDef2"<expr->accept(*this); TypeConvert(tmpInst, varType); @@ -551,7 +542,6 @@ void IRBuilder::visit(SyntaxTree::LVal &node) { auto constIndex = dynamic_pointer_cast(tmpInst); auto globalIdent = dynamic_pointer_cast(ident); if(globalIdent != nullptr && globalIdent->is_const() && constIndex != nullptr) { - std::cout << "Const LVal "<(globalIdent->get_init()); tmpInst = arrayInit->get_element_value(constIndex->get_value()); } else { @@ -601,9 +591,7 @@ void IRBuilder::visit(SyntaxTree::ReturnStmt &node) { auto expectRetType = builder->get_insert_block()->get_parent()->get_return_type(); TypeConvert(tmpInst, expectRetType); - std::cout << "RET" <create_store(tmpInst, retAlloca); - std::cout << "RET" <create_br(retBB); @@ -614,7 +602,7 @@ void IRBuilder::visit(SyntaxTree::ReturnStmt &node) { void IRBuilder::visit(SyntaxTree::BlockStmt &node) { scope.enter(); for (const auto &stmt : node.body) { - std::cout << "Block" <accept(*this); } scope.exit(); diff --git a/src/main.cpp b/src/main.cpp index 5d5a62d..a4232bd 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,6 @@ int main(int argc, char *argv[]) m->set_file_name(filename); m->set_print_name(); auto IR = m->print(); - std::cout << "END OUT" <