Lower.def 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 SetLegacyOpen1D;
  14. (* Bootstrap compatibility: use legacy {count,data} 1-D open ABI. *)
  15. PROCEDURE SetSeparate (b: BOOLEAN);
  16. (* M2 -c: bodyless modules emit an empty <module>_init for cross-object
  17. init calls. *)
  18. PROCEDURE SetDefUnit (b: BOOLEAN);
  19. (* Lowering the target's own .def just to emit exported data; do not
  20. emit a second init. *)
  21. PROCEDURE BeginUnit;
  22. PROCEDURE LowerUnitNow (unit: AST.Node; isProg: BOOLEAN);
  23. PROCEDURE EndSession;
  24. (* The expression/statement/declaration walkers are mutually recursive.
  25. gm2's link pass rejects FORWARD and V3 has no whole-module pass, so
  26. they are declared here (definition-visible throughout the
  27. implementation) instead of being forward-declared. *)
  28. PROCEDURE IsBuiltin (nm: ARRAY OF CHAR): BOOLEAN;
  29. PROCEDURE LowerExpr (n: AST.Node; VAR t: SymTab.TypeIndex;
  30. VAR q: QbeGen.QVal);
  31. PROCEDURE LowerStmt (seq: AST.Node);
  32. PROCEDURE LowerDecls (seq: AST.Node);
  33. PROCEDURE Reset;
  34. PROCEDURE NoteVar (name: ARRAY OF CHAR; kind: INTEGER; t: SymTab.TypeIndex);
  35. PROCEDURE NoteConstVal (val: ARRAY OF CHAR);
  36. PROCEDURE NoteSetMask (name: ARRAY OF CHAR; mask: ARRAY OF CARDINAL;
  37. words: CARDINAL; lo: INTEGER);
  38. (* Records a SET CONST's mask (bit i is value lo+i). *)
  39. PROCEDURE SetConstMaskOf (n: AST.Node; VAR mask: ARRAY OF CARDINAL;
  40. VAR words: CARDINAL; VAR lo: INTEGER): BOOLEAN;
  41. (* TRUE when n is a compile-time set constant; mask gets its bits
  42. (relative to lo) and words its 32-bit width. The grammar calls this
  43. for a SET CONST declaration, then NoteSetMask on success. *)
  44. PROCEDURE ScopeEnter;
  45. PROCEDURE ScopeLeave;
  46. (* Procedure-scope stack: Enter pushes the enclosing owner, Leave seals
  47. the top and pops. ReenterScopeProc resumes a noted entry for the
  48. re-parse pass without re-registering it. *)
  49. PROCEDURE ReenterScopeProc (ty: INTEGER);
  50. PROCEDURE CurScopeProc (): INTEGER;
  51. (* The proc entry NoteProc most recently made current. *)
  52. PROCEDURE NoteProc (name: ARRAY OF CHAR; uid: CARDINAL;
  53. res: SymTab.TypeIndex; depth: CARDINAL; ext: BOOLEAN);
  54. PROCEDURE AliasProc (name: ARRAY OF CHAR; uid: CARDINAL;
  55. res: SymTab.TypeIndex; depth: CARDINAL; ext: BOOLEAN);
  56. (* Bind a generic procedure formal to an actual (proc-table alias). *)
  57. PROCEDURE MarkProcExternal;
  58. PROCEDURE NoteCProc (name: ARRAY OF CHAR);
  59. PROCEDURE NoteImportedProc (name: ARRAY OF CHAR);
  60. PROCEDURE NoteProcNode (n: AST.Node);
  61. PROCEDURE SetProcRes (t: SymTab.TypeIndex);
  62. PROCEDURE NoteParam (name: ARRAY OF CHAR; t: SymTab.TypeIndex;
  63. isVar: BOOLEAN);
  64. END Lower.