Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.iecc.com!nerds-end From: vincent_belliard Newsgroups: comp.compilers Subject: LLVM generation for the Entity language compiler Date: Fri, 30 Mar 2012 08:13:24 -0700 (PDT) Organization: Compilers Central Lines: 51 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <12-03-071@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: leila.iecc.com 1333180487 50319 64.57.183.58 (31 Mar 2012 07:54:47 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Sat, 31 Mar 2012 07:54:47 +0000 (UTC) Keywords: available Posted-Date: 31 Mar 2012 03:54:47 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:538 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* = %_self->data ; var cmp: 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.