4 #include <boost/foreach.hpp>
6 #include <core/assert.hh>
7 #include <core/string.hh>
8 #include <core/process.hh>
10 #include <ast/ascii-visitor.hh>
11 #include <ast/llvm-generator-visitor.hh>
12 #include <ast/type-checker-visitor.hh>
13 #include <ast/simplify-visitor.hh>
14 #include <ast/scope-builder-visitor.hh>
15 #include <lang/parser-factory.hh>
16 #include <compiler.hh>
18 #include <parse-task.hh>
23 astDumpTypeCheck_(false),
24 astDumpSimplify_(false)
33 Compiler::addTask(Task
* task
)
36 std::vector
<Task
*> * deps
= task
->dependancies();
39 BOOST_FOREACH(Task
* dep
, *deps
)
43 tasks_
.push_back(task
);
49 std::sort(tasks_
.begin(), tasks_
.end());
50 std::unique(tasks_
.begin(), tasks_
.end());
51 BOOST_FOREACH(Task
* task
, tasks_
)
59 Compiler::work(Task
& /*task*/)
65 Compiler::work(ParseTask
& task
)
67 ast::File
* file
= lang::ParserFactory::parseFile(task
.filename
);
68 file
->path
= task
.filename
;
70 std::cout
<< "Parsed AST" << std::endl
;
75 ast::ScopeBuilderVisitor sbv
;
78 ast::TypeCheckerVisitor tcv
;
80 if (astDumpTypeCheck_
) {
81 std::cout
<< "TypeChecked AST" << std::endl
;
86 ast::SimplifyVisitor sv
;
88 if (astDumpSimplify_
) {
89 std::cout
<< "Simplified AST" << std::endl
;
94 std::string
asm_filename(task
.filename
);
95 core::replace_extention(asm_filename
, "ll");
96 std::ofstream
asm_stream(asm_filename
.c_str(),
97 std::ios_base::out
| std::ios_base::trunc
);
98 ast::LLVMGeneratorVisitor
lgv(asm_stream
);
102 core::Process llvm_as
;
103 llvm_as
.setBinary("llvm-as");
104 llvm_as
.addArg("-f");
105 llvm_as
.addArg(asm_filename
);
107 assert(!llvm_as
.wait());
109 std::string
bc_filename(asm_filename
);
110 core::replace_extention(bc_filename
, "bc");
111 std::string
bin_filename(asm_filename
);
112 core::replace_extention(bin_filename
, "");
113 core::Process llvm_ld
;
114 llvm_ld
.setBinary("llvm-ld");
115 llvm_ld
.addArg("-native");
116 llvm_ld
.addArg("-o");
117 llvm_ld
.addArg(bin_filename
);
118 llvm_ld
.addArg(bc_filename
);
120 assert(!llvm_ld
.wait());