types.h 3.4 KB

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