cmake: Generate token headers.
authorMathias Preiner <mathias.preiner@gmail.com>
Wed, 15 Aug 2018 00:43:17 +0000 (17:43 -0700)
committerMathias Preiner <mathias.preiner@gmail.com>
Sat, 22 Sep 2018 23:30:59 +0000 (16:30 -0700)
src/main/CMakeLists.txt
src/main/gen-token-header.sh [new file with mode: 0644]

index a66ab5a1e7fe9ea65ef564088bcc7053c6f39cc3..023d02cbe8d9e0e8d04c11003a3c49960af56585 100644 (file)
@@ -19,6 +19,7 @@ add_executable(cvc4-main ${cvc4main_src_files})
 target_compile_definitions(cvc4-main PRIVATE -D__BUILDING_CVC4DRIVER)
 set_target_properties(cvc4-main PROPERTIES OUTPUT_NAME cvc4)
 target_link_libraries(cvc4-main main)
+add_dependencies(cvc4-main token-headers)
 
 #set(pcvc4_src_files
 #  main.cpp
@@ -32,3 +33,44 @@ target_link_libraries(cvc4-main main)
 #  command_executor_portfolio.h
 #  driver_unified.cpp
 #)
+
+add_custom_command(
+  OUTPUT cvc_tokens.h
+  COMMAND
+    sh ${CMAKE_CURRENT_LIST_DIR}/gen-token-header.sh
+        ${CMAKE_CURRENT_LIST_DIR}/../parser/cvc/Cvc.g
+        ${CMAKE_CURRENT_BINARY_DIR}/cvc_tokens.h
+  DEPENDS ../parser/cvc/Cvc.g
+)
+
+add_custom_command(
+  OUTPUT smt1_tokens.h
+  COMMAND
+    sh ${CMAKE_CURRENT_LIST_DIR}/gen-token-header.sh
+        ${CMAKE_CURRENT_LIST_DIR}/../parser/smt1/Smt1.g
+        ${CMAKE_CURRENT_BINARY_DIR}/smt1_tokens.h
+  DEPENDS ../parser/smt1/Smt1.g
+)
+
+add_custom_command(
+  OUTPUT smt2_tokens.h
+  COMMAND
+    sh ${CMAKE_CURRENT_LIST_DIR}/gen-token-header.sh
+        ${CMAKE_CURRENT_LIST_DIR}/../parser/smt2/Smt2.g
+        ${CMAKE_CURRENT_BINARY_DIR}/smt2_tokens.h
+  DEPENDS ../parser/smt2/Smt2.g
+)
+
+add_custom_command(
+  OUTPUT tptp_tokens.h
+  COMMAND
+    sh ${CMAKE_CURRENT_LIST_DIR}/gen-token-header.sh
+        ${CMAKE_CURRENT_LIST_DIR}/../parser/tptp/Tptp.g
+        ${CMAKE_CURRENT_BINARY_DIR}/tptp_tokens.h
+  DEPENDS ../parser/tptp/Tptp.g
+)
+
+add_custom_target(
+  token-headers
+  DEPENDS cvc_tokens.h smt1_tokens.h smt2_tokens.h tptp_tokens.h
+)
diff --git a/src/main/gen-token-header.sh b/src/main/gen-token-header.sh
new file mode 100644 (file)
index 0000000..86e30ae
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+grep "'[a-zA-Z][a-zA-Z0-9_-][a-zA-Z0-9_-]*'" "$1" | \
+  sed 's/.*'\''\([a-zA-Z0-9_-]*\)'\''.*/"\1",/' | \
+  sort -u > "$2"