Author: kjs
Date: Sun Dec 28 10:45:05 2008
New Revision: 34512
Modified:
trunk/compilers/pirc/new/main.c
trunk/compilers/pirc/new/pircompiler.h
trunk/compilers/pirc/new/pircompunit.c
trunk/compilers/pirc/new/piremit.c
trunk/compilers/pirc/new/piremit.h
Log:
[pirc] fix -o commandline option, so it works with -H and -E.
Modified: trunk/compilers/pirc/new/main.c
==============================================================================
--- trunk/compilers/pirc/new/main.c (original)
+++ trunk/compilers/pirc/new/main.c Sun Dec 28 10:45:05 2008
@@ -74,8 +74,7 @@
" -H heredoc preprocessing only\n"
" -m <size> specify initial macro buffer size; default is 4096 bytes\n"
" -n no output, only print 'ok' if successful\n"
- " -o <file> write output to the specified file. "
- "Currently only works in combination with '-E' option\n"
+ " -o <file> write output to the specified file.\n"
" -p pasm output\n"
" -r activate the register allocator for improved register usage\n"
" -S do not perform strength reduction\n"
@@ -136,7 +135,8 @@
This will be the proper declaration after testing for thread-safety:
-void parse_file(int flexdebug, FILE *infile, char * const filename, int flags)
+void parse_file(int flexdebug, FILE *infile, char * const filename, int flags,
+ char * const outputfile)
*/
@@ -144,7 +144,7 @@
void
parse_file(int flexdebug, FILE *infile, char * const filename, int flags, int
thr_id,
- unsigned macro_size)
+ unsigned macro_size, char * const outputfile)
{
yyscan_t yyscanner;
lexer_state *lexer = NULL;
@@ -184,7 +184,7 @@
if (TEST_FLAG(lexer->flags, LEXER_FLAG_NOOUTPUT)) /* handy for testing
the compiler */
fprintf(stdout, "ok\n");
else if (TEST_FLAG(lexer->flags, LEXER_FLAG_PREPROCESS))
- emit_pir_subs(lexer);
+ emit_pir_subs(lexer, outputfile);
else if (TEST_FLAG(lexer->flags, LEXER_FLAG_OUTPUTPBC))
emit_pbc(lexer);
else
@@ -300,7 +300,7 @@
int thr_id = args->thr_id;
int flags = args->flags;
- parse_file(flexdebug, infile, filename, flags, thr_id, INIT_MACRO_SIZE);
+ parse_file(flexdebug, infile, filename, flags, thr_id, INIT_MACRO_SIZE,
NULL);
return NULL;
}
@@ -325,6 +325,7 @@
int flags = 0;
char *filename = NULL;
char *outputfile = NULL;
+ char *hdocoutfile = NULL;
unsigned macrosize = INIT_MACRO_SIZE;
@@ -469,17 +470,26 @@
exit(EXIT_FAILURE);
}
- /* if user requested only to process heredocs, send output to stdout and
return. */
- if (TEST_FLAG(flags, LEXER_FLAG_HEREDOCONLY)) {
+ if (outputfile != NULL && TEST_FLAG(flags, LEXER_FLAG_HEREDOCONLY)) {
+ file = open_file(outputfile, "w");
+ process_heredocs(argv[0], file);
+ fclose(file);
+ return 0;
+ }
+ else if (TEST_FLAG(flags, LEXER_FLAG_HEREDOCONLY)) {
process_heredocs(argv[0], stdout);
return 0;
}
+ else {
+ hdocoutfile = _tempnam(NULL, "hdoc");
+ file = open_file(hdocoutfile, "w");
+ process_heredocs(argv[0], file);
+ fclose(file);
+ }
+
- file = fopen("heredoc.out", "w");
- process_heredocs(argv[0], file);
- fclose(file);
/* done handling arguments, open the file */
- file = open_file("heredoc.out", "r");
+ file = open_file(hdocoutfile, "r");
filename = argv[0];
if (file == NULL) {
@@ -487,7 +497,7 @@
exit(EXIT_FAILURE);
}
- parse_file(flexdebug, file, filename, flags, 0, macrosize);
+ parse_file(flexdebug, file, filename, flags, 0, macrosize, outputfile);
}
#endif
Modified: trunk/compilers/pirc/new/pircompiler.h
==============================================================================
--- trunk/compilers/pirc/new/pircompiler.h (original)
+++ trunk/compilers/pirc/new/pircompiler.h Sun Dec 28 10:45:05 2008
@@ -90,7 +90,7 @@
int flags; /* general flags, e.g. warnings level */
unsigned parse_errors;
char const *filename; /* name of input file */
- FILE *outfile; /* name of output file */
+ FILE *outfile; /* output file */
subroutine *subs; /* list of subs; always points to the
current sub. */
Modified: trunk/compilers/pirc/new/pircompunit.c
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.c (original)
+++ trunk/compilers/pirc/new/pircompunit.c Sun Dec 28 10:45:05 2008
@@ -655,12 +655,12 @@
/* :slurpy can only be set on a PMC parameter */
if (TEST_FLAG(flag, TARGET_FLAG_SLURPY) && param->info->type != PMC_TYPE)
yypirerror(lexer->yyscanner, lexer,
- "cannot set :slurpy flag on non-pmc %s",
param->info->id.name);
+ "cannot set :slurpy flag on non-pmc parameter '%s'",
param->info->id.name);
/* :opt_flag can only be set on a int parameter */
if (TEST_FLAG(flag, TARGET_FLAG_OPT_FLAG) && param->info->type != INT_TYPE)
yypirerror(lexer->yyscanner, lexer,
- "cannot set :opt_flag flag on non-int %s",
param->info->id.name);
+ "cannot set :opt_flag flag on non-int parameter '%s'",
param->info->id.name);
return param;
}
Modified: trunk/compilers/pirc/new/piremit.c
==============================================================================
--- trunk/compilers/pirc/new/piremit.c (original)
+++ trunk/compilers/pirc/new/piremit.c Sun Dec 28 10:45:05 2008
@@ -44,7 +44,7 @@
"lexid"
};
-#define out stdout
+#define out lexer->outfile
/* the order of these letters match with the pir_type enumeration.
* These are used for human-readable PASM output.
@@ -377,11 +377,17 @@
*/
void
-emit_pir_subs(lexer_state * const lexer) {
+emit_pir_subs(lexer_state * const lexer, char const * const outfile) {
if (lexer->subs != NULL) {
/* set iterator to first item */
subroutine *subiter = lexer->subs->next;
+ if (outfile)
+ lexer->outfile = fopen(outfile, "w");
+ else
+ lexer->outfile = stdout;
+
+
do {
int i;
fprintf(out, "\n.namespace ");
@@ -589,26 +595,30 @@
if (lexer->subs == NULL)
return;
-
+/*
fprintf(stderr, "emit_pbc(): starting...\n");
-
+*/
create_codesegment(lexer->bc, lexer->codesize);
+/*
fprintf(stderr, "ok 1\n");
+*/
subiter = lexer->subs->next;
assert(subiter);
/* iterate over all instructions and emit them */
do {
+/*
fprintf(stderr, "start offset of sub '%s' is: %d\tend offest: %d\n",
subiter->info.subname, subiter->info.startoffset,
subiter->info.endoffset);
-
+*/
emit_pbc_sub(lexer, subiter);
subiter = subiter->next;
}
while (subiter != lexer->subs->next);
/* write the output to a file. */
+
write_pbc_file(lexer->bc, "a.pbc");
/* XXX just make sure no seg. faults happened */
Modified: trunk/compilers/pirc/new/piremit.h
==============================================================================
--- trunk/compilers/pirc/new/piremit.h (original)
+++ trunk/compilers/pirc/new/piremit.h Sun Dec 28 10:45:05 2008
@@ -11,7 +11,7 @@
struct constant;
void print_subs(struct lexer_state * const lexer);
-void emit_pir_subs(struct lexer_state * const lexer);
+void emit_pir_subs(struct lexer_state * const lexer, char const * const
outfile);
void emit_pbc(struct lexer_state * const lexer);
int emit_pbc_const(struct lexer_state * const lexer, struct constant * const
pirconst);