Compiler.Mod 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. MODULE Compiler; (** AUTHOR "fof & fn"; PURPOSE "Oberon Compiler Command Interface"; **)
  2. (* (c) fof ETH Zürich, 2008 *)
  3. IMPORT
  4. Basic := FoxBasic, Scanner := FoxScanner, Parser := FoxParser,
  5. SemanticChecker := FoxSemanticChecker, SyntaxTree := FoxSyntaxTree, Formats := FoxFormats,
  6. Streams, Commands,Diagnostics, Options, Kernel, Printout := FoxPrintout, Backend := FoxBackend,Strings, Global := FoxGlobal,
  7. Frontend := FoxFrontend, Files, Machine;
  8. CONST
  9. (* flags *)
  10. Print* = 0;
  11. Silent* = 1;
  12. Check* = 2;
  13. TraceError* = 3;
  14. Info* = 4;
  15. FindPC* = 5;
  16. Warnings*=7;
  17. ForceModuleBodies*=8;
  18. UseDarwinCCalls*=9; (* use Darwin stack alignment for ext. C procedures *) (*fld*)
  19. SingleModule*=10;
  20. Oberon07*=11;
  21. ChangeCase*=12;
  22. Cooperative*=13;
  23. CellsAreObjects*=14;
  24. UseLineNumbers*=15;
  25. DefaultBackend = "AMD";
  26. DefaultFrontend = "Oberon";
  27. TYPE
  28. SectionName = ARRAY 256 OF CHAR; (*! move *)
  29. CompilerOptions*= RECORD
  30. flags*: SET;
  31. frontend*: Frontend.Frontend;
  32. backend*: Backend.Backend;
  33. symbolFile*: Formats.SymbolFileFormat;
  34. objectFile*: Formats.ObjectFileFormat;
  35. findPC*: SectionName;
  36. documentation*: Backend.Backend;
  37. srcPath, destPath: Files.FileName;
  38. replacements: SemanticChecker.Replacement;
  39. platformCallingConvention: SyntaxTree.CallingConvention;
  40. END;
  41. PROCEDURE ParseReplacements(CONST filename: ARRAY OF CHAR; VAR replacement: SemanticChecker.Replacement; diagnostics: Diagnostics.Diagnostics): BOOLEAN;
  42. VAR reader: Streams.Reader; r: SemanticChecker.Replacement;
  43. identifier: SyntaxTree.QualifiedIdentifier;
  44. scanner: Scanner.Scanner; parser: Parser.Parser; expression: SyntaxTree.Expression;
  45. BEGIN
  46. replacement := NIL;
  47. reader := Basic.GetFileReader(filename);
  48. IF reader = NIL THEN
  49. diagnostics.Error (filename, Diagnostics.Invalid, Diagnostics.Invalid, "failed to open");
  50. ELSE
  51. scanner := Scanner.NewScanner(filename, reader, 0, diagnostics);
  52. NEW(parser, scanner, diagnostics);
  53. REPEAT (* WHILE parser.Peek(Scanner.Identifier) DO*)
  54. identifier := parser.QualifiedIdentifier();
  55. IF parser.Mandatory(Scanner.Equal) THEN
  56. expression := parser.Expression();
  57. NEW(r); identifier.GetName(r.name); r.expression := expression; r.used := FALSE;
  58. r.next := replacement; replacement := r;
  59. END;
  60. WHILE parser.Optional(Scanner.Semicolon) DO END;
  61. UNTIL ~parser.Peek(Scanner.Identifier); (*END;*)
  62. END;
  63. (*done := FALSE;
  64. WHILE reader.GetString(name) & ~done DO
  65. IF reader.GetChar(equal) & (equal = "=") & reader.GetString(value) THEN
  66. NEW(r); r.name := name; r.string := Strings.NewString(value); r.used := FALSE;
  67. r.next := replacement; replacement := r;
  68. ELSE done := TRUE;
  69. END;
  70. END;
  71. *)
  72. RETURN (replacement # NIL)
  73. END ParseReplacements;
  74. PROCEDURE Modules*(CONST source: ARRAY OF CHAR; (* source file name, for debugging and better error reports *)
  75. reader: Streams.Reader; (* reader to read from *)
  76. position: LONGINT; (* starting position in reader *)
  77. diagnostics: Diagnostics.Diagnostics; (* error output and status report *)
  78. log: Streams.Writer;
  79. CONST options: CompilerOptions;
  80. VAR importCache: SyntaxTree.ModuleScope): BOOLEAN;
  81. VAR
  82. module: SyntaxTree.Module;
  83. checker: SemanticChecker.Checker;
  84. warnings: SemanticChecker.Warnings;
  85. printer: Printout.Printer;
  86. system: Global.System;
  87. generatedModule: Formats.GeneratedModule;
  88. split: Strings.StringArray;
  89. sectionOffset: LONGINT;
  90. flags: SET;
  91. backendName: ARRAY 32 OF CHAR;
  92. PROCEDURE FinalMessage(error: BOOLEAN; CONST msg: ARRAY OF CHAR);
  93. VAR message,name: ARRAY 256 OF CHAR;
  94. BEGIN
  95. message := "";
  96. IF module # NIL THEN
  97. Global.GetModuleName(module, message);
  98. END;
  99. Strings.Append (message, msg);
  100. IF error THEN
  101. IF diagnostics # NIL THEN
  102. diagnostics.Error (source, Diagnostics.Invalid, Diagnostics.Invalid, message);
  103. END;
  104. ELSE
  105. IF (log # NIL) & ~(Silent IN options.flags) & ~(FindPC IN options.flags) THEN
  106. log.String("compiling ");
  107. IF source # "" THEN log.String(source); log.String(" => "); END;
  108. log.String(message); log.Ln;
  109. log.Update;
  110. END;
  111. END;
  112. END FinalMessage;
  113. PROCEDURE PrintModule;
  114. VAR print: Streams.Writer;
  115. BEGIN
  116. print := Basic.GetWriter(Basic.GetDebugWriter("Compiler Debug Output"));
  117. IF Info IN options.flags THEN
  118. printer := Printout.NewPrinter(print,Printout.All,Info IN options.flags);
  119. ELSE
  120. printer := Printout.NewPrinter(print,Printout.SourceCode,Info IN options.flags);
  121. END;
  122. print.Ln; printer.Module(module); print.Ln;
  123. print.Update;
  124. END PrintModule;
  125. BEGIN
  126. flags := options.flags;
  127. IF options.findPC # "" THEN EXCL(flags, Warnings) END;
  128. IF TraceError IN options.flags THEN
  129. diagnostics := Basic.GetTracingDiagnostics(diagnostics)
  130. END;
  131. IF options.backend = NIL THEN
  132. system := Global.DefaultSystem()
  133. ELSE
  134. IF Oberon07 IN options.flags THEN options.backend.SetOberon07 END; (* inform the backend about that the Oberon07 mode, it will return the corresponding Sytem object *)
  135. system := options.backend.GetSystem();
  136. END;
  137. system.SetCellsAreObjects(CellsAreObjects IN flags);
  138. system.SetPlatformCallingConvention(options.platformCallingConvention);
  139. IF (options.objectFile # NIL) & (options.objectFile.ForceModuleBodies()) THEN INCL(flags, ForceModuleBodies) END;
  140. options.frontend.Initialize(diagnostics, flags, reader, source, position);
  141. REPEAT
  142. (** first phase: scan and parse **)
  143. module := options.frontend.Parse();
  144. IF options.frontend.Error() THEN
  145. FinalMessage(TRUE," could not be compiled (parser errors).");
  146. RETURN FALSE;
  147. END;
  148. ASSERT(module # NIL);
  149. IF Check IN flags THEN
  150. (** second phase: check and resolve symbols **)
  151. IF (options.symbolFile # NIL) THEN
  152. options.symbolFile.Initialize(diagnostics,system,options.destPath);
  153. END;
  154. IF options.backend # NIL THEN
  155. COPY(options.backend.name, backendName);
  156. ELSE
  157. backendName := "";
  158. END;
  159. checker := SemanticChecker.NewChecker(diagnostics,Info IN flags,UseDarwinCCalls IN flags,Cooperative IN flags,system,options.symbolFile,importCache,backendName);
  160. checker.replacements := options.replacements;
  161. checker.Module(module);
  162. IF checker.error THEN
  163. FinalMessage(TRUE," could not be compiled (checker errors).");
  164. RETURN FALSE
  165. ELSIF Warnings IN flags THEN
  166. warnings := SemanticChecker.NewWarnings(diagnostics);
  167. warnings.Module(module);
  168. END;
  169. IF Print IN flags THEN
  170. IF ChangeCase IN flags THEN module.SetCase(1-module.case) END;
  171. PrintModule;
  172. IF ChangeCase IN flags THEN module.SetCase(1-module.case) END;
  173. END;
  174. (** third phase: generate code, can consist of sub-phases (such as intermediate backend / hardware backend) **)
  175. IF options.backend # NIL THEN
  176. options.backend.Initialize(diagnostics, log, flags, checker, system);
  177. IF options.findPC # "" THEN
  178. split := Strings.Split(options.findPC,":");
  179. IF LEN(split)>1 THEN
  180. Strings.StrToInt(split[1]^,sectionOffset);
  181. options.backend.FindPC(module, split[0]^,sectionOffset);
  182. IF options.backend.error THEN
  183. FinalMessage(TRUE," could not be compiled (backend errors).");
  184. RETURN FALSE
  185. ELSE
  186. RETURN TRUE
  187. END;
  188. END;
  189. END;
  190. generatedModule := options.backend.ProcessSyntaxTreeModule(module);
  191. IF options.backend.error THEN
  192. FinalMessage(TRUE, " could not be compiled (backend errors).");
  193. RETURN FALSE
  194. END;
  195. END;
  196. (** generate symbol file **)
  197. IF (options.symbolFile # NIL) & ~options.symbolFile.Export(module, importCache) THEN
  198. FinalMessage(TRUE, " could not be compiled (symbol File errors).");
  199. RETURN FALSE
  200. END;
  201. (** generate object file **)
  202. IF options.objectFile # NIL THEN
  203. options.objectFile.Initialize(diagnostics);
  204. options.objectFile.SetPath(options.destPath);
  205. IF options.findPC # "" THEN
  206. Strings.StrToInt(options.findPC, sectionOffset);
  207. generatedModule.SetFindPC(sectionOffset);
  208. END;
  209. IF generatedModule = NIL THEN
  210. FinalMessage(TRUE, " could not write object file (nothing generated).");
  211. RETURN FALSE
  212. ELSIF ~options.objectFile.Export(generatedModule,options.symbolFile) THEN
  213. FinalMessage(TRUE, " could not be compiled (object file errors).");
  214. RETURN FALSE
  215. END;
  216. END;
  217. IF options.documentation # NIL THEN
  218. options.documentation.Initialize(diagnostics,log, flags,checker,system);
  219. generatedModule := options.documentation.ProcessSyntaxTreeModule(module);
  220. END;
  221. FinalMessage(FALSE, " done.");
  222. ELSIF Print IN flags THEN
  223. IF ChangeCase IN flags THEN module.SetCase(1-module.case) END;
  224. PrintModule;
  225. FinalMessage(FALSE, " done.")
  226. ELSE
  227. FinalMessage(FALSE, " done.");
  228. END;
  229. UNTIL (SingleModule IN flags) OR options.frontend.Done();
  230. RETURN TRUE;
  231. END Modules;
  232. PROCEDURE GetOptions*(input: Streams.Reader; error:Streams.Writer; diagnostics: Diagnostics.Diagnostics;
  233. VAR compilerOptions: CompilerOptions): BOOLEAN;
  234. VAR options: Options.Options; name: ARRAY 256 OF CHAR; result: BOOLEAN; position: LONGINT;
  235. defaults: Streams.Reader;
  236. parsed: BOOLEAN;
  237. PROCEDURE Error(CONST error: ARRAY OF CHAR);
  238. BEGIN
  239. IF diagnostics # NIL THEN
  240. diagnostics.Error("",Diagnostics.Invalid,Diagnostics.Invalid,error);
  241. END;
  242. END Error;
  243. BEGIN
  244. result := TRUE;
  245. NEW(options);
  246. options.Add("p","platform",Options.String);
  247. options.Add(0X,"showOptions",Options.Flag);
  248. options.Add("l","lineNumbers", Options.Flag);
  249. options.Add(0X,"print",Options.Flag);
  250. options.Add(0X,"Print",Options.Flag);
  251. options.Add(0X,"silent",Options.Flag);
  252. options.Add("c","check",Options.Flag);
  253. options.Add("e","traceError",Options.Flag);
  254. options.Add("I","interface",Options.Flag);
  255. options.Add("i","info",Options.Flag);
  256. options.Add(0X,"oberon07",Options.Flag);
  257. options.Add("b","backend",Options.String);
  258. options.Add("F","frontEnd",Options.String);
  259. options.Add("f","findPC",Options.String);
  260. options.Add(0X,"singleModule",Options.Flag);
  261. options.Add(0X, "symbolFile", Options.String);
  262. options.Add(0X, "objectFile", Options.String);
  263. options.Add("w","warnings", Options.Flag);
  264. options.Add(0X,"darwinHost", Options.Flag);
  265. options.Add(0X,"hardware", Options.String);
  266. options.Add("d","documentation", Options.String);
  267. options.Add("S","srcPath", Options.String);
  268. options.Add("D","destPath", Options.String);
  269. options.Add(0X,"replacements", Options.String);
  270. options.Add(0X,"cooperative", Options.Flag);
  271. options.Add(0X,"platformCC",Options.String);
  272. position := input.Pos();
  273. parsed := options.ParseStaged(input, error);
  274. IF options.GetString("platform", name) OR GetDefaultPlatform(name) THEN
  275. defaults := platforms.Get(name);
  276. IF defaults = NIL THEN
  277. error.String("Unknown platform"); error.Ln
  278. ELSE
  279. parsed := options.ParseStaged(defaults, error) & parsed;
  280. input.SetPos(position);
  281. parsed := options.ParseStaged(input, error) & parsed; (* reparse overwrites *)
  282. END;
  283. ELSE
  284. defaults := NIL;
  285. END;
  286. IF options.GetString("b", name) THEN
  287. IF name = "" THEN compilerOptions.backend := NIL
  288. ELSE
  289. compilerOptions.backend := Backend.GetBackendByName(name);
  290. IF (compilerOptions.backend = NIL) THEN
  291. Error("backend could not be installed"); result := FALSE;
  292. END;
  293. END;
  294. ELSE compilerOptions.backend := Backend.GetBackendByName(DefaultBackend);
  295. IF compilerOptions.backend = NIL THEN Error("default backend could not be installed"); result := FALSE END;
  296. END;
  297. IF options.GetString("F", name) THEN
  298. IF name = "" THEN compilerOptions.frontend := NIL
  299. ELSE
  300. compilerOptions.frontend := Frontend.GetFrontendByName(name);
  301. IF (compilerOptions.frontend = NIL) THEN
  302. Error("backend could not be installed"); result := FALSE;
  303. END;
  304. END;
  305. ELSE compilerOptions.frontend := Frontend.GetFrontendByName(DefaultFrontend);
  306. IF compilerOptions.frontend = NIL THEN Error("default frontend could not be installed"); result := FALSE END;
  307. END;
  308. IF options.GetString("objectFile",name) THEN
  309. IF name = "" THEN compilerOptions.objectFile := NIL
  310. ELSE
  311. compilerOptions.objectFile := Formats.GetObjectFileFormat(name);
  312. IF compilerOptions.objectFile = NIL THEN Error("object file format could not be installed"); result := FALSE END;
  313. END;
  314. ELSIF compilerOptions.backend # NIL THEN
  315. compilerOptions.objectFile := compilerOptions.backend.DefaultObjectFileFormat();
  316. END;
  317. IF options.GetString("symbolFile",name) THEN
  318. IF name = "" THEN compilerOptions.symbolFile := NIL
  319. ELSE
  320. compilerOptions.symbolFile := Formats.GetSymbolFileFormat(name);
  321. IF compilerOptions.symbolFile = NIL THEN Error("symbol file format could not be installed"); result := FALSE END;
  322. END;
  323. ELSIF compilerOptions.backend # NIL THEN
  324. compilerOptions.symbolFile := compilerOptions.backend.DefaultSymbolFileFormat();
  325. IF (compilerOptions.symbolFile = NIL) & (compilerOptions.objectFile # NIL) THEN
  326. compilerOptions.symbolFile := compilerOptions.objectFile.DefaultSymbolFileFormat();
  327. END;
  328. ELSIF compilerOptions.objectFile # NIL THEN
  329. compilerOptions.symbolFile := compilerOptions.objectFile.DefaultSymbolFileFormat();
  330. END;
  331. IF options.GetString("d", name) THEN
  332. compilerOptions.documentation := Backend.GetBackendByName("Documentation");
  333. IF (compilerOptions.documentation = NIL) THEN
  334. Error("documentation engine could not be installed"); result := FALSE;
  335. END;
  336. ELSE
  337. compilerOptions.documentation := NIL
  338. END;
  339. IF options.GetString("replacements", name) THEN
  340. IF ~ParseReplacements(name, compilerOptions.replacements, diagnostics) THEN
  341. Error("replacement file could not be opened or is empty"); result := FALSE;
  342. END;
  343. ELSE compilerOptions.replacements := NIL
  344. END;
  345. IF compilerOptions.backend # NIL THEN compilerOptions.backend.DefineOptions (options); INCL(compilerOptions.flags,Check); END;
  346. IF compilerOptions.symbolFile # NIL THEN compilerOptions.symbolFile.DefineOptions(options); INCL(compilerOptions.flags,Check) END;
  347. IF compilerOptions.objectFile # NIL THEN compilerOptions.objectFile.DefineOptions(options); INCL(compilerOptions.flags,Check) END;
  348. IF compilerOptions.documentation # NIL THEN compilerOptions.documentation.DefineOptions(options) END;
  349. IF result & ~parsed THEN
  350. options.Clear;
  351. IF defaults # NIL THEN
  352. defaults.SetPos(0);
  353. parsed := options.Parse(defaults, error);
  354. END;
  355. input.SetPos(position);
  356. result := options.Parse(input,error)
  357. END;
  358. IF result THEN
  359. IF options.GetFlag("print") THEN INCL(compilerOptions.flags, Print) END;
  360. IF options.GetFlag("Print") THEN INCL(compilerOptions.flags, Print); INCL(compilerOptions.flags, ChangeCase) END;
  361. IF options.GetFlag("silent") THEN INCL(compilerOptions.flags, Silent) END;
  362. IF options.GetFlag("check") THEN INCL(compilerOptions.flags, Check) END;
  363. IF options.GetFlag("traceError") THEN INCL(compilerOptions.flags, TraceError) END;
  364. IF options.GetFlag("info") THEN INCL(compilerOptions.flags,Info) END;
  365. IF options.GetString("findPC",compilerOptions.findPC) THEN INCL(compilerOptions.flags,FindPC) END;
  366. IF options.GetFlag("warnings") THEN INCL(compilerOptions.flags, Warnings) END;
  367. IF options.GetFlag("darwinHost") THEN INCL(compilerOptions.flags,UseDarwinCCalls) END; (*fld*)
  368. IF options.GetFlag("singleModule") THEN INCL(compilerOptions.flags,SingleModule) END;
  369. IF options.GetFlag("oberon07") THEN INCL(compilerOptions.flags, Oberon07) END;
  370. IF options.GetFlag("cooperative") THEN INCL(compilerOptions.flags, Cooperative) END;
  371. IF options.GetFlag("cellsAreObjects") THEN INCL(compilerOptions.flags, CellsAreObjects) END;
  372. IF ~options.GetString("srcPath", compilerOptions.srcPath) THEN compilerOptions.srcPath := "" END;
  373. IF ~options.GetString("destPath", compilerOptions.destPath) THEN compilerOptions.destPath := "" END;
  374. IF compilerOptions.backend # NIL THEN compilerOptions.backend.GetOptions (options) END;
  375. IF compilerOptions.symbolFile # NIL THEN compilerOptions.symbolFile.GetOptions(options) END;
  376. IF compilerOptions.objectFile # NIL THEN compilerOptions.objectFile.GetOptions(options) END;
  377. IF compilerOptions.documentation # NIL THEN compilerOptions.documentation.GetOptions(options) END;
  378. IF options.GetFlag("lineNumbers") THEN INCL(compilerOptions.flags, UseLineNumbers) END;
  379. IF options.GetString("platformCC", name) THEN
  380. IF name = Global.StringC THEN compilerOptions.platformCallingConvention := SyntaxTree.CCallingConvention
  381. ELSIF name = Global.StringWinAPI THEN compilerOptions.platformCallingConvention := SyntaxTree.WinAPICallingConvention
  382. ELSE
  383. compilerOptions.platformCallingConvention := SyntaxTree.UndefinedCallingConvention
  384. END;
  385. ELSE
  386. compilerOptions.platformCallingConvention := SyntaxTree.UndefinedCallingConvention
  387. END
  388. END;
  389. IF options.GetFlag("showOptions") THEN options.Show(error) END;
  390. RETURN result
  391. END GetOptions;
  392. PROCEDURE Compile*(context : Commands.Context);
  393. VAR
  394. filename, path, file: Files.FileName;
  395. error: BOOLEAN;
  396. diagnostics: Diagnostics.Diagnostics;
  397. time: LONGINT; reader: Streams.Reader;
  398. importCache: SyntaxTree.ModuleScope;
  399. options: CompilerOptions;
  400. replacement: SemanticChecker.Replacement;
  401. name: ARRAY 128 OF CHAR;
  402. BEGIN
  403. error := FALSE;
  404. diagnostics := Basic.GetDiagnostics(context.error);
  405. IF GetOptions(context.arg,context.error,diagnostics,options) THEN
  406. time := Kernel.GetTicks();
  407. WHILE Basic.GetStringParameter(context.arg,filename) & ~error DO
  408. IF options.srcPath # "" THEN
  409. Files.SplitPath(filename, path, file);
  410. IF path = "" THEN Files.JoinPath(options.srcPath, file, filename) END;
  411. END;
  412. reader := Basic.GetFileReader(filename);
  413. IF reader = NIL THEN
  414. diagnostics.Error (filename, Diagnostics.Invalid, Diagnostics.Invalid, "failed to open"); error := TRUE;
  415. ELSE
  416. error := ~Modules(filename, reader, 0, diagnostics,context.out, options, importCache);
  417. END;
  418. context.out.Update;
  419. context.error.Update;
  420. END;
  421. IF Silent IN options.flags THEN
  422. time := Kernel.GetTicks()-time;
  423. context.out.Ln; context.out.String("compiler elapsed ms"); context.out.Int(time,10);
  424. END;
  425. IF ~error THEN
  426. replacement := options.replacements;
  427. WHILE replacement # NIL DO
  428. IF ~replacement.used THEN
  429. name := replacement.name;
  430. diagnostics.Warning(name, Diagnostics.Invalid, Diagnostics.Invalid, " unused replacement.");
  431. END;
  432. replacement := replacement.next;
  433. END;
  434. END;
  435. END;
  436. IF error THEN context.result := -1 ELSE context.result := Commands.Ok END;
  437. END Compile;
  438. PROCEDURE CompileReader*(context: Commands.Context; reader: Streams.Reader);
  439. VAR
  440. filename: ARRAY 256 OF CHAR;
  441. error: BOOLEAN;
  442. diagnostics: Diagnostics.Diagnostics;
  443. importCache: SyntaxTree.ModuleScope;
  444. options: CompilerOptions;
  445. BEGIN
  446. error := FALSE;
  447. diagnostics := Basic.GetDiagnostics(context.error);
  448. IF GetOptions(context.arg,context.error,diagnostics,options) THEN
  449. IF reader = NIL THEN
  450. diagnostics.Error (filename, Diagnostics.Invalid, Diagnostics.Invalid, "failed to open"); error := TRUE;
  451. ELSE
  452. error := ~Modules(filename, reader, 0, diagnostics, context.out, options, importCache);
  453. END;
  454. context.out.Update;
  455. END;
  456. END CompileReader;
  457. VAR
  458. platforms: Options.Defaults;
  459. defaultPlatform: ARRAY 32 OF CHAR;
  460. PROCEDURE DoAddPlatform(CONST name: ARRAY OF CHAR; CONST defaults: ARRAY OF CHAR);
  461. BEGIN
  462. platforms.Add(name, defaults);
  463. END DoAddPlatform;
  464. PROCEDURE ShowDefaults*(context: Commands.Context);
  465. BEGIN
  466. platforms.Show(context.out)
  467. END ShowDefaults;
  468. PROCEDURE AddPlatform*(context: Commands.Context);
  469. VAR name: ARRAY 32 OF CHAR; defaults: ARRAY 1024 OF CHAR;
  470. BEGIN
  471. IF context.arg.GetString(name) & context.arg.GetString(defaults) THEN
  472. DoAddPlatform(name, defaults);
  473. END;
  474. END AddPlatform;
  475. PROCEDURE SetDefaultPlatform*(context: Commands.Context);
  476. VAR name: ARRAY 32 OF CHAR;
  477. BEGIN
  478. IF context.arg.GetString(name) THEN
  479. COPY(name, defaultPlatform);
  480. END;
  481. END SetDefaultPlatform;
  482. PROCEDURE GetDefaultPlatform(VAR name: ARRAY OF CHAR): BOOLEAN;
  483. BEGIN
  484. IF defaultPlatform # "" THEN
  485. COPY(defaultPlatform, name);
  486. RETURN TRUE
  487. ELSE
  488. RETURN FALSE
  489. END
  490. END GetDefaultPlatform;
  491. PROCEDURE SetupDefaults;
  492. VAR extension: Files.FileName;
  493. BEGIN
  494. Machine.GetConfig("ObjectFileExtension", extension);
  495. IF extension = "" THEN
  496. COPY(Machine.DefaultObjectFileExtension, extension)
  497. END;
  498. (* infer platform from default object file extension *)
  499. platforms.Find("objectFileExtension", extension, defaultPlatform);
  500. END SetupDefaults;
  501. BEGIN
  502. NEW(platforms);
  503. (* platform definitions hard coded for the common cases -- maybe (parts of it) should be outsourced to a file ?*)
  504. DoAddPlatform("Bios32","-b=AMD --newObjectFile --mergeSections --objectFileExtension=.Gof --symbolFileExtension=.SymG --preciseGC");
  505. DoAddPlatform("Win32","-b=AMD --newObjectFile --mergeSections --objectFileExtension=.GofW --symbolFileExtension=.SymW --preciseGC --trackLeave --cellsAreObjects --platformCC=WINAPI");
  506. DoAddPlatform("Win64","-b=AMD --bits=64 --newObjectFile --mergeSections --objectFileExtension=.GofWw --symbolFileExtension=.SymWw --preciseGC --trackLeave --cellsAreObjects --platformCC=WINAPI");
  507. DoAddPlatform("Win32C","-b=AMD --cooperative --newObjectFile --traceModule=Trace --objectFileExtension=.GofCW --symbolFileExtension=.SymCW --platformCC=WINAPI");
  508. DoAddPlatform("ARM","-b=ARM --newObjectFile --metaData=simple --objectFileExtension=.Goa --symbolFileExtension=.Sya");
  509. DoAddPlatform("Minos","-b=ARM --objectFile=Minos");
  510. DoAddPlatform("TRM","-b=TRM --objectFile=Generic --newObjectFile --metaData=simple --objectFileExtension=.GofT --symbolFileExtension=.SymT");
  511. DoAddPlatform("TRMI","-b=TRM --objectFile=Intermediate --newObjectFile --metaData=simple --objectFileExtension=.IroT --symbolFileExtension=.IrsT");
  512. DoAddPlatform("A2Coop","-b=AMD --cooperative --newObjectFile --traceModule=Trace --mergeSections");
  513. DoAddPlatform("ARMA2","-b=ARM --newObjectFile --mergeSections");
  514. DoAddPlatform("Linux32","-b=AMD --newObjectFile --mergeSections --traceModule=Trace --objectFileExtension=.GofU --symbolFileExtension=.SymU --preciseGC --cellsAreObjects --platformCC=C");
  515. DoAddPlatform("Linux64","-b=AMD --bits=64 --newObjectFile --mergeSections --traceModule=Trace --objectFileExtension=.GofUu --symbolFileExtension=.SymUu --preciseGC --cellsAreObjects --platformCC=C");
  516. SetupDefaults;
  517. END Compiler.