diff options
| author | Nagi5Yeq <wu@x-nagi.com> | 2020-05-27 02:42:01 +0800 |
|---|---|---|
| committer | Nagi5Yeq <wu@x-nagi.com> | 2020-05-27 02:42:01 +0800 |
| commit | c84e212d0de5ff9f14ab14ac5143e56d2839ac82 (patch) | |
| tree | f511bc44b251d5dac2a7ab87b687e8d00b3dc07c | |
| parent | ba1e3fdd1eea618a38e56918912dc966d1e399a8 (diff) | |
fix the rr-conflicts
| -rw-r--r-- | Driver.cc | 4 | ||||
| -rw-r--r-- | Lexer.l | 7 | ||||
| -rw-r--r-- | Log.hh | 2 | ||||
| -rw-r--r-- | Parser.y | 15 | ||||
| -rw-r--r-- | Version.cc | 1 | ||||
| -rw-r--r-- | main.cc | 5 | ||||
| -rw-r--r-- | node/FunctionNode.cc | 2 |
7 files changed, 26 insertions, 10 deletions
@@ -1,4 +1,5 @@ #include "Driver.hh" +#include "Log.hh" #include "Parser.hh" namespace pcc { @@ -13,6 +14,9 @@ std::shared_ptr<ProgramNode> Driver::Parse(std::string& filename) { return nullptr; } Parser parser(*this, &context_); + if (CurrentLogLevel == pcc::PCC_DEBUG) { + parser.set_debug_level(1); + } parser.parse(); StopLexer(); return root_; @@ -24,7 +24,7 @@ namespace pcc { %option never-interactive %option nounistd %option case-insensitive -%option noyywrap nounput noinput batch debug +%option noyywrap nounput noinput batch decimal ([1-9][0-9]*)|0 octal 0[0-7]* @@ -158,9 +158,12 @@ white [\t\f\r ] namespace pcc { int Driver::StartLexer(std::string& filename) { + if(CurrentLogLevel==LogLevel::PCC_DEBUG){ + yy_flex_debug = 1; + } yyin = std::fopen(filename.c_str(), "r"); if (yyin == NULL) { - Log(PCC_ERROR, "Failed to open file %s", filename.c_str()); + Log(LogLevel::PCC_ERROR, "Failed to open file %s", filename.c_str()); return -1; } return 0; @@ -5,7 +5,7 @@ #include <cstdio> namespace pcc { -enum LogLevel { PCC_ERROR, PCC_WARNING, PCC_INFO, PCC_DEBUG }; +enum LogLevel { PCC_DEBUG, PCC_INFO, PCC_WARNING, PCC_ERROR }; extern LogLevel CurrentLogLevel; @@ -36,6 +36,7 @@ YY_DECL; %define api.location.type {pcc::Location} %define api.value.type variant %define api.token.constructor +%define parse.trace %define parse.error verbose %define parse.assert @@ -62,7 +63,7 @@ YY_DECL; %type <std::shared_ptr<pcc::ExprNode>> literal lvalue %type <std::list<std::shared_ptr<pcc::ExprNode>>> arguments %type <std::shared_ptr<pcc::FunctionCallNode>> function_call -%type <std::shared_ptr<pcc::ExprNode>> expression l1_expression l2_expression l3_expression +%type <std::shared_ptr<pcc::ExprNode>> expression l1_expression l2_expression l3_expression standalone_expression %type <pcc::BinaryOperator> l1_operator l2_operator l3_operator %type <pcc::UnaryOperator> l4_operator @@ -203,11 +204,15 @@ l2_expression ; l3_expression + : l4_operator l3_expression {$$=std::make_shared<pcc::UnaryExprNode>(ctx,$1,$2);} + | standalone_expression {$$=$1;} + ; + +standalone_expression : lvalue {$$=std::make_shared<pcc::L2RCastingNode>(ctx, $1);} | function_call {$$=$1;} | literal {$$=$1;} | LPARENTHESIS expression RPARENTHESIS {$$=$2;} - | l4_operator l3_expression {$$=std::make_shared<pcc::UnaryExprNode>(ctx,$1,$2);} ; l1_operator @@ -240,9 +245,9 @@ l4_operator ; lvalue - : IDENTIFIER {$$=std::make_shared<pcc::IdentifierNode>(ctx, $1);} - | expression LBRACKET expression RBRACKET {$$=std::make_shared<pcc::BinaryExprNode>(ctx, pcc::BinaryOperator::ARRAY_ACCESS, $1, $3);} - | expression DOT IDENTIFIER + : IDENTIFIER {$$=std::make_shared<pcc::IdentifierNode>(ctx, $1);} + | standalone_expression LBRACKET expression RBRACKET {$$=std::make_shared<pcc::BinaryExprNode>(ctx, pcc::BinaryOperator::ARRAY_ACCESS, $1, $3);} + | standalone_expression DOT IDENTIFIER ; function_call @@ -27,6 +27,7 @@ PCC_NORETURN void ShowHelp() { std::cerr << PCC_NAME " version " PCC_VERSION_STRING "\n" << "Usage: " PCC_NAME " [-vVh] file...\n" << " -v Verbose mode.\n" + " -vv Very verbose mode.\n" " -V Show version and exit.\n" " -h Show this help and exit." << std::endl; @@ -14,11 +14,11 @@ int main(int argc, char* argv[]) { int rv; - pcc::LogLevel level = pcc::PCC_WARNING; + int level = pcc::ToUnderlying(pcc::PCC_WARNING); while ((rv = getopt(argc, argv, "vVh")) != -1) { switch (rv) { case 'v': - level = pcc::PCC_DEBUG; + level = (level == 0 ? 0 : level - 1); break; case 'V': pcc::ShowVersion(); @@ -29,6 +29,7 @@ int main(int argc, char* argv[]) { pcc::ShowHelp(); } } + pcc::SetLogLevel(static_cast<pcc::LogLevel>(level)); if (optind >= argc) { pcc::Log(pcc::PCC_ERROR, "No input file specified"); return 0; diff --git a/node/FunctionNode.cc b/node/FunctionNode.cc index 6352b5b..349b02d 100644 --- a/node/FunctionNode.cc +++ b/node/FunctionNode.cc @@ -46,6 +46,8 @@ Value FunctionNode::CodeGen() { function->setCallingConv(llvm::CallingConv::C); llvm::BasicBlock* block = llvm::BasicBlock::Create(GlobalLLVMContext, name_, function); + Log(LogLevel::PCC_INFO, "generating function %s of type %s", name_.c_str(), + type->GetCommonName()); builder->SetInsertPoint(block); // alloc arguments llvm::Function::arg_iterator ArgIt = function->arg_begin(); |
