Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • sac2c sac2c
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 394
    • Issues 394
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 19
    • Merge requests 19
  • Deployments
    • Deployments
    • Releases
  • Wiki
    • Wiki
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • sac-group
  • sac2csac2c
  • Wiki
  • Misc
  • phases

phases · Changes

Page history
Explain more about intresting phases to break in phases.md authored Apr 09, 2025 by Quinten Cabo's avatar Quinten Cabo
Hide whitespace changes
Inline Side-by-side
misc/phases.md
View page @ 0c154d58
An incomplete short summary of all the compiler phases & traversals. This file holds an incomplete short summary of all the compiler phases & traversals.
If you are reading a traversal you can come here and create or improve a summary of it to improve your and later others understanding of the traversal and the compiler as a whole. If you are reading a traversal you can come here and create or improve a summary of it to improve your and later others understanding of the traversal and the compiler as a whole.
For the full picture of each traversal see the corresponding file in the `src` directory. For the full picture of each traversal see the corresponding file in the `src` directory.
The sac compiler operates in many phases.
Each phase is a composition of traversals and there are many traversals.
It is best to work on a need to know basis with the traversals but it is good to have a rough idea of what each phase does.
# Breaking at interesting phases
You can stop at a certain phase by using the `-b` flag.
For instance `-b 1` will stop after the first phase.
It is a good idea to write a simple program and run the compiler increasing the number after the `-b` flag to see what each phase does.
It is also a good idea to run with `-noprelude` to remove the prelude from the output which is introduced in phase 4.
It is also a good idea to run with `-v 3` to see the names of each traversal in each phase.
Looking before opt (optimizations), currently 10 or ewl and after opt is always interesting.
After opt if you don't have with loops you can mostly skip to 16 or mem.
After `mem` the code starts to looks a lot less readable.
The code gen phase (22 or cg) is quite interesting if you do `-b cg` you will get nothing.
At the end of dm `-b dm` there are only assignments, primitive functions and do-while loops and conditions left.
(The do-while loops and conditions are reintroduced in ussa:f2l)
With `-b cg:cpl` is an crazy traversal of 10k loc which turns all the assignments and primitive functions into [intermediate code macros]() (CPL)
At this point the code is actually quite readable again because all the primitive functions applications and assignments are turned into macros.
# Phases
## 1: Loading SAC program ...
Locate and load the given SAC program source code.
Run the C preprocessor on the source code.
Lex and parse it into an ast.
## 2: Preprocessing type patterns ...
Run the type pattern preprocessor on the ast.
## 3: Preprocessing SAC program ...
## 4: Running module system ...
## 5: Simplifying source code ...
## 6: Converting to static single assignment form ...
## 7: Running type inference system ...
## 8: Processing exports ...
## 9: Preparing for code optimization ...
## 10: Enhancing with-loops ...
## 11: Running SAC optimizations ...
## 12: Automatic parallelisation for GPUs skipped.
## 13: Transforming with-loop representation ...
## 14: Running 3rd generation multithreading skipped.
## 15: Introducing task parallelization skipped.
## 16: Introducing memory management instructions ...
## 17: Introduce profiling instruction ...
## 18: Converting from static single assignment form ...
## 19: Running automatic parallelisation skipped.
## 20: Preparing C code generation ...
## 21: Distributed Memory skipped.
## 23: Generating Code ...
----
# Traversals
# Loading SAC program # Loading SAC program
In this phase the compiler loads the given SAC program. In this phase the compiler loads the given SAC program.
...@@ -191,3 +274,4 @@ To make sure the renaming is consistent with the previous 2 phases the same rena ...@@ -191,3 +274,4 @@ To make sure the renaming is consistent with the previous 2 phases the same rena
## Hiding struct definition behind typedefs and accessors (hs) ## Hiding struct definition behind typedefs and accessors (hs)
#
\ No newline at end of file
Clone repository
  • concepts
    • Deprecated Modules
    • Globals
    • Named Tuples
    • Overloading
    • Preprocessor
    • Primitive functions
    • Runetime Representations
    • input stdin
    • phm xt
    • ref counting methods
    • type famlies
    • type patterns
  • error messages
    • Anthropomorphic error essages
    • Colored error messages
    • Empty file error
View All Pages