Author: kjs
Date: Thu Apr 12 03:55:58 2007
New Revision: 18163
Modified:
trunk/compilers/pirc/src/jsonout.c
trunk/compilers/pirc/src/pastout.c
trunk/compilers/pirc/src/pirout.c
Log:
compilers/pirc:
* fix errors in back-end: if no outputfile specified, seg.fault. This is now
fixed.
Modified: trunk/compilers/pirc/src/jsonout.c
==============================================================================
--- trunk/compilers/pirc/src/jsonout.c (original)
+++ trunk/compilers/pirc/src/jsonout.c Thu Apr 12 03:55:58 2007
@@ -146,7 +146,9 @@
static void
json_init(emit_data *data) {
- data->file = open_file(data->outputfile, "w");
+ if (data->outputfile) data->file = open_file(data->outputfile, "w");
+ else data->file = stdout;
+
fprintf(data->file, "{\n");
indent(data);
}
@@ -348,7 +350,7 @@
*/
static void
json_destroy(emit_data *data) {
- fclose(data->file);
+ if (data->outputfile) fclose(data->file);
free(data);
data = NULL;
}
Modified: trunk/compilers/pirc/src/pastout.c
==============================================================================
--- trunk/compilers/pirc/src/pastout.c (original)
+++ trunk/compilers/pirc/src/pastout.c Thu Apr 12 03:55:58 2007
@@ -70,12 +70,9 @@
*/
static void
past_init(struct emit_data *data) {
- data->file = fopen(data->outputfile, "w");
- if (data->file == NULL) {
- fprintf(stderr, "Failed to open file '%s'\n", data->outputfile);
- exit(1);
- }
+ if (data->outputfile) data->file = open_file(data->outputfile, "w");
+ else data->file = stdout;
fprintf(data->file, "\"past\" => PMC 'PAST::Block' {\n");
indent(data);
@@ -243,7 +240,7 @@
*/
static void
past_destroy(emit_data *data) {
- fclose(data->file);
+ if (data->outputfile) fclose(data->file);
free(data);
data = NULL;
}
Modified: trunk/compilers/pirc/src/pirout.c
==============================================================================
--- trunk/compilers/pirc/src/pirout.c (original)
+++ trunk/compilers/pirc/src/pirout.c Thu Apr 12 03:55:58 2007
@@ -110,7 +110,7 @@
*/
static void
pir_destroy(emit_data *data) {
- fclose(data->file);
+ if (data->outputfile) fclose(data->file);
free(data);
data = NULL;
}
@@ -122,7 +122,8 @@
static void
pir_init(emit_data *data) {
- data->file = open_file(data->outputfile, "w");
+ if (data->outputfile) data->file = open_file(data->outputfile, "w");
+ else data->file = stdout;
}