[Pvfs2-cvs] commit by walt in pvfs2-1/src/common/statecomp:
codegen.c parser.y scanner.l
CVS commit program
cvs at parl.clemson.edu
Tue Aug 1 11:52:02 EDT 2006
Update of /projects/cvsroot/pvfs2-1/src/common/statecomp
In directory parlweb1:/tmp/cvs-serv30331/src/common/statecomp
Modified Files:
Tag: WALT3
codegen.c parser.y scanner.l
Log Message:
updated term code, SM union remval and statecomp update for pjmp states
compiles clean, beginning test
Index: codegen.c
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/common/statecomp/codegen.c,v
diff -p -u -r1.20 -r1.20.4.1
--- codegen.c 30 May 2006 19:17:13 -0000 1.20
+++ codegen.c 1 Aug 2006 15:52:02 -0000 1.20.4.1
@@ -18,12 +18,13 @@
extern FILE *out_file;
extern int terminate_path_flag;
static char *current_machine;
+static int needcomma = 1;
void gen_init(void);
void gen_state_decl(char *state_name);
void gen_machine(char *machine_name, char *first_state_name);
void gen_state_start(char *state_name);
-void gen_state_action(char *run_func, int flag);
+void gen_state_action(char *run_func, int flag, char *state_action);
void gen_return_code(char *return_code);
void gen_next_state(int flag, char *new_state);
void gen_state_end(void);
@@ -35,8 +36,11 @@ void gen_init(void)
void gen_state_decl(char *state_name)
{
- fprintf(out_file, "static union PINT_state_array_values ST_%s[];\n",
- state_name);
+ fprintf(out_file, "static struct PINT_state_s ST_%s[];\n", state_name);
+ fprintf(out_file, "static struct PINT_pjmp_tbl_s ST_%s_pjtbl[];\n",
+ state_name);
+ fprintf(out_file, "static struct PINT_tran_tbl_s ST_%s_trtbl[];\n",
+ state_name);
}
void gen_machine(char *machine_name,
@@ -52,9 +56,9 @@ void gen_machine(char *machine_name,
void gen_state_start(char *state_name)
{
fprintf(out_file,
- "static union PINT_state_array_values ST_%s[] = {\n"
+ "static struct PINT_state_s ST_%s[] = {\n"
"\t{ .state_name = \"%s\" },\n"
- "\t{ .parent_machine = &%s },\n",
+ "\t{ .parent_machine = &%s },\n" ,
state_name, state_name, current_machine);
}
@@ -63,16 +67,26 @@ void gen_state_start(char *state_name)
* or "jump") and the second being the action itself (either a
* function or a nested state machine).
*/
-void gen_state_action(char *run_func, int flag)
+void gen_state_action(char *run_func, int flag, char *state_name)
{
switch (flag) {
- case SM_NONE:
- fprintf(out_file, "\t{ .flag = SM_NONE },\n");
- fprintf(out_file, "\t{ .state_action = %s }", run_func);
+ case SM_RUN:
+ fprintf(out_file, "\t{ .flag = SM_RUN },\n");
+ fprintf(out_file, "\t{ .action.func = %s },\n", run_func);
+ fprintf(out_file,"\t{ .pjtbl = NULL },\n");
+ fprintf(out_file,"\t{ .trtbl = ST_%s_trtbl }", state_name);
+ break;
+ case SM_PJMP:
+ fprintf(out_file, "\t{ .flag = SM_PJMP },\n");
+ fprintf(out_file, "\t{ .action.nested = &%s },\n", run_func);
+ fprintf(out_file,"\t{ .pjtbl = ST_%s_pjtbl },\n", state_name);
+ fprintf(out_file,"\t{ .trtbl = ST_%s_trtbl }", state_name);
break;
case SM_JUMP:
fprintf(out_file, "\t{ .flag = SM_JUMP },\n");
- fprintf(out_file, "\t{ .nested_machine = &%s }", run_func);
+ fprintf(out_file, "\t{ .action.nested = &%s },\n", run_func);
+ fprintf(out_file,"\t{ .pjtbl = NULL },\n");
+ fprintf(out_file,"\t{ .trtbl = ST_%s_trtbl }", state_name);
break;
default:
fprintf(stderr,
@@ -80,32 +94,59 @@ void gen_state_action(char *run_func, in
run_func);
exit(1);
}
+ /* generate the end of the state struct with refs to jump tbls */
+}
+
+void gen_trtbl(char *state_name)
+{
+ fprintf(out_file,"\n};\n\n");
+ fprintf(out_file,"static struct PINT_tran_tbl_s ST_%s_trtbl[] = {\n",
+ state_name);
+ needcomma = 0;
+}
+
+void gen_pjtbl(char *state_name)
+{
+ fprintf(out_file,"\n};\n\n");
+ fprintf(out_file,"static struct PINT_pjmp_tbl_s ST_%s_pjtbl[] = {\n",
+ state_name);
+ needcomma = 0;
}
void gen_return_code(char *return_code)
{
- fprintf(out_file, ",\n\t{ .return_value = %s }", return_code);
+ if (needcomma)
+ {
+ fprintf(out_file,",\n");
+ }
+ fprintf(out_file, "\t{ .return_value = %s }", return_code);
+ needcomma = 1;
}
void gen_next_state(int flag, char *new_state)
{
+ if (needcomma)
+ {
+ fprintf(out_file,",\n");
+ }
switch (flag) {
case SM_NEXT:
- fprintf(out_file, ",\n\t{ .next_state = ST_%s }", new_state);
+ fprintf(out_file, "\t{ .next_state = ST_%s }", new_state);
break;
case SM_RETURN:
terminate_path_flag = 1;
- fprintf(out_file, ",\n\t{ .flag = SM_RETURN }");
+ fprintf(out_file, "\t{ .flag = SM_RETURN }");
break;
- case SM_TERMINATE:
+ case SM_TERM:
terminate_path_flag = 1;
- fprintf(out_file, ",\n\t{ .flag = SM_TERMINATE }");
+ fprintf(out_file, "\t{ .flag = SM_TERM }");
break;
default:
fprintf(stderr,
"invalid flag associated with target (no more info)\n");
exit(1);
}
+ needcomma = 1;
}
void gen_state_end(void)
Index: parser.y
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/common/statecomp/parser.y,v
diff -p -u -r1.25 -r1.25.36.1
--- parser.y 11 Jan 2005 14:00:27 -0000 1.25
+++ parser.y 1 Aug 2006 15:52:02 -0000 1.25.36.1
@@ -24,7 +24,9 @@ void gen_init(void);
void gen_state_decl(char *state_name);
void gen_state_array(char *machine_name, char *first_state_name);
void gen_state_start(char *state_name);
-void gen_state_action(char *run_func, int flag);
+void gen_state_action(char *run_func, int flag, char *state_name);
+void gen_trtbl(char *state_name);
+void gen_pjtbl(char *state_name);
void gen_return_code(char *return_code);
void gen_next_state(int flag, char *new_state);
void gen_state_end(void);
@@ -57,6 +59,7 @@ void yyerror(char *);
%token <i> STATE
%token <i> EXTERN
%token <i> RUN
+%token <i> PJMP
%token <i> JUMP
%token <i> STATE_RETURN
%token <i> STATE_TERMINATE
@@ -79,6 +82,7 @@ void yyerror(char *);
%type <s> state_decl_list .state_decl_list. state_decl
state_def state_def_list .state_def_list.
transition transition_list state_machine target state_machine_list
+ task task_list
%start state_machine_list
@@ -141,17 +145,18 @@ state_def_list : state_def
| state_def state_def_list
;
-state_def : STATE identifier LBRACE
- {$$ = symlook($2);
- if ($$->type != TYPE_STATE){
- fprintf(stderr,"bad state identifier %s\n", $2);
- fprintf(stderr,"declared as another type\n");
- exit(1);
- }
- else{
- gen_state_start($2);}}
- .state_body. RBRACE
- {gen_state_end();}
+state_def : STATE identifier LBRACE
+ {$$ = symlook($2);
+ if ($$->type != TYPE_STATE)
+ {
+ fprintf(stderr,"bad state identifier %s\n", $2);
+ fprintf(stderr,"declared as another type\n");
+ exit(1);
+ } else{
+ gen_state_start($2);}
+ }
+ .state_body. RBRACE
+ {gen_state_end();}
;
.state_body. : /* empty */
@@ -159,13 +164,30 @@ state_def : STATE identifier LBRACE
| state_body
;
-state_body : state_action transition_list
+state_body : state_action
+ {gen_trtbl($<c>-2);}
+ transition_list
;
state_action : RUN identifier SEMICOLON
- {gen_state_action($2, SM_NONE);}
+ {gen_state_action($2, SM_RUN, $<c>-2);}
+ | PJMP identifier
+ {gen_state_action($2, SM_PJMP, $<c>-2);}
+ LBRACE
+ {gen_pjtbl($<c>-2);}
+ task_list RBRACE SEMICOLON
| JUMP identifier SEMICOLON
- {gen_state_action($2, SM_JUMP);}
+ {gen_state_action($2, SM_JUMP, $<c>-2);}
+ ;
+
+task_list : task
+ | task task_list
+ ;
+
+task : return_code
+ {gen_return_code($1);}
+ ARROW identifier SEMICOLON
+ {gen_next_state(SM_NEXT, $4);}
;
transition_list : transition
@@ -178,20 +200,21 @@ transition : return_code
{$$ = $4;}
;
-target : identifier
+target : identifier
{$$ = symlook($1);
if ($$ == NULL){
- fprintf(stderr,"jump to undeclared state %s\n", $1);
- exit(1);
- }
- else{
- gen_next_state(SM_NEXT, $$->name);}}
+ fprintf(stderr,"jump to undeclared state %s\n", $1);
+ exit(1);
+ }else{
+ gen_next_state(SM_NEXT, $$->name);
+ }
+ }
| STATE_RETURN
{$$ = NULL;
gen_next_state(SM_RETURN, NULL);}
| STATE_TERMINATE
{$$ = NULL;
- gen_next_state(SM_TERMINATE, NULL);}
+ gen_next_state(SM_TERM, NULL);}
;
return_code : SUCCESS {$$ = "0";}
Index: scanner.l
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/common/statecomp/scanner.l,v
diff -p -u -r1.17 -r1.17.14.1
--- scanner.l 20 Dec 2005 16:58:54 -0000 1.17
+++ scanner.l 1 Aug 2006 15:52:02 -0000 1.17.14.1
@@ -88,6 +88,7 @@ w [ \t\n]*
<CODE>"extern" {LIST; RETURNVAL(EXTERN);}
<CODE>"return" {LIST; RETURNVAL(STATE_RETURN);}
<CODE>"run" {LIST; RETURNVAL(RUN);}
+<CODE>"pjmp" {LIST; RETURNVAL(PJMP);}
<CODE>"jump" {LIST; RETURNVAL(JUMP);}
<CODE>"success" {LIST; RETURNVAL(SUCCESS);}
<CODE>"default" {LIST; RETURNVAL(DEFAULT);}
More information about the Pvfs2-cvs
mailing list