annotate dang/compiler.d @ 91:1a24e61eb104 new_gen

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