1
0
mirror of https://github.com/cc65/cc65.git synced 2025-02-10 09:31:08 +00:00

If main() takes arguments, generate a forced import to a special module

constructor which will setup command line arguments.


git-svn-id: svn://svn.cc65.org/cc65/trunk@2011 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2003-03-07 12:41:47 +00:00
parent 9257570050
commit 065b8f2596
3 changed files with 34 additions and 7 deletions

View File

@ -387,6 +387,14 @@ void g_defimport (const char* Name, int ZP)
void g_importmainargs (void)
/* Forced import of a special symbol that handles arguments to main */
{
AddTextLine ("\t.forceimport\tinitmainargs");
}
/*****************************************************************************/
/* Load functions for various registers */
/*****************************************************************************/

View File

@ -155,6 +155,9 @@ void g_defexport (const char* Name, int ZP);
void g_defimport (const char* Name, int ZP);
/* Import the given label */
void g_importmainargs (void);
/* Forced import of a special symbol that handles arguments to main */
/*****************************************************************************/

View File

@ -6,9 +6,9 @@
/* */
/* */
/* */
/* (C) 2000-2002 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* (C) 2000-2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
@ -369,6 +369,22 @@ void NewFunc (SymEntry* Func)
/* Allocate code and data segments for this function */
Func->V.F.Seg = PushSegments (Func);
/* Special handling for main() */
if (strcmp (Func->Name, "main") == 0) {
/* Main cannot be a fastcall function */
if (IsFastCallFunc (Func->Type)) {
Error ("`main' cannot be declared as __fastcall__");
}
/* If main() takes parameters, generate a forced import to a function
* that will setup these parameters. This way, programs that do not
* need the additional code will not get it.
*/
if (D->ParamCount > 0 || (D->Flags & FD_VARIADIC) != 0) {
g_importmainargs ();
}
}
/* If this is a fastcall function, push the last parameter onto the stack */
if (IsFastCallFunc (Func->Type) && D->ParamCount > 0) {