From 17cec530b0a4d792bde2d37583b6c26e89f9b1bd Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 13 Oct 2026 12:32:03 +0000 Subject: fix: distinguish compiler errors and report compilation termination Co-Authored-By: Claude Fable 5.1 --- lib/CodeGen/ArithmeticHandler.cc | 8 ++++---- lib/CodeGen/CodeGen.cc | 3 ++- lib/CodeGen/FunctionGen.cc | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 15 deletions(-) (limited to 'lib/CodeGen') diff --git a/lib/CodeGen/ArithmeticHandler.cc b/lib/CodeGen/ArithmeticHandler.cc index b7f0665..cd4e7b3 100644 --- a/lib/CodeGen/ArithmeticHandler.cc +++ b/lib/CodeGen/ArithmeticHandler.cc @@ -28,7 +28,7 @@ Value *ArithmeticHandler::emitBinaryOp(int Op, Value *LHS, Value *RHS, int Line) if (LVal->getType()->isIntegerTy(64)) LVal = Builder.CreateSIToFP(LVal, Type::getDoubleTy(Context)); if (RVal->getType()->isIntegerTy(64)) RVal = Builder.CreateSIToFP(RVal, Type::getDoubleTy(Context)); if (!LVal->getType()->isDoubleTy() || !RVal->getType()->isDoubleTy()) { - fprintf(stderr, "Error: '/' requires numeric operands (line %d).\n", Line); + fprintf(stderr, "error: '/' requires numeric operands (line %d).\n", Line); HadError = true; return nullptr; } @@ -39,7 +39,7 @@ Value *ArithmeticHandler::emitBinaryOp(int Op, Value *LHS, Value *RHS, int Line) if (Op == tok_div || Op == tok_mod) { if (!LIsInt || !RIsInt) { - fprintf(stderr, "Error: DIV and MOD operators require INTEGER operands (line %d).\n", Line); + fprintf(stderr, "error: DIV and MOD operators require INTEGER operands (line %d).\n", Line); HadError = true; return nullptr; } @@ -96,7 +96,7 @@ Value *ArithmeticHandler::emitBinaryOp(int Op, Value *LHS, Value *RHS, int Line) R = widenSmallInt(Builder, Context, R); } if (L->getType() != R->getType()) { - fprintf(stderr, "Error: Mismatched operand types for binary operator (line %d).\n", Line); + fprintf(stderr, "error: Mismatched operand types for binary operator (line %d).\n", Line); HadError = true; return nullptr; } @@ -114,7 +114,7 @@ Value *ArithmeticHandler::emitBinaryOp(int Op, Value *LHS, Value *RHS, int Line) } } - fprintf(stderr, "Error: Unsupported operand types for binary operator (line %d).\n", Line); + fprintf(stderr, "error: Unsupported operand types for binary operator (line %d).\n", Line); HadError = true; return nullptr; } diff --git a/lib/CodeGen/CodeGen.cc b/lib/CodeGen/CodeGen.cc index c0da7ee..f12c6ce 100644 --- a/lib/CodeGen/CodeGen.cc +++ b/lib/CodeGen/CodeGen.cc @@ -56,7 +56,7 @@ bool CodeGen::isBuiltinName(const std::string &Name) { void CodeGen::reportError(const char *Fmt, ...) { va_list Args; va_start(Args, Fmt); - fprintf(stderr, "Error: "); + fprintf(stderr, "error: "); vfprintf(stderr, Fmt, Args); fprintf(stderr, "\n"); va_end(Args); @@ -536,6 +536,7 @@ void CodeGen::compile(const std::vector> &Statements) { } if (verifyModule(*TheModule, &errs())) { + errs() << "fatal error: LLVM module verification failed\n"; HadError = true; } } diff --git a/lib/CodeGen/FunctionGen.cc b/lib/CodeGen/FunctionGen.cc index 99c6a1e..2589797 100644 --- a/lib/CodeGen/FunctionGen.cc +++ b/lib/CodeGen/FunctionGen.cc @@ -24,7 +24,7 @@ static bool isReservedRuntimeName(const std::string &Name) { Type *FunctionGen::getLLVMType(const std::string &TypeName) { Type *Resolved = Types.getLLVMType(TypeName); if (!Resolved) { - fprintf(stderr, "Error: Unknown type %s\n", TypeName.c_str()); + fprintf(stderr, "error: Unknown type %s\n", TypeName.c_str()); HadError = true; return Type::getInt64Ty(Context); } @@ -35,11 +35,11 @@ void FunctionGen::createArgumentAllocas(Function *F, const std::vectorarg_begin(); for (const ParamDecl &P : Params) { if (Types.lookupEnumConstant(P.Name)) { - fprintf(stderr, "Error: parameter '%s' collides with an enum value\n", P.Name.c_str()); + fprintf(stderr, "error: parameter '%s' collides with an enum value\n", P.Name.c_str()); HadError = true; } if (Types.resolve(P.Name)) { - fprintf(stderr, "Error: parameter '%s' collides with a type name\n", P.Name.c_str()); + fprintf(stderr, "error: parameter '%s' collides with a type name\n", P.Name.c_str()); HadError = true; } Value *ArgVal = &(*AI); @@ -85,25 +85,25 @@ const FuncSig *FunctionGen::getSignature(const std::string &Name) const { Function *FunctionGen::emitPrototype(PrototypeAST *Proto) { if (isReservedRuntimeName(Proto->getName())) { - fprintf(stderr, "Error: '%s' is a reserved runtime symbol and cannot be a FUNCTION/PROCEDURE name\n", + fprintf(stderr, "error: '%s' is a reserved runtime symbol and cannot be a FUNCTION/PROCEDURE name\n", Proto->getName().c_str()); HadError = true; return nullptr; } if (CodeGen::isBuiltinName(Proto->getName())) { - fprintf(stderr, "Error: '%s' is a built-in function and cannot be redefined\n", + fprintf(stderr, "error: '%s' is a built-in function and cannot be redefined\n", Proto->getName().c_str()); HadError = true; return nullptr; } if (Types.lookupEnumConstant(Proto->getName())) { - fprintf(stderr, "Error: '%s' is an enum value and cannot be a FUNCTION/PROCEDURE name\n", + fprintf(stderr, "error: '%s' is an enum value and cannot be a FUNCTION/PROCEDURE name\n", Proto->getName().c_str()); HadError = true; return nullptr; } if (Types.resolve(Proto->getName())) { - fprintf(stderr, "Error: '%s' is a type name and cannot be a FUNCTION/PROCEDURE name\n", + fprintf(stderr, "error: '%s' is a type name and cannot be a FUNCTION/PROCEDURE name\n", Proto->getName().c_str()); HadError = true; return nullptr; @@ -141,7 +141,7 @@ Function *FunctionGen::emitPrototype(PrototypeAST *Proto) { FunctionType *FT = FunctionType::get(RetType, ArgTypes, false); Function *F = Module.getFunction(Proto->getName()); if (F && F->getFunctionType() != FT) { - fprintf(stderr, "Error: Function %s conflicts with an existing declaration of a different type\n", + fprintf(stderr, "error: Function %s conflicts with an existing declaration of a different type\n", Proto->getName().c_str()); HadError = true; return nullptr; @@ -174,7 +174,7 @@ Function *FunctionGen::emitFunctionDef(FunctionDefAST *FuncAST, if (!TheFunction) return nullptr; if (!TheFunction->empty()) { - fprintf(stderr, "Error: Function %s cannot be redefined.\n", Proto->getName().c_str()); + fprintf(stderr, "error: Function %s cannot be redefined.\n", Proto->getName().c_str()); HadError = true; return nullptr; } @@ -210,7 +210,7 @@ static Value *GenerateCall(llvm::Module &Module, bool &HadError) { Function *CalleeF = Module.getFunction(CalleeName); if (!CalleeF) { - fprintf(stderr, "Error: Call to undefined function %s\n", CalleeName.c_str()); + fprintf(stderr, "error: Call to undefined function %s\n", CalleeName.c_str()); HadError = true; return nullptr; } -- cgit v1.3.1-4-g156e