define.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*
  2. * GTools C compiler
  3. * =================
  4. * source file :
  5. * #define's
  6. *
  7. * Copyright 2001-2004 Paul Froissart.
  8. * Credits to Christoph van Wuellen and Matthew Brandt.
  9. * All commercial rights reserved.
  10. *
  11. * This compiler may be redistributed as long there is no
  12. * commercial interest. The compiler must not be redistributed
  13. * without its full sources. This notice must stay intact.
  14. */
  15. //#define SHOWSTEP
  16. #ifndef DEFINE_H
  17. #define DEFINE_H
  18. #if 0
  19. #ifdef PC
  20. #define debugcls() (void)0
  21. #define debugf printf
  22. #else
  23. #define debugcls clrscr
  24. extern int progr;
  25. #define debugf(f...) (printf(f),progr_process(func_sp?func_sp->name:0,curname,progr),ngetchx())
  26. #endif
  27. #define debugfq printf
  28. #else
  29. #define debugcls() (void)0
  30. #if defined(PC) && !defined(__GNUC__)
  31. /*@unused@*/ static void debugf(char *s,...) {}
  32. /*@unused@*/ static void debugfq(char *s,...) {}
  33. #else
  34. #define debugf(f...) (void)0
  35. #define debugfq(f...) (void)0
  36. #endif
  37. #endif
  38. #if !defined(PC) || !defined(DEBUGGING)
  39. #define enum(tp) unsigned int // some compilers make enums signed, make them happy
  40. #else
  41. #define enum(tp) enum tp // we want nice debugging output
  42. #endif
  43. #define IS_VALID >=0
  44. #define IS_INVALID <0
  45. #define nxtlabel() (short)(nextlabel++)
  46. #ifdef AS
  47. #define nxtglabel() (short)(glblabel++)
  48. #else
  49. #define nxtglabel() (short)(nextlabel++)
  50. #endif
  51. #define local(__l) (__l>=0)
  52. #define global(__l) (((unsigned short)__l)<0xC000) // only valid if !local(__l)
  53. #define external(__l) (((unsigned short)__l)>=0xC000)
  54. #ifdef PC
  55. #define splbl(__sp) (__sp->value.splab?__sp->value.splab:(__sp->value.splab=label(__sp->name)))
  56. #else
  57. #define splbl(__sp) (__sp->value.splab?:(__sp->value.splab=label(__sp->name)))
  58. #endif
  59. #ifdef PC
  60. #define TWIN_COMPILE
  61. #endif
  62. #define DUAL_STACK // save space on the stack by allocating on a temporary buffer just the size we need
  63. #ifdef PC
  64. #define OBJ_OUT
  65. #endif
  66. //#define INFINITE_REGISTERS // compile for a virtual machine with an arbitrarily high number of registers
  67. #ifdef DISABLE_OPTS
  68. #undef VCG
  69. #endif
  70. #define USE_WORDS_IN_SWITCH // use dc.w instead of dc.l in 'real' switch statements
  71. #define NEW_ATTR // allows TI-GCC-like attribute declaration
  72. #ifdef PC
  73. #ifndef DISABLE_OPTS
  74. #define ADV_OPT // is it worth the extra exe size & comp time ? => disabled on-calc
  75. #endif
  76. #endif
  77. #ifdef VCG
  78. #define GENERATE_ROL_ROR // optimize (x<<12)|(x>>4) into a ror; depends on VCG because commutativity is not tested
  79. #endif
  80. //#define NO_ICONST_SCAN
  81. //#define ALTERNATE_HOOK
  82. #define OPT_ROMCALLS // assumes that *(void **)0xC8 is never modified
  83. //#define DEFAULT_STKPARM
  84. #define TWOBYTE_ARRAY_EXTRA_OPT // {add.w d3,a0;add.w d3,a0} instead of
  85. // {move.w d3,d0;add.w d0,d0;add.w d0,a0}
  86. //#define AREG_AS_DREG // some fine-tune should be done before this switch provides any benefit
  87. #define PREFER_POS_VALUES // allows for better CSE collection (seems like there's a bug in
  88. // Optimize which is fixed or reduced by this switch too...)
  89. #define ADVANCED_TEMP_REGS // to be fit one day in Gen68k in order to optimize free temp regs
  90. #if 0
  91. #define ADVANCED_MEMORY_MOVE // optimize contiguous sequences of move's (< auto_init/g_fcall)
  92. // (rather time-consuming, for very low consequences...
  93. // => disabled, even on PC)
  94. #endif
  95. #ifdef PC // only valid on PC!
  96. #define REQ_MGT // enable required files management
  97. #endif
  98. #define MULTIFILE // enable multiple file support
  99. #define OPTIMIZED_AINCDEC_TEST // allows for dbf too
  100. #define LONG_ADDS_IN_AREG // so that lea can be used rather than addi.l
  101. //#define NO_OFFSET_AUTOCON // useless as of now
  102. #define ADD_REDUNDANCY // increases compression ratios at the cost of function-overhead speed
  103. #define REGALLOC_FOR_SIZE
  104. //#define HARDCORE_FOR_UNPACKED_SIZE // favour size wherever possible, with little improvement
  105. // of packed size and even more probably regression (lsl.w #2...)
  106. #define SPEED_OPT
  107. //#define speed_opt_value 1 // we may add n instruction before the bra (1 : useful for dbf)
  108. //#define G_CAST2 // this might remove some op_ext's : to be tested
  109. #define RAM_CALLS // support for RAM_CALLs
  110. #ifdef PC
  111. #define FLINE_RC // support for F-Line ROM_CALLs
  112. #endif
  113. #define SHORT_STRUCT_PASSING // allows HSym to be defined as a structure
  114. #ifdef PC
  115. #define EXE_OUT // output an EXE program (implementation incomplete)
  116. #endif
  117. #define NO_SECURE_POINTERS // assert that all array accesses are less than 32kb
  118. //#define POP_OPT // still buggy as of now
  119. #define NO_TRIVIAL_CASTS // suppresses trivial en_cast's ; might add bugs, but not certain
  120. #define NO_VERYTRIVIAL_CASTS // suppresses obvious en_cast's ; was already there, but possibly buggy
  121. #define MID_DECL // allows for powerful middle decl handler
  122. #define MINIMAL_SIZES // so that (long)x>>(char)y won't be converted to (long)x>>(long)y
  123. //#define USE_SWAP_FOR_SHIFT16 // use op_swap wherever possible for shifts (buggy, FIXME)
  124. #define AUTOINIT_PAD // pad auto_init statements ('side' requires this, for example)
  125. #define MACRO_PPDIR
  126. #define MEXP_SUPPORTS_PCH // this is mandatory for TiGccLib's RR_* support.
  127. // The way speed is affected I don't know, but perhaps it's
  128. // faster with this option enabled... (slightly more PCH
  129. // searches, very slightly fewer HTable searches)
  130. // Some tests should be performed about this.
  131. // TODO:
  132. // - add FAVOUR_RELATIVE_BSS directive so that once a BSS is CSE'd, all other BSS
  133. // refer to it rather than to the classical BSS (what's more, CSE::scan should favour
  134. // such optimizations by doing some sort of most_used_BSS_cse->desire += (other_BSS_cse's)>>1)
  135. // This would allow for intensive use of BSS :)
  136. // - add RELATIVE_CSE directive so that when constantly using mylib__0000+2,
  137. // CSE searches for all mylib__0000 occurrences and finds out that it's better to use
  138. // mylib__0000+2 (replacing should take this into a count)
  139. // -- but complicated and not *that* useful...
  140. #if !defined(NONSTD_MACRO_CONCAT) && !defined(NONSTD_MACRO_CONCAT_V2)
  141. #define STD_MACRO_CONCAT
  142. #endif
  143. #define EXT_AS_ID // enabled since the dirty getch() management of .b/.w/.l is no more necessary
  144. #if defined(NOFLOAT) || !defined(BCDFLT)
  145. #define NOBCDFLT
  146. #endif
  147. #ifndef AS
  148. #ifdef AS92p
  149. #define FORBID_TABLES
  150. #endif
  151. #endif
  152. #define push_local_mem_ctx() { int _locsize=locsize,_locindx=locindx; \
  153. struct blk *_locblk=locblk; locblk=0; locsize=0
  154. #define pop_local_mem_ctx() rel_local(); locsize=_locsize; locindx=_locindx; locblk=_locblk; }
  155. #define put_align(__a) put_align2()
  156. #ifdef VCG
  157. #define VCG_MAX 5
  158. #endif
  159. #ifdef EXE_OUT
  160. #ifdef PC
  161. //#ifndef _DEBUG
  162. #define SIZE_STATS // include statistics to determine the part of code generated from C code
  163. //#endif
  164. #endif
  165. #endif
  166. #ifdef FLASH_VERSION
  167. #define HAS_CMDLINE_EXTENSION
  168. #endif
  169. #ifdef BIGSTACK
  170. #define XLST_TYPE long
  171. #define REG_PARAMS 0xF000
  172. #define REG_PARAMLOG 12
  173. #else
  174. #define XLST_TYPE int
  175. /* limits the param size to 2 kb - not much of a problem ;) */
  176. #define REG_PARAMS 0x7800
  177. #define REG_PARAMLOG 11
  178. #endif
  179. #ifndef HAS_TI_SHORT
  180. #ifdef PC
  181. typedef struct {
  182. unsigned char x0,x1,x2,x3;
  183. } TI_LONG;
  184. typedef struct {
  185. unsigned char hi,lo;
  186. } TI_SHORT;
  187. #else
  188. typedef unsigned long TI_LONG;
  189. typedef unsigned short TI_SHORT;
  190. #endif
  191. #ifdef PC
  192. extern unsigned long _w2ul(TI_LONG *p);
  193. extern unsigned short _w2us(TI_SHORT *p);
  194. #define w2ul(x) _w2ul(&(x))
  195. #define w2us(x) _w2us(&(x))
  196. #else
  197. #define w2ul(x) (x)
  198. #define w2us(x) (x)
  199. #endif
  200. #endif
  201. #ifndef NOFLOAT
  202. #ifndef PC
  203. #ifndef BCDFLT
  204. #define double long
  205. #endif
  206. #endif
  207. #endif
  208. #ifndef NOBCDFLT
  209. #define BCDLEN 8
  210. typedef struct bcd {
  211. unsigned short exponent;
  212. unsigned char mantissa[BCDLEN];
  213. } BCD;
  214. #endif
  215. #ifdef PC
  216. #define infunc(f) if (!strcmp(func_sp->name,f))
  217. #define bkpt() printf("")
  218. #define DB_POSSIBLE
  219. #define DEBUG 1
  220. #ifdef SHORT_INT
  221. #define int short
  222. #endif
  223. #ifdef CMAIN_C
  224. long alloc[3][0xE000];
  225. #else
  226. extern long alloc[][0xE000];
  227. #endif
  228. enum myEnum {
  229. ANONYMOUS=0, COPYNODE=1, ENTERNODE=2, STRINGLIT=3, LITLATE=4,
  230. STRSAVE=5, MK_TYPE=6, _DECLARE=7, DECLENUM=8, ENUMBODY=9,
  231. DECLSTRUCT=0xA, SV_TYPE=0xB, MK_NODE=0xC, MK_ICON=0xD,
  232. NAMEREF=0xE, FUNCBODY=0xF, MK_INT=0x10, MK_SCRATCH=0x11,
  233. MK_LABEL=0x12, MK_IMMED=0x13, MK_OFFSET=0x14, COPY_ADDR=0x15,
  234. G_DEREF=0x16, G_EXPR=0x17, MK_REG=0x18, MK_MASK=0x19,
  235. MK_STRLAB=0x1A, GENLOOP=0x1B, G_CODE=0x1C, G_LABEL=0x1D,
  236. DODEFINE=0x1E, G_PUSH=0x1F, TEMP_DATA=0x20, TEMP_ADDR=0x21,
  237. SYMBOL=0x22, REF_ADD=0x23, LAB_ADD_REF=0x24, RT_ADD_REF=0x25,
  238. ENODE=0x1000, CSE=0x2000, SLIT=0x3000, STR=0x4000, _TYP=0x5000,
  239. _SYM=0x6000, AMODE=0x7000, OCODE=0x8000, _TABLE=0x9000,
  240. SNODE=0xA000, _TAB=0xB000, _REF=0xC000, _RT=0xD000,
  241. };
  242. #define xalloc(s,c) (alloc[temp_mem?2:!!global_flag][(c)]+=(s)+((s)&1),_xalloc(((s)+3)&-4))
  243. #define _FILE(x)
  244. #define dseg() while (0)
  245. #define cseg() while (0)
  246. #define compound_done getsym
  247. #ifdef _MSC_VER
  248. #pragma warning (disable : 4033 4013 4716 4715 4133)
  249. #pragma warning (disable : 4996) // strcpy/fopen/... are declared deprecated in VC++ 2005 :D
  250. #ifdef SHORT_INT
  251. #pragma warning (disable : 4305 4244 4761)
  252. #endif
  253. #endif
  254. #ifdef SHORT_INT
  255. #undef int
  256. #endif
  257. #define debug(x) ((void)0)
  258. #include <memory.h>
  259. #include <string.h>
  260. #include <stdio.h>
  261. #include <stdlib.h>
  262. #include <ctype.h>
  263. #ifndef _MSC_VER
  264. #ifndef __MINGW32__
  265. #include <alloca.h>
  266. #else
  267. #include <malloc.h>
  268. #endif
  269. #else
  270. #define alloca _alloca
  271. #endif
  272. #ifdef SHORT_INT
  273. #define int short
  274. #endif
  275. #ifndef max
  276. #define max(a,b) ((a)>(b)?(a):(b))
  277. #endif
  278. #define getline getline_gtc
  279. typedef size_t short_size;
  280. #else
  281. #define infunc(f) if (0)
  282. #define bkpt() {}
  283. #define DB_POSSIBLE
  284. #define DEBUG 0
  285. #define xalloc(__s,__c) _xalloc(__s+(__s&1))
  286. //#define _FILE(x) asm(".ascii \""x"\";.even");
  287. #define _FILE(__x)
  288. #define cached_sym (int)_cached_sym
  289. #define AS92p
  290. #ifndef CMAIN_C
  291. #define NOSTUB
  292. #define _rom_call(type,args,ind) (*(type(**)args)(*(long*)0xC8+0x##ind*4))
  293. #else
  294. #include "lib_map.h"
  295. #define USE_KERNEL
  296. //#define USE_FULL_LONGMUL_PATCH
  297. //#define USE_FULL_LONGDIV_PATCH
  298. int _ti89;
  299. #endif
  300. #ifndef gtc_compiled
  301. #include <tigcclib.h>
  302. #else
  303. #define FILE void
  304. #define NULL (void *)0
  305. #endif
  306. #undef off
  307. //#define stkparm
  308. #ifndef FLASH_VERSION
  309. #define debug(x) ((void)0)
  310. #undef clrscr
  311. #define clrscr gtcrt__0000
  312. #undef printf
  313. #define printf gtcrt__0001
  314. #undef vcbprintf
  315. #define vcbprintf gtcrt__0002
  316. #undef fopen
  317. #define fopen gtcrt__0008
  318. FILE *fopen(const char *,const char *);
  319. #undef fclose
  320. #define fclose gtcrt__0009
  321. #undef fputc
  322. #define fputc gtcrt__000a
  323. int fputc(int,FILE *);
  324. #undef fgetc
  325. #define fgetc gtcrt__000b
  326. #undef fwrite
  327. #define fwrite gtcrt__000c
  328. int fwrite(void *,int,int,FILE *);
  329. #undef fputs
  330. #define fputs gtcrt__0010
  331. #undef fgets
  332. #define fgets gtcrt__0011
  333. char *fgets(char *,int,FILE *);
  334. #undef fprintf
  335. #define fprintf gtcrt__0014
  336. #else
  337. #define debug(x) ((void)0) // for flash ver
  338. #undef fclose
  339. #define fclose my_fclose // fix buggy fclose
  340. void my_fclose(FILE *f);
  341. #define OPTIMIZE_BSS
  342. #define BSS_SIZE 8192
  343. #endif /* FLASH_VERSION */
  344. typedef short short_size;
  345. //#undef printf
  346. //#undef fputchar
  347. //#define printf print
  348. //#define printf(f...) (((void(*)(void*,char*,...))prtf)(fputchar,##f))
  349. //#define fputchar ((short(*)(char))ptch)
  350. #endif
  351. #ifndef FLASH_VERSION
  352. #define CGLOB =0
  353. #define CGLOBL ={0}
  354. #define xstatic static
  355. #define readonly
  356. #else
  357. #define CGLOB
  358. #define CGLOBL
  359. #define xstatic
  360. #define readonly const
  361. #endif
  362. #include "protos.h"
  363. #ifndef nl
  364. void nl(void);
  365. #endif
  366. #ifndef PC
  367. char *__attribute__((stkparm)) sUnpack(char *in,char *out,char *dic);
  368. #else
  369. char *sUnpack(char *in,char *out,char *dic);
  370. #endif
  371. #endif
  372. // vim:ts=4:sw=4