target.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #ifndef TARGET_H
  2. #define TARGET_H
  3. #include "machine.h"
  4. extern struct symbol *size_t_ctype;
  5. extern struct symbol *ssize_t_ctype;
  6. extern struct symbol *ptrdiff_ctype;
  7. extern struct symbol *intptr_ctype;
  8. extern struct symbol *uintptr_ctype;
  9. extern struct symbol *intmax_ctype;
  10. extern struct symbol *uintmax_ctype;
  11. extern struct symbol *int64_ctype;
  12. extern struct symbol *uint64_ctype;
  13. extern struct symbol *int32_ctype;
  14. extern struct symbol *uint32_ctype;
  15. extern struct symbol *wchar_ctype;
  16. extern struct symbol *wint_ctype;
  17. extern struct symbol *least8_ctype;
  18. extern struct symbol *uleast8_ctype;
  19. extern struct symbol *least16_ctype;
  20. extern struct symbol *uleast16_ctype;
  21. extern struct symbol *least32_ctype;
  22. extern struct symbol *uleast32_ctype;
  23. extern struct symbol *least64_ctype;
  24. extern struct symbol *uleast64_ctype;
  25. extern struct symbol *fast8_ctype;
  26. extern struct symbol *ufast8_ctype;
  27. extern struct symbol *fast16_ctype;
  28. extern struct symbol *ufast16_ctype;
  29. extern struct symbol *fast32_ctype;
  30. extern struct symbol *ufast32_ctype;
  31. extern struct symbol *fast64_ctype;
  32. extern struct symbol *ufast64_ctype;
  33. extern struct symbol *sig_atomic_ctype;
  34. /*
  35. * For "__attribute__((aligned))"
  36. */
  37. extern int max_alignment;
  38. /*
  39. * Integer data types
  40. */
  41. extern int bits_in_bool;
  42. extern int bits_in_char;
  43. extern int bits_in_short;
  44. extern int bits_in_int;
  45. extern int bits_in_long;
  46. extern int bits_in_longlong;
  47. extern int bits_in_longlonglong;
  48. extern int max_int_alignment;
  49. /*
  50. * Floating point data types
  51. */
  52. extern int bits_in_float;
  53. extern int bits_in_double;
  54. extern int bits_in_longdouble;
  55. extern int max_fp_alignment;
  56. /*
  57. * Pointer data type
  58. */
  59. extern int bits_in_pointer;
  60. extern int pointer_alignment;
  61. /*
  62. * Enum data types
  63. */
  64. extern int bits_in_enum;
  65. extern int enum_alignment;
  66. struct asm_operand;
  67. struct builtin_fn;
  68. struct target {
  69. enum machine mach;
  70. enum bitness bitness;
  71. unsigned int big_endian:1;
  72. unsigned int unsigned_char:1;
  73. unsigned int size_t_long:1;
  74. unsigned int has_int128:1;
  75. unsigned long flags;
  76. struct symbol *wchar;
  77. struct symbol *wint;
  78. unsigned int bits_in_longdouble;
  79. unsigned int max_fp_alignment;
  80. const struct target *target_32bit;
  81. const struct target *target_x32bit;
  82. const struct target *target_64bit;
  83. const struct builtin_fn *builtins;
  84. void (*init)(const struct target *self);
  85. void (*parse_march)(const char *arg);
  86. void (*predefine)(const struct target *self);
  87. const char *(*asm_constraint)(struct asm_operand *op, int c, const char *str);
  88. };
  89. extern const struct target target_default;
  90. extern const struct target target_alpha;
  91. extern const struct target target_arm;
  92. extern const struct target target_arm64;
  93. extern const struct target target_bfin;
  94. extern const struct target target_h8300;
  95. extern const struct target target_m68k;
  96. extern const struct target target_microblaze;
  97. extern const struct target target_mips32;
  98. extern const struct target target_mips64;
  99. extern const struct target target_nds32;
  100. extern const struct target target_nios2;
  101. extern const struct target target_openrisc;
  102. extern const struct target target_ppc32;
  103. extern const struct target target_ppc64;
  104. extern const struct target target_riscv32;
  105. extern const struct target target_riscv64;
  106. extern const struct target target_s390;
  107. extern const struct target target_s390x;
  108. extern const struct target target_sh;
  109. extern const struct target target_sparc32;
  110. extern const struct target target_sparc64;
  111. extern const struct target target_i386;
  112. extern const struct target target_x86_64;
  113. extern const struct target target_xtensa;
  114. /* target.c */
  115. extern const struct target *arch_target;
  116. enum machine target_parse(const char *name);
  117. void target_os(const char *name);
  118. void target_config(enum machine mach);
  119. void target_init(void);
  120. /*
  121. * Helper functions for converting bits to bytes and vice versa.
  122. */
  123. static inline int bits_to_bytes(int bits)
  124. {
  125. return bits >= 0 ? (bits + bits_in_char - 1) / bits_in_char : -1;
  126. }
  127. static inline int bytes_to_bits(int bytes)
  128. {
  129. return bytes * bits_in_char;
  130. }
  131. static inline unsigned long array_element_offset(unsigned long base_bits, int idx)
  132. {
  133. int fragment = base_bits % bits_in_char;
  134. if (fragment)
  135. base_bits += bits_in_char - fragment;
  136. return base_bits * idx;
  137. }
  138. #endif