Author: kjs
Date: Fri Mar 30 14:13:18 2007
New Revision: 17868
Modified:
trunk/compilers/pirc/src/no_output.c
trunk/compilers/pirc/src/pirmain.c
trunk/compilers/pirc/src/pirout.c
trunk/compilers/pirc/src/pirparser.c
trunk/compilers/pirc/src/pirvtable.h
Log:
compilers/pirc:
* add name routine to vtable
Modified: trunk/compilers/pirc/src/no_output.c
==============================================================================
--- trunk/compilers/pirc/src/no_output.c (original)
+++ trunk/compilers/pirc/src/no_output.c Fri Mar 30 14:13:18 2007
@@ -14,6 +14,7 @@
vtable->sub_start = none;
vtable->sub_end = none;
+ vtable->name = none;
return vtable;
}
Modified: trunk/compilers/pirc/src/pirmain.c
==============================================================================
--- trunk/compilers/pirc/src/pirmain.c (original)
+++ trunk/compilers/pirc/src/pirmain.c Fri Mar 30 14:13:18 2007
@@ -19,7 +19,7 @@
/* create a new parser, specifying the file name */
- p = new_parser(argv[1], OUTPUT_NONE);
+ p = new_parser(argv[1], OUTPUT_PAST);
/* start parsing */
TOP(p);
Modified: trunk/compilers/pirc/src/pirout.c
==============================================================================
--- trunk/compilers/pirc/src/pirout.c (original)
+++ trunk/compilers/pirc/src/pirout.c Fri Mar 30 14:13:18 2007
@@ -4,7 +4,7 @@
#include <stdio.h>
#include <malloc.h>
-/*
+/*
=head1 API
@@ -25,7 +25,7 @@
/*fprintf(stderr, "pirout:\n");
*/
-
+
switch (t) {
case T_RPAREN: /* HACK */
fprintf(stderr, ")"); /* and print newline as well, nec. for
macros */
@@ -55,6 +55,11 @@
}
+static void
+pir_name(struct parser_state *p, char *name) {
+ fprintf(stderr, " %s ", name);
+}
+
/*
@@ -69,10 +74,11 @@
pirvtable *
init_pir_vtable(void) {
pirvtable *vtable = (pirvtable *)malloc(sizeof(pirvtable));
-
+
vtable->sub_start = pirout;
vtable->sub_end = pirout;
-
+ vtable->name = pir_name;
+
return vtable;
}
Modified: trunk/compilers/pirc/src/pirparser.c
==============================================================================
--- trunk/compilers/pirc/src/pirparser.c (original)
+++ trunk/compilers/pirc/src/pirparser.c Fri Mar 30 14:13:18 2007
@@ -55,11 +55,13 @@
#include "pirlexer.h"
#include "pirparser.h"
+
+/* output stuff */
#include "pirvtable.h"
+#include "pirout.h" /* for PIR output */
+#include "pastout.h" /* for PAST output */
+#include "no_output.h" /* guess what... */
-#include "pirout.h" /* for test output */
-#include "pastout.h" /* experimental output of PAST */
-#include "no_output.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
@@ -73,11 +75,12 @@
The parser_state structure has the following fields:
typedef struct parser_state {
- struct lexer_state *lexer; -- the lexer
- token curtoken; -- the current token as returned by the
lexer
- char *heredoc_ids[10]; -- array for holding heredoc arguments.
XXX Limited to 10 currently XXX
- unsigned heredoc_index; -- index to keep track of heredoc ids in
the array
- unsigned parse_errors; -- counter for parse_errors
+ struct lexer_state *lexer; -- the lexer
+ token curtoken; -- the current token as returned by the
lexer
+ char *heredoc_ids[10]; -- array for holding heredoc arguments.
XXX Limited to 10 currently XXX
+ unsigned heredoc_index; -- index to keep track of heredoc ids
in the array
+ unsigned parse_errors; -- counter for parse_errors
+ pirvtable *vtable; -- vtable holding pointers for output
}
=cut
@@ -85,13 +88,13 @@
*/
typedef struct parser_state {
- struct lexer_state *lexer;
- token curtoken;
- char *heredoc_ids[10];
- unsigned heredoc_index;
- unsigned parse_errors;
+ struct lexer_state *lexer;
+ token curtoken;
+ char *heredoc_ids[10];
+ unsigned heredoc_index;
+ unsigned parse_errors;
pirvtable *vtable;
-
+
} parser_state;
@@ -101,7 +104,7 @@
/* call next() to get the next token from the lexer */ /* NOTE: it's calling
pirout() */
-#define next(P) P->curtoken = next_token(P->lexer)
+#define next(P) P->curtoken = next_token(P->lexer)
/*
#define next(P) do { pirout(P); P->curtoken = next_token(P->lexer); } while(0)
@@ -167,7 +170,8 @@
p->curtoken = next_token(p->lexer);
p->parse_errors = 0;
p->heredoc_index = 0;
-
+
+ /* based on the output type, create the appropiate vtable */
switch (output) {
case OUTPUT_NONE:
p->vtable = init_none_vtable();
@@ -177,12 +181,12 @@
break;
case OUTPUT_PAST:
p->vtable = init_past_vtable();
- break;
+ break;
default:
fprintf(stderr, "Unknown output type specified\n");
exit(1);
}
-
+
return p;
}
@@ -1806,23 +1810,30 @@
/* either '.sub' or '.pcc_sub'. This kind of optimization (just skipping)
* can be done more often, if we're sure the token has already been
checked for.
*/
+
+ /* call emit method */
+ emit_sub_start(p);
+
next(p);
- if (p->curtoken == T_IDENTIFIER) match(p, T_IDENTIFIER);
- else stringconstant(p);
-
- /* call emit method */
- emit_sub_start(p);
-
+ if (p->curtoken == T_IDENTIFIER) {
+ emit_name(p, get_current_token(p->lexer));
+ match(p, T_IDENTIFIER);
+ }
+ else {
+ emit_name(p, get_current_token(p->lexer));
+ stringconstant(p);
+ }
+
sub_flags(p);
match(p, T_NEWLINE);
parameters(p);
instructions(p);
match(p, T_END);
-
+
/* call emit method */
emit_sub_end(p);
-
+
}
/*
Modified: trunk/compilers/pirc/src/pirvtable.h
==============================================================================
--- trunk/compilers/pirc/src/pirvtable.h (original)
+++ trunk/compilers/pirc/src/pirvtable.h Fri Mar 30 14:13:18 2007
@@ -7,10 +7,11 @@
* routines.
*/
typedef struct pirvtable {
-
+
void (* sub_start)(struct parser_state *p);
void (* sub_end) (struct parser_state *p);
-
+ void (* name) (struct parser_state *p, char *name);
+
} pirvtable;
@@ -18,6 +19,8 @@
/* #defines for cleaner invocation syntax */
# define emit_sub_start(P) (*P->vtable->sub_start)(P)
# define emit_sub_end(P) (*P->vtable->sub_end) (P)
+# define emit_name(P,N) (*P->vtable->name) (P,N)
+
@@ -31,4 +34,3 @@
* End:
* vim: expandtab shiftwidth=4:
*/
-
\ No newline at end of file