summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/llvmtranslate/llvm-type-visitor.hh
diff options
context:
space:
mode:
Diffstat (limited to 'tiger-compiler/src/llvmtranslate/llvm-type-visitor.hh')
-rw-r--r--tiger-compiler/src/llvmtranslate/llvm-type-visitor.hh50
1 files changed, 50 insertions, 0 deletions
diff --git a/tiger-compiler/src/llvmtranslate/llvm-type-visitor.hh b/tiger-compiler/src/llvmtranslate/llvm-type-visitor.hh
new file mode 100644
index 0000000..d19ea9d
--- /dev/null
+++ b/tiger-compiler/src/llvmtranslate/llvm-type-visitor.hh
@@ -0,0 +1,50 @@
+/**
+ ** \file llvmtranslate/llvm-type-visitor.hh
+ ** \brief Definition of llvmtranslator::LLVMTypeVisitor.
+ */
+
+#pragma once
+
+#include <llvm/IR/LLVMContext.h>
+
+#include <llvmtranslate/fwd.hh>
+#include <type/default-visitor.hh>
+
+namespace llvmtranslate
+{
+ /// Visit a Type and return the corresponding llvm::Type.
+ class LLVMTypeVisitor : public type::DefaultConstVisitor
+ {
+ public:
+ using super_type = type::DefaultConstVisitor;
+ // Import overloaded virtual functions.
+ using super_type::operator();
+
+ LLVMTypeVisitor(llvm::LLVMContext& ctx);
+
+ llvm::Type* llvm_type_get();
+ llvm::Type* get_record_ltype(const type::Record* e);
+
+ /// Visit methods.
+ /// \{
+ void operator()(const type::Nil& e) override;
+ void operator()(const type::Void& e) override;
+ void operator()(const type::Int& e) override;
+ void operator()(const type::String& e) override;
+ void operator()(const type::Named& e) override;
+ void operator()(const type::Record& e) override;
+ void operator()(const type::Array& e) override;
+ /// \}
+
+ private:
+ /// The global context.
+ llvm::LLVMContext& ctx_;
+ /// The type of the last visited node.
+ llvm::Type* type_ = nullptr;
+ /// llvm::StructTypes for each type::Record
+ std::map<const type::Record*, llvm::StructType*> structs_;
+ /// Recurse and return the type_.
+ llvm::Type* llvm_type(const type::Type& type);
+ };
+
+} // namespace llvmtranslate