mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Further bitstruct cast fixes. Updated code.
This commit is contained in:
@@ -137,5 +137,5 @@ fn void main()
|
||||
};
|
||||
dynamic_arena.reset();
|
||||
}
|
||||
dynamic_arena.destroy();
|
||||
dynamic_arena.free();
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ typedef enum
|
||||
CAST_ANYPTR,
|
||||
CAST_APTSA,
|
||||
CAST_ARRVEC,
|
||||
CAST_ARRBS,
|
||||
CAST_BOOLBOOL,
|
||||
CAST_BOOLFP,
|
||||
CAST_BOOLINT,
|
||||
@@ -103,6 +104,7 @@ typedef enum
|
||||
CAST_INTBOOL,
|
||||
CAST_INTENUM,
|
||||
CAST_INTFP,
|
||||
CAST_INTBS,
|
||||
CAST_NUMVEC,
|
||||
CAST_PTRANY,
|
||||
CAST_PTRBOOL,
|
||||
|
||||
@@ -342,6 +342,8 @@ static inline bool expr_cast_is_constant_eval(Expr *expr, ConstantEvalKind eval_
|
||||
return false;
|
||||
case CAST_BSINT:
|
||||
case CAST_BSARRY:
|
||||
case CAST_INTBS:
|
||||
case CAST_ARRBS:
|
||||
return true;
|
||||
case CAST_INTENUM:
|
||||
case CAST_ANYPTR:
|
||||
|
||||
@@ -1347,12 +1347,14 @@ void llvm_emit_cast(GenContext *c, CastKind cast_kind, Expr *expr, BEValue *valu
|
||||
llvm_value_aggregate_two(c, value, to_type, value->value, typeid.value);
|
||||
return;
|
||||
}
|
||||
case CAST_ARRBS:
|
||||
case CAST_BSARRY:
|
||||
llvm_value_addr(c, value);
|
||||
llvm_value_bitcast(c, value, to_type);
|
||||
llvm_value_rvalue(c, value);
|
||||
return;
|
||||
case CAST_BSINT:
|
||||
case CAST_INTBS:
|
||||
llvm_value_addr(c, value);
|
||||
llvm_value_bitcast(c, value, to_type);
|
||||
llvm_value_rvalue(c, value);
|
||||
|
||||
@@ -1337,6 +1337,10 @@ RETRY:
|
||||
case TYPE_ENUM:
|
||||
if (is_explicit) goto CAST;
|
||||
goto REQUIRE_CAST;
|
||||
case TYPE_BITSTRUCT:
|
||||
if (type_flatten(to->decl->bitstruct.base_type->type) != type_flatten(from)) break;
|
||||
if (is_explicit) goto CAST;
|
||||
goto REQUIRE_CAST;
|
||||
case ALL_INTS:
|
||||
{
|
||||
// All explicit casts work.
|
||||
@@ -1850,6 +1854,7 @@ static bool cast_inner(Expr *expr, Type *from_type, Type *to, Type *to_type)
|
||||
if (to == type_bool) return integer_to_bool(expr, to_type);
|
||||
if (to->type_kind == TYPE_POINTER) return integer_to_pointer(expr, to_type);
|
||||
if (to->type_kind == TYPE_ENUM) return integer_to_enum(expr, to, to_type);
|
||||
if (to->type_kind == TYPE_BITSTRUCT) return insert_cast(expr, CAST_INTBS, to_type);
|
||||
if (type_kind_is_any_vector(to->type_kind)) return integer_expand_to_vector_conversion(expr, to, to_type);
|
||||
break;
|
||||
case ALL_UNSIGNED_INTS:
|
||||
@@ -1859,6 +1864,7 @@ static bool cast_inner(Expr *expr, Type *from_type, Type *to, Type *to_type)
|
||||
if (to->type_kind == TYPE_POINTER) return integer_to_pointer(expr, to_type);
|
||||
if (to->type_kind == TYPE_ENUM) return integer_to_enum(expr, to, to_type);
|
||||
if (type_kind_is_any_vector(to->type_kind)) return integer_expand_to_vector_conversion(expr, to, to_type);
|
||||
if (to->type_kind == TYPE_BITSTRUCT) return insert_cast(expr, CAST_INTBS, to_type);
|
||||
break;
|
||||
case ALL_FLOATS:
|
||||
if (type_is_integer(to)) return float_to_integer(expr, to, to_type);
|
||||
@@ -1894,11 +1900,7 @@ static bool cast_inner(Expr *expr, Type *from_type, Type *to, Type *to_type)
|
||||
return false;
|
||||
case TYPE_ARRAY:
|
||||
if (to->type_kind == TYPE_VECTOR) return array_to_vector(expr, to_type);
|
||||
if (to->type_kind == TYPE_BITSTRUCT)
|
||||
{
|
||||
expr->type = to_type;
|
||||
return true;
|
||||
}
|
||||
if (to->type_kind == TYPE_BITSTRUCT) return insert_cast(expr, CAST_ARRBS, to_type);
|
||||
FALLTHROUGH;
|
||||
case TYPE_STRUCT:
|
||||
case TYPE_UNION:
|
||||
|
||||
Reference in New Issue
Block a user