void X86TestSuite::run() { size_t i; size_t testCount = testList.getLength(); for (i = 0; i < testCount; i++) { X86Compiler compiler; StringLogger logger; logger.setLogBinary(true); compiler.setLogger(&logger); X86Test* test = testList[i]; test->compile(compiler); void *func = compiler.make(); // In case that compilation fails uncomment this section to log immediately // after "compiler.make()". // // fprintf(stdout, "%s\n", logger.getString()); // fflush(stdout); if (func != NULL) { StringBuilder output; StringBuilder expected; if (test->run(func, output, expected)) { fprintf(stdout, "[Success] %s.\n", test->getName()); } else { fprintf(stdout, "[Failure] %s.\n", test->getName()); fprintf(stdout, "-------------------------------------------------------------------------------\n"); fprintf(stdout, "%s", logger.getString()); fprintf(stdout, "\n"); fprintf(stdout, "Result : %s\n", output.getData()); fprintf(stdout, "Expected: %s\n", expected.getData()); fprintf(stdout, "-------------------------------------------------------------------------------\n"); } MemoryManager::getGlobal()->free(func); } else { fprintf(stdout, "[Failure] %s.\n", test->getName()); fprintf(stdout, "-------------------------------------------------------------------------------\n"); fprintf(stdout, "%s\n", logger.getString()); fprintf(stdout, "-------------------------------------------------------------------------------\n"); } fflush(stdout); } fputs("\n", stdout); fputs(testOutput.getData(), stdout); fflush(stdout); }
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; }