aboutsummaryrefslogtreecommitdiff
path: root/src/checker.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-03-31 00:14:49 +0100
committergingerBill <bill@gingerbill.org>2022-03-31 00:14:49 +0100
commit203382461b43db30977c17f51929a565c1f3a229 (patch)
tree132c33b56db7b61e0bada1e151af4b4a0ae55b66 /src/checker.cpp
parent4eb4ae6305720d226f6ccd1ee8d7b18b8436ced0 (diff)
Replace the atomic intrinsics
Matching C11 in style
Diffstat (limited to 'src/checker.cpp')
-rw-r--r--src/checker.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/checker.cpp b/src/checker.cpp
index 53bba654d..0c72a8e14 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -829,15 +829,16 @@ struct GlobalEnumValue {
i64 value;
};
-Slice<Entity *> add_global_enum_type(String const &type_name, GlobalEnumValue *values, isize value_count) {
+Slice<Entity *> add_global_enum_type(String const &type_name, GlobalEnumValue *values, isize value_count, Type **enum_type_ = nullptr) {
Scope *scope = create_scope(nullptr, builtin_pkg->scope);
- Entity *e = alloc_entity_type_name(scope, make_token_ident(type_name), nullptr, EntityState_Resolved);
+ Entity *entity = alloc_entity_type_name(scope, make_token_ident(type_name), nullptr, EntityState_Resolved);
Type *enum_type = alloc_type_enum();
- Type *named_type = alloc_type_named(type_name, enum_type, e);
+ Type *named_type = alloc_type_named(type_name, enum_type, entity);
set_base_type(named_type, enum_type);
enum_type->Enum.base_type = t_int;
enum_type->Enum.scope = scope;
+ entity->type = named_type;
auto fields = array_make<Entity *>(permanent_allocator(), value_count);
for (isize i = 0; i < value_count; i++) {
@@ -858,6 +859,9 @@ Slice<Entity *> add_global_enum_type(String const &type_name, GlobalEnumValue *v
enum_type->Enum.min_value = &enum_type->Enum.fields[enum_type->Enum.min_value_index]->Constant.value;
enum_type->Enum.max_value = &enum_type->Enum.fields[enum_type->Enum.max_value_index]->Constant.value;
+
+ if (enum_type_) *enum_type_ = named_type;
+
return slice_from_array(fields);
}
void add_global_enum_constant(Slice<Entity *> const &fields, char const *name, i64 value) {
@@ -986,6 +990,21 @@ void init_universal(void) {
add_global_enum_constant(fields, "ODIN_ERROR_POS_STYLE", build_context.ODIN_ERROR_POS_STYLE);
}
+ {
+ GlobalEnumValue values[OdinAtomicMemoryOrder_COUNT] = {
+ {"relaxed", OdinAtomicMemoryOrder_relaxed},
+ {"consume", OdinAtomicMemoryOrder_consume},
+ {"acquire", OdinAtomicMemoryOrder_acquire},
+ {"release", OdinAtomicMemoryOrder_release},
+ {"acq_rel", OdinAtomicMemoryOrder_acq_rel},
+ {"seq_cst", OdinAtomicMemoryOrder_seq_cst},
+ };
+
+ add_global_enum_type(str_lit("Atomic_Memory_Order"), values, gb_count_of(values), &t_atomic_memory_order);
+ GB_ASSERT(t_atomic_memory_order->kind == Type_Named);
+ scope_insert(intrinsics_pkg->scope, t_atomic_memory_order->Named.type_name);
+ }
+
add_global_bool_constant("ODIN_DEBUG", bc->ODIN_DEBUG);
add_global_bool_constant("ODIN_DISABLE_ASSERT", bc->ODIN_DISABLE_ASSERT);