ELVM

From Esolang
Jump to navigation Jump to search

ELVM is a compiler infrastructure (similar to LLVM) for esotoric (and some non-esotoric) languages. It can be used to compile C to many esotoric and other languages. A online demonstration can be found here.

ELVM is similar to LLVM but dedicated to Esoteric Languages. This project consists of two components - frontend and backend. Currently, the only frontend we have is a modified version of 8cc. The modified 8cc translates C code to an internal representation format called ELVM IR (EIR). Unlike LLVM bitcode, EIR is designed to be extremely simple, so there's more chance we can write a translator from EIR to an esoteric language.

Some backends include:

Contributions, such as adding features (e.g. bit operations), adding backends, and others, would be welcome!

Internals

  • Harvard architecture, not Neumann (allowing self-modifying code is hard)
  • 6 registers: A, B, C, D, SP, and BP
  • Ops: mov, add, sub, load, store, setcc, jcc, putc, getc, and exit
  • Psuedo ops: .text, .data, .long, and .string
  • mul/div/mod are implemented by _builtin*
  • No bit operations
  • No floating point arithmetic
  • sizeof(char) == sizeof(int) == sizeof(void*) == 1
  • The word-size is backend dependent, but most backend uses 24bit words
  • A single programming counter may contain multiple operations