From 3ba916584db5485c38ebf2390e8d22bc6d81bf8e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 4 Nov 2022 18:47:19 -0700 Subject: actually remove stage1 --- src/stage1/util.cpp | 115 ---------------------------------------------------- 1 file changed, 115 deletions(-) delete mode 100644 src/stage1/util.cpp (limited to 'src/stage1/util.cpp') diff --git a/src/stage1/util.cpp b/src/stage1/util.cpp deleted file mode 100644 index e1e167adf9..0000000000 --- a/src/stage1/util.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2015 Andrew Kelley - * - * This file is part of zig, which is MIT licensed. - * See http://opensource.org/licenses/MIT - */ - -#include "util.hpp" -#include "stage2.h" - -#include -#include - -void zig_panic(const char *format, ...) { - va_list ap; - va_start(ap, format); - vfprintf(stderr, format, ap); - fflush(stderr); - va_end(ap); - stage2_panic("", 0); - abort(); -} - -// Ported from std/mem.zig. -bool SplitIterator_isSplitByte(SplitIterator *self, uint8_t byte) { - for (size_t i = 0; i < self->split_bytes.len; i += 1) { - if (byte == self->split_bytes.ptr[i]) { - return true; - } - } - return false; -} - -// Ported from std/mem.zig. -Optional> SplitIterator_next(SplitIterator *self) { - // move to beginning of token - while (self->index < self->buffer.len && - SplitIterator_isSplitByte(self, self->buffer.ptr[self->index])) - { - self->index += 1; - } - size_t start = self->index; - if (start == self->buffer.len) { - return {}; - } - - // move to end of token - while (self->index < self->buffer.len && - !SplitIterator_isSplitByte(self, self->buffer.ptr[self->index])) - { - self->index += 1; - } - size_t end = self->index; - - return Optional>::some(self->buffer.slice(start, end)); -} - -// Ported from std/mem.zig. -// This one won't collapse multiple separators into one, so you could use it, for example, -// to parse Comma Separated Value format. -Optional> SplitIterator_next_separate(SplitIterator *self) { - // move to beginning of token - if (self->index < self->buffer.len && - SplitIterator_isSplitByte(self, self->buffer.ptr[self->index])) - { - self->index += 1; - } - size_t start = self->index; - if (start == self->buffer.len) { - return {}; - } - - // move to end of token - while (self->index < self->buffer.len && - !SplitIterator_isSplitByte(self, self->buffer.ptr[self->index])) - { - self->index += 1; - } - size_t end = self->index; - - return Optional>::some(self->buffer.slice(start, end)); -} - -// Ported from std/mem.zig -Slice SplitIterator_rest(SplitIterator *self) { - // move to beginning of token - size_t index = self->index; - while (index < self->buffer.len && SplitIterator_isSplitByte(self, self->buffer.ptr[index])) { - index += 1; - } - return self->buffer.sliceFrom(index); -} - -// Ported from std/mem.zig -SplitIterator memSplit(Slice buffer, Slice split_bytes) { - return SplitIterator{0, buffer, split_bytes}; -} - -void zig_pretty_print_bytes(FILE *f, double n) { - if (n > 1024.0 * 1024.0 * 1024.0) { - fprintf(f, "%.03f GiB", n / 1024.0 / 1024.0 / 1024.0); - return; - } - if (n > 1024.0 * 1024.0) { - fprintf(f, "%.03f MiB", n / 1024.0 / 1024.0); - return; - } - if (n > 1024.0) { - fprintf(f, "%.03f KiB", n / 1024.0); - return; - } - fprintf(f, "%.03f bytes", n ); - return; -} - -- cgit v1.2.3