Files
asmjit/test/asmjitutils.h
kobalicek 073f6e85e4 [ABI] Improvements to avoid UB and warnings, clean build with MSAN
* Added more clang compilers on CI (CI)
  * Added memory sanitizer to build matrix (CI)
  * Use problem matcher in all builds (CI)
  * Fixed the use of some constructs in tests
  * Fixed warnings about unused functions in tests
  * Fixed warnings about unused variables caused by some build options
  * Fixed tests to be clean with MSAN (zeroing memory filled by JIT code)
  * Removed -Wclass-memaccess (gcc) from ignored warnings
  * Removed -Wconstant-logical-operand (clang) from ignored warnings
  * Removed -Wunnamed-type-template-args (clang) from ignored warnings
  * Reworked InstData and InstExData to not cause UB (ABI break)

Unfortunately the existing InstData and InstExData was not good for static
analysis and in general compilers emitted warnings regarding accessing
InstNode::_opArray. The reason was that InstExNode added one or two
more operands which extended InstData::_opArray, but there was no way to
tell the C++ compiler about this layout.

It has been changed to InstNode having no operands and InstNodeWithOperands
being templatized for the right number of operands. Nodes that need to
inherit InstNode would just inherit InstNodeWithOperands<N>. It works the
same way as before, just the class hierarchy changed a little.
2023-12-26 19:00:00 +01:00

61 lines
1.6 KiB
C

// This file is part of AsmJit project <https://asmjit.com>
//
// See asmjit.h or LICENSE.md for license and copyright information
// SPDX-License-Identifier: Zlib
#ifndef ASMJITUTILS_H_INCLUDED
#define ASMJITUTILS_H_INCLUDED
#include <asmjit/core.h>
namespace {
ASMJIT_MAYBE_UNUSED
const char* asmjitArchAsString(asmjit::Arch arch) noexcept {
switch (arch) {
case asmjit::Arch::kX86 : return "X86";
case asmjit::Arch::kX64 : return "X64";
case asmjit::Arch::kRISCV32 : return "RISCV32";
case asmjit::Arch::kRISCV64 : return "RISCV64";
case asmjit::Arch::kARM : return "ARM";
case asmjit::Arch::kAArch64 : return "AArch64";
case asmjit::Arch::kThumb : return "Thumb";
case asmjit::Arch::kMIPS32_LE : return "MIPS_LE";
case asmjit::Arch::kMIPS64_LE : return "MIPS64_LE";
case asmjit::Arch::kARM_BE : return "ARM_BE";
case asmjit::Arch::kThumb_BE : return "Thumb_BE";
case asmjit::Arch::kAArch64_BE: return "AArch64_BE";
case asmjit::Arch::kMIPS32_BE : return "MIPS_BE";
case asmjit::Arch::kMIPS64_BE : return "MIPS64_BE";
default:
return "<Unknown>";
}
}
ASMJIT_MAYBE_UNUSED
void printIndented(const char* str, size_t indent) noexcept {
const char* start = str;
while (*str) {
if (*str == '\n') {
size_t size = (size_t)(str - start);
printf("%*s%.*s\n", size ? int(indent) : 0, "", int(size), start);
start = str + 1;
}
str++;
}
size_t size = (size_t)(str - start);
if (size)
printf("%*s%.*s\n", int(indent), "", int(size), start);
}
} // {anonymous}
#endif // ASMJITUTILS_H_INCLUDED