all.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * GTools C compiler
  3. * =================
  4. * source file :
  5. * (on-calc) main file
  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 DECLARE
  16. #define FLASH_VERSION
  17. #define GTDEV
  18. #include "define.h"
  19. #ifdef OPTIMIZE_BSS
  20. register void *bssdata asm("a5");
  21. #endif
  22. #define dseg() while (0)
  23. #define cseg() while (0)
  24. #define nl() while (0)
  25. #define compound_done getsym
  26. #include "c.h"
  27. #include "expr.h"
  28. #include "gen.h"
  29. #include "cglbdec.h"
  30. #include "flashhdr.h"
  31. #ifdef GTDEV
  32. #include "GtDevComm.h"
  33. #endif
  34. #include "flashhdr.c"
  35. #ifndef debug
  36. void debug(int c) {
  37. printf("%c ",c);
  38. ngetchx();
  39. }
  40. #endif
  41. #undef exit
  42. #define exit(k) asm(" move.l exit_a7,%sp\n rts")
  43. extern char *curname;
  44. extern void fatal(char *s) __attribute__ ((noreturn));
  45. #include "out68k_as.c"
  46. #include "decl.c"
  47. #include "expr.c"
  48. #ifdef ASM
  49. #include "getasm.c"
  50. #endif
  51. #include "getsym.c"
  52. #include "init.c"
  53. #include "intexpr.c"
  54. //#include "memmgt.c" // xalloc is common to both modules
  55. #include "preproc.c"
  56. #include "searchkw.c"
  57. #include "stmt.c"
  58. #include "symbol.c"
  59. void *exit_a7 CGLOB;
  60. #if 0
  61. void _exit(int code) {
  62. clean_up();
  63. printf("\nerror code %d",code);
  64. while (!kbhit());
  65. asm(" move.l exit_a7,%sp; rts");
  66. // exit(0);
  67. }
  68. #endif
  69. void _noreturn assert_terminated();
  70. #ifdef GTDEV
  71. void fatal(char *message) {
  72. clean_up();
  73. msg_process(message, ET_FATAL, "", "", -1, -1);
  74. exit(0);
  75. assert_terminated();
  76. }
  77. #else
  78. void fatal(char *message) {
  79. clean_up();
  80. msg2("Fatal error!\n%s\n", message);
  81. // msg("There may be a syntax error or a compiler bug.\n");
  82. // while (!kbhit());
  83. ngetchx();
  84. asm(" move.l exit_a7,%sp; rts");
  85. assert_terminated();
  86. // exit(0);
  87. }
  88. #endif
  89. void fatal(char *s) __attribute__ ((noreturn));
  90. #define mk_node near_mk_node
  91. #define mk_icon near_mk_icon
  92. struct enode *mk_node(enum(e_node) nt, struct enode *v1, struct enode *v2) {
  93. /*
  94. * build an expression node with a node type of nt and values v1 and v2.
  95. */
  96. struct enode *ep;
  97. ep = (struct enode *) xalloc((int) sizeof(struct enode), ENODE+MK_NODE);
  98. ep->nodetype = nt;
  99. ep->etype = bt_void;
  100. ep->esize = -1;
  101. ep->v.p[0] = v1;
  102. ep->v.p[1] = v2;
  103. return ep;
  104. }
  105. struct enode *mk_icon(long i) {
  106. /*
  107. * build an expression node forming an integer constant
  108. */
  109. struct enode *ep;
  110. // ep = (struct enode *) xalloc((int) sizeof(struct enode), ENODE+MK_ICON);
  111. ep = (struct enode *) xalloc((int) sizeof(struct xcon), ENODE+MK_ICON);
  112. ep->nodetype = en_icon;
  113. ep->etype = bt_void;
  114. #ifdef NO_CALLOC
  115. ep->esize = 0;
  116. #endif
  117. ep->v.i = i;
  118. return ep;
  119. }
  120. #include "analyze.c"
  121. #include "func.c"
  122. #include "gen68k.c"
  123. #include "genffp.c"
  124. #include "genstmt.c"
  125. #include "memmgt.c" // xalloc is common to both modules
  126. #include "optimize.c"
  127. #include "peep68k.c"
  128. #include "reg68k.c"
  129. /* this is reimplemented because old versions of TIGCC didn't check for _F_WRIT */
  130. void my_fclose(FILE *f) {
  131. if (f->flags&_F_WRIT)
  132. HeapRealloc(f->handle,*(unsigned short*)f->base+2);
  133. HeapUnlock(f->handle);
  134. free(f);
  135. }
  136. asm("bcopy:\n"
  137. " move.w (12,%sp),-(%sp)\n"
  138. " clr.w -(%sp)\n"
  139. " move.l (8,%sp),-(%sp)\n"
  140. " move.l (16,%sp),-(%sp)\n"
  141. " movea.l 0xC8,%a0\n"
  142. " movea.l (%a0,0x26A*4),%a0\n"
  143. " jsr (%a0) /* memcpy */\n"
  144. " lea (%sp,12),%sp\n"
  145. " rts\n"
  146. "__mulsi3:\n"
  147. " move.l (4,%sp),%d1\n"
  148. " move.l (8,%sp),%d2\n"
  149. " move.l %d2,%d0\n"
  150. " mulu %d1,%d0\n"
  151. " swap %d2\n"
  152. " mulu %d1,%d2\n"
  153. " swap %d1\n"
  154. " mulu (10,%sp),%d1\n"
  155. " add.w %d1,%d2\n"
  156. " swap %d2\n"
  157. " clr.w %d2\n"
  158. " add.l %d2,%d0\n"
  159. " rts\n"
  160. "__modsi3:\n"
  161. " move.w #0x2A9*4,%d2 /* _ms32s32 */\n"
  162. " bra.s __div_entry\n"
  163. "__divsi3:\n"
  164. " move.w #0x2A8*4,%d2 /* _ds32s32 */\n"
  165. " bra.s __div_entry\n"
  166. "__umodsi3:\n"
  167. " move.w #0x2A9*4,%d2 /* _mu32u32 */\n"
  168. " bra.s __div_entry\n"
  169. "__udivsi3:\n"
  170. " move.w #0x2A8*4,%d2 /* _du32u32 */\n"
  171. " bra.s __div_entry\n"
  172. " nop\n"
  173. "__div_entry:\n"
  174. " move.l (4,%sp),%d1\n"
  175. " move.l (8,%sp),%d0\n"
  176. " movea.l 0xC8,%a0\n"
  177. " movea.l (%a0,%d2.w),%a0\n"
  178. " jsr (%a0)\n"
  179. " move.l %d1,%d0\n"
  180. " rts");
  181. #include "cmain.c"
  182. #include "flashend.c"
  183. // vim:ts=4:sw=4