generic.h 6.7 KB

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