Permalink
Browse files

Initial checkin - pulled the LLVM frontend out from the existing Firt…

…ree code

and wrote a simple tool, kernel2llvm, to test it.
  • Loading branch information...
Rich Wareham
Rich Wareham committed Jun 2, 2009
0 parents commit f356e16d54dfed4b42e3b5556082c72f2f2c32ec
Showing with 8,061 additions and 0 deletions.
  1. +9 −0 .bzrignore
  2. +45 −0 CMakeLists.txt
  3. +339 −0 LICENSE
  4. +76 −0 cmake/Modules/FindLLVM.cmake
  5. +64 −0 cmake/Modules/FindStyx.cmake
  6. +58 −0 cmake/Modules/UseStyx.cmake
  7. +13 −0 common/CMakeLists.txt
  8. +236 −0 common/common.cpp
  9. +232 −0 common/common.h
  10. +61 −0 llvm-frontend/CMakeLists.txt
  11. +242 −0 llvm-frontend/builtins.h
  12. +173 −0 llvm-frontend/llvm-compiled-kernel.h
  13. +550 −0 llvm-frontend/llvm_compiled_kernel.cc
  14. +117 −0 llvm-frontend/llvm_emit_binop_arith.cc
  15. +137 −0 llvm-frontend/llvm_emit_binop_assign.cc
  16. +212 −0 llvm-frontend/llvm_emit_binop_cmp.cc
  17. +145 −0 llvm-frontend/llvm_emit_binop_logic.cc
  18. +306 −0 llvm-frontend/llvm_emit_constant.cc
  19. +77 −0 llvm-frontend/llvm_emit_constant.h
  20. +741 −0 llvm-frontend/llvm_emit_decl.cc
  21. +78 −0 llvm-frontend/llvm_emit_decl.h
  22. +91 −0 llvm-frontend/llvm_emit_expr_list.cc
  23. +339 −0 llvm-frontend/llvm_emit_function_call.cc
  24. +196 −0 llvm-frontend/llvm_emit_loop.cc
  25. +131 −0 llvm-frontend/llvm_emit_negate.cc
  26. +103 −0 llvm-frontend/llvm_emit_return.cc
  27. +126 −0 llvm-frontend/llvm_emit_selection.cc
  28. +300 −0 llvm-frontend/llvm_emit_swizzle.cc
  29. +160 −0 llvm-frontend/llvm_emit_unary_incdec.cc
  30. +135 −0 llvm-frontend/llvm_emit_variable.cc
  31. +182 −0 llvm-frontend/llvm_emit_variable_declaration.cc
  32. +188 −0 llvm-frontend/llvm_expression.cc
  33. +202 −0 llvm-frontend/llvm_expression.h
  34. +332 −0 llvm-frontend/llvm_frontend.cc
  35. +288 −0 llvm-frontend/llvm_frontend.h
  36. +244 −0 llvm-frontend/llvm_private.h
  37. +336 −0 llvm-frontend/llvm_type_cast.cc
  38. +53 −0 llvm-frontend/llvm_type_cast.h
  39. +45 −0 llvm-frontend/prodnames.incl
  40. +28 −0 llvm-frontend/styx-parser/CMakeLists.txt
  41. +422 −0 llvm-frontend/styx-parser/firtree.sty
  42. +78 −0 llvm-frontend/symbol_table.cc
  43. +12 −0 tools/CMakeLists.txt
  44. +159 −0 tools/kernel2llvm.cc
@@ -0,0 +1,9 @@
+CMakeCache.txt
+CMakeFiles
+Makefile
+cmake_install.cmake
+llvm-frontend/styx-parser/firtree_*
+llvm-frontend/styx-parser/firtree.abs
+llvm-frontend/styx-parser/ctoh.cth
+
+tools/kernel2llvm
@@ -0,0 +1,45 @@
+# CMake project file for firtree
+#
+# Copyright (C) 2009 Rich Wareham <richwareham@gmail.com>
+#
+# See LICENSE file for distribution rights.
+
+# The name of this project is 'Firtree'.
+project(Firtree)
+
+# Set the minimum CMake version
+cmake_minimum_required(VERSION 2.6)
+
+# Update the module path to include any extra CMake modiles we might ship.
+set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
+
+# We use pkg-config to fing glib et al
+find_package(PkgConfig)
+
+# Set some variables indicating the version number of Firtree.
+set(FIRTREE_VERSION_MAJOR "0")
+set(FIRTREE_VERSION_MINOR "1")
+set(FIRTREE_VERSION_PATCH "0")
+set(FIRTREE_VERSION "${FIRTREE_VERSION_MAJOR}.${FIRTREE_VERSION_MINOR}.${FIRTREE_VERSION_PATCH}")
+
+set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -pthread)
+set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -pthread)
+
+# Add the root source dir as an include dir
+include_directories("${CMAKE_SOURCE_DIR}")
+
+# Find glib et al
+pkg_check_modules(GLIB REQUIRED glib-2.0)
+include_directories(${GLIB_INCLUDE_DIRS})
+
+# Build the common C++ support libraries
+add_subdirectory(common)
+
+# Build the Kernel language -> LLVM frontend.
+add_subdirectory(llvm-frontend)
+
+# Build the example command line tools
+add_subdirectory(tools)
+
+# vim:sw=4:ts=4:autoindent:et
+
339 LICENSE

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,76 @@
+# - Find LLVM
+# Set the following variables on entry
+#
+# LLVM_CONFIG_COMPONENTS (optional) - list of components to use.
+#
+# This module finds an installed LLVM. It sets the following variables:
+# LLVM_FOUND - set to true if LLVM is found
+# LLVM_VERSION - set to the LLVM version.
+# LLVM_MAJOR - set to the LLVM major version number.
+# LLVM_MINOR - set to the LLVM minor version number.
+# LLVM_CONFIG_EXECUTABLE - the path to the llvm-config executable
+# LLVM_AS_EXECUTABLE - the path to the llvm-as executable
+# LLVM_OPT_EXECUTABLE - the path to the llvm opt executable
+# LLVM_HOST_TARGET - Target triple used to configure LLVM.
+# LLVM_INCLUDE_DIR - where to find the LLVM headers.
+# LLVM_LIBRARY_DIR - the LLVM library directory
+# LLVM_LIBRARIES - the LLVM libraries to link against.
+#
+
+FIND_PROGRAM(LLVM_CONFIG_EXECUTABLE llvm-config)
+FIND_PROGRAM(LLVM_AS_EXECUTABLE llvm-as)
+FIND_PROGRAM(LLVM_OPT_EXECUTABLE opt)
+
+MACRO(LLVM_RUN_CONFIG arg outvar)
+ EXECUTE_PROCESS(COMMAND "${LLVM_CONFIG_EXECUTABLE}" ${LLVM_CONFIG_COMPONENTS} "${arg}"
+ OUTPUT_VARIABLE ${outvar}
+ ERROR_VARIABLE LLVM_llvm_config_error
+ RESULT_VARIABLE LLVM_llvm_config_result)
+ IF(LLVM_llvm_config_result)
+ MESSAGE(SEND_ERROR "Command \"${LLVM_CONFIG_EXECUTABLE} ${arg}\" failed with output:\n${LLVM_llvm_config_error}")
+ ENDIF(LLVM_llvm_config_result)
+ENDMACRO(LLVM_RUN_CONFIG)
+
+IF(LLVM_CONFIG_EXECUTABLE)
+ LLVM_RUN_CONFIG("--version" LLVM_VERSION)
+ LLVM_RUN_CONFIG("--libdir" LLVM_LIBRARY_DIR)
+ LLVM_RUN_CONFIG("--includedir" LLVM_INCLUDE_DIR)
+ LLVM_RUN_CONFIG("--libfiles" LLVM_LIBRARIES)
+ LLVM_RUN_CONFIG("--host-target" LLVM_HOST_TARGET)
+ STRING(REGEX REPLACE "[ \n\t]+" "" LLVM_HOST_TARGET ${LLVM_HOST_TARGET})
+ STRING(REGEX REPLACE "[ \n\t]+" "" LLVM_VERSION ${LLVM_VERSION})
+ STRING(REGEX REPLACE "[ \n\t]+" " " LLVM_LIBRARY_DIR ${LLVM_LIBRARY_DIR})
+ STRING(REGEX REPLACE "[ \n\t]+" " " LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR})
+ STRING(REGEX REPLACE "[ \n\t]+" " " LLVM_LIBRARIES ${LLVM_LIBRARIES})
+
+ STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\1" LLVM_MAJOR ${LLVM_VERSION})
+ STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\2" LLVM_MINOR ${LLVM_VERSION})
+
+ STRING(REGEX REPLACE "[^;\n\t ]+\\.o" "" LLVM_STATIC_LIBS ${LLVM_LIBRARIES})
+ STRING(REGEX REPLACE "[^;\n\t ]+\\.a" "" LLVM_STATIC_OBJS ${LLVM_LIBRARIES})
+
+ SEPARATE_ARGUMENTS(LLVM_LIBRARIES)
+ SEPARATE_ARGUMENTS(LLVM_STATIC_LIBS)
+ SEPARATE_ARGUMENTS(LLVM_STATIC_OBJS)
+ENDIF(LLVM_CONFIG_EXECUTABLE)
+
+# Assume LLVM is found unless anything indicates otherwise
+SET( LLVM_FOUND "YES" )
+
+IF(NOT LLVM_CONFIG_EXECUTABLE)
+ SET( LLVM_FOUND "NO" )
+ENDIF(NOT LLVM_CONFIG_EXECUTABLE)
+
+IF(NOT LLVM_LIBRARY_DIR)
+ SET( LLVM_FOUND "NO" )
+ENDIF(NOT LLVM_LIBRARY_DIR)
+
+IF(NOT LLVM_INCLUDE_DIR)
+ SET( LLVM_FOUND "NO" )
+ENDIF(NOT LLVM_INCLUDE_DIR)
+
+IF(NOT LLVM_LIBRARIES)
+ SET( LLVM_FOUND "NO" )
+ENDIF(NOT LLVM_LIBRARIES)
+
+# vim:sw=2:ts=2:et
@@ -0,0 +1,64 @@
+# - Find Styx
+# This module finds an installed Styx grammar parser and associated
+# utilities. It sets the following variables:
+# STYX_FOUND - set to true if Styx is found
+# STYX_EXECUTABLE - the path to the styx executable
+# STYX_CTOH_EXECUTABLE - the path to styx's ctoh executable
+# STYX_INCLUDE_DIR - where to find the styx headers.
+# STYX_LIBRARIES - the styx libraries to link against.
+# STYX_LIBRARY_DIR - the styx library directory
+#
+# Set STYX_USE_STATIC_LIBS to TRUE to use static libs.
+
+# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
+IF( STYX_USE_STATIC_LIBS )
+ SET( _styx_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ SET( _styx_ORIG_CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES})
+ SET( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX} )
+ SET( CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_STATIC_LIBRARY_PREFIX} )
+ENDIF( STYX_USE_STATIC_LIBS )
+
+FIND_PROGRAM(STYX_EXECUTABLE styx)
+FIND_PROGRAM(STYX_CTOH_EXECUTABLE ctoh)
+FIND_PATH(STYX_INCLUDE_DIR ptm.h
+ /usr/include/styx
+ /usr/local/include/styx
+ /opt/local/include/styx
+)
+FIND_LIBRARY(STYX_dstyx_LIBRARY dstyx
+ /usr/lib
+ /usr/local/lib
+ /opt/local/lib
+)
+
+IF( STYX_USE_STATIC_LIBS )
+ SET( CMAKE_FIND_LIBRARY_SUFFIXES ${_styx_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES} )
+ SET( CMAKE_FIND_LIBRARY_PREFIXES ${_styx_ORIG_CMAKE_FIND_LIBRARY_PREFIXES} )
+ENDIF( STYX_USE_STATIC_LIBS )
+
+# Assume Styx is found unless anything indicates otherwise
+SET( STYX_FOUND "YES" )
+
+IF(NOT STYX_EXECUTABLE)
+ SET( STYX_FOUND "NO" )
+ENDIF(NOT STYX_EXECUTABLE)
+
+IF(NOT STYX_CTOH_EXECUTABLE)
+ SET( STYX_FOUND "NO" )
+ENDIF(NOT STYX_CTOH_EXECUTABLE)
+
+IF(NOT STYX_INCLUDE_DIR)
+ SET( STYX_FOUND "NO" )
+ENDIF(NOT STYX_INCLUDE_DIR)
+
+SET( STYX_LIBRARIES "" )
+
+IF(STYX_dstyx_LIBRARY)
+ SET( STYX_LIBRARIES
+ ${STYX_LIBRARIES}
+ ${STYX_dstyx_LIBRARY}
+ )
+ GET_FILENAME_COMPONENT(STYX_LIBRARY_DIR ${STYX_dstyx_LIBRARY} PATH)
+ELSE(STYX_dstyx_LIBRARY)
+ SET( STYX_FOUND "NO" )
+ENDIF(STYX_dstyx_LIBRARY)
@@ -0,0 +1,58 @@
+# - Use Styx
+
+# WARNING! Due to the nature of the styx ctoh program it will DELETE
+# all files of the form *.h in the source directory. Ideally all of your
+# styx sources should be in their own directory to guard against this.
+
+MACRO(_styx_find_package)
+ FIND_PACKAGE(Styx)
+
+ IF(NOT STYX_FOUND)
+ MESSAGE(FATAL_ERROR "Styx (http://speculate.de/) is required.")
+ ENDIF(NOT STYX_FOUND)
+ENDMACRO(_styx_find_package)
+
+MACRO(add_styx_grammars)
+ _styx_find_package()
+
+ FOREACH(_grammar_FILE ${ARGV})
+ MESSAGE(STATUS "Generating grammar from Styx source ${_grammar_FILE}.")
+
+ GET_FILENAME_COMPONENT(_absolute ${_grammar_FILE} ABSOLUTE)
+ GET_FILENAME_COMPONENT(_path ${_absolute} PATH)
+ GET_FILENAME_COMPONENT(_base ${_absolute} NAME_WE)
+
+ ADD_CUSTOM_COMMAND(
+ OUTPUT
+ "${_path}/${_base}_int.c" "${_path}/${_base}_pim.c"
+ "${_path}/${_base}_lim.c" "${_path}/${_base}.abs"
+ COMMAND
+ ${STYX_EXECUTABLE}
+ ARGS
+ -makeC "${_base}"
+ WORKING_DIRECTORY
+ "${_path}"
+ DEPENDS
+ "${_grammar_FILE}"
+ )
+
+ ADD_CUSTOM_COMMAND(
+ OUTPUT
+ "${_path}/${_base}_int.h" "${_path}/${_base}_pim.h"
+ "${_path}/${_base}_lim.h" "${_path}/ctoh.cth"
+ COMMAND
+ ${STYX_CTOH_EXECUTABLE}
+ ARGS
+ "-CPATH=${_path}"
+ "-HPATH=${_path}"
+ "-PRJ=${_path}"
+ WORKING_DIRECTORY
+ "${_path}"
+ DEPENDS
+ "${_path}/${_base}_int.c" "${_path}/${_base}_pim.c"
+ "${_path}/${_base}_lim.c"
+ )
+ ENDFOREACH(_grammar_FILE)
+ENDMACRO(add_styx_grammars)
+
+# vim:sw=2:ts=2:et
@@ -0,0 +1,13 @@
+# CMake project file for firtree
+#
+# Copyright (C) 2009 Rich Wareham <richwareham@gmail.com>
+#
+# See LICENSE file for distribution rights.
+
+add_library(common
+ common.h common.cpp)
+
+target_link_libraries(common ${GLIB_LIBRARIES})
+
+# vim:sw=4:ts=4:autoindent:et
+
Oops, something went wrong.

0 comments on commit f356e16

Please sign in to comment.