Mercurial > projects > dang
annotate dang/compiler.d @ 150:6c5a3c0bb4fb
Make switch work again
Also added locations to statements (only filled out for switch)
Added a verification pass
Removed some comments
author | Anders Halager <halager@gmail.com> |
---|---|
date | Mon, 21 Jul 2008 20:35:03 +0200 |
parents | 2be29b296081 |
children | 7982eb63c0eb |
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, |
136 | 8 tango.text.Util, |
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
|
9 tango.io.FileConduit, |
1 | 10 tango.io.FilePath; |
11 | |
12 import lexer.Lexer, | |
13 parser.Parser; | |
14 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
15 import basic.SourceManager; |
1 | 16 |
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
|
17 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
|
18 |
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
|
19 import ast.Module; |
1 | 20 |
21 import tools.AstPrinter, | |
22 tools.DotPrinter; | |
23 | |
51
c96cdcbdb9d6
Rearranged some stuff, and renamed LLVMGen -> CodeGen
Anders Halager <halager@gmail.com>
parents:
50
diff
changeset
|
24 import gen.CodeGen; |
1 | 25 |
13
e5caf9971207
Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
1
diff
changeset
|
26 import sema.Visitor, |
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, |
106
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
29 sema.LiteralInterpreter, |
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
|
30 sema.ScopeCheck, |
150 | 31 sema.VC, |
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
|
32 sema.TypeCheck; |
1 | 33 |
97
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
34 import tango.stdc.posix.unistd; |
136 | 35 import tango.stdc.stdlib; |
97
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
36 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
37 import Opt = dang.OptParse; |
136 | 38 |
39 class NullAction : Action | |
40 { | |
41 } | |
1 | 42 |
43 void checkFiles(char[][] *files) | |
44 { | |
91
1a24e61eb104
Fixed the SourceLocation/SourceManager for files stretching by more then one CheckPoints
johnsen@johnsen-laptop
parents:
90
diff
changeset
|
45 GC.disable(); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
46 bool non_existant_files = false; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
47 bool duplicate_files = false; |
1 | 48 |
49 char[][] validFiles; | |
50 | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
51 foreach (file; *files) |
1 | 52 { |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
53 scope path = new FilePath(file); |
1 | 54 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
55 if (!path.exists) |
1 | 56 { |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
57 Stderr.formatln("'{}' does not exist", file).newline; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
58 non_existant_files = true; |
1 | 59 |
60 continue; | |
61 } | |
62 | |
63 bool fileInStack = false; | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
64 foreach (vFile; validFiles) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
65 if (vFile == file) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
66 { |
1 | 67 fileInStack = true; |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
68 duplicate_files = true; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
69 } |
1 | 70 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
71 if (fileInStack) |
1 | 72 continue; |
73 | |
136 | 74 validFiles ~= path.toString(); |
1 | 75 } |
76 | |
77 *files = validFiles; | |
78 | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
79 if (non_existant_files) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
80 throw new Exception("All files given must exist"); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
81 if (duplicate_files) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
82 Stderr("warning: duplicate files ignored").newline; |
1 | 83 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
84 |
1 | 85 void main(char[][] args) |
86 { | |
87 char[][] filesToHandle; | |
88 | |
89 Signal!(char[][]*) preStart; | |
90 | |
91 Signal!(char[]) preLex; | |
92 Signal!(Lexer) postLex; | |
93 | |
94 Signal!(Lexer) preParse; | |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
95 Signal!(Module[], SourceManager) postParse; |
136 | 96 Signal!(Module[], SourceManager) postSema; |
1 | 97 |
98 preStart.attach(&checkFiles); | |
99 | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
100 auto argParse = new Opt.OptionParser(`Dang "D" compiler v0.0`); |
1 | 101 |
40
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
102 bool optimize = false; |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
103 bool inline = false; |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
104 |
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
|
105 |
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
|
106 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
|
107 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
|
108 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
109 argParse.addOption(["-h", "--help"], Opt.Action.Help) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
110 .help("Show this help message"); |
1 | 111 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
112 argParse.addOption(["--ast-dump-dot"], |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
113 "what-to-do", Opt.Action.StoreConst, "dot") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
114 .help("Output the AST in the dot format"); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
115 argParse.addOption(["--ast-dump-code"], |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
116 "what-to-do", Opt.Action.StoreConst, "code") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
117 .help("Output the AST as code"); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
118 argParse.addOption(["--gen-llvm"], |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
119 "what-to-do", Opt.Action.StoreConst, "gen-llvm") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
120 .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
|
121 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
|
122 "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
|
123 .help("Compile to .o or executeable"); |
136 | 124 argParse.addOption(["--syntax-only"], |
125 "what-to-do", Opt.Action.StoreConst, "parse") | |
126 .help("Only parse the file(s) and output parseing errors."); | |
40
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
127 |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
128 argParse.addOption( |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
129 ["-O","--optimize"], { |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
130 optimize = true; |
1 | 131 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
132 ).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
|
133 |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
134 argParse.addOption( |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
135 ["--inline"], { |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
136 inline = true; |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
137 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
138 ).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
|
139 |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
140 argParse |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
141 .addOption(["--time"], Opt.Action.SetTrue, "time") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
142 .help("Time the various operations performed."); |
1 | 143 |
144 auto options = argParse.parse(args); | |
145 | |
146 filesToHandle ~= options.args; | |
147 | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
148 // 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
|
149 preStart(&filesToHandle); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
150 |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
151 struct Measurement { char[] label; double time; } |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
152 Measurement[] timings; |
1 | 153 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
154 auto what = options["what-to-do"]; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
155 if (what == "" || what == "gen-llvm") |
136 | 156 postSema.attach( |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
157 (Module[] modules, SourceManager sm) { |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
158 foreach(m ; modules) |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
159 { |
136 | 160 if (!m.outputModule) |
161 continue; | |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
162 StopWatch w; w.start; |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
163 auto llvmGen = new CodeGen(); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
164 auto file = new FileConduit(m.moduleName~".bc", FileConduit.WriteCreate); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
165 llvmGen.gen(m, file.fileHandle, optimize, inline); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
166 timings ~= Measurement("Generating LLVM bytecode", w.stop); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
167 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
168 }); |
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
|
169 else if (what == "compile") |
136 | 170 postSema.attach( |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
171 (Module[] modules, SourceManager sm) { |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
172 foreach(m ; modules) |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
173 { |
136 | 174 if (!m.outputModule) |
175 continue; | |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
176 StopWatch w; w.start; |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
177 auto llvmGen = new CodeGen(); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
178 auto llc = new Process("llc","-o=-"); |
136 | 179 auto gcc = new Process("gcc","-c","-o",m.moduleName~".o","-x","assembler","-"); |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
180 llc.execute(); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
181 int i = dup(llc.stdin.fileHandle); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
182 llc.stdin.detach; |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
183 llvmGen.gen(m, i, optimize, inline); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
184 llc.wait(); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
185 gcc.execute(); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
186 gcc.stdin.copy(llc.stdout); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
187 gcc.stdin.detach; |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
188 gcc.wait(); |
150 | 189 timings ~= Measurement("Generating ASM", w.stop); |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
190 } |
97
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
191 |
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
|
192 }); |
136 | 193 else if (what == "parse") |
194 preParse.attach( | |
195 (Lexer lexer) { | |
196 auto parser = new Parser(messages); | |
197 auto action = new NullAction(); | |
198 parser.parse(src_mgr, lexer, action); | |
199 messages.checkErrors(ExitLevel.Parser); | |
200 exit(0); | |
201 }); | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
202 else if (what == "dot") |
136 | 203 postSema.attach( |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
204 (Module[] m, SourceManager sm) { |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
205 StopWatch w; w.start; |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
206 // auto print = new DotPrinter(); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
207 // print.print(m); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
208 timings ~= Measurement("Generating dot output", w.stop); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
209 }); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
210 else if (what == "code") |
136 | 211 postSema.attach( |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
212 (Module[] modules, SourceManager sm) { |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
213 StopWatch w; w.start; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
214 auto print = new AstPrinter(sm); |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
215 foreach ( m ; modules ) |
136 | 216 if (m.outputModule) |
217 print.print(m); | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
218 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
|
219 }); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
220 StopWatch total; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
221 total.start; |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
222 |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
223 Module[] modules; |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
224 |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
225 StopWatch watch; |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
226 watch.start; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
227 foreach (file; filesToHandle) |
1 | 228 { |
229 preLex(file); | |
230 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
231 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
|
232 auto lexer = new Lexer(start, src_mgr, messages); |
1 | 233 postLex(lexer); |
234 | |
235 preParse(lexer); | |
236 | |
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
|
237 auto parser = new Parser(messages); |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
238 auto action = new AstAction(src_mgr); |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
239 modules ~= cast(Module)parser.parse(src_mgr, lexer, action); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
240 timings ~= Measurement("Lex + Parse of '"~file~"'", 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
|
241 messages.checkErrors(ExitLevel.Parser); |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
242 /* |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
243 StopWatch watch2; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
244 watch.start; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
245 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
|
246 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
|
247 (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
|
248 auto scope_builder = watch2.stop; |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
249 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
|
250 (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
|
251 auto scope_check = watch2.stop; |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
252 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
|
253 (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
|
254 auto type_check = watch2.stop; |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
255 watch2.start; |
13
e5caf9971207
Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
1
diff
changeset
|
256 |
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
|
257 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
|
258 decl.simplify(); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
259 auto simplify = watch2.stop; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
260 auto extra_stuff = watch.stop; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
261 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
|
262 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
|
263 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
|
264 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
|
265 |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
266 postParse(m, src_mgr);*/ |
1 | 267 } |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
268 |
106
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
269 (new LiteralInterpreter(messages)).visit(modules); |
136 | 270 messages.checkErrors; |
271 postParse(modules, src_mgr); | |
272 | |
273 class ModuleLoader : Visitor!(void) | |
274 { | |
275 Module[] visit(Module[] modules, MessageHandler messages, SourceManager src_mgr) | |
276 { | |
277 this.modules = modules; | |
278 this.messages = messages; | |
279 this.src_mgr = src_mgr; | |
280 super.visit(modules); | |
281 return this.modules; | |
282 } | |
283 | |
284 override void visitImportDecl(ImportDecl decl) | |
285 { | |
286 char[] path = replace!(char)(decl.get,'.','/')~".d"; | |
287 | |
288 auto start = src_mgr.addFile(path); | |
289 auto lexer = new Lexer(start, src_mgr, messages); | |
290 | |
291 auto parser = new Parser(messages); | |
292 auto action = new AstAction(src_mgr); | |
293 | |
294 Module m = cast(Module)parser.parse(src_mgr, lexer, action); | |
295 modules ~= m; | |
296 m.outputModule = false; | |
297 // decl.env.mHandle.add(m); | |
298 messages.checkErrors(ExitLevel.Parser); | |
299 } | |
300 | |
301 Module[] modules; | |
302 SourceManager src_mgr; | |
303 MessageHandler messages; | |
304 } | |
305 | |
306 modules = (new ModuleLoader()).visit(modules, messages, src_mgr); | |
307 messages.checkErrors; | |
106
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
308 |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
309 (new ScopeBuilder).visit(modules); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
310 StopWatch watch2; |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
311 watch.start; |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
312 watch2.start; |
114
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
106
diff
changeset
|
313 (new ScopeCheck(messages)).visit(modules); |
150 | 314 messages.checkErrors; |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
315 auto scope_check = watch2.stop; |
150 | 316 |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
317 watch2.start; |
114
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
106
diff
changeset
|
318 (new TypeCheck(messages)).visit(modules); |
150 | 319 messages.checkErrors; |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
320 auto type_check = watch2.stop; |
150 | 321 |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
322 watch2.start; |
150 | 323 auto vc = new VC; |
324 vc.msg = messages; | |
325 foreach (m; modules) | |
326 m.verify(vc); | |
114
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
106
diff
changeset
|
327 messages.checkErrors; |
150 | 328 auto ast_verify = watch2.stop; |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
329 |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
330 foreach (m; modules) |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
331 foreach (decl; m.decls) |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
332 decl.simplify(); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
333 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
334 timings ~= Measurement("Total", total.stop); |
136 | 335 postSema(modules, src_mgr); |
1 | 336 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
337 if (options.flag("time")) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
338 foreach (m; timings) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
339 Stderr.formatln("{,-45} {}ms", m.label, m.time*1e3); |
1 | 340 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
341 |