remove the last remaining C++ code from libjit.so so that
it is now a pure C library.
+ * include/jit/jit-insn.h, include/jit/jit-opcode.h,
+ include/jit/jit-plus.h, jit/jit-insn.c, jit/jit-interp.c,
+ jit/jit-opcode.c, jitplus/jit-plus-function.cpp:
+ add the "jit_insn_alloca" instruction.
+
2004-05-20 Rhys Weatherley <rweather@southern-storm.com.au>
* include/jit/jit-value.h, jit/jit-insn.c, jit/jit-value.c:
int jit_insn_memset
(jit_function_t func, jit_value_t dest,
jit_value_t value, jit_value_t size) JIT_NOTHROW;
+jit_value_t jit_insn_alloca
+ (jit_function_t func, jit_value_t size) JIT_NOTHROW;
int jit_insn_move_blocks
(jit_function_t func, jit_label_t from_label, jit_label_t to_label);
#define JIT_OP_MEMMOVE 0x0196
#define JIT_OP_MEMSET 0x0197
+/*
+ * Allocate memory from the stack.
+ */
+#define JIT_OP_ALLOCA 0x0198
+
/*
* The number of opcodes in the above list.
*/
-#define JIT_OP_NUM_OPCODES 0x0198
+#define JIT_OP_NUM_OPCODES 0x0199
/*
* Opcode information.
(const jit_value& dest, const jit_value& src, const jit_value& size);
void insn_memset
(const jit_value& dest, const jit_value& value, const jit_value& size);
+ jit_value insn_alloca(const jit_value& size);
private:
jit_function_t func;
return apply_ternary(func, JIT_OP_MEMSET, dest, value, size);
}
+/*@
+ * @deftypefun jit_value_t jit_insn_alloca (jit_function_t func, jit_value_t size)
+ * Allocate @code{size} bytes of memory from the stack.
+ * @end deftypefun
+@*/
+jit_value_t jit_insn_alloca(jit_function_t func, jit_value_t size)
+{
+ /* Round the size to the best alignment boundary on this platform */
+ size = jit_insn_convert(func, size, jit_type_nuint, 0);
+ size = jit_insn_add
+ (func, size, jit_value_create_nint_constant
+ (func, jit_type_nuint, JIT_BEST_ALIGNMENT - 1));
+ size = jit_insn_and
+ (func, size, jit_value_create_nint_constant
+ (func, jit_type_nuint, ~((jit_nint)(JIT_BEST_ALIGNMENT - 1))));
+
+ /* Allocate "size" bytes of memory from the stack */
+ return apply_unary(func, JIT_OP_ALLOCA, size, jit_type_void_ptr);
+}
+
/*@
* @deftypefun int jit_insn_move_blocks (jit_function_t func, jit_label_t from_label, jit_label_t to_label)
* Move all of the blocks between @code{from_label} (inclusive) and
}
VMBREAK;
+ /******************************************************************
+ * Allocate memory from the stack.
+ ******************************************************************/
+
+ VMCASE(JIT_OP_ALLOCA):
+ {
+ /* Allocate memory from the stack */
+ VM_STK_PTR0 = (void *)alloca(VM_STK_NUINT0);
+ VM_MODIFY_PC_AND_STACK(1, 0);
+
+ /* We need to reset the "setjmp" point for this function
+ because the saved stack pointer is no longer the same.
+ If we don't do this, then an exception throw will pop
+ the alloca'ed memory, causing dangling pointer problems */
+ if(jbuf)
+ {
+ if(setjmp(jbuf->buf))
+ {
+ exception_object = jit_exception_get_last_and_clear();
+ goto handle_exception;
+ }
+ }
+ }
+ VMBREAK;
+
/******************************************************************
* Argument variable access opcodes.
******************************************************************/
{"memcpy", F_(PTR, PTR, PTR)},
{"memmove", F_(PTR, PTR, PTR)},
{"memset", F_(PTR, INT, PTR)},
+
+ /*
+ * Allocate memory from the stack.
+ */
+ {"alloca", F_(PTR, PTR, EMPTY)},
+
};
#if defined(JIT_BACKEND_INTERP)
* @deftypemethodx jit_function void insn_memcpy ({const jit_value&} dest, {const jit_value&} src, {const jit_value&} size)
* @deftypemethodx void insn_memmove ({const jit_value&} dest, {const jit_value&} src, {const jit_value&} size)
* @deftypemethodx void jit_insn_memset ({const jit_value&} dest, {const jit_value&} value, {const jit_value&} size)
+ * @deftypemethodx jit_value jit_insn_alloca ({const jit_value&} size)
* Create instructions of various kinds. @xref{Instructions}, for more
* information on the individual instructions and their arguments.
* @end deftypemethod
}
}
+jit_value jit_function::insn_alloca(const jit_value& size)
+{
+ value_wrap(jit_insn_alloca(func, size.raw()));
+}
+
void jit_function::register_on_demand()
{
jit_function_set_on_demand_compiler(func, on_demand_compiler);