开发者

Any C compiler with C output? [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 7 years ago.

Improve this question

We all know that C compilers spit out assemb开发者_如何学运维ly.

However I am doing research where my tool only accepts a narrow subset of ANSI C. Is there any C-to-C translators out there that can inline functions or flatten struct's, but writes out C code?

Any other tool that could simplify C code, let me hear them.


LLVM supports something like this.


If you do not require the resulting C code to be particularily readable, you could use your regular compiler to produce a binary executable, and then use a decompiler to produce C code from the binary. The decompiler will most likely not be able to "deinline" the functions that the compiler inlined. Not sure about the structs, though, but if you compile without debugging symbols and use a not-too-sophisticated decompiler, it might not detect the structs at all.


Clang can translate its AST back to C as far as I can understand from various sources on the Internet.


The old MIT project C2C (was on FTP for some time) and the newer Cilk give you the possibility to run the C->AST->C process.

Cilk and Cilk++ are actively maintained. They include a very good ANSI C parser.


Our DMS Software Reengineering Toolkit and its C Front End can do this.

DMS provides generic machinery for parsing, building ASTs, symbol tables, generally analyzing ASTs, and specific analyzers for control/dataflow/points-to/value range, as well as transforming ASTs aribtrarily either procedurally or using patterns, and regeneration of source text including comments. DMS's ability to process multiple compilation units at the same time allow for global analzyers and transformations that affect multiple compilation units simultaneously.

DMS's C Front end specializes all this for C (it has front ends for a variety of other langauges). It handles variety of dialects, including ANSI, GCC 3/4, MS Visual C and Green Hills C; it can be customized for other dialects as needed.

DMS has been used for a variety of C analysis/transformation projects, including analyzing a 26 million line software system.

An interesting application of DMS is to instrument C source to catch pointer errors when they occur (rather than suffering a long-delayed crash); see our CheckPointer tool. This tool reads the source code, inserts extra code to check each pointer access, and then writes out the results. In the process of doing this, it normalizes the C code to a simplified subset to get rid of lots of special cases. This normalization may be pretty close to the kind of thing OP wants to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜