LLVM generation for the Entity language compiler

vincent_belliard <vincent@famillebelliard.fr>
Fri, 30 Mar 2012 08:13:24 -0700 (PDT)

          From comp.compilers

Related articles
LLVM generation for the Entity language compiler vincent@famillebelliard.fr (vincent_belliard) (2012-03-30)
| List of all articles for this month |

From: vincent_belliard <vincent@famillebelliard.fr>
Newsgroups: comp.compilers
Date: Fri, 30 Mar 2012 08:13:24 -0700 (PDT)
Organization: Compilers Central
Keywords: available
Posted-Date: 31 Mar 2012 03:54:47 EDT

A new computer language has a compiler which generate LLVM. It's the Entity
language (http://code.google.com/p/entity-language/). It was a real pleasure
to do the LLVM generation. LLVM is very consistent and, when you had
understood all the concepts, very easy to use. It took me four months to do
the LLVM generation (I just work during my spare time). During these four
months, the only verification I was able to do was compiling the generated
LLVM IR with the LLVM compiler. LLVM is so rigorous that it complained each
time the generated code wasn't perfect. After four months I was finally able
to test the result and it worked immediately.


To generate LLVM I did two things. First I made classes to handle LLVM
instructions. It works well and it's easy to generate LLVM from the internal
Entity classes. Second, I tried to use this module to write system subroutines
directly in LLVM (I didn't want to write theses subroutines in C to avoid an
external library use). It was very tedious to program like that. To solve the
problem I made a very small language absolutely closed to LLVM but with a C
like syntax. It works very well and here is an example of the language.


i1 @equals_string_contents(%_self: %string_content*, %_cmp: %string_content*)
{
var size_ref: i64 = %_self->size ;
var size_cmp: i64 = %_cmp->size ;
if (size_ref ne size_cmp) return 0 ;
var count: i64 = size_ref >> 3 ;
var ref: i64* = <i64*>%_self->data ;
var cmp: i64* = <i64*>%_cmp->data ;
loop
{
phi phi_count: i64 = count | next_count ;
phi phi_ref: i64* = ref | next_ref ;
phi phi_cmp: i64* = cmp | next_cmp ;
if (phi_count eq 0) return 1 ;
if (*phi_ref ne *phi_cmp) return 0 ;
var next_count: i64 = phi_count - 1 ;
var next_ref: i64* = phi_ref + 1 ;
var next_cmp: i64* = phi_cmp + 1 ;
}
}


It uses the same SSA method as LLVM and the final LLVM IR is generated without
ambiguity. Now only the instructions I needed are available but I will finish
this language and make a stand alone library. Every one would be able to use
it for making a compiler (of course this library is written in Entity).


About Entity: Entity is a generalist OO language base on C++ and Java. I tried
to make something more powerful, easier to use, even easier to read and robust
(no way to have buffers overflow or things like that). To know more about
Entity go to http://code.google.com/p/entity-language/.


PS: in Entity all the strings are aligned on 8 bytes boundary and padded with
0 so we can do strings comparison on 64 bits instead of 8 bits.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.