本文整理汇总了C++中X86Compiler::newFunc方法的典型用法代码示例。如果您正苦于以下问题:C++ X86Compiler::newFunc方法的具体用法?C++ X86Compiler::newFunc怎么用?C++ X86Compiler::newFunc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类X86Compiler
的用法示例。
在下文中一共展示了X86Compiler::newFunc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compile
virtual void compile(X86Compiler& c)
{
c.newFunc(kX86FuncConvDefault, FuncBuilder3<Void, uint32_t*, const uint32_t*, size_t>());
c.getFunc()->setHint(kFuncHintNaked, true); // Omit unnecessary prolog/epilog.
Label L_Loop = c.newLabel(); // Create base labels we use
Label L_Exit = c.newLabel(); // in our function.
GpVar dst(c.getGpArg(0)); // Get reference to function
GpVar src(c.getGpArg(1)); // arguments.
GpVar cnt(c.getGpArg(2));
c.alloc(dst); // Allocate all registers now,
c.alloc(src); // because we want to keep them
c.alloc(cnt); // in physical registers only.
c.test(cnt, cnt); // Exit if length is zero.
c.jz(L_Exit);
c.bind(L_Loop); // Bind the loop label here.
GpVar tmp(c.newGpVar(kX86VarTypeGpd)); // Copy a single dword (4 bytes).
c.mov(tmp, dword_ptr(src));
c.mov(dword_ptr(dst), tmp);
c.add(src, 4); // Increment dst/src pointers.
c.add(dst, 4);
c.dec(cnt); // Loop until cnt isn't zero.
c.jnz(L_Loop);
c.bind(L_Exit); // Bind the exit label here.
c.endFunc(); // End of function.
}
示例2: main
int main(int argc, char* argv[])
{
using namespace AsmJit;
// ==========================================================================
// Log compiler output.
FileLogger logger(stderr);
logger.setLogBinary(true);
// Create compiler.
/*
X86Compiler c;
c.setLogger(&logger);
c.newFunc(kX86FuncConvDefault, FuncBuilder0<Void>());
c.getFunc()->setHint(kFuncHintNaked, true);
X86CompilerFuncCall* ctx = c.call((void*)dummyFunc);
ctx->setPrototype(kX86FuncConvDefault, FuncBuilder0<Void>());
c.endFunc();
*/
X86Compiler c;
c.setLogger(&logger);
c.newFunc(kX86FuncConvDefault, FuncBuilder0<void>());
c.getFunc()->setHint(kFuncHintNaked, true);
Label l91 = c.newLabel();
Label l92 = c.newLabel();
Label l93 = c.newLabel();
Label l94 = c.newLabel();
Label l95 = c.newLabel();
Label l96 = c.newLabel();
Label l97 = c.newLabel();
c.bind(l92);
GpVar _var91(c.newGpVar());
GpVar _var92(c.newGpVar());
c.bind(l93);
c.jmp(l91);
c.bind(l95);
c.mov(_var91, imm(0));
c.bind(l96);
c.jmp(l93);
c.mov(_var92, imm(1));
c.jmp(l91);
c.bind(l94);
c.jmp(l92);
c.bind(l97);
c.add(_var91, _var92);
c.bind(l91);
c.ret();
c.endFunc();
typedef void (*Func9)(void);
Func9 func9 = asmjit_cast<Func9>(c.make());
// ==========================================================================
// ==========================================================================
// Make the function.
// MyFn fn = asmjit_cast<MyFn>(c.make());
// Call it.
// printf("Result %llu\n", (unsigned long long)fn());
// Free the generated function if it's not needed anymore.
//MemoryManager::getGlobal()->free((void*)fn);
// ==========================================================================
return 0;
}