Implement basic IR generator

Signed-off-by: CHatingPython <chatingpython@gmail.com>
This commit is contained in:
CHatingPython
2026-05-31 16:15:53 +02:00
committed by CHatingPython
parent f431d9b725
commit 646d185d40
8 changed files with 324 additions and 6 deletions
+24 -4
View File
@@ -1,14 +1,34 @@
#ifndef LIBFURC
// #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 return x = y;\n}");
std::cout << parser.parse() << '\n';
furc::front::parser parser("<TEMP>", "func main() {\n return 7 + 6 * 10;\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
// #endif // LIBFURC