home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / assembler / as / src / c / option < prev    next >
Encoding:
Text File  |  1992-08-04  |  7.3 KB  |  303 lines

  1.  
  2. /*
  3.  * option.c
  4.  * Copyright © 1992 Niklas Röjemo
  5.  */
  6.  
  7. #include <ctype.h>
  8. #include "option.h"
  9. #include "error.h"
  10. #include "input.h"
  11.  
  12. extern int pedantic;
  13.  
  14. static WORD getCond(void)
  15. {
  16.   WORD cc;
  17.   switch(inputLook()) {
  18.     case 'a':case 'A':
  19.       switch(inputLookN(1)) {
  20.         case 'l':case 'L':  cc = AL; inputSkipN(2); break;
  21.         default:   cc = AL;
  22.       }
  23.       break;
  24.     case 'c':case 'C':
  25.       switch(inputLookN(1)) {
  26.         case 'c':case 'C': cc = CC; inputSkipN(2); break;
  27.         case 's':case 'S': cc = CS; inputSkipN(2); break;
  28.         default:  cc = AL;
  29.       }
  30.       break;
  31.     case 'e':case 'E':
  32.       switch(inputLookN(1)){
  33.         case 'q':case 'Q': cc = EQ; inputSkipN(2); break;
  34.         default:  cc = AL;
  35.       }
  36.       break;
  37.     case 'g':case 'G':
  38.       switch(inputLookN(1)) {
  39.         case 'e':case 'E': cc = GE; inputSkipN(2); break;
  40.         case 't':case 'T': cc = GT; inputSkipN(2); break;
  41.         default:  cc = AL;
  42.       }
  43.       break;
  44.     case 'h':case 'H':
  45.       switch(inputLookN(1)) {
  46.         case 'i':case 'I': cc = HI; inputSkipN(2); break;
  47.         case 's':case 'S': cc = HS; inputSkipN(2); break;
  48.         default:  cc = AL;
  49.       }
  50.       break;
  51.     case 'l':case 'L':
  52.       switch(inputLookN(1)) {
  53.         case 'e':case 'E': cc = LE; inputSkipN(2); break;
  54.         case 'o':case 'O': cc = LO; inputSkipN(2); break;
  55.         case 's':case 'S': cc = LS; inputSkipN(2); break;
  56.         case 't':case 'T': cc = LT; inputSkipN(2); break;
  57.         default:  cc = AL;
  58.       }
  59.       break;
  60.     case 'm':case 'M':
  61.       switch(inputLookN(1)) {
  62.         case 'i':case 'I': cc = MI; inputSkipN(2); break;
  63.         default:  cc = AL;
  64.       }
  65.       break;
  66.     case 'n':case 'N':
  67.       switch(inputLookN(1)) {
  68.         case 'e':case 'E': cc = NE; inputSkipN(2); break;
  69.         case 'v':case 'V': cc = NV; inputSkipN(2); break;
  70.         default:  cc = AL;
  71.       }
  72.       break;
  73.     case 'p':case 'P':
  74.       switch(inputLookN(1)) {
  75.         case 'l':case 'L': cc = PL; inputSkipN(2); break;
  76.         default:  cc = AL;
  77.       }
  78.       break;
  79.     case 'v':case 'V':
  80.       switch(inputLookN(1)) {
  81.         case 'c':case 'C': cc = VC; inputSkipN(2); break;
  82.         case 's':case 'S': cc = VS; inputSkipN(2); break;
  83.         default:  cc = AL;
  84.       }
  85.       break;
  86.     default: cc = AL;
  87.   }
  88.   return cc;
  89.  
  90. static WORD getDir(BOOL ldm)
  91. {
  92.   WORD dir;
  93.   switch(inputLook()) {
  94.     case 'd':case 'D':
  95.       switch(inputLookN(1)) {
  96.         case 'b':case 'B': dir = DB; inputSkipN(2); break;
  97.         case 'a':case 'A': dir = DA; inputSkipN(2); break;
  98.         default: goto illegal;
  99.       }
  100.       break;
  101.     case 'e':case 'E':
  102.       switch(inputLookN(1)) {
  103.         case 'd':case 'D': dir = (ldm?IB:DA); inputSkipN(2); break;
  104.         case 'a':case 'A': dir = (ldm?DB:IA); inputSkipN(2); break;
  105.         default: goto illegal;
  106.       }
  107.       break;
  108.     case 'f':case 'F':
  109.       switch(inputLookN(1)) {
  110.         case 'd':case 'D': dir = (ldm?IA:DB); inputSkipN(2); break;
  111.         case 'a':case 'A': dir = (ldm?DA:IB); inputSkipN(2); break;
  112.         default: goto illegal;
  113.       }
  114.       break;
  115.     case 'i':case 'I':    
  116.       switch(inputLookN(1)) {
  117.         case 'b':case 'B': dir = IB; inputSkipN(2); break;
  118.         case 'a':case 'A': dir = IA; inputSkipN(2); break;
  119.         default: goto illegal;
  120.       }
  121.       break;
  122.     default:
  123. illegal:
  124.       return optionError;
  125.   }
  126.   return dir;
  127. }
  128.  
  129. static WORD getPrec(int P)
  130. {
  131.   switch(inputGet()) {
  132.     case 's': case 'S': return P?PRECISION_MEM_SINGLE:PRECISION_SINGLE; 
  133.     case 'd': case 'D': return P?PRECISION_MEM_DOUBLE:PRECISION_DOUBLE; 
  134.     case 'e': case 'E': return P?PRECISION_MEM_EXTENDED:PRECISION_EXTENDED; 
  135.     case 'p': case 'P': return P?PRECISION_MEM_PACKED:optionError;
  136.   }
  137.   return optionError;
  138. }
  139.  
  140. static WORD getRound(void)
  141. {
  142.   switch(inputLook()) {
  143.     case 'p': case 'P': inputSkip(); return ROUND_PLUSINF; 
  144.     case 'm': case 'M': inputSkip(); return ROUND_MINUSINF; 
  145.     case 'z': case 'Z': inputSkip(); return ROUND_ZERO;
  146.   }
  147.   return ROUND_NEAREST;
  148. }
  149.  
  150. static WORD isOK(WORD option)
  151. {
  152.   if(!isspace(inputGet()))
  153.     return optionError;
  154.   else
  155.     return option;
  156. }  
  157. WORD optionCond(void)
  158. {
  159.   return isOK(getCond());
  160. }
  161.  
  162. WORD optionCondS(void)
  163. {
  164.   WORD option = getCond();
  165.   if(inputLook() == 's' || inputLook() == 'S') {
  166.     option |= S_FLAG;
  167.     inputSkip();
  168.   }
  169.   return isOK(option);
  170. }
  171.   
  172. WORD optionCondSP(void)
  173. {
  174.   WORD option = getCond() | S_FLAG;
  175.   if(inputLook() == 's' || inputLook() == 'S') { 
  176.     inputSkip();
  177.     if(pedantic) error(ErrorInfo,TRUE,"S is implicit in test instructions.");
  178.   }
  179.   if(inputLook() == 'p' || inputLook() == 'P') {
  180.     option |= P_FLAG;
  181.     inputSkip();
  182.   }
  183.   return isOK(option);
  184. }
  185.  
  186. WORD optionCondB(void)
  187. {
  188.   WORD option = getCond();
  189.   if(inputLook() == 'b' || inputLook() == 'B') {
  190.     option |= B_FLAG;
  191.     inputSkip();
  192.   }
  193.   return isOK(option);
  194. }
  195.  
  196. WORD optionCondBT(void)
  197. {
  198.   WORD option = getCond();
  199.   if(inputLook() == 'b' || inputLook() == 'B') {
  200.     option |= B_FLAG;
  201.     inputSkip();
  202.   }
  203.   if(inputLook() == 't' || inputLook() == 'T') {
  204.     option |= T_FLAG;
  205.     inputSkip();
  206.   }
  207.   return isOK(option);
  208. }
  209.  
  210. WORD optionCondDirLdm(void)
  211. {
  212.   WORD option = getCond();
  213.   if(optionError == (option |= getDir(TRUE)))
  214.     return optionError;
  215.   return isOK(option);
  216. }
  217.  
  218. WORD optionCondDirStm(void)
  219. {
  220.   WORD option = getCond();
  221.   if(optionError == (option |= getDir(FALSE)))
  222.     return optionError;
  223.   return isOK(option);
  224. }
  225.  
  226. WORD optionCondPrecRound(void)
  227. {
  228.   WORD option = getCond();
  229.   if(optionError == (option |= getPrec(FALSE)))
  230.     return optionError;
  231.   return isOK(option | getRound());
  232. }
  233.  
  234. WORD optionCondPrec_P(void)
  235. {
  236.   WORD option = getCond();
  237.   if(optionError == (option |= getPrec(TRUE)))
  238.     return optionError;
  239.   return isOK(option);
  240. }
  241.  
  242. WORD optionCondL(void)
  243. {
  244.   WORD option = getCond();
  245.   if(inputLook() == 'l' || inputLook() == 'L') {
  246.     option |= L_FLAG;
  247.     inputSkip();
  248.   }
  249.   return isOK(option);
  250. }
  251.  
  252. /****** Trouble mnemonics **********/
  253.  
  254. WORD optionLinkCond(void)   /* 'b' is matched before call */
  255. {
  256.   if(inputLook() != 'l' && inputLook() != 'L') { /* Only b.CC possible  */
  257.     return isOK(getCond());
  258.   } else {
  259.     inputSkip();                                 /* bl.CC or b.l?  */
  260.     switch(inputLook()) {
  261.       case 'e':case 'E':                         /* b.le or bl.eq */
  262.           inputSkip();
  263.         switch(inputLook()) {
  264.           case 'q': case 'Q':                    /* Only bl.eq */
  265.             inputSkip(); 
  266.             return isOK(EQ|LINK_BIT);
  267.           default:                               /* Only b.le */
  268.             return isOK(LE);
  269.         }
  270.       case 'o':case 'O': /* Only b.lo possible */
  271.         inputSkip();
  272.         return isOK(LO);
  273.       case 's':case 'S': /* Only b.ls possible */
  274.         inputSkip();
  275.         return isOK(LS);
  276.       case 't':case 'T': /* Only b.lt possible */
  277.         inputSkip();
  278.         return isOK(LT);
  279.       default:  /* Only bl.CC possible */
  280.         return isOK(getCond() | LINK_BIT);
  281.     }
  282.   }
  283.   return optionError;
  284. }
  285.  
  286. WORD optionExceptionCond(void)
  287.   int c;
  288.   if(inputLook() != 'e' && inputLook() != 'E') { /* Only cmf.CC possible  */
  289.     return isOK(getCond());
  290.   } else {        /* cmf.eq or cmfe.CC */
  291.     inputSkip();
  292.     if((c=inputLook()) == 'q' || c == 'Q') {   /* Only cmf.eq */
  293.       inputSkip();
  294.       return isOK(EQ);
  295.     } else {                                   /* Only cmfe.CC */
  296.       return isOK(getCond()|EXEPTION_BIT);
  297.     }
  298.   }
  299.   return optionError;
  300. }
  301.