CodeGen.def 866 B

12345678910111213141516171819202122232425262728
  1. DEFINITION MODULE CodeGen;
  2. (* Backend for SimpleMod2: pretty-prints the parsed program as a
  3. complete, ready-to-compile Modula-2 program module.
  4. OpenModule(name) creates "gen/<name>.mod" (directory "gen" must
  5. exist). Grammar actions then call Emit / Brk / Ind / Ded while
  6. parsing; Close finishes the file. Since the source language is a
  7. Modula-2 subset, re-emitted code compiles with e.g. gm2 -fiso. *)
  8. PROCEDURE OpenModule (name: ARRAY OF CHAR);
  9. (* Opens gen/<name>.mod for writing, resets indentation. *)
  10. PROCEDURE Close;
  11. (* Closes the output file (no-op if not open). *)
  12. PROCEDURE Emit (s: ARRAY OF CHAR);
  13. (* Writes raw text (keyword, identifier, literal, punctuation). *)
  14. PROCEDURE Brk;
  15. (* Newline + current indentation. *)
  16. PROCEDURE Ind;
  17. (* Indentation level + 1. *)
  18. PROCEDURE Ded;
  19. (* Indentation level - 1 (floored at 0). *)
  20. END CodeGen.