asmjit 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/asmjit.gemspec +1 -1
- data/ext/asmjit/asmjit/.editorconfig +10 -0
- data/ext/asmjit/asmjit/.github/FUNDING.yml +1 -0
- data/ext/asmjit/asmjit/.github/workflows/build-config.json +47 -0
- data/ext/asmjit/asmjit/.github/workflows/build.yml +156 -0
- data/ext/asmjit/asmjit/.gitignore +6 -0
- data/ext/asmjit/asmjit/CMakeLists.txt +611 -0
- data/ext/asmjit/asmjit/LICENSE.md +17 -0
- data/ext/asmjit/asmjit/README.md +69 -0
- data/ext/asmjit/asmjit/src/asmjit/a64.h +62 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64archtraits_p.h +81 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.cpp +5115 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.h +72 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.cpp +51 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.h +57 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.cpp +60 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.h +247 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper.cpp +464 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper_p.h +50 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64emitter.h +1228 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter.cpp +298 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter_p.h +59 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64func.cpp +189 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64func_p.h +33 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64globals.h +1894 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi.cpp +278 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi_p.h +41 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.cpp +1957 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.h +74 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb_p.h +876 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.cpp +85 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.h +312 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass.cpp +852 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass_p.h +105 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64utils.h +179 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/armformatter.cpp +143 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/armformatter_p.h +44 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/armglobals.h +21 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/armoperand.h +621 -0
- data/ext/asmjit/asmjit/src/asmjit/arm.h +62 -0
- data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-begin.h +17 -0
- data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-end.h +9 -0
- data/ext/asmjit/asmjit/src/asmjit/asmjit.h +33 -0
- data/ext/asmjit/asmjit/src/asmjit/core/api-build_p.h +55 -0
- data/ext/asmjit/asmjit/src/asmjit/core/api-config.h +613 -0
- data/ext/asmjit/asmjit/src/asmjit/core/archcommons.h +229 -0
- data/ext/asmjit/asmjit/src/asmjit/core/archtraits.cpp +160 -0
- data/ext/asmjit/asmjit/src/asmjit/core/archtraits.h +290 -0
- data/ext/asmjit/asmjit/src/asmjit/core/assembler.cpp +406 -0
- data/ext/asmjit/asmjit/src/asmjit/core/assembler.h +129 -0
- data/ext/asmjit/asmjit/src/asmjit/core/builder.cpp +889 -0
- data/ext/asmjit/asmjit/src/asmjit/core/builder.h +1391 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codebuffer.h +113 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codeholder.cpp +1149 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codeholder.h +1035 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codewriter.cpp +175 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codewriter_p.h +179 -0
- data/ext/asmjit/asmjit/src/asmjit/core/compiler.cpp +582 -0
- data/ext/asmjit/asmjit/src/asmjit/core/compiler.h +737 -0
- data/ext/asmjit/asmjit/src/asmjit/core/compilerdefs.h +173 -0
- data/ext/asmjit/asmjit/src/asmjit/core/constpool.cpp +363 -0
- data/ext/asmjit/asmjit/src/asmjit/core/constpool.h +250 -0
- data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.cpp +1162 -0
- data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.h +813 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emithelper.cpp +323 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emithelper_p.h +58 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emitter.cpp +333 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emitter.h +741 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emitterutils.cpp +129 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emitterutils_p.h +89 -0
- data/ext/asmjit/asmjit/src/asmjit/core/environment.cpp +46 -0
- data/ext/asmjit/asmjit/src/asmjit/core/environment.h +508 -0
- data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.cpp +14 -0
- data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.h +228 -0
- data/ext/asmjit/asmjit/src/asmjit/core/formatter.cpp +584 -0
- data/ext/asmjit/asmjit/src/asmjit/core/formatter.h +247 -0
- data/ext/asmjit/asmjit/src/asmjit/core/formatter_p.h +34 -0
- data/ext/asmjit/asmjit/src/asmjit/core/func.cpp +286 -0
- data/ext/asmjit/asmjit/src/asmjit/core/func.h +1445 -0
- data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext.cpp +293 -0
- data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext_p.h +199 -0
- data/ext/asmjit/asmjit/src/asmjit/core/globals.cpp +133 -0
- data/ext/asmjit/asmjit/src/asmjit/core/globals.h +393 -0
- data/ext/asmjit/asmjit/src/asmjit/core/inst.cpp +113 -0
- data/ext/asmjit/asmjit/src/asmjit/core/inst.h +772 -0
- data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.cpp +1242 -0
- data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.h +261 -0
- data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.cpp +80 -0
- data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.h +89 -0
- data/ext/asmjit/asmjit/src/asmjit/core/logger.cpp +69 -0
- data/ext/asmjit/asmjit/src/asmjit/core/logger.h +198 -0
- data/ext/asmjit/asmjit/src/asmjit/core/misc_p.h +33 -0
- data/ext/asmjit/asmjit/src/asmjit/core/operand.cpp +132 -0
- data/ext/asmjit/asmjit/src/asmjit/core/operand.h +1611 -0
- data/ext/asmjit/asmjit/src/asmjit/core/osutils.cpp +84 -0
- data/ext/asmjit/asmjit/src/asmjit/core/osutils.h +61 -0
- data/ext/asmjit/asmjit/src/asmjit/core/osutils_p.h +68 -0
- data/ext/asmjit/asmjit/src/asmjit/core/raassignment_p.h +418 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rabuilders_p.h +612 -0
- data/ext/asmjit/asmjit/src/asmjit/core/radefs_p.h +1204 -0
- data/ext/asmjit/asmjit/src/asmjit/core/ralocal.cpp +1166 -0
- data/ext/asmjit/asmjit/src/asmjit/core/ralocal_p.h +254 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rapass.cpp +1969 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rapass_p.h +1183 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rastack.cpp +184 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rastack_p.h +171 -0
- data/ext/asmjit/asmjit/src/asmjit/core/string.cpp +559 -0
- data/ext/asmjit/asmjit/src/asmjit/core/string.h +372 -0
- data/ext/asmjit/asmjit/src/asmjit/core/support.cpp +494 -0
- data/ext/asmjit/asmjit/src/asmjit/core/support.h +1773 -0
- data/ext/asmjit/asmjit/src/asmjit/core/target.cpp +14 -0
- data/ext/asmjit/asmjit/src/asmjit/core/target.h +53 -0
- data/ext/asmjit/asmjit/src/asmjit/core/type.cpp +74 -0
- data/ext/asmjit/asmjit/src/asmjit/core/type.h +419 -0
- data/ext/asmjit/asmjit/src/asmjit/core/virtmem.cpp +722 -0
- data/ext/asmjit/asmjit/src/asmjit/core/virtmem.h +242 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zone.cpp +353 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zone.h +615 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonehash.cpp +309 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonehash.h +186 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonelist.cpp +163 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonelist.h +209 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonestack.cpp +176 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonestack.h +239 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonestring.h +120 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonetree.cpp +99 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonetree.h +380 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonevector.cpp +356 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonevector.h +690 -0
- data/ext/asmjit/asmjit/src/asmjit/core.h +1861 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86archtraits_p.h +148 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.cpp +5110 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.h +685 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.cpp +52 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.h +351 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.cpp +61 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.h +721 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper.cpp +619 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper_p.h +60 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86emitter.h +4315 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter.cpp +944 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter_p.h +58 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86func.cpp +503 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86func_p.h +33 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86globals.h +2169 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi.cpp +1732 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi_p.h +41 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.cpp +4427 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.h +563 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb_p.h +311 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86opcode_p.h +436 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.cpp +231 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.h +1085 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass.cpp +1509 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass_p.h +94 -0
- data/ext/asmjit/asmjit/src/asmjit/x86.h +93 -0
- data/ext/asmjit/asmjit/src/asmjit.natvis +245 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler.cpp +84 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler.h +85 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler_a64.cpp +4006 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler_x64.cpp +17833 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler_x86.cpp +8300 -0
- data/ext/asmjit/asmjit/test/asmjit_test_compiler.cpp +253 -0
- data/ext/asmjit/asmjit/test/asmjit_test_compiler.h +73 -0
- data/ext/asmjit/asmjit/test/asmjit_test_compiler_a64.cpp +690 -0
- data/ext/asmjit/asmjit/test/asmjit_test_compiler_x86.cpp +4317 -0
- data/ext/asmjit/asmjit/test/asmjit_test_emitters.cpp +197 -0
- data/ext/asmjit/asmjit/test/asmjit_test_instinfo.cpp +181 -0
- data/ext/asmjit/asmjit/test/asmjit_test_misc.h +257 -0
- data/ext/asmjit/asmjit/test/asmjit_test_perf.cpp +62 -0
- data/ext/asmjit/asmjit/test/asmjit_test_perf.h +61 -0
- data/ext/asmjit/asmjit/test/asmjit_test_perf_a64.cpp +699 -0
- data/ext/asmjit/asmjit/test/asmjit_test_perf_x86.cpp +5032 -0
- data/ext/asmjit/asmjit/test/asmjit_test_unit.cpp +172 -0
- data/ext/asmjit/asmjit/test/asmjit_test_x86_sections.cpp +172 -0
- data/ext/asmjit/asmjit/test/asmjitutils.h +38 -0
- data/ext/asmjit/asmjit/test/broken.cpp +312 -0
- data/ext/asmjit/asmjit/test/broken.h +148 -0
- data/ext/asmjit/asmjit/test/cmdline.h +61 -0
- data/ext/asmjit/asmjit/test/performancetimer.h +41 -0
- data/ext/asmjit/asmjit/tools/configure-makefiles.sh +13 -0
- data/ext/asmjit/asmjit/tools/configure-ninja.sh +13 -0
- data/ext/asmjit/asmjit/tools/configure-sanitizers.sh +13 -0
- data/ext/asmjit/asmjit/tools/configure-vs2019-x64.bat +2 -0
- data/ext/asmjit/asmjit/tools/configure-vs2019-x86.bat +2 -0
- data/ext/asmjit/asmjit/tools/configure-vs2022-x64.bat +2 -0
- data/ext/asmjit/asmjit/tools/configure-vs2022-x86.bat +2 -0
- data/ext/asmjit/asmjit/tools/configure-xcode.sh +8 -0
- data/ext/asmjit/asmjit/tools/enumgen.js +417 -0
- data/ext/asmjit/asmjit/tools/enumgen.sh +3 -0
- data/ext/asmjit/asmjit/tools/tablegen-arm.js +365 -0
- data/ext/asmjit/asmjit/tools/tablegen-arm.sh +3 -0
- data/ext/asmjit/asmjit/tools/tablegen-x86.js +2638 -0
- data/ext/asmjit/asmjit/tools/tablegen-x86.sh +3 -0
- data/ext/asmjit/asmjit/tools/tablegen.js +947 -0
- data/ext/asmjit/asmjit/tools/tablegen.sh +4 -0
- data/ext/asmjit/asmjit.cc +18 -0
- data/lib/asmjit/version.rb +1 -1
- metadata +197 -2
@@ -0,0 +1,228 @@
|
|
1
|
+
// This file is part of AsmJit project <https://asmjit.com>
|
2
|
+
//
|
3
|
+
// See asmjit.h or LICENSE.md for license and copyright information
|
4
|
+
// SPDX-License-Identifier: Zlib
|
5
|
+
|
6
|
+
#ifndef ASMJIT_CORE_ERRORHANDLER_H_INCLUDED
|
7
|
+
#define ASMJIT_CORE_ERRORHANDLER_H_INCLUDED
|
8
|
+
|
9
|
+
#include "../core/globals.h"
|
10
|
+
|
11
|
+
ASMJIT_BEGIN_NAMESPACE
|
12
|
+
|
13
|
+
//! \addtogroup asmjit_error_handling
|
14
|
+
//! \{
|
15
|
+
|
16
|
+
class BaseEmitter;
|
17
|
+
|
18
|
+
//! Error handler can be used to override the default behavior of error handling.
|
19
|
+
//!
|
20
|
+
//! It's available to all classes that inherit `BaseEmitter`. Override \ref ErrorHandler::handleError() to implement
|
21
|
+
//! your own error handler.
|
22
|
+
//!
|
23
|
+
//! The following use-cases are supported:
|
24
|
+
//!
|
25
|
+
//! - Record the error and continue code generation. This is the simplest approach that can be used to at least log
|
26
|
+
//! possible errors.
|
27
|
+
//! - Throw an exception. AsmJit doesn't use exceptions and is completely exception-safe, but it's perfectly legal
|
28
|
+
//! to throw an exception from the error handler.
|
29
|
+
//! - Use plain old C's `setjmp()` and `longjmp()`. Asmjit always puts Assembler, Builder and Compiler to
|
30
|
+
//! a consistent state before calling \ref handleError(), so `longjmp()` can be used without issues to cancel the
|
31
|
+
//! code generation if an error occurred. This method can be used if exception handling in your project is turned
|
32
|
+
//! off and you still want some comfort. In most cases it should be safe as AsmJit uses \ref Zone memory and the
|
33
|
+
//! ownership of memory it allocates always ends with the instance that allocated it. If using this approach please
|
34
|
+
//! never jump outside the life-time of \ref CodeHolder and \ref BaseEmitter.
|
35
|
+
//!
|
36
|
+
//! \ref ErrorHandler can be attached to \ref CodeHolder or \ref BaseEmitter, which has a priority. The example below
|
37
|
+
//! uses error handler that just prints the error, but lets AsmJit continue:
|
38
|
+
//!
|
39
|
+
//! ```
|
40
|
+
//! // Error Handling #1 - Logging and returning Error.
|
41
|
+
//! #include <asmjit/x86.h>
|
42
|
+
//! #include <stdio.h>
|
43
|
+
//!
|
44
|
+
//! using namespace asmjit;
|
45
|
+
//!
|
46
|
+
//! // Error handler that just prints the error and lets AsmJit ignore it.
|
47
|
+
//! class SimpleErrorHandler : public ErrorHandler {
|
48
|
+
//! public:
|
49
|
+
//! Error err;
|
50
|
+
//!
|
51
|
+
//! inline SimpleErrorHandler() : err(kErrorOk) {}
|
52
|
+
//!
|
53
|
+
//! void handleError(Error err, const char* message, BaseEmitter* origin) override {
|
54
|
+
//! this->err = err;
|
55
|
+
//! fprintf(stderr, "ERROR: %s\n", message);
|
56
|
+
//! }
|
57
|
+
//! };
|
58
|
+
//!
|
59
|
+
//! int main() {
|
60
|
+
//! JitRuntime rt;
|
61
|
+
//! SimpleErrorHandler eh;
|
62
|
+
//!
|
63
|
+
//! CodeHolder code;
|
64
|
+
//! code.init(rt.environment());
|
65
|
+
//! code.setErrorHandler(&eh);
|
66
|
+
//!
|
67
|
+
//! // Try to emit instruction that doesn't exist.
|
68
|
+
//! x86::Assembler a(&code);
|
69
|
+
//! a.emit(x86::Inst::kIdMov, x86::xmm0, x86::xmm1);
|
70
|
+
//!
|
71
|
+
//! if (eh.err) {
|
72
|
+
//! // Assembler failed!
|
73
|
+
//! return 1;
|
74
|
+
//! }
|
75
|
+
//!
|
76
|
+
//! return 0;
|
77
|
+
//! }
|
78
|
+
//! ```
|
79
|
+
//!
|
80
|
+
//! If error happens during instruction emitting / encoding the assembler behaves transactionally - the output buffer
|
81
|
+
//! won't advance if encoding failed, thus either a fully encoded instruction or nothing is emitted. The error handling
|
82
|
+
//! shown above is useful, but it's still not the best way of dealing with errors in AsmJit. The following example
|
83
|
+
//! shows how to use exception handling to handle errors in a more C++ way:
|
84
|
+
//!
|
85
|
+
//! ```
|
86
|
+
//! // Error Handling #2 - Throwing an exception.
|
87
|
+
//! #include <asmjit/x86.h>
|
88
|
+
//! #include <exception>
|
89
|
+
//! #include <string>
|
90
|
+
//! #include <stdio.h>
|
91
|
+
//!
|
92
|
+
//! using namespace asmjit;
|
93
|
+
//!
|
94
|
+
//! // Error handler that throws a user-defined `AsmJitException`.
|
95
|
+
//! class AsmJitException : public std::exception {
|
96
|
+
//! public:
|
97
|
+
//! Error err;
|
98
|
+
//! std::string message;
|
99
|
+
//!
|
100
|
+
//! AsmJitException(Error err, const char* message) noexcept
|
101
|
+
//! : err(err),
|
102
|
+
//! message(message) {}
|
103
|
+
//!
|
104
|
+
//! const char* what() const noexcept override { return message.c_str(); }
|
105
|
+
//! };
|
106
|
+
//!
|
107
|
+
//! class ThrowableErrorHandler : public ErrorHandler {
|
108
|
+
//! public:
|
109
|
+
//! // Throw is possible, functions that use ErrorHandler are never 'noexcept'.
|
110
|
+
//! void handleError(Error err, const char* message, BaseEmitter* origin) override {
|
111
|
+
//! throw AsmJitException(err, message);
|
112
|
+
//! }
|
113
|
+
//! };
|
114
|
+
//!
|
115
|
+
//! int main() {
|
116
|
+
//! JitRuntime rt;
|
117
|
+
//! ThrowableErrorHandler eh;
|
118
|
+
//!
|
119
|
+
//! CodeHolder code;
|
120
|
+
//! code.init(rt.environment());
|
121
|
+
//! code.setErrorHandler(&eh);
|
122
|
+
//!
|
123
|
+
//! x86::Assembler a(&code);
|
124
|
+
//!
|
125
|
+
//! // Try to emit instruction that doesn't exist.
|
126
|
+
//! try {
|
127
|
+
//! a.emit(x86::Inst::kIdMov, x86::xmm0, x86::xmm1);
|
128
|
+
//! }
|
129
|
+
//! catch (const AsmJitException& ex) {
|
130
|
+
//! printf("EXCEPTION THROWN: %s\n", ex.what());
|
131
|
+
//! return 1;
|
132
|
+
//! }
|
133
|
+
//!
|
134
|
+
//! return 0;
|
135
|
+
//! }
|
136
|
+
//! ```
|
137
|
+
//!
|
138
|
+
//! If C++ exceptions are not what you like or your project turns off them completely there is still a way of reducing
|
139
|
+
//! the error handling to a minimum by using a standard setjmp/longjmp approach. AsmJit is exception-safe and cleans
|
140
|
+
//! up everything before calling the ErrorHandler, so any approach is safe. You can simply jump from the error handler
|
141
|
+
//! without causing any side-effects or memory leaks. The following example demonstrates how it could be done:
|
142
|
+
//!
|
143
|
+
//! ```
|
144
|
+
//! // Error Handling #3 - Using setjmp/longjmp if exceptions are not allowed.
|
145
|
+
//! #include <asmjit/x86.h>
|
146
|
+
//! #include <setjmp.h>
|
147
|
+
//! #include <stdio.h>
|
148
|
+
//!
|
149
|
+
//! class LongJmpErrorHandler : public asmjit::ErrorHandler {
|
150
|
+
//! public:
|
151
|
+
//! inline LongJmpErrorHandler() : err(asmjit::kErrorOk) {}
|
152
|
+
//!
|
153
|
+
//! void handleError(asmjit::Error err, const char* message, asmjit::BaseEmitter* origin) override {
|
154
|
+
//! this->err = err;
|
155
|
+
//! longjmp(state, 1);
|
156
|
+
//! }
|
157
|
+
//!
|
158
|
+
//! jmp_buf state;
|
159
|
+
//! asmjit::Error err;
|
160
|
+
//! };
|
161
|
+
//!
|
162
|
+
//! int main(int argc, char* argv[]) {
|
163
|
+
//! using namespace asmjit;
|
164
|
+
//!
|
165
|
+
//! JitRuntime rt;
|
166
|
+
//! LongJmpErrorHandler eh;
|
167
|
+
//!
|
168
|
+
//! CodeHolder code;
|
169
|
+
//! code.init(rt.rt.environment());
|
170
|
+
//! code.setErrorHandler(&eh);
|
171
|
+
//!
|
172
|
+
//! x86::Assembler a(&code);
|
173
|
+
//!
|
174
|
+
//! if (!setjmp(eh.state)) {
|
175
|
+
//! // Try to emit instruction that doesn't exist.
|
176
|
+
//! a.emit(x86::Inst::kIdMov, x86::xmm0, x86::xmm1);
|
177
|
+
//! }
|
178
|
+
//! else {
|
179
|
+
//! Error err = eh.err;
|
180
|
+
//! printf("ASMJIT ERROR: 0x%08X [%s]\n", err, DebugUtils::errorAsString(err));
|
181
|
+
//! }
|
182
|
+
//!
|
183
|
+
//! return 0;
|
184
|
+
//! }
|
185
|
+
//! ```
|
186
|
+
class ASMJIT_VIRTAPI ErrorHandler {
|
187
|
+
public:
|
188
|
+
ASMJIT_BASE_CLASS(ErrorHandler)
|
189
|
+
|
190
|
+
//! \name Construction & Destruction
|
191
|
+
//! \{
|
192
|
+
|
193
|
+
//! Creates a new `ErrorHandler` instance.
|
194
|
+
ASMJIT_API ErrorHandler() noexcept;
|
195
|
+
//! Destroys the `ErrorHandler` instance.
|
196
|
+
ASMJIT_API virtual ~ErrorHandler() noexcept;
|
197
|
+
|
198
|
+
//! \}
|
199
|
+
|
200
|
+
//! \name Interface
|
201
|
+
//! \{
|
202
|
+
|
203
|
+
//! Error handler (must be reimplemented).
|
204
|
+
//!
|
205
|
+
//! Error handler is called after an error happened and before it's propagated to the caller. There are multiple
|
206
|
+
//! ways how the error handler can be used:
|
207
|
+
//!
|
208
|
+
//! 1. User-based error handling without throwing exception or using C's`longjmp()`. This is for users that don't
|
209
|
+
//! use exceptions and want customized error handling.
|
210
|
+
//!
|
211
|
+
//! 2. Throwing an exception. AsmJit doesn't use exceptions and is completely exception-safe, but you can throw
|
212
|
+
//! exception from your error handler if this way is the preferred way of handling errors in your project.
|
213
|
+
//!
|
214
|
+
//! 3. Using plain old C's `setjmp()` and `longjmp()`. Asmjit always puts `BaseEmitter` to a consistent state before
|
215
|
+
//! calling `handleError()` so `longjmp()` can be used without any issues to cancel the code generation if an
|
216
|
+
//! error occurred. There is no difference between exceptions and `longjmp()` from AsmJit's perspective, however,
|
217
|
+
//! never jump outside of `CodeHolder` and `BaseEmitter` scope as you would leak memory.
|
218
|
+
virtual void handleError(Error err, const char* message, BaseEmitter* origin) = 0;
|
219
|
+
|
220
|
+
//! \}
|
221
|
+
};
|
222
|
+
|
223
|
+
//! \}
|
224
|
+
|
225
|
+
ASMJIT_END_NAMESPACE
|
226
|
+
|
227
|
+
#endif // ASMJIT_CORE_ERRORHANDLER_H_INCLUDED
|
228
|
+
|