types.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /****************************************************************************
  2. * dcc project general header
  3. * (C) Cristina Cifuentes, Mike van Emmerik
  4. ****************************************************************************/
  5. #pragma once
  6. #include <cassert>
  7. #include <stdint.h>
  8. #include "Enums.h"
  9. /**** Common definitions and macros ****/
  10. #define MAX 0x7FFFFFFF
  11. /* Type definitions used in the program */
  12. typedef unsigned char byte; /* 8 bits */
  13. typedef unsigned short word;/* 16 bits */
  14. typedef short int16; /* 16 bits */
  15. typedef unsigned char boolT; /* 8 bits */
  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) ((word)((byte *)(p))[0] + ((word)((byte *)(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) (((byte *)(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. void setFlags(uint16_t x)
  53. {
  54. def = x&DEF;
  55. use = x&USE;
  56. val = x&VAL;
  57. }
  58. bool isUSE_VAL() {return use&&val;} /* Use and Val */
  59. };
  60. static constexpr const char * hlTypes[13] = {
  61. "", "char", "unsigned char", "int", "unsigned int",
  62. "long", "unsigned long", "record", "int *", "char *",
  63. "", "float", "double"
  64. };
  65. struct TypeContainer
  66. {
  67. hlType m_type;
  68. size_t m_size;
  69. TypeContainer(hlType t,size_t sz) : m_type(t),m_size(sz)
  70. {
  71. }
  72. static size_t typeSize(hlType t)
  73. {
  74. switch(t)
  75. {
  76. case TYPE_WORD_SIGN: case TYPE_WORD_UNSIGN:
  77. return 2;
  78. case TYPE_BYTE_SIGN: case TYPE_BYTE_UNSIGN:
  79. return 1;
  80. case TYPE_LONG_SIGN: case TYPE_LONG_UNSIGN:
  81. return 4;
  82. case TYPE_FLOAT:
  83. return 4;
  84. default:
  85. return ~0;
  86. }
  87. return 0;
  88. }
  89. static hlType defaultTypeForSize(size_t x)
  90. {
  91. /* Type of the symbol according to the number of bytes it uses */
  92. static hlType cbType[] = {TYPE_UNKNOWN, TYPE_BYTE_UNSIGN, TYPE_WORD_SIGN,
  93. TYPE_UNKNOWN, TYPE_LONG_SIGN};
  94. assert(x < sizeof(cbType)/sizeof(hlType));
  95. return cbType[x];
  96. }
  97. static constexpr const char *typeName(hlType t)
  98. {
  99. return hlTypes[t];
  100. }
  101. };