-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdriver.cpp
More file actions
97 lines (84 loc) · 3.58 KB
/
driver.cpp
File metadata and controls
97 lines (84 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
// #define FP_DEFAULT_HASH_TABLE_BASE_SIZE 16
#define FP_IMPLEMENTATION
#define ECRS_IMPLEMENTATION
#include "module.hpp"
#include "file_manager.hpp"
#include "diagnostics.hpp"
#include "interface.hpp"
#include "parser.hpp"
#include "print.hpp"
#include "sema/canonicalize/sort.hpp"
#include "sema/canonicalize/materialize_function_types_and_parameters.hpp"
#include "sema/lookup.hpp"
#include "sema/strip_names.hpp"
#include "sema/function_arity.hpp"
#include "sema/name_reuse.hpp"
#include "opt/inline_functions.hpp"
#include "opt/materialize_aliases.hpp"
#include "opt/compute_compiler_namespace.hpp"
#include "opt/mizu_materialize_immediates.hpp"
#include "opt/pin_registers.hpp"
#include "opt/allocate_registers.hpp"
#include "temp_byte_dumper.hpp"
#include <filesystem>
#include <iostream>
#include <fstream>
int main(int argc, char** argv) {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " <path to file to compile>" << std::endl;
return 0;
}
doir::module mod;
std::vector<doir::block_builder> builders;
builders.push_back(doir::block_builder::create(mod).build_global_block());
auto parser = initialize_parser(builders);
mod.parse_file(parser, argv[1]);
if(doir::diagnostics().count() > 0) {
doir::diagnostics().print_all();
if(doir::diagnostics().has_errors()) return -1;
}
auto root = builders.front().block;
doir::verify::structure(doir::diagnostics(), mod, root);
root = doir::canonicalize::sort(mod, root);
doir::system::sorted(doir::canonicalize::materialize_function_types_and_parameters, false, true)(mod);
// doir::print(std::cout, mod, doir::canonicalize::new_root, true, true);
using namespace std::placeholders;
auto sema_schedule = ecrs::system::sequential(
doir::system::sorted(doir::sema::validate::name_reuse),
doir::system::sorted(std::bind(doir::sema::resolve_lookups, _1, _2, true)),
doir::system::sorted(doir::canonicalize::materialize_function_types_and_parameters, false, true),
doir::system::sorted(std::bind(doir::sema::resolve_lookups, _1, _2, false)), // We may have materialized some function parameters which can now be found
// doir::system::print(std::cout),
doir::system::sorted(doir::sema::validate::lookups_resolved),
// ecrs::system::parallel(
// // doir::system::sorted(doir::sema::strip_names),
doir::system::sorted(doir::sema::validate::function_arity)
// )
);
auto opt_schedule = ecrs::system::sequential(
doir::system::sorted(doir::opt::pin_registers),
doir::system::sorted(doir::opt::allocate_registers, false, true),
doir::system::sorted(doir::opt::pin_registers),
doir::system::sorted(std::bind(doir::opt::compute_compiler_namespace, _1, _2, false)),
doir::system::sorted(doir::opt::mizu::materialize_immediates, false, true),
// doir::system::print(std::cout),
doir::system::sorted(doir::opt::inline_functions, false, true),
doir::system::sorted(std::bind(doir::opt::compute_compiler_namespace, _1, _2, true))
// doir::system::sorted(doir::system::bind_root(doir::opt::materialize_aliases))
);
sema_schedule(mod);
opt_schedule(mod);
// doir::print(std::cout, mod, doir::canonicalize::new_root, true, true);
root = doir::canonicalize::sort(mod, doir::canonicalize::new_root);
// doir::print(std::cout, mod, root, true, true);
doir::verify::structure(doir::diagnostics(), mod, root);
doir::print(std::cout, mod, root, true, true);
{
mod.interner.intern("compiler.emit"); mod.interner.intern("compiler.emit_bytes");
auto bytes = doir::byte_dumper().interpret(mod, root);
std::ofstream fout("res.bin", std::ios::binary);
fout.write((char*)bytes.data(), bytes.size());
}
}