Fei Jia
2011-Oct-10 23:15 UTC
[LLVMdev] There are compiling errors when converting bytecode to c by LLC
I convert C to bytecode by LLVM, and then convert the bytecode back to C by LLC, but the generated C code cannot be compiled. Could anyone give me some suggestions? Thanks! The initial C file is rather simple (hello world): #include <stdio.h> int main() { printf("hello world\n"); printf("hello world1\n"); return 0; } The two commands: llvm-gcc -emit-llvm -c -o hello.bc hello.c llc -march=c hello.bc Version of LLVM: 2.9 The source of error in generated c file: /* Global Variable Declarations */ static _OC_str { unsigned char array[12]; }; static _OC_str1 { unsigned char array[13]; }; /* Global Variable Definitions and Initialization */ static _OC_str { unsigned char array[12]; } = { "hello world" }; static _OC_str1 { unsigned char array[13]; } = { "hello world1" }; It seems that _OC_str, and _OC_str1 are structure variables, but I have never seen such way of declarations, definitions, and initialization of structure in C code. I guess it may be supported in some standards of C. Could anyone please give me some information about the problem? Thanks! -- Best Regards, Fei Jia -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111010/d326447e/attachment.html>
Dmitry N. Mikushin
2011-Oct-29 23:43 UTC
[LLVMdev] There are compiling errors when converting bytecode to c by LLC
Hi Fei Jia, What revision are you using? I suggest you to try C backend with the most recent LLVM version, if possible. I recall I had some similar C backend breakages in July-August: structs definitions were lost somewhere. To my understanding, the correct result should look like this: /* Typedefs */ typedef struct l_unnamed_0 l_unnamed_0; typedef struct l_unnamed_1 l_unnamed_1; /* Structure contents */ struct l_unnamed_0 { unsigned char array[12]; }; struct l_unnamed_1 { unsigned char array[13]; }; /* Global Variable Declarations */ static l_unnamed_0 _OC_cst; static l_unnamed_1 _OC_cst1; /* Global Variable Definitions and Initialization */ extern static l_unnamed_0 _OC_cst = { "hello world" }; extern static l_unnamed_1 _OC_cst1 = { "hello world1" }; - D. 2011/10/11 Fei Jia <j.jiafei at gmail.com>:> I convert C to bytecode by LLVM, and then convert the bytecode back to C by > LLC, but the generated C code cannot be compiled. Could anyone give me some > suggestions? Thanks! > The initial C file is rather simple (hello world): > > #include <stdio.h> > > int main() { > > printf("hello world\n"); > > printf("hello world1\n"); > > return 0; > > } > > The two commands: > > llvm-gcc -emit-llvm -c -o hello.bc hello.c > > llc -march=c hello.bc > > Version of LLVM: 2.9 > > The source of error in generated c file: > > /* Global Variable Declarations */ > > static _OC_str { unsigned char array[12]; }; > > static _OC_str1 { unsigned char array[13]; }; > > > > /* Global Variable Definitions and Initialization */ > > static _OC_str { unsigned char array[12]; } = { "hello world" }; > > static _OC_str1 { unsigned char array[13]; } = { "hello world1" }; > > It seems that _OC_str, and _OC_str1 are structure variables, but I have > never seen such way of declarations, definitions, and initialization of > structure in C code. I guess it may be supported in some standards of C. > Could anyone please give me some information about the problem? Thanks! > -- > Best Regards, > Fei Jia > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >
Fei Jia
2011-Oct-31 23:55 UTC
[LLVMdev] There are compiling errors when converting bytecode to c by LLC
Dear Dmitry, Thanks for your reply. I have just updated my version from svn sever and it's perfect now. The previous version is from the svn server several days before Oct 10, and I guess the code related with gcc might not be updated at that time. Thanks a lot! -- Best Regards, Fei Jia On Sat, Oct 29, 2011 at 4:43 PM, Dmitry N. Mikushin <maemarcus at gmail.com>wrote:> Hi Fei Jia, > > What revision are you using? I suggest you to try C backend with the > most recent LLVM version, if possible. I recall I had some similar C > backend breakages in July-August: structs definitions were lost > somewhere. To my understanding, the correct result should look like > this: > > /* Typedefs */ > typedef struct l_unnamed_0 l_unnamed_0; > typedef struct l_unnamed_1 l_unnamed_1; > > /* Structure contents */ > struct l_unnamed_0 { > unsigned char array[12]; > }; > > struct l_unnamed_1 { > unsigned char array[13]; > }; > > /* Global Variable Declarations */ > static l_unnamed_0 _OC_cst; > static l_unnamed_1 _OC_cst1; > > /* Global Variable Definitions and Initialization */ > extern static l_unnamed_0 _OC_cst = { "hello world" }; > extern static l_unnamed_1 _OC_cst1 = { "hello world1" }; > > - D. > > 2011/10/11 Fei Jia <j.jiafei at gmail.com>: > > I convert C to bytecode by LLVM, and then convert the bytecode back to C > by > > LLC, but the generated C code cannot be compiled. Could anyone give me > some > > suggestions? Thanks! > > The initial C file is rather simple (hello world): > > > > #include <stdio.h> > > > > int main() { > > > > printf("hello world\n"); > > > > printf("hello world1\n"); > > > > return 0; > > > > } > > > > The two commands: > > > > llvm-gcc -emit-llvm -c -o hello.bc hello.c > > > > llc -march=c hello.bc > > > > Version of LLVM: 2.9 > > > > The source of error in generated c file: > > > > /* Global Variable Declarations */ > > > > static _OC_str { unsigned char array[12]; }; > > > > static _OC_str1 { unsigned char array[13]; }; > > > > > > > > /* Global Variable Definitions and Initialization */ > > > > static _OC_str { unsigned char array[12]; } = { "hello world" }; > > > > static _OC_str1 { unsigned char array[13]; } = { "hello world1" }; > > > > It seems that _OC_str, and _OC_str1 are structure variables, but I have > > never seen such way of declarations, definitions, and initialization of > > structure in C code. I guess it may be supported in some standards of C. > > Could anyone please give me some information about the problem? Thanks! > > -- > > Best Regards, > > Fei Jia > > > > _______________________________________________ > > LLVM Developers mailing list > > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111031/dbc6d962/attachment.html>
Maybe Matching Threads
- [LLVMdev] There are compiling errors when converting bytecode to c by LLC
- [LLVMdev] question on difference of bitcode between C and C++
- [LLVMdev] question on difference of bitcode between C and C++
- [LLVMdev] question on difference of bitcode between C and C++
- [LLVMdev] question on difference of bitcode between C and C++