LLVM and GMP

Hello

I've been looking to LLVM, in order to develop a compiler for a cryptography oriented language. I started by following the tutorials on Kaleidoscope, and I must say they were very usefull. Now I need to use GMP, so i can add Big Integer support. I am trying to change Kaleidoscope to support BigIntegers instead of doubles, but I don't really know how to do that. I'd really appreciate some help in this.

Thanks in advance
Paulo Matias

I could be wrong, but I think that you may need to add a 'big-integer'
intrinsic type to llvm.

No, please don't. GMP is just another library like libc, your front-end should just generate calls into it like any other library. This is similar to how we handle threading and many other "language features".

-Chris

Oh. I see. That way the bigints don't need a representation in llvm IR... neat.

Sorry for the misdirecton!

Oh. One more thing:

Paulo, while your working out how to do what Chris said (making usage
of bigints into library calls), wouldn't it just warm your heart to
document the process on the wiki?

</wiki pimping>

Hi Paulo,

Paulo Matias wrote:

I've been looking to LLVM, in order to develop a compiler for a
cryptography oriented language. I started by following the tutorials on
Kaleidoscope, and I must say they were very usefull. Now I need to use
GMP, so i can add Big Integer support. I am trying to change
Kaleidoscope to support BigIntegers instead of doubles, but I don't
really know how to do that. I'd really appreciate some help in this.

If you don't mind using an existing LLVM-based language, "Pure" has GMP
bigints built into it, and rational numbers (and complex rationals) as
well. And you have a full-featured language to boot, which can also do
symbolic algebraic manipulations (it's based on term rewriting).

Being dynamically typed, Pure isn't quite as fast as compiled Haskell or
ML, but it does LLVM JIT compilation and in the latest version you can
also create standalone executables. Interfacing to your own C code is as
easy as pie:

using "lib:my_c_stuff.so";
extern char *foo(mpz_t *x);

If nothing else, the Pure interpreter also provides you with a bunch of
C++ code using LLVM which goes well beyond Kaleidoscope. I hear that
people are already using it that way, as well as for testing their LLVM
ports and packages. :wink:

You can find Pure here:
http://pure-lang.googlecode.com/

Cheers,
Albert