Compiler.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* voc 2.1.0 [2021/07/05]. Bootstrapping compiler for address size 8, alignment 8. xrtspamS */
  2. #define SHORTINT INT8
  3. #define INTEGER INT16
  4. #define LONGINT INT32
  5. #define SET UINT32
  6. #include "SYSTEM.h"
  7. #include "Configuration.h"
  8. #include "Heap.h"
  9. #include "OPB.h"
  10. #include "OPC.h"
  11. #include "OPM.h"
  12. #include "OPP.h"
  13. #include "OPT.h"
  14. #include "OPV.h"
  15. #include "Platform.h"
  16. #include "Strings.h"
  17. #include "VT100.h"
  18. #include "extTools.h"
  19. static void Compiler_FindLocalObjectFiles (CHAR *objectnames, ADDRESS objectnames__len);
  20. export void Compiler_Module (BOOLEAN *done);
  21. static void Compiler_PropagateElementaryTypeSizes (void);
  22. export void Compiler_Translate (void);
  23. static void Compiler_Trap (INT32 sig);
  24. void Compiler_Module (BOOLEAN *done)
  25. {
  26. BOOLEAN ext, new;
  27. OPT_Node p = NIL;
  28. OPP_Module(&p, OPM_Options);
  29. if (OPM_noerr) {
  30. OPV_Init();
  31. OPT_InitRecno();
  32. OPV_AdrAndSize(OPT_topScope);
  33. OPT_Export(&ext, &new);
  34. if (OPM_noerr) {
  35. OPM_OpenFiles((void*)OPT_SelfName, 256);
  36. OPM_DeleteObj((void*)OPT_SelfName, 256);
  37. OPC_Init();
  38. OPV_Module(p);
  39. if (OPM_noerr) {
  40. if ((__IN(10, OPM_Options, 32) && __STRCMP(OPM_modName, "SYSTEM") != 0)) {
  41. OPM_DeleteSym((void*)OPT_SelfName, 256);
  42. OPM_LogVT100((CHAR*)"32m", 4);
  43. OPM_LogWStr((CHAR*)" Main program.", 16);
  44. OPM_LogVT100((CHAR*)"0m", 3);
  45. } else {
  46. if (new) {
  47. OPM_LogVT100((CHAR*)"32m", 4);
  48. OPM_LogWStr((CHAR*)" New symbol file.", 19);
  49. OPM_LogVT100((CHAR*)"0m", 3);
  50. OPM_RegisterNewSym();
  51. } else if (ext) {
  52. OPM_LogWStr((CHAR*)" Extended symbol file.", 24);
  53. OPM_RegisterNewSym();
  54. }
  55. }
  56. } else {
  57. OPM_DeleteSym((void*)OPT_SelfName, 256);
  58. }
  59. }
  60. }
  61. OPM_CloseFiles();
  62. OPT_Close();
  63. OPM_LogWLn();
  64. *done = OPM_noerr;
  65. }
  66. static void Compiler_PropagateElementaryTypeSizes (void)
  67. {
  68. OPT_Struct adrinttyp = NIL;
  69. OPT_sysptrtyp->size = OPM_AddressSize;
  70. OPT_sysptrtyp->idfp = OPT_sysptrtyp->form;
  71. OPM_FPrint(&OPT_sysptrtyp->idfp, OPT_sysptrtyp->size);
  72. OPT_adrtyp->size = OPM_AddressSize;
  73. OPT_adrtyp->idfp = OPT_adrtyp->form;
  74. OPM_FPrint(&OPT_adrtyp->idfp, OPT_adrtyp->size);
  75. adrinttyp = OPT_IntType(OPM_AddressSize);
  76. OPT_adrtyp->strobj = adrinttyp->strobj;
  77. OPT_sinttyp = OPT_IntType(OPM_ShortintSize);
  78. OPT_inttyp = OPT_IntType(OPM_IntegerSize);
  79. OPT_linttyp = OPT_IntType(OPM_LongintSize);
  80. OPT_sintobj->typ = OPT_sinttyp;
  81. OPT_intobj->typ = OPT_inttyp;
  82. OPT_lintobj->typ = OPT_linttyp;
  83. switch (OPM_SetSize) {
  84. case 4:
  85. OPT_settyp = OPT_set32typ;
  86. break;
  87. default:
  88. OPT_settyp = OPT_set64typ;
  89. break;
  90. }
  91. OPT_setobj->typ = OPT_settyp;
  92. if (__STRCMP(OPM_Model, "C") == 0) {
  93. OPT_cpbytetyp->strobj->name[4] = 0x00;
  94. } else {
  95. OPT_cpbytetyp->strobj->name[4] = '@';
  96. }
  97. }
  98. static void Compiler_FindLocalObjectFiles (CHAR *objectnames, ADDRESS objectnames__len)
  99. {
  100. OPT_Link l = NIL;
  101. CHAR fn[64];
  102. Platform_FileIdentity id;
  103. objectnames[0] = 0x00;
  104. l = OPT_Links;
  105. while (l != NIL) {
  106. __COPY(l->name, fn, 64);
  107. Strings_Append((CHAR*)".sym", 5, (void*)fn, 64);
  108. if (Platform_IdentifyByName(fn, 64, &id, Platform_FileIdentity__typ) == 0) {
  109. __COPY(l->name, fn, 64);
  110. Strings_Append((CHAR*)".o", 3, (void*)fn, 64);
  111. if (Platform_IdentifyByName(fn, 64, &id, Platform_FileIdentity__typ) == 0) {
  112. Strings_Append((CHAR*)" ", 2, (void*)objectnames, objectnames__len);
  113. Strings_Append(fn, 64, (void*)objectnames, objectnames__len);
  114. } else {
  115. OPM_LogVT100((CHAR*)"91m", 4);
  116. OPM_LogWStr((CHAR*)"Link warning: a local symbol file is present for module ", 57);
  117. OPM_LogWStr(l->name, 256);
  118. OPM_LogWStr((CHAR*)", but local object file '", 26);
  119. OPM_LogWStr(fn, 64);
  120. OPM_LogWStr((CHAR*)"' is missing.", 14);
  121. OPM_LogVT100((CHAR*)"0m", 3);
  122. OPM_LogWLn();
  123. }
  124. }
  125. l = l->next;
  126. }
  127. }
  128. void Compiler_Translate (void)
  129. {
  130. BOOLEAN done;
  131. CHAR linkfiles[2048];
  132. if (OPM_OpenPar()) {
  133. for (;;) {
  134. OPM_Init(&done);
  135. if (!done) {
  136. return;
  137. }
  138. OPM_InitOptions();
  139. Compiler_PropagateElementaryTypeSizes();
  140. Heap_GC(0);
  141. Compiler_Module(&done);
  142. if (!done) {
  143. OPM_LogWLn();
  144. OPM_LogWStr((CHAR*)"Module compilation failed.", 27);
  145. OPM_LogWLn();
  146. Platform_Exit(1);
  147. }
  148. if (!__IN(13, OPM_Options, 32)) {
  149. if (__IN(14, OPM_Options, 32)) {
  150. extTools_Assemble(OPM_modName, 32);
  151. } else {
  152. if (!__IN(10, OPM_Options, 32)) {
  153. extTools_Assemble(OPM_modName, 32);
  154. } else {
  155. Compiler_FindLocalObjectFiles((void*)linkfiles, 2048);
  156. extTools_LinkMain((void*)OPM_modName, 32, __IN(15, OPM_Options, 32), linkfiles, 2048);
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
  163. static void Compiler_Trap (INT32 sig)
  164. {
  165. Heap_FINALL();
  166. if (sig == 3) {
  167. Platform_Exit(0);
  168. } else {
  169. if (sig == 4) {
  170. OPM_LogWStr((CHAR*)" --- Oberon compiler internal error", 36);
  171. OPM_LogWLn();
  172. }
  173. Platform_Exit(2);
  174. }
  175. }
  176. export int main(int argc, char **argv)
  177. {
  178. __INIT(argc, argv);
  179. __MODULE_IMPORT(Configuration);
  180. __MODULE_IMPORT(Heap);
  181. __MODULE_IMPORT(OPB);
  182. __MODULE_IMPORT(OPC);
  183. __MODULE_IMPORT(OPM);
  184. __MODULE_IMPORT(OPP);
  185. __MODULE_IMPORT(OPT);
  186. __MODULE_IMPORT(OPV);
  187. __MODULE_IMPORT(Platform);
  188. __MODULE_IMPORT(Strings);
  189. __MODULE_IMPORT(VT100);
  190. __MODULE_IMPORT(extTools);
  191. __REGMAIN("Compiler", 0);
  192. __REGCMD("Translate", Compiler_Translate);
  193. /* BEGIN */
  194. Platform_SetInterruptHandler(Compiler_Trap);
  195. Platform_SetQuitHandler(Compiler_Trap);
  196. Platform_SetBadInstructionHandler(Compiler_Trap);
  197. Compiler_Translate();
  198. __FINI;
  199. }