2 * Author: Frank Pfenning <fp@cs.cmu.edu>
5 -----------------------------------------------------------------------
7 -----------------------------------------------------------------------
9 This is some starter code for the L1 compiler you have to build for
10 the Lab1. It contains a lexer, parser, translator, and even a code
11 generator, except that the code generator creates pseudo assembly
12 language with fictitious instructions and an unlimited number of
13 registers. We took some care to use good style (according to the
14 instructor); you may consider this a model for your own coding. Feel
15 free to modify any and all of this code as you see fit.
17 Bug reports to the instructor Frank Pfenning <fp@cs.cmu.edu> are
18 particularly welcome and will be noted in the extra credit category.
20 -----------------------------------------------------------------------
22 -----------------------------------------------------------------------
23 There are many different compilers for SML, perhaps the most
26 SML/NJ -- http://www.smlnj.org/
27 MLton -- http://www.mlton.org/
28 Poly/ML -- http://www.polyml.org/
30 In this class we will be using SML/NJ v110.59. Please make sure your
31 code compiles under specifically this version on the lab machines
32 where it is the default and can be invoked simply with "sml" in a
35 If you develop your implementation on other machines, similar versions
36 of SML/NJ are likely to be compatible, but you should certainly check
37 your code on the lab machines.
39 For (almost universal) Standard Basis Libraries, see
40 http://www.standardml.org/Basis/index.html. Further resources, such
41 as documentation for ML-Lex and ML-Yacc, and documentation for the SML/NJ
42 specific libraries which are used in the starter code, can be found at
44 http://www.cs.cmu.edu/~fp/courses/15411-f08/resources.html
46 ------------------------------------------------------------------------
48 ------------------------------------------------------------------------
49 The following are the source files for the L1 compiler
53 Makefile -- makefile for the compiler
56 % make l1c (generates file bin/l1c.heap.<os-tag>)
57 % bin/l1c --verbose ../tests/test1.c
59 should generate ../tests/test1.s in pseudo assembly
61 % make clean (removes generated files)
62 % make TAGS (creates file TAGS, for Emacs tags commands)
64 compile-l1c.sml -- SML commands that will create bin/l1c.heap.<os-tag>
65 bin/l1c -- the script that will run the exported SML heap
67 sources.cm -- lists all source files, including libraries,
68 and lexer and grammar specifications
72 - CM.make "sources.cm";
73 - Top.test "--verbose ../tests/test1.c";
75 should generate ../tests/test1.s in pseudo assembly
77 parse/ast.sml -- definition and printer for abstract syntax trees (AST's)
78 parse/l1.lex -- L1 lexer
79 parse/l1.grm -- L1 grammar
80 parse/parse.sml -- L1 parser
81 parse/parsestate.sml -- L1 parser support for error messages
83 type/typechecker.sml -- (trivial) type-checker for AST
85 trans/temp.sml -- functions to generate and track temp's
86 trans/tree.sml -- definition and pretty printer for IR trees
87 trans/trans.sml -- translation from AST to IR trees
89 codegen/assem.sml -- pseudo assembly format for this starter code
90 codegen/codegen.sml -- pseudo code generator
92 util/errormsg.sml -- error message utilities
93 util/flag.sml -- library for defining flags
94 util/mark.sml -- library for tracking source file positions
95 util/safe-io.sml -- I/O utilities
96 util/symbol.sml -- symbol table library
97 util/word32.sml -- machine word utilities for two's complement interpretation
99 top/top.sml -- top level function for export to binary and testing
101 ------------------------------------------------------------------------
103 ------------------------------------------------------------------------
106 - Top.test "--verbose --dump-ast --dump-ir --dump-assem file.l1";
108 to print information from all the phases of the current compiler.
110 If you want to see the internal representations, you can call directly
113 - val ast = Parse.parse "file.l1";
114 - val ir = Trans.translate ast;
115 - val assem = Codegen.codgen ir;
117 This will use SML's internal printing function to print the data
118 structures. However, not everything will show.
120 "-" means that the type is opaque. Sometimes you can replace an opaque
121 signature ascription ":>" with a transparent one ":" to see the info.
122 For reasons of general hygiene, however, you should change it back
125 "#" means that the printing depth is exceeded. Use
127 - Control.Print.printDepth := 100;
129 to increase the depth if you need to see more.
131 "..." means that the printing length is exceeded. Use
133 - Control.Print.printLength := 1000;
135 to increase the length if you need to see more.
137 ------------------------------------------------------------------------
139 ------------------------------------------------------------------------
140 See util/symbol.sml for some uses of libraries provided with SML/NJ
141 (and some other SML implementations). BinaryMapFn and
142 BinarySetFn are likely of general use. To see their interface,
143 you can check http://www.smlnj.org/doc/smlnj-lib/Manual/toc.html.
144 I found binary maps and binary sets to be occasionally helpful.