Initial revision
[charm.git] / src / xlat++ / xp-sfilter.flex
1 %{
2 #include <string.h>
3
4 char CoreName[256] ;
5 int currentline=1;
6 #ifdef yywrap
7 #undef yywrap
8 #endif
9 %}
10
11 WS [ \t\n]*
12 WSN [ \t]*
13
14 MODULE module
15 STR [ \t\n]*
16 NAME [a-z0-9A-Z_]+
17 NA [^a-zA-Z0-9_]
18
19 %%
20
21 FunctionNameToRef{WS}"("  { CheckReturns(yytext); fprintf(yyout,"FunctionNameToRef("); }
22 FunctionRefToName{WS}"("  { CheckReturns(yytext); fprintf(yyout,"FunctionRefToName("); }
23 new_message{WS}"("        { CheckReturns(yytext); fprintf(yyout,"new_message("); }
24 new_packbuffer{WS}"("     { CheckReturns(yytext); fprintf(yyout,"new_packbuffer("); }
25 delete_message{WS}"("     { CheckReturns(yytext); fprintf(yyout,"delete_message("); }
26 new_prio_message{WS}"("   { CheckReturns(yytext); fprintf(yyout,"new_prio_message("); }
27 SendMsg{WS}"("            { CheckReturns(yytext); fprintf(yyout,"SendMsg("); }
28 Insert{WS}"("             { CheckReturns(yytext); fprintf(yyout,"Insert("); }
29 Find{WS}"("               { CheckReturns(yytext); fprintf(yyout,"Find("); }
30 Delete{WS}"("             { CheckReturns(yytext); fprintf(yyout,"Delete("); }
31   
32 new_chare{WS}"("          { CheckReturns(yytext); fprintf(yyout,"new_chare("); }
33 new_branched_chare{WS}"(" { CheckReturns(yytext); fprintf(yyout,"new_branched_chare("); }
34 new_accumulator{WS}"("    { CheckReturns(yytext); fprintf(yyout,"new_accumulator("); }
35 CollectValue{WS}"("       { CheckReturns(yytext); fprintf(yyout,"CollectValue(");}
36 new_monotonic{WS}"("      { CheckReturns(yytext); fprintf(yyout,"new_monotonic("); }
37 CharmExit{WS}"("          { CheckReturns(yytext); fprintf(yyout,"CharmExit("); }
38 CPriorityPtr{WS}"("       { CheckReturns(yytext); fprintf(yyout,"CPriorityPtr("); }
39 CTimer{WS}"("             { CheckReturns(yytext); fprintf(yyout,"CTimer("); }
40 CUTimer{WS}"("            { CheckReturns(yytext); fprintf(yyout,"CUTimer("); }
41 CHTimer{WS}"("            { CheckReturns(yytext); fprintf(yyout,"CHTimer("); }
42
43 "#"{WSN}[line]{WSN}[0-9]+                               { currentline=GetLine(yytext); fprintf(yyout,"%s",yytext); }
44 "#"{WSN}[line]?{WSN}[0-9]+{WSN}\"[^\n]*\"{WSN}[0-9]+    { currentline=GetLine(yytext); fprintf(yyout,"%s",yytext); }
45 "#"{WSN}[line]?{WSN}[0-9]+{WSN}\"[^\n]*\"{WSN}[0-9]+{WSN}[0-9]+ { currentline = GetLine(yytext); fprintf(yyout,"%s",yytext);}
46 "#"{WSN}[line]?{WSN}[0-9]+{WSN}\"[^\n]*\"{WSN}[0-9]+{WSN}[0-9]+{WSN}[0-9]+ { currentline = GetLine(yytext); fprintf(yyout,"%s",yytext);}
47
48 "#"{WSN}[0-9]+{WSN}\n     { CountReturns(yytext); fprintf(yyout,"\n") ; }
49 .                         { CountReturns(yytext); fprintf(yyout,"%s",yytext); }
50
51 %%
52
53 yywrap(){ return(1); }
54
55
56 main(argc,argv) 
57 int argc ;
58 char *argv[] ;
59
60         char pgm[256] ;
61         int len; char *bgn, *end;
62
63         if ( argc != 2 ) {
64                 printf("Spacefilter invoked improperly ! Aborting.\n") ;
65                 exit(1) ;       
66         }
67 /* Find the file name */
68         strcpy(pgm,argv[1]);
69
70         bgn = strrchr(argv[1], '/');
71         if (bgn==0) bgn=argv[1];
72         end = bgn;
73         while (1)
74             {
75             char c = *end;
76             if (!(((c>='a')&&(c<='z'))||
77                   ((c>='A')&&(c<='Z'))||
78                   ((c>='0')&&(c<='9'))||
79                   (c=='_'))) break;
80             end++;
81             }
82         strncpy(CoreName, bgn, end-bgn);
83         CoreName[(end-bgn)] = '\0' ;
84
85         yyin = fopen(argv[1],"r") ;
86
87 /* Do the rest of the stuff.. */
88         writem4(); 
89         writeundef(); 
90         yylex(); 
91 }
92
93 GetLine(string)
94 char string[];
95 { int i=0,j;
96   char dummy[10];
97
98   while ((string[i]<'0')||(string[i]>'9')) i++;
99   j=0;
100   while ((string[i]>='0')&&(string[i]<='9')) dummy[j++] = string[i++];
101   dummy[j]='\0';
102   return(atoi(dummy));
103 }
104
105 output_proper_line(string)
106 char string[];
107 {
108    int length;
109
110    length=strlen(string)-1;
111    while (string[length-1]!='"') length--;
112    string[length]='\0';
113    fprintf(yyout,"%s",string);
114 }
115
116 CountReturns(string)
117 char *string;
118 {
119   while (*string) {
120     if (*string=='\n') currentline++;
121     string++;
122   }
123 }
124
125 CheckReturns(string)
126 char *string;
127 {
128   int anyret=0;
129   while (*string) {
130     if (*string=='\n') { currentline++; anyret=1; }
131     string++;
132   }
133   if (anyret)
134     fprintf(yyout,"# line %d\n",currentline);
135 }
136
137
138
139
140 /* SANJEEV */
141 char *ckfreemsg="define(delete_message,`CkFreeMsg((void *)$1)')";
142
143 char *charmexit="define(CharmExit,`CkExit()')";
144 char *cpriorityptr="define(CPriorityPtr,`CkPriorityPtr($1)')";
145 char *ctimer="define(CTimer,`CkTimer()')";
146 char *cutimer="define(CUTimer,`CkUTimer()')";
147 char *chtimer="define(CHTimer,`CkHTimer()')";
148
149
150 char * createchare="define(new_chare,`_CK_CreateChare(_CK_chare_$1,$2,$3,ifelse($4,,NULL_VID,$4),ifelse($5,,CK_PE_ANY,$5))')" ;
151
152 char * createboc="define(new_branched_chare,`_CK_CreateBoc(_CK_chare_$1,$2,$3,ifelse($4,,-1`,'NULL,$4`,'$5))')" ;
153
154 char * createacc="define(new_accumulator,`_CK_CreateAcc(_CK_acc_$1,$2,ifelse($3,,-1`,'NULL,$3`,'$4))')" ;
155 char * createmono="define(new_monotonic,`_CK_CreateMono(_CK_mono_$1,$2,ifelse($3,,-1`,'NULL,$3`,'$4))')" ;
156
157 char * functionreftoname="define(FunctionRefToName,`CsvAccess(_CK_9_GlobalFunctionTable)[$1]')" ;
158 char * functionnametoref="define(FunctionNameToRef,`_CK_func_$1')" ;
159
160 char * ckallocpackbuffer="define(new_packbuffer,`CkAllocPackBuffer($1,$2)')" ;
161
162
163
164 writem4()
165
166   char ckallocmsg[256] ;
167   char ckallocpriomsg[256] ;
168
169 /* SANJEEV */
170   printf("%s\n",ckfreemsg) ;
171   printf("%s\n%s\n%s\n%s\n%s\n",
172          charmexit,cpriorityptr,ctimer,cutimer,chtimer) ;
173   printf("%s\n%s\n%s\n%s\n",createacc,createmono,createchare, createboc);
174
175 sprintf(ckallocmsg,"define(new_message,`ifelse($2,,GenericCkAlloc(_CK_%s._CK_msg_$1`,'sizeof($1)`,'0),((ALLOCFNPTR)(CsvAccess(MsgToStructTable)[_CK_%s._CK_msg_$1].alloc))(_CK_%s._CK_msg_$1`,'sizeof($1)`,'$2`,'0))')", CoreName, CoreName, CoreName );
176
177 sprintf(ckallocpriomsg,"define(new_prio_message,`ifelse($3,,GenericCkAlloc(_CK_%s._CK_msg_$1`,'sizeof($1)`,'$2),((ALLOCFNPTR)(CsvAccess(MsgToStructTable)[_CK_%s._CK_msg_$1].alloc))(_CK_%s._CK_msg_$1`,'sizeof($1)`,'$3`,'$2))')", CoreName, CoreName, CoreName ) ;
178
179   printf("%s\n%s\n%s\n%s\n%s\n\n",ckallocmsg, ckallocpriomsg, 
180                 functionreftoname, functionnametoref, ckallocpackbuffer );
181 }
182
183
184 writeundef()
185 { printf("undefine(`changequote')\n");
186   printf("undefine(`divert')\n");
187   printf("undefine(`divnum')\n");
188   printf("undefine(`dnl')\n");
189   printf("undefine(`dumpdef')\n");
190   printf("undefine(`errprint')\n");
191   printf("undefine(`eval')\n");
192   printf("undefine(`ifdef')\n");
193   printf("undefine(`include')\n");
194   printf("undefine(`incr')\n");
195   printf("undefine(`index')\n");
196   printf("undefine(`len')\n");
197   printf("undefine(`maketemp')\n");
198   printf("undefine(`sinclude')\n");
199   printf("undefine(`substr')\n");
200   printf("undefine(`syscmd')\n");
201   printf("undefine(`translit')\n");
202   printf("undefine(`undivert')\n");
203   printf("undefine(`define')\n");
204   printf("undefine(`undefine')\n");
205 }
206