Mercurial > projects > dang
annotate dang/compiler.d @ 101:fea8d61a2451 new_gen
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...?)
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Wed, 07 May 2008 19:58:13 +0200 |
parents | 5f258eaf9517 |
children | 89db676fbacb |
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, |
51
c96cdcbdb9d6
Rearranged some stuff, and renamed LLVMGen -> CodeGen
Anders Halager <halager@gmail.com>
parents:
50
diff
changeset
|
26 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
|
27 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
|
28 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
|
29 sema.TypeCheck; |
1 | 30 |
97
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
31 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
|
32 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
33 import Opt = dang.OptParse; |
1 | 34 |
35 void checkFiles(char[][] *files) | |
36 { | |
91
1a24e61eb104
Fixed the SourceLocation/SourceManager for files stretching by more then one CheckPoints
johnsen@johnsen-laptop
parents:
90
diff
changeset
|
37 GC.disable(); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
38 bool non_existant_files = false; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
39 bool duplicate_files = false; |
1 | 40 |
41 char[][] validFiles; | |
42 | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
43 foreach (file; *files) |
1 | 44 { |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
45 scope path = new FilePath(file); |
1 | 46 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
47 if (!path.exists) |
1 | 48 { |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
49 Stderr.formatln("'{}' does not exist", file).newline; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
50 non_existant_files = true; |
1 | 51 |
52 continue; | |
53 } | |
54 | |
55 bool fileInStack = false; | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
56 foreach (vFile; validFiles) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
57 if (vFile == file) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
58 { |
1 | 59 fileInStack = true; |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
60 duplicate_files = true; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
61 } |
1 | 62 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
63 if (fileInStack) |
1 | 64 continue; |
65 | |
66 validFiles ~= file; | |
67 } | |
68 | |
69 *files = validFiles; | |
70 | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
71 if (non_existant_files) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
72 throw new Exception("All files given must exist"); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
73 if (duplicate_files) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
74 Stderr("warning: duplicate files ignored").newline; |
1 | 75 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
76 |
1 | 77 void main(char[][] args) |
78 { | |
79 char[][] filesToHandle; | |
80 | |
81 Signal!(char[][]*) preStart; | |
82 | |
83 Signal!(char[]) preLex; | |
84 Signal!(Lexer) postLex; | |
85 | |
86 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
|
87 Signal!(Module[], SourceManager) postParse; |
1 | 88 |
89 preStart.attach(&checkFiles); | |
90 | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
91 auto argParse = new Opt.OptionParser(`Dang "D" compiler v0.0`); |
1 | 92 |
40
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
93 bool optimize = false; |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
94 bool inline = false; |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
95 |
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
|
96 |
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 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
|
98 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
|
99 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
100 argParse.addOption(["-h", "--help"], Opt.Action.Help) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
101 .help("Show this help message"); |
1 | 102 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
103 argParse.addOption(["--ast-dump-dot"], |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
104 "what-to-do", Opt.Action.StoreConst, "dot") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
105 .help("Output the AST in the dot format"); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
106 argParse.addOption(["--ast-dump-code"], |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
107 "what-to-do", Opt.Action.StoreConst, "code") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
108 .help("Output the AST as code"); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
109 argParse.addOption(["--gen-llvm"], |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
110 "what-to-do", Opt.Action.StoreConst, "gen-llvm") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
111 .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
|
112 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
|
113 "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
|
114 .help("Compile to .o or executeable"); |
40
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
115 |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
116 argParse.addOption( |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
117 ["-O","--optimize"], { |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
118 optimize = true; |
1 | 119 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
120 ).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
|
121 |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
122 argParse.addOption( |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
123 ["--inline"], { |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
124 inline = true; |
9fb190ad81a4
Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
125 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
126 ).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
|
127 |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
128 argParse |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
129 .addOption(["--time"], Opt.Action.SetTrue, "time") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
130 .help("Time the various operations performed."); |
1 | 131 |
132 auto options = argParse.parse(args); | |
133 | |
134 filesToHandle ~= options.args; | |
135 | |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
136 // 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
|
137 preStart(&filesToHandle); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
138 |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
139 struct Measurement { char[] label; double time; } |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
140 Measurement[] timings; |
1 | 141 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
142 auto what = options["what-to-do"]; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
143 if (what == "" || what == "gen-llvm") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
144 postParse.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
|
145 (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
|
146 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
|
147 { |
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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
154 }); |
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
|
155 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
|
156 postParse.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 { |
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
|
160 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
|
161 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
|
162 auto llc = new Process("llc","-o=-"); |
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 gcc = new Process("gcc","-c","-o","out.o","-x","assembler","-"); |
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 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 gcc.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
|
173 timings ~= Measurement("Generating assemble 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
|
174 } |
97
198ad05f3ace
"-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
175 |
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
|
176 }); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
177 else if (what == "dot") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
178 postParse.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
|
179 (Module[] m, SourceManager sm) { |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
180 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
|
181 // 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
|
182 // print.print(m); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
183 timings ~= Measurement("Generating dot output", w.stop); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
184 }); |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
185 else if (what == "code") |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
186 postParse.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
|
187 (Module[] modules, SourceManager sm) { |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
188 StopWatch w; w.start; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
189 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
|
190 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
|
191 print.print(m); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
192 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
|
193 }); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
194 StopWatch total; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
195 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
|
196 |
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
|
197 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
|
198 |
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
|
199 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
|
200 watch.start; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
201 foreach (file; filesToHandle) |
1 | 202 { |
203 preLex(file); | |
204 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
205 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
|
206 auto lexer = new Lexer(start, src_mgr, messages); |
1 | 207 postLex(lexer); |
208 | |
209 preParse(lexer); | |
210 | |
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
|
211 auto parser = new Parser(messages); |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
212 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
|
213 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
|
214 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
|
215 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
|
216 /* |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
217 StopWatch watch2; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
218 watch.start; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
219 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
|
220 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
|
221 (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
|
222 auto scope_builder = watch2.stop; |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
223 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
|
224 (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
|
225 auto scope_check = watch2.stop; |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
226 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
|
227 (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
|
228 auto type_check = watch2.stop; |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
229 watch2.start; |
13
e5caf9971207
Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
1
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 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
|
232 decl.simplify(); |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
233 auto simplify = watch2.stop; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
234 auto extra_stuff = watch.stop; |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
235 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
|
236 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
|
237 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
|
238 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
|
239 |
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
|
240 postParse(m, src_mgr);*/ |
1 | 241 } |
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 |
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
|
243 (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
|
244 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
|
245 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
|
246 watch2.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
|
247 (new ScopeCheck).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
|
248 auto scope_check = watch2.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
|
249 watch2.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
|
250 (new TypeCheck).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
|
251 auto type_check = watch2.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
|
252 watch2.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
|
253 |
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
|
254 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
|
255 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
|
256 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
|
257 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
258 timings ~= Measurement("Total", total.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
|
259 postParse(modules, src_mgr); |
1 | 260 |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
261 if (options.flag("time")) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
262 foreach (m; timings) |
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
263 Stderr.formatln("{,-45} {}ms", m.label, m.time*1e3); |
1 | 264 } |
87
9a35a973175a
Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
265 |