Lower.def 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. DEFINITION MODULE Lower;
  2. (* AST -> QBE walk for the two-phase frontend (docs/plan-lower.md).
  3. Test-only: after a normal parse has built the AST and emitted the
  4. legacy image, CanLower gates whether the unit is in the supported
  5. subset; LowerUnit then re-emits it into a fresh QbeGen state, writing
  6. gen_ssa/<mod>L.ssa for a byte-compare against the legacy 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 CanLower (unit: AST.Node): BOOLEAN;
  13. PROCEDURE LowerUnit (unit: AST.Node);
  14. PROCEDURE LowerSession (units: ARRAY OF AST.Node; n: CARDINAL;
  15. progName: ARRAY OF CHAR);
  16. PROCEDURE BeginSession (progName: ARRAY OF CHAR);
  17. PROCEDURE BeginUnit;
  18. PROCEDURE LowerUnitNow (unit: AST.Node; isProg: BOOLEAN);
  19. PROCEDURE EndSession;
  20. (* The expression/statement/declaration walkers are mutually recursive.
  21. gm2's link pass rejects FORWARD and V3 has no whole-module pass, so
  22. they are declared here (definition-visible throughout the
  23. implementation) instead of being forward-declared. *)
  24. PROCEDURE CanExpr (n: AST.Node): BOOLEAN;
  25. PROCEDURE CanDecls (seq: AST.Node): BOOLEAN;
  26. PROCEDURE CanProc (proc: AST.Node): BOOLEAN;
  27. PROCEDURE IsBuiltin (nm: ARRAY OF CHAR): BOOLEAN;
  28. PROCEDURE LowerExpr (n: AST.Node; VAR t: SymTab.TypeIndex;
  29. VAR q: QbeGen.QVal);
  30. PROCEDURE LowerStmt (seq: AST.Node);
  31. PROCEDURE LowerDecls (seq: AST.Node);
  32. PROCEDURE Reset;
  33. PROCEDURE NoteVar (name: ARRAY OF CHAR; kind: INTEGER; t: SymTab.TypeIndex);
  34. PROCEDURE NoteConstVal (val: ARRAY OF CHAR);
  35. PROCEDURE ScopeEnter;
  36. PROCEDURE ScopeLeave;
  37. PROCEDURE NoteProc (name: ARRAY OF CHAR; uid: CARDINAL;
  38. res: SymTab.TypeIndex; depth: CARDINAL; ext: BOOLEAN);
  39. PROCEDURE MarkProcExternal;
  40. PROCEDURE NoteProcNode (n: AST.Node);
  41. PROCEDURE SetProcRes (t: SymTab.TypeIndex);
  42. PROCEDURE NoteParam (name: ARRAY OF CHAR; t: SymTab.TypeIndex;
  43. isVar: BOOLEAN);
  44. END Lower.