generic.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* generic.h: Header file to be included by all other files
  2. Copyright (C) 2002-2004 Sebastian Reichelt
  3. Copyright (C) 2007-2008 Kevin Kofler
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  15. /*
  16. User-Definable Functionality
  17. ==============================
  18. Specify these in the command line for GCC with the '-D...' switch, or define
  19. them in this file.
  20. ENABLE_HELP
  21. Enable '--help' and '--version' options.
  22. ENABLE_STATS
  23. Enable the display of program statistics via '--verbose'.
  24. ENABLE_DUMP
  25. Include support for dumping the contents (via '--dump...' switches in
  26. executable version).
  27. TARGET_EMBEDDED
  28. Compile non-executable version which can be linked to a program dynamically
  29. or statically.
  30. TARGET_DLL
  31. Compile as a DLL (dynamic link library). This includes TARGET_EMBEDDED.
  32. COFF_SUPPORT
  33. Support COFF input files.
  34. AMIGAOS_SUPPORT
  35. Support AmigaOS input files.
  36. TIOS_SUPPORT
  37. Support the TIOS output target.
  38. NOSTUB_DLL_SUPPORT
  39. Support the Nostub DLL output target.
  40. FLASH_OS_SUPPORT
  41. Support the Flash OS output target.
  42. FARGO_SUPPORT
  43. Support the Fargo output target.
  44. DATA_VAR_SUPPORT
  45. Support external data variables.
  46. TIOS_FILE_SUPPORT
  47. Support the TIOS file format if TARGET_EMBEDDED is not defined.
  48. TIOS_UPGRADE_FILE_SUPPORT
  49. Support the TIOS upgrade file format if TARGET_EMBEDDED is not defined.
  50. */
  51. #ifndef GENERIC_H
  52. #define GENERIC_H
  53. // This defines the current version of ld-tigcc and ar-tigcc.
  54. #define PROGRAM_VERSION_STRING "1.08"
  55. #define COPYRIGHT_NOTICE_STRING "Copyright (C) 2002-2008 Sebastian Reichelt, Kevin Kofler and Billy Charvet"
  56. // Handling of user-defined functionality dependencies.
  57. #ifdef TARGET_DLL
  58. #define TARGET_EMBEDDED
  59. #endif /* TARGET_DLL */
  60. #define ATTRIBUTE_PACKED __attribute__((__packed__))
  61. #define ATTRIBUTE_UNUSED __attribute__((__unused__))
  62. #define ATTRIBUTE_INTERFACE __attribute__((__cdecl__))
  63. #if defined(__GNUC__) && (__GNUC__>=4 || (__GNUC__==3 && __GNUC_MINOR__>=3))
  64. #define ATTRIBUTE_MAY_ALIAS __attribute__((__may_alias__))
  65. #else
  66. #define ATTRIBUTE_MAY_ALIAS /**/
  67. #endif
  68. // When compiling an executable, don't do anything with exported functions.
  69. // Otherwise, default to the cdecl calling convention.
  70. // When compiling a DLL, also mark the function as exported.
  71. #ifdef TARGET_DLL
  72. #define ATTRIBUTE_EXPORTED ATTRIBUTE_INTERFACE __declspec(dllexport)
  73. #else /* !TARGET_DLL */
  74. #ifdef TARGET_EMBEDDED
  75. #define ATTRIBUTE_EXPORTED ATTRIBUTE_INTERFACE
  76. #else /* !TARGET_EMBEDDED */
  77. #define ATTRIBUTE_EXPORTED
  78. #endif /* !TARGET_EMBEDDED */
  79. #endif /* !TARGET_DLL */
  80. // This specifies how a variable-length array is specified (for example via
  81. // '[1]', '[0]', or '[]', depending on the capabilities of the compiler).
  82. #ifdef __GNUC__
  83. #if __GNUC__ >= 3
  84. #define VAR_ARRAY []
  85. #else /* __GNUC__ < 3 */
  86. #define VAR_ARRAY [0]
  87. #endif /* __GNUC__ < 3 */
  88. #else /* !__GNUC__ */
  89. #define VAR_ARRAY [1]
  90. #endif /* !__GNUC__ */
  91. // Attempt to auto-detect I1, I2, I4, SI1, SI2 and SI4 based on <limits.h>.
  92. // It is a good idea to double-check these definitions on every new system
  93. // you compile on.
  94. // Such a check is also performed at run time (or optimized away as dead
  95. // code).
  96. #include <limits.h>
  97. // Make sure that the character types take exactly 1 byte.
  98. #if UCHAR_MAX != 0xFF
  99. #error Need 1-byte unsigned char type.
  100. #endif /* UCHAR_MAX != 0xFF */
  101. #if SCHAR_MIN != (-0x80) || SCHAR_MAX != 0x7F
  102. #error Need 1-byte signed char type.
  103. #endif /* UCHAR_MAX != 0xFF */
  104. // Unsigned types.
  105. typedef unsigned char I1;
  106. #if USHRT_MAX == 0xFFFF
  107. typedef unsigned short I2;
  108. #elif UINT_MAX == 0xFFFF
  109. typedef unsigned int I2;
  110. #elif ULONG_MAX == 0xFFFF
  111. typedef unsigned long I2;
  112. #else /* no 2-byte unsigned int */
  113. #error No 2-byte unsigned integer type found.
  114. #endif /* 2-byte unsigned int */
  115. #if ULONG_MAX == 0xFFFFFFFF
  116. typedef unsigned long I4;
  117. #elif UINT_MAX == 0xFFFFFFFF
  118. typedef unsigned int I4;
  119. #elif ULONG_LONG_MAX == 0xFFFFFFFF || ULLONG_MAX == 0xFFFFFFFF
  120. typedef unsigned long long I4;
  121. #else /* no 4-byte unsigned int */
  122. #error No 4-byte unsigned integer type found.
  123. #endif /* 4-byte unsigned int */
  124. // Signed types.
  125. typedef signed char SI1;
  126. #if SHRT_MIN == (-0x8000) && SHRT_MAX == 0x7FFF
  127. typedef short SI2;
  128. #elif INT_MIN == (-0x8000) && INT_MAX == 0x7FFF
  129. typedef int SI2;
  130. #elif LONG_MIN == (-0x8000) && LONG_MAX == 0x7FFF
  131. typedef long SI2;
  132. #else /* no 2-byte signed int */
  133. #error No 2-byte signed integer type found.
  134. #endif /* 2-byte signed int */
  135. #if LONG_MIN == (-0x80000000) && LONG_MAX == 0x7FFFFFFF
  136. typedef long SI4;
  137. #elif INT_MIN == (-0x80000000) && INT_MAX == 0x7FFFFFFF
  138. typedef int SI4;
  139. #elif (LONG_LONG_MIN == (-0x80000000) && LONG_LONG_MAX == 0x7FFFFFFF) \
  140. || (LLONG_MIN == (-0x80000000) && LLONG_MAX == 0x7FFFFFFF)
  141. typedef long long SI4;
  142. #else /* no 4-byte signed int */
  143. #error No 4-byte signed integer type found.
  144. #endif /* 4-byte signed int */
  145. // Maximum used specific-size integers.
  146. #define IMAX I4
  147. #define SIMAX SI4
  148. // Boolean types.
  149. typedef I1 B1;
  150. typedef I2 B2;
  151. typedef I4 B4;
  152. // These should be all right in most cases.
  153. typedef int BOOLEAN;
  154. typedef SI4 OFFSET;
  155. #define MAX_OFFSET 0x7FFFFFFF
  156. typedef OFFSET FILE_PTR;
  157. typedef SI4 COUNT;
  158. typedef COUNT SIZE;
  159. // These are for setting only! Do not use them to check values.
  160. #define FALSE 0
  161. #define TRUE (!FALSE)
  162. #ifndef NULL
  163. #define NULL ((void *) 0)
  164. #endif
  165. // Diagnostic messages.
  166. #ifdef TARGET_EMBEDDED
  167. extern void Error_Internal (const char *FileName, const char *Text);
  168. extern void Warning_Internal (const char *FileName, const char *Text);
  169. #include <stdio.h>
  170. #define Error(FileName,Text...) ({ char s__[256*4]; sprintf (s__, Text); Error_Internal (FileName, s__); })
  171. #define Warning(FileName,Text...) ({ char s__[256*4]; sprintf (s__, Text); Warning_Internal (FileName, s__); })
  172. #else /* !TARGET_EMBEDDED */
  173. #include <stdio.h>
  174. #define Error(FileName,Text...) ({ register const char *filename__ = (FileName); if (filename__) fprintf (stderr, "%s: Error: ", filename__); else fprintf (stderr, "Error: "); fprintf (stderr, Text); fprintf (stderr, "\n"); })
  175. #define Warning(FileName,Text...) ({ register const char *filename__ = (FileName); if (filename__) fprintf (stderr, "%s: Warning: ", filename__); else fprintf (stderr, "Warning: "); fprintf (stderr, Text); fprintf (stderr, "\n"); })
  176. #endif /* !TARGET_EMBEDDED */
  177. // Macro to check whether two ranges overlap. The ranges include Start1 and
  178. // Start2, but not End1 and End2.
  179. #define RangesOverlap(Start1,End1,Start2,End2) (((End1) > (Start2)) && ((End2) > (Start1)))
  180. #endif