annotate dang/compiler.d @ 97:198ad05f3ace new_gen

"-c" as argument now generates out.o (only works on linux now)
author Anders Johnsen <skabet@gmail.com>
date Tue, 06 May 2008 21:28:05 +0200
parents 48bb2287c035
children 5f258eaf9517
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
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
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,
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
34
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
35 void checkFiles(char[][] *files)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
40
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
41 char[][] validFiles;
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 foreach (file; *files)
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 scope path = new FilePath(file);
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 if (!path.exists)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
51
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
52 continue;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
53 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
54
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
62
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
63 if (fileInStack)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
64 continue;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
65
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
66 validFiles ~= file;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
67 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
68
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
69 *files = validFiles;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
75 }
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
76
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
77 void main(char[][] args)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
78 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
79 char[][] filesToHandle;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
80
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
81 Signal!(char[][]*) preStart;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
82
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
83 Signal!(char[]) preLex;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
84 Signal!(Lexer) postLex;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
85
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
86 Signal!(Lexer) preParse;
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
87 Signal!(Module, SourceManager) postParse;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
88
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
89 preStart.attach(&checkFiles);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
131
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
132 auto options = argParse.parse(args);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
133
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
134 filesToHandle ~= options.args;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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(
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
145 (Module m, SourceManager sm) {
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
146 StopWatch w; w.start;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
147 auto llvmGen = new CodeGen();
90
4b6d8563e943 Write file again
Anders Halager <halager@gmail.com>
parents: 89
diff changeset
148 auto file = new FileConduit("out.bc", FileConduit.WriteCreate);
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
149 llvmGen.gen(m, file.fileHandle, optimize, inline);
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
150 timings ~= Measurement("Generating LLVM bytecode", w.stop);
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
151 });
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
152 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
153 postParse.attach(
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
154 (Module m, SourceManager sm) {
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
155 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
156 auto llvmGen = new CodeGen();
97
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
157 auto llc = new Process("llc","-o=-");
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
158 auto gcc = new Process("gcc","-c","-o","out.o","-x","assembler","-");
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
159 llc.execute();
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
160 int i = dup(llc.stdin.fileHandle);
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
161 llc.stdin.detach;
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
162 llvmGen.gen(m, i, optimize, inline);
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
163 llc.wait();
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
164 gcc.execute();
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
165 gcc.stdin.copy(llc.stdout);
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
166 gcc.stdin.detach;
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
167 gcc.wait();
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
168
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
169 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
170 });
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
171 else if (what == "dot")
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
172 postParse.attach(
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
173 (Module m, SourceManager sm) {
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
174 StopWatch w; w.start;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
175 auto print = new DotPrinter();
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
176 print.print(m);
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
177 timings ~= Measurement("Generating dot output", w.stop);
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
178 });
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
179 else if (what == "code")
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
180 postParse.attach(
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
181 (Module m, SourceManager sm) {
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
182 StopWatch w; w.start;
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
183 auto print = new AstPrinter(sm);
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
184 print.print(m);
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
185 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
186 });
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
187 StopWatch total;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
188 total.start;
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
189 foreach (file; filesToHandle)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
190 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
191 preLex(file);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
192
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
193 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
194 auto lexer = new Lexer(start, src_mgr, messages);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
195 postLex(lexer);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
196
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
197 preParse(lexer);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
198
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
199 StopWatch watch;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
200 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
201 auto parser = new Parser(messages);
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
202 auto action = new AstAction(src_mgr);
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
203 auto m = cast(Module)parser.parse(src_mgr, lexer, action);
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
204 timings ~= Measurement("Lex + Parse", watch.stop);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 91
diff changeset
205 messages.checkErrors(ExitLevel.Parser);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
206
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
207 StopWatch watch2;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
208 watch.start;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
209 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
210 (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
211 auto scope_builder = watch2.stop;
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
212 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
213 (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
214 auto scope_check = watch2.stop;
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
215 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
216 (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
217 auto type_check = watch2.stop;
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
218 watch2.start;
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents: 1
diff changeset
219
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
220 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
221 decl.simplify();
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
222 auto simplify = watch2.stop;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
223 auto extra_stuff = watch.stop;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
224 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
225 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
226 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
227 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
228
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
229 postParse(m, src_mgr);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
230 }
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
231 timings ~= Measurement("Total", total.stop);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
232
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
233 if (options.flag("time"))
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
234 foreach (m; timings)
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
235 Stderr.formatln("{,-45} {}ms", m.label, m.time*1e3);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
236 }
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
237