📄 readme
字号:
ebfc is a compiler for a tiny programming language called Brainfuck.(If the name of the language offends you, then you might as well stopreading now and just delete this entire subdirectory.) This languagewas created by Urban Mueller, apparently solely for the purpose ofbeing able to create a compiler for the Amiga under 256 bytes in size.(My own efforts along these lines can be found in the tiny/subdirectory, by the way.) I chose to write a compiler for thislanguage so as to keep the details of the language translation to aminimum, and focus on the process of building an ELF file completelyfrom scratch.ebfc can compile Brainfuck programs into executables, sharedlibraries, and/or object files. Refer to the manpage for a descriptionof the command-line options and of the Brainfuck language itself.Most of the code that deals with creating the ELF file is built into aseparate library, called elfparts. This library is too primitive to bea real general-purpose library (though it might serve as a startingpoint for such a thing). The main justification for the separation isto clearly distinguish the compilation activities from the moregeneral housekeeping involved in building a functional ELF file.The file elfparts.txt contains a description of the library interface.Most of the compiler's work is very straightforward. The Brainfuckcommands all translate directly to a few bytes of machine language.The real work is mainly in creating the prolog code, which hasdifferent requirements depending on the type of file being generated.There are two "objects", the program and the 30000-byte array.Compiling to an executable merely requires that the address of thedata segment be properly inserted into the prolog code, and theaddress of the text segment is placed in the ELF header's e_entryfield. Compiling to an object file instead requires that theseaddresses are added to a relocation table, with the function beingglobal and the array being local. Finally, compiling to a sharedlibrary requires that the function be added to the symbol table, andthe array's address be indirectly computed via the global offsettable. And, of course, the actual code to use for the prolog dependson how the function is being invoked (i.e., from the OS, anotherprogram, or another part of the same program).The ebfc/bf/ subdirectory contains a few Brainfuck programs, which canbe used to test the compiler. prime.b was written by Urban Mueller;the others were written by myself.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -