--- a/c2iec.y +++ b/c2iec.y @@ -69,6 +69,9 @@ // check if fifo is empty int fifo_empty(fifo_entry_t type); +// check fill status of queue +int fifo_size(fifo_entry_t type); + // map c datatype to iec (standard and userdefined) char *maptype(char *ctype); @@ -95,7 +98,6 @@ static char s_szFuncName[SYM_SIZE]; void setFunctionName(char *szName); char *getFunctionName(void); - // lex/yacc functions extern int yylex (void); @@ -312,19 +314,25 @@ | declaration_specifiers init_declarator_list ';' { char *p; + int isFuncDecl = 0; while( (p=fifo_pop(decl_func)) != NULL) { printf(p, $<str>1); + isFuncDecl = 1; } while( (p=fifo_pop(decl_param)) != NULL) { printf(p, $<str>1); + isFuncDecl = 0; } while( (p=fifo_pop(decl_all)) != NULL) { printf(p, $<str>1); + isFuncDecl = 0; } strcpy($<str>$, ""); + if (isFuncDecl) + printf("END_FUNCTION\n\n"); } ; @@ -510,7 +518,7 @@ // don't push function declarations to decl_all if (fifo_empty(decl_func)) { - fifo_push(decl_all, $<str>$); + fifo_push(decl_all, $<str>$); } } | direct_declarator @@ -530,11 +538,11 @@ direct_declarator : IDENTIFIER | '(' declarator ')' - { printf ("not supported direct_declerator\n"); } + { printf ("not supported direct_declerator\n"); exit(-1); } | direct_declarator '[' type_qualifier_list assignment_expression ']' - { printf ("not supported direct_declerator\n"); } + { printf ("not supported direct_declerator\n"); exit(-1); } | direct_declarator '[' type_qualifier_list ']' - { printf ("not supported direct_declerator\n"); } + { printf ("not supported direct_declerator\n"); exit(-1); } | direct_declarator '[' assignment_expression ']' { if (strlen($<str>1) > 0) @@ -790,6 +798,7 @@ printf(p, $<str>1); } printf("%s", $<str>3); + printf("END_FUNCTION\n"); strcpy($<str>$, ""); } ; @@ -861,6 +870,11 @@ return 1; } return 0; +} + +int fifo_size(fifo_entry_t type) +{ + return ((s_fifos[type].write + FIFO_SIZE) - s_fifos[type].read) % FIFO_SIZE; } void fifo_tag(fifo_entry_t type)