index.mli 1.1 KB

1234567891011121314151617181920
  1. (** Tag variable declarations with stack frame indices. *)
  2. (** The assembly phase needs to know indices of variables in the current stack
  3. frame to be pass to [load|store] instructions. This phase traverses the AST
  4. and adds [Index] annotations based on a counter that is increased when
  5. declaration is encountered.
  6. A problem, however, is that uses of these declarations do not inherit these
  7. annotations, since the declaration annotations are not references.
  8. Therefore, this phase first strips all context analysis by replacing
  9. variable/function uses with the original [Var|Assign|FunCall] nodes. Then,
  10. index analysis is performed on declarations. Finally, the
  11. {!Context.analyse_context} traversal is re-run to carry the [Index]
  12. annotations to the variable/function uses. Note that we can safely assume
  13. that no errors will occur during this context analysis, since incorrect uses
  14. would have been identified by the earlier context analysis already.
  15. *)
  16. (** Main phase function, called by {!Main}. *)
  17. val phase : Main.phase_func