error.cpp 3.0 KB

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