diff options
| author | Nagi5Yeq <wu@x-nagi.com> | 2020-06-01 14:06:48 +0800 |
|---|---|---|
| committer | Nagi5Yeq <wu@x-nagi.com> | 2020-06-01 14:06:48 +0800 |
| commit | 31d35de96576d2cddc134cdd0646ce4966052ae3 (patch) | |
| tree | 1df4283f87c57e8e1d9e22959f1c389b9f274d62 | |
| parent | 1e993f800921d2a49ad0c71375512a9209347321 (diff) | |
disable formatv for LLVM release lacks of RTTI support
| -rw-r--r-- | Lexer.l | 4 | ||||
| -rw-r--r-- | Log.cc | 25 | ||||
| -rw-r--r-- | Log.hh | 30 | ||||
| -rw-r--r-- | Parser.y | 2 | ||||
| -rw-r--r-- | Type.cc | 2 | ||||
| -rw-r--r-- | TypeManager.cc | 14 | ||||
| -rw-r--r-- | VariableList.cc | 4 | ||||
| -rw-r--r-- | Version.cc | 5 | ||||
| -rw-r--r-- | main.cc | 18 | ||||
| -rw-r--r-- | node/ExprNode.cc | 22 | ||||
| -rw-r--r-- | node/FunctionNode.cc | 6 | ||||
| -rw-r--r-- | node/StatementNode.cc | 6 | ||||
| -rw-r--r-- | t/trivial.pas | 24 |
13 files changed, 79 insertions, 83 deletions
@@ -168,7 +168,7 @@ comment {comment1}|{comment2}|{comment3} {comment} {} . { - pcc::Log(pcc::LogLevel::PCC_ERROR, "Unrecognized token \"{0}\"", yytext); + pcc::Log(pcc::PCC_ERROR, "Unrecognized token \"%s\"", yytext); } <<EOF>> {return Parser::make_FILE_END(loc);} @@ -180,7 +180,7 @@ int Driver::StartLexer(std::string& filename) { yy_flex_debug = (GetLogLevel()==LogLevel::PCC_DEBUG); yyin = std::fopen(filename.c_str(), "r"); if (yyin == NULL) { - Log(LogLevel::PCC_ERROR, "Failed to open file {0}", filename); + Log(LogLevel::PCC_ERROR, "Failed to open file %s", filename.c_str()); return -1; } return 0; @@ -1,9 +1,32 @@ #include <string> -#include <utility> #include "Log.hh" namespace pcc { +void Log(LogLevel level, const char* format, ...) { + va_list va; + va_start(va, format); + if (GetLogLevel() <= level) { + switch (level) { + case PCC_ERROR: + std::fprintf(stderr, "[ERROR] "); + break; + case PCC_WARNING: + std::fprintf(stderr, "[WARNING] "); + break; + case PCC_INFO: + std::fprintf(stderr, "[INFO] "); + break; + case PCC_DEBUG: + std::fprintf(stderr, "[DEBUG] "); + break; + } + std::vfprintf(stderr, format, va); + std::fputc('\n', stderr); + } + va_end(va); +} + static LogLevel CurrentLogLevel = PCC_ERROR; void SetLogLevel(LogLevel level) { CurrentLogLevel = level; } @@ -4,11 +4,6 @@ #include <cstdarg> #include <cstdio> -#include <llvm/Support/FormatVariadic.h> -#include <llvm/Support/WithColor.h> - -#include "Context.hh" - namespace pcc { enum LogLevel { PCC_DEBUG, PCC_INFO, PCC_WARNING, PCC_ERROR }; @@ -18,30 +13,7 @@ LogLevel GetLogLevel(); void SetExecutableName(const char* name); const char* GetExecutableName(); -template <typename... Args> -void Log(LogLevel level, const char* format, Args&&... args) { - if (level < GetLogLevel()) { - return; - } - auto msg = llvm::formatv(format, std::forward<Args>(args)...); - const char* name = GetExecutableName(); - switch (level) { - case PCC_DEBUG: - llvm::WithColor::remark(llvm::errs(), name) << msg << '\n'; - break; - case PCC_INFO: - llvm::WithColor::note(llvm::errs(), name) << msg << '\n'; - break; - case PCC_WARNING: - llvm::WithColor::warning(llvm::errs(), name) << msg << '\n'; - break; - case PCC_ERROR: - llvm::WithColor::error(llvm::errs(), name) << msg << '\n'; - break; - default: - break; - } -} +void Log(LogLevel level, const char* format, ...); } // namespace pcc #endif @@ -347,7 +347,7 @@ namespace pcc { { std::stringstream loc; loc<<l; - Log(LogLevel::PCC_ERROR, "error at {0}: {1}", loc.str().c_str(), m.c_str()); + Log(LogLevel::PCC_ERROR, "error at %s: %s", loc.str().c_str(), m.c_str()); } } @@ -375,7 +375,7 @@ std::pair<int, std::shared_ptr<Type>> RecordType::GetMember(const std::string& name) { decltype(members_.end()) result = members_.find(name); if (result == members_.end()) { - Log(LogLevel::PCC_ERROR, "the member {0} doesn't exist", name.c_str()); + Log(LogLevel::PCC_ERROR, "the member %s doesn't exist", name.c_str()); return {0, nullptr}; } return std::get<1>(*result); diff --git a/TypeManager.cc b/TypeManager.cc index b790dd4..7402875 100644 --- a/TypeManager.cc +++ b/TypeManager.cc @@ -44,14 +44,14 @@ std::pair<std::shared_ptr<Type>, Value> // add/sub a pointer with a integer if (LeftPointerType != nullptr && RightPointerType == nullptr) { if (op != BinaryOperator::ADD && op != BinaryOperator::SUB) { - Log(LogLevel::PCC_ERROR, "unsupported operation {0} on %s and {1}", + Log(LogLevel::PCC_ERROR, "unsupported operation %s on %s and %s", GetOperatorName(op), LeftType->GetCommonName(), RightType->GetCommonName()); return {nullptr, nullptr}; } if (RightIntegerBaseType == nullptr) { Log(LogLevel::PCC_ERROR, - "can not add pointer with non-integer type {0}", + "can not add pointer with non-integer type %s", RightType->GetCommonName()); return {nullptr, nullptr}; } @@ -101,7 +101,7 @@ std::pair<std::shared_ptr<Type>, Value> : RightType); } else { Log(LogLevel::PCC_ERROR, - "can not apply binary operator on two different type {0} and {1}", + "can not apply binary operator on two different type %s and %s", LeftType->GetCommonName(), RightType->GetCommonName()); return {nullptr, nullptr}; } @@ -114,7 +114,7 @@ std::pair<std::shared_ptr<Type>, Value> ConvertedRight, context); if (result == nullptr) { Log(LogLevel::PCC_ERROR, - "binary operator {0} is not supported on type {1}", + "binary operator %s is not supported on type %s", GetOperatorName(op), CommonType->GetCommonName()); } // logical operators return boolean type @@ -130,7 +130,7 @@ Value TypeManager::CreateOperation(UnaryOperator op, std::shared_ptr<Type> type, Value result = type->CreateUnaryOperation(op, v, context); if (result == nullptr) { Log(LogLevel::PCC_ERROR, - "unary operator {0} is not supported on type {1}", + "unary operator %s is not supported on type %s", GetOperatorName(op), type->GetCommonName()); } return result; @@ -179,7 +179,7 @@ Value TypeManager::CreateCast(std::shared_ptr<Type> DstType, return builder->CreateInBoundsGEP(v, indices); } } - Log(LogLevel::PCC_ERROR, "unsupported type casting from {0} to {1}", + Log(LogLevel::PCC_ERROR, "unsupported type casting from %s to %s", SrcType->GetCommonName(), DstType->GetCommonName()); return nullptr; } @@ -209,7 +209,7 @@ std::shared_ptr<ArrayType> if (IndexType != end->GetType()) { Log(LogLevel::PCC_ERROR, "the start and end indices of an array type must be same " - "(start={0}, end={1})", + "(start=%s, end=%s)", IndexType->GetCommonName(), end->GetType()->GetCommonName()); return nullptr; } diff --git a/VariableList.cc b/VariableList.cc index e112bac..eef1205 100644 --- a/VariableList.cc +++ b/VariableList.cc @@ -19,7 +19,7 @@ Variable VariableList::FindVariable(const std::string& name) { } } if (found == false) { - Log(LogLevel::PCC_ERROR, "unknown identifier {0}", name); + Log(LogLevel::PCC_ERROR, "unknown identifier %s", name.c_str()); return {nullptr, nullptr}; } return std::get<1>(*result); @@ -43,7 +43,7 @@ std::shared_ptr<Type> VariableList::FindTypeAlias(const std::string& name) { } } if (found == false) { - Log(LogLevel::PCC_ERROR, "unknown type alias {0}", name); + Log(LogLevel::PCC_ERROR, "unknown type alias %s", name.c_str()); return nullptr; } return std::get<1>(*result); @@ -1,5 +1,6 @@ #include <llvm/Config/llvm-config.h> +#include "Log.hh" #include "Version.hh" namespace pcc { @@ -25,8 +26,8 @@ PCC_NORETURN void ShowVersion() { PCC_NORETURN void ShowHelp() { std::cerr << PCC_NAME " version " PCC_VERSION_STRING "\n" - << "Usage: " PCC_NAME - " [-vVhiSc] [-O <0,1,2,3>] [-o <output>] file...\n" + << "Usage: " << GetExecutableName() + << " [-vVhiSc] [-O <0,1,2,3>] [-o <output>] file...\n" << " -v Verbose mode.\n" << " -vv Very verbose mode.\n" << " -V Show version and exit.\n" @@ -21,7 +21,7 @@ void compile(llvm::Module* module, llvm::raw_pwrite_stream& output, int main(int argc, char* argv[]) { int rv; - int level = pcc::PCC_WARNING; + int level = pcc::ToUnderlying(pcc::PCC_WARNING); std::string OutputFileName; enum { IR, ASSEMBLY, OBJECT } CompileType = IR; int OptLevel = 2; @@ -51,8 +51,8 @@ int main(int argc, char* argv[]) { case 'O': OptLevel = optarg[0] - '0'; if (OptLevel > 3 || OptLevel < 0) { - pcc::Log(pcc::PCC_ERROR, - "{0} is not a valid optimization level", optarg[0]); + pcc::Log(pcc::PCC_ERROR, "%c is not a valid optimization level", + optarg[0]); pcc::ShowHelp(); } break; @@ -61,7 +61,6 @@ int main(int argc, char* argv[]) { pcc::ShowHelp(); } } - pcc::SetLogLevel(static_cast<pcc::LogLevel>(level)); llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmParser(); @@ -72,7 +71,7 @@ int main(int argc, char* argv[]) { llvm::TargetRegistry::lookupTarget(triple, error); if (!error.empty()) { pcc::Log(pcc::PCC_ERROR, - "failed to find target with triple {0}, reason {1}", + "failed to find target with triple %s, reason %s", triple.c_str(), error.c_str()); return -1; } @@ -83,8 +82,9 @@ int main(int argc, char* argv[]) { std::string features = ""; llvm::TargetOptions options; llvm::TargetMachine* machine = - target->createTargetMachine(triple, cpu, features, options, llvm::None, - llvm::None, optimization[OptLevel]); + target->createTargetMachine(triple, cpu, features, options, llvm::None); + target->createTargetMachine(triple, cpu, features, options, llvm::None, + llvm::None, optimization[OptLevel]); llvm::DataLayout layout = machine->createDataLayout(); if (optind >= argc) { @@ -111,7 +111,7 @@ int main(int argc, char* argv[]) { llvm::verifyModule(*module, &MsgStream); MsgStream.flush(); if (!msg.empty()) { - pcc::Log(pcc::PCC_WARNING, "{0}", msg.c_str()); + pcc::Log(pcc::PCC_WARNING, "%s", msg.c_str()); } } else { continue; @@ -141,7 +141,7 @@ int main(int argc, char* argv[]) { default: break; } - pcc::Log(pcc::PCC_INFO, "{0} compiled to {1}", argv[i], + pcc::Log(pcc::PCC_INFO, "%s compiled to %s", argv[i], OutputFileName.c_str()); OutputFileName.clear(); } diff --git a/node/ExprNode.cc b/node/ExprNode.cc index d785534..e75eda5 100644 --- a/node/ExprNode.cc +++ b/node/ExprNode.cc @@ -66,7 +66,7 @@ Value L2RCastingNode::CodeGen() { std::dynamic_pointer_cast<PointerType>(lvalue_->GetType()); if (type == nullptr) { Log(LogLevel::PCC_ERROR, - "type {0} is not a valid pointer type, this lvalue can't be loaded", + "type %s is not a valid pointer type, this lvalue can't be loaded", lvalue_->GetType()->GetCommonName()); } type_ = type->GetElementType(); @@ -87,7 +87,7 @@ Value PointerAccessNode::CodeGen() { std::dynamic_pointer_cast<PointerType>(lhs_->GetType()); if (pointer == nullptr) { Log(LogLevel::PCC_ERROR, - "type {0} is not a valid type for pointer access operator[]", + "type %s is not a valid type for pointer access operator[]", lhs_->GetType()->GetCommonName()); return nullptr; } @@ -114,7 +114,7 @@ Value ArrayAccessNode::CodeGen() { std::shared_ptr<Type> RightType = rhs_->GetType(); if (LeftType == nullptr) { Log(LogLevel::PCC_ERROR, - "type {0} is not a valid type for array access operator[]", + "type %s is not a valid type for array access operator[]", lhs_->GetType()->GetCommonName()); return nullptr; } @@ -147,7 +147,7 @@ Value ArrayAccessNode::CodeGen() { return builder->CreateInBoundsGEP(PointerValue, CastedRight); } Log(LogLevel::PCC_ERROR, - "type {0} is not a valid lvalue type for array access operator[]", + "type %s is not a valid lvalue type for array access operator[]", lhs_->GetType()->GetCommonName()); return nullptr; } @@ -162,7 +162,7 @@ Value DereferenceNode::CodeGen() { std::shared_ptr<PointerType> pointer = std::dynamic_pointer_cast<PointerType>(lhs_->GetType()); if (pointer == nullptr) { - Log(LogLevel::PCC_ERROR, "type {0} is not a valid type for dereference", + Log(LogLevel::PCC_ERROR, "type %s is not a valid type for dereference", lhs_->GetType()->GetCommonName()); return nullptr; } @@ -187,14 +187,14 @@ Value MemberAccessNode::CodeGen() { std::dynamic_pointer_cast<PointerType>(lhs_->GetType()); if (LeftType == nullptr) { Log(LogLevel::PCC_ERROR, - "type {0} is not a valid type for member access", + "type %s is not a valid type for member access", lhs_->GetType()->GetCommonName()); return nullptr; } std::shared_ptr<RecordType> LeftInner = std::dynamic_pointer_cast<RecordType>(LeftType->GetElementType()); if (LeftInner == nullptr) { - Log(LogLevel::PCC_ERROR, "type {0} is not a record type", + Log(LogLevel::PCC_ERROR, "type %s is not a record type", LeftType->GetElementType()->GetCommonName()); return nullptr; } @@ -229,14 +229,14 @@ Value FunctionCallNode::CodeGen() { Function function = context_->FindFunction(name_); std::shared_ptr<FunctionType> type = std::get<0>(function); if (type == nullptr) { - Log(LogLevel::PCC_ERROR, "call to undefined function {0}", + Log(LogLevel::PCC_ERROR, "call to undefined function %s", name_.c_str()); return nullptr; } const std::vector<std::shared_ptr<Type>>& ArgTypes = type->GetArgTypes(); if (type->IsVariadic() == false && ArgTypes.size() != args_.size()) { Log(LogLevel ::PCC_ERROR, - "argument number mismatch, {0} wanted, {1} given", ArgTypes.size(), + "argument number mismatch, %d wanted, %d given", ArgTypes.size(), args_.size()); return nullptr; } @@ -249,8 +249,8 @@ Value FunctionCallNode::CodeGen() { manager->CreateCast(ArgType, (*ArgIt)->GetType(), argv, context_); if (ConvertedArgv == nullptr) { Log(LogLevel ::PCC_ERROR, - "argument type mismatch, the function type is {0}, an argument " - "of type {1} needed", + "argument type mismatch, the function type is %s, an argument " + "of type %s needed", type->GetCommonName(), ArgType->GetCommonName()); } *ArgValueIt = ConvertedArgv; diff --git a/node/FunctionNode.cc b/node/FunctionNode.cc index 0dcafb1..4fb5138 100644 --- a/node/FunctionNode.cc +++ b/node/FunctionNode.cc @@ -47,7 +47,7 @@ Value FunctionNode::CodeGen() { context_->AddFunction(name_, {type, function}); llvm::BasicBlock* block = llvm::BasicBlock::Create(GlobalLLVMContext, name_, function); - Log(LogLevel::PCC_INFO, "generating function {0} of type {1}", name_, + Log(LogLevel::PCC_INFO, "generating function %s of type %s", name_.c_str(), type->GetCommonName()); builder->SetInsertPoint(block); context_->PushScope(&locals_); @@ -86,7 +86,7 @@ Value FunctionNode::CodeGen() { llvm::verifyFunction(*function, &MsgStream); MsgStream.flush(); if (!msg.empty()) { - Log(LogLevel::PCC_WARNING, "{0}", msg); + Log(LogLevel::PCC_INFO, "%s", msg.c_str()); } return nullptr; } @@ -117,7 +117,7 @@ Value ExternNode::CodeGen() { llvm::Function* function = llvm::cast<llvm::Function>(callee.getCallee()); function->setCallingConv(llvm::CallingConv::C); context_->AddFunction(name_, {type, function}); - Log(LogLevel::PCC_INFO, "extern function {0} of type {1}", name_, + Log(LogLevel::PCC_INFO, "extern function %s of type %s", name_.c_str(), type->GetCommonName()); return nullptr; } diff --git a/node/StatementNode.cc b/node/StatementNode.cc index 40c07af..07babe2 100644 --- a/node/StatementNode.cc +++ b/node/StatementNode.cc @@ -36,7 +36,7 @@ Value AssignStatementNode::CodeGen() { std::dynamic_pointer_cast<PointerType>(lhs_->GetType()); if (LeftType == nullptr) { Log(LogLevel::PCC_ERROR, - "type {0} is not a valid pointer type, can't store anything into " + "type %s is not a valid pointer type, can't store anything into " "this lvalue", lhs_->GetType()->GetCommonName()); return nullptr; @@ -212,7 +212,7 @@ Value ForStatementNode::CodeGen() { std::dynamic_pointer_cast<PointerType>(variable_->GetType()); if (LoopPointer == nullptr) { Log(LogLevel::PCC_ERROR, - "type {0} is not a valid pointer type, can't store anything into " + "type %s is not a valid pointer type, can't store anything into " "this lvalue", variable_->GetType()->GetCommonName()); return nullptr; @@ -222,7 +222,7 @@ Value ForStatementNode::CodeGen() { LoopPointer->GetElementType()); if (LoopType == nullptr) { Log(LogLevel::PCC_ERROR, - "loop variable should have a integer-like type, not {0}", + "loop variable should have a integer-like type, not %s", LoopPointer->GetElementType()->GetCommonName()); return nullptr; } diff --git a/t/trivial.pas b/t/trivial.pas index 3be4ca5..52a6ebe 100644 --- a/t/trivial.pas +++ b/t/trivial.pas @@ -11,6 +11,18 @@ var gvp:^char; gva:array[0..4] of integer; +(**)function {}comment_test({}):integer{};(**) +{comment} +begin{ +begin(* this is in a comment *) +end; +} +comment_test:=1 +(* +{begin end; also in a comment} +*)(**)(****)(* *)(***) +end; + function arithmetic_test(a:integer;b:char;c:real):integer; var d:integer; @@ -218,15 +230,3 @@ begin pa^.m4[1].m1[2]:=1234; record_test:=a.m3[6]+pa^.m3[a.m1]+a.m4[1].m1[2]; end; - -(**)function {}comment_test({}):integer{};(**) -{comment} -begin{ -begin(* this is in a comment *) -end; -} -comment_test:=1 -(* -{begin end; also in a comment} -*)(**)(****)(* *)(***) -end; |
