From 0c1ce21f7d5f2756bc9e642c17092db9f9f2cf05 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 12 Feb 2016 01:23:06 -0700 Subject: add @compile_var("environ") --- src/codegen.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 4dc5c18557..2579092567 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3500,6 +3500,31 @@ static void define_builtin_types(CodeGen *g) { g->builtin_types.entry_arch_enum = entry; } + + { + TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdEnum); + entry->zero_bits = true; // only allowed at compile time + buf_init_from_str(&entry->name, "@Environ"); + uint32_t field_count = target_environ_count(); + entry->data.enumeration.field_count = field_count; + entry->data.enumeration.fields = allocate(field_count); + for (uint32_t i = 0; i < field_count; i += 1) { + TypeEnumField *type_enum_field = &entry->data.enumeration.fields[i]; + ZigLLVM_EnvironmentType environ_type = get_target_environ(i); + type_enum_field->name = buf_create_from_str(ZigLLVMGetEnvironmentTypeName(environ_type)); + type_enum_field->value = i; + + if (environ_type == g->zig_target.environ) { + g->target_environ_index = i; + } + } + entry->data.enumeration.complete = true; + + TypeTableEntry *tag_type_entry = get_smallest_unsigned_int_type(g, field_count); + entry->data.enumeration.tag_type = tag_type_entry; + + g->builtin_types.entry_environ_enum = entry; + } } -- cgit v1.2.3