home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / program / language / as / source / c / option < prev    next >
Encoding:
Text File  |  1993-12-28  |  7.5 KB  |  312 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(inputLook && !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 optionCondOptPrecRound(void)
  235. {
  236.   WORD optionCC = getCond();
  237.   WORD optionPrec = getPrec(FALSE); 
  238.   if(optionError == optionPrec)
  239.     optionPrec = PRECISION_EXTENDED;
  240.   return isOK(optionCC | optionPrec | getRound());
  241. }
  242.  
  243. WORD optionCondPrec_P(void)
  244. {
  245.   WORD option = getCond();
  246.   if(optionError == (option |= getPrec(TRUE)))
  247.     return optionError;
  248.   return isOK(option);
  249. }
  250.  
  251. WORD optionCondL(void)
  252. {
  253.   WORD option = getCond();
  254.   if(inputLook() == 'l' || inputLook() == 'L') {
  255.     option |= L_FLAG;
  256.     inputSkip();
  257.   }
  258.   return isOK(option);
  259. }
  260.  
  261. /****** Trouble mnemonics **********/
  262.  
  263. WORD optionLinkCond(void)   /* 'b' is matched before call */
  264. {
  265.   if(inputLook() != 'l' && inputLook() != 'L') { /* Only b.CC possible  */
  266.     return isOK(getCond());
  267.   } else {
  268.     inputSkip();                                 /* bl.CC or b.l?  */
  269.     switch(inputLook()) {
  270.       case 'e':case 'E':                         /* b.le or bl.eq */
  271.           inputSkip();
  272.         switch(inputLook()) {
  273.           case 'q': case 'Q':                    /* Only bl.eq */
  274.             inputSkip(); 
  275.             return isOK(EQ|LINK_BIT);
  276.           default:                               /* Only b.le */
  277.             return isOK(LE);
  278.         }
  279.       case 'o':case 'O': /* Only b.lo possible */
  280.         inputSkip();
  281.         return isOK(LO);
  282.       case 's':case 'S': /* Only b.ls possible */
  283.         inputSkip();
  284.         return isOK(LS);
  285.       case 't':case 'T': /* Only b.lt possible */
  286.         inputSkip();
  287.         return isOK(LT);
  288.       default:  /* Only bl.CC possible */
  289.         return isOK(getCond() | LINK_BIT);
  290.     }
  291.   }
  292.   return optionError;
  293. }
  294.  
  295. WORD optionExceptionCond(void)
  296.   int c;
  297.   if(inputLook() != 'e' && inputLook() != 'E') { /* Only cmf.CC possible  */
  298.     return isOK(getCond());
  299.   } else {        /* cmf.eq or cmfe.CC */
  300.     inputSkip();
  301.     if((c=inputLook()) == 'q' || c == 'Q') {   /* Only cmf.eq */
  302.       inputSkip();
  303.       return isOK(EQ);
  304.     } else {                                   /* Only cmfe.CC */
  305.       return isOK(getCond()|EXEPTION_BIT);
  306.     }
  307.   }
  308.   return optionError;
  309. }
  310.