Lower.def 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. DEFINITION MODULE Lower;
  2. (* AST -> QBE walk for the two-phase frontend (docs/plan-lower.md).
  3. The driver (compiler.frm) drives a per-unit re-emit through
  4. BeginSession/BeginUnit/LowerUnitNow/EndSession: the grammar's own
  5. inline emit runs suppressed, and Lower emits each unit's AST into the
  6. one session image.
  7. Symbol resolution is self-contained (zero SymTab surface): the grammar
  8. records each declaration's kind/type and each procedure's signature in
  9. the tables below while the scope is open, so the walk can resolve names
  10. after SymTab has popped their scopes. *)
  11. IMPORT AST, SymTab, QbeGen;
  12. PROCEDURE BeginSession (progName: ARRAY OF CHAR);
  13. PROCEDURE BeginUnit;
  14. PROCEDURE LowerUnitNow (unit: AST.Node; isProg: BOOLEAN);
  15. PROCEDURE EndSession;
  16. (* The expression/statement/declaration walkers are mutually recursive.
  17. gm2's link pass rejects FORWARD and V3 has no whole-module pass, so
  18. they are declared here (definition-visible throughout the
  19. implementation) instead of being forward-declared. *)
  20. PROCEDURE IsBuiltin (nm: ARRAY OF CHAR): BOOLEAN;
  21. PROCEDURE LowerExpr (n: AST.Node; VAR t: SymTab.TypeIndex;
  22. VAR q: QbeGen.QVal);
  23. PROCEDURE LowerStmt (seq: AST.Node);
  24. PROCEDURE LowerDecls (seq: AST.Node);
  25. PROCEDURE Reset;
  26. PROCEDURE NoteVar (name: ARRAY OF CHAR; kind: INTEGER; t: SymTab.TypeIndex);
  27. PROCEDURE NoteConstVal (val: ARRAY OF CHAR);
  28. PROCEDURE ScopeEnter;
  29. PROCEDURE ScopeLeave;
  30. (* Procedure-scope stack: Enter pushes the enclosing owner, Leave seals
  31. the top and pops. ReenterScopeProc resumes a noted entry for the
  32. re-parse pass without re-registering it. *)
  33. PROCEDURE ReenterScopeProc (ty: INTEGER);
  34. PROCEDURE NoteProc (name: ARRAY OF CHAR; uid: CARDINAL;
  35. res: SymTab.TypeIndex; depth: CARDINAL; ext: BOOLEAN);
  36. PROCEDURE MarkProcExternal;
  37. PROCEDURE NoteCProc (name: ARRAY OF CHAR);
  38. PROCEDURE NoteImportedProc (name: ARRAY OF CHAR);
  39. PROCEDURE NoteProcNode (n: AST.Node);
  40. PROCEDURE SetProcRes (t: SymTab.TypeIndex);
  41. PROCEDURE NoteParam (name: ARRAY OF CHAR; t: SymTab.TypeIndex;
  42. isVar: BOOLEAN);
  43. END Lower.