Skip to content

Commit

Permalink
sed the generated enum yytokentype
Browse files Browse the repository at this point in the history
to avoid LTO -Wodr warnings. yacc doesnt support this yet
  • Loading branch information
rurban committed Mar 15, 2024
1 parent 0732e66 commit 9d5b270
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ else()
message(STATUS "IPO / LTO not supported: <${error}>")
endif()

find_program(SED sed gsed)

add_subdirectory(src)
add_subdirectory(regression)
add_subdirectory(unit)
Expand Down
13 changes: 9 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ macro(generic_bison name)
COMPILE_FLAGS "${bison_warnings_as_errors} -pyy${name}"
)
set(renamed_parser_header "${CMAKE_CURRENT_BINARY_DIR}/${bison_header}")
add_custom_command(OUTPUT "${renamed_parser_header}"
COMMAND "${CMAKE_COMMAND}" -E copy "${BISON_parser_OUTPUT_HEADER}" "${renamed_parser_header}"
MAIN_DEPENDENCY "${BISON_parser_OUTPUT_HEADER}"
)
if(${SED} STREQUAL "SED-NOTFOUND")
add_custom_command(OUTPUT "${renamed_parser_header}"
COMMAND "${CMAKE_COMMAND}" -E copy "${BISON_parser_OUTPUT_HEADER}" "${renamed_parser_header}"
MAIN_DEPENDENCY "${BISON_parser_OUTPUT_HEADER}")
else()
add_custom_command(OUTPUT "${renamed_parser_header}"
COMMAND ${SED} -e "s,enum yytokentype,enum yytokentype_${name}," <${BISON_parser_OUTPUT_HEADER} >${renamed_parser_header}
MAIN_DEPENDENCY "${BISON_parser_OUTPUT_HEADER}")
endif()
list(REMOVE_ITEM BISON_parser_OUTPUTS "${BISON_parser_OUTPUT_HEADER}")
list(APPEND BISON_parser_OUTPUTS "${renamed_parser_header}")
endmacro(generic_bison)
Expand Down
3 changes: 3 additions & 0 deletions src/ansi-c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ all: ansi-c$(LIBEXT)

ansi_c_y.tab.cpp: parser.y
$(YACC) $(YFLAGS) -pyyansi_c parser.y --defines=ansi_c_y.tab.h -o $@
$(SED) -e's,enum yytokentype,enum yytokentype_ansi,' \
<ansi_c_y.tab.h >ansi_c_y.tab.h.tmp && \
mv ansi_c_y.tab.h.tmp ansi_c_y.tab.h

ansi_c_y.tab.h: ansi_c_y.tab.cpp

Expand Down
10 changes: 10 additions & 0 deletions src/common
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ endif
ifeq ($(origin LEX),default)
LEX = flex
endif
ifeq ($(origin SED),default)
SED = sed
endif

else ifeq ($(BUILD_ENV_),Cygwin)
# use these for Cygwin:
Expand Down Expand Up @@ -130,6 +133,9 @@ endif
ifeq ($(origin LEX),default)
LEX = flex
endif
ifeq ($(origin SED),default)
SED = sed
endif


else ifeq ($(BUILD_ENV_),MSVC)
Expand Down Expand Up @@ -158,6 +164,10 @@ endif
ifeq ($(origin LEX),default)
LEX = win_flex
endif
ifeq ($(origin SED),default)
# on MSVC there is no lto
SED = rem
endif


else
Expand Down
3 changes: 3 additions & 0 deletions src/statement-list/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ all: statement-list$(LIBEXT)

statement_list_y.tab.cpp: parser.y
$(YACC) $(YFLAGS) -pyystatement_list parser.y --defines=statement_list_y.tab.h -o $@
$(SED) -e's,enum yytokentype,enum yytokentype_stmt,' \
<statement_list_y.tab.h >statement_list_y.tab.h.tmp && \
mv statement_list_y.tab.h.tmp statement_list_y.tab.h

statement_list_y.tab.h: statement_list_y.tab.cpp

Expand Down

0 comments on commit 9d5b270

Please sign in to comment.