#include #include #include int main(int argc, char** argv){ jit_context_t context; jit_function_t f_main; jit_type_t signature_main; jit_type_t params[1]; jit_value_t one_constant; jit_value_t long_constant; jit_value_t shift_constant; jit_value_t value_to_shift_var; jit_value_t shift_amount_var; jit_value_t escaped_var; jit_value_t addr_var; jit_value_t to_jump_var; jit_value_t result_var; jit_label_t label_end; jit_label_t label_call; int result; /* Initialize the context */ context = jit_context_create(); /* Allocate a new function */ signature_main = jit_type_create_signature(jit_abi_cdecl, jit_type_int, params, 0, 0); f_main = jit_function_create(context, signature_main); /* Initialize the labels */ label_end = jit_label_undefined; label_call = jit_label_undefined; /* Make the variables */ value_to_shift_var = jit_value_create(f_main, jit_type_int); shift_amount_var = jit_value_create(f_main, jit_type_int); escaped_var = jit_value_create(f_main, jit_type_uint); /* Make the constants */ long_constant = jit_value_create_nint_constant(f_main, jit_type_int, 1); shift_constant = jit_value_create_nint_constant(f_main, jit_type_int, 0); one_constant = jit_value_create_nint_constant(f_main, jit_type_uint, 1); /* Store the constants to the variables */ jit_insn_store(f_main, value_to_shift_var, long_constant); jit_insn_store(f_main, shift_amount_var, shift_constant); jit_insn_store(f_main, escaped_var, one_constant); /* Get the address of the escaped variable */ addr_var = jit_insn_address_of(f_main, escaped_var); jit_value_set_addressable(escaped_var); /* Apply the shift operation */ result_var = jit_insn_shl(f_main, value_to_shift_var, shift_amount_var); /* Check the result */ to_jump_var = jit_insn_and(f_main, escaped_var, result_var); jit_insn_branch_if_not(f_main, to_jump_var, &label_call); jit_insn_branch(f_main, &label_end); /* Call a dummy function */ jit_insn_label(f_main, &label_call); jit_insn_store(f_main, escaped_var, one_constant); /* Return */ jit_insn_label(f_main, &label_end); jit_insn_return(f_main, shift_amount_var); /* Compile the function */ // jit_dump_function(stdout, f_main, " "); jit_function_compile(f_main); // jit_dump_function(stdout, f_main, " "); /* Execute the function */ result=0; jit_function_apply(f_main, NULL, &result); printf("Result = %d (should be 0)\n", result); /* Return */ return result; }