Giter VIP home page Giter VIP logo

abc's Introduction

A B Compiler

ABC is a compiler for the B Programming Language that targets x86_32 processors. It is currently tested under Linux but should work on (or at least be easily ported to) other UNIX-like systems. The code is based on an early C compiler (last1120c) by Dennis Ritchie.

Documentation

  • The Programming Language B
  • B Reference by Ken Thompson describes a presumably earlier variant of B, which is slightly different from the one described above. ABC cannot understand it, but a compatibility mode is possible (the differences are minor).
  • Examples of B programs are in the examples directory. They are mostly from Brian Kernighan’s tutorial.

Implementation

Since B was first implemented for machines with word addressing, some hacking was required to make it work on the byte-addressed x86. Addresses filled in by the linker are always byte addresses, so pointers to these addresses are collectively stored at the end of the .data section and are then converted to word addresses at runtime, before main is called.

ABC generates very inefficient object code; not even constant expressions are reduced at compile time. Also I/O is currently not buffered.

How To Use

abc is a frontend for the actual compiler, which feels somewhat like GCC (it also handles assembling and linking).

The installation requires a little configuration.

Before you can use ABC, adjust the INSTALL_DIR variable in the Makefile to point to a place to install ABC. It should not be the same place as your checkout of this Git repository. By default, INSTALL_DIR is $HOME/abc.

Then type

make install

which compiles the compiler b, installs the abc frontend, and compiles the B runtime support files.

Now, include your shiny new B compiler in your $PATH:

export PATH="$PATH:$HOME/abc/bin"

(Adjust that command to reflect your actual $(INSTALL_DIR)/bin.)

To compile and link a B program, simply type

abc -o outfile file1.b [file2.b ...]

(If you don’t provide a -o option, the output file will be named a.out.)

If you want to compile and assemble only, but not link:

abc -c file1.b [file2.b ...]

To generate only the assembly code:

abc -S file1.b [file2.b ...]

Bugs

Since command line parameters aren’t passed word-aligned, B can’t handle them easily. brt.s copies the strings to another location and aligns them. The space is not dynamically allocated, however, and only 256 bytes are available by default to store them.

The library is incomplete but has some of the most important functions.

abc is only known to work on x64_64 Linux systems.

abc's People

Contributors

aap avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.