| author | |
| committer | |
| log | 17b935325e7c315304952f38037c7200595c5f10 |
| tree | 748a728084493ea3faf645039bb96b263273c880 |
| parent | c5dd536845cffdf9f0c22de0a67a89d84d078e24 |
See #226
Closes #22033 files changed, 315 insertions(+), 419 deletions(-)
doc/langref.md-17| ... | ... | @@ -446,23 +446,6 @@ This function can only occur inside `@c_import`. |
| 446 | 446 | |
| 447 | 447 | This appends `#undef $name` to the `c_import` temporary buffer. |
| 448 | 448 | |
| 449 | ### @compileVar(comptime name: []u8) -> (varying type) | |
| 450 | ||
| 451 | This function returns a compile-time variable. There are built in compile | |
| 452 | variables: | |
| 453 | ||
| 454 | * "is_big_endian" `bool` - either `true` for big endian or `false` for little endian. | |
| 455 | * "is_release" `bool`- either `true` for release mode builds or `false` for debug mode builds. | |
| 456 | * "is_test" `bool`- either `true` for test builds or `false` otherwise. | |
| 457 | * "os" `Os` - use `zig targets` to see what enum values are possible here. | |
| 458 | * "arch" `Arch` - use `zig targets` to see what enum values are possible here. | |
| 459 | * "environ" `Environ` - use `zig targets` to see what enum values are possible here. | |
| 460 | ||
| 461 | Build scripts can set additional compile variables of any name and type. | |
| 462 | ||
| 463 | The result of this function is a compile time constant that is marked as | |
| 464 | depending on a compile variable. | |
| 465 | ||
| 466 | 449 | ### @generatedCode(expression) -> @typeOf(expression) |
| 467 | 450 | |
| 468 | 451 | This function wraps an expression and returns the result of the expression |
src/all_types.hpp+3-9| ... | ... | @@ -1173,7 +1173,6 @@ enum BuiltinFnId { |
| 1173 | 1173 | BuiltinFnIdCInclude, |
| 1174 | 1174 | BuiltinFnIdCDefine, |
| 1175 | 1175 | BuiltinFnIdCUndef, |
| 1176 | BuiltinFnIdCompileVar, | |
| 1177 | 1176 | BuiltinFnIdCompileErr, |
| 1178 | 1177 | BuiltinFnIdCompileLog, |
| 1179 | 1178 | BuiltinFnIdGeneratedCode, |
| ... | ... | @@ -1323,7 +1322,6 @@ struct CodeGen { |
| 1323 | 1322 | HashMap<GenericFnTypeId *, FnTableEntry *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table; |
| 1324 | 1323 | HashMap<Scope *, IrInstruction *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table; |
| 1325 | 1324 | HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table; |
| 1326 | HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> compile_vars; | |
| 1327 | 1325 | HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> exported_symbol_names; |
| 1328 | 1326 | HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes; |
| 1329 | 1327 | |
| ... | ... | @@ -1407,6 +1405,8 @@ struct CodeGen { |
| 1407 | 1405 | PackageTableEntry *std_package; |
| 1408 | 1406 | PackageTableEntry *zigrt_package; |
| 1409 | 1407 | PackageTableEntry *test_runner_package; |
| 1408 | PackageTableEntry *compile_var_package; | |
| 1409 | ImportTableEntry *compile_var_import; | |
| 1410 | 1410 | Buf *root_out_name; |
| 1411 | 1411 | bool windows_subsystem_windows; |
| 1412 | 1412 | bool windows_subsystem_console; |
| ... | ... | @@ -1635,6 +1635,7 @@ struct ScopeFnDef { |
| 1635 | 1635 | FnTableEntry *fn_entry; |
| 1636 | 1636 | }; |
| 1637 | 1637 | |
| 1638 | // synchronized with code in define_builtin_compile_vars | |
| 1638 | 1639 | enum AtomicOrder { |
| 1639 | 1640 | AtomicOrderUnordered, |
| 1640 | 1641 | AtomicOrderMonotonic, |
| ... | ... | @@ -1706,7 +1707,6 @@ enum IrInstructionId { |
| 1706 | 1707 | IrInstructionIdArrayType, |
| 1707 | 1708 | IrInstructionIdSliceType, |
| 1708 | 1709 | IrInstructionIdAsm, |
| 1709 | IrInstructionIdCompileVar, | |
| 1710 | 1710 | IrInstructionIdSizeOf, |
| 1711 | 1711 | IrInstructionIdTestNonNull, |
| 1712 | 1712 | IrInstructionIdUnwrapMaybe, |
| ... | ... | @@ -2085,12 +2085,6 @@ struct IrInstructionAsm { |
| 2085 | 2085 | bool has_side_effects; |
| 2086 | 2086 | }; |
| 2087 | 2087 | |
| 2088 | struct IrInstructionCompileVar { | |
| 2089 | IrInstruction base; | |
| 2090 | ||
| 2091 | IrInstruction *name; | |
| 2092 | }; | |
| 2093 | ||
| 2094 | 2088 | struct IrInstructionSizeOf { |
| 2095 | 2089 | IrInstruction base; |
| 2096 | 2090 |
src/analyze.cpp+9-1| ... | ... | @@ -2084,6 +2084,14 @@ void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source |
| 2084 | 2084 | tld->parent_scope = parent_scope; |
| 2085 | 2085 | } |
| 2086 | 2086 | |
| 2087 | void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value) { | |
| 2088 | Tld *tld = g->compile_var_import->decls_scope->decl_table.get(name); | |
| 2089 | resolve_top_level_decl(g, tld, false); | |
| 2090 | assert(tld->id == TldIdVar); | |
| 2091 | TldVar *tld_var = (TldVar *)tld; | |
| 2092 | tld_var->var->value = value; | |
| 2093 | } | |
| 2094 | ||
| 2087 | 2095 | void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { |
| 2088 | 2096 | switch (node->type) { |
| 2089 | 2097 | case NodeTypeRoot: |
| ... | ... | @@ -2122,7 +2130,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { |
| 2122 | 2130 | if (import == g->root_import && scope_is_root_decls(&decls_scope->base) && |
| 2123 | 2131 | buf_eql_str(fn_name, "panic")) |
| 2124 | 2132 | { |
| 2125 | g->compile_vars.put(buf_create_from_str("panic_implementation_provided"), | |
| 2133 | update_compile_var(g, buf_create_from_str("__zig_panic_implementation_provided"), | |
| 2126 | 2134 | create_const_bool(g, true)); |
| 2127 | 2135 | } |
| 2128 | 2136 |
src/analyze.hpp+1| ... | ... | @@ -152,5 +152,6 @@ ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value); |
| 152 | 152 | FnTableEntry *get_extern_panic_fn(CodeGen *g); |
| 153 | 153 | TypeTableEntry *create_enum_tag_type(CodeGen *g, TypeTableEntry *enum_type, TypeTableEntry *int_type); |
| 154 | 154 | void expand_undef_array(CodeGen *g, ConstExprValue *const_val); |
| 155 | void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value); | |
| 155 | 156 | |
| 156 | 157 | #endif |
src/codegen.cpp+167-228| ... | ... | @@ -47,7 +47,7 @@ static void init_darwin_native(CodeGen *g) { |
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | PackageTableEntry *new_package(const char *root_src_dir, const char *root_src_path) { | |
| 50 | static PackageTableEntry *new_package(const char *root_src_dir, const char *root_src_path) { | |
| 51 | 51 | PackageTableEntry *entry = allocate<PackageTableEntry>(1); |
| 52 | 52 | entry->package_table.init(4); |
| 53 | 53 | buf_init_from_str(&entry->root_src_dir, root_src_dir); |
| ... | ... | @@ -70,7 +70,6 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out |
| 70 | 70 | g->generic_table.init(16); |
| 71 | 71 | g->llvm_fn_table.init(16); |
| 72 | 72 | g->memoized_fn_eval_table.init(16); |
| 73 | g->compile_vars.init(16); | |
| 74 | 73 | g->exported_symbol_names.init(8); |
| 75 | 74 | g->external_prototypes.init(8); |
| 76 | 75 | g->is_release_build = false; |
| ... | ... | @@ -2883,7 +2882,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, |
| 2883 | 2882 | case IrInstructionIdSetDebugSafety: |
| 2884 | 2883 | case IrInstructionIdArrayType: |
| 2885 | 2884 | case IrInstructionIdSliceType: |
| 2886 | case IrInstructionIdCompileVar: | |
| 2887 | 2885 | case IrInstructionIdSizeOf: |
| 2888 | 2886 | case IrInstructionIdSwitchTarget: |
| 2889 | 2887 | case IrInstructionIdContainerInitFields: |
| ... | ... | @@ -3627,6 +3625,13 @@ static LLVMValueRef build_alloca(CodeGen *g, TypeTableEntry *type_entry, const c |
| 3627 | 3625 | return result; |
| 3628 | 3626 | } |
| 3629 | 3627 | |
| 3628 | static void ensure_cache_dir(CodeGen *g) { | |
| 3629 | int err; | |
| 3630 | if ((err = os_make_path(g->cache_dir))) { | |
| 3631 | zig_panic("unable to make cache dir: %s", err_str(err)); | |
| 3632 | } | |
| 3633 | } | |
| 3634 | ||
| 3630 | 3635 | static void do_code_gen(CodeGen *g) { |
| 3631 | 3636 | if (g->verbose) { |
| 3632 | 3637 | fprintf(stderr, "\nCode Generation:\n"); |
| ... | ... | @@ -3919,10 +3924,7 @@ static void do_code_gen(CodeGen *g) { |
| 3919 | 3924 | buf_append_str(o_basename, o_ext); |
| 3920 | 3925 | Buf *output_path = buf_alloc(); |
| 3921 | 3926 | os_path_join(g->cache_dir, o_basename, output_path); |
| 3922 | int err; | |
| 3923 | if ((err = os_make_path(g->cache_dir))) { | |
| 3924 | zig_panic("unable to make cache dir: %s", err_str(err)); | |
| 3925 | } | |
| 3927 | ensure_cache_dir(g); | |
| 3926 | 3928 | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 3927 | 3929 | LLVMObjectFile, &err_msg, !g->is_release_build)) |
| 3928 | 3930 | { |
| ... | ... | @@ -3970,36 +3972,6 @@ static const GlobalLinkageValue global_linkage_values[] = { |
| 3970 | 3972 | {GlobalLinkageIdLinkOnce, "LinkOnce"}, |
| 3971 | 3973 | }; |
| 3972 | 3974 | |
| 3973 | static void init_enum_debug_info(CodeGen *g, TypeTableEntry *enum_type) { | |
| 3974 | uint32_t field_count = enum_type->data.enumeration.src_field_count; | |
| 3975 | ||
| 3976 | TypeTableEntry *tag_int_type = get_smallest_unsigned_int_type(g, field_count); | |
| 3977 | TypeTableEntry *tag_type_entry = create_enum_tag_type(g, enum_type, tag_int_type); | |
| 3978 | enum_type->data.enumeration.tag_type = tag_type_entry; | |
| 3979 | ||
| 3980 | ZigLLVMDIEnumerator **di_enumerators = allocate<ZigLLVMDIEnumerator*>(field_count); | |
| 3981 | for (uint32_t i = 0; i < field_count; i += 1) { | |
| 3982 | TypeEnumField *field = &enum_type->data.enumeration.fields[i]; | |
| 3983 | di_enumerators[i] = ZigLLVMCreateDebugEnumerator(g->dbuilder, buf_ptr(field->name), i); | |
| 3984 | } | |
| 3985 | ||
| 3986 | // create debug type for tag | |
| 3987 | uint64_t tag_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, tag_type_entry->type_ref); | |
| 3988 | uint64_t tag_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, tag_type_entry->type_ref); | |
| 3989 | enum_type->di_type = ZigLLVMCreateDebugEnumerationType(g->dbuilder, | |
| 3990 | nullptr, buf_ptr(&enum_type->name), | |
| 3991 | nullptr, 0, | |
| 3992 | tag_debug_size_in_bits, | |
| 3993 | tag_debug_align_in_bits, | |
| 3994 | di_enumerators, field_count, | |
| 3995 | tag_type_entry->di_type, ""); | |
| 3996 | ||
| 3997 | enum_type->type_ref = tag_type_entry->type_ref; | |
| 3998 | ||
| 3999 | enum_type->data.enumeration.complete = true; | |
| 4000 | enum_type->data.enumeration.zero_bits_known = true; | |
| 4001 | } | |
| 4002 | ||
| 4003 | 3975 | static void define_builtin_types(CodeGen *g) { |
| 4004 | 3976 | { |
| 4005 | 3977 | // if this type is anywhere in the AST, we should never hit codegen. |
| ... | ... | @@ -4218,167 +4190,6 @@ static void define_builtin_types(CodeGen *g) { |
| 4218 | 4190 | g->primitive_type_table.put(&entry->name, entry); |
| 4219 | 4191 | } |
| 4220 | 4192 | |
| 4221 | { | |
| 4222 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdEnum); | |
| 4223 | buf_init_from_str(&entry->name, "Os"); | |
| 4224 | uint32_t field_count = (uint32_t)target_os_count(); | |
| 4225 | entry->data.enumeration.src_field_count = field_count; | |
| 4226 | entry->data.enumeration.fields = allocate<TypeEnumField>(field_count); | |
| 4227 | for (uint32_t i = 0; i < field_count; i += 1) { | |
| 4228 | TypeEnumField *type_enum_field = &entry->data.enumeration.fields[i]; | |
| 4229 | ZigLLVM_OSType os_type = get_target_os(i); | |
| 4230 | type_enum_field->name = buf_create_from_str(get_target_os_name(os_type)); | |
| 4231 | type_enum_field->value = i; | |
| 4232 | type_enum_field->type_entry = g->builtin_types.entry_void; | |
| 4233 | ||
| 4234 | if (os_type == g->zig_target.os) { | |
| 4235 | g->target_os_index = i; | |
| 4236 | } | |
| 4237 | } | |
| 4238 | ||
| 4239 | init_enum_debug_info(g, entry); | |
| 4240 | ||
| 4241 | g->builtin_types.entry_os_enum = entry; | |
| 4242 | g->primitive_type_table.put(&entry->name, entry); | |
| 4243 | } | |
| 4244 | ||
| 4245 | { | |
| 4246 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdEnum); | |
| 4247 | buf_init_from_str(&entry->name, "Arch"); | |
| 4248 | uint32_t field_count = (uint32_t)target_arch_count(); | |
| 4249 | entry->data.enumeration.src_field_count = field_count; | |
| 4250 | entry->data.enumeration.fields = allocate<TypeEnumField>(field_count); | |
| 4251 | for (uint32_t i = 0; i < field_count; i += 1) { | |
| 4252 | TypeEnumField *type_enum_field = &entry->data.enumeration.fields[i]; | |
| 4253 | const ArchType *arch_type = get_target_arch(i); | |
| 4254 | type_enum_field->name = buf_alloc(); | |
| 4255 | buf_resize(type_enum_field->name, 50); | |
| 4256 | get_arch_name(buf_ptr(type_enum_field->name), arch_type); | |
| 4257 | buf_resize(type_enum_field->name, strlen(buf_ptr(type_enum_field->name))); | |
| 4258 | ||
| 4259 | type_enum_field->value = i; | |
| 4260 | type_enum_field->type_entry = g->builtin_types.entry_void; | |
| 4261 | ||
| 4262 | if (arch_type->arch == g->zig_target.arch.arch && | |
| 4263 | arch_type->sub_arch == g->zig_target.arch.sub_arch) | |
| 4264 | { | |
| 4265 | g->target_arch_index = i; | |
| 4266 | } | |
| 4267 | } | |
| 4268 | ||
| 4269 | init_enum_debug_info(g, entry); | |
| 4270 | ||
| 4271 | g->builtin_types.entry_arch_enum = entry; | |
| 4272 | g->primitive_type_table.put(&entry->name, entry); | |
| 4273 | } | |
| 4274 | ||
| 4275 | { | |
| 4276 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdEnum); | |
| 4277 | buf_init_from_str(&entry->name, "Environ"); | |
| 4278 | uint32_t field_count = (uint32_t)target_environ_count(); | |
| 4279 | entry->data.enumeration.src_field_count = field_count; | |
| 4280 | entry->data.enumeration.fields = allocate<TypeEnumField>(field_count); | |
| 4281 | for (uint32_t i = 0; i < field_count; i += 1) { | |
| 4282 | TypeEnumField *type_enum_field = &entry->data.enumeration.fields[i]; | |
| 4283 | ZigLLVM_EnvironmentType environ_type = get_target_environ(i); | |
| 4284 | type_enum_field->name = buf_create_from_str(ZigLLVMGetEnvironmentTypeName(environ_type)); | |
| 4285 | type_enum_field->value = i; | |
| 4286 | type_enum_field->type_entry = g->builtin_types.entry_void; | |
| 4287 | ||
| 4288 | if (environ_type == g->zig_target.env_type) { | |
| 4289 | g->target_environ_index = i; | |
| 4290 | } | |
| 4291 | } | |
| 4292 | ||
| 4293 | init_enum_debug_info(g, entry); | |
| 4294 | ||
| 4295 | g->builtin_types.entry_environ_enum = entry; | |
| 4296 | g->primitive_type_table.put(&entry->name, entry); | |
| 4297 | } | |
| 4298 | ||
| 4299 | { | |
| 4300 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdEnum); | |
| 4301 | buf_init_from_str(&entry->name, "ObjectFormat"); | |
| 4302 | uint32_t field_count = (uint32_t)target_oformat_count(); | |
| 4303 | entry->data.enumeration.src_field_count = field_count; | |
| 4304 | entry->data.enumeration.fields = allocate<TypeEnumField>(field_count); | |
| 4305 | for (uint32_t i = 0; i < field_count; i += 1) { | |
| 4306 | TypeEnumField *type_enum_field = &entry->data.enumeration.fields[i]; | |
| 4307 | ZigLLVM_ObjectFormatType oformat = get_target_oformat(i); | |
| 4308 | type_enum_field->name = buf_create_from_str(get_target_oformat_name(oformat)); | |
| 4309 | type_enum_field->value = i; | |
| 4310 | type_enum_field->type_entry = g->builtin_types.entry_void; | |
| 4311 | ||
| 4312 | if (oformat == g->zig_target.oformat) { | |
| 4313 | g->target_oformat_index = i; | |
| 4314 | } | |
| 4315 | } | |
| 4316 | ||
| 4317 | init_enum_debug_info(g, entry); | |
| 4318 | ||
| 4319 | g->builtin_types.entry_oformat_enum = entry; | |
| 4320 | g->primitive_type_table.put(&entry->name, entry); | |
| 4321 | } | |
| 4322 | ||
| 4323 | { | |
| 4324 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdEnum); | |
| 4325 | entry->zero_bits = true; // only allowed at compile time | |
| 4326 | buf_init_from_str(&entry->name, "GlobalLinkage"); | |
| 4327 | uint32_t field_count = array_length(global_linkage_values); | |
| 4328 | entry->data.enumeration.src_field_count = field_count; | |
| 4329 | entry->data.enumeration.fields = allocate<TypeEnumField>(field_count); | |
| 4330 | for (uint32_t i = 0; i < field_count; i += 1) { | |
| 4331 | TypeEnumField *type_enum_field = &entry->data.enumeration.fields[i]; | |
| 4332 | const GlobalLinkageValue *value = &global_linkage_values[i]; | |
| 4333 | type_enum_field->name = buf_create_from_str(value->name); | |
| 4334 | type_enum_field->value = i; | |
| 4335 | type_enum_field->type_entry = g->builtin_types.entry_void; | |
| 4336 | } | |
| 4337 | entry->data.enumeration.complete = true; | |
| 4338 | entry->data.enumeration.zero_bits_known = true; | |
| 4339 | ||
| 4340 | TypeTableEntry *tag_type_entry = get_smallest_unsigned_int_type(g, field_count); | |
| 4341 | entry->data.enumeration.tag_type = tag_type_entry; | |
| 4342 | ||
| 4343 | g->builtin_types.entry_global_linkage_enum = entry; | |
| 4344 | g->primitive_type_table.put(&entry->name, entry); | |
| 4345 | } | |
| 4346 | ||
| 4347 | { | |
| 4348 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdEnum); | |
| 4349 | entry->zero_bits = true; // only allowed at compile time | |
| 4350 | buf_init_from_str(&entry->name, "AtomicOrder"); | |
| 4351 | uint32_t field_count = 6; | |
| 4352 | entry->data.enumeration.src_field_count = field_count; | |
| 4353 | entry->data.enumeration.fields = allocate<TypeEnumField>(field_count); | |
| 4354 | entry->data.enumeration.fields[0].name = buf_create_from_str("Unordered"); | |
| 4355 | entry->data.enumeration.fields[0].value = AtomicOrderUnordered; | |
| 4356 | entry->data.enumeration.fields[0].type_entry = g->builtin_types.entry_void; | |
| 4357 | entry->data.enumeration.fields[1].name = buf_create_from_str("Monotonic"); | |
| 4358 | entry->data.enumeration.fields[1].value = AtomicOrderMonotonic; | |
| 4359 | entry->data.enumeration.fields[1].type_entry = g->builtin_types.entry_void; | |
| 4360 | entry->data.enumeration.fields[2].name = buf_create_from_str("Acquire"); | |
| 4361 | entry->data.enumeration.fields[2].value = AtomicOrderAcquire; | |
| 4362 | entry->data.enumeration.fields[2].type_entry = g->builtin_types.entry_void; | |
| 4363 | entry->data.enumeration.fields[3].name = buf_create_from_str("Release"); | |
| 4364 | entry->data.enumeration.fields[3].value = AtomicOrderRelease; | |
| 4365 | entry->data.enumeration.fields[3].type_entry = g->builtin_types.entry_void; | |
| 4366 | entry->data.enumeration.fields[4].name = buf_create_from_str("AcqRel"); | |
| 4367 | entry->data.enumeration.fields[4].value = AtomicOrderAcqRel; | |
| 4368 | entry->data.enumeration.fields[4].type_entry = g->builtin_types.entry_void; | |
| 4369 | entry->data.enumeration.fields[5].name = buf_create_from_str("SeqCst"); | |
| 4370 | entry->data.enumeration.fields[5].value = AtomicOrderSeqCst; | |
| 4371 | entry->data.enumeration.fields[5].type_entry = g->builtin_types.entry_void; | |
| 4372 | ||
| 4373 | entry->data.enumeration.complete = true; | |
| 4374 | entry->data.enumeration.zero_bits_known = true; | |
| 4375 | ||
| 4376 | TypeTableEntry *tag_type_entry = get_smallest_unsigned_int_type(g, field_count); | |
| 4377 | entry->data.enumeration.tag_type = tag_type_entry; | |
| 4378 | ||
| 4379 | g->builtin_types.entry_atomic_order_enum = entry; | |
| 4380 | g->primitive_type_table.put(&entry->name, entry); | |
| 4381 | } | |
| 4382 | 4193 | } |
| 4383 | 4194 | |
| 4384 | 4195 | |
| ... | ... | @@ -4475,7 +4286,6 @@ static void define_builtin_fns(CodeGen *g) { |
| 4475 | 4286 | create_builtin_fn(g, BuiltinFnIdCInclude, "cInclude", 1); |
| 4476 | 4287 | create_builtin_fn(g, BuiltinFnIdCDefine, "cDefine", 2); |
| 4477 | 4288 | create_builtin_fn(g, BuiltinFnIdCUndef, "cUndef", 1); |
| 4478 | create_builtin_fn(g, BuiltinFnIdCompileVar, "compileVar", 1); | |
| 4479 | 4289 | create_builtin_fn(g, BuiltinFnIdGeneratedCode, "generatedCode", 1); |
| 4480 | 4290 | create_builtin_fn(g, BuiltinFnIdCtz, "ctz", 1); |
| 4481 | 4291 | create_builtin_fn(g, BuiltinFnIdClz, "clz", 1); |
| ... | ... | @@ -4506,38 +4316,159 @@ static void define_builtin_fns(CodeGen *g) { |
| 4506 | 4316 | create_builtin_fn(g, BuiltinFnIdOffsetOf, "offsetOf", 2); |
| 4507 | 4317 | } |
| 4508 | 4318 | |
| 4509 | static void add_compile_var(CodeGen *g, const char *name, ConstExprValue *value) { | |
| 4510 | g->compile_vars.put_unique(buf_create_from_str(name), value); | |
| 4319 | static const char *bool_to_str(bool b) { | |
| 4320 | return b ? "true" : "false"; | |
| 4511 | 4321 | } |
| 4512 | 4322 | |
| 4513 | 4323 | static void define_builtin_compile_vars(CodeGen *g) { |
| 4514 | add_compile_var(g, "is_big_endian", create_const_bool(g, g->is_big_endian)); | |
| 4515 | add_compile_var(g, "is_release", create_const_bool(g, g->is_release_build)); | |
| 4516 | add_compile_var(g, "is_test", create_const_bool(g, g->is_test_build)); | |
| 4517 | add_compile_var(g, "os", create_const_enum_tag(g->builtin_types.entry_os_enum, g->target_os_index)); | |
| 4518 | add_compile_var(g, "arch", create_const_enum_tag(g->builtin_types.entry_arch_enum, g->target_arch_index)); | |
| 4519 | add_compile_var(g, "environ", create_const_enum_tag(g->builtin_types.entry_environ_enum, g->target_environ_index)); | |
| 4520 | add_compile_var(g, "object_format", create_const_enum_tag( | |
| 4521 | g->builtin_types.entry_oformat_enum, g->target_oformat_index)); | |
| 4324 | if (g->std_package == nullptr) | |
| 4325 | return; | |
| 4326 | ||
| 4327 | const char *builtin_zig_basename = "builtin.zig"; | |
| 4328 | Buf *builtin_zig_path = buf_alloc(); | |
| 4329 | os_path_join(g->cache_dir, buf_create_from_str(builtin_zig_basename), builtin_zig_path); | |
| 4330 | Buf *contents = buf_alloc(); | |
| 4331 | ||
| 4332 | const char *cur_os = nullptr; | |
| 4333 | { | |
| 4334 | buf_appendf(contents, "pub const Os = enum {\n"); | |
| 4335 | uint32_t field_count = (uint32_t)target_os_count(); | |
| 4336 | for (uint32_t i = 0; i < field_count; i += 1) { | |
| 4337 | ZigLLVM_OSType os_type = get_target_os(i); | |
| 4338 | const char *name = get_target_os_name(os_type); | |
| 4339 | buf_appendf(contents, " %s,\n", name); | |
| 4340 | ||
| 4341 | if (os_type == g->zig_target.os) { | |
| 4342 | g->target_os_index = i; | |
| 4343 | cur_os = name; | |
| 4344 | } | |
| 4345 | } | |
| 4346 | buf_appendf(contents, "};\n\n"); | |
| 4347 | } | |
| 4348 | assert(cur_os != nullptr); | |
| 4349 | ||
| 4350 | const char *cur_arch = nullptr; | |
| 4351 | { | |
| 4352 | buf_appendf(contents, "pub const Arch = enum {\n"); | |
| 4353 | uint32_t field_count = (uint32_t)target_arch_count(); | |
| 4354 | for (uint32_t i = 0; i < field_count; i += 1) { | |
| 4355 | const ArchType *arch_type = get_target_arch(i); | |
| 4356 | Buf *arch_name = buf_alloc(); | |
| 4357 | buf_resize(arch_name, 50); | |
| 4358 | get_arch_name(buf_ptr(arch_name), arch_type); | |
| 4359 | buf_resize(arch_name, strlen(buf_ptr(arch_name))); | |
| 4360 | ||
| 4361 | buf_appendf(contents, " %s,\n", buf_ptr(arch_name)); | |
| 4362 | ||
| 4363 | if (arch_type->arch == g->zig_target.arch.arch && | |
| 4364 | arch_type->sub_arch == g->zig_target.arch.sub_arch) | |
| 4365 | { | |
| 4366 | g->target_arch_index = i; | |
| 4367 | cur_arch = buf_ptr(arch_name); | |
| 4368 | } | |
| 4369 | } | |
| 4370 | buf_appendf(contents, "};\n\n"); | |
| 4371 | } | |
| 4372 | assert(cur_arch != nullptr); | |
| 4373 | ||
| 4374 | const char *cur_environ = nullptr; | |
| 4375 | { | |
| 4376 | buf_appendf(contents, "pub const Environ = enum {\n"); | |
| 4377 | uint32_t field_count = (uint32_t)target_environ_count(); | |
| 4378 | for (uint32_t i = 0; i < field_count; i += 1) { | |
| 4379 | ZigLLVM_EnvironmentType environ_type = get_target_environ(i); | |
| 4380 | const char *name = ZigLLVMGetEnvironmentTypeName(environ_type); | |
| 4381 | buf_appendf(contents, " %s,\n", name); | |
| 4382 | ||
| 4383 | if (environ_type == g->zig_target.env_type) { | |
| 4384 | g->target_environ_index = i; | |
| 4385 | cur_environ = name; | |
| 4386 | } | |
| 4387 | } | |
| 4388 | buf_appendf(contents, "};\n\n"); | |
| 4389 | } | |
| 4390 | assert(cur_environ != nullptr); | |
| 4522 | 4391 | |
| 4392 | const char *cur_obj_fmt = nullptr; | |
| 4523 | 4393 | { |
| 4524 | TypeTableEntry *str_type = get_slice_type(g, g->builtin_types.entry_u8, true); | |
| 4525 | ConstExprValue *const_val = allocate<ConstExprValue>(1); | |
| 4526 | const_val->special = ConstValSpecialStatic; | |
| 4527 | const_val->type = get_array_type(g, str_type, g->link_libs.length); | |
| 4528 | const_val->data.x_array.s_none.elements = allocate<ConstExprValue>(g->link_libs.length); | |
| 4394 | buf_appendf(contents, "pub const ObjectFormat = enum {\n"); | |
| 4395 | uint32_t field_count = (uint32_t)target_oformat_count(); | |
| 4396 | for (uint32_t i = 0; i < field_count; i += 1) { | |
| 4397 | ZigLLVM_ObjectFormatType oformat = get_target_oformat(i); | |
| 4398 | const char *name = get_target_oformat_name(oformat); | |
| 4399 | buf_appendf(contents, " %s,\n", name); | |
| 4400 | ||
| 4401 | if (oformat == g->zig_target.oformat) { | |
| 4402 | g->target_oformat_index = i; | |
| 4403 | cur_obj_fmt = name; | |
| 4404 | } | |
| 4405 | } | |
| 4406 | ||
| 4407 | buf_appendf(contents, "};\n\n"); | |
| 4408 | } | |
| 4409 | assert(cur_obj_fmt != nullptr); | |
| 4410 | ||
| 4411 | { | |
| 4412 | buf_appendf(contents, "pub const GlobalLinkage = enum {\n"); | |
| 4413 | uint32_t field_count = array_length(global_linkage_values); | |
| 4414 | for (uint32_t i = 0; i < field_count; i += 1) { | |
| 4415 | const GlobalLinkageValue *value = &global_linkage_values[i]; | |
| 4416 | buf_appendf(contents, " %s,\n", value->name); | |
| 4417 | } | |
| 4418 | buf_appendf(contents, "};\n\n"); | |
| 4419 | } | |
| 4420 | { | |
| 4421 | buf_appendf(contents, | |
| 4422 | "pub const AtomicOrder = enum {\n" | |
| 4423 | " Unordered,\n" | |
| 4424 | " Monotonic,\n" | |
| 4425 | " Acquire,\n" | |
| 4426 | " Release,\n" | |
| 4427 | " AcqRel,\n" | |
| 4428 | " SeqCst,\n" | |
| 4429 | "};\n\n"); | |
| 4430 | } | |
| 4431 | buf_appendf(contents, "pub const is_big_endian = %s;\n", bool_to_str(g->is_big_endian)); | |
| 4432 | buf_appendf(contents, "pub const is_release = %s;\n", bool_to_str(g->is_release_build)); | |
| 4433 | buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build)); | |
| 4434 | buf_appendf(contents, "pub const os = Os.%s;\n", cur_os); | |
| 4435 | buf_appendf(contents, "pub const arch = Arch.%s;\n", cur_arch); | |
| 4436 | buf_appendf(contents, "pub const environ = Environ.%s;\n", cur_environ); | |
| 4437 | buf_appendf(contents, "pub const object_format = ObjectFormat.%s;\n", cur_obj_fmt); | |
| 4438 | ||
| 4439 | { | |
| 4440 | buf_appendf(contents, "pub const link_libs = [][]const u8 {\n"); | |
| 4529 | 4441 | for (size_t i = 0; i < g->link_libs.length; i += 1) { |
| 4530 | 4442 | Buf *link_lib_buf = g->link_libs.at(i); |
| 4531 | ConstExprValue *array_val = create_const_str_lit(g, link_lib_buf); | |
| 4532 | init_const_slice(g, &const_val->data.x_array.s_none.elements[i], array_val, 0, buf_len(link_lib_buf), true); | |
| 4443 | buf_appendf(contents, " \"%s\",\n", buf_ptr(link_lib_buf)); | |
| 4533 | 4444 | } |
| 4445 | buf_appendf(contents, "};\n"); | |
| 4446 | } | |
| 4447 | ||
| 4448 | buf_appendf(contents, "pub const __zig_panic_implementation_provided = %s; // overwritten later\n", | |
| 4449 | bool_to_str(false)); | |
| 4450 | buf_appendf(contents, "pub const __zig_test_fn_slice = {}; // overwritten later\n"); | |
| 4534 | 4451 | |
| 4535 | add_compile_var(g, "link_libs", const_val); | |
| 4452 | ensure_cache_dir(g); | |
| 4453 | os_write_file(builtin_zig_path, contents); | |
| 4454 | ||
| 4455 | int err; | |
| 4456 | Buf *abs_full_path = buf_alloc(); | |
| 4457 | if ((err = os_path_real(builtin_zig_path, abs_full_path))) { | |
| 4458 | zig_panic("unable to open '%s': %s", buf_ptr(builtin_zig_path), err_str(err)); | |
| 4536 | 4459 | } |
| 4537 | add_compile_var(g, "panic_implementation_provided", create_const_bool(g, false)); | |
| 4460 | ||
| 4461 | assert(g->root_package); | |
| 4462 | assert(g->std_package); | |
| 4463 | g->compile_var_package = new_package(buf_ptr(g->cache_dir), builtin_zig_basename); | |
| 4464 | g->root_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package); | |
| 4465 | g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package); | |
| 4466 | g->compile_var_import = add_source_file(g, g->compile_var_package, abs_full_path, contents); | |
| 4538 | 4467 | } |
| 4539 | 4468 | |
| 4540 | 4469 | static void init(CodeGen *g) { |
| 4470 | if (g->module) | |
| 4471 | return; | |
| 4541 | 4472 | assert(g->root_out_name); |
| 4542 | 4473 | g->module = LLVMModuleCreateWithName(buf_ptr(g->root_out_name)); |
| 4543 | 4474 | |
| ... | ... | @@ -4600,14 +4531,15 @@ static void init(CodeGen *g) { |
| 4600 | 4531 | g->dummy_di_file = nullptr; |
| 4601 | 4532 | |
| 4602 | 4533 | define_builtin_types(g); |
| 4603 | define_builtin_fns(g); | |
| 4604 | define_builtin_compile_vars(g); | |
| 4605 | 4534 | |
| 4606 | 4535 | g->invalid_instruction = allocate<IrInstruction>(1); |
| 4607 | 4536 | g->invalid_instruction->value.type = g->builtin_types.entry_invalid; |
| 4608 | 4537 | |
| 4609 | 4538 | g->const_void_val.special = ConstValSpecialStatic; |
| 4610 | 4539 | g->const_void_val.type = g->builtin_types.entry_void; |
| 4540 | ||
| 4541 | define_builtin_fns(g); | |
| 4542 | define_builtin_compile_vars(g); | |
| 4611 | 4543 | } |
| 4612 | 4544 | |
| 4613 | 4545 | void codegen_parseh(CodeGen *g, Buf *full_path) { |
| ... | ... | @@ -4661,21 +4593,17 @@ static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package |
| 4661 | 4593 | } |
| 4662 | 4594 | |
| 4663 | 4595 | static PackageTableEntry *create_bootstrap_pkg(CodeGen *g, PackageTableEntry *pkg_with_main) { |
| 4664 | PackageTableEntry *package = new_package(buf_ptr(g->zig_std_special_dir), ""); | |
| 4665 | package->package_table.put(buf_create_from_str("std"), g->std_package); | |
| 4596 | PackageTableEntry *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig"); | |
| 4666 | 4597 | package->package_table.put(buf_create_from_str("@root"), pkg_with_main); |
| 4667 | 4598 | return package; |
| 4668 | 4599 | } |
| 4669 | 4600 | |
| 4670 | 4601 | static PackageTableEntry *create_test_runner_pkg(CodeGen *g) { |
| 4671 | PackageTableEntry *package = new_package(buf_ptr(g->zig_std_special_dir), "test_runner.zig"); | |
| 4672 | package->package_table.put(buf_create_from_str("std"), g->std_package); | |
| 4673 | return package; | |
| 4602 | return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "test_runner.zig"); | |
| 4674 | 4603 | } |
| 4675 | 4604 | |
| 4676 | 4605 | static PackageTableEntry *create_zigrt_pkg(CodeGen *g) { |
| 4677 | PackageTableEntry *package = new_package(buf_ptr(g->zig_std_special_dir), ""); | |
| 4678 | package->package_table.put(buf_create_from_str("std"), g->std_package); | |
| 4606 | PackageTableEntry *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "zigrt.zig"); | |
| 4679 | 4607 | package->package_table.put(buf_create_from_str("@root"), g->root_package); |
| 4680 | 4608 | return package; |
| 4681 | 4609 | } |
| ... | ... | @@ -4723,7 +4651,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) { |
| 4723 | 4651 | |
| 4724 | 4652 | ConstExprValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true); |
| 4725 | 4653 | |
| 4726 | g->compile_vars.put(buf_create_from_str("zig_test_fn_slice"), test_fn_slice); | |
| 4654 | update_compile_var(g, buf_create_from_str("__zig_test_fn_slice"), test_fn_slice); | |
| 4727 | 4655 | g->test_runner_package = create_test_runner_pkg(g); |
| 4728 | 4656 | g->test_runner_import = add_special_code(g, g->test_runner_package, "test_runner.zig"); |
| 4729 | 4657 | } |
| ... | ... | @@ -5066,3 +4994,14 @@ void codegen_build(CodeGen *g) { |
| 5066 | 4994 | do_code_gen(g); |
| 5067 | 4995 | gen_h_file(g); |
| 5068 | 4996 | } |
| 4997 | ||
| 4998 | PackageTableEntry *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path) { | |
| 4999 | init(g); | |
| 5000 | PackageTableEntry *pkg = new_package(root_src_dir, root_src_path); | |
| 5001 | if (g->std_package != nullptr) { | |
| 5002 | assert(g->compile_var_package != nullptr); | |
| 5003 | pkg->package_table.put(buf_create_from_str("std"), g->std_package); | |
| 5004 | pkg->package_table.put(buf_create_from_str("builtin"), g->compile_var_package); | |
| 5005 | } | |
| 5006 | return pkg; | |
| 5007 | } |
src/codegen.hpp+1-1| ... | ... | @@ -52,7 +52,7 @@ void codegen_add_time_event(CodeGen *g, const char *name); |
| 52 | 52 | void codegen_print_timing_report(CodeGen *g, FILE *f); |
| 53 | 53 | void codegen_build(CodeGen *g); |
| 54 | 54 | |
| 55 | PackageTableEntry *new_package(const char *root_src_dir, const char *root_src_path); | |
| 55 | PackageTableEntry *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path); | |
| 56 | 56 | void codegen_add_assembly(CodeGen *g, Buf *path); |
| 57 | 57 | void codegen_add_object(CodeGen *g, Buf *object_path); |
| 58 | 58 |
src/ir.cpp-55| ... | ... | @@ -294,10 +294,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAsm *) { |
| 294 | 294 | return IrInstructionIdAsm; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileVar *) { | |
| 298 | return IrInstructionIdCompileVar; | |
| 299 | } | |
| 300 | ||
| 301 | 297 | static constexpr IrInstructionId ir_instruction_id(IrInstructionSizeOf *) { |
| 302 | 298 | return IrInstructionIdSizeOf; |
| 303 | 299 | } |
| ... | ... | @@ -1249,15 +1245,6 @@ static IrInstruction *ir_build_asm_from(IrBuilder *irb, IrInstruction *old_instr |
| 1249 | 1245 | return new_instruction; |
| 1250 | 1246 | } |
| 1251 | 1247 | |
| 1252 | static IrInstruction *ir_build_compile_var(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) { | |
| 1253 | IrInstructionCompileVar *instruction = ir_build_instruction<IrInstructionCompileVar>(irb, scope, source_node); | |
| 1254 | instruction->name = name; | |
| 1255 | ||
| 1256 | ir_ref_instruction(name, irb->current_basic_block); | |
| 1257 | ||
| 1258 | return &instruction->base; | |
| 1259 | } | |
| 1260 | ||
| 1261 | 1248 | static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value) { |
| 1262 | 1249 | IrInstructionSizeOf *instruction = ir_build_instruction<IrInstructionSizeOf>(irb, scope, source_node); |
| 1263 | 1250 | instruction->type_value = type_value; |
| ... | ... | @@ -2431,13 +2418,6 @@ static IrInstruction *ir_instruction_asm_get_dep(IrInstructionAsm *instruction, |
| 2431 | 2418 | return nullptr; |
| 2432 | 2419 | } |
| 2433 | 2420 | |
| 2434 | static IrInstruction *ir_instruction_compilevar_get_dep(IrInstructionCompileVar *instruction, size_t index) { | |
| 2435 | switch (index) { | |
| 2436 | case 0: return instruction->name; | |
| 2437 | default: return nullptr; | |
| 2438 | } | |
| 2439 | } | |
| 2440 | ||
| 2441 | 2421 | static IrInstruction *ir_instruction_sizeof_get_dep(IrInstructionSizeOf *instruction, size_t index) { |
| 2442 | 2422 | switch (index) { |
| 2443 | 2423 | case 0: return instruction->type_value; |
| ... | ... | @@ -2979,8 +2959,6 @@ static IrInstruction *ir_instruction_get_dep(IrInstruction *instruction, size_t |
| 2979 | 2959 | return ir_instruction_slicetype_get_dep((IrInstructionSliceType *) instruction, index); |
| 2980 | 2960 | case IrInstructionIdAsm: |
| 2981 | 2961 | return ir_instruction_asm_get_dep((IrInstructionAsm *) instruction, index); |
| 2982 | case IrInstructionIdCompileVar: | |
| 2983 | return ir_instruction_compilevar_get_dep((IrInstructionCompileVar *) instruction, index); | |
| 2984 | 2962 | case IrInstructionIdSizeOf: |
| 2985 | 2963 | return ir_instruction_sizeof_get_dep((IrInstructionSizeOf *) instruction, index); |
| 2986 | 2964 | case IrInstructionIdTestNonNull: |
| ... | ... | @@ -3937,15 +3915,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 3937 | 3915 | |
| 3938 | 3916 | return ir_build_set_debug_safety(irb, scope, node, arg0_value, arg1_value); |
| 3939 | 3917 | } |
| 3940 | case BuiltinFnIdCompileVar: | |
| 3941 | { | |
| 3942 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | |
| 3943 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); | |
| 3944 | if (arg0_value == irb->codegen->invalid_instruction) | |
| 3945 | return arg0_value; | |
| 3946 | ||
| 3947 | return ir_build_compile_var(irb, scope, node, arg0_value); | |
| 3948 | } | |
| 3949 | 3918 | case BuiltinFnIdSizeof: |
| 3950 | 3919 | { |
| 3951 | 3920 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| ... | ... | @@ -10409,27 +10378,6 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 10409 | 10378 | zig_unreachable(); |
| 10410 | 10379 | } |
| 10411 | 10380 | |
| 10412 | static TypeTableEntry *ir_analyze_instruction_compile_var(IrAnalyze *ira, | |
| 10413 | IrInstructionCompileVar *compile_var_instruction) | |
| 10414 | { | |
| 10415 | IrInstruction *name_value = compile_var_instruction->name->other; | |
| 10416 | Buf *var_name = ir_resolve_str(ira, name_value); | |
| 10417 | if (!var_name) | |
| 10418 | return ira->codegen->builtin_types.entry_invalid; | |
| 10419 | ||
| 10420 | ConstExprValue *out_val = ir_build_const_from(ira, &compile_var_instruction->base); | |
| 10421 | auto entry = ira->codegen->compile_vars.maybe_get(var_name); | |
| 10422 | if (entry) { | |
| 10423 | *out_val = *entry->value; | |
| 10424 | return out_val->type; | |
| 10425 | } else { | |
| 10426 | ir_add_error_node(ira, name_value->source_node, | |
| 10427 | buf_sprintf("unrecognized compile variable: '%s'", buf_ptr(var_name))); | |
| 10428 | return ira->codegen->builtin_types.entry_invalid; | |
| 10429 | } | |
| 10430 | zig_unreachable(); | |
| 10431 | } | |
| 10432 | ||
| 10433 | 10381 | static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 10434 | 10382 | IrInstructionSizeOf *size_of_instruction) |
| 10435 | 10383 | { |
| ... | ... | @@ -13039,8 +12987,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi |
| 13039 | 12987 | return ir_analyze_instruction_asm(ira, (IrInstructionAsm *)instruction); |
| 13040 | 12988 | case IrInstructionIdArrayType: |
| 13041 | 12989 | return ir_analyze_instruction_array_type(ira, (IrInstructionArrayType *)instruction); |
| 13042 | case IrInstructionIdCompileVar: | |
| 13043 | return ir_analyze_instruction_compile_var(ira, (IrInstructionCompileVar *)instruction); | |
| 13044 | 12990 | case IrInstructionIdSizeOf: |
| 13045 | 12991 | return ir_analyze_instruction_size_of(ira, (IrInstructionSizeOf *)instruction); |
| 13046 | 12992 | case IrInstructionIdTestNonNull: |
| ... | ... | @@ -13292,7 +13238,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 13292 | 13238 | case IrInstructionIdEnumFieldPtr: |
| 13293 | 13239 | case IrInstructionIdArrayType: |
| 13294 | 13240 | case IrInstructionIdSliceType: |
| 13295 | case IrInstructionIdCompileVar: | |
| 13296 | 13241 | case IrInstructionIdSizeOf: |
| 13297 | 13242 | case IrInstructionIdTestNonNull: |
| 13298 | 13243 | case IrInstructionIdUnwrapMaybe: |
src/ir_print.cpp-9| ... | ... | @@ -403,12 +403,6 @@ static void ir_print_asm(IrPrint *irp, IrInstructionAsm *instruction) { |
| 403 | 403 | fprintf(irp->f, ")"); |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | static void ir_print_compile_var(IrPrint *irp, IrInstructionCompileVar *instruction) { | |
| 407 | fprintf(irp->f, "@compileVar("); | |
| 408 | ir_print_other_instruction(irp, instruction->name); | |
| 409 | fprintf(irp->f, ")"); | |
| 410 | } | |
| 411 | ||
| 412 | 406 | static void ir_print_size_of(IrPrint *irp, IrInstructionSizeOf *instruction) { |
| 413 | 407 | fprintf(irp->f, "@sizeOf("); |
| 414 | 408 | ir_print_other_instruction(irp, instruction->type_value); |
| ... | ... | @@ -987,9 +981,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) { |
| 987 | 981 | case IrInstructionIdAsm: |
| 988 | 982 | ir_print_asm(irp, (IrInstructionAsm *)instruction); |
| 989 | 983 | break; |
| 990 | case IrInstructionIdCompileVar: | |
| 991 | ir_print_compile_var(irp, (IrInstructionCompileVar *)instruction); | |
| 992 | break; | |
| 993 | 984 | case IrInstructionIdSizeOf: |
| 994 | 985 | ir_print_size_of(irp, (IrInstructionSizeOf *)instruction); |
| 995 | 986 | break; |
src/main.cpp+2-2| ... | ... | @@ -263,8 +263,8 @@ int main(int argc, char **argv) { |
| 263 | 263 | return 1; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | PackageTableEntry *build_pkg = new_package(buf_ptr(&build_file_dirname), buf_ptr(&build_file_basename)); | |
| 267 | build_pkg->package_table.put(buf_create_from_str("std"), g->std_package); | |
| 266 | PackageTableEntry *build_pkg = codegen_create_package(g, buf_ptr(&build_file_dirname), | |
| 267 | buf_ptr(&build_file_basename)); | |
| 268 | 268 | g->root_package->package_table.put(buf_create_from_str("@build"), build_pkg); |
| 269 | 269 | codegen_build(g); |
| 270 | 270 | codegen_link(g, buf_ptr(path_to_build_exe)); |
std/build.zig+14-9| ... | ... | @@ -1,3 +1,4 @@ |
| 1 | const builtin = @import("builtin"); | |
| 1 | 2 | const io = @import("io.zig"); |
| 2 | 3 | const mem = @import("mem.zig"); |
| 3 | 4 | const debug = @import("debug.zig"); |
| ... | ... | @@ -625,9 +626,9 @@ const Version = struct { |
| 625 | 626 | }; |
| 626 | 627 | |
| 627 | 628 | const CrossTarget = struct { |
| 628 | arch: Arch, | |
| 629 | os: Os, | |
| 630 | environ: Environ, | |
| 629 | arch: builtin.Arch, | |
| 630 | os: builtin.Os, | |
| 631 | environ: builtin.Environ, | |
| 631 | 632 | }; |
| 632 | 633 | |
| 633 | 634 | const Target = enum { |
| ... | ... | @@ -636,22 +637,22 @@ const Target = enum { |
| 636 | 637 | |
| 637 | 638 | pub fn oFileExt(self: &const Target) -> []const u8 { |
| 638 | 639 | const environ = switch (*self) { |
| 639 | Target.Native => @compileVar("environ"), | |
| 640 | Target.Native => builtin.environ, | |
| 640 | 641 | Target.Cross => |t| t.environ, |
| 641 | 642 | }; |
| 642 | 643 | return switch (environ) { |
| 643 | Environ.msvc => ".obj", | |
| 644 | builtin.Environ.msvc => ".obj", | |
| 644 | 645 | else => ".o", |
| 645 | 646 | }; |
| 646 | 647 | } |
| 647 | 648 | |
| 648 | 649 | pub fn exeFileExt(self: &const Target) -> []const u8 { |
| 649 | 650 | const target_os = switch (*self) { |
| 650 | Target.Native => @compileVar("os"), | |
| 651 | Target.Native => builtin.os, | |
| 651 | 652 | Target.Cross => |t| t.os, |
| 652 | 653 | }; |
| 653 | 654 | return switch (target_os) { |
| 654 | Os.windows => ".exe", | |
| 655 | builtin.Os.windows => ".exe", | |
| 655 | 656 | else => "", |
| 656 | 657 | }; |
| 657 | 658 | } |
| ... | ... | @@ -761,7 +762,9 @@ pub const LibExeObjStep = struct { |
| 761 | 762 | } |
| 762 | 763 | } |
| 763 | 764 | |
| 764 | pub fn setTarget(self: &LibExeObjStep, target_arch: Arch, target_os: Os, target_environ: Environ) { | |
| 765 | pub fn setTarget(self: &LibExeObjStep, target_arch: builtin.Arch, target_os: builtin.Os, | |
| 766 | target_environ: builtin.Environ) | |
| 767 | { | |
| 765 | 768 | self.target = Target.Cross { |
| 766 | 769 | CrossTarget { |
| 767 | 770 | .arch = target_arch, |
| ... | ... | @@ -1392,7 +1395,9 @@ pub const CLibExeObjStep = struct { |
| 1392 | 1395 | } |
| 1393 | 1396 | } |
| 1394 | 1397 | |
| 1395 | pub fn setTarget(self: &CLibExeObjStep, target_arch: Arch, target_os: Os, target_environ: Environ) { | |
| 1398 | pub fn setTarget(self: &CLibExeObjStep, target_arch: builtin.Arch, target_os: builtin.Os, | |
| 1399 | target_environ: builtin.Environ) | |
| 1400 | { | |
| 1396 | 1401 | self.target = Target.Cross { |
| 1397 | 1402 | CrossTarget { |
| 1398 | 1403 | .arch = target_arch, |
std/c/index.zig+3-1| ... | ... | @@ -1,6 +1,8 @@ |
| 1 | 1 | pub use @import("../os/errno.zig"); |
| 2 | const builtin = @import("builtin"); | |
| 3 | const Os = builtin.Os; | |
| 2 | 4 | |
| 3 | pub use switch(@compileVar("os")) { | |
| 5 | pub use switch(builtin.os) { | |
| 4 | 6 | Os.linux => @import("linux.zig"), |
| 5 | 7 | Os.windows => @import("windows.zig"), |
| 6 | 8 | Os.darwin, Os.macosx, Os.ios => @import("darwin.zig"), |
std/debug.zig+6-5| ... | ... | @@ -4,6 +4,7 @@ const os = @import("os/index.zig"); |
| 4 | 4 | const elf = @import("elf.zig"); |
| 5 | 5 | const DW = @import("dwarf.zig"); |
| 6 | 6 | const List = @import("list.zig").List; |
| 7 | const builtin = @import("builtin"); | |
| 7 | 8 | |
| 8 | 9 | error MissingDebugInfo; |
| 9 | 10 | error InvalidDebugInfo; |
| ... | ... | @@ -50,8 +51,8 @@ pub var user_main_fn: ?fn() -> %void = null; |
| 50 | 51 | pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty_color: bool, |
| 51 | 52 | ignore_frame_count: usize) -> %void |
| 52 | 53 | { |
| 53 | switch (@compileVar("object_format")) { | |
| 54 | ObjectFormat.elf => { | |
| 54 | switch (builtin.object_format) { | |
| 55 | builtin.ObjectFormat.elf => { | |
| 55 | 56 | var stack_trace = ElfStackTrace { |
| 56 | 57 | .self_exe_stream = undefined, |
| 57 | 58 | .elf = undefined, |
| ... | ... | @@ -125,13 +126,13 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty |
| 125 | 126 | %return out_stream.flush(); |
| 126 | 127 | } |
| 127 | 128 | }, |
| 128 | ObjectFormat.coff => { | |
| 129 | builtin.ObjectFormat.coff => { | |
| 129 | 130 | %return out_stream.write("(stack trace unavailable for COFF object format)\n"); |
| 130 | 131 | }, |
| 131 | ObjectFormat.macho => { | |
| 132 | builtin.ObjectFormat.macho => { | |
| 132 | 133 | %return out_stream.write("(stack trace unavailable for Mach-O object format)\n"); |
| 133 | 134 | }, |
| 134 | ObjectFormat.unknown => { | |
| 135 | builtin.ObjectFormat.unknown => { | |
| 135 | 136 | %return out_stream.write("(stack trace unavailable for unknown object format)\n"); |
| 136 | 137 | }, |
| 137 | 138 | } |
std/elf.zig+11-13| ... | ... | @@ -36,9 +36,7 @@ pub const FileType = enum { |
| 36 | 36 | Core, |
| 37 | 37 | }; |
| 38 | 38 | |
| 39 | // TODO rename this to Arch when the builtin Arch enum is namespaced | |
| 40 | // or make debug info work for builtin enums | |
| 41 | pub const ElfArch = enum { | |
| 39 | pub const Arch = enum { | |
| 42 | 40 | Sparc, |
| 43 | 41 | x86, |
| 44 | 42 | Mips, |
| ... | ... | @@ -69,7 +67,7 @@ pub const Elf = struct { |
| 69 | 67 | is_64: bool, |
| 70 | 68 | is_big_endian: bool, |
| 71 | 69 | file_type: FileType, |
| 72 | arch: ElfArch, | |
| 70 | arch: Arch, | |
| 73 | 71 | entry_addr: u64, |
| 74 | 72 | program_header_offset: u64, |
| 75 | 73 | section_header_offset: u64, |
| ... | ... | @@ -123,15 +121,15 @@ pub const Elf = struct { |
| 123 | 121 | }; |
| 124 | 122 | |
| 125 | 123 | elf.arch = switch (%return elf.in_stream.readInt(elf.is_big_endian, u16)) { |
| 126 | 0x02 => ElfArch.Sparc, | |
| 127 | 0x03 => ElfArch.x86, | |
| 128 | 0x08 => ElfArch.Mips, | |
| 129 | 0x14 => ElfArch.PowerPc, | |
| 130 | 0x28 => ElfArch.Arm, | |
| 131 | 0x2A => ElfArch.SuperH, | |
| 132 | 0x32 => ElfArch.IA_64, | |
| 133 | 0x3E => ElfArch.x86_64, | |
| 134 | 0xb7 => ElfArch.AArch64, | |
| 124 | 0x02 => Arch.Sparc, | |
| 125 | 0x03 => Arch.x86, | |
| 126 | 0x08 => Arch.Mips, | |
| 127 | 0x14 => Arch.PowerPc, | |
| 128 | 0x28 => Arch.Arm, | |
| 129 | 0x2A => Arch.SuperH, | |
| 130 | 0x32 => Arch.IA_64, | |
| 131 | 0x3E => Arch.x86_64, | |
| 132 | 0xb7 => Arch.AArch64, | |
| 135 | 133 | else => return error.InvalidFormat, |
| 136 | 134 | }; |
| 137 | 135 |
std/endian.zig+2-1| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | const mem = @import("mem.zig"); |
| 2 | const builtin = @import("builtin"); | |
| 2 | 3 | |
| 3 | 4 | pub fn swapIfLe(comptime T: type, x: T) -> T { |
| 4 | 5 | swapIf(false, T, x) |
| ... | ... | @@ -9,7 +10,7 @@ pub fn swapIfBe(comptime T: type, x: T) -> T { |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | 12 | pub fn swapIf(is_be: bool, comptime T: type, x: T) -> T { |
| 12 | if (@compileVar("is_big_endian") == is_be) swap(T, x) else x | |
| 13 | if (builtin.is_big_endian == is_be) swap(T, x) else x | |
| 13 | 14 | } |
| 14 | 15 | |
| 15 | 16 | pub fn swap(comptime T: type, x: T) -> T { |
std/hash_map.zig+2-1| ... | ... | @@ -3,8 +3,9 @@ const assert = debug.assert; |
| 3 | 3 | const math = @import("math.zig"); |
| 4 | 4 | const mem = @import("mem.zig"); |
| 5 | 5 | const Allocator = mem.Allocator; |
| 6 | const builtin = @import("builtin"); | |
| 6 | 7 | |
| 7 | const want_modification_safety = !@compileVar("is_release"); | |
| 8 | const want_modification_safety = !builtin.is_release; | |
| 8 | 9 | const debug_u32 = if (want_modification_safety) u32 else void; |
| 9 | 10 | |
| 10 | 11 | pub fn HashMap(comptime K: type, comptime V: type, |
std/io.zig+11-9| ... | ... | @@ -1,4 +1,6 @@ |
| 1 | const system = switch(@compileVar("os")) { | |
| 1 | const builtin = @import("builtin"); | |
| 2 | const Os = builtin.Os; | |
| 3 | const system = switch(builtin.os) { | |
| 2 | 4 | Os.linux => @import("os/linux.zig"), |
| 3 | 5 | Os.darwin => @import("os/darwin.zig"), |
| 4 | 6 | else => @compileError("Unsupported OS"), |
| ... | ... | @@ -79,7 +81,7 @@ pub const OutStream = struct { |
| 79 | 81 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. |
| 80 | 82 | /// Call close to clean up. |
| 81 | 83 | pub fn openMode(path: []const u8, mode: usize, allocator: ?&mem.Allocator) -> %OutStream { |
| 82 | switch (@compileVar("os")) { | |
| 84 | switch (builtin.os) { | |
| 83 | 85 | Os.linux, Os.darwin, Os.macosx, Os.ios => { |
| 84 | 86 | const flags = system.O_LARGEFILE|system.O_WRONLY|system.O_CREAT|system.O_CLOEXEC|system.O_TRUNC; |
| 85 | 87 | const fd = %return os.posixOpen(path, flags, mode, allocator); |
| ... | ... | @@ -176,7 +178,7 @@ pub const InStream = struct { |
| 176 | 178 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. |
| 177 | 179 | /// Call close to clean up. |
| 178 | 180 | pub fn open(path: []const u8, allocator: ?&mem.Allocator) -> %InStream { |
| 179 | switch (@compileVar("os")) { | |
| 181 | switch (builtin.os) { | |
| 180 | 182 | Os.linux, Os.darwin, Os.macosx, Os.ios => { |
| 181 | 183 | const flags = system.O_LARGEFILE|system.O_RDONLY; |
| 182 | 184 | const fd = %return os.posixOpen(path, flags, 0, allocator); |
| ... | ... | @@ -191,7 +193,7 @@ pub const InStream = struct { |
| 191 | 193 | /// Upon success, the stream is in an uninitialized state. To continue using it, |
| 192 | 194 | /// you must use the open() function. |
| 193 | 195 | pub fn close(self: &InStream) { |
| 194 | switch (@compileVar("os")) { | |
| 196 | switch (builtin.os) { | |
| 195 | 197 | Os.linux, Os.darwin, Os.macosx, Os.ios => { |
| 196 | 198 | os.posixClose(self.fd); |
| 197 | 199 | }, |
| ... | ... | @@ -202,7 +204,7 @@ pub const InStream = struct { |
| 202 | 204 | /// Returns the number of bytes read. If the number read is smaller than buf.len, then |
| 203 | 205 | /// the stream reached End Of File. |
| 204 | 206 | pub fn read(is: &InStream, buf: []u8) -> %usize { |
| 205 | switch (@compileVar("os")) { | |
| 207 | switch (builtin.os) { | |
| 206 | 208 | Os.linux, Os.darwin => { |
| 207 | 209 | var index: usize = 0; |
| 208 | 210 | while (index < buf.len) { |
| ... | ... | @@ -268,7 +270,7 @@ pub const InStream = struct { |
| 268 | 270 | } |
| 269 | 271 | |
| 270 | 272 | pub fn seekForward(is: &InStream, amount: usize) -> %void { |
| 271 | switch (@compileVar("os")) { | |
| 273 | switch (builtin.os) { | |
| 272 | 274 | Os.linux, Os.darwin => { |
| 273 | 275 | const result = system.lseek(is.fd, amount, system.SEEK_CUR); |
| 274 | 276 | const err = system.getErrno(result); |
| ... | ... | @@ -288,7 +290,7 @@ pub const InStream = struct { |
| 288 | 290 | } |
| 289 | 291 | |
| 290 | 292 | pub fn seekTo(is: &InStream, pos: usize) -> %void { |
| 291 | switch (@compileVar("os")) { | |
| 293 | switch (builtin.os) { | |
| 292 | 294 | Os.linux, Os.darwin => { |
| 293 | 295 | const result = system.lseek(is.fd, pos, system.SEEK_SET); |
| 294 | 296 | const err = system.getErrno(result); |
| ... | ... | @@ -308,7 +310,7 @@ pub const InStream = struct { |
| 308 | 310 | } |
| 309 | 311 | |
| 310 | 312 | pub fn getPos(is: &InStream) -> %usize { |
| 311 | switch (@compileVar("os")) { | |
| 313 | switch (builtin.os) { | |
| 312 | 314 | Os.linux, Os.darwin => { |
| 313 | 315 | const result = system.lseek(is.fd, 0, system.SEEK_CUR); |
| 314 | 316 | const err = system.getErrno(result); |
| ... | ... | @@ -365,7 +367,7 @@ pub const InStream = struct { |
| 365 | 367 | }; |
| 366 | 368 | |
| 367 | 369 | pub fn openSelfExe() -> %InStream { |
| 368 | switch (@compileVar("os")) { | |
| 370 | switch (builtin.os) { | |
| 369 | 371 | Os.linux => { |
| 370 | 372 | return InStream.open("/proc/self/exe", null); |
| 371 | 373 | }, |
std/mem.zig+3-1| ... | ... | @@ -2,6 +2,8 @@ const assert = @import("debug.zig").assert; |
| 2 | 2 | const math = @import("math.zig"); |
| 3 | 3 | const os = @import("os/index.zig"); |
| 4 | 4 | const io = @import("io.zig"); |
| 5 | const builtin = @import("builtin"); | |
| 6 | const Os = builtin.Os; | |
| 5 | 7 | |
| 6 | 8 | pub const Cmp = math.Cmp; |
| 7 | 9 | |
| ... | ... | @@ -53,7 +55,7 @@ pub const IncrementingAllocator = struct { |
| 53 | 55 | end_index: usize, |
| 54 | 56 | |
| 55 | 57 | fn init(capacity: usize) -> %IncrementingAllocator { |
| 56 | switch (@compileVar("os")) { | |
| 58 | switch (builtin.os) { | |
| 57 | 59 | Os.linux, Os.darwin, Os.macosx, Os.ios => { |
| 58 | 60 | const p = os.posix; |
| 59 | 61 | const addr = p.mmap(null, capacity, p.PROT_READ|p.PROT_WRITE, |
std/os/child_process.zig+3-1| ... | ... | @@ -7,6 +7,8 @@ const errno = @import("errno.zig"); |
| 7 | 7 | const debug = @import("../debug.zig"); |
| 8 | 8 | const assert = debug.assert; |
| 9 | 9 | const BufMap = @import("../buf_map.zig").BufMap; |
| 10 | const builtin = @import("builtin"); | |
| 11 | const Os = builtin.Os; | |
| 10 | 12 | |
| 11 | 13 | pub const ChildProcess = struct { |
| 12 | 14 | pid: i32, |
| ... | ... | @@ -34,7 +36,7 @@ pub const ChildProcess = struct { |
| 34 | 36 | cwd: ?[]const u8, env_map: &const BufMap, |
| 35 | 37 | stdin: StdIo, stdout: StdIo, stderr: StdIo, allocator: &Allocator) -> %ChildProcess |
| 36 | 38 | { |
| 37 | switch (@compileVar("os")) { | |
| 39 | switch (builtin.os) { | |
| 38 | 40 | Os.linux, Os.macosx, Os.ios, Os.darwin => { |
| 39 | 41 | return spawnPosix(exe_path, args, cwd, env_map, stdin, stdout, stderr, allocator); |
| 40 | 42 | }, |
std/os/darwin.zig+3-2| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | |
| 2 | const arch = switch (@compileVar("arch")) { | |
| 3 | Arch.x86_64 => @import("darwin_x86_64.zig"), | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const arch = switch (builtin.arch) { | |
| 4 | builtin.Arch.x86_64 => @import("darwin_x86_64.zig"), | |
| 4 | 5 | else => @compileError("unsupported arch"), |
| 5 | 6 | }; |
| 6 | 7 |
std/os/index.zig+6-4| ... | ... | @@ -1,7 +1,9 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | const Os = builtin.Os; | |
| 1 | 3 | pub const windows = @import("windows.zig"); |
| 2 | 4 | pub const darwin = @import("darwin.zig"); |
| 3 | 5 | pub const linux = @import("linux.zig"); |
| 4 | pub const posix = switch(@compileVar("os")) { | |
| 6 | pub const posix = switch(builtin.os) { | |
| 5 | 7 | Os.linux => linux, |
| 6 | 8 | Os.darwin, Os.macosx, Os.ios => darwin, |
| 7 | 9 | Os.windows => windows, |
| ... | ... | @@ -12,7 +14,7 @@ pub const max_noalloc_path_len = 1024; |
| 12 | 14 | pub const ChildProcess = @import("child_process.zig").ChildProcess; |
| 13 | 15 | pub const path = @import("path.zig"); |
| 14 | 16 | |
| 15 | pub const line_sep = switch (@compileVar("os")) { | |
| 17 | pub const line_sep = switch (builtin.os) { | |
| 16 | 18 | Os.windows => "\r\n", |
| 17 | 19 | else => "\n", |
| 18 | 20 | }; |
| ... | ... | @@ -56,7 +58,7 @@ error DirNotEmpty; |
| 56 | 58 | /// library implementation. |
| 57 | 59 | pub fn getRandomBytes(buf: []u8) -> %void { |
| 58 | 60 | while (true) { |
| 59 | const err = switch (@compileVar("os")) { | |
| 61 | const err = switch (builtin.os) { | |
| 60 | 62 | Os.linux => { |
| 61 | 63 | if (linking_libc) { |
| 62 | 64 | if (c.getrandom(buf.ptr, buf.len, 0) == -1) *c._errno() else 0 |
| ... | ... | @@ -104,7 +106,7 @@ pub coldcc fn abort() -> noreturn { |
| 104 | 106 | if (linking_libc) { |
| 105 | 107 | c.abort(); |
| 106 | 108 | } |
| 107 | switch (@compileVar("os")) { | |
| 109 | switch (builtin.os) { | |
| 108 | 110 | Os.linux, Os.darwin, Os.macosx, Os.ios => { |
| 109 | 111 | _ = posix.raise(posix.SIGABRT); |
| 110 | 112 | _ = posix.raise(posix.SIGKILL); |
std/os/linux.zig+4-3| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | const arch = switch (@compileVar("arch")) { | |
| 2 | Arch.x86_64 => @import("linux_x86_64.zig"), | |
| 3 | Arch.i386 => @import("linux_i386.zig"), | |
| 1 | const builtin = @import("builtin"); | |
| 2 | const arch = switch (builtin.arch) { | |
| 3 | builtin.Arch.x86_64 => @import("linux_x86_64.zig"), | |
| 4 | builtin.Arch.i386 => @import("linux_i386.zig"), | |
| 4 | 5 | else => @compileError("unsupported arch"), |
| 5 | 6 | }; |
| 6 | 7 | const errno = @import("errno.zig"); |
std/os/path.zig+5-3| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | const Os = builtin.Os; | |
| 1 | 3 | const debug = @import("../debug.zig"); |
| 2 | 4 | const assert = debug.assert; |
| 3 | 5 | const mem = @import("../mem.zig"); |
| ... | ... | @@ -7,11 +9,11 @@ const os = @import("index.zig"); |
| 7 | 9 | const math = @import("../math.zig"); |
| 8 | 10 | const posix = os.posix; |
| 9 | 11 | |
| 10 | pub const sep = switch (@compileVar("os")) { | |
| 12 | pub const sep = switch (builtin.os) { | |
| 11 | 13 | Os.windows => '\\', |
| 12 | 14 | else => '/', |
| 13 | 15 | }; |
| 14 | pub const delimiter = switch (@compileVar("os")) { | |
| 16 | pub const delimiter = switch (builtin.os) { | |
| 15 | 17 | Os.windows => ';', |
| 16 | 18 | else => ':', |
| 17 | 19 | }; |
| ... | ... | @@ -61,7 +63,7 @@ test "os.path.join" { |
| 61 | 63 | } |
| 62 | 64 | |
| 63 | 65 | pub fn isAbsolute(path: []const u8) -> bool { |
| 64 | switch (@compileVar("os")) { | |
| 66 | switch (builtin.os) { | |
| 65 | 67 | Os.windows => @compileError("Unsupported OS"), |
| 66 | 68 | else => return path[0] == sep, |
| 67 | 69 | } |
std/special/bootstrap.zig+6-5| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | |
| 4 | 4 | const root = @import("@root"); |
| 5 | 5 | const std = @import("std"); |
| 6 | const builtin = @import("builtin"); | |
| 6 | 7 | |
| 7 | 8 | const want_main_symbol = std.target.linking_libc; |
| 8 | 9 | const want_start_symbol = !want_main_symbol; |
| ... | ... | @@ -13,15 +14,15 @@ var argc_ptr: &usize = undefined; |
| 13 | 14 | |
| 14 | 15 | export nakedcc fn _start() -> noreturn { |
| 15 | 16 | if (!want_start_symbol) { |
| 16 | @setGlobalLinkage(_start, GlobalLinkage.Internal); | |
| 17 | @setGlobalLinkage(_start, builtin.GlobalLinkage.Internal); | |
| 17 | 18 | unreachable; |
| 18 | 19 | } |
| 19 | 20 | |
| 20 | switch (@compileVar("arch")) { | |
| 21 | Arch.x86_64 => { | |
| 21 | switch (builtin.arch) { | |
| 22 | builtin.Arch.x86_64 => { | |
| 22 | 23 | argc_ptr = asm("lea (%%rsp), %[argc]": [argc] "=r" (-> &usize)); |
| 23 | 24 | }, |
| 24 | Arch.i386 => { | |
| 25 | builtin.Arch.i386 => { | |
| 25 | 26 | argc_ptr = asm("lea (%%esp), %[argc]": [argc] "=r" (-> &usize)); |
| 26 | 27 | }, |
| 27 | 28 | else => @compileError("unsupported arch"), |
| ... | ... | @@ -51,7 +52,7 @@ fn callMain(argc: usize, argv: &&u8, envp: &?&u8) -> %void { |
| 51 | 52 | |
| 52 | 53 | export fn main(c_argc: i32, c_argv: &&u8, c_envp: &?&u8) -> i32 { |
| 53 | 54 | if (!want_main_symbol) { |
| 54 | @setGlobalLinkage(main, GlobalLinkage.Internal); | |
| 55 | @setGlobalLinkage(main, builtin.GlobalLinkage.Internal); | |
| 55 | 56 | unreachable; |
| 56 | 57 | } |
| 57 | 58 |
std/special/compiler_rt.zig+23-21| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | ||
| 1 | 3 | const CHAR_BIT = 8; |
| 2 | 4 | const du_int = u64; |
| 3 | 5 | const di_int = i64; |
| ... | ... | @@ -5,7 +7,7 @@ const si_int = c_int; |
| 5 | 7 | const su_int = c_uint; |
| 6 | 8 | |
| 7 | 9 | const udwords = [2]su_int; |
| 8 | const low = if (@compileVar("is_big_endian")) 1 else 0; | |
| 10 | const low = if (builtin.is_big_endian) 1 else 0; | |
| 9 | 11 | const high = 1 - low; |
| 10 | 12 | |
| 11 | 13 | export fn __udivdi3(a: du_int, b: du_int) -> du_int { |
| ... | ... | @@ -213,25 +215,25 @@ export fn __umoddi3(a: du_int, b: du_int) -> du_int { |
| 213 | 215 | } |
| 214 | 216 | |
| 215 | 217 | fn isArmArch() -> bool { |
| 216 | return switch (@compileVar("arch")) { | |
| 217 | Arch.armv8_2a, | |
| 218 | Arch.armv8_1a, | |
| 219 | Arch.armv8, | |
| 220 | Arch.armv8m_baseline, | |
| 221 | Arch.armv8m_mainline, | |
| 222 | Arch.armv7, | |
| 223 | Arch.armv7em, | |
| 224 | Arch.armv7m, | |
| 225 | Arch.armv7s, | |
| 226 | Arch.armv7k, | |
| 227 | Arch.armv6, | |
| 228 | Arch.armv6m, | |
| 229 | Arch.armv6k, | |
| 230 | Arch.armv6t2, | |
| 231 | Arch.armv5, | |
| 232 | Arch.armv5te, | |
| 233 | Arch.armv4t, | |
| 234 | Arch.armeb => true, | |
| 218 | return switch (builtin.arch) { | |
| 219 | builtin.Arch.armv8_2a, | |
| 220 | builtin.Arch.armv8_1a, | |
| 221 | builtin.Arch.armv8, | |
| 222 | builtin.Arch.armv8m_baseline, | |
| 223 | builtin.Arch.armv8m_mainline, | |
| 224 | builtin.Arch.armv7, | |
| 225 | builtin.Arch.armv7em, | |
| 226 | builtin.Arch.armv7m, | |
| 227 | builtin.Arch.armv7s, | |
| 228 | builtin.Arch.armv7k, | |
| 229 | builtin.Arch.armv6, | |
| 230 | builtin.Arch.armv6m, | |
| 231 | builtin.Arch.armv6k, | |
| 232 | builtin.Arch.armv6t2, | |
| 233 | builtin.Arch.armv5, | |
| 234 | builtin.Arch.armv5te, | |
| 235 | builtin.Arch.armv4t, | |
| 236 | builtin.Arch.armeb => true, | |
| 235 | 237 | else => false, |
| 236 | 238 | }; |
| 237 | 239 | } |
| ... | ... | @@ -252,7 +254,7 @@ export nakedcc fn __aeabi_uidivmod() { |
| 252 | 254 | unreachable; |
| 253 | 255 | } |
| 254 | 256 | |
| 255 | @setGlobalLinkage(__aeabi_uidivmod, GlobalLinkage.Internal); | |
| 257 | @setGlobalLinkage(__aeabi_uidivmod, builtin.GlobalLinkage.Internal); | |
| 256 | 258 | } |
| 257 | 259 | |
| 258 | 260 | export fn __udivmodsi4(a: su_int, b: su_int, rem: &su_int) -> su_int { |
std/special/test_runner.zig+2-1| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const io = @import("std").io; |
| 2 | const test_fn_list = @compileVar("zig_test_fn_slice"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const test_fn_list = builtin.__zig_test_fn_slice; | |
| 3 | 4 | |
| 4 | 5 | pub fn main() -> %void { |
| 5 | 6 | for (test_fn_list) |test_fn, i| { |
std/special/zigrt.zig+5-3| ... | ... | @@ -2,13 +2,15 @@ |
| 2 | 2 | // multiple .o files. The symbols are defined Weak so that multiple |
| 3 | 3 | // instances of zig_rt.zig do not conflict with each other. |
| 4 | 4 | |
| 5 | const builtin = @import("builtin"); | |
| 6 | ||
| 5 | 7 | export coldcc fn __zig_panic(message_ptr: &const u8, message_len: usize) -> noreturn { |
| 6 | @setGlobalLinkage(__zig_panic, GlobalLinkage.Weak); | |
| 8 | @setGlobalLinkage(__zig_panic, builtin.GlobalLinkage.Weak); | |
| 7 | 9 | @setDebugSafety(this, false); |
| 8 | 10 | |
| 9 | if (@compileVar("panic_implementation_provided")) { | |
| 11 | if (builtin.__zig_panic_implementation_provided) { | |
| 10 | 12 | @import("@root").panic(message_ptr[0...message_len]); |
| 11 | } else if (@compileVar("os") == Os.freestanding) { | |
| 13 | } else if (builtin.os == builtin.Os.freestanding) { | |
| 12 | 14 | while (true) {} |
| 13 | 15 | } else { |
| 14 | 16 | @import("std").debug.panic("{}", message_ptr[0...message_len]); |
std/target.zig+3-2| ... | ... | @@ -1,11 +1,12 @@ |
| 1 | 1 | const mem = @import("mem.zig"); |
| 2 | const builtin = @import("builtin"); | |
| 2 | 3 | |
| 3 | 4 | pub const linking_libc = linkingLibrary("c"); |
| 4 | 5 | |
| 5 | 6 | pub fn linkingLibrary(lib_name: []const u8) -> bool { |
| 6 | 7 | // TODO shouldn't need this if |
| 7 | if (@compileVar("link_libs").len != 0) { | |
| 8 | for (@compileVar("link_libs")) |link_lib| { | |
| 8 | if (builtin.link_libs.len != 0) { | |
| 9 | for (builtin.link_libs) |link_lib| { | |
| 9 | 10 | if (mem.eql(u8, link_lib, lib_name)) { |
| 10 | 11 | return true; |
| 11 | 12 | } |
test/assemble_and_link.zig+2-1| ... | ... | @@ -1,7 +1,8 @@ |
| 1 | const builtin = @import("builtin"); | |
| 1 | 2 | const tests = @import("tests.zig"); |
| 2 | 3 | |
| 3 | 4 | pub fn addCases(cases: &tests.CompareOutputContext) { |
| 4 | if (@compileVar("os") == Os.linux and @compileVar("arch") == Arch.x86_64) { | |
| 5 | if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) { | |
| 5 | 6 | cases.addAsm("hello world linux x86_64", |
| 6 | 7 | \\.text |
| 7 | 8 | \\.globl _start |
test/cases/asm.zig+3-2| ... | ... | @@ -1,7 +1,8 @@ |
| 1 | const config = @import("builtin"); | |
| 1 | 2 | const assert = @import("std").debug.assert; |
| 2 | 3 | |
| 3 | 4 | comptime { |
| 4 | if (@compileVar("arch") == Arch.x86_64) { | |
| 5 | if (config.arch == config.Arch.x86_64) { | |
| 5 | 6 | asm volatile ( |
| 6 | 7 | \\.globl aoeu; |
| 7 | 8 | \\.type aoeu, @function; |
| ... | ... | @@ -11,7 +12,7 @@ comptime { |
| 11 | 12 | } |
| 12 | 13 | |
| 13 | 14 | test "module level assembly" { |
| 14 | if (@compileVar("arch") == Arch.x86_64) { | |
| 15 | if (config.arch == config.Arch.x86_64) { | |
| 15 | 16 | assert(aoeu() == 1234); |
| 16 | 17 | } |
| 17 | 18 | } |
test/cases/atomics.zig+1| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | const assert = @import("std").debug.assert; |
| 2 | const AtomicOrder = @import("builtin").AtomicOrder; | |
| 2 | 3 | |
| 3 | 4 | test "cmpxchg" { |
| 4 | 5 | var x: i32 = 1234; |
test/cases/misc.zig+2-1| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const assert = @import("std").debug.assert; |
| 2 | 2 | const mem = @import("std").mem; |
| 3 | 3 | const cstr = @import("std").cstr; |
| 4 | const builtin = @import("builtin"); | |
| 4 | 5 | |
| 5 | 6 | // normal comment |
| 6 | 7 | /// this is a documentation comment |
| ... | ... | @@ -12,7 +13,7 @@ test "emptyFunctionWithComments" { |
| 12 | 13 | } |
| 13 | 14 | |
| 14 | 15 | export fn disabledExternFn() { |
| 15 | @setGlobalLinkage(disabledExternFn, GlobalLinkage.Internal); | |
| 16 | @setGlobalLinkage(disabledExternFn, builtin.GlobalLinkage.Internal); | |
| 16 | 17 | } |
| 17 | 18 | |
| 18 | 19 | test "callDisabledExternFn" { |
test/cases/namespace_depends_on_compile_var/index.zig+3-2| ... | ... | @@ -1,3 +1,4 @@ |
| 1 | const builtin = @import("builtin"); | |
| 1 | 2 | const assert = @import("std").debug.assert; |
| 2 | 3 | |
| 3 | 4 | test "namespaceDependsOnCompileVar" { |
| ... | ... | @@ -7,7 +8,7 @@ test "namespaceDependsOnCompileVar" { |
| 7 | 8 | assert(!some_namespace.a_bool); |
| 8 | 9 | } |
| 9 | 10 | } |
| 10 | const some_namespace = switch(@compileVar("os")) { | |
| 11 | Os.linux => @import("a.zig"), | |
| 11 | const some_namespace = switch(builtin.os) { | |
| 12 | builtin.Os.linux => @import("a.zig"), | |
| 12 | 13 | else => @import("b.zig"), |
| 13 | 14 | }; |
test/compile_errors.zig+9-6| ... | ... | @@ -688,9 +688,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 688 | 688 | |
| 689 | 689 | |
| 690 | 690 | cases.add("bogus compile var", |
| 691 | \\const x = @compileVar("bogus"); | |
| 691 | \\const x = @import("builtin").bogus; | |
| 692 | 692 | \\export fn entry() -> usize { @sizeOf(@typeOf(x)) } |
| 693 | , ".tmp_source.zig:1:23: error: unrecognized compile variable: 'bogus'"); | |
| 693 | , ".tmp_source.zig:1:29: error: no member named 'bogus' in '"); | |
| 694 | 694 | |
| 695 | 695 | |
| 696 | 696 | cases.add("non constant expression in array size outside function", |
| ... | ... | @@ -910,18 +910,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 910 | 910 | , ".tmp_source.zig:2:15: error: unable to infer expression type"); |
| 911 | 911 | |
| 912 | 912 | cases.add("atomic orderings of cmpxchg - failure stricter than success", |
| 913 | \\const AtomicOrder = @import("builtin").AtomicOrder; | |
| 913 | 914 | \\export fn f() { |
| 914 | 915 | \\ var x: i32 = 1234; |
| 915 | 916 | \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {} |
| 916 | 917 | \\} |
| 917 | , ".tmp_source.zig:3:72: error: failure atomic ordering must be no stricter than success"); | |
| 918 | , ".tmp_source.zig:4:72: error: failure atomic ordering must be no stricter than success"); | |
| 918 | 919 | |
| 919 | 920 | cases.add("atomic orderings of cmpxchg - success Monotonic or stricter", |
| 921 | \\const AtomicOrder = @import("builtin").AtomicOrder; | |
| 920 | 922 | \\export fn f() { |
| 921 | 923 | \\ var x: i32 = 1234; |
| 922 | 924 | \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {} |
| 923 | 925 | \\} |
| 924 | , ".tmp_source.zig:3:49: error: success atomic ordering must be Monotonic or stricter"); | |
| 926 | , ".tmp_source.zig:4:49: error: success atomic ordering must be Monotonic or stricter"); | |
| 925 | 927 | |
| 926 | 928 | cases.add("negation overflow in function evaluation", |
| 927 | 929 | \\const y = neg(-128); |
| ... | ... | @@ -1487,10 +1489,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1487 | 1489 | , ".tmp_source.zig:6:5: error: unable to evaluate constant expression"); |
| 1488 | 1490 | |
| 1489 | 1491 | cases.add("invalid member of builtin enum", |
| 1492 | \\const builtin = @import("builtin"); | |
| 1490 | 1493 | \\export fn entry() { |
| 1491 | \\ const foo = Arch.x86; | |
| 1494 | \\ const foo = builtin.Arch.x86; | |
| 1492 | 1495 | \\} |
| 1493 | , ".tmp_source.zig:2:21: error: container 'Arch' has no member called 'x86'"); | |
| 1496 | , ".tmp_source.zig:3:29: error: container 'Arch' has no member called 'x86'"); | |
| 1494 | 1497 | |
| 1495 | 1498 | cases.add("int to ptr of 0 bits", |
| 1496 | 1499 | \\export fn foo() { |