From 64aa538142148faf06b9a3c71907eacee04cd49d Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 17 Oct 2026 09:16:22 +0000 Subject: feat(codegen): FUNCTION MAIN entry point Invoke the internal entry function through the generated exception handler and truncate its INTEGER result to the process exit status. Co-Authored-By: Claude Opus 5.5 --- lib/CodeGen/FunctionGen.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/CodeGen/FunctionGen.cc') diff --git a/lib/CodeGen/FunctionGen.cc b/lib/CodeGen/FunctionGen.cc index 220a97a..47971cf 100644 --- a/lib/CodeGen/FunctionGen.cc +++ b/lib/CodeGen/FunctionGen.cc @@ -12,7 +12,7 @@ using namespace cps; // FUNCTION/PROCEDURE with one of these names would hijack the runtime. static bool isReservedRuntimeName(const std::string &Name) { static const char *Reserved[] = { - "main", "printf", "scanf", "malloc", "free", "strlen", "memcpy", + "__cps_main", "printf", "scanf", "malloc", "free", "strlen", "memcpy", "strcpy", "strcat", "toupper", "tolower", "sprintf", "snprintf", "strtol", "strtoll", "strtod", "memset", "exit", "fopen", "fclose", "fgetc", "ungetc", "fputs", "fputc", @@ -105,7 +105,7 @@ void FunctionGen::createArgumentAllocas(Function *F, const std::vectorsecond.OwnerUnit)) ? nullptr : &It->second; } @@ -180,7 +180,10 @@ Function *FunctionGen::emitPrototype(PrototypeAST *Proto) { return nullptr; } if (!F) { - F = Function::Create(FT, Function::ExternalLinkage, Proto->getLinkName(), &Module); + F = Function::Create(FT, + Proto->getOwnerClass().empty() && sameIdentifier(Proto->getName(), "MAIN") + ? Function::InternalLinkage : Function::ExternalLinkage, + Proto->getLinkName(), &Module); } Exceptions.prepareFunction(F); -- cgit v1.3.1-4-g156e