I just posted about my toying around with llvm bindings for felix on
felix-lang.org:

http://felix-lang.org/blog/2008/mar/22/llvm-bindings/

But since many of you aren't actually subscribed to the google groups
list, I've cc'ed it here:


For a long time I've wanted to write a [llvm](http://www.llvm.org)
backend for felix, however, it seems to be a bit easier to bind the
llvm libraries to felix. So here's my first attempt. It's pretty
trivial:

`llvm.flx:`
{{{
namespace llvm {
 requires package "llvm";

 requires header "#include <llvm/Value.h>";
 requires header "#include <llvm/Type.h>";
 requires header "#include <llvm/DerivedTypes.h>";

 open C_hack;

 typeclass Value[t] {
   virtual proc dump: cptr[t] = "$1->dump();";
 }

 typeclass Type[t] {
   inherit Value[t];

   fun is_integer: t -> bool = "$1->isInteger()";
 }

 type type_ = "::llvm::Type";
 instance Type[type_] {}

 typeclass IntegerType[t] {
   inherit Type[t];

   fun get_bit_width: cptr[t] -> int = "$1->getBitWidth()";
 }

 type integer_type = "::llvm::IntegerType";
 instance IntegerType[integer_type] {}

 fun int8_type  : unit -> cptr[integer_type] = "::llvm::Type::Int8Ty";
 fun int16_type : unit -> cptr[integer_type] = "::llvm::Type::Int16Ty";
 fun int32_type : unit -> cptr[integer_type] = "::llvm::Type::Int32Ty";
 fun int64_type : unit -> cptr[integer_type] = "::llvm::Type::Int64Ty";

 fun float_type : unit -> cptr[type_] = "::llvm::Type::FloatTy";
}
}}}

`llvm.fpc:`
{{{
cflags: -I/tmp/llvm/include  -D_DEBUG  -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
provides_dlib: -L/tmp/llvm/lib  -lpthread -lm -lLLVMCore -lLLVMSupport
-lLLVMSystem
}}}

`foo.flx:`
{{{
include "llvm";
open llvm;

Value::dump $ int8_type ();
println $ Type::is_integer $ int8_type ();
println $ IntegerType::get_bit_width $ int8_type ();

Value::dump $ float_type ();
println $ Type::is_integer $ float_type ();
}}}

Which, when run, results in:

{{{
flx foo.flx
Other exn = Flx_exceptions.Free_fixpoint(_)
i8
true
8
float
false
}}}

Of course there seems to be a couple typeclass bugs we're running
into, as if we have this call:

{{{
println $ IntegerType::get_bit_width $ float_type ()
}}}

We manage to get through felix and error out in c++:

{{{
foo.cpp: In function 'void flxusr::foo::_init_(flxusr::foo::thread_frame_t*)':
foo.cpp:82: error: 'const class llvm::Type' has no member named 'getBitWidth'
compilation terminated due to -Wfatal-errors.
}}}

So we've got some work to do. :)

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to