mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-17 20:44:37 +03:00
Codebase update and improvements, instruction DB update
* Denested src folder to root, renamed testing to asmjit-testing
* Refactored how headers are included into <asmjit/...> form. This
is necessary as compilers would never simplify a path once a ..
appears in include directory - then paths such as ../core/../core
appeared in asserts, which was ugly
* Moved support utilities into asmjit/support/... (still included
by asmjit/core.h for convenience and compatibility)
* Added CMakePresets.json for making it easy to develop AsmJit
* Reworked CMakeLists to be shorter and use CMake option(),
etc... This simplifies it and makes it using more standard
features
* ASMJIT_EMBED now creates asmjit_embed INTERFACE library,
which is accessible via asmjit::asmjit target - this simplifies
embedding and makes it the same as library targets from a CMake
perspective
* Removed ASMJIT_DEPS - this is now provided by cmake target
aliases - 'asmjit::asmjit' so users should not need this variable
* Changed meaning of ASMJIT_LIBS - this now contains only AsmJit
dependencies without asmjit::asmjit target alias. Don't rely on
ASMJIT_LIBS anymore as it's only used internally
* Removed ASMJIT_NO_DEPRECATED option - AsmJit is not going
to provide controllable deprecations in the future
* Removed ASMJIT_NO_VALIDATION in favor of ASMJIT_NO_INTROSPECTION,
which now controls query, features, and validation API presence
* Removed ASMJIT_DIR option - it was never really needed
* Removed AMX_TRANSPOSE feature from instruction database (X86).
Intel has removed it as well, so it's a feature that won't
be siliconized
This commit is contained in:
109
asmjit-testing/tests/asmjit_test_assembler.h
Normal file
109
asmjit-testing/tests/asmjit_test_assembler.h
Normal file
@@ -0,0 +1,109 @@
|
||||
// This file is part of AsmJit project <https://asmjit.com>
|
||||
//
|
||||
// See <asmjit/core.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 verbose;
|
||||
bool validate;
|
||||
};
|
||||
|
||||
template<typename AssemblerType>
|
||||
class AssemblerTester {
|
||||
public:
|
||||
asmjit::Environment env {};
|
||||
asmjit::CodeHolder code {};
|
||||
AssemblerType assembler {};
|
||||
asmjit::Label L0 {};
|
||||
const TestSettings& settings;
|
||||
|
||||
size_t passed {};
|
||||
size_t count {};
|
||||
|
||||
AssemblerTester(asmjit::Arch arch, const TestSettings& settings) noexcept
|
||||
: env(arch),
|
||||
settings(settings) {
|
||||
prepare();
|
||||
}
|
||||
|
||||
void print_header(const char* arch_name) noexcept {
|
||||
printf("%s assembler tests:\n", arch_name);
|
||||
}
|
||||
|
||||
void print_summary() noexcept {
|
||||
printf(" Passed: %zu / %zu tests\n\n", passed, count);
|
||||
}
|
||||
|
||||
bool did_pass() const noexcept { return passed == count; }
|
||||
|
||||
void prepare() noexcept {
|
||||
code.reset();
|
||||
code.init(env, 0);
|
||||
code.attach(&assembler);
|
||||
L0 = assembler.new_label();
|
||||
|
||||
if (settings.validate)
|
||||
assembler.add_diagnostic_options(asmjit::DiagnosticOptions::kValidateAssembler);
|
||||
}
|
||||
|
||||
ASMJIT_NOINLINE bool test_valid_instruction(const char* s, const char* expected_opcode, asmjit::Error err = asmjit::Error::kOk) noexcept {
|
||||
count++;
|
||||
|
||||
if (err != asmjit::Error::kOk) {
|
||||
printf(" !! %s\n"
|
||||
" <%s>\n", s, asmjit::DebugUtils::error_as_string(err));
|
||||
prepare();
|
||||
return false;
|
||||
}
|
||||
|
||||
asmjit::String encoded_opcode;
|
||||
asmjit::Section* text = code.text_section();
|
||||
|
||||
encoded_opcode.append_hex(text->data(), text->buffer_size());
|
||||
if (encoded_opcode != expected_opcode) {
|
||||
printf(" !! [%s] <- %s\n"
|
||||
" [%s] (Expected)\n", encoded_opcode.data(), s, expected_opcode);
|
||||
prepare();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (settings.verbose)
|
||||
printf(" OK [%s] <- %s\n", encoded_opcode.data(), s);
|
||||
|
||||
passed++;
|
||||
prepare();
|
||||
return true;
|
||||
}
|
||||
|
||||
ASMJIT_NOINLINE bool test_invalid_instruction(const char* s, asmjit::Error expected_error, asmjit::Error err) noexcept {
|
||||
count++;
|
||||
|
||||
if (err == asmjit::Error::kOk) {
|
||||
printf(" !! %s passed, but should have failed with <%s> error\n", s, asmjit::DebugUtils::error_as_string(expected_error));
|
||||
prepare();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (err != asmjit::Error::kOk) {
|
||||
printf(" !! %s failed with <%s>, but should have failed with <%s>\n", s, asmjit::DebugUtils::error_as_string(err), asmjit::DebugUtils::error_as_string(expected_error));
|
||||
prepare();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (settings.verbose)
|
||||
printf(" OK [%s] <- %s\n", asmjit::DebugUtils::error_as_string(err), s);
|
||||
|
||||
passed++;
|
||||
prepare();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // ASMJIT_TEST_ASSEMBLER_H_INCLUDED
|
||||
Reference in New Issue
Block a user