コード例 #1
0
ファイル: ludicrous_ext.c プロジェクト: cout/ludicrous
/* Emit jit instructions to set the current sourceline and sourcefile.
 */
static VALUE function_set_ruby_source(VALUE self, VALUE node_v)
{
#ifndef RUBY_VM
  NODE * n;
  jit_function_t function;

  Data_Get_Struct(self, struct _jit_function, function);
  Data_Get_Struct(node_v, NODE, n); // TODO: type check

  VALUE value_objects = (VALUE)jit_function_get_meta(function, RJT_VALUE_OBJECTS);

  jit_constant_t c;

  c.type = jit_type_int;
  c.un.int_value = nd_line(n);
  jit_value_t line = jit_value_create_constant(function, &c);

  c.type = jit_type_void_ptr;
  c.un.ptr_value = n->nd_file;
  jit_value_t file = jit_value_create_constant(function, &c);

  c.type = jit_type_void_ptr;
  c.un.ptr_value = n;
  jit_value_t node = jit_value_create_constant(function, &c);

  c.type = jit_type_void_ptr;
  c.un.ptr_value = &ruby_sourceline;
  jit_value_t ruby_sourceline_ptr = jit_value_create_constant(function, &c);

  c.type = jit_type_void_ptr;
  c.un.ptr_value = &ruby_sourcefile;
  jit_value_t ruby_sourcefile_ptr = jit_value_create_constant(function, &c);

  c.type = jit_type_void_ptr;
  c.un.ptr_value = &ruby_current_node;
  jit_value_t ruby_current_node_ptr = jit_value_create_constant(function, &c);

  jit_insn_store_relative(function, ruby_sourceline_ptr, 0, line);
  jit_insn_store_relative(function, ruby_sourcefile_ptr, 0, file);
  jit_insn_store_relative(function, ruby_current_node_ptr, 0, node);

  rb_ary_push(value_objects, node_v);

#else
  /* TODO: Not sure what to do on 1.9 yet */
#endif

  return Qnil;
}
コード例 #2
0
ファイル: bf-jit.c プロジェクト: sankha93/bf-jit
void emitDecrement(jit_function_t function, jit_value_t ptr, ops *unit) {
    jit_value_t tmp = jit_insn_load_relative(function, ptr, 0, jit_type_ubyte);
    jit_value_t numbyte = jit_value_create_nint_constant(function, jit_type_ubyte, unit->count);
    tmp = jit_insn_sub(function, tmp, numbyte);
    tmp = jit_insn_convert(function, tmp, jit_type_ubyte, 0);
    jit_insn_store_relative(function, ptr, 0, tmp);
}
コード例 #3
0
void jit_function::insn_store_relative
	(const jit_value& dest, jit_nint offset, const jit_value& value)
{
	if(!jit_insn_store_relative(func, dest.raw(), offset, value.raw()))
	{
		out_of_memory();
	}
}
コード例 #4
0
ファイル: ludicrous_ext.c プロジェクト: cout/ludicrous
static VALUE function_set_ruby_struct_member(
    VALUE self, VALUE struct_name, VALUE member_name, VALUE ptr_v, VALUE value_v)
{
  jit_function_t function;
  jit_value_t ptr = get_value(ptr_v, "ptr");
  jit_value_t value = get_value(value_v, "value");

  struct Member_Info * member_info = get_member_info(
      struct_name,
      member_name);

  Data_Get_Struct(self, struct _jit_function, function);

  jit_insn_store_relative(
      function, ptr, member_info->offset, value);

  return Qnil;
}
コード例 #5
0
ファイル: bf-jit.c プロジェクト: sankha93/bf-jit
jit_function_t bf_compile(jit_context_t cx, FILE *fp) {
    jit_type_t params[1], putchar_params[1], signature, putchar_sig, getchar_sig;
    jit_value_t ptr, uptr, ubyte, tmp;
    bf_loop_t loop = NULL;

    ubyte_ptr = jit_type_create_pointer(jit_type_ubyte, 1);
    params[0] = ubyte_ptr;
    putchar_params[0] = jit_type_ubyte;
    signature = jit_type_create_signature(jit_abi_cdecl, jit_type_void, params, 1, 1);
    putchar_sig = jit_type_create_signature(jit_abi_cdecl, jit_type_ubyte, putchar_params, 1, 1);
    getchar_sig = jit_type_create_signature(jit_abi_cdecl, jit_type_ubyte, NULL, 0, 1);
    jit_function_t function = jit_function_create(cx, signature);
    ptr = jit_value_get_param(function, 0);
    uptr = jit_value_create_nint_constant(function, ubyte_ptr, 1);
    ubyte = jit_value_create_nint_constant(function, jit_type_ubyte, 1);

    ops *unit = (ops*)malloc(sizeof(ops));
    unit->count = 0;
    int first = 1;

    while(!feof(fp)) {
        char c = fgetc(fp);
        if (first) {
            unit->token = c;
            first = 0;
        }
        switch(c) {
            case '>':
                OPTIMIZE_TOKEN('>')
            case '<':
                OPTIMIZE_TOKEN('<')
            case '+':
                OPTIMIZE_TOKEN('+')
            case '-':
                OPTIMIZE_TOKEN('-')
            case '.':
                emitOpcodes(function, ptr, unit);
                unit->token = '.';
                tmp = jit_insn_load_relative(function, ptr, 0, jit_type_ubyte);
                jit_insn_call_native(function, "putchar", putchar, putchar_sig, &tmp, 1, JIT_CALL_NOTHROW);
                break;
            case ',':
                emitOpcodes(function, ptr, unit);
                unit->token = ',';
                jit_insn_call_native(function, "getchar", getchar, getchar_sig, NULL, 0, JIT_CALL_NOTHROW);
                jit_insn_store_relative(function, ptr, 0, tmp);
                break;
            case '[':
                emitOpcodes(function, ptr, unit);
                unit->token = '[';
                loop_start(function, &loop);
                tmp = jit_insn_load_relative(function, ptr, 0, jit_type_ubyte);
                jit_insn_branch_if_not(function, tmp, &loop->stop);
                break;
            case ']':
                emitOpcodes(function, ptr, unit);
                unit->token = ']';
                loop_stop(function, &loop);
                break;
        }
    }

    jit_insn_return(function, NULL);
    jit_function_compile(function);

    return function;
}
コード例 #6
0
ファイル: libjitformula.cpp プロジェクト: cpence/aformula
void *LibJITFormula::emit (BinaryExprAST *expr)
{
	// Deal with assign separately, we don't want to compile the LHS
	if (expr->op == "=")
	{
		VariableExprAST *var = dynamic_cast<VariableExprAST *>(expr->LHS);
		if (!var) return NULL;

		jit_value_t val = (jit_value_t)expr->RHS->generate (this);
		if (!val) return NULL;

		// Get a pointer for this variable
		jit_value_t pointer = jit_value_create_nint_constant (function, jit_type_void_ptr,
		                                                      (jit_nint)var->pointer);

		// Emit a store instruction
		jit_insn_store_relative (function, pointer, 0, val);

		// Return value
		return val;
	}

	// Generate both sides
	jit_value_t L = (jit_value_t)expr->LHS->generate (this);
	jit_value_t R = (jit_value_t)expr->RHS->generate (this);
	if (L == NULL || R == NULL) return NULL;

	if (expr->op == "<=")
		return jit_insn_le (function, L, R);
	else if (expr->op == ">=")
		return jit_insn_ge (function, L, R);
	else if (expr->op == "!=")
		return jit_insn_ne (function, L, R);
	else if (expr->op == "==")
		return jit_insn_eq (function, L, R);
	else if (expr->op == "<")
		return jit_insn_lt (function, L, R);
	else if (expr->op == ">")
		return jit_insn_gt (function, L, R);
	else if (expr->op == "+")
		return jit_insn_add (function, L, R);
	else if (expr->op == "-")
		return jit_insn_sub (function, L, R);
	else if (expr->op == "*")
		return jit_insn_mul (function, L, R);
	else if (expr->op == "/")
		return jit_insn_div (function, L, R);
	else if (expr->op == "^")
	{
		// jit_insn_pow seems to give the wrong results?
		jit_type_t params[2];
		params[0] = jit_type_float64;
		params[1] = jit_type_float64;
		jit_type_t signature;
		signature = jit_type_create_signature (jit_abi_cdecl, jit_type_float64,
		                                       params, 2, 1);
		jit_value_t args[2];
		args[0] = L;
		args[1] = R;

		return jit_insn_call_native (function, "pow",
                                 (void *)((double (*)(double, double))pow),
                                 signature, args, 2, 0);
	}
	else
		return NULL;
}