Skip to content

Commit

Permalink
add target to generate CSV symbols map
Browse files Browse the repository at this point in the history
  • Loading branch information
smx-smx committed Apr 10, 2024
1 parent c8ac54b commit f84ef2c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(CMAKE_C_STANDARD 23)
set(CMAKE_BUILD_TYPE Debug)

find_library(LZMA_LIBRARY NAMES liblzma.a REQUIRED)
find_program(SED_COMMAND NAMES sed REQUIRED)
message(STATUS "Using ${LZMA_LIBRARY}")

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand All @@ -28,6 +29,17 @@ add_custom_command(
)
add_custom_target(gen_lds DEPENDS ${CMAKE_BINARY_DIR}/xzre.lds)

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/xzre.csv
COMMAND ${CMAKE_C_COMPILER}
-DGEN_CSV -x c -E -P
${CMAKE_SOURCE_DIR}/xzre.lds.in | sed "/^\\s*$/d;s/^\\s*//" > ${CMAKE_BINARY_DIR}/xzre.csv
DEPENDS ${CMAKE_SOURCE_DIR}/xzre.lds.in
VERBATIM
)
add_custom_target(gen_csv ALL DEPENDS ${CMAKE_BINARY_DIR}/xzre.csv)


target_sources(xzre PRIVATE ${SOURCES})
target_sources(lzma PRIVATE ${SOURCES})
target_compile_definitions(lzma PRIVATE XZRE_SHARED)
Expand Down
13 changes: 10 additions & 3 deletions xzre.lds.in
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#define QUOTED(a) #a
#define QUOTE(a) QUOTED(a)
#define QUOTED(a) #a
#define QUOTE(a) QUOTED(a)

#ifdef GEN_CSV
#define DEFSYM(name, section) QUOTE(name),QUOTE(section)
#define SECTIONS_BEGIN()
#define SECTIONS_END(name)
// CSV header
name,section
#else
#define DEFSYM(name, section) \
section : { \
QUOTE(name) = QUOTE(.); \
*(section); \
}

#define SECTIONS_BEGIN() SECTIONS {
#define SECTIONS_END(name) } INSERT AFTER name;
#endif

SECTIONS_BEGIN()
DEFSYM(x86_dasm, .text.x86_codd)
Expand Down

0 comments on commit f84ef2c

Please sign in to comment.