From 56f4f48c47983432670d7aaa18614a98bd35961a Mon Sep 17 00:00:00 2001
From: Antti Ajanki <antti.ajanki@iki.fi>
Date: Sat, 18 May 2013 11:36:52 +0300
Subject: [PATCH 01/29] Support for LLVM 3.3

---
 conf/FindLLVM.cmake            |  6 ++++++
 src/scripting/abc.cpp          | 15 +++++++++++----
 src/scripting/abc_codesynt.cpp | 25 ++++++++++++++++++-------
 3 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/conf/FindLLVM.cmake b/conf/FindLLVM.cmake
index ab8f95d..c94d7d4 100644
--- a/conf/FindLLVM.cmake
+++ b/conf/FindLLVM.cmake
@@ -53,6 +53,7 @@ else (LLVM_INCLUDE_DIR)
     /usr/lib/llvm-3.0/bin
     /usr/lib/llvm-3.1/bin
     /usr/lib/llvm-3.2/bin
+    /usr/lib/llvm-3.3/bin
     )
 
   find_program(LLVM_GCC_EXECUTABLE
@@ -170,11 +171,16 @@ else (LLVM_INCLUDE_DIR)
 
   set(CMAKE_REQUIRED_INCLUDES ${LLVM_INCLUDE_DIR})
   check_include_file_cxx("llvm/DataLayout.h" HAVE_DATALAYOUT_H)
+  check_include_file_cxx("llvm/IR/DataLayout.h" HAVE_IR_DATALAYOUT_H)
   unset(CMAKE_REQUIRED_INCLUDES)
   MESSAGE(STATUS "HAVE_DATALAYOUT_H: " ${HAVE_DATALAYOUT_H})
+  MESSAGE(STATUS "HAVE_IR_DATALAYOUT_H: " ${HAVE_IR_DATALAYOUT_H})
   IF(HAVE_DATALAYOUT_H)
     ADD_DEFINITIONS(-DHAVE_DATALAYOUT_H)
   ENDIF(HAVE_DATALAYOUT_H)
+  IF(HAVE_IR_DATALAYOUT_H)
+    ADD_DEFINITIONS(-DHAVE_IR_DATALAYOUT_H)
+  ENDIF(HAVE_IR_DATALAYOUT_H)
   
   exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --cxxflags  OUTPUT_VARIABLE LLVM_COMPILE_FLAGS )
   MESSAGE(STATUS "LLVM CXX flags: " ${LLVM_COMPILE_FLAGS})
diff --git a/src/scripting/abc.cpp b/src/scripting/abc.cpp
index 608fe01..49f2e06 100644
--- a/src/scripting/abc.cpp
+++ b/src/scripting/abc.cpp
@@ -23,12 +23,19 @@
 
 #include "compat.h"
 
-#include <llvm/Module.h>
 #include <llvm/ExecutionEngine/ExecutionEngine.h>
 #include <llvm/ExecutionEngine/JIT.h>
 #include <llvm/PassManager.h>
-#include <llvm/LLVMContext.h>
-#ifdef HAVE_DATALAYOUT_H
+#ifdef HAVE_IR_DATALAYOUT_H
+#  include <llvm/IR/Module.h>
+#  include <llvm/IR/LLVMContext.h>
+#else
+#  include <llvm/Module.h>
+#  include <llvm/LLVMContext.h>
+#endif
+#ifdef HAVE_IR_DATALAYOUT_H
+#  include <llvm/IR/DataLayout.h>
+#elif defined HAVE_DATALAYOUT_H
 #  include <llvm/DataLayout.h>
 #else
 #  include <llvm/Target/TargetData.h>
@@ -1516,7 +1523,7 @@ void ABCVm::Run(ABCVm* th)
 		assert_and_throw(th->ex);
 
 		th->FPM=new llvm::FunctionPassManager(th->module);
-#ifdef HAVE_DATALAYOUT_H
+#if defined HAVE_DATALAYOUT_H || defined HAVE_IR_DATALAYOUT_H
 		th->FPM->add(new llvm::DataLayout(*th->ex->getDataLayout()));
 #else
 		th->FPM->add(new llvm::TargetData(*th->ex->getTargetData()));
diff --git a/src/scripting/abc_codesynt.cpp b/src/scripting/abc_codesynt.cpp
index 2018be3..bb8e9a5 100644
--- a/src/scripting/abc_codesynt.cpp
+++ b/src/scripting/abc_codesynt.cpp
@@ -25,18 +25,29 @@
 #endif
 
 #include "compat.h"
-#include <llvm/Module.h>
-#include <llvm/DerivedTypes.h>
 #include <llvm/ExecutionEngine/ExecutionEngine.h>
 #include <llvm/PassManager.h>
-#include <llvm/Constants.h>
-#ifdef HAVE_IRBUILDER_H
+#ifdef HAVE_IR_DATALAYOUT_H
+#  include <llvm/IR/Constants.h>
+#  include <llvm/IR/DerivedTypes.h>
+#  include <llvm/IR/Module.h>
+#  include <llvm/IR/LLVMContext.h>
+#else
+#  include <llvm/Constants.h>
+#  include <llvm/DerivedTypes.h>
+#  include <llvm/Module.h>
+#  include <llvm/LLVMContext.h>
+#endif
+#ifdef HAVE_IR_DATALAYOUT_H
+#  include <llvm/IR/IRBuilder.h>
+#elif defined HAVE_IRBUILDER_H
 #  include <llvm/IRBuilder.h>
 #else
 #  include <llvm/Support/IRBuilder.h>
 #endif
-#include <llvm/LLVMContext.h>
-#ifdef HAVE_DATALAYOUT_H
+#ifdef HAVE_IR_DATALAYOUT_H
+#  include <llvm/IR/DataLayout.h>
+#elif defined HAVE_DATALAYOUT_H
 #  include <llvm/DataLayout.h>
 #else
 #  include <llvm/Target/TargetData.h>
@@ -279,7 +290,7 @@ void ABCVm::registerFunctions()
 	llvm::FunctionType* FT=NULL;
 
 	//Create types
-#ifdef HAVE_DATALAYOUT_H
+#if defined HAVE_DATALAYOUT_H || defined HAVE_IR_DATALAYOUT_H
 	ptr_type=ex->getDataLayout()->getIntPtrType(llvm_context());
 #else
 	ptr_type=ex->getTargetData()->getIntPtrType(llvm_context());
-- 
1.8.3