| author | |
| committer | |
| log | d8d45908fa6c572c661ba51132da87a3bc10c640 |
| tree | be408495a03e5253de2150ccba981de253235f87 |
| parent | 1c8fee41c247ea60aebd1d8b0fdba4002701b1cf |
14 files changed, 126 insertions(+), 44 deletions(-)
CMakeLists.txt+4-1| ... | ... | @@ -175,7 +175,7 @@ if(MINGW) |
| 175 | 175 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args") |
| 176 | 176 | endif() |
| 177 | 177 | |
| 178 | set(EXE_CFLAGS "-std=c++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__USE_MINGW_ANSI_STDIO -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces") | |
| 178 | set(EXE_CFLAGS "-std=c++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces") | |
| 179 | 179 | set(EXE_LDFLAGS " ") |
| 180 | 180 | if(ZIG_TEST_COVERAGE) |
| 181 | 181 | set(EXE_CFLAGS "${EXE_CFLAGS} -fprofile-arcs -ftest-coverage") |
| ... | ... | @@ -193,6 +193,9 @@ target_link_libraries(zig LINK_PUBLIC |
| 193 | 193 | ${LLVM_LIBRARIES} |
| 194 | 194 | ${CMAKE_THREAD_LIBS_INIT} |
| 195 | 195 | ) |
| 196 | if(MINGW) | |
| 197 | target_link_libraries(zig LINK_PUBLIC version) | |
| 198 | endif() | |
| 196 | 199 | install(TARGETS zig DESTINATION bin) |
| 197 | 200 | |
| 198 | 201 | install(FILES ${C_HEADERS} DESTINATION ${C_HEADERS_DEST}) |
src/analyze.cpp+6-6| ... | ... | @@ -573,7 +573,7 @@ TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t |
| 573 | 573 | entry->is_copyable = false; |
| 574 | 574 | |
| 575 | 575 | buf_resize(&entry->name, 0); |
| 576 | buf_appendf(&entry->name, "[%" PRIu64 "]%s", array_size, buf_ptr(&child_type->name)); | |
| 576 | buf_appendf(&entry->name, "[%" ZIG_PRI_u64 "]%s", array_size, buf_ptr(&child_type->name)); | |
| 577 | 577 | |
| 578 | 578 | if (!entry->zero_bits) { |
| 579 | 579 | entry->type_ref = child_type->type_ref ? LLVMArrayType(child_type->type_ref, |
| ... | ... | @@ -2756,7 +2756,7 @@ void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entry, Vari |
| 2756 | 2756 | if (param_decl_node && !is_var_args) { |
| 2757 | 2757 | param_name = param_decl_node->data.param_decl.name; |
| 2758 | 2758 | } else { |
| 2759 | param_name = buf_sprintf("arg%zu", i); | |
| 2759 | param_name = buf_sprintf("arg%" ZIG_PRI_usize "", i); | |
| 2760 | 2760 | } |
| 2761 | 2761 | |
| 2762 | 2762 | TypeTableEntry *param_type = param_info->type; |
| ... | ... | @@ -3934,7 +3934,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { |
| 3934 | 3934 | { |
| 3935 | 3935 | BigNum *bignum = &const_val->data.x_bignum; |
| 3936 | 3936 | const char *negative_str = bignum->is_negative ? "-" : ""; |
| 3937 | buf_appendf(buf, "%s%llu", negative_str, bignum->data.x_uint); | |
| 3937 | buf_appendf(buf, "%s%" ZIG_PRI_llu, negative_str, bignum->data.x_uint); | |
| 3938 | 3938 | return; |
| 3939 | 3939 | } |
| 3940 | 3940 | case TypeTableEntryIdMetaType: |
| ... | ... | @@ -3945,7 +3945,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { |
| 3945 | 3945 | BigNum *bignum = &const_val->data.x_bignum; |
| 3946 | 3946 | assert(bignum->kind == BigNumKindInt); |
| 3947 | 3947 | const char *negative_str = bignum->is_negative ? "-" : ""; |
| 3948 | buf_appendf(buf, "%s%llu", negative_str, bignum->data.x_uint); | |
| 3948 | buf_appendf(buf, "%s%" ZIG_PRI_llu, negative_str, bignum->data.x_uint); | |
| 3949 | 3949 | } |
| 3950 | 3950 | return; |
| 3951 | 3951 | case TypeTableEntryIdFloat: |
| ... | ... | @@ -3983,7 +3983,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { |
| 3983 | 3983 | return; |
| 3984 | 3984 | } |
| 3985 | 3985 | case ConstPtrSpecialHardCodedAddr: |
| 3986 | buf_appendf(buf, "(&%s)(%" PRIx64 ")", buf_ptr(&type_entry->data.pointer.child_type->name), | |
| 3986 | buf_appendf(buf, "(&%s)(%" ZIG_PRI_x64 ")", buf_ptr(&type_entry->data.pointer.child_type->name), | |
| 3987 | 3987 | const_val->data.x_ptr.data.hard_coded_addr.addr); |
| 3988 | 3988 | return; |
| 3989 | 3989 | case ConstPtrSpecialDiscard: |
| ... | ... | @@ -4000,7 +4000,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { |
| 4000 | 4000 | case TypeTableEntryIdBlock: |
| 4001 | 4001 | { |
| 4002 | 4002 | AstNode *node = const_val->data.x_block->source_node; |
| 4003 | buf_appendf(buf, "(scope:%zu:%zu)", node->line + 1, node->column + 1); | |
| 4003 | buf_appendf(buf, "(scope:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", node->line + 1, node->column + 1); | |
| 4004 | 4004 | return; |
| 4005 | 4005 | } |
| 4006 | 4006 | case TypeTableEntryIdArray: |
src/ast_render.cpp+4-3| ... | ... | @@ -5,8 +5,9 @@ |
| 5 | 5 | * See http://opensource.org/licenses/MIT |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | #include "ast_render.hpp" | |
| 9 | 8 | #include "analyze.hpp" |
| 9 | #include "ast_render.hpp" | |
| 10 | #include "os.hpp" | |
| 10 | 11 | |
| 11 | 12 | #include <stdio.h> |
| 12 | 13 | |
| ... | ... | @@ -529,7 +530,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 529 | 530 | case BigNumKindInt: |
| 530 | 531 | { |
| 531 | 532 | const char *negative_str = node->data.number_literal.bignum->is_negative ? "-" : ""; |
| 532 | fprintf(ar->f, "%s%llu", negative_str, node->data.number_literal.bignum->data.x_uint); | |
| 533 | fprintf(ar->f, "%s%" ZIG_PRI_llu, negative_str, node->data.number_literal.bignum->data.x_uint); | |
| 533 | 534 | } |
| 534 | 535 | break; |
| 535 | 536 | case BigNumKindFloat: |
| ... | ... | @@ -962,7 +963,7 @@ static void ast_render_tld_fn(AstRender *ar, Buf *name, TldFn *tld_fn) { |
| 962 | 963 | if (param_info->is_noalias) { |
| 963 | 964 | fprintf(ar->f, "noalias "); |
| 964 | 965 | } |
| 965 | Buf *param_name = tld_fn->fn_entry->param_names ? tld_fn->fn_entry->param_names[i] : buf_sprintf("arg%zu", i); | |
| 966 | Buf *param_name = tld_fn->fn_entry->param_names ? tld_fn->fn_entry->param_names[i] : buf_sprintf("arg%" ZIG_PRI_usize "", i); | |
| 966 | 967 | fprintf(ar->f, "%s: %s", buf_ptr(param_name), buf_ptr(&param_info->type->name)); |
| 967 | 968 | } |
| 968 | 969 | if (fn_type_id->return_type->id == TypeTableEntryIdVoid) { |
src/bignum.cpp+2-1| ... | ... | @@ -7,6 +7,7 @@ |
| 7 | 7 | |
| 8 | 8 | #include "bignum.hpp" |
| 9 | 9 | #include "buffer.hpp" |
| 10 | #include "os.hpp" | |
| 10 | 11 | |
| 11 | 12 | #include <assert.h> |
| 12 | 13 | #include <math.h> |
| ... | ... | @@ -350,7 +351,7 @@ Buf *bignum_to_buf(BigNum *bn) { |
| 350 | 351 | return buf_sprintf("%f", bn->data.x_float); |
| 351 | 352 | } else { |
| 352 | 353 | const char *neg = bn->is_negative ? "-" : ""; |
| 353 | return buf_sprintf("%s%llu", neg, bn->data.x_uint); | |
| 354 | return buf_sprintf("%s%" ZIG_PRI_llu "", neg, bn->data.x_uint); | |
| 354 | 355 | } |
| 355 | 356 | } |
| 356 | 357 |
src/codegen.cpp+2-2| ... | ... | @@ -559,7 +559,7 @@ static LLVMValueRef get_floor_ceil_fn(CodeGen *g, TypeTableEntry *type_entry, Zi |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | char fn_name[64]; |
| 562 | sprintf(fn_name, "llvm.%s.f%zu", name, type_entry->data.floating.bit_count); | |
| 562 | sprintf(fn_name, "llvm.%s.f%" ZIG_PRI_usize "", name, type_entry->data.floating.bit_count); | |
| 563 | 563 | LLVMTypeRef fn_type = LLVMFunctionType(type_entry->type_ref, &type_entry->type_ref, 1, false); |
| 564 | 564 | LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type); |
| 565 | 565 | |
| ... | ... | @@ -2166,7 +2166,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru |
| 2166 | 2166 | { |
| 2167 | 2167 | size_t index = find_asm_index(g, asm_node, asm_token); |
| 2168 | 2168 | assert(index < SIZE_MAX); |
| 2169 | buf_appendf(&llvm_template, "$%zu", index); | |
| 2169 | buf_appendf(&llvm_template, "$%" ZIG_PRI_usize "", index); | |
| 2170 | 2170 | break; |
| 2171 | 2171 | } |
| 2172 | 2172 | case AsmTokenIdUniqueId: |
src/errmsg.cpp+4-4| ... | ... | @@ -30,9 +30,9 @@ static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) |
| 30 | 30 | |
| 31 | 31 | if (color == ErrColorOn || (color == ErrColorAuto && os_stderr_tty())) { |
| 32 | 32 | if (err_type == ErrTypeError) { |
| 33 | fprintf(stderr, WHITE "%s:%zu:%zu: " RED "error:" WHITE " %s" RESET "\n", path, line, col, text); | |
| 33 | fprintf(stderr, WHITE "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": " RED "error:" WHITE " %s" RESET "\n", path, line, col, text); | |
| 34 | 34 | } else if (err_type == ErrTypeNote) { |
| 35 | fprintf(stderr, WHITE "%s:%zu:%zu: " CYAN "note:" WHITE " %s" RESET "\n", path, line, col, text); | |
| 35 | fprintf(stderr, WHITE "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": " CYAN "note:" WHITE " %s" RESET "\n", path, line, col, text); | |
| 36 | 36 | } else { |
| 37 | 37 | zig_unreachable(); |
| 38 | 38 | } |
| ... | ... | @@ -44,9 +44,9 @@ static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) |
| 44 | 44 | fprintf(stderr, GREEN "^" RESET "\n"); |
| 45 | 45 | } else { |
| 46 | 46 | if (err_type == ErrTypeError) { |
| 47 | fprintf(stderr, "%s:%zu:%zu: error: %s\n", path, line, col, text); | |
| 47 | fprintf(stderr, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": error: %s\n", path, line, col, text); | |
| 48 | 48 | } else if (err_type == ErrTypeNote) { |
| 49 | fprintf(stderr, " %s:%zu:%zu: note: %s\n", path, line, col, text); | |
| 49 | fprintf(stderr, " %s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": note: %s\n", path, line, col, text); | |
| 50 | 50 | } else { |
| 51 | 51 | zig_unreachable(); |
| 52 | 52 | } |
src/ir.cpp+11-11| ... | ... | @@ -3815,7 +3815,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 3815 | 3815 | |
| 3816 | 3816 | if (builtin_fn->param_count != SIZE_MAX && builtin_fn->param_count != actual_param_count) { |
| 3817 | 3817 | add_node_error(irb->codegen, node, |
| 3818 | buf_sprintf("expected %zu arguments, found %zu", | |
| 3818 | buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize, | |
| 3819 | 3819 | builtin_fn->param_count, actual_param_count)); |
| 3820 | 3820 | return irb->codegen->invalid_instruction; |
| 3821 | 3821 | } |
| ... | ... | @@ -5810,7 +5810,7 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, |
| 5810 | 5810 | render_instance_name_recursive(irb->codegen, name, &fn_entry->fndef_scope->base, irb->exec->begin_scope); |
| 5811 | 5811 | buf_appendf(name, ")"); |
| 5812 | 5812 | } else { |
| 5813 | name = buf_sprintf("(anonymous %s at %s:%zu:%zu)", container_string(kind), | |
| 5813 | name = buf_sprintf("(anonymous %s at %s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", container_string(kind), | |
| 5814 | 5814 | buf_ptr(node->owner->path), node->line + 1, node->column + 1); |
| 5815 | 5815 | } |
| 5816 | 5816 | } |
| ... | ... | @@ -6681,7 +6681,7 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru |
| 6681 | 6681 | |
| 6682 | 6682 | *bbc += 1; |
| 6683 | 6683 | if (*bbc > quota) { |
| 6684 | ir_add_error(ira, source_instruction, buf_sprintf("evaluation exceeded %zu backwards branches", quota)); | |
| 6684 | ir_add_error(ira, source_instruction, buf_sprintf("evaluation exceeded %" ZIG_PRI_usize " backwards branches", quota)); | |
| 6685 | 6685 | return false; |
| 6686 | 6686 | } |
| 6687 | 6687 | return true; |
| ... | ... | @@ -7236,7 +7236,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 7236 | 7236 | uint64_t index = val->data.x_bignum.data.x_uint; |
| 7237 | 7237 | if (index == 0 || index >= ira->codegen->error_decls.length) { |
| 7238 | 7238 | ir_add_error(ira, source_instr, |
| 7239 | buf_sprintf("integer value %" PRIu64 " represents no error", index)); | |
| 7239 | buf_sprintf("integer value %" ZIG_PRI_u64 " represents no error", index)); | |
| 7240 | 7240 | return ira->codegen->invalid_instruction; |
| 7241 | 7241 | } |
| 7242 | 7242 | |
| ... | ... | @@ -8949,7 +8949,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 8949 | 8949 | if (fn_type_id->is_var_args) { |
| 8950 | 8950 | if (call_param_count < src_param_count) { |
| 8951 | 8951 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 8952 | buf_sprintf("expected at least %zu arguments, found %zu", src_param_count, call_param_count)); | |
| 8952 | buf_sprintf("expected at least %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize "", src_param_count, call_param_count)); | |
| 8953 | 8953 | if (fn_proto_node) { |
| 8954 | 8954 | add_error_note(ira->codegen, msg, fn_proto_node, |
| 8955 | 8955 | buf_sprintf("declared here")); |
| ... | ... | @@ -8958,7 +8958,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 8958 | 8958 | } |
| 8959 | 8959 | } else if (src_param_count != call_param_count) { |
| 8960 | 8960 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 8961 | buf_sprintf("expected %zu arguments, found %zu", src_param_count, call_param_count)); | |
| 8961 | buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize "", src_param_count, call_param_count)); | |
| 8962 | 8962 | if (fn_proto_node) { |
| 8963 | 8963 | add_error_note(ira->codegen, msg, fn_proto_node, |
| 8964 | 8964 | buf_sprintf("declared here")); |
| ... | ... | @@ -9784,7 +9784,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 9784 | 9784 | size_t len = end - start; |
| 9785 | 9785 | if (index >= len) { |
| 9786 | 9786 | ir_add_error(ira, &elem_ptr_instruction->base, |
| 9787 | buf_sprintf("index %zu outside argument list of size %zu", index, len)); | |
| 9787 | buf_sprintf("index %" ZIG_PRI_usize " outside argument list of size %" ZIG_PRI_usize "", index, len)); | |
| 9788 | 9788 | return ira->codegen->builtin_types.entry_invalid; |
| 9789 | 9789 | } |
| 9790 | 9790 | size_t abs_index = start + index; |
| ... | ... | @@ -9818,7 +9818,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 9818 | 9818 | uint64_t array_len = array_type->data.array.len; |
| 9819 | 9819 | if (index >= array_len) { |
| 9820 | 9820 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 9821 | buf_sprintf("index %" PRIu64 " outside array of size %" PRIu64, | |
| 9821 | buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64, | |
| 9822 | 9822 | index, array_len)); |
| 9823 | 9823 | return ira->codegen->builtin_types.entry_invalid; |
| 9824 | 9824 | } |
| ... | ... | @@ -9876,7 +9876,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 9876 | 9876 | } |
| 9877 | 9877 | if (new_index >= mem_size) { |
| 9878 | 9878 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 9879 | buf_sprintf("index %" PRIu64 " outside pointer of size %zu", index, old_size)); | |
| 9879 | buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size)); | |
| 9880 | 9880 | return ira->codegen->builtin_types.entry_invalid; |
| 9881 | 9881 | } |
| 9882 | 9882 | } else if (is_slice(array_type)) { |
| ... | ... | @@ -9885,7 +9885,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 9885 | 9885 | uint64_t slice_len = len_field->data.x_bignum.data.x_uint; |
| 9886 | 9886 | if (index >= slice_len) { |
| 9887 | 9887 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 9888 | buf_sprintf("index %" PRIu64 " outside slice of size %" PRIu64, | |
| 9888 | buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64, | |
| 9889 | 9889 | index, slice_len)); |
| 9890 | 9890 | return ira->codegen->builtin_types.entry_invalid; |
| 9891 | 9891 | } |
| ... | ... | @@ -11986,7 +11986,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 11986 | 11986 | size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index; |
| 11987 | 11987 | if (ptr_field_index != field->src_index) { |
| 11988 | 11988 | ir_add_error(ira, &instruction->base, |
| 11989 | buf_sprintf("field '%s' has index %zu but pointer value is index %zu of struct '%s'", | |
| 11989 | buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'", | |
| 11990 | 11990 | buf_ptr(field->name), field->src_index, |
| 11991 | 11991 | ptr_field_index, buf_ptr(&container_type->name))); |
| 11992 | 11992 | return ira->codegen->builtin_types.entry_invalid; |
src/ir_print.cpp+6-5| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | #include "analyze.hpp" |
| 9 | 9 | #include "ir.hpp" |
| 10 | 10 | #include "ir_print.hpp" |
| 11 | #include "os.hpp" | |
| 11 | 12 | |
| 12 | 13 | struct IrPrint { |
| 13 | 14 | CodeGen *codegen; |
| ... | ... | @@ -28,7 +29,7 @@ static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction) { |
| 28 | 29 | ir_print_indent(irp); |
| 29 | 30 | const char *type_name = instruction->value.type ? buf_ptr(&instruction->value.type->name) : "(unknown)"; |
| 30 | 31 | const char *ref_count = ir_has_side_effects(instruction) ? |
| 31 | "-" : buf_ptr(buf_sprintf("%zu", instruction->ref_count)); | |
| 32 | "-" : buf_ptr(buf_sprintf("%" ZIG_PRI_usize "", instruction->ref_count)); | |
| 32 | 33 | fprintf(irp->f, "#%-3zu| %-12s| %-2s| ", instruction->debug_id, type_name, ref_count); |
| 33 | 34 | } |
| 34 | 35 | |
| ... | ... | @@ -40,7 +41,7 @@ static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) { |
| 40 | 41 | } |
| 41 | 42 | |
| 42 | 43 | static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) { |
| 43 | fprintf(irp->f, "#%zu", instruction->debug_id); | |
| 44 | fprintf(irp->f, "#%" ZIG_PRI_usize "", instruction->debug_id); | |
| 44 | 45 | } |
| 45 | 46 | |
| 46 | 47 | static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction) { |
| ... | ... | @@ -52,7 +53,7 @@ static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction) |
| 52 | 53 | } |
| 53 | 54 | |
| 54 | 55 | static void ir_print_other_block(IrPrint *irp, IrBasicBlock *bb) { |
| 55 | fprintf(irp->f, "$%s_%zu", bb->name_hint, bb->debug_id); | |
| 56 | fprintf(irp->f, "$%s_%" ZIG_PRI_usize "", bb->name_hint, bb->debug_id); | |
| 56 | 57 | } |
| 57 | 58 | |
| 58 | 59 | static void ir_print_return(IrPrint *irp, IrInstructionReturn *return_instruction) { |
| ... | ... | @@ -245,7 +246,7 @@ static void ir_print_container_init_list(IrPrint *irp, IrInstructionContainerIni |
| 245 | 246 | ir_print_other_instruction(irp, instruction->container_type); |
| 246 | 247 | fprintf(irp->f, "{"); |
| 247 | 248 | if (instruction->item_count > 50) { |
| 248 | fprintf(irp->f, "...(%zu items)...", instruction->item_count); | |
| 249 | fprintf(irp->f, "...(%" ZIG_PRI_usize " items)...", instruction->item_count); | |
| 249 | 250 | } else { |
| 250 | 251 | for (size_t i = 0; i < instruction->item_count; i += 1) { |
| 251 | 252 | IrInstruction *item = instruction->items[i]; |
| ... | ... | @@ -1194,7 +1195,7 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si |
| 1194 | 1195 | |
| 1195 | 1196 | for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) { |
| 1196 | 1197 | IrBasicBlock *current_block = executable->basic_block_list.at(bb_i); |
| 1197 | fprintf(irp->f, "%s_%zu:\n", current_block->name_hint, current_block->debug_id); | |
| 1198 | fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id); | |
| 1198 | 1199 | for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) { |
| 1199 | 1200 | IrInstruction *instruction = current_block->instruction_list.at(instr_i); |
| 1200 | 1201 | ir_print_instruction(irp, instruction); |
src/link.cpp+2-2| ... | ... | @@ -184,10 +184,10 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 184 | 184 | lj->args.append("-shared"); |
| 185 | 185 | |
| 186 | 186 | if (buf_len(&lj->out_file) == 0) { |
| 187 | buf_appendf(&lj->out_file, "lib%s.so.%zu.%zu.%zu", | |
| 187 | buf_appendf(&lj->out_file, "lib%s.so.%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".%" ZIG_PRI_usize "", | |
| 188 | 188 | buf_ptr(g->root_out_name), g->version_major, g->version_minor, g->version_patch); |
| 189 | 189 | } |
| 190 | soname = buf_sprintf("lib%s.so.%zu", buf_ptr(g->root_out_name), g->version_major); | |
| 190 | soname = buf_sprintf("lib%s.so.%" ZIG_PRI_usize "", buf_ptr(g->root_out_name), g->version_major); | |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | lj->args.append("-o"); |
src/os.cpp+54-7| ... | ... | @@ -10,7 +10,6 @@ |
| 10 | 10 | #include "error.hpp" |
| 11 | 11 | |
| 12 | 12 | #if defined(_WIN32) |
| 13 | #define ZIG_OS_WINDOWS | |
| 14 | 13 | |
| 15 | 14 | #if !defined(NOMINMAX) |
| 16 | 15 | #define NOMINMAX |
| ... | ... | @@ -38,11 +37,18 @@ |
| 38 | 37 | |
| 39 | 38 | #endif |
| 40 | 39 | |
| 40 | ||
| 41 | 41 | #if defined(__MACH__) |
| 42 | 42 | #include <mach/clock.h> |
| 43 | 43 | #include <mach/mach.h> |
| 44 | 44 | #endif |
| 45 | 45 | |
| 46 | #if defined(ZIG_OS_WINDOWS) | |
| 47 | static double win32_time_resolution; | |
| 48 | #elif defined(__MACH__) | |
| 49 | static clock_serv_t cclock; | |
| 50 | #endif | |
| 51 | ||
| 46 | 52 | #include <stdlib.h> |
| 47 | 53 | #include <errno.h> |
| 48 | 54 | #include <time.h> |
| ... | ... | @@ -118,16 +124,24 @@ void os_path_dirname(Buf *full_path, Buf *out_dirname) { |
| 118 | 124 | return os_path_split(full_path, out_dirname, nullptr); |
| 119 | 125 | } |
| 120 | 126 | |
| 127 | bool os_is_sep(uint8_t c) { | |
| 128 | #if defined(ZIG_OS_WINDOWS) | |
| 129 | return c == '\\' || c == '/'; | |
| 130 | #else | |
| 131 | return c == '/'; | |
| 132 | #endif | |
| 133 | } | |
| 134 | ||
| 121 | 135 | void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename) { |
| 122 | 136 | size_t len = buf_len(full_path); |
| 123 | 137 | if (len != 0) { |
| 124 | 138 | size_t last_index = len - 1; |
| 125 | if (buf_ptr(full_path)[last_index] == '/') { | |
| 139 | if (os_is_sep(buf_ptr(full_path)[last_index])) { | |
| 126 | 140 | last_index -= 1; |
| 127 | 141 | } |
| 128 | 142 | for (size_t i = last_index;;) { |
| 129 | 143 | uint8_t c = buf_ptr(full_path)[i]; |
| 130 | if (c == '/') { | |
| 144 | if (os_is_sep(c)) { | |
| 131 | 145 | if (out_dirname) { |
| 132 | 146 | buf_init_from_mem(out_dirname, buf_ptr(full_path), i); |
| 133 | 147 | } |
| ... | ... | @@ -177,7 +191,7 @@ void os_path_extname(Buf *full_path, Buf *out_basename, Buf *out_extname) { |
| 177 | 191 | void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path) { |
| 178 | 192 | buf_init_from_buf(out_full_path, dirname); |
| 179 | 193 | uint8_t c = *(buf_ptr(out_full_path) + buf_len(out_full_path) - 1); |
| 180 | if (c != '/') | |
| 194 | if (!os_is_sep(c)) | |
| 181 | 195 | buf_append_char(out_full_path, '/'); |
| 182 | 196 | buf_append_buf(out_full_path, basename); |
| 183 | 197 | } |
| ... | ... | @@ -214,7 +228,13 @@ int os_path_real(Buf *rel_path, Buf *out_abs_path) { |
| 214 | 228 | |
| 215 | 229 | bool os_path_is_absolute(Buf *path) { |
| 216 | 230 | #if defined(ZIG_OS_WINDOWS) |
| 217 | #error "missing os_path_is_absolute implementation" | |
| 231 | if (buf_starts_with_str(path, "/") || buf_starts_with_str(path, "\\")) | |
| 232 | return true; | |
| 233 | ||
| 234 | if (buf_len(path) >= 3 && buf_ptr(path)[1] == ':') | |
| 235 | return true; | |
| 236 | ||
| 237 | return false; | |
| 218 | 238 | #elif defined(ZIG_OS_POSIX) |
| 219 | 239 | return buf_ptr(path)[0] == '/'; |
| 220 | 240 | #else |
| ... | ... | @@ -258,7 +278,7 @@ int os_file_exists(Buf *full_path, bool *result) { |
| 258 | 278 | *result = access(buf_ptr(full_path), F_OK) != -1; |
| 259 | 279 | return 0; |
| 260 | 280 | #else |
| 261 | zig_panic("TODO implement os_file_exists for non-posix"); | |
| 281 | return GetFileAttributes(buf_ptr(full_path)) != INVALID_FILE_ATTRIBUTES; | |
| 262 | 282 | #endif |
| 263 | 283 | } |
| 264 | 284 | |
| ... | ... | @@ -465,7 +485,7 @@ static int os_exec_process_windows(const char *exe, ZigList<const char *> &args, |
| 465 | 485 | if (!GetExitCodeProcess(piProcInfo.hProcess, &exit_code)) { |
| 466 | 486 | zig_panic("GetExitCodeProcess failed"); |
| 467 | 487 | } |
| 468 | term->how == TerminationIdClean; | |
| 488 | term->how = TerminationIdClean; | |
| 469 | 489 | term->code = exit_code; |
| 470 | 490 | |
| 471 | 491 | CloseHandle(piProcInfo.hProcess); |
| ... | ... | @@ -760,6 +780,18 @@ int os_make_path(Buf *path) { |
| 760 | 780 | } |
| 761 | 781 | |
| 762 | 782 | int os_make_dir(Buf *path) { |
| 783 | #if defined(ZIG_OS_WINDOWS) | |
| 784 | if (mkdir(buf_ptr(path)) == -1) { | |
| 785 | if (errno == EEXIST) | |
| 786 | return ErrorPathAlreadyExists; | |
| 787 | if (errno == ENOENT) | |
| 788 | return ErrorFileNotFound; | |
| 789 | if (errno == EACCES) | |
| 790 | return ErrorAccess; | |
| 791 | return ErrorUnexpected; | |
| 792 | } | |
| 793 | return 0; | |
| 794 | #else | |
| 763 | 795 | if (mkdir(buf_ptr(path), 0755) == -1) { |
| 764 | 796 | if (errno == EEXIST) |
| 765 | 797 | return ErrorPathAlreadyExists; |
| ... | ... | @@ -770,4 +802,19 @@ int os_make_dir(Buf *path) { |
| 770 | 802 | return ErrorUnexpected; |
| 771 | 803 | } |
| 772 | 804 | return 0; |
| 805 | #endif | |
| 806 | } | |
| 807 | ||
| 808 | int zig_os_init(void) { | |
| 809 | #if defined(ZIG_OS_WINDOWS) | |
| 810 | unsigned __int64 frequency; | |
| 811 | if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) { | |
| 812 | win32_time_resolution = 1.0 / (double) frequency; | |
| 813 | } else { | |
| 814 | return ErrorSystemResources; | |
| 815 | } | |
| 816 | #elif defined(__MACH__) | |
| 817 | host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock); | |
| 818 | #endif | |
| 819 | return 0; | |
| 773 | 820 | } |
src/os.hpp+14| ... | ... | @@ -61,6 +61,8 @@ int os_file_exists(Buf *full_path, bool *result); |
| 61 | 61 | int os_rename(Buf *src_path, Buf *dest_path); |
| 62 | 62 | double os_get_time(void); |
| 63 | 63 | |
| 64 | bool os_is_sep(uint8_t c); | |
| 65 | ||
| 64 | 66 | #if defined(__APPLE__) |
| 65 | 67 | #define ZIG_OS_DARWIN |
| 66 | 68 | #elif defined(_WIN32) |
| ... | ... | @@ -77,4 +79,16 @@ double os_get_time(void); |
| 77 | 79 | #define ZIG_ARCH_UNKNOWN |
| 78 | 80 | #endif |
| 79 | 81 | |
| 82 | #if defined(ZIG_OS_WINDOWS) | |
| 83 | #define ZIG_PRI_usize "Iu" | |
| 84 | #define ZIG_PRI_u64 "I64u" | |
| 85 | #define ZIG_PRI_llu "I64u" | |
| 86 | #define ZIG_PRI_x64 "I64x" | |
| 87 | #else | |
| 88 | #define ZIG_PRI_usize "zu" | |
| 89 | #define ZIG_PRI_u64 PRIu64 | |
| 90 | #define ZIG_PRI_llu "llu" | |
| 91 | #define ZIG_PRI_x64 PRIx64 | |
| 92 | #endif | |
| 93 | ||
| 80 | 94 | #endif |
src/parseh.cpp+1-1| ... | ... | @@ -628,7 +628,7 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) { |
| 628 | 628 | const ParmVarDecl *param = fn_decl->getParamDecl(i); |
| 629 | 629 | const char *name = decl_name(param); |
| 630 | 630 | if (strlen(name) == 0) { |
| 631 | name_buf = buf_sprintf("arg%zu", i); | |
| 631 | name_buf = buf_sprintf("arg%" ZIG_PRI_usize "", i); | |
| 632 | 632 | } else { |
| 633 | 633 | name_buf = buf_create_from_str(name); |
| 634 | 634 | } |
src/target.cpp+1-1| ... | ... | @@ -529,7 +529,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | const char *target_o_file_ext(ZigTarget *target) { |
| 532 | if (target->env_type == ZigLLVM_MSVC) { | |
| 532 | if (target->env_type == ZigLLVM_MSVC || target->os == ZigLLVM_Win32) { | |
| 533 | 533 | return ".obj"; |
| 534 | 534 | } else { |
| 535 | 535 | return ".o"; |
std/os/path.zig+15| ... | ... | @@ -81,6 +81,9 @@ pub fn resolve(allocator: &Allocator, args: ...) -> %[]u8 { |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { |
| 84 | if (builtin.os == builtin.Os.windows) { | |
| 85 | @compileError("TODO implement os.path.resolve for windows"); | |
| 86 | } | |
| 84 | 87 | if (paths.len == 0) |
| 85 | 88 | return os.getCwd(allocator); |
| 86 | 89 | |
| ... | ... | @@ -152,6 +155,9 @@ fn testResolve(args: ...) -> []u8 { |
| 152 | 155 | } |
| 153 | 156 | |
| 154 | 157 | pub fn dirname(path: []const u8) -> []const u8 { |
| 158 | if (builtin.os == builtin.Os.windows) { | |
| 159 | @compileError("TODO implement os.path.dirname for windows"); | |
| 160 | } | |
| 155 | 161 | if (path.len == 0) |
| 156 | 162 | return path[0..0]; |
| 157 | 163 | var end_index: usize = path.len - 1; |
| ... | ... | @@ -189,6 +195,9 @@ fn testDirname(input: []const u8, expected_output: []const u8) { |
| 189 | 195 | } |
| 190 | 196 | |
| 191 | 197 | pub fn basename(path: []const u8) -> []const u8 { |
| 198 | if (builtin.os == builtin.Os.windows) { | |
| 199 | @compileError("TODO implement os.path.basename for windows"); | |
| 200 | } | |
| 192 | 201 | if (path.len == 0) |
| 193 | 202 | return []u8{}; |
| 194 | 203 | |
| ... | ... | @@ -231,6 +240,9 @@ fn testBasename(input: []const u8, expected_output: []const u8) { |
| 231 | 240 | /// resolve to the same path (after calling ::resolve on each), a zero-length |
| 232 | 241 | /// string is returned. |
| 233 | 242 | pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u8 { |
| 243 | if (builtin.os == builtin.Os.windows) { | |
| 244 | @compileError("TODO implement os.path.relative for windows"); | |
| 245 | } | |
| 234 | 246 | const resolved_from = %return resolve(allocator, from); |
| 235 | 247 | defer allocator.free(resolved_from); |
| 236 | 248 | |
| ... | ... | @@ -299,6 +311,9 @@ fn testRelative(from: []const u8, to: []const u8, expected_output: []const u8) { |
| 299 | 311 | /// extra `/` characters in ::pathname. |
| 300 | 312 | /// Caller must deallocate result. |
| 301 | 313 | pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 { |
| 314 | if (builtin.os == builtin.Os.windows) { | |
| 315 | @compileError("TODO implement os.path.real for windows"); | |
| 316 | } | |
| 302 | 317 | const fd = %return os.posixOpen(pathname, posix.O_PATH|posix.O_NONBLOCK|posix.O_CLOEXEC, 0, allocator); |
| 303 | 318 | defer os.posixClose(fd); |
| 304 | 319 |