blob: d19ea9d3630e1f735d84f3f15d77669699803514 (
plain)
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
|
/**
** \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
|