Skip to content

Commit

Permalink
Use type_is_array in a few places
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Mar 26, 2012
1 parent dea35a3 commit 6e42091
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
28 changes: 9 additions & 19 deletions src/cgen.c
Expand Up @@ -383,8 +383,6 @@ static LLVMValueRef cgen_array_len(type_t type, LLVMValueRef data)

static LLVMValueRef cgen_tmp_var(tree_t d, struct cgen_ctx *ctx)
{
LLVMValueRef var = NULL;

type_t type = tree_type(d);

// Handle case where array size is not known until run time
Expand Down Expand Up @@ -430,16 +428,13 @@ static LLVMValueRef cgen_tmp_var(tree_t d, struct cgen_ctx *ctx)

LLVMValueRef ptr = LLVMBuildPointerCast(builder, buf, ptr_type, "");

var = cgen_array_meta(type, left, right, kind_ll, ptr);
return cgen_array_meta(type, left, right, kind_ll, ptr);
}

if (var == NULL) {
else {
const char *name =
(tree_kind(d) == T_VAR_DECL ? istr(tree_ident(d)) : "");
var = LLVMBuildAlloca(builder, llvm_type(tree_type(d)), name);
return LLVMBuildAlloca(builder, llvm_type(tree_type(d)), name);
}

return var;
}

static LLVMValueRef cgen_local_var(tree_t d, struct cgen_ctx *ctx)
Expand Down Expand Up @@ -549,10 +544,9 @@ static void cgen_prototype(tree_t t, LLVMTypeRef *args, bool procedure)
case C_CONSTANT:
{
type_t type = tree_type(p);
type_kind_t type_k = type_kind(type);
port_mode_t mode = tree_port_mode(p);
bool need_ptr = ((mode == PORT_OUT || mode == PORT_INOUT)
&& !(type_k == T_UARRAY || type_k == T_CARRAY));
&& !type_is_array(type));
if (need_ptr)
args[i] = LLVMPointerType(llvm_type(type), 0);
else
Expand Down Expand Up @@ -750,7 +744,7 @@ static void cgen_call_args(tree_t t, LLVMValueRef *args, struct cgen_ctx *ctx)
if (builtin == NULL) {
port_mode_t mode = tree_port_mode(tree_port(decl, i));
bool need_ptr = ((mode == PORT_OUT || mode == PORT_INOUT)
&& !(type_k == T_UARRAY || type_k == T_CARRAY));
&& !type_is_array(type));
if (need_ptr)
args[i] = cgen_get_var(tree_ref(p.value), ctx);
}
Expand Down Expand Up @@ -1496,13 +1490,10 @@ static LLVMValueRef cgen_concat(tree_t t, struct cgen_ctx *ctx)
cgen_expr(args[1], ctx)
};

type_kind_t lkind = type_kind(tree_type(args[0]));
type_kind_t rkind = type_kind(tree_type(args[1]));

LLVMValueRef off = NULL;
type_t type = tree_type(t);

if (lkind == T_CARRAY || lkind == T_UARRAY) {
if (type_is_array(tree_type(args[0]))) {
cgen_array_copy(tree_type(args[0]), type, args_ll[0], var, NULL);
off = cgen_array_len(tree_type(args[0]), args_ll[0]);
}
Expand All @@ -1515,7 +1506,7 @@ static LLVMValueRef cgen_concat(tree_t t, struct cgen_ctx *ctx)
off = llvm_int32(1);
}

if (rkind == T_CARRAY || rkind == T_UARRAY)
if (type_is_array(tree_type(args[1])))
cgen_array_copy(tree_type(args[1]), type, args_ll[1], var, off);
else {
LLVMValueRef data = cgen_array_data_ptr(type, var);
Expand Down Expand Up @@ -1619,7 +1610,7 @@ static void cgen_var_assign(tree_t t, struct cgen_ctx *ctx)
LLVMValueRef lhs = cgen_get_var(tree_ref(target), ctx);

type_t ty = tree_type(target);
if (type_kind(ty) == T_CARRAY || type_kind(ty) == T_UARRAY)
if (type_is_array(ty))
cgen_array_copy(value_type, ty, rhs, lhs, NULL);
else
LLVMBuildStore(builder, rhs, lhs);
Expand Down Expand Up @@ -1855,8 +1846,7 @@ static void cgen_return(tree_t t, struct cgen_ctx *ctx)

// If we are returning an array then wrap it with metadata
type_t stype = tree_type(tree_value(t));
type_kind_t kind = type_kind(stype);
if (kind == T_CARRAY || kind == T_UARRAY) {
if (type_is_array(stype)) {
// Need to make a copy of this array as it is currently
// on the stack

Expand Down
3 changes: 1 addition & 2 deletions src/sem.c
Expand Up @@ -379,8 +379,7 @@ static bool type_set_uniq_composite(type_t *pt)
while (type_kind(type) == T_SUBTYPE)
type = type_base(type);

type_kind_t kind = type_kind(type);
bool comp = (kind == T_CARRAY || kind == T_UARRAY);
bool comp = type_is_array(type);
if (comp) {
if (*pt != NULL)
return false;
Expand Down

0 comments on commit 6e42091

Please sign in to comment.