summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hir/expr_ptr.hpp10
-rw-r--r--src/main.cpp3
-rw-r--r--src/mir/from_hir.cpp83
-rw-r--r--src/mir/main_bindings.hpp14
4 files changed, 104 insertions, 6 deletions
diff --git a/src/hir/expr_ptr.hpp b/src/hir/expr_ptr.hpp
index d9f0982a..4ac4e86f 100644
--- a/src/hir/expr_ptr.hpp
+++ b/src/hir/expr_ptr.hpp
@@ -1,12 +1,15 @@
/*
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * hir/expr_ptr.hpp
+ * - HIR Expression
*/
#pragma once
#include <memory>
#include <vector>
-namespace MIR {
-class Function;
-}
+#include <mir/mir_ptr.hpp>
namespace HIR {
@@ -19,6 +22,7 @@ class ExprPtr
public:
::std::vector< ::HIR::TypeRef> m_bindings;
+ ::MIR::FunctionPointer m_mir;
public:
ExprPtr();
diff --git a/src/main.cpp b/src/main.cpp
index 2316358d..d13ec346 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -19,6 +19,7 @@
#include "hir_conv/main_bindings.hpp"
#include "hir_typeck/main_bindings.hpp"
#include "hir_expand/main_bindings.hpp"
+#include "mir/main_bindings.hpp"
#include "expand/cfg.hpp"
@@ -201,7 +202,7 @@ int main(int argc, char *argv[])
// Expand closures into items
// Lower expressions into MIR
CompilePhaseV("Lower MIR", [&]() {
- //ConvertHIR_MIR(hir_crate);
+ HIR_GenerateMIR(*hir_crate);
});
// Flatten modules into "mangled" set
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 25fd4295..c7ad57ac 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -2,15 +2,17 @@
* MRustC - Rust Compiler
* - By John Hodge (Mutabah/thePowersGang)
*
- * mir/from_hir.hpp
+ * mir/from_hir.cpp
* - Construction of MIR from the HIR expression tree
*/
#include <type_traits> // for TU_MATCHA
+#include <algorithm>
#include "mir.hpp"
#include "mir_ptr.hpp"
#include <hir/expr.hpp>
#include <hir/hir.hpp>
-#include <algorithm>
+#include <hir/visitor.hpp>
+#include "main_bindings.hpp"
namespace {
class ExprVisitor_Conv:
@@ -775,3 +777,80 @@ namespace {
return ::MIR::FunctionPointer(new ::MIR::Function(mv$(fcn)));
}
+namespace {
+ class OuterVisitor:
+ public ::HIR::Visitor
+ {
+ public:
+ OuterVisitor(const ::HIR::Crate& crate)
+ {}
+
+ // NOTE: This is left here to ensure that any expressions that aren't handled by higher code cause a failure
+ void visit_expr(::HIR::ExprPtr& exp) {
+ BUG(Span(), "visit_expr hit in OuterVisitor");
+ }
+
+ void visit_type(::HIR::TypeRef& ty) override
+ {
+ TU_IFLET(::HIR::TypeRef::Data, ty.m_data, Array, e,
+ this->visit_type( *e.inner );
+ DEBUG("Array size " << ty);
+ if( e.size ) {
+ auto fcn = LowerMIR(e.size, {});
+ e.size.m_mir = mv$(fcn);
+ }
+ )
+ else {
+ ::HIR::Visitor::visit_type(ty);
+ }
+ }
+
+ // ------
+ // Code-containing items
+ // ------
+ void visit_function(::HIR::ItemPath p, ::HIR::Function& item) override {
+ if( item.m_code )
+ {
+ DEBUG("Function code " << p);
+ item.m_code.m_mir = LowerMIR(item.m_code, item.m_args);
+ }
+ else
+ {
+ DEBUG("Function code " << p << " (none)");
+ }
+ }
+ void visit_static(::HIR::ItemPath p, ::HIR::Static& item) override {
+ if( item.m_value )
+ {
+ DEBUG("`static` value " << p);
+ item.m_value.m_mir = LowerMIR(item.m_value, {});
+ }
+ }
+ void visit_constant(::HIR::ItemPath p, ::HIR::Constant& item) override {
+ if( item.m_value )
+ {
+ DEBUG("`const` value " << p);
+ item.m_value.m_mir = LowerMIR(item.m_value, {});
+ }
+ }
+ void visit_enum(::HIR::ItemPath p, ::HIR::Enum& item) override {
+ //auto enum_type = ::HIR::TypeRef(::HIR::CoreType::Isize);
+ for(auto& var : item.m_variants)
+ {
+ TU_IFLET(::HIR::Enum::Variant, var.second, Value, e,
+ //DEBUG("Enum value " << p << " - " << var.first);
+ //::std::vector< ::HIR::TypeRef> tmp;
+ //ExprVisitor_Extract ev(m_resolve, tmp, m_new_trait_impls);
+ //ev.visit_root(*e);
+ )
+ }
+ }
+ };
+}
+
+void HIR_GenerateMIR(::HIR::Crate& crate)
+{
+ OuterVisitor ov(crate);
+ ov.visit_crate( crate );
+}
+
diff --git a/src/mir/main_bindings.hpp b/src/mir/main_bindings.hpp
new file mode 100644
index 00000000..1ece8852
--- /dev/null
+++ b/src/mir/main_bindings.hpp
@@ -0,0 +1,14 @@
+/*
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * mir/main_bindings.hpp
+ * - main.cpp binding
+ */
+#pragma once
+
+namespace HIR {
+class Crate;
+}
+
+extern void HIR_GenerateMIR(::HIR::Crate& crate);