Created
March 30, 2013 14:07
-
-
Save vroad/1f2dcd2c37e03005a349 to your computer and use it in GitHub Desktop.
- Added CMakeLists.txt - Added an option to generate llvm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 79dfbdb0d3d26400c17453547b028a14c27c9f70 Mon Sep 17 00:00:00 2001 | |
From: vroad | |
Date: Sat, 30 Mar 2013 22:51:25 +0900 | |
Subject: [PATCH] - Added CMakeLists.txt - Added an option to generate llvm | |
bitcode | |
--- | |
CMakeLists.txt | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
src/Backend.cpp | 5 +++ | |
src/CMakeLists.txt | 22 ++++++++++++ | |
3 files changed, 129 insertions(+) | |
create mode 100644 CMakeLists.txt | |
create mode 100644 src/CMakeLists.txt | |
diff --git a/CMakeLists.txt b/CMakeLists.txt | |
new file mode 100644 | |
index 0000000..7022334 | |
--- /dev/null | |
+++ b/CMakeLists.txt | |
@@ -0,0 +1,102 @@ | |
+project(dragonegg) | |
+cmake_minimum_required(VERSION 2.8) | |
+ | |
+# Copyright (c) 2008-2010 Kent State University | |
+# Copyright (c) 2011-2012 Texas A&M University | |
+# | |
+# This file is distributed under the MIT License. See the accompanying file | |
+# LICENSE.txt or http://www.opensource.org/licenses/mit-license.php for terms | |
+# and conditions. | |
+ | |
+# FIXME: How do I find the version of GMP that I want to use? | |
+# What versions are available? | |
+ | |
+# NOTE: GMP prefix is understood to be the path to the root of the GMP | |
+# installation library. | |
+set(GMP_PREFIX "" CACHE PATH "The path to the prefix of a GMP installation") | |
+ | |
+find_path(GMP_INCLUDE_DIR gmp.h | |
+ PATHS ${GMP_PREFIX}/include /usr/include /usr/local/include) | |
+ | |
+find_library(GMP_LIBRARY NAMES gmp | |
+ PATHS ${GMP_PREFIX}/lib /usr/lib /usr/local/lib) | |
+ | |
+ | |
+if(GMP_INCLUDE_DIR AND GMP_LIBRARY) | |
+ get_filename_component(GMP_LIBRARY_DIR ${GMP_LIBRARY} PATH) | |
+ set(GMP_FOUND TRUE) | |
+endif() | |
+ | |
+if(GMP_FOUND) | |
+ if(NOT GMP_FIND_QUIETLY) | |
+ MESSAGE(STATUS "Found GMP: ${GMP_LIBRARY}") | |
+ endif() | |
+elseif(GMP_FOUND) | |
+ if(GMP_FIND_REQUIRED) | |
+ message(FATAL_ERROR "Could not find GMP") | |
+ endif() | |
+endif() | |
+ | |
+# find libcc1 | |
+set(LIBCC1_DIR "" CACHE PATH "The path to the prefix of a libcc1 installation") | |
+ | |
+find_library(LIBCC1_LIBRARY NAMES cc1 | |
+ PATHS ${LIBCC1_DIR} /usr/lib /usr/local/lib) | |
+ | |
+if(LIBCC1_LIBRARY) | |
+ get_filename_component(CC1_LIBRARY_DIR ${LIBCC1_LIBRARY} PATH) | |
+ set(LIBCC1_FOUND TRUE) | |
+endif() | |
+ | |
+if(LIBCC1_FOUND) | |
+ if(NOT LIBCC1_FIND_QUIETLY) | |
+ MESSAGE(STATUS "Found libgcc: ${LIBGCC_LIBRARY}") | |
+ endif() | |
+else() | |
+ MESSAGE(SEND_ERROR "Could not find libcc1") | |
+endif() | |
+ | |
+include_directories(${GOBJECT_INCLUDE_DIR}) | |
+ | |
+# A convenience variable: | |
+set(LLVM_ROOT "" CACHE PATH "Root of LLVM install.") | |
+ | |
+# A bit of a sanity check: | |
+if( NOT EXISTS ${LLVM_ROOT}/include/llvm ) | |
+message(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install") | |
+endif() | |
+ | |
+# We incorporate the CMake features provided by LLVM: | |
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT}/share/llvm/cmake") | |
+include(LLVMConfig) | |
+ | |
+if (CMAKE_COMPILER_IS_GNUCC) | |
+ execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion | |
+ OUTPUT_VARIABLE GCC_VERSION) | |
+ string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION}) | |
+ list(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR) | |
+ list(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR) | |
+ list(GET GCC_VERSION_COMPONENTS 2 GCC_MICRO) | |
+ | |
+ message(STATUS ${GCC_MAJOR}) | |
+ message(STATUS ${GCC_MINOR}) | |
+ message(STATUS ${GCC_MICRO}) | |
+endif() | |
+ | |
+# Now set the header and library paths: | |
+include_directories( ${LLVM_INCLUDE_DIRS} ) | |
+link_directories( ${LLVM_LIBRARY_DIRS} ) | |
+add_definitions( ${LLVM_DEFINITIONS} -Wall -Wextra -fvisibility=hidden -fno-rtti | |
+ -MD -MP | |
+ -DIN_GCC -DLLVM_VERSION="${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}" | |
+ -DTARGET_TRIPLE="${TARGET_TRIPLE}" | |
+ -DGCC_MAJOR=${GCC_MAJOR} -DGCC_MINOR=${GCC_MINOR} | |
+ -DGCC_MICRO=${GCC_MICRO}) | |
+ | |
+# Specify the libraries we want to link with | |
+llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES ipo x86codegen x86asmparser bitwriter) | |
+ | |
+include_directories(include/linux) | |
+include_directories(include/x86) | |
+ | |
+add_subdirectory(src) | |
\ No newline at end of file | |
diff --git a/src/Backend.cpp b/src/Backend.cpp | |
index 4900a07..cb5064b 100644 | |
--- a/src/Backend.cpp | |
+++ b/src/Backend.cpp | |
@@ -128,6 +128,7 @@ static bool DebugPassStructure; | |
static bool EnableGCCOptimizations; | |
static bool EmitIR; | |
static bool EmitObj; | |
+static bool EmitLLVM; | |
static bool SaveGCCOutput; | |
static int LLVMCodeGenOptimizeArg = -1; | |
static int LLVMIROptimizeArg = -1; | |
@@ -729,6 +730,9 @@ static void createPerModuleOptimizationPasses() { | |
// -emit-llvm -S to the GCC driver. | |
InitializeOutputStreams(false); | |
PerModulePasses->add(createPrintModulePass(OutStream)); | |
+ } else if (EmitLLVM) { | |
+ InitializeOutputStreams(true); | |
+ PerModulePasses->add(createBitcodeWriterPass(*OutStream)); | |
} else { | |
// If there are passes we have to run on the entire module, we do codegen | |
// as a separate "pass" after that happens. | |
@@ -2037,6 +2041,7 @@ static FlagDescriptor PluginFlags[] = { | |
{ "debug-pass-arguments", &DebugPassArguments }, | |
{ "enable-gcc-optzns", &EnableGCCOptimizations }, { "emit-ir", &EmitIR }, | |
{ "emit-obj", &EmitObj }, | |
+ { "emit-llvm", &EmitLLVM }, | |
{ "save-gcc-output", &SaveGCCOutput }, { NULL, NULL } // Terminator. | |
}; | |
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt | |
new file mode 100644 | |
index 0000000..af04dd6 | |
--- /dev/null | |
+++ b/src/CMakeLists.txt | |
@@ -0,0 +1,22 @@ | |
+include_directories(../include) | |
+include_directories(${GMP_INCLUDE_DIR}) | |
+ | |
+add_library(dragonegg SHARED | |
+ Aliasing.cpp | |
+ Backend.cpp | |
+ bits_and_bobs.cpp | |
+ Cache.cpp | |
+ ConstantConversion.cpp | |
+ Convert.cpp | |
+ Debug.cpp | |
+ DefaultABI.cpp | |
+ Trees.cpp | |
+ TypeConversion.cpp | |
+ x86/Target.cpp | |
+ ../utils/TargetInfo.cpp | |
+) | |
+ | |
+# Finally, we link the LLVM libraries to our executable: | |
+target_link_libraries(dragonegg ${REQ_LLVM_LIBRARIES} ${GMP_LIBRARY_NAMES} ${LIBCC1_LIBRARY}) | |
+ | |
+set_target_properties(dragonegg PROPERTIES PREFIX "") | |
\ No newline at end of file | |
-- | |
1.8.1.msysgit.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment