diff options
author | MITSUNARI Shigeo <[email protected]> | 2024-09-29 19:44:49 +0900 |
---|---|---|
committer | MITSUNARI Shigeo <[email protected]> | 2024-09-29 19:44:49 +0900 |
commit | a9ec16fa3b5e9a1917c7ea8f65b4d6ab7d16e00a (patch) | |
tree | f6c93ed4b196438debce4f58a967be54cd8e16ad /sample | |
parent | ccdf68421bc8eb85693f573080fc0a5faad862db (diff) | |
download | xbyak-a9ec16fa3b5e9a1917c7ea8f65b4d6ab7d16e00a.tar.gz xbyak-a9ec16fa3b5e9a1917c7ea8f65b4d6ab7d16e00a.zip |
[sample] add dump option to bf
Diffstat (limited to 'sample')
-rw-r--r-- | sample/bf.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/sample/bf.cpp b/sample/bf.cpp index 657c87c..a7cb8c4 100644 --- a/sample/bf.cpp +++ b/sample/bf.cpp @@ -189,18 +189,30 @@ int main(int argc, char *argv[]) fprintf(stderr, "64bit mode\n"); #endif if (argc == 1) { - fprintf(stderr, "bf filename.bf [0|1]\n"); + fprintf(stderr, "bf filename.bf [0|1|2]\n"); return 1; } std::ifstream ifs(argv[1]); int mode = argc == 3 ? atoi(argv[2]) : 0; try { Brainfuck bf(ifs); - if (mode == 0) { + switch (mode) { + case 0: { static int stack[128 * 1024]; bf.getCode<void (*)(const void*, const void*, int *)>()(reinterpret_cast<const void*>(putchar), reinterpret_cast<const void*>(getchar), stack); - } else { + break; + } + case 1: { dump(bf.getCode(), bf.getSize()); + break; + } + default: { + const char *dumpName = "bf.dump"; + printf("dump to %s\n", dumpName); + std::ofstream ofs(dumpName, std::ios::binary); + ofs.write((const char*)bf.getCode(), bf.getSize()); + break; + } } } catch (std::exception& e) { printf("ERR:%s\n", e.what()); |