forked from KPGPMC/furlang
91ef7f01a4
Signed-off-by: CHatingPython <chatingpython@gmail.com>
34 lines
984 B
C++
34 lines
984 B
C++
// #ifndef LIBFURC
|
|
|
|
#include "furc/front/ir_generator.hpp"
|
|
#include "furc/front/parser.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
int main(void) {
|
|
furc::front::parser parser("<TEMP>", "func main() {\n if (1) return 7 + 6 * 10; else return 0;\n}");
|
|
furc::front::ir_generator generator;
|
|
|
|
auto program = parser.parse();
|
|
if (program.has_error()) {
|
|
std::cerr << program << '\n';
|
|
}
|
|
program->accept(generator);
|
|
|
|
auto module = std::move(generator.move_module());
|
|
std::cout << "Generated IR:\n";
|
|
for (const auto& function : module.functions()) {
|
|
std::cout << function->name() << ":\n";
|
|
furlang::ir::block_index blockIndex = 0;
|
|
for (const auto& block : function->blocks()) {
|
|
std::cout << " # block " << blockIndex++ << '\n';
|
|
for (const auto& instruction : block->instructions()) {
|
|
std::cout << " " << *instruction << '\n';
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
// #endif // LIBFURC
|