Skip to content

Commit

Permalink
Merge pull request #41 from jberlin/master
Browse files Browse the repository at this point in the history
support for type checking and compiling expressions using LLVM
  • Loading branch information
jberlin committed Jul 1, 2016
2 parents a5f02bb + 6d170df commit 6a746ff
Show file tree
Hide file tree
Showing 260 changed files with 29,856 additions and 14,903 deletions.
34 changes: 34 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
BasedOnStyle: "Google"
AccessModifierOffset: -2
AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: true
ConstructorInitializerIndentWidth: 4
AllowShortLoopsOnASingleLine: true
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackParameters: false
BreakBeforeBraces: Attach
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Cpp11BracedListStyle: true
IndentCaseLabels: true
IndentFunctionDeclarationAfterType: true
IndentWidth: 4
MaxEmptyLinesToKeep: 1
SpaceAfterControlStatementKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
UseTab: Never
PointerBindsToType: true
#DerivePointerAlignment: false
#AllowShortCaseLabelsOnASingleLine: true

...
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
*~
.DS_Store
/build
/Linux-*
/Darwin-*
*#*#
*~
CMakeCache.txt
src/SeExpr/parser
src/SeExpr/generated
2 changes: 1 addition & 1 deletion .workonrc.products
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SeExpr
seexpr2
128 changes: 110 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright Disney Enterprises, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,13 +15,59 @@

## CMake compatibility issues: don't modify this, please!
CMAKE_MINIMUM_REQUIRED( VERSION 2.4.6 )
PROJECT (SeExpr2)
MARK_AS_ADVANCED(CMAKE_BACKWARDS_COMPATIBILITY)
## allow more human readable "if then else" constructs
SET( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE )
## Use verbose make file
SET ( CMAKE_VERBOSE_MAKEFILE TRUE )


# Configuration options
# TODO: find GTEST and boost and python the proper ways
SET (LIBDIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "lib or lib64") # defaults to lib but if it s lib64 ok
SET (BOOST_DIR $ENV{RP_boost_disney} CACHE PATH "where boost is located")
SET (BOOST_PYTHON_LIBNAME boost_python CACHE STRING "what library name for boost python")
SET (GTEST_DIR /usr/include CACHE PATH "Where to find GTEST") # /usr/include/gtest)
SET (ENABLE_LLVM_BACKEND ON CACHE BOOL "Whether to build with LLVM backend")
SET (USE_PYTHON ON CACHE BOOL "Whether to compile python libraries")

if (ENABLE_LLVM_BACKEND)
SET (LLVM_DIR /usr/share/llvm/cmake CACHE PATH "Where to search for LLVM i.e. ")

FIND_PACKAGE(LLVM CONFIG NAMES LLVM CONFIGS LLVM-Config.cmake)
if(LLVM_FOUND)
set(SEEXPR_ENABLE_LLVM_BACKEND 1)
message(STATUS "Using LLVM-Config.cmake in: ${LLVM_DIR}")
find_program(LLVM_CONFIG_EXECUTABLE NAMES llvm-config)

# Uncomment to use clang++
#set(CMAKE_CXX_COMPILER clang++)
#set(CMAKE_C_COMPILER clang)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_DIR}")
include(LLVM-Config)
include(HandleLLVMOptions)

add_definitions( ${LLVM_DEFINITIONS} )
message(STATUS "LLVM_DEFINITIONS =" ${LLVM_DEFINITIONS})

execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --ldflags
OUTPUT_VARIABLE LLVM_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "LLVM_LDFLAGS = " ${LLVM_LDFLAGS})

include_directories(${LLVM_INCLUDE_DIRS})
message(status "LLVM_LIBRARY_DIR=" ${LLVM_LIBRARY_DIRS})
link_directories(${LLVM_LIBRARY_DIR})
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LLVM_LDFLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LLVM_LDFLAGS}")
else(LLVM_FOUND)
set(ENABLE_LLVM_BACKEND off)
set(SEEXPR_ENABLE_LLVM_BACKEND 0)
endif(LLVM_FOUND)
endif(ENABLE_LLVM_BACKEND)

## project name & version
PROJECT( SeExpr )
Expand All @@ -43,10 +88,15 @@ IF(WIN32)
include (GenerateExportHeader)
ADD_DEFINITIONS (-DSEEXPR_WIN32)
ELSE(WIN32)
ADD_DEFINITIONS (-Wall -Wextra)
ADD_DEFINITIONS (-Wall -Wextra -Wno-unused-parameter)
ADD_DEFINITIONS (-pthread)

SET( CMAKE_CXX_FLAGS "-fPIC -msse4.1")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -g -std=c++11 -msse4.1")
if(NOT APPLE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
else()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-date-time")
endif()
ENDIF(WIN32)

## Choose build options
Expand All @@ -57,13 +107,23 @@ ENDIF("$ENV{FLAVOR}" STREQUAL "optimize")
IF("$ENV{FLAVOR}" STREQUAL "debug")
SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "type of build" FORCE)
ENDIF("$ENV{FLAVOR}" STREQUAL "debug")

# Set to release if nothing else defined
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)

# --- DISNEY INTERNAL --- (use custom color picker)
IF(DEFINED ENV{RP_qdgui})
ADD_DEFINITIONS (-DSEEXPR_USE_QDGUI)
ENDIF(DEFINED ENV{RP_qdgui})

IF(DEFINED ENV{RP_animlib})
ADD_DEFINITIONS (-DSEEXPR_USE_ANIMLIB)
ENDIF(DEFINED ENV{RP_animlib})

IF(CMAKE_BUILD_TYPE STREQUAL "Release")
SET(FLAVORDIR "optimize")
ELSE(CMAKE_BUILD_TYPE STREQUAL "Release")
Expand All @@ -78,25 +138,57 @@ IF (NOT DEFINED CMAKE_INSTALL_PREFIX)
SET(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/${VARIANT_DIRECTORY}-${FLAVORDIR}")
ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)

## Install location for html documentation
SET( SEEXPR_HTML_DOC_PATH "share/doc/SeExpr" )

## Make modules able to see seexpr library
# Setup environment variable to link seexpr
SET( SEEXPR_LIBRARIES SeExpr )
SET( SEEXPR_EDITOR_LIBRARIES SeExprEditor )
SET( SEEXPR_LIBRARIES SeExpr2 )
SET( SEEXPR_LLVM_LIBRARIES SeExpr2LLVM )
SET( SEEXPR_EDITOR_LIBRARIES SeExpr2Editor )

# make it so seexpr can be found
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/SeExpr )
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/SeExprEditor )

# The library directory is configured by setting CMAKE_INSTALL_LIBDIR.
# Otherwise, the defaults set here are used.
IF(EXISTS "/usr/lib64" AND NOT IS_SYMLINK "/usr/lib64")
SET(CMAKE_INSTALL_LIBDIR "lib64" CACHE STRING "Library Directory Basename")
ELSE()
SET(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "Library Directory Basename")
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR}/include )
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR}/src/SeExpr )
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/src/SeExpr )
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/src/EditorUI )

# Allowing to use lib64
IF (NOT DEFINED CMAKE_INSTALL_LIBDIR)
SET(CMAKE_INSTALL_LIBDIR "lib")
ENDIF()

set(LLVM_LIB "")
IF(ENABLE_LLVM_BACKEND AND LLVM_FOUND)
#todo infinite loop in this?
#llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES jit native)

# construct library name
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --version
OUTPUT_VARIABLE LLVM_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
#set(LLVM_LIB "-lLLVM-${LLVM_VERSION}")
link_directories(${LLVM_LIBRARY_DIRS})
#set(LLVM_LIB ${LLVM_AVAILABLE_LIBS} -lLLVMSupport -lLLVMCodeGen -lLLVMCore) #"-lLLVMCore -lLLVMMCJIT -lLLVMExecutionEngine -lLL")
set(LLVM_LIB LLVM)
message(STATUS "LLVM library " ${LLVM_LIB})
message(STATUS "LLVM version " ${LLVM_VERSION})
if(LLVM_VERSION VERSION_LESS 3.8.0)
set(ENABLE_LLVM_BACKEND off)
set(SEEXPR_ENABLE_LLVM_BACKEND 0)
message(STATUS "Not building with LLVM, version must be >= 3.8.0")
endif(LLVM_VERSION VERSION_LESS 3.8.0)
ENDIF(ENABLE_LLVM_BACKEND AND LLVM_FOUND)


## Traverse subdirectories
ADD_SUBDIRECTORY (src/SeExpr)
ADD_SUBDIRECTORY (src/SeExprEditor)
ADD_SUBDIRECTORY (src/doc)
ADD_SUBDIRECTORY (src/demos)
ADD_SUBDIRECTORY (src/ui)
ADD_SUBDIRECTORY (src/tests)
#TODO: put this back
ADD_SUBDIRECTORY (src/py)
ADD_SUBDIRECTORY (src/utils)
ADD_SUBDIRECTORY (src/demos)
ADD_SUBDIRECTORY (src/doc)
59 changes: 35 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
#!/usr/bin/env make
SH ?= sh
uname_S := $(shell $(SH) -c 'uname -s || echo system')
uname_R := $(shell $(SH) -c 'uname -r | cut -d- -f1 || echo release')
uname_M := $(shell $(SH) -c 'uname -m || echo cpu')
-include Makefile.config

FLAVOR ?= optimize
prefix ?= $(shell pf-makevar --absolute root)
libdir ?= $(shell pf-makevar lib)

# TODO: when RHEL6 is fully retired remove th
# Don't set CXX when native GCC version is 4.8.
#SETCXX := $(shell expr `gcc -dumpversion` \< 4.8)
#ifeq "$(SETCXX)" "1"
# CXX=/opt/rh/devtoolset-2/root/usr/bin/g++
#endif


platformdir ?= $(uname_S)-$(uname_R)-$(uname_M)-$(FLAVOR)
builddir ?= $(CURDIR)/build/$(platformdir)
## Temporary staging directory
# DESTDIR =

prefix ?= $(CURDIR)/$(platformdir)
#DESTDIR =
# Specified by `git make-pkg` when building .pkg files
# mac_pkg =

CMAKE_FLAGS ?= -DCMAKE_INSTALL_PREFIX=$(prefix)
export prefix DESTDIR

# The default target in this Makefile is...
all::
all:
mkdir -p build/${FLAVOR}
export CXX=${CXX}
cd build/${FLAVOR} && CXX=${CXX} cmake -DCMAKE_INSTALL_PREFIX=$(prefix) -DCMAKE_INSTALL_LIBDIR=$(libdir) ${EXTRA_CMAKE_ARGS} ../../
$(MAKE) -C build/${FLAVOR} all
clean:
rm -rf build/${FLAVOR} Linux-*

install: all
$(MAKE) -C $(builddir) DESTDIR=$(DESTDIR) install
$(MAKE) -C build/${FLAVOR} install
pkgconfig-gen --name seexpr2 --desc 'SeExpr v2 Library' \
--generate --destdir '$(DESTDIR)' --prefix $(prefix) --libdir $(libdir)

$(builddir)/stamp: $(CMAKE_FILES)
mkdir -p $(builddir)
cd $(builddir) && cmake $(CMAKE_FLAGS) ../..
touch $@
test: install
python src/tests/imageTestsReportNew.py runall

all:: $(builddir)/stamp
$(MAKE) -C $(builddir) $(MAKEARGS) all
format:
find $(CURDIR)/src -name '*.cpp' | xargs clang-format -i
find $(CURDIR)/src -name '*.h' | xargs clang-format -i

clean: $(builddir)/stamp
$(MAKE) -C $(builddir) $(MAKEARGS) clean
basictest: install
$(prefix)/share/test/SeExpr2/testmain2 -- --gtest_filter="BasicTests.*"

.PHONY: all
.PHONY: clean
.PHONY: install
precommit: format
1 change: 1 addition & 0 deletions Makefile.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXTRA_CMAKE_ARGS= -DBOOST_DIR=${RP_boost_disney} -DGTEST_DIR=/usr/
5 changes: 5 additions & 0 deletions Makefile.example.mac.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BOOST=/usr/local
LLVM=~/code/llvm-inst/share/llvm/cmake
GTEST=~/code/gtest-inst/
CUSTOM_PYTHON_FRAMEWORK="-m64 -I/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/include/python2.7 -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -L/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config -lpython2.7 -ldl"
EXTRA_CMAKE_ARGS= -DENABLE_LLVM_BACKEND=ON -DLLVM_DIR=${LLVM} -DGTEST_DIR=${GTEST} -DBOOST_DIR=${BOOST} -DCUSTOM_PYTHON_FRAMEWORK=${CUSTOM_PYTHON_FRAMEWORK} -DUSE_PYTHON=OFF
45 changes: 45 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
asciiCalc evalStr() should not ignore return

SeExprNode
getStrArg() does not belong on base SeExprNode. We use this in SeExprPlugins, but there should be a better way of looking for that
// Do we need to check the value of string arg of custom function? Shouldn't
// it be done at runtime and fail in eval stage?

SeExprPlugins
Arguments for in tangent and out tangent don't check they are constant string. Also, do we want ot make this work
foo="constant"; animCurve(foo,"fds"); (i.e. the first argument is not a SeExprStr as your current code assumes)
// in tangent and out tangent are checked as varying string before. now changed to checked as constant string.

The trim function seems unused. Can we delete it?
// deleted.

PromoteBinaryOperands should perhaps return a std::pair of value*'s instead of mutating the incoming ones
// done

The prmoting of values for binary operands compares its arguments like 3 times. Maybe there is a way to clean that up
// isLegaltoPromote are now removed. It is simplified to check if destType is vector.

Is resolveLocalVar correct. What if it needs to look in a different basic block. What are the variable resolution rules?
// Are local var are alloca'd in entry basic block. Only when codegen assignment, local var may be alloca'd.
// case like $m = 1.0; $m=$m * [1,2,3] cause a new vector version of m to be alloca'd. No other cases incur local var alloca

Select does not work on SeExprCond needs to be fixed
// fixed.


--- testing
make a script that runs all of our tests and returns exit code 0 if pass,
this should probably be python
exit code 1 if fails
make a script that runs all imageSynth tests with the interprett and with llvm
add all of your basic tests to your test suite and also a type checking test
suite TypeTester.cpp.

--- ensure that the output is clean when evaluating, no debugging on by default

--- write documentation and add it to the documentation folder in the repo in
docs/summer_documentation2

--- Fix time frame stuff use voodoo $frame in expression

--- SeExprPlugins should be integrated into the existing SeExprPlugins...
Loading

0 comments on commit 6a746ff

Please sign in to comment.