Is it possible to write a web server in LLVM IR? - llvm

I wonder if it's technically possible to write a simple web server in LLVM IR.
I've found one which is written in amd64 assembly and it's really working.

Related

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

How do I run an Answer Set Programming file from a C++ File?

What methods are there that I can use to run an ASP file from the main function of my C++ code?
I'm doing a project in which I am expected to control a simulated turtlebot using a C++ file, and use ASP code to construct an action plan that the robot can use to achieve a specified goal.
I'm using Ubuntu 14.04, SPARC (an ASP solver), ROS indigo, and gazebo.
Am I correct that SPARC is implemented in Java (this link)?
If this is the case, there are quite a few options:
You can use Java Native Interface to interact with SPARC tool directly from c++ code
Other option is to create a separate
process
from c++ code and communicate with it via stdout/files
You can implement ROS node in Java which accepts requests and uses SPARC as a library to process them. In this case your c++ doesn't care about exact SPARC implementation
Resume:
I would suggest you to try the last option. It's slightly more difficult than other 2 options, but it fits perfectly into ROS infrastructure.

Using LLVM as virtual machine - multiplatform and multiarchitecture coding

I'm currently working in a pet programming language (for learning purposes), and have gone through a lot of research over the past year, and I think its time to finally start modelling the concepts of such a languague. First of all I want it to compile to some intermediate form, such as JVM or .NET bytecode, the goal being multiplatform/architecture compatibily. Second, I want it to be fast (I also have many other things in mind, but its not the purpose of this topic to discuss those).
The best options that came to my mind were:
Compile to JVM bytecode and use OpenJDK as runtime environment,
Compile to .NET bytecode and use Mono as runtime environment,
Compile to LLVM IR and use LLVM as runtime environment.
As you may have imagined, I've chosen LLVM. Why? because its blazing fast. I did a little benchmark using the C++ N-Body code, and achieved 7s in my machine with lli jitted IR, in contrast with 27s with clang native compiled code (I know clang first make IR then machine code).
So, here is my question: Is there any redistributable version of the LLVM basic toolset (I just need lli) that I can use? Or I must compile my own? If the latter, can you provide me with any hints on how to do it? If I really must do it, I'm thinking is cross-compiling them from my machine (Intel Mac), and generating some installers (say, an .msi for windows, .rpm and .deb for popular linux distros and .pkg for Macs). Remember, I only need a minimal subset of LLVM, such that this subset is capable of acting like a VM, by using "lli ". The real question here is how to use LLVM as a typical virtual machine.
First, I think all 3 options - LLVM IR + LLVM, Java Bytecode + OpenJDK, and .NET CIL + Mono - are excellent options, and I agree deciding between them is not easy.
If you go for LLVM and you just want to use lli, you can compile LLVM to your target platform and pack the resulting lli executable with your distribution, it should work.
Another way to write a JIT compiler via LLVM is to use an execution engine - see the handy examples in the Kaleidoscope tutorial. That means that you write your own program which will JIT-compile your own language, compile it to whatever platform you want while statically linking it with LLVM, and then distribute it.
In any case, since a JIT compiler requires copying an LLVM binary to the client side, make sure to attach a copyright notice with your distribution (you don't have to open-source your distribution, though).

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.