error.cpp 2.8 KB

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