How to find compiler implementation details? [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
It is well known that switch-case constructs can provide better code performance than if-else constructs due to implementation in the form of jump-tables,etc. You can know this only when you know how the compiler implements switch-case. So my question is that how do you get to know how a compiler, for example, Microsoft C++ Compiler or g++, implements a feature? Is there some standard literature available on these topics with respect to common compilers?

It is not very useful to get information on how will a compiler implement a feature because the compiler runs multiple steps, each will modify the compiled result.
As an example:
A first step build up a meta language, a second step do a first optimization, next step maybe inline some code, next step...
So you can't get any idea of the code which will be created. So only chance you have: Try it out!
For your example of a switch/case it is important if
the case patterns are linear
the code inside the pattern is used once or multiple
the code return or modify variables or only call other functions
4 ... tons of other dependencies!
Forget about prediction of optimizer results.
For gcc you have the source, look inside :-)

Related

How to create a list containing the LOC for each function (C++) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I want to make sure that the function body for each function fits on the screen. Therefore I want to to generate a list that contains the LOC for each function (in a .cpp/.h - file, or better in all source code files in a directory). For example the list could be an CSV-file containing
foo.cpp,foobar,42
foo.cpp,foozar,13
goo.cpp,bla,666
if the file foo.cpp contains a function foobar which has a body of 42 lines, etc...
Can you recommend/suggest any tool?
The issue is simple. If you want accurate data no matter what C++ you encounter, you will need a full C++ parser with preprocessor capability. That's very hard to build due to the complex nature of C++ (now C++11 is pretty standard and C++14 is not far behind). Pretty much your choices are limited to:
Edison Design Group C++ front end
Clang
GCC
Our DMS Software Reengineering Toolkit with its C++ front end
Elsa (if it still maintained)
These are big, complex engines and take effort to configure for your task (esp. GCC, which wants to be a compiler no matter what you want it to be). An additional complication that may or may not matter to you: Clang, GCC and Elsa don't handle the MS dialects, if I understand them correctly.
If you don't care if you get the right answer all the time, you could build a very simple scanner to look for apparant function heads, counting { ... } and ( ... ) to make sure you know where the function body terminates. You'll probably have to recognize namespace and class constructs, to know to look inside them for function declarations. This seems like the easiset solution, thus fastest in time and least effort.
You can write a plugin for clang. It is well suited for these kinds of extensions.

How can I decrease compile time of TMP & macro preprocessor metaprogramming in C++? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Improve this question
Are there any tricks that can work with large pile of metaprogramming code?
I'm using the latest version of clang. But I can switch to any (free) compiler that support C++14.
Or, are there any tricks that can work with large pile of
metaprogramming code?
Prefer constexpr-functions to TMP-functions, they are generally faster. Since C++14 you can also use more than only a return-statement of working code in constexpr-functions, that eases their use even more.
Generally avoid recursion. And don't care about the complexity class of the algorithm itself too much, as long as it compiles fast. (In TMP code, getting the better complexity class can result in much slower compilation).
Don't use recursion with variadic templates like so:
template< typename First, typename ... Tail >
struct A : A<Tail...>
They create a quadratic time complexity, because the compiler has to create separate argument lists in every step! This is significantly measurable. Try instead to delegate recursion to one point in the program, the best approach is to delegate it to std::make_index_sequence, and then deduce everything to that.
Don't use Boost.PP to generate many partial/explicit specializations which handle cases. It doesn't help. 200 explicit spezializations will only make it worse, since the compiler has to search through the spezializations (beside the primary template) and look for the first and most specialized one which matches.

Manual Decompilation References [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm looking for book titles or papers about how to decompile X86 Disassembly into C/C++ code MANUALLY.
Well , I know about many tools that do the job , but I think doing it manually is more efficient even if it's a slow process.
If you are VERY used to looking at disassembly from a particular compiler, you MAY be able to come up with decent C or C++ code. But it's a TERRIBLY slow process even then. Just taking one small function (say a for-loop, a couple of if-statements and some basic math) and reconstructing it back into source code can take half an hour for me, and I don't think I'm terribly bad at it. Of course, one of the main points is identifying commonly used algorithms, such as linked lists, binary trees, string management, vector management, etc.
Doing it by machine will give you a lot of the work done for you, but even then, it can take days to do even a few hundred lines of orginal C++ code into something that is actually readable.

A C++ source code analyzer [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Could you suggest some open source tools that analyze C++ code and checks the following rules:
naming conventions,
file inclusions,
function design,
data types,
flow control,
memory allocation,
file handling,
portable code,
runs under Solaris or SUSE
http://www.google.com/search?q=misra+checker
Of course, if the rules you're trying to enforce don't exactly match someone else's idea of a coding standard, no existing tool is going to work.
It is still in early development (especially for C++) but its improving rapidly and is a really interesting open source project in a vibrant community. So see if the CLang Static Analyzer does what you need.
I have used coverity (http://coverity.com/)in my organization. It does static bug check analysis and I found it to be very useful. It is highly customization and provides a number of checks. I am not entirely sure if it works on solaris or not but I would recommend checking it out.

Is there kind of runtime C++ assembler library around? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
For my small hobby project I need to emit machine code from C++ program in runtime. I have base address 0xDEADBEEF and want to write something like this:
Assembler a((void*)0xDEADBEEF);
a.Emit() <<
Push(Reg::Eax) <<
Push(Reg::Ebx) <<
Jmp(0xFEFEFEFE);
Inline assembler isn't my choice because generated machine code is dependent of the program state.
Does anybody know any existing library for doing this? If no, would it be a good idea to develop one from scratch and make it open source? (I mean, will anybody ever use this library if it existed?)
Check out Asmjit. It seems to be the thing you're looking for.
You could use Nicolas Capen's softwire. Its really not supported any more as he now works on a similar product at Transgaming called SoftAsm. Still it kinda does what you want.
Edit June 2014: - It appears the sourceforge link above has been removed but it appears to be available under an LGPL license here.
This might be a overkill, because it supports many platforms, has its own intermediate language, does optimizations, etc, but the http://llvm.org/ seems to be a god try.