README 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. Overview
  2. ========
  3. There are three binaries in the toolchain:
  4. - The compiler "civcc", which compiles CiviC source code to assembly source
  5. - The assembler "civas", which compiles assembly source to an object file that
  6. can be run by the VM.
  7. - The virtual machine "civvm", which runs one or more object files, one of
  8. which should export a "main" function.
  9. Additionally, there is a run script "run.sh" which takes one file name argument
  10. and runs it through the entire pipeline, deleting intermediate files
  11. afterwards. E.g. for the first assignment you may want to run:
  12. $ bin/run.sh euclid.cvc
  13. <output of your main function>
  14. Reference compiler usage
  15. ========================
  16. You can use the output of the reference compiler "civcc" as benchmark for your
  17. own compiler. Apart from the extensions in the language reference, it
  18. implements constant propagation/folding on compiler-generated variables, and
  19. also does rudimentary loop unrolling. You are not expected to reproduce this,
  20. these phases are just there to show you how even simple optimizations can have
  21. a significant effect on code size.
  22. Some other remarks about the compiler:
  23. - Optimizations can be disabled with the -noopt flag.
  24. - By default it reads CiviC code from stdin, and prints assembly to stdout, so
  25. you can use it with unix pipes.
  26. - The "-v 2" verbosity option makes it print the AST after each phase, showing
  27. you step-by-step transformations. This can be very useful when you are
  28. confused about what a milestone should do. You can compile simple example
  29. file and see how the reference compiler transforms it in the different phase.
  30. Use -noopt as well if you want to get something closer to what your own
  31. compiler should do (since you don't need to implement optimizations).
  32. - the "-upto ..." argument makes the compiler stop after a certain phase and
  33. print the AST (or assembly) at that point. E.g. when you are implementing
  34. context analysis and want to compare your output to that of the refrence
  35. compiler, use "-upto context" or "-upto context -v 2".
  36. - The generated assembly code contains comments that shows to which CiviC code
  37. it corresponds. This can be used for relating instructions to AST nodes
  38. during debugging, and we recommend you do the same in your own compiler
  39. (although it is not required). Note that the last optimization phase
  40. (peephpole optimization) strips these comments, so you will need to pass "-v
  41. 2" or -noopt to actually see them. You can also disable them completely by
  42. passing "-v 0".