diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-17 09:16:22 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-17 09:16:22 +0000 |
| commit | 64aa538142148faf06b9a3c71907eacee04cd49d (patch) | |
| tree | 8c8b572d391a5cf5c269fd5c2484e1ba82ed5fcb /lib/CodeGen/FunctionGen.cc | |
| parent | 39e50838bd12057d9305575f50c63990984df01a (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/FunctionGen.cc')
| -rw-r--r-- | lib/CodeGen/FunctionGen.cc | 9 |
1 files changed, 6 insertions, 3 deletions
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::vector<ParamDecl } const FuncSig *FunctionGen::getSignature(const std::string &Name) const { - auto It = Signatures.find(Name); + auto It = Signatures.find(sameIdentifier(Name, "MAIN") ? "__cps_main" : Name); return It == Signatures.end() || (Visible && !Visible(It->second.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); |
