From d5853c13b7c7159951b54af0c19f1416ad346871 Mon Sep 17 00:00:00 2001 From: Markus Hauschild Date: Sat, 1 Jun 2013 16:41:18 +0200 Subject: [PATCH] Types! --- inc/AST/Type.h | 2 ++ src/AST/CodeGenVisitor.cpp | 1 + src/AST/Type.cpp | 20 +++++++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/inc/AST/Type.h b/inc/AST/Type.h index b0b33ee..a570f41 100644 --- a/inc/AST/Type.h +++ b/inc/AST/Type.h @@ -1,10 +1,12 @@ #ifndef TYPE_H #define TYPE_H +#include "llvm/Type.h" #include enum class Type { BOOL, INT, STRING, VOID }; std::string typeToString(Type type); +llvm::Type* typeToLLVMType(Type type); #endif // TYPE_H diff --git a/src/AST/CodeGenVisitor.cpp b/src/AST/CodeGenVisitor.cpp index 3dffdce..0c466a8 100644 --- a/src/AST/CodeGenVisitor.cpp +++ b/src/AST/CodeGenVisitor.cpp @@ -88,6 +88,7 @@ void CodeGenVisitor::visit(FunctionCallExpression* e) { } void CodeGenVisitor::visit(FunctionDefinition* e) { + //std::vector types; } void CodeGenVisitor::visit(IfStatement* e) { diff --git a/src/AST/Type.cpp b/src/AST/Type.cpp index b62669d..a875912 100644 --- a/src/AST/Type.cpp +++ b/src/AST/Type.cpp @@ -1,4 +1,6 @@ #include "AST/Type.h" +#include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" std::string typeToString(Type type) { switch (type) { @@ -12,5 +14,21 @@ std::string typeToString(Type type) { return "void"; default: return "ERROR"; - } + } +} + +llvm::Type* typeToLLVMType(Type type) { + switch (type) { + case Type::BOOL: + return llvm::Type::getInt1Ty(llvm::getGlobalContext()); + case Type::INT: + return llvm::Type::getInt32Ty(llvm::getGlobalContext()); + case Type::STRING: + return llvm::Type::getInt8PtrTy(llvm::getGlobalContext()); + case Type::VOID: + return llvm::Type::getVoidTy(llvm::getGlobalContext()); + default: + // TODO error + return llvm::Type::getVoidTy(llvm::getGlobalContext()); + } }