Files
c3c/src/compiler/codegen_internal.h
Christoffer Lerno e293c435af 0.6.0: init_new/init_temp removed. LinkedList API rewritten. List "pop" and "remove" function now return Optionals. RingBuffer API rewritten. Allocator interface changed. Deprecated Allocator, DString and mem functions removed. "identity" functions are now constants for Matrix and Complex numbers. @default implementations for interfaces removed. any* => any, same for interfaces. Emit local/private globals as "private" in LLVM, following C "static". Updated enum syntax. Add support [rgba] properties in vectors. Improved checks of aliased "void". Subarray -> slice. Fix of llvm codegen enum check. Improved alignment handling. Add --output-dir #1155. Removed List/Object append. GenericList renamed AnyList. Remove unused "unwrap". Fixes to cond. Optimize output in dead branches. Better checking of operator methods. Disallow any from implementing dynamic methods. Check for operator mismatch. Remove unnecessary bitfield. Remove numbering in --list* commands Old style enum declaration for params/type, but now the type is optional. Add note on #1086. Allow making distinct types out of "void", "typeid", "anyfault" and faults. Remove system linker build options. "Try" expressions must be simple expressions. Add optimized build to Mac tests. Register int. assert(false) only allowed in unused branches or in tests. Compile time failed asserts is a compile time error. Remove current_block_is_target. Bug when assigning an optional from an optional. Remove unused emit_zstring. Simplify phi code. Remove unnecessary unreachable blocks and remove unnecessary current_block NULL assignments. Proper handling of '.' and Win32 '//server' paths. Add "no discard" to expression blocks with a return value. Detect "unsigned >= 0" as errors. Fix issue with distinct void as a member #1147. Improve callstack debug information #1184. Fix issue with absolute output-dir paths. Lambdas were not type checked thoroughly #1185. Fix compilation warning #1187. Request jump table using @jump for switches. Path normalization - fix possible null terminator out of bounds. Improved error messages on inlined macros.
Upgrade of mingw in CI. Fix problems using reflection on interface types #1203. Improved debug information on defer. $foreach doesn't create an implicit syntactic scope.
Error if `@if` depends on `@if`. Updated Linux stacktrace. Fix of default argument stacktrace. Allow linking libraries directly by file path. Improve inlining warning messages. Added `index_of_char_from`. Compiler crash using enum nameof from different module #1205. Removed unused fields in find_msvc. Use vswhere to find msvc. Update tests for LLVM 19
2024-06-12 10:14:26 +02:00

127 lines
3.1 KiB
C

#include "compiler_internal.h"
enum IntrospectIndex
{
INTROSPECT_INDEX_KIND = 0,
INTROSPECT_INDEX_PARENTOF = 1,
INTROSPECT_INDEX_DTABLE = 2,
INTROSPECT_INDEX_SIZEOF = 3,
INTROSPECT_INDEX_INNER = 4,
INTROSPECT_INDEX_LEN = 5,
INTROSPECT_INDEX_ADDITIONAL = 6,
INTROSPECT_INDEX_TOTAL,
};
bool type_is_homogenous_aggregate(Type *type, Type **base, unsigned *elements);
static inline Type *type_reduced_from_expr(Expr *expr);
static inline bool abi_type_is_type(AbiType type);
static inline bool abi_type_is_valid(AbiType type);
static inline Type *type_lowering(Type *type)
{
while (1)
{
type = type->canonical;
switch (type->type_kind)
{
case TYPE_TYPEDEF:
UNREACHABLE
case TYPE_OPTIONAL:
type = type->optional;
continue;
case TYPE_DISTINCT:
type = type->decl->distinct->type;
continue;
case TYPE_ENUM:
type = type->decl->enums.type_info->type;
continue;
case TYPE_INTERFACE:
return type_any;
case TYPE_ANYFAULT:
case TYPE_TYPEID:
case TYPE_FAULTTYPE:
return type_iptr->canonical;
case TYPE_BITSTRUCT:
type = type->decl->bitstruct.base_type->type;
continue;
case TYPE_WILDCARD:
type = type_void;
break;
case TYPE_POINTER:
{
Type *pointer = type->pointer;
Type *flat = type_lowering(pointer);
if (flat == pointer) return type;
return type_get_ptr(flat);
}
case TYPE_SLICE:
case TYPE_ARRAY:
case TYPE_VECTOR:
case TYPE_FLEXIBLE_ARRAY:
{
Type *arr_type = type->array.base;
Type *flat = type_lowering(arr_type);
if (flat == arr_type) return type;
switch (type->type_kind)
{
case TYPE_SLICE:
return type_get_slice(flat);
case TYPE_ARRAY:
return type_get_array(flat, type->array.len);
case TYPE_VECTOR:
return type_get_vector(flat, type->array.len);
case TYPE_FLEXIBLE_ARRAY:
return type_get_flexible_array(flat);
default:
UNREACHABLE
}
}
default:
return type;
}
}
}
static inline Type *type_reduced_from_expr(Expr *expr)
{
return type_lowering(expr->type);
}
static inline bool abi_type_is_type(AbiType type)
{
return !(type.int_bits_plus_1 & 0x01);
}
static inline bool abi_type_is_valid(AbiType type)
{
return type.int_bits_plus_1 != 0;
}
UNUSED static inline bool abi_type_is_promotable_integer_or_bool(AbiType type)
{
if (abi_type_is_type(type))
{
if (!type_is_integer_or_bool_kind(type.type)) return false;
if (type.type == type_bool) return true;
return type.type->builtin.bitsize < platform_target.width_c_int;
}
// We should only get npot or > big ints here.
assert(!is_power_of_two(type.int_bits_plus_1 - 1) || type.int_bits_plus_1 < platform_target.width_c_int);
return false;
}
static inline bool expr_is_vector_index(Expr *expr)
{
return expr->expr_kind == EXPR_SUBSCRIPT
&& type_lowering(exprtype(expr->subscript_expr.expr))->type_kind == TYPE_VECTOR;
}
const char *codegen_create_asm(Ast *ast);
extern const char *benchmark_fns_var_name;
extern const char *benchmark_names_var_name;
extern const char *test_fns_var_name;
extern const char *test_names_var_name;