sammine-lang
Loading...
Searching...
No Matches
TypeConverter.h
Go to the documentation of this file.
1#pragma once
2#include "codegen/LLVMRes.h"
3#include "lex/Token.h"
4#include "typecheck/Types.h"
5#include "util/Utilities.h"
6#include <llvm/IR/DerivedTypes.h>
7#include <llvm/IR/Instructions.h>
8#include <llvm/IR/LLVMContext.h>
9#include <llvm/IR/Type.h>
10#include <map>
11
15namespace sammine_lang::AST {
16class TypeConverter {
17
18 llvm::LLVMContext &context;
19 std::map<std::string, llvm::StructType *> named_struct_types;
20 std::map<std::string, llvm::StructType *> named_enum_types;
21
22public:
23 llvm::Type *get_type(Type t);
24 llvm::Type *get_return_type(Type t);
25 llvm::FunctionType *get_closure_function_type(const FunctionType &ft);
26 llvm::CmpInst::Predicate get_cmp_func(Type a, Type b, TokenType tok);
27
28 void register_struct_type(const std::string &name,
29 llvm::StructType *llvm_type) {
30 named_struct_types[name] = llvm_type;
31 }
32 llvm::StructType *get_struct_type(const std::string &name) const {
33 auto it = named_struct_types.find(name);
34 if (it != named_struct_types.end())
35 return it->second;
36 return nullptr;
37 }
38
39 void register_enum_type(const std::string &name,
40 llvm::StructType *llvm_type) {
41 named_enum_types[name] = llvm_type;
42 }
43 llvm::StructType *get_enum_type(const std::string &name) const {
44 auto it = named_enum_types.find(name);
45 if (it != named_enum_types.end())
46 return it->second;
47 return nullptr;
48 }
49
50 TypeConverter(LLVMRes &resPtr) : context(*resPtr.Context.get()) {}
51};
52} // namespace sammine_lang::AST
Defined LLVMRes, which encapsulates the state of LLVM (Context, Modules, IRBuilder,...
Defines the token structure (TokenType, TokStream, TokenMap).
Defines the core Type system for Sammine.
Holds classes and functionalities for dealing with Error handling, source locations caching & indexin...
Definition Types.h:43
Definition LLVMRes.h:32
Definition Types.h:139