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 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'. Thank you for your assistance. Napi
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.cYup, 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.> Thank you for your assistance.Welcome to LLVM. Reid.
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
Hi: I've been able to compile the attached "helloworld.c" file converted from "helloworld.cpp". My question is how does one usually use __main() and CODE_FOR_MAIN() in tying up with the rest of the code? Attached here are the original "helloworld.cpp" and "helloworld.c" files. Thanks. Napi On Sun, 2006-11-05 at 09:14 -0800, Reid Spencer wrote:> Hi Napi, > > On Sun, 2006-11-05 at 18:30 +0800, Mohd-Hanafiah Abdullah wrote: > > > > 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.-------------- next part -------------- A non-text attachment was scrubbed... Name: helloworld.cpp Type: text/x-c++src Size: 95 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20061106/f0e8cce0/attachment.cpp> -------------- next part -------------- A non-text attachment was scrubbed... Name: helloworld.c Type: text/x-csrc Size: 8631 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20061106/f0e8cce0/attachment.c>
Hi Napi, On Mon, 2006-11-06 at 10:44 +0800, Mohd-Hanafiah Abdullah wrote:> Hi: > > I've been able to compile the attached "helloworld.c" file converted > from "helloworld.cpp".Great.> > My question is how does one usually use __main() and CODE_FOR_MAIN() > in tying up with the rest of the code?I'm not quite sure what you're asking. CODE_FOR_MAIN is defined in your helloworld.c file as: #define CODE_FOR_MAIN() /* Any target-specific code for main()*/ #if defined(__GNUC__) && !defined(__llvm__) #if defined(i386) || defined(__i386__) || defined(__i386) || defined(__x86_64__) #undef CODE_FOR_MAIN #define CODE_FOR_MAIN() \ {short F;__asm__ ("fnstcw %0" : "=m" (*&F)); \ F=(F&~0x300)|0x200;__asm__("fldcw %0"::"m"(*&F));} #endif #endif As noted in the comment, this is for target-specific code needed at the start of main. It looks like your target needs a few assembly instructions there. As for the __main function, its a gcc library call required by the compiler for program startup. The details vary but the call is needed. Amongst other things it will probably initialize your C++ static constructors. Reid.> > Attached here are the original "helloworld.cpp" and "helloworld.c" > files. > > Thanks. > > Napi > > On Sun, 2006-11-05 at 09:14 -0800, Reid Spencer wrote: > > Hi Napi, > > > > On Sun, 2006-11-05 at 18:30 +0800, Mohd-Hanafiah Abdullah wrote: > > > > > > 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.