From 6725cbaf88258327ec8188c01cedc2b0bbe9c36d Mon Sep 17 00:00:00 2001 From: Stefano Sanfilippo Date: Sat, 7 Mar 2015 14:10:49 +0100 Subject: [PATCH] Implementing MonicelliType, refactoring LLVMType. --- BitcodeEmitter.cpp | 59 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/BitcodeEmitter.cpp b/BitcodeEmitter.cpp index b2671f2..7786088 100644 --- a/BitcodeEmitter.cpp +++ b/BitcodeEmitter.cpp @@ -51,24 +51,6 @@ struct BitcodeEmitter::Private { Scope scope; }; -static -llvm::Type *LLVMType(Type const& type) { - switch (type) { - case Type::INT: - return llvm::Type::getInt64Ty(getGlobalContext()); - case Type::CHAR: - return llvm::Type::getInt8Ty(getGlobalContext()); - case Type::FLOAT: - return llvm::Type::getFloatTy(getGlobalContext()); - case Type::BOOL: - return llvm::Type::getInt1Ty(getGlobalContext()); - case Type::DOUBLE: - return llvm::Type::getDoubleTy(getGlobalContext()); - case Type::VOID: - return llvm::Type::getVoidTy(getGlobalContext()); - } -} - static llvm::AllocaInst* allocateVar(llvm::Function *func, Id const& name, llvm::Type *type) { llvm::IRBuilder<> builder(&func->getEntryBlock(), func->getEntryBlock().begin()); @@ -99,6 +81,7 @@ bool reportError(std::initializer_list const& what) { #define I1 llvm::Type::getInt1Ty(getGlobalContext()) #define F llvm::Type::getFloatTy(getGlobalContext()) #define D llvm::Type::getDoubleTy(getGlobalContext()) +#define V llvm::Type::getVoidTy(getGlobalContext()) static const std::unordered_map> TYPECAST_MAP = { {I64, { {I8, I64}, {I1, I64}, { F, D}, {D, D}}}, @@ -108,6 +91,45 @@ static const std::unordered_mapgetType(); @@ -129,6 +151,7 @@ llvm::Type* deduceResultType(llvm::Value *left, llvm::Value *right) { #undef I1 #undef F #undef D +#undef V static inline bool isFP(llvm::Type *type) {