mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-17 12:34:35 +03:00
[Bug] Assign inline comments to Invoke/Func nodes, annotate without Logger
This commit is contained in:
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: "Checkout"
|
- name: "Checkout"
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: "Setup node.js"
|
- name: "Setup node.js"
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
|
|||||||
@@ -4997,9 +4997,7 @@ EmitDone:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
resetExtraReg();
|
resetState();
|
||||||
resetInstOptions();
|
|
||||||
resetInlineComment();
|
|
||||||
|
|
||||||
writer.done(this);
|
writer.done(this);
|
||||||
return kErrorOk;
|
return kErrorOk;
|
||||||
@@ -5025,9 +5023,7 @@ Failed:
|
|||||||
#ifndef ASMJIT_NO_LOGGING
|
#ifndef ASMJIT_NO_LOGGING
|
||||||
return EmitterUtils::logInstructionFailed(this, err, instId, options, o0, o1, o2, opExt);
|
return EmitterUtils::logInstructionFailed(this, err, instId, options, o0, o1, o2, opExt);
|
||||||
#else
|
#else
|
||||||
resetExtraReg();
|
resetState();
|
||||||
resetInstOptions();
|
|
||||||
resetInlineComment();
|
|
||||||
return reportError(err);
|
return reportError(err);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -597,9 +597,7 @@ Error BaseBuilder::_emit(InstId instId, const Operand_& o0, const Operand_& o1,
|
|||||||
#ifndef ASMJIT_NO_LOGGING
|
#ifndef ASMJIT_NO_LOGGING
|
||||||
return EmitterUtils::logInstructionFailed(this, err, instId, options, o0, o1, o2, opExt);
|
return EmitterUtils::logInstructionFailed(this, err, instId, options, o0, o1, o2, opExt);
|
||||||
#else
|
#else
|
||||||
resetInstOptions();
|
resetState();
|
||||||
resetExtraReg();
|
|
||||||
resetInlineComment();
|
|
||||||
return reportError(err);
|
return reportError(err);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
35
src/asmjit/core/builder_p.h
Normal file
35
src/asmjit/core/builder_p.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
// 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_CORE_BUILDER_P_H_INCLUDED
|
||||||
|
#define ASMJIT_CORE_BUILDER_P_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../core/api-config.h"
|
||||||
|
#ifndef ASMJIT_NO_BUILDER
|
||||||
|
|
||||||
|
#include "../core/builder.h"
|
||||||
|
|
||||||
|
ASMJIT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
//! \addtogroup asmjit_builder
|
||||||
|
//! \{
|
||||||
|
|
||||||
|
static inline void BaseBuilder_assignInlineComment(BaseBuilder* self, BaseNode* node, const char* comment) noexcept {
|
||||||
|
if (comment)
|
||||||
|
node->setInlineComment(static_cast<char*>(self->_dataZone.dup(comment, strlen(comment), true)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void BaseBuilder_assignInstState(BaseBuilder* self, InstNode* node, const BaseEmitter::State& state) noexcept {
|
||||||
|
node->setOptions(state.options);
|
||||||
|
node->setExtraReg(state.extraReg);
|
||||||
|
BaseBuilder_assignInlineComment(self, node, state.comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \}
|
||||||
|
|
||||||
|
ASMJIT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // !ASMJIT_NO_BUILDER
|
||||||
|
#endif // ASMJIT_CORE_BUILDER_P_H_INCLUDED
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#ifndef ASMJIT_NO_COMPILER
|
#ifndef ASMJIT_NO_COMPILER
|
||||||
|
|
||||||
#include "../core/assembler.h"
|
#include "../core/assembler.h"
|
||||||
|
#include "../core/builder_p.h"
|
||||||
#include "../core/compiler.h"
|
#include "../core/compiler.h"
|
||||||
#include "../core/cpuinfo.h"
|
#include "../core/cpuinfo.h"
|
||||||
#include "../core/logger.h"
|
#include "../core/logger.h"
|
||||||
@@ -103,9 +104,13 @@ Error BaseCompiler::newFuncNode(FuncNode** out, const FuncSignature& signature)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Error BaseCompiler::addFuncNode(FuncNode** out, const FuncSignature& signature) {
|
Error BaseCompiler::addFuncNode(FuncNode** out, const FuncSignature& signature) {
|
||||||
|
State state = _grabState();
|
||||||
|
|
||||||
ASMJIT_PROPAGATE(newFuncNode(out, signature));
|
ASMJIT_PROPAGATE(newFuncNode(out, signature));
|
||||||
ASMJIT_ASSUME(*out != nullptr);
|
ASMJIT_ASSUME(*out != nullptr);
|
||||||
|
|
||||||
|
BaseBuilder_assignInlineComment(this, *out, state.comment);
|
||||||
|
|
||||||
addFunc(*out);
|
addFunc(*out);
|
||||||
return kErrorOk;
|
return kErrorOk;
|
||||||
}
|
}
|
||||||
@@ -127,7 +132,13 @@ Error BaseCompiler::newFuncRetNode(FuncRetNode** out, const Operand_& o0, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
Error BaseCompiler::addFuncRetNode(FuncRetNode** out, const Operand_& o0, const Operand_& o1) {
|
Error BaseCompiler::addFuncRetNode(FuncRetNode** out, const Operand_& o0, const Operand_& o1) {
|
||||||
|
State state = _grabState();
|
||||||
|
|
||||||
ASMJIT_PROPAGATE(newFuncRetNode(out, o0, o1));
|
ASMJIT_PROPAGATE(newFuncRetNode(out, o0, o1));
|
||||||
|
ASMJIT_ASSUME(*out != nullptr);
|
||||||
|
|
||||||
|
BaseBuilder_assignInlineComment(this, *out, state.comment);
|
||||||
|
|
||||||
addNode(*out);
|
addNode(*out);
|
||||||
return kErrorOk;
|
return kErrorOk;
|
||||||
}
|
}
|
||||||
@@ -146,6 +157,7 @@ FuncNode* BaseCompiler::addFunc(FuncNode* func) {
|
|||||||
|
|
||||||
Error BaseCompiler::endFunc() {
|
Error BaseCompiler::endFunc() {
|
||||||
FuncNode* func = _func;
|
FuncNode* func = _func;
|
||||||
|
resetState();
|
||||||
|
|
||||||
if (ASMJIT_UNLIKELY(!func))
|
if (ASMJIT_UNLIKELY(!func))
|
||||||
return reportError(DebugUtils::errored(kErrorInvalidState));
|
return reportError(DebugUtils::errored(kErrorInvalidState));
|
||||||
@@ -196,7 +208,12 @@ Error BaseCompiler::newInvokeNode(InvokeNode** out, InstId instId, const Operand
|
|||||||
}
|
}
|
||||||
|
|
||||||
Error BaseCompiler::addInvokeNode(InvokeNode** out, InstId instId, const Operand_& o0, const FuncSignature& signature) {
|
Error BaseCompiler::addInvokeNode(InvokeNode** out, InstId instId, const Operand_& o0, const FuncSignature& signature) {
|
||||||
|
State state = _grabState();
|
||||||
|
|
||||||
ASMJIT_PROPAGATE(newInvokeNode(out, instId, o0, signature));
|
ASMJIT_PROPAGATE(newInvokeNode(out, instId, o0, signature));
|
||||||
|
ASMJIT_ASSUME(*out != nullptr);
|
||||||
|
|
||||||
|
BaseBuilder_assignInstState(this, *out, state);
|
||||||
addNode(*out);
|
addNode(*out);
|
||||||
return kErrorOk;
|
return kErrorOk;
|
||||||
}
|
}
|
||||||
@@ -481,20 +498,13 @@ Error BaseCompiler::newJumpNode(JumpNode** out, InstId instId, InstOptions instO
|
|||||||
}
|
}
|
||||||
|
|
||||||
Error BaseCompiler::emitAnnotatedJump(InstId instId, const Operand_& o0, JumpAnnotation* annotation) {
|
Error BaseCompiler::emitAnnotatedJump(InstId instId, const Operand_& o0, JumpAnnotation* annotation) {
|
||||||
InstOptions options = instOptions() | forcedInstOptions();
|
State state = _grabState();
|
||||||
RegOnly extra = extraReg();
|
|
||||||
const char* comment = inlineComment();
|
|
||||||
|
|
||||||
resetInstOptions();
|
|
||||||
resetInlineComment();
|
|
||||||
resetExtraReg();
|
|
||||||
|
|
||||||
JumpNode* node;
|
JumpNode* node;
|
||||||
ASMJIT_PROPAGATE(newJumpNode(&node, instId, options, o0, annotation));
|
ASMJIT_PROPAGATE(newJumpNode(&node, instId, state.options, o0, annotation));
|
||||||
|
|
||||||
node->setExtraReg(extra);
|
node->setExtraReg(state.extraReg);
|
||||||
if (comment)
|
BaseBuilder_assignInlineComment(this, node, state.comment);
|
||||||
node->setInlineComment(static_cast<char*>(_dataZone.dup(comment, strlen(comment), true)));
|
|
||||||
|
|
||||||
addNode(node);
|
addNode(node);
|
||||||
return kErrorOk;
|
return kErrorOk;
|
||||||
|
|||||||
@@ -233,6 +233,13 @@ public:
|
|||||||
//! Native GP register signature and signature related information.
|
//! Native GP register signature and signature related information.
|
||||||
OperandSignature _gpSignature {};
|
OperandSignature _gpSignature {};
|
||||||
|
|
||||||
|
//! Emitter state that can be used to specify options and inline comment of a next node or instruction.
|
||||||
|
struct State {
|
||||||
|
InstOptions options;
|
||||||
|
RegOnly extraReg;
|
||||||
|
const char* comment;
|
||||||
|
};
|
||||||
|
|
||||||
//! Next instruction options (affects the next instruction).
|
//! Next instruction options (affects the next instruction).
|
||||||
InstOptions _instOptions = InstOptions::kNone;
|
InstOptions _instOptions = InstOptions::kNone;
|
||||||
//! Extra register (op-mask {k} on AVX-512) (affects the next instruction).
|
//! Extra register (op-mask {k} on AVX-512) (affects the next instruction).
|
||||||
@@ -530,6 +537,23 @@ public:
|
|||||||
|
|
||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
|
//! \name Emitter State
|
||||||
|
//! \{
|
||||||
|
|
||||||
|
inline void resetState() noexcept {
|
||||||
|
resetInstOptions();
|
||||||
|
resetExtraReg();
|
||||||
|
resetInlineComment();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline State _grabState() noexcept {
|
||||||
|
State s{_instOptions | _forcedInstOptions, _extraReg, _inlineComment};
|
||||||
|
resetState();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \}
|
||||||
|
|
||||||
//! \name Sections
|
//! \name Sections
|
||||||
//! \{
|
//! \{
|
||||||
|
|
||||||
|
|||||||
@@ -116,9 +116,7 @@ Error logInstructionFailed(
|
|||||||
sb.append(self->inlineComment());
|
sb.append(self->inlineComment());
|
||||||
}
|
}
|
||||||
|
|
||||||
self->resetInstOptions();
|
self->resetState();
|
||||||
self->resetExtraReg();
|
|
||||||
self->resetInlineComment();
|
|
||||||
return self->reportError(err, sb.data());
|
return self->reportError(err, sb.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,11 +114,14 @@ Error BaseRAPass::runOnFunction(Zone* zone, Logger* logger, FuncNode* func) {
|
|||||||
#ifndef ASMJIT_NO_LOGGING
|
#ifndef ASMJIT_NO_LOGGING
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_formatOptions.reset();
|
_formatOptions.reset();
|
||||||
_diagnosticOptions = DiagnosticOptions::kNone;
|
_diagnosticOptions = _cb->diagnosticOptions();
|
||||||
|
|
||||||
if (logger) {
|
if (logger) {
|
||||||
_formatOptions = logger->options();
|
_formatOptions = logger->options();
|
||||||
_diagnosticOptions = _cb->diagnosticOptions();
|
}
|
||||||
|
else {
|
||||||
|
_diagnosticOptions &= ~(DiagnosticOptions::kRADebugCFG |
|
||||||
|
DiagnosticOptions::kRADebugUnreachable);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
DebugUtils::unused(logger);
|
DebugUtils::unused(logger);
|
||||||
|
|||||||
@@ -4950,10 +4950,7 @@ EmitDone:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
resetExtraReg();
|
resetState();
|
||||||
resetInstOptions();
|
|
||||||
resetInlineComment();
|
|
||||||
|
|
||||||
writer.done(this);
|
writer.done(this);
|
||||||
return kErrorOk;
|
return kErrorOk;
|
||||||
|
|
||||||
@@ -4987,9 +4984,7 @@ Failed:
|
|||||||
#ifndef ASMJIT_NO_LOGGING
|
#ifndef ASMJIT_NO_LOGGING
|
||||||
return EmitterUtils::logInstructionFailed(this, err, instId, options, o0, o1, o2, opExt);
|
return EmitterUtils::logInstructionFailed(this, err, instId, options, o0, o1, o2, opExt);
|
||||||
#else
|
#else
|
||||||
resetExtraReg();
|
resetState();
|
||||||
resetInstOptions();
|
|
||||||
resetInlineComment();
|
|
||||||
return reportError(err);
|
return reportError(err);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -794,6 +794,9 @@ Error InstInternal::queryRWInfo(Arch arch, const BaseInst& inst, const Operand_*
|
|||||||
if (ASMJIT_UNLIKELY(!Inst::isDefinedId(instId)))
|
if (ASMJIT_UNLIKELY(!Inst::isDefinedId(instId)))
|
||||||
return DebugUtils::errored(kErrorInvalidInstruction);
|
return DebugUtils::errored(kErrorInvalidInstruction);
|
||||||
|
|
||||||
|
if (instId == Inst::kIdPop)
|
||||||
|
printf("HERE\n");
|
||||||
|
|
||||||
// Read/Write flags.
|
// Read/Write flags.
|
||||||
const InstDB::InstInfo& instInfo = InstDB::_instInfoTable[instId];
|
const InstDB::InstInfo& instInfo = InstDB::_instInfoTable[instId];
|
||||||
const InstDB::CommonInfo& commonInfo = InstDB::_commonInfoTable[instInfo._commonInfoIndex];
|
const InstDB::CommonInfo& commonInfo = InstDB::_commonInfoTable[instInfo._commonInfoIndex];
|
||||||
|
|||||||
@@ -2247,8 +2247,9 @@ class InstRWInfoTable extends core.Task {
|
|||||||
const operands = dbInst.operands;
|
const operands = dbInst.operands;
|
||||||
const rwOps = nullOps();
|
const rwOps = nullOps();
|
||||||
|
|
||||||
for (var j = 0; j < operands.length; j++)
|
for (var j = 0; j < operands.length; j++) {
|
||||||
rwOps[j] = makeRwFromOp(operands[j])
|
rwOps[j] = makeRwFromOp(operands[j])
|
||||||
|
}
|
||||||
|
|
||||||
var match = 0;
|
var match = 0;
|
||||||
for (var j = 0; j < rwOpsArray.length; j++)
|
for (var j = 0; j < rwOpsArray.length; j++)
|
||||||
|
|||||||
Reference in New Issue
Block a user