home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 363_01 / error.c < prev    next >
C/C++ Source or Header  |  1991-12-17  |  8KB  |  192 lines

  1. /***********************************************************************
  2.  *
  3.  *      ERROR.C
  4.  *      Error message printer for 68020 Assembler
  5.  *
  6.  *    Function: printError()
  7.  *      Prints an appropriate message to the specified output file according 
  8.  *      to the error code supplied. If the errorCode is OK, no message is 
  9.  *      printed; otherwise an WARNING or ERROR message is produced. The line 
  10.  *      number will be included in the message unless lineNum = -1.
  11.  *
  12.  *   Usage: printError(FILE *outFile, int errorCode, int lineNum)
  13.  *
  14.  *      Author: Paul McKee
  15.  *      ECE492    North Carolina State University,  12/12/86
  16.  *
  17.  *      Modified A.E. Romer     16 March 1991
  18.  *      Version 1.0
  19.  *
  20.  ************************************************************************/
  21.  
  22.  
  23. #include <stdio.h>
  24. #include "asm.h"
  25.  
  26. int printError(FILE *outFile, int errorCode, int lineNum)
  27.     {
  28.     char numBuf[20];
  29.  
  30.     if (lineNum >= 0)
  31.         sprintf(numBuf, " in line %d", lineNum);
  32.     else
  33.         numBuf[0] = '\0';
  34.  
  35.             if (errorCode > MINOR)
  36.                 fprintf(outFile, "    ERROR");
  37.             else if (errorCode > WARNING)
  38.                 fprintf(outFile, "    WARNING");
  39.  
  40.     switch (errorCode)
  41.         {
  42.         
  43. /* Severe errors */     
  44.         case SYNTAX          :
  45.             fprintf(outFile, "%s: Invalid syntax\n", numBuf);
  46.             break;
  47.         case INV_OPCODE      :
  48.             fprintf(outFile, "%s: Invalid opcode\n", numBuf);
  49.             break;
  50.         case INV_ADDR_MODE   :
  51.             fprintf(outFile, "%s: Invalid addressing mode\n", numBuf);
  52.             break;
  53.         case LABEL_REQUIRED  :
  54.             fprintf(outFile, "%s: Label required with this directive\n",
  55.                                                                     numBuf);
  56.             break;
  57.         case PHASE_ERROR     :
  58.             fprintf(outFile, "%s: Symbol value differs ", numBuf);
  59.             fprintf(outFile, "between first and second pass\n", numBuf);
  60.             break;
  61.         case UNIMPLEMENTED:
  62.             fprintf(outFile, "%s: This code is not implemented\n", numBuf);
  63.             break;
  64.         case INV_SHORT_BRANCH:
  65.             fprintf(outFile, "%s: Short branch to the immediately ", numBuf);
  66.             fprintf(outFile, "following instruction is not allowed\n", numBuf);
  67.             break;
  68.  
  69. /* Errors */
  70.         case UNDEFINED       :
  71.             fprintf(outFile, "%s: Undefined symbol\n", numBuf);
  72.             break;
  73.         case DIV_BY_ZERO     :
  74.             fprintf(outFile, "%s: Division by zero attempted\n", numBuf);
  75.             break;
  76.         case MULTIPLE_DEFS   :
  77.             fprintf(outFile, "%s: Symbol multiply defined\n", numBuf);
  78.             break;
  79.         case REG_MULT_DEFS   :
  80.             fprintf(outFile, "%s: Register list multiply defined\n", numBuf);
  81.             break;
  82.         case REG_LIST_UNDEF  :
  83.             fprintf(outFile, "%s: Register list symbol not ", numBuf);
  84.             fprintf(outFile, "previously defined\n", numBuf);
  85.             break;
  86.         case INV_FORWARD_REF :
  87.             fprintf(outFile, "%s: Forward references not ", numBuf);
  88.             fprintf(outFile, "allowed with this directive\n", numBuf);
  89.             break;
  90.         case INV_LENGTH      :
  91.             fprintf(outFile, "%s: Block length is less that zero\n",
  92.                                                                     numBuf);
  93.             break;
  94.  
  95. /* Minor errors */
  96.         case INV_SIZE_CODE   :
  97.             fprintf(outFile, "%s: Invalid size code\n", numBuf);
  98.             break;
  99.             break;
  100.         case INV_VECTOR_NUM  :
  101.             fprintf(outFile, "%s: Invalid vector number\n", numBuf);
  102.             break;
  103.         case INV_BRANCH_DISP :
  104.             fprintf(outFile, "%s: Branch instruction ", numBuf);
  105.             fprintf(outFile, "displacement is out of range or invalid\n",
  106.                                                                     numBuf);
  107.             break;
  108.         case INV_DISP          :
  109.             fprintf(outFile, "%s: Displacement out of range\n", numBuf);
  110.             break;
  111.         case INV_ABS_ADDRESS :
  112.             fprintf(outFile, "%s: Absolute address exceeds 16 bits\n",
  113.                                                                     numBuf);
  114.             break;
  115.         case INV_3_BIT_DATA  :
  116.             fprintf(outFile, "%s: Immediate data exceeds 3 bits\n",
  117.                                                                     numBuf);
  118.             break;
  119.         case INV_8_BIT_DATA  :
  120.             fprintf(outFile, "%s: Immediate data exceeds 8 bits\n",
  121.                                                                     numBuf);
  122.             break;
  123.         case INV_16_BIT_DATA :
  124.             fprintf(outFile, "%s: Immediate data exceeds 16 bits\n",
  125.                                                                     numBuf);
  126.             break;
  127.         case ODD_ADDRESS     :
  128.             fprintf(outFile, "%s: Origin value is odd, location", numBuf);
  129.             fprintf(outFile, " counter set to next higher address\n", numBuf);
  130.             break;
  131.         case NOT_REG_LIST    :
  132.             fprintf(outFile, "%s: The symbol specified is not ", numBuf);
  133.             fprintf(outFile, "a register list symbol\n", numBuf);
  134.             break;
  135.         case REG_LIST_SPEC   :
  136.             fprintf(outFile, "%s: Register list symbol used in ", numBuf);
  137.             fprintf(outFile, "an expression\n", numBuf);
  138.             break;
  139.         case INV_SHIFT_COUNT :
  140.             fprintf(outFile, "%s: Invalid constant shift count\n",
  141.                                                                     numBuf);
  142.             break;
  143.         case INV_LABEL       :
  144.             fprintf(outFile, "%s: Invalid label character\n",
  145.                                                             numBuf);
  146.  
  147. /* Warnings */
  148.             break;
  149.         case ASCII_TOO_BIG   :
  150.             fprintf(outFile, "%s: ASCII constant exceeds 4 characters\n",
  151.                                                             numBuf);
  152.             break;
  153.         case NUMBER_TOO_BIG  :
  154.             fprintf(outFile, "%s: Numeric constant exceeds 32 bits\n",
  155.                                                                     numBuf);
  156.             break;
  157.         case INCOMPLETE      :
  158.             fprintf(outFile, "%s: Evaluation of expression ", numBuf);
  159.             fprintf(outFile, "could not be completed\n", numBuf);
  160.             break;
  161.         case EXCESSIVE_SIZE  :
  162.             fprintf(outFile, "%s: Excessive size\n", numBuf);
  163.             break;
  164.         case UNSIZED         :
  165.             fprintf(outFile, "%s: Unsized instruction, size ignored\n", numBuf);
  166.             break;
  167.         case IGNORED_SIZE    :
  168.             fprintf(outFile, "%s: Invalid or illegal size ignored\n", numBuf);
  169.             break;
  170.         case CORRECTED_SIZE  :
  171.             fprintf(outFile, "%s: Invalid size, corrected\n", numBuf);
  172.             break;
  173.         case INV_QUICK_CONST :
  174.             fprintf(outFile,
  175.                 "%s: Quick arithmetic constant too small or too big\n",
  176.                                                                numBuf);
  177.             break;
  178.         case INV_MOVEQ_CONST :
  179.             fprintf(outFile,
  180.                 "%s: MOVEQ instruction constant exceeds 8 bits,\n", numBuf);
  181.             fprintf(outFile,
  182.                 "             Least significant 8 bits used\n");
  183.             break;
  184.         default :
  185.             if (errorCode)
  186.                 fprintf(outFile, "%s: No message defined\n", numBuf);
  187.         }
  188.  
  189.     return NORMAL;
  190.     }
  191.  
  192.