[LLVMdev] Issues in converting C++ code to C using llvm and llc

Raj Parihar parihar at ece.rochester.edu
Tue Dec 13 08:07:02 PST 2011


Hello All,

I came to know from a friend that using LLVM insfrastucture one can convert
C++ programs to C. I needed this for my cross-compiler because we don't
have support for C++ compilation in our cross-compiler.

I tried following:
http://llvm.org/docs/FAQ.html#translatecxx

While I can generate .bc its llc which gives error. Then I also tried
"clang" as oppose to llvm-g++.

Here is what I want to accomplish: I have a simple c++ prog which I want to
convert to c using llvm
-----------------------------------------------------------------

For example
-------------------------------------------------------------------------
c++ orig file: test_orig.cpp
-----
#include<iostream>
int main()
{
  std::cout << "hello world from C++\n";
  return 0;
}
---------------------------------
c orig file: test_orig.c
-----
#include<stdio>
int main()
{
  printf("Hello workd from C\n");
  return 0;
}
-------------------------------------
I used following commands

% clang -c -emit-llvm test_orig.*EXT* -o test_orig.bc
or
% llvm-g++ -c -emit-llvm test_orig.*EXT* -o test_orig.bc


% llc -march=c test_orig.bc -o test_new.c

and then I simply used gcc to compile test_new.c
gcc test_new.c

When *EXT* is .c then everything works fine however when it is .cpp then
when I try to recompile the test_new.c using gcc it says undefiend
references to std::cout, std::basic_ostream, std::ios_base

I thought that llvm should be able to convert "cout" to "printf" or
equivalent.
Also how does llvm handles the libraries which are not part of std C but
are in C++.
-----------------------------------------

When I tried to compile my original benchmarks (They are from PARSEC suite)
I see this error

LLVM_ERROR: code generator does not support intrinsic function
"llvm.umul.with.overflow.i32"

How can I avoid this. I am running things on 64-bit Intel machine loaded
with CentOS 5.x

Any help/pointers to solve the above issues would be highly appriciated.

Thanks,
-Raj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111213/ab22b9d5/attachment.html>


More information about the llvm-dev mailing list