mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-17 04:24:37 +03:00
Moved addFunc() from X86Compiler to Compiler.
Fixed CompilerContext not being reset after the first function is translated.
This commit is contained in:
@@ -165,6 +165,21 @@ HLHint* Compiler::newHintNode(Var& var, uint32_t hint, uint32_t value) noexcept
|
|||||||
// [asmjit::Compiler - Code-Stream]
|
// [asmjit::Compiler - Code-Stream]
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
|
HLNode* Compiler::addFunc(HLFunc* func) noexcept {
|
||||||
|
ASMJIT_ASSERT(_func == nullptr);
|
||||||
|
_func = func;
|
||||||
|
|
||||||
|
addNode(func); // Add function node.
|
||||||
|
addNode(func->getEntryNode()); // Add function entry.
|
||||||
|
HLNode* cursor = getCursor();
|
||||||
|
|
||||||
|
addNode(func->getExitNode()); // Add function exit / epilog marker.
|
||||||
|
addNode(func->getEnd()); // Add function end.
|
||||||
|
setCursor(cursor);
|
||||||
|
|
||||||
|
return func;
|
||||||
|
}
|
||||||
|
|
||||||
HLNode* Compiler::addNode(HLNode* node) noexcept {
|
HLNode* Compiler::addNode(HLNode* node) noexcept {
|
||||||
ASMJIT_ASSERT(node != nullptr);
|
ASMJIT_ASSERT(node != nullptr);
|
||||||
ASMJIT_ASSERT(node->_prev == nullptr);
|
ASMJIT_ASSERT(node->_prev == nullptr);
|
||||||
|
|||||||
@@ -291,6 +291,9 @@ struct ASMJIT_VIRTAPI Compiler : public ExternalTool {
|
|||||||
// [Code-Stream]
|
// [Code-Stream]
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//! Add a function `node` to the stream.
|
||||||
|
ASMJIT_API HLNode* addFunc(HLFunc* func) noexcept;
|
||||||
|
|
||||||
//! Add node `node` after current and set current to `node`.
|
//! Add node `node` after current and set current to `node`.
|
||||||
ASMJIT_API HLNode* addNode(HLNode* node) noexcept;
|
ASMJIT_API HLNode* addNode(HLNode* node) noexcept;
|
||||||
//! Insert `node` before `ref`.
|
//! Insert `node` before `ref`.
|
||||||
|
|||||||
@@ -3293,7 +3293,7 @@ struct ASMJIT_VIRTAPI X86Assembler : public Assembler {
|
|||||||
//! Packed DWORD unsigned maximum (SSE4.1).
|
//! Packed DWORD unsigned maximum (SSE4.1).
|
||||||
INST_2x(pmaxud, kX86InstIdPmaxud, X86XmmReg, X86XmmReg)
|
INST_2x(pmaxud, kX86InstIdPmaxud, X86XmmReg, X86XmmReg)
|
||||||
//! \overload
|
//! \overload
|
||||||
INST_2x(pmaxud,kX86InstIdPmaxud , X86XmmReg, X86Mem)
|
INST_2x(pmaxud, kX86InstIdPmaxud, X86XmmReg, X86Mem)
|
||||||
|
|
||||||
//! Packed WORD unsigned maximum (SSE4.1).
|
//! Packed WORD unsigned maximum (SSE4.1).
|
||||||
INST_2x(pmaxuw, kX86InstIdPmaxuw, X86XmmReg, X86XmmReg)
|
INST_2x(pmaxuw, kX86InstIdPmaxuw, X86XmmReg, X86XmmReg)
|
||||||
|
|||||||
@@ -292,6 +292,7 @@ Error X86Compiler::finalize() noexcept {
|
|||||||
|
|
||||||
error = context.serialize(assembler, start, node);
|
error = context.serialize(assembler, start, node);
|
||||||
context.cleanup();
|
context.cleanup();
|
||||||
|
context.reset(false);
|
||||||
|
|
||||||
if (error != kErrorOk)
|
if (error != kErrorOk)
|
||||||
break;
|
break;
|
||||||
@@ -642,18 +643,7 @@ X86FuncNode* X86Compiler::addFunc(const FuncPrototype& p) noexcept {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASMJIT_ASSERT(_func == nullptr);
|
return static_cast<X86FuncNode*>(addFunc(func));
|
||||||
_func = func;
|
|
||||||
|
|
||||||
addNode(func); // Add function node.
|
|
||||||
addNode(func->getEntryNode()); // Add function entry.
|
|
||||||
HLNode* cursor = getCursor();
|
|
||||||
|
|
||||||
addNode(func->getExitNode()); // Add function exit / epilog marker.
|
|
||||||
addNode(func->getEnd()); // Add function end.
|
|
||||||
setCursor(cursor);
|
|
||||||
|
|
||||||
return func;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HLSentinel* X86Compiler::endFunc() noexcept {
|
HLSentinel* X86Compiler::endFunc() noexcept {
|
||||||
|
|||||||
@@ -856,6 +856,8 @@ struct ASMJIT_VIRTAPI X86Compiler : public Compiler {
|
|||||||
//! Create a new `X86FuncNode`.
|
//! Create a new `X86FuncNode`.
|
||||||
ASMJIT_API X86FuncNode* newFunc(const FuncPrototype& p) noexcept;
|
ASMJIT_API X86FuncNode* newFunc(const FuncPrototype& p) noexcept;
|
||||||
|
|
||||||
|
using Compiler::addFunc;
|
||||||
|
|
||||||
//! Add a new function.
|
//! Add a new function.
|
||||||
//!
|
//!
|
||||||
//! \param p Function prototype.
|
//! \param p Function prototype.
|
||||||
|
|||||||
@@ -270,7 +270,6 @@ X86Context::X86Context(X86Compiler* compiler) : Context(compiler) {
|
|||||||
_state = &_x86State;
|
_state = &_x86State;
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
X86Context::~X86Context() {}
|
X86Context::~X86Context() {}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ struct X86Context : public Context {
|
|||||||
// [Reset]
|
// [Reset]
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
virtual void reset(bool releaseMemory = false);
|
virtual void reset(bool releaseMemory = false) override;
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// [Arch]
|
// [Arch]
|
||||||
|
|||||||
@@ -2804,6 +2804,67 @@ struct X86Test_MiscMultiRet : public X86Test {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// [X86Test_MiscMultiFunc]
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
struct X86Test_MiscMultiFunc : public X86Test {
|
||||||
|
X86Test_MiscMultiFunc() : X86Test("[Misc] MultiFunc") {}
|
||||||
|
|
||||||
|
static void add(PodVector<X86Test*>& tests) {
|
||||||
|
tests.append(new X86Test_MiscMultiFunc());
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void compile(X86Compiler& c) {
|
||||||
|
X86FuncNode* f1 = c.newFunc(FuncBuilder2<int, int, int>(kCallConvHost));
|
||||||
|
X86FuncNode* f2 = c.newFunc(FuncBuilder2<int, int, int>(kCallConvHost));
|
||||||
|
|
||||||
|
{
|
||||||
|
X86GpVar a = c.newInt32("a");
|
||||||
|
X86GpVar b = c.newInt32("b");
|
||||||
|
|
||||||
|
c.addFunc(f1);
|
||||||
|
c.setArg(0, a);
|
||||||
|
c.setArg(1, b);
|
||||||
|
|
||||||
|
X86CallNode* call = c.call(f2->getEntryLabel(), FuncBuilder2<int, int, int>(kCallConvHost));
|
||||||
|
call->setArg(0, a);
|
||||||
|
call->setArg(1, b);
|
||||||
|
call->setRet(0, a);
|
||||||
|
|
||||||
|
c.ret(a);
|
||||||
|
c.endFunc();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
X86GpVar a = c.newInt32("a");
|
||||||
|
X86GpVar b = c.newInt32("b");
|
||||||
|
|
||||||
|
c.addFunc(f2);
|
||||||
|
c.setArg(0, a);
|
||||||
|
c.setArg(1, b);
|
||||||
|
|
||||||
|
c.add(a, b);
|
||||||
|
c.ret(a);
|
||||||
|
c.endFunc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool run(void* _func, StringBuilder& result, StringBuilder& expect) {
|
||||||
|
typedef int (*Func)(int, int);
|
||||||
|
|
||||||
|
Func func = asmjit_cast<Func>(_func);
|
||||||
|
|
||||||
|
int resultRet = func(56, 22);
|
||||||
|
int expectRet = 56 + 22;
|
||||||
|
|
||||||
|
result.setFormat("ret=%d", resultRet);
|
||||||
|
expect.setFormat("ret=%d", expectRet);
|
||||||
|
|
||||||
|
return result.eq(expect);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// [X86Test_MiscUnfollow]
|
// [X86Test_MiscUnfollow]
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -2959,8 +3020,9 @@ X86TestSuite::X86TestSuite() :
|
|||||||
|
|
||||||
// Misc.
|
// Misc.
|
||||||
ADD_TEST(X86Test_MiscConstPool);
|
ADD_TEST(X86Test_MiscConstPool);
|
||||||
ADD_TEST(X86Test_MiscUnfollow);
|
|
||||||
ADD_TEST(X86Test_MiscMultiRet);
|
ADD_TEST(X86Test_MiscMultiRet);
|
||||||
|
ADD_TEST(X86Test_MiscMultiFunc);
|
||||||
|
ADD_TEST(X86Test_MiscUnfollow);
|
||||||
}
|
}
|
||||||
|
|
||||||
X86TestSuite::~X86TestSuite() {
|
X86TestSuite::~X86TestSuite() {
|
||||||
|
|||||||
Reference in New Issue
Block a user