From 42e4d454b11927b67c8a2fd2d49977cec6c491e8 Mon Sep 17 00:00:00 2001 From: Christophe Alexandre Date: Wed, 13 Mar 2002 19:04:02 +0000 Subject: [PATCH] OCP is back --- alliance/src/ocp/src/placer/iocgram.y | 140 ++++++++++++++++++++++++++ alliance/src/ocp/src/placer/iocscan.l | 34 +++++++ 2 files changed, 174 insertions(+) create mode 100644 alliance/src/ocp/src/placer/iocgram.y create mode 100644 alliance/src/ocp/src/placer/iocscan.l diff --git a/alliance/src/ocp/src/placer/iocgram.y b/alliance/src/ocp/src/placer/iocgram.y new file mode 100644 index 00000000..64f54f9a --- /dev/null +++ b/alliance/src/ocp/src/placer/iocgram.y @@ -0,0 +1,140 @@ +%{ +#include +#include +#include +#include "iocheader.h" + +extern int yylineno; +extern char *yytext; + +extern int yyerror(char *str); +extern int yylex(); + +char con_orient = ' '; +int onvavoir = 0; +int top_used = 0; +int bottom_used = 0; +int right_used = 0; +int left_used = 0; +int l, l2; +char buf[256]; +con_list *pt_list = NULL; + + +%} + +%union { +char *text; +} + +%token IGNORE TOP BOTTOM LEFT RIGHT IOPIN SPACE PAROUV PARFER PTVIRG PTZR +%token IOCID +%start file + +%% +file : + | orientation PAROUV expr PARFER file; + +orientation : TOP { + if (top_used == 0){ + con_orient = 'T'; + top_used = 1; + } else yyerror("on ioc file : TOP declared twice"); + } + | BOTTOM { + if (bottom_used == 0){ + con_orient = 'B'; + bottom_used = 1; + } else yyerror("on ioc file : BOTTOM declared twice"); + } + | RIGHT { + if (right_used == 0){ + con_orient = 'R'; + right_used = 1; + } else yyerror("on ioc file : RIGHT declared twice"); + } + | LEFT { + if (left_used == 0){ + con_orient = 'L'; + left_used = 1; + } else yyerror("on ioc file : LEFT declared twice"); + } + | IGNORE {con_orient = ' ';} + +expr : + | iopin expr; + | iopin space expr; + + +iopin : PAROUV IOPIN iopin1 PARFER PTVIRG; + +space : SPACE IOCID PTVIRG { + pt_list = add_space(pt_list, con_orient, $2); +} + +iopin1 : IOCID PTZR { + l = 0; + while ($1[l] != '.') l++; + strncpy(buf,$1,l); + buf[l] = '\0'; + pt_list = add_con(pt_list, con_orient, buf); + } + | IOCID PAROUV IOCID PARFER PTZR { + l = 0; + while ($1[l] != '(') l++; + strncpy(buf,$1,l); + buf[l] = ' '; + l += 1; + l2 = l; + while ($1[l] != ')') l++; + strncpy(&buf[l2],&$1[l2],l-l2); + buf[l] = '\0'; + pt_list = add_con(pt_list, con_orient, buf); + } +%% + +int yyerror (char *str) +{ + fflush(stdout); + fprintf(stderr, "error parsing the ioc file: %d: %s before %s\n", yylineno, str, yytext); + exit(1); +} + + +con_list* add_con(con_list* ptlist, char orient, char* name) +{ + con_list* ptcon; + ptcon = (con_list*) malloc(sizeof(con_list)); + + ptcon->ORIENT = orient; + ptcon->NAME = strdup(name); + ptcon->NEXT = ptlist; + + return ptcon; +} +con_list* add_space(con_list* ptlist, char orient, char *value) +{ + con_list* ptcon; + ptcon = (con_list*) malloc(sizeof(con_list)); + + ptcon->NAME = strdup("SPACE"); + ptcon->ORIENT = orient; + ptcon->VALUE = atoi(value); + ptcon->NEXT = ptlist; + + return ptcon; +} +con_list* iocparse(char *file) +{ + extern FILE *yyin; + if ((yyin = fopen(file,"r")) != NULL) { + yyparse(); + fclose(yyin); + } + else + { + printf("error : ioc file not present\n"); + exit(1); + } + return pt_list; +} diff --git a/alliance/src/ocp/src/placer/iocscan.l b/alliance/src/ocp/src/placer/iocscan.l new file mode 100644 index 00000000..bcddbf19 --- /dev/null +++ b/alliance/src/ocp/src/placer/iocscan.l @@ -0,0 +1,34 @@ +%{ +#include +#include "iocgram.h" + +#define YY_NO_UNPUT /* Avoids warning */ + +int yylineno = 1; + +%} + +%% +#.* {} +\n { ++yylineno; } +[Ii][Gg][Nn][Oo][Rr][Ee] {return IGNORE; } +[Tt][Oo][Pp] {return TOP; } +[Bb][Oo][Tt][Tt][Oo][Mm] {return BOTTOM; } +[Ll][Ee][Ff][Tt] {return LEFT; } +[Rr][Ii][Gg][Hh][Tt] {return RIGHT; } +[Ii][Oo][Pp][Ii][Nn] {return IOPIN; } +[Ss][Pp][Aa][Cc][Ee] {return SPACE; } +"(" {return PAROUV; } +")" {return PARFER; } +; {return PTVIRG; } +"\.0" {return PTZR; } +[a-zA-Z0-9_]+ {yylval.text = yytext; + return IOCID; } +[ \t]+ {} +. {return *yytext;} + +%% +int yywrap() +{ + return 1; +}