types.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. ***************************************************************************
  3. * dcc project general header
  4. * (C) Cristina Cifuentes, Mike van Emmerik
  5. ***************************************************************************
  6. */
  7. #pragma once
  8. #include "Enums.h"
  9. #include "msvc_fixes.h"
  10. #include <cassert>
  11. #include <stdint.h>
  12. #include <stdlib.h>
  13. /**** Common definitions and macros ****/
  14. #define MAX 0x7FFFFFFF
  15. /* Type definitions used in the program */
  16. #define SYNTHESIZED_MIN 0x100000 /* Synthesized labs use bits 21..32 */
  17. /* These are for C library signature detection */
  18. #define SYMLEN 16 /* Length of proc symbols, incl null */
  19. #define PATLEN 23 /* Length of proc patterns */
  20. #define WILD 0xF4 /* The wild byte */
  21. /* MACROS */
  22. // Macro reads a LH word from the image regardless of host convention
  23. // Returns a 16 bit quantity, e.g. C000 is read into an Int as C000
  24. //#define LH(p) ((int16)((byte *)(p))[0] + ((int16)((byte *)(p))[1] << 8))
  25. #define LH(p) ((uint16_t)((uint8_t *)(p))[0] + ((uint16_t)((uint8_t *)(p))[1] << 8))
  26. /* Macro reads a LH word from the image regardless of host convention */
  27. /* Returns a signed quantity, e.g. C000 is read into an Int as FFFFC000 */
  28. #define LH_SIGNED(p) (((uint8_t *)(p))[0] + (((char *)(p))[1] << 8))
  29. /* Macro tests bit b for type t in prog.map */
  30. #define BITMAP(b, t) (prog.map[(b) >> 2] & ((t) << (((b) & 3) << 1)))
  31. /* Macro to convert a segment, offset definition into a 20 bit address */
  32. #define opAdr(seg,off) ((seg << 4) + off)
  33. /* duVal FLAGS */
  34. struct eDuVal
  35. {
  36. eDuVal()
  37. {
  38. def=use=val=0;
  39. }
  40. enum flgs
  41. {
  42. DEF=1,
  43. USE=2,
  44. VAL=4
  45. };
  46. uint8_t def :1; //!< Variable was first defined than used
  47. uint8_t use :1; //!< Variable was first used than defined
  48. uint8_t val :1; /* Variable has an initial value. 2 cases:
  49. 1. When variable is used first (ie. global)
  50. 2. When a value is moved into the variable
  51. for the first time.
  52. */
  53. void setFlags(uint16_t x)
  54. {
  55. def = x&DEF;
  56. use = x&USE;
  57. val = x&VAL;
  58. }
  59. bool isUSE_VAL() {return use and val;} //Use and Val
  60. };
  61. static constexpr const char * hlTypes[13] = {
  62. "",
  63. "char",
  64. "unsigned char",
  65. "int",
  66. "unsigned int",
  67. "long",
  68. "unsigned long",
  69. "record",
  70. "int *",
  71. "char *",
  72. "",
  73. "float",
  74. "double"
  75. };
  76. struct TypeContainer
  77. {
  78. hlType m_type;
  79. size_t m_size;
  80. TypeContainer(hlType t,size_t sz) : m_type(t),m_size(sz)
  81. {
  82. }
  83. static size_t typeSize(hlType t)
  84. {
  85. switch(t)
  86. {
  87. case TYPE_WORD_SIGN: case TYPE_WORD_UNSIGN:
  88. return 2;
  89. case TYPE_BYTE_SIGN: case TYPE_BYTE_UNSIGN:
  90. return 1;
  91. case TYPE_LONG_SIGN: case TYPE_LONG_UNSIGN:
  92. return 4;
  93. case TYPE_FLOAT:
  94. return 4;
  95. default:
  96. return ~0;
  97. }
  98. return 0;
  99. }
  100. static hlType defaultTypeForSize(size_t x)
  101. {
  102. /* Type of the symbol according to the number of bytes it uses */
  103. static hlType cbType[] = {TYPE_UNKNOWN, TYPE_BYTE_UNSIGN, TYPE_WORD_SIGN,
  104. TYPE_UNKNOWN, TYPE_LONG_SIGN};
  105. assert(x < sizeof(cbType)/sizeof(hlType));
  106. return cbType[x];
  107. }
  108. static constexpr const char *typeName(hlType t)
  109. {
  110. return hlTypes[t];
  111. }
  112. };