target-x86.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #include "symbol.h"
  2. #include "target.h"
  3. #include "machine.h"
  4. #include "builtin.h"
  5. static void predefine_i386(const struct target *self)
  6. {
  7. predefine("__i386__", 1, "1");
  8. predefine("__i386", 1, "1");
  9. predefine_nostd("i386");
  10. }
  11. static void predefine_x86_64(const struct target *self)
  12. {
  13. predefine("__x86_64__", 1, "1");
  14. predefine("__x86_64", 1, "1");
  15. predefine("__amd64__", 1, "1");
  16. predefine("__amd64", 1, "1");
  17. }
  18. static void init_x86_common(const struct target *target)
  19. {
  20. switch (arch_os) {
  21. case OS_CYGWIN:
  22. wchar_ctype = &ushort_ctype;
  23. break;
  24. case OS_FREEBSD:
  25. wint_ctype = &int_ctype;
  26. break;
  27. case OS_OPENBSD:
  28. size_t_ctype = &ulong_ctype;
  29. ssize_t_ctype = &long_ctype;
  30. wchar_ctype = &int_ctype;
  31. wint_ctype = &int_ctype;
  32. fast16_ctype = &short_ctype;
  33. ufast16_ctype = &ushort_ctype;
  34. break;
  35. }
  36. }
  37. static const struct builtin_fn builtins_x86_common[] = {
  38. { "__builtin_ia32_pause", &void_ctype, 0, },
  39. { }
  40. };
  41. static void init_i386(const struct target *target)
  42. {
  43. fast16_ctype = &int_ctype;
  44. ufast16_ctype = &uint_ctype;
  45. fast32_ctype = &int_ctype;
  46. ufast32_ctype = &uint_ctype;
  47. init_x86_common(target);
  48. }
  49. const struct target target_i386 = {
  50. .mach = MACH_I386,
  51. .bitness = ARCH_LP32,
  52. .big_endian = 0,
  53. .unsigned_char = 0,
  54. .wchar = &long_ctype,
  55. .bits_in_longdouble = 96,
  56. .max_fp_alignment = 4,
  57. .target_64bit = &target_x86_64,
  58. .init = init_i386,
  59. .predefine = predefine_i386,
  60. .builtins = builtins_x86_common,
  61. };
  62. static void init_x86_x32(const struct target *target)
  63. {
  64. init_x86_common(target);
  65. max_int_alignment = 8;
  66. fast16_ctype = &int_ctype;
  67. ufast16_ctype = &uint_ctype;
  68. fast32_ctype = &int_ctype;
  69. ufast32_ctype = &uint_ctype;
  70. wchar_ctype = &long_ctype;
  71. }
  72. static const struct target target_x86_x32 = {
  73. .mach = MACH_X86_64,
  74. .bitness = ARCH_X32,
  75. .big_endian = 0,
  76. .unsigned_char = 0,
  77. .has_int128 = 1,
  78. .bits_in_longdouble = 128,
  79. .max_fp_alignment = 16,
  80. .target_32bit = &target_i386,
  81. .target_64bit = &target_x86_64,
  82. .init = init_x86_x32,
  83. .predefine = predefine_x86_64,
  84. };
  85. static void init_x86_64(const struct target *target)
  86. {
  87. init_x86_common(target);
  88. switch (arch_os) {
  89. case OS_CYGWIN:
  90. break;
  91. case OS_DARWIN:
  92. int64_ctype = &llong_ctype;
  93. uint64_ctype = &ullong_ctype;
  94. wint_ctype = &int_ctype;
  95. fast16_ctype = &short_ctype;
  96. ufast16_ctype = &ushort_ctype;
  97. fast32_ctype = &int_ctype;
  98. ufast32_ctype = &uint_ctype;
  99. fast64_ctype = &llong_ctype;
  100. ufast64_ctype = &ullong_ctype;
  101. break;
  102. case OS_FREEBSD:
  103. fast16_ctype = &short_ctype;
  104. ufast16_ctype = &ushort_ctype;
  105. fast32_ctype = &int_ctype;
  106. ufast32_ctype = &uint_ctype;
  107. break;
  108. case OS_NETBSD:
  109. fast8_ctype = &int_ctype;
  110. ufast8_ctype = &uint_ctype;
  111. fast16_ctype = &int_ctype;
  112. ufast16_ctype = &uint_ctype;
  113. fast32_ctype = &int_ctype;
  114. ufast32_ctype = &uint_ctype;
  115. wint_ctype = &int_ctype;
  116. break;
  117. case OS_OPENBSD:
  118. fast32_ctype = &int_ctype;
  119. ufast32_ctype = &uint_ctype;
  120. int64_ctype = &llong_ctype;
  121. uint64_ctype = &ullong_ctype;
  122. intmax_ctype = &llong_ctype;
  123. uintmax_ctype = &ullong_ctype;
  124. least64_ctype = &long_ctype;
  125. uleast64_ctype = &ulong_ctype;
  126. break;
  127. }
  128. }
  129. const struct target target_x86_64 = {
  130. .mach = MACH_X86_64,
  131. .bitness = ARCH_LP64,
  132. .big_endian = 0,
  133. .unsigned_char = 0,
  134. .has_int128 = 1,
  135. .bits_in_longdouble = 128,
  136. .max_fp_alignment = 16,
  137. .target_32bit = &target_i386,
  138. .target_x32bit = &target_x86_x32,
  139. .init = init_x86_64,
  140. .predefine = predefine_x86_64,
  141. .builtins = builtins_x86_common,
  142. };