#include "xbyak/xbyak.h" #include #include #include #include #ifdef _MSC_VER #pragma warning(disable : 4996) // scanf #define snprintf _snprintf_s #endif class Brainfuck : public Xbyak::CodeGenerator { public: int getContinuousChar(std::istream& is, char c) { int count = 1; char p; while (is >> p) { if (p != c) break; count++; } is.unget(); return count; } Brainfuck(std::istream& is) : CodeGenerator(100000) { // void (*)(void* putchar, void* getchar, int *stack) using namespace Xbyak; #ifdef XBYAK32 const Reg32& pPutchar(esi); const Reg32& pGetchar(edi); const Reg32& stack(ebp); const Address cur = byte [stack]; push(ebp); // stack push(esi); push(edi); const int P_ = 4 * 3; mov(pPutchar, ptr[esp + P_ + 4]); // putchar mov(pGetchar, ptr[esp + P_ + 8]); // getchar mov(stack, ptr[esp + P_ + 12]); // stack #elif defined(XBYAK64_WIN) const Reg64& pPutchar(rsi); const Reg64& pGetchar(rdi); const Reg64& stack(rbp); // stack const Address cur = byte [stack]; push(rsi); push(rdi); push(rbp); mov(pPutchar, rcx); // putchar mov(pGetchar, rdx); // getchar mov(stack, r8); // stack #else const Reg64& pPutchar(rbx); const Reg64& pGetchar(rbp); const Reg64& stack(r12); // stack const Address cur = byte [stack]; push(rbx); push(rbp); push(r12); mov(pPutchar, rdi); // putchar mov(pGetchar, rsi); // getchar mov(stack, rdx); // stack #endif std::stack