Convert C++ to C. What is 0x0p+0 ?

In llvm-gcc3 where could I find the bytecode version of libstdc++ ?

Thanks.

Napi

Emil:

Do you know where I could get libstdc++ that has been pre-compiled to
LLVM bytecode? I know you have been trying to get it compiled, but if
there's an older version of it that's available that will be useful to
me already. With it I can use llc to get the C version and then compile
it using AMPC.

Thanks.

Napi

Mohd-Hanafiah Abdullah wrote:

  

I don't think you will need to deal with any names. The C++ standard
library has already been compiled to LLVM bytecode (it is part of the
llvm-gcc/llvm-g++ distribution). If you use "llvm-g++ -lstdc++" it
should link in whatever libstdc++ functions are needed by your program;
they will get translated to C code along with the rest of your program
when you use llc.
      

Note that that only works with llvm-gcc3. With llvm-gcc4 you need to
compile libstdc++ to bytecode explicitly.
    
In llvm-gcc3 where could I find the bytecode version of libstdc++ ?
  

You can download llvm-gcc3 from here (look for the LLVM-GCC 3.4 frontend
for your platform):
http://llvm.org/releases/download.html#1.9

The pre-compiled libstdc++ should be in <platform>/llvm-gcc/lib/libstdc++.a.

Two caveats:

1) I don't know if using this bytecode version of libstdc++ will work
with llvm-gcc4. If you want to use it, you may need to use llvm-gcc3.

2. llvm-gcc3 is missing features from llvm-gcc4. Furthermore, support
for llvm-gcc3 will probably be dropped in the LLVM 2.0 release.

-- John T.

How does the C back-end of LLVM differ from the one in gcc2c developed
by SUN several years ago?

Thanks.

Napi

Hi Napi,

For one, it converts LLVM's bytecode to C instead of GCC's RTL. It's
also under a different license.

As far as code quality, I don't believe it's been compared.

-bw

Hi Bill:

Would it be easier to convert from LLVM's bytecode to C as opposed to
from RTL? What about the readability of the produced C code. I would
think since RTL maintains a structure that is directly inherited from
the high-level language structure it would be less difficult to turn it
into some C code that is relatively more readable, as compared to
synthesizing C code from the low-level bytecode. I stand corrected.

Thanks.

Napi

Hi Napi,

Considering that LLVM already has a C backend, then it's easier to generate it from the LLVM bytecode. :slight_smile: LLVM's intermediate representation of the program (the bytecode) is also derived directly from the high-level language. When it gets to the C backend part, it simply has had transformations done on it.

I don't believe that the C backend was made for readability. In fact, because LLVM is in SSA form, it uses many temporary variables and loses a lot of the information about what the original variable's name was.

The best way to get a feel for how it is is to write a program and generate the C code for it with the LLVM backend. (See the llc tool for information on this.)

Though, this begs the question of why you want to use something which converts it to C instead of just using one of the target backends to generate native code.

-bw

Hi Bill:

I've been looking for a C++ to C translator for quite some time.
The purpose is to support C++ for the compiler I developed targeting the
JVM. But the compiler I wrote only supports ANSI C (1989). So the C++
to C translator is needed, and among the options are as follows:

a) EDG (rather expensive, around USD 100K with source code)
b) Comeau (around USD 25K for customization service and you don't get
   the source code)
c) LLVM (tried, but the resulting C code is quite hairy, pardon the
   expression)
d) gcc2c (trying now, don't know how useful yet)

For more info on the said C to JVM compiler you can check out our
website: http://www.axiomsol.com

Cheers.

Napi

So you just want to feed the C code to your C-to-JVM compiler? I don't
understand why "hairy" code would be a problem for that usage.

As a different option, how about writing a JVM backend for LLVM?

This is definitely an option too. Another one would be to write a JVM
backend for gcc. But, I think somebody tried many years ago and stopped
halfway (it's egcs-jvm I think). Does LLVM use RTL as intermediate
language like gcc does?

Thanks.

Napi

I'm not exactly sure how llvm-g++ works. I think it goes through the
standard gcc sequence (gimple, rtl, and such) but then outputs LLVM
(http://llvm.org/docs/LangRef.html), which is the intermediate
representation used by the rest of the chain. To make an LLVM backend
you would not need to deal with RTL and such at all.

There's a name change in progress to make it clearer that what's now
called LLVM is much more than just the LLVM language :slight_smile:

~ Scott

llvm-g++ converts from trees to high-gimple to LLVM. RTL is not involved.

LLVM also does have an MSIL backend, if you are interested in a JVM backend, it may be a starting point.

-Chris

Need to know if anyone has compiled the libstdc++ to LLVM bitcode. If
it's available please where could I download it from?

Thanks.

Napi

I did this last year.

Check out:
http://goanna.cs.rmit.edu.au/~emil/dietstdcxx.1.tar.bz2

--Emil

Hi Emil:

Thanks for the fast reply.

Cheers.

Napi

I've read and followed the README.LLVM file that comes with LLVM-GCC 4.0
Front End source, but got the following error when compiling:

configure: error: You must specify valid path to your LLVM tree with
--enable-llvm=DIR
make: *** [configure-gcc] Error 1

I've done the following in csh before hand:
$ setenv LLVMOBJDIR /home/napi/proj/c2jvm/llvm/llvm-gcc/obj

Where did I go wrong?

Thanks.

Napi

Hi Napi,

I always just specify it with the "--enable-llvm" command instead of
an environment variable. The doc might be wrong in this instance...

-bw

In the directory obj, I did:

% ../llvm-gcc4.0-2.1.source/configure --prefix=`pwd`/../install
--program-prefix=llvm-
--enable-llvm= /home/napi/proj/c2jvm/llvm/llvm-gcc/obj
--enable-languages=c,c++

But, still got the same problem.

Thanks.

Napi

I didn't realize that you were pointing to "llvm-gcc" :-). Let's say
that you have your trees set up like so:

~/llvm-gcc
~/llvm

and the object directories are:

~/llvm-gcc.obj
~/llvm.obj

then you'd use:

--enable-llvm=~/llvm.obj

or set the environment variable to that.

-bw

I've read and followed the README.LLVM file that comes with LLVM-GCC 4.0
Front End source, but got the following error when compiling:

configure: error: You must specify valid path to your LLVM tree with
--enable-llvm=DIR
make: *** [configure-gcc] Error 1

I've done the following in csh before hand:
$ setenv LLVMOBJDIR /home/napi/proj/c2jvm/llvm/llvm-gcc/obj

Where did I go wrong?

LLVMOBJDIR needs to be the LLVM tree, not llvm-gcc.

-Tanya