diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-02-12 01:23:06 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-02-12 01:23:06 -0700 |
| commit | 0c1ce21f7d5f2756bc9e642c17092db9f9f2cf05 (patch) | |
| tree | 1a84a6d707b8d427665b5fe7c31c41886359c2ea | |
| parent | 51b2621e6201fa182f166783e79a47f49c04d5cf (diff) | |
| download | zig-0c1ce21f7d5f2756bc9e642c17092db9f9f2cf05.tar.gz zig-0c1ce21f7d5f2756bc9e642c17092db9f9f2cf05.zip | |
add @compile_var("environ")
| -rw-r--r-- | src/all_types.hpp | 2 | ||||
| -rw-r--r-- | src/analyze.cpp | 3 | ||||
| -rw-r--r-- | src/codegen.cpp | 25 |
3 files changed, 30 insertions, 0 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp index 9285e71c29..bfde81f2e3 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1110,6 +1110,7 @@ struct CodeGen { TypeTableEntry *entry_pure_error; TypeTableEntry *entry_os_enum; TypeTableEntry *entry_arch_enum; + TypeTableEntry *entry_environ_enum; } builtin_types; ZigTarget zig_target; @@ -1130,6 +1131,7 @@ struct CodeGen { bool is_test_build; uint32_t target_os_index; uint32_t target_arch_index; + uint32_t target_environ_index; LLVMTargetMachineRef target_machine; LLVMZigDIFile *dummy_di_file; bool is_native_target; diff --git a/src/analyze.cpp b/src/analyze.cpp index 6650e0ed06..32abb2f3a8 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -4250,6 +4250,9 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry } else if (buf_eql_str(&var_name, "arch")) { const_val->data.x_enum.tag = g->target_arch_index; return g->builtin_types.entry_arch_enum; + } else if (buf_eql_str(&var_name, "environ")) { + const_val->data.x_enum.tag = g->target_environ_index; + return g->builtin_types.entry_environ_enum; } else { add_node_error(g, *str_node, buf_sprintf("unrecognized compile variable: '%s'", buf_ptr(&var_name))); 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<TypeEnumField>(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; + } } |
