Files
asmjit/test/asmjit_test_assembler.h
kobalicek 996deae327 [ABI] Refactored AsmJit to use strong-typed enums, this breaks both API and ABI
[ABI] Added ABI version as an inline namespace, which forms asmjit::_abi_MAJOR_MINOR
[ABI] Added support for AVX512_FP16, 16-bit broadcast, and AVX512_FP16 tests
[ABI] Added initial support for consecutive registers into instruction database and register allocator
[ABI] Added a possibility to use temporary memory in CodeHolder's zone
[ABI] Compiler::setArg() is now deprecated, use FuncNode::setArg()
[Bug] Fixed correct RW information of instructions that only support implicit zeroing with {k}
[Bug] Fixed broadcast to be able to broadcast bcst16 operands
2021-12-13 19:34:56 +01:00

84 lines
2.0 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 ASMJIT_TEST_ASSEMBLER_H_INCLUDED
#define ASMJIT_TEST_ASSEMBLER_H_INCLUDED
#include <asmjit/core.h>
#include <stdio.h>
struct TestSettings {
bool quiet;
bool validate;
};
template<typename AssemblerType>
class AssemblerTester {
public:
asmjit::Environment env {};
asmjit::CodeHolder code {};
AssemblerType assembler {};
const TestSettings& settings;
size_t passed {};
size_t count {};
AssemblerTester(asmjit::Arch arch, const TestSettings& settings) noexcept
: env(arch),
settings(settings) {
prepare();
}
void printHeader(const char* archName) noexcept {
printf("%s assembler tests:\n", archName);
}
void printSummary() noexcept {
printf(" Passed: %zu / %zu tests\n\n", passed, count);
}
bool didPass() const noexcept { return passed == count; }
void prepare() noexcept {
code.reset();
code.init(env, 0);
code.attach(&assembler);
if (settings.validate)
assembler.addDiagnosticOptions(asmjit::DiagnosticOptions::kValidateAssembler);
}
ASMJIT_NOINLINE bool testInstruction(const char* expectedOpcode, const char* s, uint32_t err) noexcept {
count++;
if (err) {
printf(" !! %s\n"
" <%s>\n", s, asmjit::DebugUtils::errorAsString(err));
prepare();
return false;
}
asmjit::String encodedOpcode;
asmjit::Section* text = code.textSection();
encodedOpcode.appendHex(text->data(), text->bufferSize());
if (encodedOpcode != expectedOpcode) {
printf(" !! [%s] <- %s\n"
" [%s] (Expected)\n", encodedOpcode.data(), s, expectedOpcode);
prepare();
return false;
}
if (!settings.quiet)
printf(" OK [%s] <- %s\n", encodedOpcode.data(), s);
passed++;
prepare();
return true;
}
};
#endif // ASMJIT_TEST_ASSEMBLER_H_INCLUDED