| 1 | /* |
| 2 | * C second pass -- tables |
| 3 | */ |
| 4 | #include "c1.h" |
| 5 | /* |
| 6 | * Operator dope table-- see description in c0. |
| 7 | */ |
| 8 | int opdope[] { |
| 9 | 000000, /* EOFC */ |
| 10 | 000000, /* ; */ |
| 11 | 000000, /* { */ |
| 12 | 000000, /* } */ |
| 13 | 036000, /* [ */ |
| 14 | 002000, /* ] */ |
| 15 | 036000, /* ( */ |
| 16 | 002000, /* ) */ |
| 17 | 014201, /* : */ |
| 18 | 007001, /* , */ |
| 19 | 000000, /* field selection */ |
| 20 | 000000, /* reverse field selection */ |
| 21 | 000001, /* temporary field selection */ |
| 22 | 000001, /* int->ptr */ |
| 23 | 000001, /* ptr->int */ |
| 24 | 000001, /* long->ptr */ |
| 25 | 000001, /* field assignment */ |
| 26 | 000001, /* >> unsigned */ |
| 27 | 000001, /* >> unsigned */ |
| 28 | 000000, /* 19 */ |
| 29 | 000400, /* name */ |
| 30 | 000400, /* short constant */ |
| 31 | 000400, /* string */ |
| 32 | 000400, /* float */ |
| 33 | 000400, /* double */ |
| 34 | 0000400, /* long const */ |
| 35 | 000400, /* long const <= 16 bits */ |
| 36 | 000400, /* autoi, *r++ */ |
| 37 | 000400, /* autod, *--r */ |
| 38 | 000000, /* 29 */ |
| 39 | 034203, /* ++pre */ |
| 40 | 034203, /* --pre */ |
| 41 | 034203, /* ++post */ |
| 42 | 034203, /* --post */ |
| 43 | 034220, /* !un */ |
| 44 | 034202, /* &un */ |
| 45 | 034220, /* *un */ |
| 46 | 034200, /* -un */ |
| 47 | 034220, /* ~un */ |
| 48 | 036001, /* . (structure reference) */ |
| 49 | 030101, /* + */ |
| 50 | 030001, /* - */ |
| 51 | 032101, /* * */ |
| 52 | 032001, /* / */ |
| 53 | 032001, /* % */ |
| 54 | 026061, /* >> */ |
| 55 | 026061, /* << */ |
| 56 | 020161, /* & */ |
| 57 | 016161, /* | */ |
| 58 | 016161, /* ^ */ |
| 59 | 036001, /* -> */ |
| 60 | 001000, /* int -> double */ |
| 61 | 001000, /* double -> int */ |
| 62 | 000001, /* && */ |
| 63 | 000001, /* || */ |
| 64 | 030001, /* &~ */ |
| 65 | 001000, /* double -> long */ |
| 66 | 001000, /* long -> double */ |
| 67 | 001000, /* integer -> long */ |
| 68 | 000000, /* long -> integer */ |
| 69 | 022005, /* == */ |
| 70 | 022005, /* != */ |
| 71 | 024005, /* <= */ |
| 72 | 024005, /* < */ |
| 73 | 024005, /* >= */ |
| 74 | 024005, /* > */ |
| 75 | 024005, /* <p */ |
| 76 | 024005, /* <=p */ |
| 77 | 024005, /* >p */ |
| 78 | 024005, /* >=p */ |
| 79 | 012213, /* =+ */ |
| 80 | 012213, /* =- */ |
| 81 | 012213, /* =* */ |
| 82 | 012213, /* =/ */ |
| 83 | 012213, /* =% */ |
| 84 | 012253, /* =>> */ |
| 85 | 012253, /* =<< */ |
| 86 | 012253, /* =& */ |
| 87 | 012253, /* =| */ |
| 88 | 012253, /* =^ */ |
| 89 | 012213, /* = */ |
| 90 | 030001, /* & for tests */ |
| 91 | 032001, /* * (long) */ |
| 92 | 032001, /* / (long) */ |
| 93 | 032001, /* % (long) */ |
| 94 | 012253, /* =& ~ */ |
| 95 | 012213, /* =* (long) */ |
| 96 | 012213, /* / (long) */ |
| 97 | 012213, /* % (long) */ |
| 98 | 000000, /* 89 */ |
| 99 | 014201, /* ? */ |
| 100 | 026061, /* long << */ |
| 101 | 012253, /* long =<< */ |
| 102 | 000101, /* max */ |
| 103 | 000101, /* maxp */ |
| 104 | 000101, /* min */ |
| 105 | 000101, /* minp */ |
| 106 | 000001, /* , */ |
| 107 | 000000, /* 98 */ |
| 108 | 000000, /* 99 */ |
| 109 | 036001, /* call */ |
| 110 | 036000, /* mcall */ |
| 111 | 000000, /* goto */ |
| 112 | 000000, /* jump cond */ |
| 113 | 000000, /* branch cond */ |
| 114 | 000400, /* set nregs */ |
| 115 | 000000, /* 106 */ |
| 116 | 000000, /* 107 */ |
| 117 | 000000, /* 108 */ |
| 118 | 000000, /* int->char */ |
| 119 | 000000, /* force r0 */ |
| 120 | 000000, /* 111 */ |
| 121 | 000000, /* 112 */ |
| 122 | 000000, /* 113 */ |
| 123 | 000000, /* 114 */ |
| 124 | 000000, /* structure assign */ |
| 125 | 000001, /* struct assignment setup */ |
| 126 | }; |
| 127 | |
| 128 | char *opntab[] { |
| 129 | 0, |
| 130 | 0, |
| 131 | 0, |
| 132 | 0, |
| 133 | 0, |
| 134 | 0, |
| 135 | 0, |
| 136 | 0, |
| 137 | ":", |
| 138 | ",", |
| 139 | "field select", |
| 140 | 0, |
| 141 | 0, |
| 142 | "int->ptr", |
| 143 | "ptr->int", |
| 144 | "long->ptr", |
| 145 | "field assign", |
| 146 | ">>", |
| 147 | ">>", |
| 148 | 0, |
| 149 | "name", |
| 150 | "short constant", |
| 151 | "string", |
| 152 | "float", |
| 153 | "double", |
| 154 | "long constant", |
| 155 | "long constant", |
| 156 | "*r++", |
| 157 | "*--r", |
| 158 | 0, |
| 159 | "++pre", |
| 160 | "--pre", |
| 161 | "++post", |
| 162 | "--post", |
| 163 | "!un", |
| 164 | "&", |
| 165 | "*", |
| 166 | "-", |
| 167 | "~", |
| 168 | ".", |
| 169 | "+", |
| 170 | "-", |
| 171 | "*", |
| 172 | "/", |
| 173 | "%", |
| 174 | ">>", |
| 175 | "<<", |
| 176 | "&", |
| 177 | "|", |
| 178 | "^", |
| 179 | "->", |
| 180 | "int->double", |
| 181 | "double->int", |
| 182 | "&&", |
| 183 | "||", |
| 184 | "&~", |
| 185 | "double->long", |
| 186 | "long->double", |
| 187 | "integer->long", |
| 188 | "long->integer", |
| 189 | "==", |
| 190 | "!=", |
| 191 | "<=", |
| 192 | "<", |
| 193 | ">=", |
| 194 | ">", |
| 195 | "<p", |
| 196 | "<=p", |
| 197 | ">p", |
| 198 | ">=p", |
| 199 | "+=", |
| 200 | "-=", |
| 201 | "*=", |
| 202 | "/=", |
| 203 | "%=", |
| 204 | ">>=", |
| 205 | "<<=", |
| 206 | "&=", |
| 207 | "|=", |
| 208 | "^=", |
| 209 | "=", |
| 210 | "& for tests", |
| 211 | "*", |
| 212 | "/", |
| 213 | "%", |
| 214 | "&= ~", |
| 215 | "*=", |
| 216 | "/=", |
| 217 | "%=", |
| 218 | 0, |
| 219 | "?", |
| 220 | "<<", |
| 221 | "<<=", |
| 222 | "\\/", |
| 223 | "\\/", |
| 224 | "/\\", |
| 225 | "/\\", |
| 226 | 0, |
| 227 | "call", |
| 228 | "call", |
| 229 | "call", |
| 230 | 0, |
| 231 | "goto", |
| 232 | "jump cond", |
| 233 | "branch cond", |
| 234 | "set nregs", |
| 235 | "load value", |
| 236 | 0, |
| 237 | 0, |
| 238 | "int->char", |
| 239 | "force register", |
| 240 | "", |
| 241 | "", |
| 242 | "", |
| 243 | "", |
| 244 | "=structure", |
| 245 | "= (struct setup)", |
| 246 | }; |
| 247 | |
| 248 | /* |
| 249 | * Strings for instruction tables. |
| 250 | */ |
| 251 | char mov[] "mov"; |
| 252 | char clr[] "clr"; |
| 253 | char cmp[] "cmp"; |
| 254 | char tst[] "tst"; |
| 255 | char add[] "add"; |
| 256 | char sub[] "sub"; |
| 257 | char inc[] "inc"; |
| 258 | char dec[] "dec"; |
| 259 | char mul[] "mul"; |
| 260 | char div[] "div"; |
| 261 | char asr[] "asr"; |
| 262 | char ash[] "ash"; |
| 263 | char asl[] "asl"; |
| 264 | char bic[] "bic"; |
| 265 | char bic1[] "bic $1,"; |
| 266 | char bit[] "bit"; |
| 267 | char bit1[] "bit $1,"; |
| 268 | char bis[] "bis"; |
| 269 | char bis1[] "bis $1,"; |
| 270 | char xor[] "xor"; |
| 271 | char neg[] "neg"; |
| 272 | char com[] "com"; |
| 273 | char stdol[] "*$"; |
| 274 | char ashc[] "ashc"; |
| 275 | char slmul[] "lmul"; |
| 276 | char sldiv[] "ldiv"; |
| 277 | char slrem[] "lrem"; |
| 278 | char almul[] "almul"; |
| 279 | char aldiv[] "aldiv"; |
| 280 | char alrem[] "alrem"; |
| 281 | char jeq[] "jeq"; |
| 282 | char jne[] "jne"; |
| 283 | char jle[] "jle"; |
| 284 | char jgt[] "jgt"; |
| 285 | char jlt[] "jlt"; |
| 286 | char jge[] "jge"; |
| 287 | char jlos[] "jlos"; |
| 288 | char jhi[] "jhi"; |
| 289 | char jlo[] "jlo"; |
| 290 | char jhis[] "jhis"; |
| 291 | char nop[] "/nop"; |
| 292 | char jbr[] "jbr"; |
| 293 | |
| 294 | /* |
| 295 | * Instruction tables, accessed by |
| 296 | * I (first operand) or I' (second) macros. |
| 297 | */ |
| 298 | |
| 299 | struct instab instab[] { |
| 300 | LOAD, mov, tst, |
| 301 | ASSIGN, mov, clr, |
| 302 | EQUAL, cmp, tst, |
| 303 | NEQUAL, cmp, tst, |
| 304 | LESSEQ, cmp, tst, |
| 305 | LESS, cmp, tst, |
| 306 | GREATEQ,cmp, tst, |
| 307 | GREAT, cmp, tst, |
| 308 | LESSEQP,cmp, tst, |
| 309 | LESSP, cmp, tst, |
| 310 | GREATQP,cmp, tst, |
| 311 | GREATP, cmp, tst, |
| 312 | PLUS, add, inc, |
| 313 | ASPLUS, add, inc, |
| 314 | MINUS, sub, dec, |
| 315 | ASMINUS,sub, dec, |
| 316 | INCBEF, add, inc, |
| 317 | DECBEF, sub, dec, |
| 318 | INCAFT, add, inc, |
| 319 | DECAFT, sub, dec, |
| 320 | TIMES, mul, mul, |
| 321 | ASTIMES,mul, mul, |
| 322 | DIVIDE, div, div, |
| 323 | ASDIV, div, div, |
| 324 | MOD, div, div, |
| 325 | ASMOD, div, div, |
| 326 | PTOI, div, div, |
| 327 | RSHIFT, ash, asr, |
| 328 | ASRSH, ash, asr, |
| 329 | LSHIFT, ash, asl, |
| 330 | ASLSH, ash, asl, |
| 331 | AND, bic, bic1, |
| 332 | ANDN, bic, bic1, |
| 333 | ASANDN, bic, bic1, |
| 334 | TAND, bit, bit1, |
| 335 | OR, bis, bis1, |
| 336 | ASOR, bis, bis1, |
| 337 | EXOR, xor, xor, |
| 338 | ASXOR, xor, xor, |
| 339 | NEG, neg, neg, |
| 340 | COMPL, com, com, |
| 341 | CALL1, stdol, stdol, |
| 342 | CALL2, "", "", |
| 343 | LLSHIFT,ashc, ashc, |
| 344 | ASLSHL, ashc, ashc, |
| 345 | LTIMES, slmul, slmul, |
| 346 | LDIV, sldiv, sldiv, |
| 347 | LMOD, slrem, slrem, |
| 348 | LASTIMES,almul, almul, |
| 349 | LASDIV, aldiv, aldiv, |
| 350 | LASMOD, alrem, alrem, |
| 351 | ULSH, ashc, ashc, |
| 352 | ASULSH, ashc, ashc, |
| 353 | 0, 0, 0}; |
| 354 | |
| 355 | /* |
| 356 | * Similar table for relationals. |
| 357 | * The first string is for the positive |
| 358 | * test, the second for the inverted one. |
| 359 | * The '200+' entries are |
| 360 | * used in tests against 0 where a 'tst' |
| 361 | * instruction is used; it clears the c-bit |
| 362 | * the c-bit so ptr tests are funny. |
| 363 | */ |
| 364 | struct instab branchtab[] { |
| 365 | EQUAL, jeq, jne, |
| 366 | NEQUAL, jne, jeq, |
| 367 | LESSEQ, jle, jgt, |
| 368 | LESS, jlt, jge, |
| 369 | GREATEQ,jge, jlt, |
| 370 | GREAT, jgt, jle, |
| 371 | LESSEQP,jlos, jhi, |
| 372 | LESSP, jlo, jhis, |
| 373 | GREATQP,jhis, jlo, |
| 374 | GREATP, jhi, jlos, |
| 375 | 200+EQUAL, jeq, jne, |
| 376 | 200+NEQUAL, jne, jeq, |
| 377 | 200+LESSEQ, jle, jgt, |
| 378 | 200+LESS, jlt, jge, |
| 379 | 200+GREATEQ, jge, jlt, |
| 380 | 200+GREAT, jgt, jle, |
| 381 | 200+LESSEQP, jeq, jne, |
| 382 | 200+LESSP, nop, jbr, |
| 383 | 200+GREATQP, jbr, nop, |
| 384 | 200+GREATP, jne, jeq, |
| 385 | 0, 0, 0 }; |