From e75de2c9260cea428ea73cb9515d6c6f8d0d44dd Mon Sep 17 00:00:00 2001 From: Josh Maxwell Pollock Date: Sat, 13 Oct 2018 15:30:27 -0700 Subject: [PATCH] attempt at adding antlr4 to cmake. remove outdated grammar rules. update tests --- CMakeLists.txt | 21 +++++++++++++++++++++ python/tvm/relay/grammar/Relay.g4 | 2 -- tests/python/relay/test_ir_parser.py | 5 +---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bd76bbd79068..87933771f9f75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -272,6 +272,27 @@ else(INSTALL_DEV) ) endif(INSTALL_DEV) +# ANTLR4 build definitions +# find_program(ANTLR4 antlr4) + +# set(RELAY_PARSER_DIR +# ${CMAKE_CURRENT_SOURCE_DIR}/relay/python/relay/parser) + +# set(RELAY_PARSER +# ${RELAY_PARSER_DIR}/RelayVisitor.py +# ${RELAY_PARSER_DIR}/RelayParser.py +# ${RELAY_PARSER_DIR}/RelayLexer.py) + +# if(ANTLR4) +# # 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} +# DEPENDS ${RELAY_PARSER_DIR}/Relay.g4 +# WORKING_DIRECTORY ${RELAY_PARSER_DIR}) +# endif() + +# add_custom_target(relay_parser ALL DEPENDS ${RELAY_PARSER}) + # More target definitions if(MSVC) target_compile_definitions(tvm PRIVATE -DHalide_EXPORTS) diff --git a/python/tvm/relay/grammar/Relay.g4 b/python/tvm/relay/grammar/Relay.g4 index bbc311e7ef853..269a298e0f53e 100644 --- a/python/tvm/relay/grammar/Relay.g4 +++ b/python/tvm/relay/grammar/Relay.g4 @@ -102,11 +102,9 @@ type_ | '(' type_ ',' ')' # tupleType | '(' type_ (',' type_)+ ')' # tupleType | identType # identTypeType - | identType '(' (type_ (',' type_)*)? ')' # callType | identType '[' (type_ (',' type_)*)? ']' # callType | '(' (type_ (',' type_)*)? ')' '->' type_ # funcType // Mut, Int, UInt, Float, Bool, Tensor - // | type_ '.' INT # projectType | INT # intType | '_' # incompleteType ; diff --git a/tests/python/relay/test_ir_parser.py b/tests/python/relay/test_ir_parser.py index 2f8f02857ebb4..5f91f93ec7b43 100644 --- a/tests/python/relay/test_ir_parser.py +++ b/tests/python/relay/test_ir_parser.py @@ -335,10 +335,7 @@ def test_call_type(): # let %_ : Int(0, 1) = (); () for call_type, arity in CALL_TYPES.items(): for i in range(1, arity + 1): - # custom tuple printing to avoid hanging comma for one-tuples - tup = "(" + ",".join([str(num) for num in range(i)]) + ")" - print("let %_ : {}{} = (); ()".format(call_type, tup)) - parse_expr("let %_ : {}{} = (); ()".format(call_type, tup)) + parse_expr("let %_ : {}{} = (); ()".format(call_type, range(i))) def test_function_type(): assert alpha_equal(