Example on how to do error handling for llvm - llvm

I am using llvm 14 and I had looked at the llvm docs for error handling but I am still not able to understand how to implement it by using the CPP API. Is there an example on how to do this?

Related

POCO C++ library is not compiling with CMAke and MinGW. Thread_WIN32.cpp __except error

everyone. I try to build POCO C++ library with CMake and MinGW compiler, but I receive syntax error in POCO Thread_WIN32.cpp file (Picrealted). I think it is somehow related with compiler exact version, posix-sjlj. Has anyone encountered this problem?
Setup:
Windows 10
MinGW-W64 x86_64-posix-sjlj-rev0 8.1.0
CMake 3.26.0-rc1
error pic (link)
UPDATE 1
I tried another version of MinGW-w64 (MinGW-W64 x86_64-posix-seh-rev0 8.1.0), but it also didn't work. I have another question: maybe compiler just makes it's job right? In Thread_WIN32.cpp file from POCO GitHub in setThreadName function no __catch before __except. Why? Mustn't it be there?
pic of setThreadName function from POCO GitHub
UPDATE 2
Okay, after __try shoudn't be __catch, after __try follows __except and that's all. This is microsoft own way to handle errors - SEH. But I wonder hard is there some way to properly use MinGW-w64 compiler with SEH. I read about __try1 and __except1 in MinGW, but Internet said that it might be unsafe and very painful
So, I tried some different variations of MinGW-w64 compiler, but it didn't work. I decided to download MSVC compiler with Microsoft Build Tools and it did pretty well, all libraries compiled

What is the alternative to "'llc -march=cpp" in LLVM 12

LLVM used to provide llc -march=cpp test.ll -o test.cpp instruction to learn C++ API, but this is not available in llvm 12.
Unfortunately, there is no alternative. The reason why C++ backend was removed long time ago is quite simple: it did not serve its main intention to be a guide to LLVM C++ API well, it generated suboptimal code and was not updated to support the latest changes to C++ API.
You can use the code of existing transformation passes to learn LLVM C++ API

LLVM : generating a "ir" file for specifically z80 processor using llvm

I am working on LLVM, and want to generate the files according to specific target architecure e.g-z80. I have downloaded z80 source code and clang. I used --target in clang command to specify z80 but it is not working. can anybody help me out in this problem? Thanks in advance.
LLVM has no official z80 backend/target. There appear to be some third-party projects attempting to implement one, like llvm-z80, so you can try to check them out. The alternative would be writing a new backend.

using an llvm backend (Mips, Sparc etc)

I am trying to find some code examples which allow me to hook up a llvm backend for code generation. For example, hooking up the IR to either the Mips or Sparc backend. However, I haven't been able to find any such examples. The only closest thing I could find is the use of the AMD IL & GPU backend, currently in the mesa tree but not yet merged into the llvm backend. I have read the Writing an LLVM Backend tutorial but its not really obvious to me as to how to hook up the backend. I am sure I am missing something from the examples so could someone point me to some examples for this ? I already have code to generate the IR.
Thanks
You might want to look at the LLVM llc command. It reads a bitcode IR file and calls any of the backends on it.
The llc command would compile LLVM IR to target machine assembly.
With argument "march=[your target]", you can get assembly for different targets,
"march=mips" for Mips, for example.

Possible to auto-generate llvm c++ api code from LLVM-IR?

The clang 3.0 online demo page http://llvm.org/demo/index.cgi provides an option to output LLVM C++ API code" representing the LLVM-IR for the input program.
Is "produce LLVM C++ API code" output a clang option (and if so, what is it)?
Or is it an llvm tool option (which one)?
Is it possible to do the same thing but from LLVM-IR input? Basically I'd like to see the proper llvm c++ api calls needed to produce a particular given llvm-ir sequence. I'd like to learn backwards by example rather than forwards from the documentation.
Manual pages and --help and --help-hidden for clang, llvm-as and llvm-dis don't show anything obvious.
edit: OK now I see in the output on that web page, "generated by llvm2cpp". But I can't find that tool in recent llvm releases, only old releases, has a new tool in 2.9 and 3.0 taken over for llvm2cpp?
Yes. C++ backend is the tool which does this. Try "llc -march=cpp foo.bc"
I ran into exactly the same problem and saw the CPPBuilder mentioned a couple of times. This approach unfortunately no longer works on recent LLVM versions as the CPPBackend was removed between 3.8 and 3.9.
If you want the CPP backend you (i) have to configure llvm and add cppbackend to -DLLVM_TARGETS_TO_BUILD during the initial configure and (ii) run an llvm <= 3.8.
The feature was removed because it did not use IRBuilder and almost nobody used it. My solution was to rely on the old version to get inspired, then implement it myself.