On Sat, 2006-11-04 at 21:06 -0800, Reid Spencer wrote:> Hi Napi, > > On Sun, 2006-11-05 at 12:40 +0800, Mohd-Hanafiah Abdullah wrote: > > Hi: > > > > I'm interested in using llvm to convert C++ code to C code. > > I used the following command to do this: > > > > % llvm-g++ -c foo.cpp -o - | llc -march=c -o foo.cbe.c > > Yup, that'll do it. Although you might want to do a little optimization > otherwise you're going to get a lot of C code on output. Try passing -O2 > to llvm-g++. > > > In the resulting file foo.cbe.c there are many occurences of '0x0p+0'. > > What is it used for? Here's a code snippet from the file foo.cbe.c > > > > if ((ltmp_126_2 > 0x0p+0)) { > > goto ltmp_363_19; > > } else { > > goto ltmp_364_19; > > } > > > > llvm-gcc is able to compile foo.cbe.c, but I need to use another C > > compiler which gives a syntax error message for not recognizing > > the expression '0x0p+0'. > > Get a new C compiler :) > > The syntax in question is a C99 feature. It is printed by the C Backend > with the %a conversion token for printf. This is the representation of a > floating point number in hexadecimal. It allows certain values that > cannot otherwise be represented with a decimal number to be represented. > The C Backend needs to use this to ensure that the floating point value > it has in mind is *exactly* represented through the conversion to the C > source and then back by your C compiler.Hi Reid: Thank you for your email. I need to use this C compiler that only supports ANSI C 1989. What is the equivalent of '0x0p+0' in C89 ? Is there any way around this? Thanks. Napi
On Nov 5, 2006, at 2:30 AM, Mohd-Hanafiah Abdullah wrote:> On Sat, 2006-11-04 at 21:06 -0800, Reid Spencer wrote: >>> In the resulting file foo.cbe.c there are many occurences of '0x0p >>> +0'. >>> What is it used for? Here's a code snippet from the file foo.cbe.c >>> >>> if ((ltmp_126_2 > 0x0p+0)) { >>> goto ltmp_363_19; >>> } else { >>> goto ltmp_364_19; >>> } >>> >>> llvm-gcc is able to compile foo.cbe.c, but I need to use another C >>> compiler which gives a syntax error message for not recognizing >>> the expression '0x0p+0'. >> >> Get a new C compiler :) >> >> The syntax in question is a C99 feature. It is printed by the C >> Backend >> with the %a conversion token for printf. This is the >> representation of a >> floating point number in hexadecimal. It allows certain values that >> cannot otherwise be represented with a decimal number to be >> represented. >> The C Backend needs to use this to ensure that the floating point >> value >> it has in mind is *exactly* represented through the conversion to >> the C >> source and then back by your C compiler. > > Hi Reid: > > Thank you for your email. I need to use this C compiler that only > supports ANSI C 1989. What is the equivalent of '0x0p+0' in C89 ? > Is there any way around this? >$ cat t.cpp #include <iostream> int main(int argc, char** argv) { std::cout << "0x0p+0 == " << 0x0p+0 << "\n"; } $ ./t 0x0p+0 == 0 I supposed you could always hack the CBE to have it produce traditional floating point numbers (like 0.0 or whatever) using "%f" instead of "%a". However, you might have problems with precision during comparisons. I.e., if you have something like "if (a == 37.927)", it may not work. -bw
On Sun, 2006-11-05 at 13:48 -0800, Bill Wendling wrote:> I supposed you could always hack the CBE to have it produce > traditional floating point numbers (like 0.0 or whatever) using "%f" > instead of "%a". However, you might have problems with precision > during comparisons. I.e., if you have something like "if (a == > 37.927)", it may not work.The "hack" has already been implemented. As I mentioned in my last email, all you need to do is configure LLVM with --disable-cbe-printf-a and it will avoid using the %a conversion token and instead use ftostr. Reid.
After converting a piece of C++ code to C one of the functions that are generated is this: _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc Where is it defined and where can I find the source for it? I need the source to compile it with a C compiler (AMPC) that will convert the C code to Java Bytecode. If the above function is in C++ then I need to convert it to C first. Here's the code segment that uses the function: int main(void) { struct l_struct_2E_std_3A__3A_basic_ostream_3C_char_2C_std_3A__3A_char_traits_ 3C_char_3E__20__3E_ *ltmp_2_2; CODE_FOR_MAIN(); /*tail*/ __main(); ltmp_2_2 = /*tail*/ _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(( &_ZSt4cout), (&(_2E_str_1[0]))); return 0; } Thanks for any tips. 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 On Mon, 2006-11-20 at 10:21 +1100, Emil Mikulic wrote:> On Sat, Nov 18, 2006 at 03:55:14PM +0800, Mohd-Hanafiah Abdullah wrote: > > Hi Emil: > > > > How did you modify the Makefile to make it compile libstdc++ into LLVM > > bytecode? Have you had any luck so far? > > I haven't managed to get this to work yet. > > I tried manually compiling pieces of the libsup/ and src/ directories > but I've still got unresolved symbols left over.