From fec4c1684e8680285f51ebd4898fe35127c7e098 Mon Sep 17 00:00:00 2001 From: Oxore Date: Sun, 18 Feb 2024 21:18:23 +0300 Subject: Refactor CMakeLists.txt and fix new warnings --- CMakeLists.txt | 54 +++++++++++++++++++++++++++++++++++------------------- src/disasm.cpp | 12 ++++++------ src/main.cpp | 8 ++++++++ 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 13c67a2..a778958 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,30 +8,46 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_EXPORT_COMPILE_COMMANDS True) -set(common_flags) -set(common_debug_flags "-fsanitize=address -fno-omit-frame-pointer -O1") -# Uncomment to enalbe profiler -#set(common_debug_flags "${common_debug_flags} -pg") -set(common_compile_flags "-Wall -Wextra -pedantic") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${common_compile_flags} ${common_flags}") -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${common_debug_flags}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${common_compile_flags} ${common_flags}") -# Speed up compilation with -fno-exceptions and -fno-rtti -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -Wno-nested-anon-types") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${common_debug_flags}") -set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${common_flags}") -set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} ${common_debug_flags}") -set(m68kdisasm_sources +set(common_debug_flags + -fsanitize=address,undefined + -fno-omit-frame-pointer + -O1 + -g3 + # Uncomment to enable profiler + # -pg + ) + +add_executable(m68k-disasm src/main.cpp src/data_buffer.cpp src/disasm.cpp src/elf_image.cpp ) -add_executable(m68k-disasm ${m68kdisasm_sources}) - -include_directories( - . - lib +target_compile_options(m68k-disasm PRIVATE + $<$:${common_debug_flags}> + $<$:-Wno-nested-anon-types> + # Speed up compilation with -fno-exceptions and -fno-rtti + $<$:-fno-exceptions> + $<$:-fno-rtti> + $<$:-Wold-style-cast> + $<$:-Wsuggest-override> + $<$:-Wsuggest-final-types> + $<$:-Wsuggest-final-methods> + $<$:-fstrict-volatile-bitfields> + $<$:-fstrict-volatile-bitfields> + $<$:-Wlogical-op> + $<$:-Wlogical-op> + $<$:-ffile-prefix-map=${CMAKE_SOURCE_DIR}/=> + $<$:-ffile-prefix-map=${CMAKE_SOURCE_DIR}/=> + -Wall + -Wextra + -pedantic + -Wcast-align + -Wshadow ) + +target_compile_definitions(m68k-disasm PRIVATE $<$:_FORTIFY_SOURCE=2>) +target_link_options(m68k-disasm PRIVATE $<$:${common_debug_flags}>) +target_include_directories(m68k-disasm PRIVATE . lib) diff --git a/src/disasm.cpp b/src/disasm.cpp index 2b2ea81..be4a9a8 100644 --- a/src/disasm.cpp +++ b/src/disasm.cpp @@ -83,9 +83,9 @@ constexpr Arg FetchArg( } // Xi number (lower 3 bits, mask 0x7) with An/Dn bit (mask 0x8) const uint8_t xi = (briefext >> 12) & 0xf; - const OpSize s = ((briefext >> 11) & 1) ? OpSize::kLong : OpSize::kWord; + const OpSize s2 = ((briefext >> 11) & 1) ? OpSize::kLong : OpSize::kWord; const int8_t d8 = briefext & 0xff; - return Arg::D8AnXiAddr(xn, xi, s, d8); + return Arg::D8AnXiAddr(xn, xi, s2, d8); } break; case 7: @@ -118,9 +118,9 @@ constexpr Arg FetchArg( } // Xi number (lower 3 bits, mask 0x7) with An/Dn bit (mask 0x8) const uint8_t xi = (briefext >> 12) & 0xf; - const OpSize s = ((briefext >> 11) & 1) ? OpSize::kLong : OpSize::kWord; + const OpSize s2 = ((briefext >> 11) & 1) ? OpSize::kLong : OpSize::kWord; const int8_t d8 = briefext & 0xff; - return Arg::D8PCXiAddr(xn, xi, s, d8); + return Arg::D8PCXiAddr(xn, xi, s2, d8); } break; case 4: // #imm @@ -1979,7 +1979,7 @@ int Op::FPrint( } } -void DisasmNode::AddReferencedBy(const uint32_t address, const ReferenceType type) +void DisasmNode::AddReferencedBy(const uint32_t address_from, const ReferenceType ref_type) { ReferenceNode *node{}; if (this->last_ref_by) { @@ -1989,7 +1989,7 @@ void DisasmNode::AddReferencedBy(const uint32_t address, const ReferenceType typ assert(node); this->ref_by = this->last_ref_by = node; } - node->refs[node->refs_count] = ReferenceRecord{type, address}; + node->refs[node->refs_count] = ReferenceRecord{ref_type, address_from}; node->refs_count++; if (node->refs_count >= kRefsCountPerBuffer) { ReferenceNode *new_node = new ReferenceNode{}; diff --git a/src/main.cpp b/src/main.cpp index a6f73b3..89aa2ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,7 +8,15 @@ #define OPTPARSE_IMPLEMENTATION #define OPTPARSE_API static +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wshadow" +#endif #include "optparse/optparse.h" +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif #include #include -- cgit v1.2.3