From 6578cc4fb17647b8e5c72bf55de0ca059d834eec Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Fri, 15 Sep 2023 11:12:06 +0900 Subject: [PATCH] not run --- sample/bf.cpp | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 sample/bf.cpp diff --git a/sample/bf.cpp b/sample/bf.cpp new file mode 100644 index 0000000..691a01e --- /dev/null +++ b/sample/bf.cpp @@ -0,0 +1,121 @@ +#include +#include +#include +#include +#include + +class Brainfuck : public Xbyak_riscv::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_riscv; + const auto &pPutchar = s2; + const auto &pGetchar = s3; + const auto &stack = s4; + const int saveSize = 16*3; + addi(sp, sp, -saveSize); + sd(pPutchar, sp, 16); + sd(pGetchar, sp, 24); + sd(stack, sp, 32); + + mv(pPutchar, a0); + mv(pGetchar, a1); + mv(stack, a2); + + std::stack