Permalink
Browse files

Pass pointer to result struct uarray in _image and _inst_name

  • Loading branch information...
1 parent f564834 commit 73238051848e4882085cf00b15658daf4f356624 @nickg committed Apr 13, 2012
Showing with 32 additions and 23 deletions.
  1. +22 −9 src/cgen.c
  2. +10 −14 src/rt/rtkern.c
View
@@ -911,8 +911,15 @@ static LLVMValueRef cgen_instance_name(tree_t ref)
tree_t decl = tree_ref(ref);
LLVMValueRef signal = tree_attr_ptr(decl, sig_struct_i);
- LLVMValueRef cast = llvm_void_cast(signal);
- return LLVMBuildCall(builder, llvm_fn("_inst_name"), &cast, 1, "");
+ LLVMValueRef res = LLVMBuildAlloca(builder,
+ llvm_uarray_type(LLVMInt8Type()),
+ "inst_name");
+ LLVMValueRef args[] = {
+ llvm_void_cast(signal),
+ res
+ };
+ LLVMBuildCall(builder, llvm_fn("_inst_name"), args, ARRAY_LEN(args), "");
+ return LLVMBuildLoad(builder, res, "");
}
static LLVMValueRef cgen_fcall(tree_t t, struct cgen_ctx *ctx)
@@ -1001,14 +1008,18 @@ static LLVMValueRef cgen_fcall(tree_t t, struct cgen_ctx *ctx)
else if (icmp(builtin, "image")) {
bool is_signed = (type_kind(type_base_recur(arg_type)) == T_INTEGER);
LLVMOpcode op = (is_signed ? LLVMSExt : LLVMZExt);
+ LLVMValueRef res = LLVMBuildAlloca(builder,
+ llvm_uarray_type(LLVMInt8Type()),
+ "image");
LLVMValueRef iargs[] = {
LLVMBuildCast(builder, op, args[0], LLVMInt64Type(), ""),
llvm_int32(tree_index(tree_param(t, 0).value)),
LLVMBuildPointerCast(builder, mod_name,
- LLVMPointerType(LLVMInt8Type(), 0), "")
+ LLVMPointerType(LLVMInt8Type(), 0), ""),
+ res
};
- return LLVMBuildCall(builder, llvm_fn("_image"),
- iargs, ARRAY_LEN(iargs), "");
+ LLVMBuildCall(builder, llvm_fn("_image"), iargs, ARRAY_LEN(iargs), "");
+ return LLVMBuildLoad(builder, res, "");
}
else if (icmp(builtin, "succ")) {
return LLVMBuildAdd(builder, args[0],
@@ -2850,10 +2861,11 @@ static void cgen_support_fns(void)
LLVMTypeRef _image_args[] = {
LLVMInt64Type(),
LLVMInt32Type(),
- LLVMPointerType(LLVMInt8Type(), 0)
+ LLVMPointerType(LLVMInt8Type(), 0),
+ LLVMPointerType(llvm_uarray_type(LLVMInt8Type()), 0)
};
LLVMAddFunction(module, "_image",
- LLVMFunctionType(llvm_uarray_type(LLVMInt8Type()),
+ LLVMFunctionType(LLVMVoidType(),
_image_args,
ARRAY_LEN(_image_args),
false));
@@ -2888,10 +2900,11 @@ static void cgen_support_fns(void)
false));
LLVMTypeRef _inst_name_args[] = {
- llvm_void_ptr()
+ llvm_void_ptr(),
+ LLVMPointerType(llvm_uarray_type(LLVMInt8Type()), 0)
};
LLVMAddFunction(module, "_inst_name",
- LLVMFunctionType(llvm_uarray_type(LLVMInt8Type()),
+ LLVMFunctionType(LLVMVoidType(),
_inst_name_args,
ARRAY_LEN(_inst_name_args),
false));
View
@@ -393,7 +393,7 @@ void _array_copy(void *dst, const void *src,
memcpy((char *)dst + (off * sz), src, n * sz);
}
-struct uarray _image(int64_t val, int32_t where, const char *module)
+void _image(int64_t val, int32_t where, const char *module, struct uarray *u)
{
tree_t t = rt_recall_tree(module, where);
@@ -419,12 +419,10 @@ struct uarray _image(int64_t val, int32_t where, const char *module)
fatal_at(tree_loc(t), "cannot use 'IMAGE with this type");
}
- struct uarray u;
- u.ptr = buf;
- u.left = 0;
- u.right = len - 1;
- u.dir = RANGE_TO;
- return u;
+ u->ptr = buf;
+ u->left = 0;
+ u->right = len - 1;
+ u->dir = RANGE_TO;
}
void _debug_out(int32_t val)
@@ -440,7 +438,7 @@ int32_t _iexp(int32_t n, int32_t v)
return (int32_t)pow(n, v);
}
-struct uarray _inst_name(void *_sig)
+void _inst_name(void *_sig, struct uarray *u)
{
struct signal *sig = _sig;
@@ -450,12 +448,10 @@ struct uarray _inst_name(void *_sig)
char *buf = rt_tmp_alloc(len);
strncpy(buf, str, len);
- struct uarray u;
- u.ptr = buf;
- u.left = 0;
- u.right = len - 1;
- u.dir = RANGE_TO;
- return u;
+ u->ptr = buf;
+ u->left = 0;
+ u->right = len - 1;
+ u->dir = RANGE_TO;
}
////////////////////////////////////////////////////////////////////////////////

0 comments on commit 7323805

Please sign in to comment.