Mercurial > projects > dang
annotate dang/compiler.d @ 100:5f258eaf9517 new_gen
Loading modules in. Just need to add them to the scope of the "main" Module now.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 06 May 2008 22:49:43 +0200 |
parents | 198ad05f3ace |
children | fea8d61a2451 |
rev | line source |
---|---|
1 | 1 module dang.compiler; |
2 | |
3 import tango.io.Stdout, | |
4 tango.core.Signal, | |
91
1a24e61eb104
Fixed the SourceLocation/SourceManager for files stretching by more then one CheckPoints
johnsen@johnsen-laptop
parents:
90
diff
changeset
|
5 tango.core.Memory, |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
6 tango.sys.Process, |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
7 tango.time.StopWatch, |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
8 tango.io.FileConduit, |
1 | 9 tango.io.FilePath; |
10 | |
11 import lexer.Lexer, | |
12 parser.Parser; | |
13 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
14 import basic.SourceManager; |
1 | 15 |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
16 import basic.Message; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
17 |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
18 import ast.Module; |
1 | 19 |
20 import tools.AstPrinter, | |
21 tools.DotPrinter; | |
22 | |
51
c96cdcbdb9d6
Rearranged some stuff, and renamed LLVMGen -> CodeGen
Anders Halager <halager@gmail.com>
parents:
50
diff
changeset
|
23 import gen.CodeGen; |
1 | 24 |
13
e5caf9971207
Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
1
diff
changeset
|
25 import sema.Visitor, |
100
5f258eaf9517
Loading modules in. Just need to add them to the scope of the "main" Module now.
Anders Johnsen <skabet@gmail.com>
parents:
97
diff
changeset
|
26 sema.LoadModule, |
51
c96cdcbdb9d6
Rearranged some stuff, and renamed LLVMGen -> CodeGen
Anders Halager <halager@gmail.com>
parents:
50
diff
changeset
|
27 sema.AstAction, |
92
771ac63898e2
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents:
91
diff
changeset
|
28 sema.ScopeBuilder, |
771ac63898e2
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents:
91
diff
changeset
|
29 sema.ScopeCheck, |
771ac63898e2
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents:
91
diff
changeset
|
30 sema.TypeCheck; |
1 | 31 |
97
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
32 import tango.stdc.posix.unistd; |
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
33 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
34 import Opt = dang.OptParse; |
1 | 35 |
36 void checkFiles(char[][] *files) | |
37 { | |
91
1a24e61eb104
Fixed the SourceLocation/SourceManager for files stretching by more then one CheckPoints
johnsen@johnsen-laptop
parents:
90
diff
changeset
|
38 GC.disable(); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
39 bool non_existant_files = false; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
40 bool duplicate_files = false; |
1 | 41 |
42 char[][] validFiles; | |
43 | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
44 foreach (file; *files) |
1 | 45 { |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
46 scope path = new FilePath(file); |
1 | 47 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
48 if (!path.exists) |
1 | 49 { |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
50 Stderr.formatln("'{}' does not exist", file).newline; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
51 non_existant_files = true; |
1 | 52 |
53 continue; | |
54 } | |
55 | |
56 bool fileInStack = false; | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
57 foreach (vFile; validFiles) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
58 if (vFile == file) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
59 { |
1 | 60 fileInStack = true; |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
61 duplicate_files = true; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
62 } |
1 | 63 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
64 if (fileInStack) |
1 | 65 continue; |
66 | |
67 validFiles ~= file; | |
68 } | |
69 | |
70 *files = validFiles; | |
71 | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
72 if (non_existant_files) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
73 throw new Exception("All files given must exist"); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
74 if (duplicate_files) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
75 Stderr("warning: duplicate files ignored").newline; |
1 | 76 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
77 |
1 | 78 void main(char[][] args) |
79 { | |
80 char[][] filesToHandle; | |
81 | |
82 Signal!(char[][]*) preStart; | |
83 | |
84 Signal!(char[]) preLex; | |
85 Signal!(Lexer) postLex; | |
86 | |
87 Signal!(Lexer) preParse; | |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
88 Signal!(Module, SourceManager) postParse; |
1 | 89 |
90 preStart.attach(&checkFiles); | |
91 | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
92 auto argParse = new Opt.OptionParser(`Dang "D" compiler v0.0`); |
1 | 93 |
40
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
94 bool optimize = false; |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
95 bool inline = false; |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
96 |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
97 |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
98 SourceManager src_mgr = new SourceManager; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
99 MessageHandler messages = new MessageHandler(src_mgr); |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
100 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
101 argParse.addOption(["-h", "--help"], Opt.Action.Help) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
102 .help("Show this help message"); |
1 | 103 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
104 argParse.addOption(["--ast-dump-dot"], |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
105 "what-to-do", Opt.Action.StoreConst, "dot") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
106 .help("Output the AST in the dot format"); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
107 argParse.addOption(["--ast-dump-code"], |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
108 "what-to-do", Opt.Action.StoreConst, "code") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
109 .help("Output the AST as code"); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
110 argParse.addOption(["--gen-llvm"], |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
111 "what-to-do", Opt.Action.StoreConst, "gen-llvm") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
112 .help("Compile to LLVM code (default)"); |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
113 argParse.addOption(["-c"], |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
114 "what-to-do", Opt.Action.StoreConst, "compile") |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
115 .help("Compile to .o or executeable"); |
40
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
116 |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
117 argParse.addOption( |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
118 ["-O","--optimize"], { |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
119 optimize = true; |
1 | 120 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
121 ).help("Tell LLVM to do its standard optimizations"); |
40
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
122 |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
123 argParse.addOption( |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
124 ["--inline"], { |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
125 inline = true; |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
126 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
127 ).help("Tell LLVM that its allowed to inline functions"); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
128 |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
129 argParse |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
130 .addOption(["--time"], Opt.Action.SetTrue, "time") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
131 .help("Time the various operations performed."); |
1 | 132 |
133 auto options = argParse.parse(args); | |
134 | |
135 filesToHandle ~= options.args; | |
136 | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
137 // Will throw exception if some files don't exist |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
138 preStart(&filesToHandle); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
139 |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
140 struct Measurement { char[] label; double time; } |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
141 Measurement[] timings; |
1 | 142 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
143 auto what = options["what-to-do"]; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
144 if (what == "" || what == "gen-llvm") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
145 postParse.attach( |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
146 (Module m, SourceManager sm) { |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
147 StopWatch w; w.start; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
148 auto llvmGen = new CodeGen(); |
90 | 149 auto file = new FileConduit("out.bc", FileConduit.WriteCreate); |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
150 llvmGen.gen(m, file.fileHandle, optimize, inline); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
151 timings ~= Measurement("Generating LLVM bytecode", w.stop); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
152 }); |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
153 else if (what == "compile") |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
154 postParse.attach( |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
155 (Module m, SourceManager sm) { |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
156 StopWatch w; w.start; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
157 auto llvmGen = new CodeGen(); |
97
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
158 auto llc = new Process("llc","-o=-"); |
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
159 auto gcc = new Process("gcc","-c","-o","out.o","-x","assembler","-"); |
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
160 llc.execute(); |
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
161 int i = dup(llc.stdin.fileHandle); |
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
162 llc.stdin.detach; |
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
163 llvmGen.gen(m, i, optimize, inline); |
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
164 llc.wait(); |
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
165 gcc.execute(); |
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
166 gcc.stdin.copy(llc.stdout); |
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
167 gcc.stdin.detach; |
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
168 gcc.wait(); |
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
169 |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
170 timings ~= Measurement("Generating assemble bytecode", w.stop); |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
171 }); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
172 else if (what == "dot") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
173 postParse.attach( |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
174 (Module m, SourceManager sm) { |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
175 StopWatch w; w.start; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
176 auto print = new DotPrinter(); |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
177 print.print(m); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
178 timings ~= Measurement("Generating dot output", w.stop); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
179 }); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
180 else if (what == "code") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
181 postParse.attach( |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
182 (Module m, SourceManager sm) { |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
183 StopWatch w; w.start; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
184 auto print = new AstPrinter(sm); |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
185 print.print(m); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
186 timings ~= Measurement("Converting AST to text", w.stop); |
40
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
187 }); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
188 StopWatch total; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
189 total.start; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
190 foreach (file; filesToHandle) |
1 | 191 { |
192 preLex(file); | |
193 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
194 auto start = src_mgr.addFile(file); |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
195 auto lexer = new Lexer(start, src_mgr, messages); |
1 | 196 postLex(lexer); |
197 | |
198 preParse(lexer); | |
199 | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
200 StopWatch watch; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
201 watch.start; |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
202 auto parser = new Parser(messages); |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
203 auto action = new AstAction(src_mgr); |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
204 auto m = cast(Module)parser.parse(src_mgr, lexer, action); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
205 timings ~= Measurement("Lex + Parse", watch.stop); |
92
771ac63898e2
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents:
91
diff
changeset
|
206 messages.checkErrors(ExitLevel.Parser); |
1 | 207 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
208 StopWatch watch2; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
209 watch.start; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
210 watch2.start; |
100
5f258eaf9517
Loading modules in. Just need to add them to the scope of the "main" Module now.
Anders Johnsen <skabet@gmail.com>
parents:
97
diff
changeset
|
211 Module[] mods = (new LoadModule).visit(m, src_mgr, messages); |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
212 (new ScopeBuilder).visit(m); |
92
771ac63898e2
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents:
91
diff
changeset
|
213 auto scope_builder = watch2.stop; |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
214 watch2.start; |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
215 (new ScopeCheck).visit(m); |
92
771ac63898e2
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents:
91
diff
changeset
|
216 auto scope_check = watch2.stop; |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
217 watch2.start; |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
218 (new TypeCheck).visit(m); |
92
771ac63898e2
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents:
91
diff
changeset
|
219 auto type_check = watch2.stop; |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
220 watch2.start; |
13
e5caf9971207
Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
1
diff
changeset
|
221 |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
222 foreach (decl; m.decls) |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
51
diff
changeset
|
223 decl.simplify(); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
224 auto simplify = watch2.stop; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
225 auto extra_stuff = watch.stop; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
226 timings ~= Measurement("Extra stuff", watch.stop); |
92
771ac63898e2
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents:
91
diff
changeset
|
227 timings ~= Measurement(" - Building scopes", scope_builder); |
771ac63898e2
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents:
91
diff
changeset
|
228 timings ~= Measurement(" - Checking scopes", scope_check); |
771ac63898e2
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents:
91
diff
changeset
|
229 timings ~= Measurement(" - Checking types", type_check); |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
51
diff
changeset
|
230 |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
231 postParse(m, src_mgr); |
1 | 232 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
233 timings ~= Measurement("Total", total.stop); |
1 | 234 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
235 if (options.flag("time")) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
236 foreach (m; timings) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
237 Stderr.formatln("{,-45} {}ms", m.label, m.time*1e3); |
1 | 238 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
239 |