Can i compile in memory source code to executable with clang? - clang

reading this link :http://fdiv.net/2012/08/15/compiling-code-clang-api
i see i can load c/c++ file and compile it just fine to executable..
but i did't found any info if i have some kind of source code in c/c++
that my application generating or other way ..
in short can i pass the stage where i load the c file , and just build my own logic to compile to executable ?

Of course you can. And there is already a project for that purpose
Dig its source codes as your wish :)
Cling
What is Cling
Cling is an interactive C++ interpreter, built on the top of
LLVM and Clang libraries. Its advantages over the standard
interpreters are that it has command line prompt and uses
just-in-time (JIT) compiler for compilation. Many of the developers
(e.g. Mono in their project called CSharpRepl) of such kind
of software applications name them interactive compilers.
One of Cling's main goals is to provide contemporary, high-performance
alternative of the current C++ interpreter in the ROOT project -
CINT. The backward-compatibility with CINT is major priority during
the development.

Related

openmp pthread support for avr-gcc

I've been working with a teensy for a multithreaded project using openmp compiling with gcc, however I'm joining a project that uses avr-gcc which doesn't seem to want to compile or recognize omp.h . I get the error "avr-gcc: error: unrecognized command line option '-pthread' " when I attempt to compile and am having trouble finding more information. I found this question about gcc-avr having slower updates AVR gcc version < gcc release versions -- why? but am wondering if avr-gcc hasn't yet added openmp support or doesn't for one reason or another and if there's a work around without requiring the team to switch compilers.
thanks for the direction it appears that avr-gcc doesn't provide headers that interact with operating systems which apparently pthreads does.
"Since sockets are a feature provided by the operating system, and you are compiling code that runs bare-metal on an Arduino microcontroller, which has no operating system running on top, the whole purpose of the sys/socket.h header is nullified.
This applies to any other kind of header or library function that interacts with the operating system, such as unistd.h, fcntl.h, pthread.h etc. In fact, avr-libc, the Standard C library for AVR-GCC, does not provide such headers.
You will need to look at the avr-libc documentation to find out more about the headers and functions that are provided and their usage."

compiled vala itself with vala on windows

I'm not sure if this question is correct but...
Ok, is possible compiled the source vala in vala
because I bean downloading vala source code and inside has many vala files
here vala release source code
https://wiki.gnome.org/Vala/Release
I have been installed on windows this version
https://code.google.com/p/vala-win32/downloads/list
vala-0.12.0.exe
I wont compile the last vala release whit the vala on windows
oky, gracias :D
please, not confused with this question,
Compiling a Vala source On Windows
If 0.20.1 is enough, you can use http://www.tarnyko.net/en/?q=node/35 and possibly avoid this whole thing.
If you really need 0.22.0, Vala release tarballs don't actually require valac to compile—they contain all the generated C. You should be able to use the build system included with Vala (like Robert Rozas mentioned, or via cygwin) to generate executables even without valac installed.
GNOME wiki recommends using either MSYS2 or WSL (Windows 10 only) to get Vala compiler. Another option is using ValaForWindows, which aims to be the easiest option to install and use.

Global Management of Multiple Compilers in Lazarus IDE

I've been searching around the Lazarus IDE documentation for a bit, and thus far only found information related to cross compiling, so I was hoping someone could give me a straight answer on this. I'm currently working on a project that will require compilation for 32-bit Windows as well as 64-bit Windows. Additionally, I've already set up both versions of the Free Pascal Compiler. Does Lazarus have any built in functionality for configuring in both compilers, and then based on the build target, using the appropriate compiler? Ideally, this would be done at a global level, so that the configuration persists across projects, but if it can only be done at the project level, I don't mind doing it that way.
On further reading, I think I found my answer. I didn't realize it, but fpc has the same sort of front-end functionality as gcc. With that said, implementing the functionality described in my question is just a matter of installing the compiler as a cross compiler, rather than as an independent compiler. Since it doesn't look like you can use the x86_64 compiler to create a 32-bit version, you'll have to compile the 32-bit version, and then crosscompile the 64-bit version. In my case, I first compiled and installed the Win32 compiler using:
make all install INSTALL_PREFIX=C:\path\to\lazarus\1.0.8\fpc\2.6.3 OS_TARGET=win32 CPU_TARGET=i686 PP=ppc386.exe
Next, I compiled and crossinstalled the 64-bit compiler:
make crossall crossinstall INSTALL_PREFIX=C:\path\to\lazarus\1.0.8\fpc\2.6.3 OS_TARGET=win64 CPU_TARGET=x86_64
To confirm that it worked, you can find an executable called, ppcrossx64 in your C:\path\to\lazarus\1.0.8\fpc\2.6.3\bin\i386-win32 folder.

Is it possible to run erlang without compilation?

Is there any VM for Erlang that allows you to do compilation on the fly instead of compiling before?
There is a possibility to compile from the shell, thanks Martin.
Now, from the Erlang shell (or some other module!):
1> compile:file("mymod.erl").
{ok,mymod}
2> mymod:myfun().
Hello Joe
Is there any pros or cons with doing this?
Will you still be able to hot swap code?
Is it the regular use-case to handle code?
What benefits does the compiler give you in the end then?
From the Erlang shell, you can compile a module on the fly using c("path/to/module.erl"). You can also access this functionality through the compile module, specifically the compile:file/{1,2} functions.
For example, suppose we have a file mymod.erl:
-module(mymod).
-export([myfun/0]).
myfun() -> io:format("Hello Joe~n").
Now, from the Erlang shell (or some other module!):
1> compile:file("mymod.erl").
{ok,mymod}
2> mymod:myfun().
Hello Joe
See Erldocs on the compile module for more information.
You can do a great deal with the Erlang compiler in runtime. For example, you can dynamically generate code for a module (use erl_syntax!) and then compile it without even writing it to a file using compile:forms/{1,2}.
(Insert standard speech on great power and great responsibility.)
Will you still be able to hot swap code?
Yes.
Is it the regular use-case to handle code?
No. Normally Erlang code is compiled ahead of time into BEAM bytecode. Depending on whether Erlang was started in embedded or interactive mode, the modules are either loaded on startup, or dynamically as they are referenced. If you are building a release, you basically have to compile ahead of time.
What benefits does the compiler give you in the end then?
Well, for one thing, we can build compact releases without unnecessary components like the compiler. Of course, we also get all the traditional benefits of ahead-of-time compilation, particularly that of not having to waste time compiling all the time.
To sum it up, unless you fully understand the implications and have a very good reason not to compile your code ahead of time, please follow the standard practices.
The Erlang VM can only run compiled code! If you want to interpret Erlang code then you need an interpreter. The module erl_eval implements an Erlang interpreter and is part of the standard Erlang/OTP distribution. It is used by the Erlang shell to interpret the expressions entered.
All code handling in the Erlang VM, whether compiling, loading or updating, is done at the module level so it is impossible to compile or load a just one function. The Erlang compiler is written in Erlang and always available and can compile to either a file or a binary which can be immediately loaded into the system. As #MartinTörnwall has pointed out compiling a module from the shell using c(module) is in essence compiling on the fly.
So there would be no problems in automatically compiling code on the fly when it is used, at the module level. It is just that the current system is not designed to work that way and by default when it tries to load a module it only looks for the pre-compiled object file, the .beam file.
Erlang has an interpreter escript. Entire Erlang archive can be written in script. Almost all features are available.
By default, the script will be interpreted. You can force it to be compiled by including the -mode(compile). in the script.
Though it depends on the way you design your application, regular practice is to have .erl files which are compiled and run than having escript files.
So now you have many options.
Compile .erl file to .beam using c(my_module) this auto loads the .beam file. So the existing VM can run it on the fly. On in code you can use compile module functions like file, purge and load to load and run it on the fly.
Compile and keep the .erl files using erlc, erl -make, rebar, etc (Erlang has rich support) and then run it. You can build archives, boot scripts, rel etc to manage running and release of the Erlang software. This usually is the practice for production.
Use escript and run everything in interpreted mode.
Use escript and give -mode(compile) option to tell Erlang VM that at runtime (when starting to run escript) compile the code and run the compiled code (in memory)
Is there any pros or cons with doing this?
Compiled code is faster than interpreted code. I dont see any other right now in Erlang as pretty much everything is supported in both. Erlang even supports combination (Calling compiled code from interpreted code)
Will you still be able to hot swap code?
Yes in all cases. Your code also should be able to handle this.
Is it the regular use-case to handle code?
Option 2 for production. Option for 1 for learning / simple development. Option 3 and 4 in need basis for specific requirements (May be one time running).
What benefits does the compiler give you in the end then?
To make it clear, erlc program provides a common way to run all compilers in the Erlang system and compile module gives an interface to Erlang compilers. Compiler gives intermediate binary .beam file which helps in running Erlang code faster than interpreted counterpart. They also catch syntax errors (compilation errors).

Compile your lua files

How can I build and compile my own Lua files on Windows? And make them executable.
I am reading Beginning Lua programming, and I have Windows 7 and MacOS Lion both installed. I am having the hard time to follow the instructions. They do not work for me.
On MacOS I open the terminal and put these in:
export LUA_DIR=/usr/local/lib/lua/5.1
mkdir -p /usr/local/lib/lua/5.1 (it tells me, mkdir: illegal option) and I can not follow from here
SET LUA_DIR=”c:\program files\lua\5.1”
As for Windows I do this according to the book.
This what I see in my shell c:\Users\bd>
mkdir "c:\program files\utility" and it tells me access is denied
I have tried to right click on this folder and check off read only, but it does not work.
Any clues would be appreciated, this part has been really confusing for me.
To package your Lua files into an executable on Windows you have several options. There is srlua, there is wxLuaFreeze from wxLua (available as a binary for Windows), and there are more options in this SO answer.
Essentially, the main two options are: (1) append your Lua code to a precompiled exe file, such that it will be loaded and executed when that exe file is run, and (2) convert your Lua code into real executable by compiling it to bytecode, then to C, and then to your target platform.
As to your MacOS issue, mkdir -p means that mkdir is asked to create intermediate directories (for example, you asked to create /a/b/c, it will also create /a/b if those don't exist). As you don't say which version of MacOS you run, it's difficult to provide more detailed answer.
For now the standard distribution of Lua does not compile a script to native executable code; it execute your scripts by first compiling it to bytecode, then by interpreting the bytecode with a reasonnably fast static interpret (this also means that it is easily portable across native or virtual systems, and very resistant to attacks (that could be targetting bugs in the native compiler itself).
Also Lua still does not feature a runtime JIT compiler like Java and .Net: Lua still does not features a VM to produce a safe sandbox.
There exists Lua packages that convert your bytecode (or directly a source script) to a C source that can be used to convert a Lua library into native mode via the same C compiler used to compile the Lua engine itself (this is how the builtin libraries are produced, though they are slightly optimized manually in some time-critical parts).
However it is possible to compile Lua to a javascript source, and run it with fast performance using Javascript, because today's Javascript interprets do have good performance with their implemented VM featuring a JIT compiler for their own bytecodes.
It is also possible by converting it the Lua bytecode to a .Net or Java source that can then be executed directly from Lua (for that you need a version of Lua that has been ported to .Net or Java or Javascript, something that is not so complicate than developing in C/C++ directly a VM with a JIT compiler (a moderately complex part is the bytecode verifier, but the really complex part is the memory manager its garbage collector and its sandbox so that your Lua script will be fully isolated from the Lua engine itself for itw own memory, but the most complex part if the runtime optimizer and collection of profiling statistics: this has been done in the modern VMs for Java, .Net, Javascript, PHP/Zend, Python, Perl...).
I dont know which other language VM would offer the best performance to port Lua and implement on it a compiler to their own bytecode running at near native speed in their VM. But my own small experience with programs (in a much simpler language) self-generating a bytecode that they can run themselves, has always shown me Java winning in performance over .Net and Javascript. This is most probably because Java features an profiling-based dynamic code optimizer
(On the opposite the .Net optimizer runs only once during program installation, using some profiling data collected during the installation of the .Net VM itself, or at first instanciation of the script, without really knowing any profiling data collected during execution of the compiled program itself, and based on some cheked assumptions about the platform capabilities).
I also don't if would be faster in PHP, Python or Perl; the comparison with newer Javascript engines was never attempted though. Porting/compiling a Lua program to Javascript is relatively easy because it implements closures relatively easy for the resolution of linkages. Then the generated Javascript will compile to native code with the excellent Javascript's JIT compilers we have today (and never cease to improve in performance, so much that I've seen various appliactions running now faster in Javascript than before when they were written in C++ or plain C; as well the memory footprint has largely been reduced, we no longer have memory leaks, and even if there's a garbage collector, today's Javascript VM have a very efficient one, which is even better than the GC implemented in the native Lua).
But Lua remains useful as it is easy to secure and sandbox and offers various security benefits (but there are security issues in Lua as well for some kinds of applications, where Javascript offers some solutions, notably for side-channel attacks based on variation of time of execution; but these side-channel attacks are very hard to solve and can affect any system, any program, any programming language, and this starts becoming a critical issue because they are now more esily exploitable; the reason of that comes from hardware optimizations that we depend more and more today when we want to maximize the performances). And with Lua you may be more immune to these problems that a sandboxing sofware environment cannot solve alone.
Probably later we'll see a true VM implementation of Lua with a JIT and self-generating code and the possibility to instanciate new sandboxed VMs to run their self-generated code. It will take more time to generate an EXE file for distribution; notably because it generally requires adding also an installer and a distribution manager.
So for now we could imagine distributing Lua applications compiled to the bytecode of another JIT-capable VM: this generated bytecode would be faster than the Lua bytecode, and would then be extremely complex to reverse-engineer to the semantics of Lua because it would require two separate reverse engineering first from the bytecode of the other VM to the bytecode of Lua, both bytecodes loosing some easiy inferable rules and options tested and foll, and then again to sme Lua source
For the OSX terminal issue:
This command should work
export LUA_DIR=/usr/local/lib/lua/5.1
This command will probably give you permission problems:
mkdir -p /usr/local/lib/lua/5.1
You may try this to solve that. You will be prompted for your password:
sudo mkdir -p /usr/local/lib/lua/5.1
This command has nothing to do with OSX and will not work. This is a windows command:
SET LUA_DIR=”c:\program files\lua\5.1”
You have a permissions problem with Windows- try creating your cmd or PowerShell in Administrator mode. C:\Program Files is a protected directory that a regular user account doesn't have permission to write to.
As for the OS X issue, check out the mkdir OS X manual page to make sure you have the command correct.
So, if I understood your question correctly, you are trying to build Lua on Windows.
This is of course possible, but not easy for beginners. I would highly recommend you to use a binary distribution, which is much easier to install, unless you have special requirements.
Here are several Windows distributions :
Lua Binaries (Lua 5.1 and 5.2)
LuaForWindows (Lua 5.1)
LuaDist (Lua 5.2)

Resources