Skip to content

Commit 6a746ff

Browse files
authored
Merge pull request #41 from jberlin/master
support for type checking and compiling expressions using LLVM
2 parents a5f02bb + 6d170df commit 6a746ff

260 files changed

Lines changed: 29856 additions & 14903 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
BasedOnStyle: "Google"
3+
AccessModifierOffset: -2
4+
AlignEscapedNewlinesLeft: true
5+
AlignTrailingComments: true
6+
AllowAllParametersOfDeclarationOnNextLine: false
7+
AllowShortIfStatementsOnASingleLine: true
8+
ConstructorInitializerIndentWidth: 4
9+
AllowShortLoopsOnASingleLine: true
10+
AlwaysBreakBeforeMultilineStrings: true
11+
AlwaysBreakTemplateDeclarations: true
12+
BinPackParameters: false
13+
BreakBeforeBraces: Attach
14+
BreakConstructorInitializersBeforeComma: false
15+
ColumnLimit: 120
16+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
17+
Cpp11BracedListStyle: true
18+
IndentCaseLabels: true
19+
IndentFunctionDeclarationAfterType: true
20+
IndentWidth: 4
21+
MaxEmptyLinesToKeep: 1
22+
SpaceAfterControlStatementKeyword: true
23+
SpaceBeforeAssignmentOperators: true
24+
SpaceInEmptyParentheses: false
25+
SpacesBeforeTrailingComments: 2
26+
SpacesInAngles: false
27+
SpacesInCStyleCastParentheses: false
28+
SpacesInParentheses: false
29+
UseTab: Never
30+
PointerBindsToType: true
31+
#DerivePointerAlignment: false
32+
#AllowShortCaseLabelsOnASingleLine: true
33+
34+
...

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
*~
2+
.DS_Store
23
/build
34
/Linux-*
45
/Darwin-*
56
*#*#
67
*~
78
CMakeCache.txt
9+
src/SeExpr/parser
10+
src/SeExpr/generated

.workonrc.products

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SeExpr
1+
seexpr2

CMakeLists.txt

Lines changed: 110 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Copyright Disney Enterprises, Inc. All rights reserved.
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,13 +15,59 @@
1615

1716
## CMake compatibility issues: don't modify this, please!
1817
CMAKE_MINIMUM_REQUIRED( VERSION 2.4.6 )
18+
PROJECT (SeExpr2)
1919
MARK_AS_ADVANCED(CMAKE_BACKWARDS_COMPATIBILITY)
2020
## allow more human readable "if then else" constructs
2121
SET( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE )
2222
## Use verbose make file
2323
SET ( CMAKE_VERBOSE_MAKEFILE TRUE )
2424

25-
25+
# Configuration options
26+
# TODO: find GTEST and boost and python the proper ways
27+
SET (LIBDIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "lib or lib64") # defaults to lib but if it s lib64 ok
28+
SET (BOOST_DIR $ENV{RP_boost_disney} CACHE PATH "where boost is located")
29+
SET (BOOST_PYTHON_LIBNAME boost_python CACHE STRING "what library name for boost python")
30+
SET (GTEST_DIR /usr/include CACHE PATH "Where to find GTEST") # /usr/include/gtest)
31+
SET (ENABLE_LLVM_BACKEND ON CACHE BOOL "Whether to build with LLVM backend")
32+
SET (USE_PYTHON ON CACHE BOOL "Whether to compile python libraries")
33+
34+
if (ENABLE_LLVM_BACKEND)
35+
SET (LLVM_DIR /usr/share/llvm/cmake CACHE PATH "Where to search for LLVM i.e. ")
36+
37+
FIND_PACKAGE(LLVM CONFIG NAMES LLVM CONFIGS LLVM-Config.cmake)
38+
if(LLVM_FOUND)
39+
set(SEEXPR_ENABLE_LLVM_BACKEND 1)
40+
message(STATUS "Using LLVM-Config.cmake in: ${LLVM_DIR}")
41+
find_program(LLVM_CONFIG_EXECUTABLE NAMES llvm-config)
42+
43+
# Uncomment to use clang++
44+
#set(CMAKE_CXX_COMPILER clang++)
45+
#set(CMAKE_C_COMPILER clang)
46+
47+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_DIR}")
48+
include(LLVM-Config)
49+
include(HandleLLVMOptions)
50+
51+
add_definitions( ${LLVM_DEFINITIONS} )
52+
message(STATUS "LLVM_DEFINITIONS =" ${LLVM_DEFINITIONS})
53+
54+
execute_process(
55+
COMMAND ${LLVM_CONFIG_EXECUTABLE} --ldflags
56+
OUTPUT_VARIABLE LLVM_LDFLAGS
57+
OUTPUT_STRIP_TRAILING_WHITESPACE
58+
)
59+
message(STATUS "LLVM_LDFLAGS = " ${LLVM_LDFLAGS})
60+
61+
include_directories(${LLVM_INCLUDE_DIRS})
62+
message(status "LLVM_LIBRARY_DIR=" ${LLVM_LIBRARY_DIRS})
63+
link_directories(${LLVM_LIBRARY_DIR})
64+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LLVM_LDFLAGS}")
65+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LLVM_LDFLAGS}")
66+
else(LLVM_FOUND)
67+
set(ENABLE_LLVM_BACKEND off)
68+
set(SEEXPR_ENABLE_LLVM_BACKEND 0)
69+
endif(LLVM_FOUND)
70+
endif(ENABLE_LLVM_BACKEND)
2671

2772
## project name & version
2873
PROJECT( SeExpr )
@@ -43,10 +88,15 @@ IF(WIN32)
4388
include (GenerateExportHeader)
4489
ADD_DEFINITIONS (-DSEEXPR_WIN32)
4590
ELSE(WIN32)
46-
ADD_DEFINITIONS (-Wall -Wextra)
91+
ADD_DEFINITIONS (-Wall -Wextra -Wno-unused-parameter)
4792
ADD_DEFINITIONS (-pthread)
4893

49-
SET( CMAKE_CXX_FLAGS "-fPIC -msse4.1")
94+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -g -std=c++11 -msse4.1")
95+
if(NOT APPLE)
96+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
97+
else()
98+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-date-time")
99+
endif()
50100
ENDIF(WIN32)
51101

52102
## Choose build options
@@ -57,13 +107,23 @@ ENDIF("$ENV{FLAVOR}" STREQUAL "optimize")
57107
IF("$ENV{FLAVOR}" STREQUAL "debug")
58108
SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "type of build" FORCE)
59109
ENDIF("$ENV{FLAVOR}" STREQUAL "debug")
110+
60111
# Set to release if nothing else defined
61112
IF(NOT CMAKE_BUILD_TYPE)
62113
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING
63114
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
64115
FORCE)
65116
ENDIF(NOT CMAKE_BUILD_TYPE)
66117

118+
# --- DISNEY INTERNAL --- (use custom color picker)
119+
IF(DEFINED ENV{RP_qdgui})
120+
ADD_DEFINITIONS (-DSEEXPR_USE_QDGUI)
121+
ENDIF(DEFINED ENV{RP_qdgui})
122+
123+
IF(DEFINED ENV{RP_animlib})
124+
ADD_DEFINITIONS (-DSEEXPR_USE_ANIMLIB)
125+
ENDIF(DEFINED ENV{RP_animlib})
126+
67127
IF(CMAKE_BUILD_TYPE STREQUAL "Release")
68128
SET(FLAVORDIR "optimize")
69129
ELSE(CMAKE_BUILD_TYPE STREQUAL "Release")
@@ -78,25 +138,57 @@ IF (NOT DEFINED CMAKE_INSTALL_PREFIX)
78138
SET(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/${VARIANT_DIRECTORY}-${FLAVORDIR}")
79139
ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)
80140

141+
## Install location for html documentation
142+
SET( SEEXPR_HTML_DOC_PATH "share/doc/SeExpr" )
143+
81144
## Make modules able to see seexpr library
82145
# Setup environment variable to link seexpr
83-
SET( SEEXPR_LIBRARIES SeExpr )
84-
SET( SEEXPR_EDITOR_LIBRARIES SeExprEditor )
146+
SET( SEEXPR_LIBRARIES SeExpr2 )
147+
SET( SEEXPR_LLVM_LIBRARIES SeExpr2LLVM )
148+
SET( SEEXPR_EDITOR_LIBRARIES SeExpr2Editor )
149+
85150
# make it so seexpr can be found
86-
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/SeExpr )
87-
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/SeExprEditor )
88-
89-
# The library directory is configured by setting CMAKE_INSTALL_LIBDIR.
90-
# Otherwise, the defaults set here are used.
91-
IF(EXISTS "/usr/lib64" AND NOT IS_SYMLINK "/usr/lib64")
92-
SET(CMAKE_INSTALL_LIBDIR "lib64" CACHE STRING "Library Directory Basename")
93-
ELSE()
94-
SET(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "Library Directory Basename")
151+
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR}/include )
152+
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR}/src/SeExpr )
153+
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/src/SeExpr )
154+
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/src/EditorUI )
155+
156+
# Allowing to use lib64
157+
IF (NOT DEFINED CMAKE_INSTALL_LIBDIR)
158+
SET(CMAKE_INSTALL_LIBDIR "lib")
95159
ENDIF()
96160

161+
set(LLVM_LIB "")
162+
IF(ENABLE_LLVM_BACKEND AND LLVM_FOUND)
163+
#todo infinite loop in this?
164+
#llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES jit native)
165+
166+
# construct library name
167+
execute_process(
168+
COMMAND ${LLVM_CONFIG_EXECUTABLE} --version
169+
OUTPUT_VARIABLE LLVM_VERSION
170+
OUTPUT_STRIP_TRAILING_WHITESPACE
171+
)
172+
#set(LLVM_LIB "-lLLVM-${LLVM_VERSION}")
173+
link_directories(${LLVM_LIBRARY_DIRS})
174+
#set(LLVM_LIB ${LLVM_AVAILABLE_LIBS} -lLLVMSupport -lLLVMCodeGen -lLLVMCore) #"-lLLVMCore -lLLVMMCJIT -lLLVMExecutionEngine -lLL")
175+
set(LLVM_LIB LLVM)
176+
message(STATUS "LLVM library " ${LLVM_LIB})
177+
message(STATUS "LLVM version " ${LLVM_VERSION})
178+
if(LLVM_VERSION VERSION_LESS 3.8.0)
179+
set(ENABLE_LLVM_BACKEND off)
180+
set(SEEXPR_ENABLE_LLVM_BACKEND 0)
181+
message(STATUS "Not building with LLVM, version must be >= 3.8.0")
182+
endif(LLVM_VERSION VERSION_LESS 3.8.0)
183+
ENDIF(ENABLE_LLVM_BACKEND AND LLVM_FOUND)
184+
185+
97186
## Traverse subdirectories
98187
ADD_SUBDIRECTORY (src/SeExpr)
99-
ADD_SUBDIRECTORY (src/SeExprEditor)
100-
ADD_SUBDIRECTORY (src/doc)
101-
ADD_SUBDIRECTORY (src/demos)
188+
ADD_SUBDIRECTORY (src/ui)
102189
ADD_SUBDIRECTORY (src/tests)
190+
#TODO: put this back
191+
ADD_SUBDIRECTORY (src/py)
192+
ADD_SUBDIRECTORY (src/utils)
193+
ADD_SUBDIRECTORY (src/demos)
194+
ADD_SUBDIRECTORY (src/doc)

Makefile

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
1-
#!/usr/bin/env make
2-
SH ?= sh
3-
uname_S := $(shell $(SH) -c 'uname -s || echo system')
4-
uname_R := $(shell $(SH) -c 'uname -r | cut -d- -f1 || echo release')
5-
uname_M := $(shell $(SH) -c 'uname -m || echo cpu')
1+
-include Makefile.config
2+
63
FLAVOR ?= optimize
4+
prefix ?= $(shell pf-makevar --absolute root)
5+
libdir ?= $(shell pf-makevar lib)
6+
7+
# TODO: when RHEL6 is fully retired remove th
8+
# Don't set CXX when native GCC version is 4.8.
9+
#SETCXX := $(shell expr `gcc -dumpversion` \< 4.8)
10+
#ifeq "$(SETCXX)" "1"
11+
# CXX=/opt/rh/devtoolset-2/root/usr/bin/g++
12+
#endif
13+
714

8-
platformdir ?= $(uname_S)-$(uname_R)-$(uname_M)-$(FLAVOR)
9-
builddir ?= $(CURDIR)/build/$(platformdir)
15+
## Temporary staging directory
16+
# DESTDIR =
1017

11-
prefix ?= $(CURDIR)/$(platformdir)
12-
#DESTDIR =
18+
# Specified by `git make-pkg` when building .pkg files
19+
# mac_pkg =
1320

14-
CMAKE_FLAGS ?= -DCMAKE_INSTALL_PREFIX=$(prefix)
21+
export prefix DESTDIR
1522

16-
# The default target in this Makefile is...
17-
all::
23+
all:
24+
mkdir -p build/${FLAVOR}
25+
export CXX=${CXX}
26+
cd build/${FLAVOR} && CXX=${CXX} cmake -DCMAKE_INSTALL_PREFIX=$(prefix) -DCMAKE_INSTALL_LIBDIR=$(libdir) ${EXTRA_CMAKE_ARGS} ../../
27+
$(MAKE) -C build/${FLAVOR} all
28+
clean:
29+
rm -rf build/${FLAVOR} Linux-*
1830

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

22-
$(builddir)/stamp: $(CMAKE_FILES)
23-
mkdir -p $(builddir)
24-
cd $(builddir) && cmake $(CMAKE_FLAGS) ../..
25-
touch $@
36+
test: install
37+
python src/tests/imageTestsReportNew.py runall
2638

27-
all:: $(builddir)/stamp
28-
$(MAKE) -C $(builddir) $(MAKEARGS) all
39+
format:
40+
find $(CURDIR)/src -name '*.cpp' | xargs clang-format -i
41+
find $(CURDIR)/src -name '*.h' | xargs clang-format -i
2942

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

33-
.PHONY: all
34-
.PHONY: clean
35-
.PHONY: install
46+
precommit: format

Makefile.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
EXTRA_CMAKE_ARGS= -DBOOST_DIR=${RP_boost_disney} -DGTEST_DIR=/usr/

Makefile.example.mac.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BOOST=/usr/local
2+
LLVM=~/code/llvm-inst/share/llvm/cmake
3+
GTEST=~/code/gtest-inst/
4+
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"
5+
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

TODO.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
asciiCalc evalStr() should not ignore return
2+
3+
SeExprNode
4+
getStrArg() does not belong on base SeExprNode. We use this in SeExprPlugins, but there should be a better way of looking for that
5+
// Do we need to check the value of string arg of custom function? Shouldn't
6+
// it be done at runtime and fail in eval stage?
7+
8+
SeExprPlugins
9+
Arguments for in tangent and out tangent don't check they are constant string. Also, do we want ot make this work
10+
foo="constant"; animCurve(foo,"fds"); (i.e. the first argument is not a SeExprStr as your current code assumes)
11+
// in tangent and out tangent are checked as varying string before. now changed to checked as constant string.
12+
13+
The trim function seems unused. Can we delete it?
14+
// deleted.
15+
16+
PromoteBinaryOperands should perhaps return a std::pair of value*'s instead of mutating the incoming ones
17+
// done
18+
19+
The prmoting of values for binary operands compares its arguments like 3 times. Maybe there is a way to clean that up
20+
// isLegaltoPromote are now removed. It is simplified to check if destType is vector.
21+
22+
Is resolveLocalVar correct. What if it needs to look in a different basic block. What are the variable resolution rules?
23+
// Are local var are alloca'd in entry basic block. Only when codegen assignment, local var may be alloca'd.
24+
// 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
25+
26+
Select does not work on SeExprCond needs to be fixed
27+
// fixed.
28+
29+
30+
--- testing
31+
make a script that runs all of our tests and returns exit code 0 if pass,
32+
this should probably be python
33+
exit code 1 if fails
34+
make a script that runs all imageSynth tests with the interprett and with llvm
35+
add all of your basic tests to your test suite and also a type checking test
36+
suite TypeTester.cpp.
37+
38+
--- ensure that the output is clean when evaluating, no debugging on by default
39+
40+
--- write documentation and add it to the documentation folder in the repo in
41+
docs/summer_documentation2
42+
43+
--- Fix time frame stuff use voodoo $frame in expression
44+
45+
--- SeExprPlugins should be integrated into the existing SeExprPlugins...

0 commit comments

Comments
 (0)