Closed. This question does not meet Stack Overflow 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
Is there any source-to-source converter (translator) from Ada (95, 2005) to C?
How full they are (can they convert every feature of Ada into gnu c99 + pthreads + POSIX)?
Is it possible to use such ada-to-c translator in critical applications?
PS: Translators to C++ (up to 2003 with gnu extensions) are welcome too.
PPS: when said "gnu c99", it means only that C99 + most gnu extensions are supported, but don't mean the GCC.
I don't know of any open source Ada-to-C translator. The only one I knew of at all was SofCheck's, which was reportedly pretty good.
SofCheck has since been bought by AdaCore, and I did a very brief search of the AdaCore website for the translator, and nothing jumped out. You could ask them at sales#adacore.com, if pursuing a commercial solution is a viable option for you. (At least get a price.)
Unless there is an incredibly strong reason to use Ada for this application (e.g., customer demands it, or you already have a big application coded in Ada that you want to use), it will likely be a lot less painful if you just bite the bullet and code your solution in well-crafted C99 or C++ as you see fit.
If you insist, Sofcheck's translator might be best; they've been working on it a long time.
Failing that, you might(?) build a translator starting with the ASIS output of an Ada compiler. That's likely rather a lot of persnickety work since Ada has pretty precise semantics that you'd better preserve if you want to just carelessly code in Ada, translate and run. It will be even more work if you want the output to be "pretty" for the final customer. (Long term maintenance should be a consideration). I suspect implementing code to simulate Ada's rendezvous might be rather tricky, being both semantically complicated and asynchronous at the same time. The real flaw with this approach is that it is a lot of work; maybe just getting on with your life and coding the application itself in something non-Ada would be less effort.
See my caveats on language translation done poorly and alternative methods.
Related
Closed. This question does not meet Stack Overflow 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 8 years ago.
Improve this question
I started a while ago to learn the C language, and has spent several hours I search THE miracle software.
I am looking for software that import sources of software in C (files.c) and generates a "mind map" of the code with all files, functions, variables, etc ...
Do you know if it exists? It'll help me a lot to understand the architecture of complex software.
Thank you very much for all your answers.
Take a look at the "call graph". This sort of visualization should get you started.
As the comment suggests, Doxygen is a good open-source tool. Take a look at some output here. Doxygen is straight-forward to configure for call-graph generation under *nix. It's a little more complex for Windows. First, check out this SO post: how to get doxygen to produce call & caller graphs for c functions. Doxygen's HTML output provides a number of nice cross-referencing features (files, variables, structs, etc.) in addition to caller/callee graphs.
On the commercial side, Understand for C/C++ has first-rate visualization features. Google "c call graph diagram" for other commercial and open-source options.
Finally, there are some older SO posts, like this one Tools to get a pictorial function call graph of code. Take a look at it.
Look into the program ctags. It is an indexer of names and functions based on the structure of the programming language.
It is quite mature, and has integration with a number of other tools. I use it with an older (but very nice) text editor called vi, but it can be used independently from the command line.
It does not generate a graphical view of the connections. However, in my estimation there are probably too many connections in most C programs to display visually without creating a large amount of information overload.
This answer differs from Throwback's answer in some interesting ways. A call graph can mean a few things. One thing it can mean is the path a running program took through a section of code, and another is the combination of all paths a running program might take through the code, and another is the combination of all paths in the code (whether they can be reached or not).
Your needs will drive which tool you should use.
Closed. This question does not meet Stack Overflow 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
Are there any libs out there that can parse C syntax?
For example I would like to write my own code/scripts that will analyze c files given the c syntax. Number of "if" statements per function/file, lines of comments per lines of code in a function and so on.....
I have no problem writing all this custom code just wanted to make the job easier if there was already some lib that I can use to jump start instead of starting with the parser.
Thanks!
Besides the clang suggestion already made, consider pycparser and Boost.Wave.
Although they are more targeted at semantical analyses rather than syntactical ones, you might be interested in CIL and Frama-C, which is based on it (both in OCaml). Another tool (OCaml and Python bindings) of interest is Coccinelle.
Personally, I would look first for an existing tool to do what you want. This sounds like an awful lot of work and there are a lot of good free tools out there for code metrics (did you look on SourceForge?).
If you insist on going ahead with your project, you might google for Lex/Yacc grammars for C.
However, I switched from Lex/Yacc a few years ago to Antlr. I particularly like the way it allows you visually step through your parsing.
A great tool, and free. There is a complete grammar for C available too, so you can modify that to suit your needs.
Hope this helps. Good Luck
you might also consider trying a code coverage tool. although code coverage is meant to show you how much percent of the source code is executed but some of them also show how many conditional statements or loops it encountered whilst doing code coverage. One example that I can share based on my experience is windriver workbench code coverage tool
Closed. This question does not meet Stack Overflow 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 assembly.
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.
Closed. This question does not meet Stack Overflow 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 6 years ago.
Improve this question
What tools are there that supports refactoring C code (renaming variables, extracting methods, finding method references, ...)
Preferably for a Linux environment, but Windows tools are ok too.
If there's something available for emacs, even better!
Netbeans 6.7 and above have reasonably decent basic C (and possibly C++, but haven't tried it) refactoring. I use it when doing the JNI part of one of my projects, and stuff like renaming vars, macros, functions, finding usages of a function all work well. Definitely worth a try, to see if it does the rest of what you want, if you're not wedded to emacs yet.
For emacs, there is xrefactory but I haven't tried it myself.
I use Eclipse with CDT as an IDE and find that it works well for refactoring and searching code.
Old, but not bad is cscope and the GUI frontend kscope.
Qt Creator is very fast and useful IDE. It's not only for Qt Framework. You can use it for C and pure C++ projects too. Also it have many refactoring features. It's cross-platform and have vi emulation too. For refactoring features please refer it's documentation.
Slickedit is good at refactoring.
Maybe this previous question could help, at least in speeding up the compile-run cycle.
Fast compiling (or maybe more apt, fast lexical analysis) is one of the things needed to create a system supportive of refactoring.
This article discusses some C++ refactoring tools for Visual Studio.
Closed. This question does not meet Stack Overflow 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 6 years ago.
Improve this question
Can you recommend peer reviewed libraries that I can use in C environment (something like Boost for C++) ? Something that provides hash, thread, interprocess communications, lists, smart memory management...
The environment is embedded system, not a very minimal system, but also not a PC!
+1 for GLib from me, too. Plus, it has its own threading API too, so you don't have to learn pthreads if you don't want to.
Not sure if there exists such a thing as "smart memory management" in C, it's not very easy when you don't have the safety nets of destructors and control over operators. But, again, GLib has plenty of memory-oriented data structures and stuff that really makes life easier.
And no, I'm not on the GLib team, but I really do like it. :)
Check out the Apache Portable Runtime (APR) project.
Some of it's features:
memory management API
threads, mutexes
file I/O
atomic operations
hash tables, arrays
network sockets and protocol
shared memory, mmap
Not to mention it's portable.
I'm not sure if you'll find a single library that covers all of that... but you can check out glib and pthreads to cover a good bit of that.
Look at Boehm GC a widely used conservative garbage collector for C (or C++) that might serve your needs as far as smart memory management is concerned.
I'll jump on the GLib bandwagon too. Remember that C doesn't provide any syntactic sugar for complex data structures, so there are lots of casts and long function names in GLib, but it really does a great and efficient job with a little added verbosity!!
About the Glib use.
You probably can take what you need and cross-compile it. So if you just need the thread package - just compile that and don't take everything.
I'm doing the same thing with the Python VM. PyMite fits on a microcontroller and doesn't use all the functionality.