Repository navigation
Expand file tree
/
Copy pathdriver.cpp
More file actions
143 lines (130 loc) · 5.33 KB
/
Copy pathdriver.cpp
File metadata and controls
143 lines (130 loc) · 5.33 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#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 "systems.hpp"
#include "sema/canonicalize/sort.hpp"
#include "sema/canonicalize/materialize_function_types_and_parameters.hpp"
#include "sema/canonicalize/process_early_include.hpp"
#include "sema/lookup.hpp"
#include "sema/strip_names.hpp"
#include "sema/function_arity.hpp"
#include "sema/name_reuse.hpp"
#include "sema/comptime.hpp"
#include "opt/inline_functions.hpp"
#include "opt/materialize_aliases.hpp"
#include "opt/compute_compiler_namespace.hpp"
#include "opt/pin_registers.hpp"
#include "opt/allocate_registers.hpp"
#include "opt/strip_freestanding_blocks.hpp"
#include "opt/mizu/materialize_immediates.hpp"
#include "opt/mizu/comptime_evaluate.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_builtin_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);
using namespace std::placeholders;
auto canonicalize_schedule = ecrs::system::sequential(
doir::canonicalize::system::sort(root),
doir::system::sorted(std::bind(doir::canonicalize::process_early_include, _1, _2, std::ref(parser), std::ref(builders)), false, true),
doir::system::sorted(doir::canonicalize::materialize_function_types_and_parameters, false, true)
);
canonicalize_schedule(mod);
// root = doir::canonicalize::new_root;
// doir::print(std::cout, mod, doir::canonicalize::new_root, true, true);
if(doir::diagnostics().count() > 0) {
doir::diagnostics().print_all();
if(doir::diagnostics().has_errors()) return -1;
}
auto sema_schedule = ecrs::system::sequential(
// doir::system::print(std::cout),
doir::system::depth_first(doir::sema::validate::name_reuse),
// doir::system::print(std::cout),
doir::system::depth_first(std::bind(doir::sema::resolve_lookups, _1, _2, true)),
// doir::system::print(std::cout),
doir::system::depth_first(doir::canonicalize::materialize_function_types_and_parameters),
doir::system::depth_first(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::depth_first(doir::sema::validate::lookups_resolved),
// ecrs::system::parallel(
// // doir::system::sorted(doir::sema::strip_names),
ecrs::system::sequential(
doir::system::fixed_point(doir::system::depth_first(doir::sema::bubble_comptime)),
doir::system::depth_first(doir::sema::validate::comptime)
),
doir::system::depth_first(doir::sema::validate::function_arity),
// )
doir::canonicalize::system::sort()
);
auto mizu_schedule = ecrs::system::sequential(
// doir::system::print(std::cout),
doir::system::depth_first(doir::opt::pin_registers),
// doir::system::print(std::cout),
doir::system::breadth_first(doir::opt::allocate_registers),
// doir::system::print(std::cout),
doir::system::depth_first(doir::opt::pin_registers),
// doir::system::print(std::cout),
doir::system::breadth_first(std::bind(doir::opt::compute_compiler_namespace, _1, _2, false)),
// doir::system::print(std::cout),
doir::system::depth_first(doir::opt::mizu::materialize_immediates),
// doir::system::print(std::cout),
doir::system::breadth_first(doir::opt::inline_functions),
// doir::system::print(std::cout),
doir::system::breadth_first(std::bind(doir::opt::compute_compiler_namespace, _1, _2, true))
// doir::system::sorted(doir::system::bind_root(doir::opt::materialize_aliases))
);
auto opt_schedule = ecrs::system::sequential(
// doir::system::print(std::cout),
doir::system::fixed_point(
doir::system::depth_first(std::bind(doir::opt::mizu::comptime_evaluate, _1, _2, std::ref(mizu_schedule)))
),
// doir::system::print(std::cout),
doir::system::breadth_first(doir::opt::strip_freestanding_blocks),
mizu_schedule
);
;
sema_schedule(mod);
if(doir::diagnostics().count() > 0) {
doir::diagnostics().print_all();
if(doir::diagnostics().has_errors()) return -1;
}
opt_schedule(mod);
if(doir::diagnostics().count() > 0) {
doir::diagnostics().print_all();
if(doir::diagnostics().has_errors()) return -1;
}
// 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, doir::canonicalize::new_root);
std::ofstream fout("res.bin", std::ios::binary);
fout.write((char*)bytes.data(), bytes.size());
}
}