All pastes #122769 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-08-08 22:03 UTC
rendered paste body
#include <stdio.h>
#include <jit/jit.h>
int main(int argc, char **argv){
        jit_context_t context;
        jit_type_t signature;
        jit_function_t function;
        jit_value_t temp1;
        jit_int result;

        /* Create a context to hold the JIT's primary state */
        context = jit_context_create();

        /* Lock the context while we build and compile the function */
        jit_context_build_start(context);

        /* Build the function signature */
        signature = jit_type_create_signature(jit_abi_cdecl, jit_type_nint, 0, 0, 1);

        /* Create the function object */
        function = jit_function_create(context, signature);

        temp1 = jit_value_create_nint_constant(function, jit_type_nint, (jit_nint) 1);
        jit_insn_return (function, temp1);

        /* Unlock the context */
        jit_context_build_end(context);

        /* Execute the function and print the result */
        jit_function_apply(function, 0, &result);
        printf("result = %d\n", (int)result);

        /* Clean up */
        jit_context_destroy(context);

        /* Finished */
        return 0;
}