error.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /****************************************************************************
  2. * dcc project error messages
  3. * (C) Cristina Cifuentes
  4. ***************************************************************************/
  5. #include "dcc.h"
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. //#ifndef __UNIX__
  9. #if 1
  10. #include <stdarg.h>
  11. #else
  12. #include <varargs.h>
  13. #endif
  14. static const char *errorMessage[] = {
  15. "Invalid option -%c\n", /* INVALID_ARG */
  16. "Invalid instruction %02X at location %06lX\n", /* INVALID_OPCODE */
  17. "Don't understand 80386 instruction %02X at location %06lX\n", /* INVALID_386OP */
  18. "Segment override with no memory operand at location %06lX\n", /* FUNNY_SEGOVR */
  19. "REP prefix without a string instruction at location %06lX\n",/* FUNNY_REP */
  20. "Cannot open %s\n", /* CANNOT_OPEN */
  21. "Error while reading %s\n", /* CANNOT_READ */
  22. "malloc of %ld bytes failed\n", /* MALLOC_FAILED */
  23. "Don't understand new EXE format\n", /* NEWEXE_FORMAT */
  24. "Failed to find a BB for jump to %ld in proc %s\n", /* NO_BB */
  25. "Basic Block is a synthetic jump\n", /* INVALID_SYNTHETIC_BB */
  26. "Failed to find a BB for interval\n", /* INVALID_INT_BB */
  27. "Instruction at location %06lX goes beyond loaded image\n", /* IP_OUT_OF_RANGE*/
  28. "Definition not found for condition code usage at opcode %d\n",
  29. /* DEF_NOT_FOUND */
  30. "JX use, definition not supported at opcode #%d\n", /* JX_NOT_DEF */
  31. "Def - use not supported. Def op = %d, use op = %d.\n", /* NOT_DEF_USE */
  32. "Failed to construct repeat..until() condition.\n", /* REPEAT_FAIL */
  33. "Failed to construct while() condition.\n", /* WHILE_FAIL */
  34. };
  35. /****************************************************************************
  36. fatalError: displays error message and exits the program.
  37. ****************************************************************************/
  38. void fatalError(eErrorId errId, ...)
  39. { va_list args;
  40. //#ifdef __UNIX__ /* ultrix */
  41. #if 0
  42. Int errId;
  43. va_start(args);
  44. errId = va_arg(args, Int);
  45. #else
  46. va_start(args, errId);
  47. #endif
  48. if (errId == USAGE)
  49. fprintf(stderr,"Usage: dcc [-a1a2cmpsvVi][-o asmfile] DOS_executable\n");
  50. else {
  51. fprintf(stderr, "dcc: ");
  52. vfprintf(stderr, errorMessage[errId - 1], args);
  53. }
  54. va_end(args);
  55. exit((int)errId);
  56. }
  57. /****************************************************************************
  58. reportError: reports the warning/error and continues with the program.
  59. ****************************************************************************/
  60. void reportError(eErrorId errId, ...)
  61. { va_list args;
  62. //#ifdef __UNIX__ /* ultrix */
  63. #if 0
  64. Int errId;
  65. va_start(args);
  66. errId = va_arg(args, Int);
  67. #else /* msdos or windows*/
  68. va_start(args, errId);
  69. #endif
  70. fprintf(stderr, "dcc: ");
  71. vfprintf(stderr, errorMessage[errId - 1], args);
  72. va_end(args);
  73. }