1 /* $Id: mktables.c,v 1.5 1994/06/24 10:03:34 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
8 /* Author: E.G. Keizer */
15 /* This program reads the human readable interpreter specification
16 and produces a efficient machine representation that can be
17 translated by a C-compiler.
27 extern char em_mnem[][4] ;
28 char esca[] = "escape" ;
29 #define ename(no) ((no)==ESCAP?esca:em_mnem[(no)])
31 extern char em_flag[] ;
33 main(argc,argv) char **argv ; {
35 if ( freopen(argv[1],"r",stdin)==NULL) {
36 fatal("Cannot open %s",argv[1]) ;
40 if ( freopen(argv[2],"w",stdout)==NULL) {
41 fatal("Cannot create %s",argv[2]) ;
45 fatal("%s [ file [ file ] ]",argv[0]) ;
59 while ( !feof(stdin) ) {
61 if ( *firstid=='\n' || feof(stdin) ) continue ;
62 opcode = getmnem(firstid) ;
63 printf("%d ",opcode+1) ;
64 flags = decflag(ident(),opcode) ;
65 switch(em_flag[opcode]&EM_PAR) {
66 case PAR_D: case PAR_F: case PAR_B: case PAR_L: case PAR_C:
70 while ( (c=readchar())!='\n' && c!=EOF ) putchar(c) ;
76 /* skip spaces and tabs, anything up to space,tab or eof is
78 Anything from # to end-of-line is an end-of-line.
79 End-of-line is an identifier all by itself.
82 static char array[200] ;
88 } while ( c==' ' || c=='\t' ) ;
89 for ( cc=array ; cc<&array[(sizeof array) - 1] ; cc++ ) {
93 } while ( c!='\n' && c!=EOF ) ;
96 if ( c=='\n' && cc==array ) break ;
102 if ( c==' ' || c=='\t' || c==EOF ) break ;
108 int getmnem(str) char *str ; {
111 for ( ptr = em_mnem ; *ptr<= &em_mnem[sp_lmnem][0] ; ptr++ ) {
112 if ( strcmp(*ptr,str)==0 ) return (ptr-em_mnem) ;
114 error("Illegal mnemonic") ;
118 error(str,a1,a2,a3,a4,a5,a6) /* VARARGS1 */ char *str ; {
119 if ( !atend ) fprintf(stderr,"line %d: ",line) ;
120 fprintf(stderr,str,a1,a2,a3,a4,a5,a6) ;
121 fprintf(stderr,"\n");
125 mess(str,a1,a2,a3,a4,a5,a6) /* VARARGS1 */ char *str ; {
126 if ( !atend ) fprintf(stderr,"line %d: ",line) ;
127 fprintf(stderr,str,a1,a2,a3,a4,a5,a6) ;
128 fprintf(stderr,"\n");
131 fatal(str,a1,a2,a3,a4,a5,a6) /* VARARGS1 */ char *str ; {
132 error(str,a1,a2,a3,a4,a5,a6) ;
138 check(val) int val ; {
139 if ( val!=ILLGL ) error("Illegal flag combination") ;
142 int decflag(str,opc) char *str ; {
150 type=escape=range=wordm=notzero= ILLGL ;
151 while ( c= *str++ ) {
154 check(type) ; type=OPMINI ; break ;
156 check(type) ; type=OPSHORT ; break ;
158 check(type) ; type=OPNO ;
159 if ( (em_flag[opc]&EM_PAR)==PAR_W ) c='i' ;
162 check(type) ; type=OP8 ; break ;
164 check(type) ; type=OP16 ; break ;
166 check(type) ; type=OP32 ; break ;
168 check(type) ; type=OP64 ; break ;
170 check(type) ; type=OP16U ; break ;
172 check(escape) ; escape=0 ; break ;
174 check(range) ; range= 2 ; break ;
176 check(range) ; range= 1 ; break ;
178 check(wordm) ; wordm=0 ; break ;
180 check(notzero) ; notzero=0 ; break ;
182 error("Unknown flag") ;
186 if ( type==ILLGL ) error("Type must be specified") ;
190 if ( escape!=ILLGL ) error("Conflicting escapes") ;
197 if ( notzero!=ILLGL ) mess("Improbable OPNZ") ;
198 if ( type==OPNO && range!=ILLGL ) {
199 mess("No operand in range") ;
202 if ( escape!=ILLGL ) type|=OPESC ;
203 if ( wordm!=ILLGL ) type|=OPWORD ;
205 case ILLGL : type|=OP_BOTH ; break ;
206 case 1 : type|=OP_POS ; break ;
207 case 2 : type|=OP_NEG ; break ;
209 if ( notzero!=ILLGL ) type|=OPNZ ;
213 static int pushchar ;
223 if ( feof(stdin) ) return EOF ;
226 if ( c=='\n' ) line++ ;
232 fatal("Double pushback") ;
236 if ( c=='\n' ) line-- ;