home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / assembler / as / src / c / get < prev    next >
Encoding:
Text File  |  1992-07-31  |  4.2 KB  |  171 lines

  1.  
  2. /*
  3.  * get.c
  4.  * Copyright © 1992 Niklas Röjemo
  5.  */
  6.  
  7. #include "get.h"
  8. #include "error.h"
  9. #include "input.h"
  10. #include "lex.h"
  11. #include "symbol.h"
  12. #include "expr.h"
  13. #include "reloc.h"
  14. #include "help_cpu.h"
  15. #include "fix.h"
  16.  
  17. WORD getCpuReg(void)
  18. {
  19.   Symbol *sym = symbolGet(lexGetId());
  20.  
  21.   if(sym->type & SYMBOL_DEFINED && sym->type & SYMBOL_ABSOLUTE) {
  22.     if(SYMBOL_GETREG(sym->type) == SYMBOL_CPUREG)
  23.       return sym->value.ValueInt.i;
  24.     else
  25.       error(ErrorError,TRUE,"'%s' (=%d) is not a cpu register.",sym->str,sym->value);
  26.   } else
  27.     error(ErrorError,TRUE,"Undefined register %s.",sym->str);
  28.   return 0;
  29. }
  30.  
  31. WORD getFpuReg(void)
  32. {
  33.   Symbol *sym = symbolGet(lexGetId());
  34.  
  35.   if(sym->type & SYMBOL_DEFINED && sym->type & SYMBOL_ABSOLUTE) {
  36.     if(SYMBOL_GETREG(sym->type) == SYMBOL_FPUREG)
  37.       return sym->value.ValueInt.i;
  38.     else
  39.       error(ErrorError,TRUE,"'%s' (=%d) is not a fpu register.",sym->str,sym->value);
  40.   } else
  41.     error(ErrorError,TRUE,"Undefined float register %s.",sym->str);
  42.   return 0;
  43. }
  44.  
  45. WORD getCopReg(void)
  46. {
  47.   Symbol *sym = symbolGet(lexGetId());
  48.  
  49.   if(sym->type & SYMBOL_DEFINED && sym->type & SYMBOL_ABSOLUTE) {
  50.     if(SYMBOL_GETREG(sym->type) == SYMBOL_COPREG)
  51.       return sym->value.ValueInt.i;
  52.     else
  53.       error(ErrorError,TRUE,"'%s' (=%d) is not a cop register.",sym->str,sym->value);
  54.   } else
  55.     error(ErrorError,TRUE,"Undefined coprocessor register %s.",sym->str);
  56.   return 0;
  57. }
  58.  
  59. static WORD getShiftOp(void)
  60. {
  61.   WORD r;
  62.   switch(inputLook()) {
  63.     case 'a':case 'A':
  64.       if(inputLookN(1) == 's' || inputLookN(1) == 'S') {
  65.         switch(inputLookN(2)) {
  66.           case 'l':case 'L': r = ASL; inputSkipN(3); break;
  67.           case 'r':case 'R': r = ASR; inputSkipN(3); break;
  68.           default:  goto illegal;
  69.         }
  70.       } else
  71.         goto illegal;
  72.       break;
  73.     case 'l':case 'L':
  74.       if(inputLookN(1) == 's' || inputLookN(1) == 'S') {
  75.         switch(inputLookN(2)) {
  76.           case 'l':case 'L': r = LSL; inputSkipN(3); break;
  77.           case 'r':case 'R': r = LSR; inputSkipN(3); break;
  78.           default:  goto illegal;
  79.         }
  80.       } else
  81.         goto illegal;
  82.       break;
  83.     case 'r':case 'R':
  84.       switch(inputLookN(1)) {
  85.         case 'o':case 'O':
  86.           if(inputLookN(2) == 'r' || inputLookN(2) == 'R') { r = ROR; inputSkipN(3); break;}
  87.           else goto illegal;
  88.         case 'r':case 'R':
  89.           if(inputLookN(2) == 'x' || inputLookN(2) == 'X') { r = RRX; inputSkipN(3); break;}
  90.           else goto illegal;
  91.         default:   goto illegal;
  92.       }
  93.       break;
  94.     default:
  95. illegal:
  96.       error(ErrorError,TRUE,"Illegal shiftop %c%c%c.",inputLook(),inputLookN(1),inputLookN(2));
  97.   }
  98.   return r;
  99. }
  100.  
  101.  
  102. static WORD getShift(BOOL immonly)
  103. {
  104.   WORD shift;
  105.   WORD op = 0;
  106.   Value im;
  107.   shift = getShiftOp();
  108.  
  109.   if(shift != RRX) {
  110.     skipblanks();
  111.     if(inputLook() == '#') {
  112.       inputSkip();
  113.       exprBuild();
  114.       im = exprEval(ValueInt | ValueCode|ValueLateLabel);
  115.       switch(im.Tag) {
  116.       case ValueInt:
  117.         op = fixShiftImm(inputLineNo,shift,im.ValueInt.i);   /* !! Fixed !! */
  118.         break;
  119.       case ValueCode: case ValueLateLabel:
  120.         relocShiftImm(shift,im);
  121.         op = SHIFT_OP(shift);                                /* !! Fixed !! */
  122.         break;
  123.       default:
  124.         error(ErrorError,TRUE,"Illegal shift expression.");
  125.         break;
  126.       }
  127.     } else {
  128.       if(immonly) {
  129.         error(ErrorError,TRUE,"Only shift immediate allowed here.");
  130.       } else {
  131.         op = SHIFT_REG(getCpuReg()) | SHIFT_OP(shift);
  132.       }
  133.     }
  134.   } else 
  135.     op = SHIFT_OP(shift);
  136.   return op;
  137. }
  138.  
  139. WORD getRhs(BOOL immonly, WORD  ir)
  140. {
  141.   Value im;
  142.   if(inputLook() == '#') {
  143.     ir |= IMM_RHS;
  144.     inputSkip();
  145.     exprBuild();
  146.     im = exprEval(ValueInt | ValueCode|ValueLateLabel);
  147.     switch(im.Tag) {
  148.       case ValueInt:
  149.         ir = fixImm8s4(inputLineNo,ir,im.ValueInt.i);
  150.         break;
  151.       case ValueCode: case ValueLateLabel:
  152.         relocImm8s4(ir,im);
  153.         break;
  154.       default:
  155.         error(ErrorError,TRUE,"Illegal immediate expression.");
  156.         break;
  157.     }
  158.   } else {
  159.     ir |= getCpuReg();
  160.     skipblanks();
  161.     if(inputLook() == ',') {
  162.       inputSkip();
  163.       skipblanks();
  164.       ir |= getShift(immonly);
  165.     } else {
  166.       ir |= NO_SHIFT;
  167.     }
  168.   }
  169.   return ir;
  170. }
  171.