error.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 const 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 ,"%x: 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. {
  37. va_list args;
  38. //#ifdef __UNIX__ /* ultrix */
  39. #if 0
  40. int errId;
  41. va_start(args);
  42. errId = va_arg(args, int);
  43. #else
  44. va_start(args, errId);
  45. #endif
  46. if (errId == USAGE)
  47. fprintf(stderr,"Usage: dcc [-a1a2cmpsvVi][-o asmfile] DOS_executable\n");
  48. else {
  49. auto msg_iter = errorMessage.find(errId);
  50. assert(msg_iter!=errorMessage.end());
  51. fprintf(stderr, "dcc: ");
  52. vfprintf(stderr, msg_iter->second.c_str(), 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. {
  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. auto msg_iter = errorMessage.find(errId);
  73. assert(msg_iter!=errorMessage.end());
  74. vfprintf(stderr, msg_iter->second.c_str(), args);
  75. va_end(args);
  76. }