## 3.4 Extending the compiler

The compiler supplies a couple of hooks to add user-level passes to the compilation process. Before compilation commences any Scheme source-files or compiled code specified using the `-extend` option are loaded and evaluated. The parameters `user-options-pass, user-read-pass, user-preprocessor-pass, user-pass, user-pass-2` and `user-post-analysis-pass` can be set to procedures that are called to perform certain compilation passes instead of the usual processing (for more information about parameters see: 6.7.

[parameter] user-options-pass
  Holds a procedure that will be called with a list of command-line arguments and should return two values: the source-filename and the actual list of options, where compiler switches have their leading `-` (hyphen) removed and are converted to symbols. Note that this parameter is invoked before processing of the `-extend` option, and so can only be changed in compiled user passes.

[parameter] user-read-pass
  Holds a procedure of three arguments. The first argument is a list of strings with the code passed to the compiler via `-prelude` options. The second argument is a list of source files including any files specified by `-prologue` and `-epilogue`. The third argument is a list of strings specified using `-postlude` options. The procedure should return a list of toplevel Scheme expressions.

[parameter] user-preprocessor-pass
  Holds a procedure of one argument. This procedure is applied to each toplevel expression in the source file before macro-expansion. The result is macro-expanded and compiled in place of the original expression.

[parameter] user-pass
  Holds a procedure of one argument. This procedure is applied to each toplevel expression after macro-expansion. The result of the procedure is then compiled in place of the original expression.

[parameter] user-pass-2
  Holds a procedure of two arguments, which is called with the canonicalized node-graph and the analysis database as arguments. The result is ignored, so this pass has to mutate the node-structure to cause any effect.

[parameter] user-post-analysis-pass
  Holds a procedure that will be called after the last performed program analysis. The procedure (when defined) will be called with three arguments: the program database, a getter and a setter-procedure which can be used to access and manipulate the program database, which holds various information about the compiled program. The getter procedure should be called with two arguments: a symbol representing the binding for which information should be retrieved, and a symbol that specifies the database-entry. The current value of the database entry will be returned or `#f`, if no such entry is available. The setter procedure is called with three arguments: the symbol and key and the new value.

  For information about the contents of the program database contact the author.

Loaded code (via the `-extend` option) has access to the library units `extras, srfi-1, srfi-4, script-utils, regex` and the pattern matching macros. The highlevel macro-system and multithreading is not available.

Note that the macroexpansion/canonicalization phase of the compiler adds certain forms to the source program. These extra expressions are not seen by `user-preprocessor-pass` but by `user-pass`.