FoxCompiler.Mod 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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. ActiveCells := FoxActiveCells, Hardware := FoxHardware, Frontend := FoxFrontend,
  8. Files;
  9. CONST
  10. (* flags *)
  11. Print* = 0;
  12. Silent* = 1;
  13. Check* = 2;
  14. TraceError* = 3;
  15. Info* = 4;
  16. FindPC* = 5;
  17. ActiveCellsFlag*=6;
  18. Warnings*=7;
  19. ForceModuleBodies*=8;
  20. UseDarwinCCalls*=9; (* use Darwin stack alignment for ext. C procedures *) (*fld*)
  21. SingleModule*=10;
  22. Oberon07*=11;
  23. ChangeCase*=12;
  24. Cooperative*=13;
  25. CellsAreObjects*=14;
  26. DefaultBackend = "AMD";
  27. DefaultFrontend = "Oberon";
  28. TYPE
  29. SectionName = ARRAY 256 OF CHAR; (*! move *)
  30. CompilerOptions*= RECORD
  31. flags*: SET;
  32. frontend*: Frontend.Frontend;
  33. backend*: Backend.Backend;
  34. symbolFile*: Formats.SymbolFileFormat;
  35. objectFile*: Formats.ObjectFileFormat;
  36. hardware*: Hardware.Description;
  37. findPC*: SectionName;
  38. documentation*: Backend.Backend;
  39. activeCellsBackend, activeCellsAssembler: Backend.Backend;
  40. srcPath, destPath: Files.FileName;
  41. replacements: SemanticChecker.Replacement;
  42. END;
  43. PROCEDURE ParseReplacements(CONST filename: ARRAY OF CHAR; VAR replacement: SemanticChecker.Replacement; diagnostics: Diagnostics.Diagnostics): BOOLEAN;
  44. VAR reader: Streams.Reader; r: SemanticChecker.Replacement;
  45. identifier: SyntaxTree.QualifiedIdentifier;
  46. scanner: Scanner.Scanner; parser: Parser.Parser; expression: SyntaxTree.Expression;
  47. BEGIN
  48. replacement := NIL;
  49. reader := Basic.GetFileReader(filename);
  50. IF reader = NIL THEN
  51. diagnostics.Error (filename, Diagnostics.Invalid, Diagnostics.Invalid, "failed to open");
  52. ELSE
  53. NEW(scanner, filename, reader,0, diagnostics);
  54. NEW(parser, scanner, diagnostics);
  55. REPEAT (* WHILE parser.Peek(Scanner.Identifier) DO*)
  56. identifier := parser.QualifiedIdentifier();
  57. IF parser.Mandatory(Scanner.Equal) THEN
  58. expression := parser.Expression();
  59. NEW(r); identifier.GetName(r.name); r.expression := expression; r.used := FALSE;
  60. r.next := replacement; replacement := r;
  61. END;
  62. WHILE parser.Optional(Scanner.Semicolon) DO END;
  63. UNTIL ~parser.Peek(Scanner.Identifier); (*END;*)
  64. END;
  65. (*done := FALSE;
  66. WHILE reader.GetString(name) & ~done DO
  67. IF reader.GetChar(equal) & (equal = "=") & reader.GetString(value) THEN
  68. NEW(r); r.name := name; r.string := Strings.NewString(value); r.used := FALSE;
  69. r.next := replacement; replacement := r;
  70. ELSE done := TRUE;
  71. END;
  72. END;
  73. *)
  74. RETURN (replacement # NIL)
  75. END ParseReplacements;
  76. PROCEDURE Modules*(CONST source: ARRAY OF CHAR; (* source file name, for debugging and better error reports *)
  77. reader: Streams.Reader; (* reader to read from *)
  78. position: LONGINT; (* starting position in reader *)
  79. diagnostics: Diagnostics.Diagnostics; (* error output and status report *)
  80. log: Streams.Writer;
  81. CONST options: CompilerOptions;
  82. VAR importCache: SyntaxTree.ModuleScope): BOOLEAN;
  83. VAR
  84. module: SyntaxTree.Module;
  85. checker: SemanticChecker.Checker;
  86. warnings: SemanticChecker.Warnings;
  87. printer: Printout.Printer;
  88. system: Global.System;
  89. generatedModule: Formats.GeneratedModule;
  90. name: SyntaxTree.IdentifierString;
  91. split: Strings.StringArray;
  92. sectionOffset: LONGINT;
  93. activeCellsSpecification: ActiveCells.Specification;
  94. flags: SET;
  95. PROCEDURE FinalMessage(error: BOOLEAN; CONST msg: ARRAY OF CHAR);
  96. VAR message,name: ARRAY 256 OF CHAR;
  97. BEGIN
  98. message := "";
  99. IF (module # NIL) & (module.context # SyntaxTree.invalidIdentifier) THEN
  100. Basic.GetString(module.context,message);
  101. Strings.Append (message, ".");
  102. ELSE
  103. message := "";
  104. END;
  105. IF (module # NIL) & (module.name # SyntaxTree.invalidIdentifier) THEN
  106. Basic.GetString(module.name,name);
  107. Strings.Append (message, name);
  108. END;
  109. Strings.Append (message, msg);
  110. IF error THEN
  111. IF diagnostics # NIL THEN
  112. diagnostics.Error (source, Diagnostics.Invalid, Diagnostics.Invalid, message);
  113. END;
  114. ELSE
  115. IF (log # NIL) & ~(Silent IN options.flags) & ~(FindPC IN options.flags) THEN
  116. log.String("compiling ");
  117. IF source # "" THEN log.String(source); log.String(" => "); END;
  118. log.String(message); log.Ln;
  119. END;
  120. END;
  121. END FinalMessage;
  122. PROCEDURE PrintModule;
  123. VAR print: Streams.Writer;
  124. BEGIN
  125. print := Basic.GetWriter(Basic.GetDebugWriter("Compiler Debug Output"));
  126. IF Info IN options.flags THEN
  127. printer := Printout.NewPrinter(print,Printout.All,Info IN options.flags);
  128. ELSE
  129. printer := Printout.NewPrinter(print,Printout.SourceCode,Info IN options.flags);
  130. END;
  131. print.Ln; printer.Module(module); print.Ln;
  132. print.Update;
  133. END PrintModule;
  134. BEGIN
  135. flags := options.flags;
  136. IF options.findPC # "" THEN EXCL(flags, Warnings) END;
  137. IF TraceError IN options.flags THEN
  138. diagnostics := Basic.GetTracingDiagnostics(diagnostics)
  139. END;
  140. IF options.backend = NIL THEN
  141. system := Global.DefaultSystem()
  142. ELSE
  143. 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 *)
  144. system := options.backend.GetSystem();
  145. END;
  146. system.SetCellsAreObjects(CellsAreObjects IN flags);
  147. IF (options.objectFile # NIL) & (options.objectFile.ForceModuleBodies()) THEN INCL(flags, ForceModuleBodies) END;
  148. IF (ActiveCellsFlag IN flags) & ~(CellsAreObjects IN flags) THEN
  149. NEW(activeCellsSpecification, "", diagnostics, log);
  150. IF (system # NIL) THEN
  151. activeCellsSpecification.DefineDevices(system);
  152. Global.OperatorDefined(system, Scanner.Questionmarks, TRUE);
  153. END;
  154. IF options.activeCellsBackend = NIL THEN FinalMessage(TRUE,"could not install activeCells backend"); RETURN FALSE END;
  155. END;
  156. options.frontend.Initialize(diagnostics, reader, source, position, ActiveCellsFlag IN flags);
  157. REPEAT
  158. (** first phase: scan and parse **)
  159. module := options.frontend.Parse();
  160. IF options.frontend.Error() THEN
  161. FinalMessage(TRUE," could not be compiled (parser errors).");
  162. RETURN FALSE;
  163. END;
  164. ASSERT(module # NIL);
  165. IF Check IN flags THEN
  166. (** second phase: check and resolve symbols **)
  167. IF (options.symbolFile # NIL) THEN
  168. options.symbolFile.Initialize(diagnostics,system,options.destPath);
  169. END;
  170. checker := SemanticChecker.NewChecker(diagnostics,Info IN flags,UseDarwinCCalls IN flags,Cooperative IN flags,system,options.symbolFile,activeCellsSpecification,importCache);
  171. checker.replacements := options.replacements;
  172. checker.Module(module);
  173. IF checker.error THEN
  174. FinalMessage(TRUE," could not be compiled (checker errors).");
  175. RETURN FALSE
  176. ELSIF Warnings IN flags THEN
  177. warnings := SemanticChecker.NewWarnings(diagnostics);
  178. warnings.Module(module);
  179. END;
  180. IF Print IN flags THEN
  181. IF ChangeCase IN flags THEN module.SetCase(1-module.case) END;
  182. PrintModule;
  183. IF ChangeCase IN flags THEN module.SetCase(1-module.case) END;
  184. END;
  185. IF (ActiveCellsFlag IN flags) & ~(CellsAreObjects IN flags) THEN
  186. Global.GetSymbolName(module,name);
  187. activeCellsSpecification.Init(name,diagnostics,log)
  188. END;
  189. (** third phase: generate code, can consist of sub-phases (such as intermediate backend / hardware backend) **)
  190. IF options.backend # NIL THEN
  191. options.backend.Initialize(diagnostics, log, flags, checker, system, activeCellsSpecification);
  192. IF options.findPC # "" THEN
  193. split := Strings.Split(options.findPC,":");
  194. IF LEN(split)>1 THEN
  195. Strings.StrToInt(split[1]^,sectionOffset);
  196. options.backend.FindPC(module, split[0]^,sectionOffset);
  197. IF options.backend.error THEN
  198. FinalMessage(TRUE," could not be compiled (backend errors).");
  199. RETURN FALSE
  200. ELSE
  201. RETURN TRUE
  202. END;
  203. END;
  204. END;
  205. generatedModule := options.backend.ProcessSyntaxTreeModule(module);
  206. IF options.backend.error THEN
  207. FinalMessage(TRUE, " could not be compiled (backend errors).");
  208. RETURN FALSE
  209. END;
  210. END;
  211. (** generate symbol file **)
  212. IF (options.symbolFile # NIL) & ~options.symbolFile.Export(module, importCache) THEN
  213. FinalMessage(TRUE, " could not be compiled (symbol File errors).");
  214. RETURN FALSE
  215. END;
  216. (** generate object file **)
  217. IF options.objectFile # NIL THEN
  218. options.objectFile.Initialize(diagnostics, options.destPath);
  219. IF options.findPC # "" THEN
  220. Strings.StrToInt(options.findPC, sectionOffset);
  221. generatedModule.SetFindPC(sectionOffset);
  222. END;
  223. IF generatedModule = NIL THEN
  224. FinalMessage(TRUE, " could not write object file (nothing generated).");
  225. RETURN FALSE
  226. ELSIF ~options.objectFile.Export(generatedModule,options.symbolFile) THEN
  227. FinalMessage(TRUE, " could not be compiled (object file errors).");
  228. RETURN FALSE
  229. END;
  230. END;
  231. IF activeCellsSpecification # NIL THEN
  232. options.activeCellsBackend.Initialize(diagnostics,log, flags,checker,system,activeCellsSpecification);
  233. generatedModule := options.activeCellsBackend.ProcessSyntaxTreeModule(module);
  234. IF options.activeCellsBackend.error THEN
  235. FinalMessage(TRUE, " could not be compiled (activeCells backend errors)");
  236. RETURN FALSE
  237. END;
  238. END;
  239. IF activeCellsSpecification = NIL THEN (* no activeCells *)
  240. ELSIF (activeCellsSpecification.types.Length() = 0) & (activeCellsSpecification.instances.Length()=0) THEN (* nothing defined *)
  241. ELSE
  242. IF options.activeCellsAssembler= NIL THEN FinalMessage(TRUE,"could not install activeCells assembler"); RETURN FALSE END;
  243. options.activeCellsAssembler.Initialize(diagnostics, log, flags, checker, system, activeCellsSpecification);
  244. IF options.hardware # NIL THEN options.hardware.Init(diagnostics, log) END;
  245. IF ~options.activeCellsAssembler.Emit(options.backend) THEN
  246. (*activeCellsSpecification.Link(diagnostics,system.codeUnit, system.dataUnit) *)
  247. FinalMessage(TRUE, " could not assemble"); RETURN FALSE
  248. ELSIF ~activeCellsSpecification.Emit() THEN
  249. FinalMessage(TRUE, " could not emit backend specification"); RETURN FALSE;
  250. ELSIF (options.hardware # NIL) & ~options.hardware.Emit(activeCellsSpecification) THEN
  251. FinalMessage(TRUE, " could not emit hardware"); RETURN FALSE;
  252. END;
  253. END;
  254. IF options.documentation # NIL THEN
  255. options.documentation.Initialize(diagnostics,log, flags,checker,system,activeCellsSpecification);
  256. generatedModule := options.documentation.ProcessSyntaxTreeModule(module);
  257. END;
  258. FinalMessage(FALSE, " done.");
  259. ELSIF Print IN flags THEN
  260. IF ChangeCase IN flags THEN module.SetCase(1-module.case) END;
  261. PrintModule;
  262. FinalMessage(FALSE, " done.")
  263. ELSE
  264. FinalMessage(FALSE, " done.");
  265. END;
  266. UNTIL (SingleModule IN flags) OR options.frontend.Done();
  267. RETURN TRUE;
  268. END Modules;
  269. PROCEDURE GetOptions*(input: Streams.Reader; error:Streams.Writer; diagnostics: Diagnostics.Diagnostics;
  270. VAR compilerOptions: CompilerOptions): BOOLEAN;
  271. VAR options: Options.Options; name: ARRAY 256 OF CHAR; result: BOOLEAN; position: LONGINT;
  272. parsed: BOOLEAN;
  273. PROCEDURE Error(CONST error: ARRAY OF CHAR);
  274. BEGIN
  275. IF diagnostics # NIL THEN
  276. diagnostics.Error("",Diagnostics.Invalid,Diagnostics.Invalid,error);
  277. END;
  278. END Error;
  279. BEGIN
  280. result := TRUE;
  281. NEW(options);
  282. options.Add("p","print",Options.Flag);
  283. options.Add("P","Print",Options.Flag);
  284. options.Add(0X,"silent",Options.Flag);
  285. options.Add("c","check",Options.Flag);
  286. options.Add("e","traceError",Options.Flag);
  287. options.Add("I","interface",Options.Flag);
  288. options.Add("i","info",Options.Flag);
  289. options.Add(0X,"oberon07",Options.Flag);
  290. options.Add("b","backend",Options.String);
  291. options.Add("F","frontEnd",Options.String);
  292. options.Add("f","findPC",Options.String);
  293. options.Add(0X,"singleModule",Options.Flag);
  294. options.Add(0X, "symbolFile", Options.String);
  295. options.Add(0X, "objectFile", Options.String);
  296. options.Add(0X,"activeCells", Options.Flag);
  297. options.Add("w","warnings", Options.Flag);
  298. options.Add(0X,"darwinHost", Options.Flag);
  299. options.Add(0X,"hardware", Options.String);
  300. options.Add("d","documentation", Options.String);
  301. options.Add("S","srcPath", Options.String);
  302. options.Add("D","destPath", Options.String);
  303. options.Add(0X,"replacements", Options.String);
  304. options.Add(0X,"cooperative", Options.Flag);
  305. position := input.Pos();
  306. parsed := options.Parse(input,NIL);
  307. IF options.GetString("b", name) THEN
  308. IF name = "" THEN compilerOptions.backend := NIL
  309. ELSE
  310. compilerOptions.backend := Backend.GetBackendByName(name);
  311. IF (compilerOptions.backend = NIL) THEN
  312. Error("backend could not be installed"); result := FALSE;
  313. END;
  314. END;
  315. ELSE compilerOptions.backend := Backend.GetBackendByName(DefaultBackend);
  316. IF compilerOptions.backend = NIL THEN Error("default backend could not be installed"); result := FALSE END;
  317. END;
  318. IF options.GetString("F", name) THEN
  319. IF name = "" THEN compilerOptions.frontend := NIL
  320. ELSE
  321. compilerOptions.frontend := Frontend.GetFrontendByName(name);
  322. IF (compilerOptions.frontend = NIL) THEN
  323. Error("backend could not be installed"); result := FALSE;
  324. END;
  325. END;
  326. ELSE compilerOptions.frontend := Frontend.GetFrontendByName(DefaultFrontend);
  327. IF compilerOptions.frontend = NIL THEN Error("default frontend could not be installed"); result := FALSE END;
  328. END;
  329. IF options.GetString("objectFile",name) THEN
  330. IF name = "" THEN compilerOptions.objectFile := NIL
  331. ELSE
  332. compilerOptions.objectFile := Formats.GetObjectFileFormat(name);
  333. IF compilerOptions.objectFile = NIL THEN Error("object file format could not be installed"); result := FALSE END;
  334. END;
  335. ELSIF compilerOptions.backend # NIL THEN
  336. compilerOptions.objectFile := compilerOptions.backend.DefaultObjectFileFormat();
  337. END;
  338. IF options.GetString("symbolFile",name) THEN
  339. IF name = "" THEN compilerOptions.symbolFile := NIL
  340. ELSE
  341. compilerOptions.symbolFile := Formats.GetSymbolFileFormat(name);
  342. IF compilerOptions.symbolFile = NIL THEN Error("symbol file format could not be installed"); result := FALSE END;
  343. END;
  344. ELSIF compilerOptions.backend # NIL THEN
  345. compilerOptions.symbolFile := compilerOptions.backend.DefaultSymbolFileFormat();
  346. IF (compilerOptions.symbolFile = NIL) & (compilerOptions.objectFile # NIL) THEN
  347. compilerOptions.symbolFile := compilerOptions.objectFile.DefaultSymbolFileFormat();
  348. END;
  349. ELSIF compilerOptions.objectFile # NIL THEN
  350. compilerOptions.symbolFile := compilerOptions.objectFile.DefaultSymbolFileFormat();
  351. END;
  352. IF options.GetString("hardware",name) THEN
  353. compilerOptions.hardware := Hardware.GetDescription(name);
  354. IF compilerOptions.hardware = NIL THEN
  355. Error("hardware description could not be installed"); result := FALSE;
  356. END;
  357. END;
  358. IF options.GetString("d", name) THEN
  359. compilerOptions.documentation := Backend.GetBackendByName("Documentation");
  360. IF (compilerOptions.documentation = NIL) THEN
  361. Error("documentation engine could not be installed"); result := FALSE;
  362. END;
  363. ELSE
  364. compilerOptions.documentation := NIL
  365. END;
  366. IF options.GetFlag("activeCells") THEN
  367. compilerOptions.activeCellsBackend := Backend.GetBackendByName("FoxActiveCellsBackend");
  368. compilerOptions.activeCellsAssembler := Backend.GetBackendByName("FoxIntermediateLinker");
  369. END;
  370. IF options.GetString("replacements", name) THEN
  371. IF ~ParseReplacements(name, compilerOptions.replacements, diagnostics) THEN
  372. Error("replacement file could not be opened or is empty"); result := FALSE;
  373. END;
  374. ELSE compilerOptions.replacements := NIL
  375. END;
  376. IF compilerOptions.backend # NIL THEN compilerOptions.backend.DefineOptions (options); INCL(compilerOptions.flags,Check); END;
  377. IF compilerOptions.symbolFile # NIL THEN compilerOptions.symbolFile.DefineOptions(options); INCL(compilerOptions.flags,Check) END;
  378. IF compilerOptions.objectFile # NIL THEN compilerOptions.objectFile.DefineOptions(options); INCL(compilerOptions.flags,Check) END;
  379. IF compilerOptions.documentation # NIL THEN compilerOptions.documentation.DefineOptions(options) END;
  380. IF compilerOptions.activeCellsBackend # NIL THEN compilerOptions.activeCellsBackend.DefineOptions(options) END;
  381. IF compilerOptions.activeCellsAssembler # NIL THEN compilerOptions.activeCellsAssembler.DefineOptions(options) END;
  382. IF result & ~parsed THEN
  383. options.Clear;
  384. input.SetPos(position);
  385. result := options.Parse(input,error)
  386. END;
  387. IF result THEN
  388. IF options.GetFlag("print") THEN INCL(compilerOptions.flags, Print) END;
  389. IF options.GetFlag("Print") THEN INCL(compilerOptions.flags, Print); INCL(compilerOptions.flags, ChangeCase) END;
  390. IF options.GetFlag("silent") THEN INCL(compilerOptions.flags, Silent) END;
  391. IF options.GetFlag("check") THEN INCL(compilerOptions.flags, Check) END;
  392. IF options.GetFlag("traceError") THEN INCL(compilerOptions.flags, TraceError) END;
  393. IF options.GetFlag("info") THEN INCL(compilerOptions.flags,Info) END;
  394. IF options.GetString("findPC",compilerOptions.findPC) THEN INCL(compilerOptions.flags,FindPC) END;
  395. IF options.GetFlag("warnings") THEN INCL(compilerOptions.flags, Warnings) END;
  396. IF options.GetFlag("darwinHost") THEN INCL(compilerOptions.flags,UseDarwinCCalls) END; (*fld*)
  397. IF options.GetFlag("singleModule") THEN INCL(compilerOptions.flags,SingleModule) END;
  398. IF options.GetFlag("oberon07") THEN INCL(compilerOptions.flags, Oberon07) END;
  399. IF options.GetFlag("activeCells") THEN INCL(compilerOptions.flags, ActiveCellsFlag) END;
  400. IF options.GetFlag("cooperative") THEN INCL(compilerOptions.flags, Cooperative) END;
  401. IF options.GetFlag("cellsAreObjects") THEN INCL(compilerOptions.flags, CellsAreObjects) END;
  402. IF ~options.GetString("srcPath", compilerOptions.srcPath) THEN compilerOptions.srcPath := "" END;
  403. IF ~options.GetString("destPath", compilerOptions.destPath) THEN compilerOptions.destPath := "" END;
  404. IF compilerOptions.backend # NIL THEN compilerOptions.backend.GetOptions (options) END;
  405. IF compilerOptions.symbolFile # NIL THEN compilerOptions.symbolFile.GetOptions(options) END;
  406. IF compilerOptions.objectFile # NIL THEN compilerOptions.objectFile.GetOptions(options) END;
  407. IF compilerOptions.documentation # NIL THEN compilerOptions.documentation.GetOptions(options) END;
  408. IF compilerOptions.activeCellsBackend # NIL THEN compilerOptions.activeCellsBackend.GetOptions(options) END;
  409. IF compilerOptions.activeCellsAssembler # NIL THEN compilerOptions.activeCellsAssembler.GetOptions(options) END;
  410. END;
  411. RETURN result
  412. END GetOptions;
  413. PROCEDURE Compile*(context : Commands.Context);
  414. VAR
  415. filename, path, file: Files.FileName;
  416. error: BOOLEAN;
  417. diagnostics: Diagnostics.Diagnostics;
  418. time: LONGINT; reader: Streams.Reader;
  419. importCache: SyntaxTree.ModuleScope;
  420. options: CompilerOptions;
  421. replacement: SemanticChecker.Replacement;
  422. name: ARRAY 128 OF CHAR;
  423. BEGIN
  424. error := FALSE;
  425. diagnostics := Basic.GetDiagnostics(context.error);
  426. IF GetOptions(context.arg,context.error,diagnostics,options) THEN
  427. time := Kernel.GetTicks();
  428. WHILE Basic.GetStringParameter(context.arg,filename) & ~error DO
  429. IF options.srcPath # "" THEN
  430. Files.SplitPath(filename, path, file);
  431. IF path = "" THEN Files.JoinPath(options.srcPath, file, filename) END;
  432. END;
  433. reader := Basic.GetFileReader(filename);
  434. IF reader = NIL THEN
  435. diagnostics.Error (filename, Diagnostics.Invalid, Diagnostics.Invalid, "failed to open"); error := TRUE;
  436. ELSE
  437. error := ~Modules(filename, reader, 0, diagnostics,context.out, options, importCache);
  438. END;
  439. context.out.Update;
  440. context.error.Update;
  441. END;
  442. IF Silent IN options.flags THEN
  443. time := Kernel.GetTicks()-time;
  444. context.out.Ln; context.out.String("compiler elapsed ms"); context.out.Int(time,10);
  445. END;
  446. IF ~error THEN
  447. replacement := options.replacements;
  448. WHILE replacement # NIL DO
  449. IF ~replacement.used THEN
  450. name := replacement.name;
  451. diagnostics.Warning(name, Diagnostics.Invalid, Diagnostics.Invalid, " unused replacement.");
  452. END;
  453. replacement := replacement.next;
  454. END;
  455. END;
  456. END;
  457. IF error THEN context.result := -1 ELSE context.result := Commands.Ok END;
  458. END Compile;
  459. PROCEDURE CompileReader*(context: Commands.Context; reader: Streams.Reader);
  460. VAR
  461. filename: ARRAY 256 OF CHAR;
  462. error: BOOLEAN;
  463. diagnostics: Diagnostics.Diagnostics;
  464. importCache: SyntaxTree.ModuleScope;
  465. options: CompilerOptions;
  466. BEGIN
  467. error := FALSE;
  468. diagnostics := Basic.GetDiagnostics(context.error);
  469. IF GetOptions(context.arg,context.error,diagnostics,options) THEN
  470. IF reader = NIL THEN
  471. diagnostics.Error (filename, Diagnostics.Invalid, Diagnostics.Invalid, "failed to open"); error := TRUE;
  472. ELSE
  473. error := ~Modules(filename, reader, 0, diagnostics, context.out, options, importCache);
  474. END;
  475. context.out.Update;
  476. END;
  477. END CompileReader;
  478. END Compiler.