{"id":20090473,"url":"https://github.com/qookei/tbfc","last_synced_at":"2026-04-17T03:34:46.675Z","repository":{"id":110463263,"uuid":"219330446","full_name":"qookei/tbfc","owner":"qookei","description":"Tiny brainfuck compiler","archived":false,"fork":false,"pushed_at":"2019-11-03T17:47:08.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-13T02:46:01.601Z","etag":null,"topics":["assembly","brainfuck","brainfuck-compiler","cpp17"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qookei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-03T16:28:08.000Z","updated_at":"2019-11-03T17:49:43.000Z","dependencies_parsed_at":"2023-12-24T06:15:26.399Z","dependency_job_id":null,"html_url":"https://github.com/qookei/tbfc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qookei%2Ftbfc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qookei%2Ftbfc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qookei%2Ftbfc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qookei%2Ftbfc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qookei","download_url":"https://codeload.github.com/qookei/tbfc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241526025,"owners_count":19976833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assembly","brainfuck","brainfuck-compiler","cpp17"],"created_at":"2024-11-13T16:24:37.459Z","updated_at":"2026-04-17T03:34:41.630Z","avatar_url":"https://github.com/qookei.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tbfc\ntbfc is a tiny (about 270 lines) brainfuck compiler which generates 32-bit assembly.\n\nThe compiler performs some optimizations, namely it reduces increments and decrements (both of the tape pointer and of the tape cell) into a single operation.\n\nThe generated code is ready to be compiled with `nasm`, linked with `ld` and ran on (probably) any x86 Linux system.\nMaking the compiler target different operating systems is as simple as changing the generated prologue and epilogue.\n\n## Building\n\nTo compile, you need a C++17 compiler, and make.\n\nTo compile with G++, simply do:\n```\n$ make\n```\n\nIf you wish to compile with a different compiler, just set the CXX environment variable, like so:\n```\n$ CXX=clang++ make # replace clang++ with your compiler of choice\n```\n\n## Usage\nUsing tbfc is simple, it prints nothing to stdout, and the generated code to stderr, so to save the code to a file do the following:\n```\n$ tbfc input 2\u003eoutput\n```\n\nThen, to compile the code, `nasm` is recommended (the code is generated with it in mind). To do so, do the following:\n```\n$ nasm -felf32 \u003cinput\u003e.asm \u003coutput\u003e.o\n```\n\nAfter that, you need to link the code into the final executable, like so:\n```\n$ ld -melf_i386 \u003cinput\u003e.o -o \u003coutput\u003e -nostdlib\n```\n\nAfter all that is done, you should have a working binary.\n\n## Compliance\nThe generated code uses a 30000 cell tape, where each cell is 8-bit. On overflow/underflow of the tape pointer, it wraps around to the end/beginning of the tape. On overflow/underflow of the value in the cell, the value also wraps around.\n\nThe compiler appears to compile most (everything I tested) programs fine, including [The Lost Kindgom](https://jonripley.com/i-fiction/games/LostKingdomBF.html).\n\nIncluded are some examples and a makefile to compile and link them.\n\n## Speed\nGenerating the assembly is rather fast (doing so for The Lost Kingdom took about 2 seconds on my machine).\n\nThe generated code is also pretty fast.\n\nFurther improvements could be made by better optimizing the IR and generated assembly (eliminating loops, replacing tape pointer movement with static offsets, etc.), but that will be done at a later time, if at all.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqookei%2Ftbfc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqookei%2Ftbfc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqookei%2Ftbfc/lists"}