diff options
author | Oxore <oxore@protonmail.com> | 2024-02-18 21:18:23 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2024-02-18 21:18:23 +0300 |
commit | fec4c1684e8680285f51ebd4898fe35127c7e098 (patch) | |
tree | 62d4191931edd6584c77049d0ca653005065fc8d | |
parent | 21a9aa92a7cf8767a0fcb33858546dea744c4071 (diff) |
Refactor CMakeLists.txt and fix new warnings
-rw-r--r-- | CMakeLists.txt | 54 | ||||
-rw-r--r-- | src/disasm.cpp | 12 | ||||
-rw-r--r-- | 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 + $<$<CONFIG:Debug>:${common_debug_flags}> + $<$<COMPILE_LANGUAGE:C>:-Wno-nested-anon-types> + # Speed up compilation with -fno-exceptions and -fno-rtti + $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions> + $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti> + $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast> + $<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-override> + $<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wsuggest-final-types> + $<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wsuggest-final-methods> + $<$<COMPILE_LANG_AND_ID:CXX,GNU>:-fstrict-volatile-bitfields> + $<$<COMPILE_LANG_AND_ID:C,GNU>:-fstrict-volatile-bitfields> + $<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wlogical-op> + $<$<COMPILE_LANG_AND_ID:C,GNU>:-Wlogical-op> + $<$<COMPILE_LANG_AND_ID:CXX,GNU>:-ffile-prefix-map=${CMAKE_SOURCE_DIR}/=> + $<$<COMPILE_LANG_AND_ID:C,GNU>:-ffile-prefix-map=${CMAKE_SOURCE_DIR}/=> + -Wall + -Wextra + -pedantic + -Wcast-align + -Wshadow ) + +target_compile_definitions(m68k-disasm PRIVATE $<$<CONFIG:Debug>:_FORTIFY_SOURCE=2>) +target_link_options(m68k-disasm PRIVATE $<$<CONFIG:Debug>:${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 <cassert> #include <cinttypes> |