Skip to content

Commit

Permalink
[Relay][Parser] simplify build script, remove python 2 support (apach…
Browse files Browse the repository at this point in the history
…e#3419)

* simplify build script, remove python 2 support

* remove py2 file

* update py3
  • Loading branch information
MarisaKirisame authored and Wei Chen committed Jun 28, 2019
1 parent 755c570 commit c320d06
Show file tree
Hide file tree
Showing 16 changed files with 20 additions and 3,199 deletions.
49 changes: 12 additions & 37 deletions cmake/modules/ANTLR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,19 @@
# under the License.

if(USE_ANTLR)
file(GLOB_RECURSE ANTLR4
/usr/local/lib/antlr-*-complete.jar
/usr/local/Cellar/*antlr-*-complete.jar)
set(RELAY_PARSER_DIR
${CMAKE_CURRENT_SOURCE_DIR}/python/tvm/relay/grammar)

if(ANTLR4)
# Get the first element of the list of antlr jars.
# Sort and reverse the list so the item selected is the highest
# version in lib or else in Cellar if no lib installation exists.
list(SORT ANTLR4)
list(REVERSE ANTLR4)
list(GET ANTLR4 0 ANTLR4)
set(RELAY_PARSER_DIR
${CMAKE_CURRENT_SOURCE_DIR}/python/tvm/relay/grammar)
set(RELAY_PARSER
${RELAY_PARSER_DIR}/py3/RelayVisitor.py
${RELAY_PARSER_DIR}/py3/RelayParser.py
${RELAY_PARSER_DIR}/py3/RelayLexer.py)

set(RELAY_PARSER
${RELAY_PARSER_DIR}/py2/RelayVisitor.py
${RELAY_PARSER_DIR}/py2/RelayParser.py
${RELAY_PARSER_DIR}/py2/RelayLexer.py
# Generate ANTLR grammar for parsing.
add_custom_command(OUTPUT ${RELAY_PARSER}
COMMAND antlr4 -visitor -no-listener -Dlanguage=Python3 ${RELAY_PARSER_DIR}/Relay.g4 -o ${RELAY_PARSER_DIR}/py3
DEPENDS ${RELAY_PARSER_DIR}/Relay.g4
WORKING_DIRECTORY ${RELAY_PARSER_DIR})

${RELAY_PARSER_DIR}/py3/RelayVisitor.py
${RELAY_PARSER_DIR}/py3/RelayParser.py
${RELAY_PARSER_DIR}/py3/RelayLexer.py)

set(JAVA_HOME $ENV{JAVA_HOME})
if (NOT DEFINED JAVA_HOME)
# Hack to get system to search for Java itself.
set(JAVA_HOME "/usr")
endif()

# Generate ANTLR grammar for parsing.
add_custom_command(OUTPUT ${RELAY_PARSER}
COMMAND ${JAVA_HOME}/bin/java -jar ${ANTLR4} -visitor -no-listener -Dlanguage=Python2 ${RELAY_PARSER_DIR}/Relay.g4 -o ${RELAY_PARSER_DIR}/py2
COMMAND ${JAVA_HOME}/bin/java -jar ${ANTLR4} -visitor -no-listener -Dlanguage=Python3 ${RELAY_PARSER_DIR}/Relay.g4 -o ${RELAY_PARSER_DIR}/py3
DEPENDS ${RELAY_PARSER_DIR}/Relay.g4
WORKING_DIRECTORY ${RELAY_PARSER_DIR})

add_custom_target(relay_parser ALL DEPENDS ${RELAY_PARSER})
else()
message(FATAL_ERROR "Can't find ANTLR4: ANTLR4=" ${ANTLR4})
endif()
add_custom_target(relay_parser ALL DEPENDS ${RELAY_PARSER})
endif(USE_ANTLR)
11 changes: 3 additions & 8 deletions python/tvm/relay/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,9 @@ def __init__(self, message):

PYTHON_VERSION = sys.version_info.major
try:
if PYTHON_VERSION == 2:
from .grammar.py2.RelayVisitor import RelayVisitor
from .grammar.py2.RelayParser import RelayParser
from .grammar.py2.RelayLexer import RelayLexer
else:
from .grammar.py3.RelayVisitor import RelayVisitor
from .grammar.py3.RelayParser import RelayParser
from .grammar.py3.RelayLexer import RelayLexer
from .grammar.py3.RelayVisitor import RelayVisitor
from .grammar.py3.RelayParser import RelayParser
from .grammar.py3.RelayLexer import RelayLexer
except ImportError:
raise ParseError("Couldn't find ANTLR parser. Try building with USE_ANTLR=ON.")

Expand Down
3 changes: 0 additions & 3 deletions python/tvm/relay/grammar/py2/.gitattributes

This file was deleted.

109 changes: 0 additions & 109 deletions python/tvm/relay/grammar/py2/Relay.interp

This file was deleted.

70 changes: 0 additions & 70 deletions python/tvm/relay/grammar/py2/Relay.tokens

This file was deleted.

Loading

0 comments on commit c320d06

Please sign in to comment.