OpaqueType::get() function in LLVM - llvm

I am following the code from the project
https://llvm.org/svn/llvm-project/java/trunk/lib/Compiler/Resolver.cpp that uses OpaqueType::get() and it used to be in llvm/IR/DerivedType.h, but it's been removed now. What should I use instead.
Also, my code https://llvm.org/svn/llvm-project/java/trunk/tools/class2llvm/class2llvm.cpp included one header file #include <llvm/Bytecode/WriteBytecodePass.h>
which has also changed.
Please tell me what I should use in replacement of these.

Well, opaque types disappeared more than 7 years ago in LLVM 3.0. As a replacement – you should use just empty StructType. Bytecode disappeared in LLVM 2.0 which was released more than 11 years ago. Everything is "bitcode" now and there are plenty examples within LLVM codebase how to use the corresponding API. E.g. almost any tool inside "tools" subdir has such code. See "tools/opt/opt.cpp" as an example.
The code that you're trying to "upgrade" is 12 years old, unmaintained and always was of proof-of-concept quality.

Related

Programming and platform dependance for c++ questions [duplicate]

This question already has answers here:
How to write portable code in c++?
(12 answers)
What is "Portable C++"? [duplicate]
(2 answers)
What is meant when a piece of code is said to be portable? [closed]
(3 answers)
Closed 4 months ago.
The community reviewed whether to reopen this question 4 months ago and left it closed:
Original close reason(s) were not resolved
Not sure if this is the right place to ask this:
How do programs written in c++ run on other computers if you don't write them specifically to do that? I saw something about not just sending the .exe, but also sending other things with it?
Is there a high level programming language that is as fast or nearly as fast (in run speed) as c++ while also being platform independent?
See above.
You compile your code for all the platforms you target and deploy a number of executables. Hence, Write once, compile anywhere.
C++ allows you to write portable source code. So assuming you write portable code to start with, you can compile it for some target platform, and run the resulting binary on that target.
Now, depending on what your program uses, you may have to package other "stuff" with the executable. What you mention ("I saw something about not just sending the .exe, but also sending other things with it?") would arise if your program used some dynamic link libraries that were not part of the OS (presumably Windows, based on the mention of .exe). But, it's kind of up to you to decide whether to use a library that's packaged as a DLL or not. If you don't want to package DLLs with your executable, don't use them (but sometimes, you may decide it's less trouble to use and package the DLL than do without).
As far as another language goes...doesn't really make a lot of difference as a rule. If you write code that depends on something else, you have to satisfy that dependency on the target computer. Some languages require you to add some DLLs to support the language itself, but most C++ compilers don't. On other OSes, those dependencies won't be called "DLLs", but most reasonably modern OSes provide something similar.

C++ __builtin_* functions source codes [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to learn how can I find source codes of __builtin functions like __builtin_cbrt() in C++. If you know, Can you help me?
I want to learn how can I find
First become acquainted with the language you are working with - learn C and C++ programming languages. Learn about the tools like git and autotools and the environment around these programming languages. Become familiar with the tool set needed browsing files - at least grep, but I recommend it's (way) faster alternatives - "the silver searcher" ag or ack, but be aware of tools like ctags or GNU Global.
Then research. GNU projects are available open source - it's very easy to find source code of GNU projects, nowadays they are even mirrored on github.
Then it's just a "feeling" or "experience". Surely a project will have builtins functions in a file named "builtins.c" or something similar. Be curious, reasonable and inventive. If you would want to add a builtin function to a codebase, where would you put it? Become familiar with the project structure you are working with. And expect big and old projects to have stuff scattered all over the place.
First I find gcc sources with builtins.def (BUILT_IN_CBRT, "cbrt", and some references of BUILT_IN_CBRT in builtins.c.
After cloning the gcc repository I scan for BUILT_IN_CBRT macro name. Browsing the code leads me to CASE_CFN_CBRT macro name, which leads me to fold-const-call.c:
CASE_CFN_CBRT:
return do_mpfr_arg1 (result, mpfr_cbrt, arg, format);
By the name of the file fold-const-call.c I suspect this part of code is taken only when folding a constant call.
From there I can browse google about mpfr_cbrt symbol, which leads me to GNU MPFR library. I find clone of MPRF library on github and search for a file named cbrt, I find cbrt.c with mpfr_cbrt() sources with the source of cbrt within MPRF library. This is the code that will be called and will compute cbrt of a number when __builtin_cbrt is folded inside a constant expression, I suspect.
When not in constnat expression, I suspect that [fold_const_call_ss]https://code.woboq.org/gcc/gcc/fold-const-call.c.html#_ZL18fold_const_call_ssP10real_value11combined_fnPKS_PK11real_format) is not called at all, instead some fold_const_* function returns to gcc that the expression cannot be constantly folded so a call to the actual cbrt() standard function is generated.

Is it possible to decompile a C++ executable file [duplicate]

This question already has answers here:
Is it possible to "decompile" a Windows .exe? Or at least view the Assembly?
(16 answers)
Is there a C++ decompiler? [closed]
(5 answers)
Closed 4 years ago.
I lost the source code to an executable file but still have the actual file. Is there any way to retrieve the original C++ code?
Duplicate of this question here.
Yes, it is possible, however when it comes to peeking function bodies and the like, you might have a little less luck. Operating systems like Kali Linux specialize in de-compilation and reverse engineering, so maybe look into a VM of that. And of course, windows has a lot of applications you can use as well to check the application code.
Look over the other question for specific app suggestions. :)
Edit : You will most likely have lost all your logic and function bodies, but you might be able to recover the overall structure. It's your EXE so you might be more familiar with how it was all connected up.
You cannot get the original source code but you can decompile the binary into source code using tools given in this similar question: Is there a C++ decompiler?
The output source code will not look like the original as the compiler will have optimised the original source when generating the executable.
Short answer NO.
Long answer, because C++ doesn't use some intermediate code like C# or Java you cannot decompile the app in some readable format. But if you can read assembly maybe you can save some time.

Determine GCC Compiler with Macro [duplicate]

This question already has answers here:
How can I detect g++ and MinGW in C++ preprocessor?
(2 answers)
Closed 7 years ago.
EDIT: Ha ha, search terms are a weird thing. I actually had to use the answer I got as a term for the search to finally find this question. In the spirit of StackOverflow, I'll vote to close my
own question as duplicate instead of deleting it, in case it'll serve as a landing point for
someone else.
I am writing several functions that are using asm, but I only want them to function when they're compiled with a compiler that can work with NASM. (I'm on C++11, by the way.)
I'm a little bit new to the whole concept of asm, but this is what I think I know:
GCC and its "relatives" (MinGW, TDM-GCC) use NASM, which is what I'm writing my functions for.
All Intel and AMD processors can theoretically understand NASM, regardless of operating system, because...
The X86/X64 assembler is determined by what the compiler implements.
Assuming the above is correct, what macro can I use to ensure that the functions I'm writing are defined if and only if I'm using a GCC (or similar) compiler, or a compiler that uses NASM? (The #ELSE would be a usable dummy version of the function to ensure general compatibility with other compilers.)
The only macros I know about of this sort relate to determining operating system (such as #IFDEF _WIN32), but that macro would incorrectly get used in the situations where I'm compiling with TDM-GCC or MinGW on Windows.
NOTE: In case anyone wonders, the functions in question are basically
"helpful, but not vital" utility functions. We don't have any plans to
compile with a non-GCC compiler, but it's open source code, so we want
to be considerate of others.
You can use the __GNUC__ macro to identify GCC (and some mostly compatible compilers like Clang and Intel's C++ compiler).
MinGW (any version) can be checking for __MINGW32__ and/or __MINGW64__.

Static Code Analyzer for C++ in Linux [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What open source C++ static analysis tools are available?
Does anybody know of an open source,good static code analyzer for C++ code in Linux ?
The idea is to catch programming errors even before the code goes in to the code review state.
It would be great to have the possibility to add rules the tool.
Does anybody know of such tool?
lint, found here: http://en.wikipedia.org/wiki/Lint_(software)
cppcheck, found here: http://cppcheck.wiki.sourceforge.net/
you can give a try pvs-studio:
http://www.viva64.com/en/pvs-studio/ (1)
also there is (bla-bla-lint):
http://www.gimpel.com/html/index.htm (2)
missed note about linux,
FlexeLint for C/C++ from (2) has linux support,
(1) only for windows, you can check it only if your product crossplatform.
You can also customize GCC (4.6) by using plugins (coded in C) or MELT extensions (MELT is a high-level domain specific language to extend and customize GCC). This approach could be appropriate if you have your own coding rules that you want to check. However, it does take some work.
Take a look at clang's static analizer: http://clang-analyzer.llvm.org/
There are other tools like KLEE based on llvm, might worth a look, too.