Make QuakePascal programs runnable.

Generate a mini-main function (".main", to avoid namespace pollution) that
calls the function named by "program", and make qwaq check for ".main" as
well as "main". If both are present, ".main" will take priority.
This commit is contained in:
Bill Currie 2011-01-12 23:35:56 +09:00
parent 332b7da127
commit 02b3dde83b
2 changed files with 22 additions and 1 deletions

View file

@ -41,9 +41,11 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
# include <strings.h>
#endif
#include "codespace.h"
#include "expr.h"
#include "function.h"
#include "qfcc.h"
#include "reloc.h"
#include "type.h"
#define YYDEBUG 1
@ -169,10 +171,28 @@ program
}
compound_statement '.'
{
def_t *main_def;
function_t *main_func;
expr_t *main_expr;
current_scope = current_scope->parent;
//current_storage = st_global;
build_code_function (current_func, 0, $5);
current_func = 0;
main_def = get_def (&type_function, ".main", pr.scope, st_static);
current_func = main_func = new_function (main_def, 0);
add_function (main_func);
reloc_def_func (main_func, main_def->ofs);
main_func->code = pr.code->size;
build_scope (main_func, main_def, 0);
build_function (main_func);
main_expr = new_block_expr ();
append_expr (main_expr,
build_function_call (new_def_expr ($1), $1->type, 0));
emit_function (main_func, main_expr);
finish_function (main_func);
current_func = 0;
}
;

View file

@ -173,7 +173,8 @@ main (int argc, char **argv)
pr_argv[i] = PR_SetTempString (&pr, argv[1 + i]);
pr_argv[i] = 0;
if ((dfunc = PR_FindFunction (&pr, "main")))
if ((dfunc = PR_FindFunction (&pr, ".main"))
|| (dfunc = PR_FindFunction (&pr, "main")))
main_func = dfunc - pr.pr_functions;
else
PR_Undefined (&pr, "function", "main");