Alien-LibJIT

 view release on metacpan or  search on metacpan

libjit/doc/libjit.texi  view on Meta::CPAN

IBM, Intel, and others have done a lot of research into JIT implementation
techniques over the years.  If you are interested in working on the
internals of @code{libjit}, then you may want to make yourself familiar
with the relevant literature (this is by no means a complete list):

@quotation
IBM's Jikes RVM (Research Virtual Machine), @*
@uref{http://www-124.ibm.com/developerworks/oss/jikesrvm/}.

Intel's ORP (Open Runtime Platform), @*
@uref{http://orp.sourceforge.net/}.
@end quotation

@c -----------------------------------------------------------------------

@node Features, Tutorials, Introduction, Top
@chapter Features of libjit
@cindex Features

@itemize
@item
The primary interface is in C, for maximal reusability.  Class
interfaces are available for programmers who prefer C++.

@item
Designed for portability to all major 32-bit and 64-bit platforms.

@item
Simple three-address API for library users, but opaque enough that other
representations can be used inside the library in future without
affecting existing users.

@item
Up-front or on-demand compilation of any function.

@item
In-built support to re-compile functions with greater optimization,
automatically redirecting previous callers to the new version.

@item
Fallback interpreter for running code on platforms that don't
have a native code generator yet.  This reduces the need for
programmers to write their own interpreters for such platforms.

@item
Arithmetic, bitwise, conversion, and comparison operators for 8-bit,
16-bit, 32-bit, or 64-bit integer types; and 32-bit, 64-bit, or longer
floating point types.  Includes overflow detecting arithmetic for
integer types.

@item
Large set of mathematical and trigonometric operations
(sqrt, sin, cos, min, abs, etc) for inlining floating-point library functions.

@item
Simplified type layout and exception handling mechanisms, upon which a
variety of different object models can be built.

@item
Support for nested functions, able to access their parent's local variables
(for implementing Pascal-style languages).
@end itemize

@c -----------------------------------------------------------------------

@node Tutorials, Tutorial 1, Features, Top
@chapter Tutorials in using libjit
@cindex Tutorials

In this chapter, we describe how to use @code{libjit} with a number of
short tutorial exercises.  Full source for these tutorials can be found
in the @code{tutorial} directory of the @code{libjit} source tree.

For simplicity, we will ignore errors such as out of memory conditions,
but a real program would be expected to handle such errors.

@menu
* Tutorial 1::              Tutorial 1 - mul_add
* Tutorial 2::              Tutorial 2 - gcd
* Tutorial 3::              Tutorial 3 - compiling on-demand
* Tutorial 4::              Tutorial 4 - mul_add, C++ version
* Tutorial 5::              Tutorial 5 - gcd, with tail calls
* Dynamic Pascal::          Dynamic Pascal - A full JIT example
@end menu

@c -----------------------------------------------------------------------

@node Tutorial 1, Tutorial 2, Tutorials, Tutorials
@section Tutorial 1 - mul_add
@cindex mul_add tutorial

In the first tutorial, we will build and compile the following function
(the source code can be found in @code{tutorial/t1.c}):

@example
int mul_add(int x, int y, int z)
@{
    return x * y + z;
@}
@end example

@noindent
To use the JIT, we first include the @code{<jit/jit.h>} file:

@example
#include <jit/jit.h>
@end example

All of the header files are placed into the @code{jit} sub-directory,
to separate them out from regular system headers.  When @code{libjit}
is installed, you will typically find these headers in
@code{/usr/local/include/jit} or @code{/usr/include/jit}, depending upon
how your system is configured.  You should also link with the
@code{-ljit} option.

@noindent
Every program that uses @code{libjit} needs to call @code{jit_context_create}:

@example
jit_context_t context;
...



( run in 0.332 second using v1.01-cache-2.11-cpan-e93a5daba3e )