add @compile_var("environ")

master
Andrew Kelley 2016-02-12 01:23:06 -07:00
parent 51b2621e62
commit 0c1ce21f7d
3 changed files with 30 additions and 0 deletions

View File

@ -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;

View File

@ -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)));

View File

@ -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;
}
}