annotate dang/compiler.d @ 89:a49bb982a7b0 new_gen

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.
author Anders Johnsen <skabet@gmail.com>
date Sun, 04 May 2008 20:27:01 +0200
parents eb5b2c719a39
children 4b6d8563e943
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1 module dang.compiler;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
2
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
3 import tango.io.Stdout,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
4 tango.core.Signal,
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
5 tango.sys.Process,
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
6 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
7 tango.io.FileConduit,
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
8 tango.io.FilePath;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
9
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
10 import lexer.Lexer,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
11 parser.Parser;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
12
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
13 import basic.SourceManager;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
14
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
15 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
16
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
17 import ast.Decl;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
18
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
19 import tools.AstPrinter,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
20 tools.DotPrinter;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
21
51
c96cdcbdb9d6 Rearranged some stuff, and renamed LLVMGen -> CodeGen
Anders Halager <halager@gmail.com>
parents: 50
diff changeset
22 import gen.CodeGen;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
23
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents: 1
diff changeset
24 import sema.Visitor,
51
c96cdcbdb9d6 Rearranged some stuff, and renamed LLVMGen -> CodeGen
Anders Halager <halager@gmail.com>
parents: 50
diff changeset
25 sema.AstAction,
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents: 1
diff changeset
26 sema.SymbolTableBuilder,
68
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 60
diff changeset
27 sema.ImplicitCast,
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents: 1
diff changeset
28 sema.Declarations;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
29
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
30 import Opt = dang.OptParse;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
31
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
32 void checkFiles(char[][] *files)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
33 {
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
34 bool non_existant_files = false;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
35 bool duplicate_files = false;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
36
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
37 char[][] validFiles;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
38
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
39 foreach (file; *files)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
40 {
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
41 scope path = new FilePath(file);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
42
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
43 if (!path.exists)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
44 {
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
45 Stderr.formatln("'{}' does not exist", file).newline;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
46 non_existant_files = true;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
47
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
48 continue;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
49 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
50
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
51 bool fileInStack = false;
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
52 foreach (vFile; validFiles)
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
53 if (vFile == file)
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
54 {
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
55 fileInStack = true;
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
56 duplicate_files = true;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
57 }
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
58
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
59 if (fileInStack)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
60 continue;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
61
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
62 validFiles ~= file;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
63 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
64
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
65 *files = validFiles;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
66
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
67 if (non_existant_files)
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
68 throw new Exception("All files given must exist");
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
69 if (duplicate_files)
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
70 Stderr("warning: duplicate files ignored").newline;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
71 }
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
72
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
73 void main(char[][] args)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
74 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
75 char[][] filesToHandle;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
76
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
77 Signal!(char[][]*) preStart;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
78
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
79 Signal!(char[]) preLex;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
80 Signal!(Lexer) postLex;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
81
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
82 Signal!(Lexer) preParse;
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
83 Signal!(Decl[], SourceManager) postParse;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
84
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
85 preStart.attach(&checkFiles);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
86
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
87 auto argParse = new Opt.OptionParser(`Dang "D" compiler v0.0`);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
88
40
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
89 bool optimize = false;
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
90 bool inline = false;
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
91
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
92
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
93 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
94 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
95
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
96 argParse.addOption(["-h", "--help"], Opt.Action.Help)
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
97 .help("Show this help message");
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
98
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
99 argParse.addOption(["--ast-dump-dot"],
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
100 "what-to-do", Opt.Action.StoreConst, "dot")
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
101 .help("Output the AST in the dot format");
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
102 argParse.addOption(["--ast-dump-code"],
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
103 "what-to-do", Opt.Action.StoreConst, "code")
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
104 .help("Output the AST as code");
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
105 argParse.addOption(["--gen-llvm"],
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
106 "what-to-do", Opt.Action.StoreConst, "gen-llvm")
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
107 .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
108 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
109 "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
110 .help("Compile to .o or executeable");
40
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
111
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
112 argParse.addOption(
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
113 ["-O","--optimize"], {
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
114 optimize = true;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
115 }
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
116 ).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
117
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
118 argParse.addOption(
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
119 ["--inline"], {
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
120 inline = true;
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
121 }
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
122 ).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
123
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
124 argParse
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
125 .addOption(["--time"], Opt.Action.SetTrue, "time")
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
126 .help("Time the various operations performed.");
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
127
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
128 auto options = argParse.parse(args);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
129
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
130 filesToHandle ~= options.args;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
131
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
132 // 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
133 preStart(&filesToHandle);
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
134
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
135 struct Measurement { char[] label; double time; }
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
136 Measurement[] timings;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
137
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
138 auto what = options["what-to-do"];
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
139 if (what == "" || what == "gen-llvm")
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
140 postParse.attach(
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
141 (Decl[] decls, SourceManager sm) {
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
142 StopWatch w; w.start;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
143 auto llvmGen = new CodeGen();
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
144 auto file = new FileConduit("out.bc");
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
145 llvmGen.gen(decls, file.fileHandle, optimize, inline);
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
146 timings ~= Measurement("Generating LLVM bytecode", w.stop);
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
147 });
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
148 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
149 postParse.attach(
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
150 (Decl[] decls, SourceManager sm) {
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
151 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
152 auto llvmGen = new CodeGen();
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 auto llc = new Process("llc");
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 llvmGen.gen(decls, llc.stdin.fileHandle, optimize, inline);
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 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
156 });
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
157 else if (what == "dot")
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
158 postParse.attach(
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
159 (Decl[] decls, SourceManager sm) {
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
160 StopWatch w; w.start;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
161 auto print = new DotPrinter();
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
162 print.print(decls);
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
163 timings ~= Measurement("Generating dot output", w.stop);
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
164 });
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
165 else if (what == "code")
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
166 postParse.attach(
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
167 (Decl[] decls, SourceManager sm) {
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
168 StopWatch w; w.start;
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
169 auto print = new AstPrinter(sm);
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
170 print.print(decls);
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
171 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
172 });
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
173 StopWatch total;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
174 total.start;
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
175 foreach (file; filesToHandle)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
176 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
177 preLex(file);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
178
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
179 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
180 auto lexer = new Lexer(start, src_mgr, messages);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
181 postLex(lexer);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
182
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
183 preParse(lexer);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
184
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
185 StopWatch watch;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
186 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
187 auto parser = new Parser(messages);
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
188 auto action = new AstAction(src_mgr);
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
189 auto decls = cast(Decl[])parser.parse(src_mgr, lexer, action);
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
190 timings ~= Measurement("Lex + Parse", watch.stop);
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
191 messages.checkErrors();
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
192
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
193 StopWatch watch2;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
194 watch.start;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
195 watch2.start;
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents: 1
diff changeset
196 (new SymbolTableBuilder).visit(decls);
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
197 auto symbol_table = watch2.stop;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
198 watch2.start;
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents: 1
diff changeset
199 (new Declarations).visit(decls);
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
200 auto declarations = watch2.stop;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
201 watch2.start;
68
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 60
diff changeset
202 (new ImplicitCast).visit(decls);
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
203 auto implicit_casts = watch2.stop;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
204 watch2.start;
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents: 1
diff changeset
205
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
206 foreach (decl; 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
207 decl.simplify();
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
208 auto simplify = watch2.stop;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
209 auto extra_stuff = watch.stop;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
210 timings ~= Measurement("Extra stuff", watch.stop);
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
211 timings ~= Measurement(" - Building scopes", symbol_table);
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
212 timings ~= Measurement(" - Extracting declarations", declarations);
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
213 timings ~= Measurement(" - Making casts explicit", implicit_casts);
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
214
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
215 postParse(decls, src_mgr);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
216 }
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
217 timings ~= Measurement("Total", total.stop);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
218
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
219 if (options.flag("time"))
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
220 foreach (m; timings)
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
221 Stderr.formatln("{,-45} {}ms", m.label, m.time*1e3);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
222 }
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
223