aboutsummaryrefslogtreecommitdiff
path: root/src/util_base.hpp
diff options
context:
space:
mode:
authorMichael Dusan <michael.dusan@gmail.com>2020-02-10 21:08:08 -0500
committerMichael Dusan <michael.dusan@gmail.com>2020-02-10 21:08:08 -0500
commitedb210905dcbe666fa5222bceacd2e5bdb16bb89 (patch)
tree984aec0e5bad756daf426855c54bae3c42c73eca /src/util_base.hpp
parent1cdefeb10b7496126bbb7d00709235abfee56a4a (diff)
downloadzig-edb210905dcbe666fa5222bceacd2e5bdb16bb89.tar.gz
zig-edb210905dcbe666fa5222bceacd2e5bdb16bb89.zip
stage1: memory/report overhaul
- split util_base.hpp from util.hpp - new namespaces: `mem` and `heap` - new `mem::Allocator` interface - new `heap::CAllocator` impl with global `heap::c_allocator` - new `heap::ArenaAllocator` impl - new `mem::TypeInfo` extracts names without RTTI - name extraction is enabled w/ ZIG_ENABLE_MEM_PROFILE=1 - new `mem::List` takes explicit `Allocator&` parameter - new `mem::HashMap` takes explicit `Allocator&` parameter - add Codegen.pass1_arena and use for all `ZigValue` allocs - deinit Codegen.pass1_arena early in `zig_llvm_emit_output()`
Diffstat (limited to 'src/util_base.hpp')
-rw-r--r--src/util_base.hpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/util_base.hpp b/src/util_base.hpp
new file mode 100644
index 0000000000..f6cea45c20
--- /dev/null
+++ b/src/util_base.hpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2015 Andrew Kelley
+ *
+ * This file is part of zig, which is MIT licensed.
+ * See http://opensource.org/licenses/MIT
+ */
+
+#ifndef ZIG_UTIL_BASE_HPP
+#define ZIG_UTIL_BASE_HPP
+
+#include <assert.h>
+
+#if defined(_MSC_VER)
+
+#define ATTRIBUTE_COLD __declspec(noinline)
+#define ATTRIBUTE_PRINTF(a, b)
+#define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
+#define ATTRIBUTE_NORETURN __declspec(noreturn)
+#define ATTRIBUTE_MUST_USE
+
+#define BREAKPOINT __debugbreak()
+
+#else
+
+#define ATTRIBUTE_COLD __attribute__((cold))
+#define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b)))
+#define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
+#define ATTRIBUTE_NORETURN __attribute__((noreturn))
+#define ATTRIBUTE_MUST_USE __attribute__((warn_unused_result))
+
+#if defined(__MINGW32__) || defined(__MINGW64__)
+#define BREAKPOINT __debugbreak()
+#elif defined(__i386__) || defined(__x86_64__)
+#define BREAKPOINT __asm__ volatile("int $0x03");
+#elif defined(__clang__)
+#define BREAKPOINT __builtin_debugtrap()
+#elif defined(__GNUC__)
+#define BREAKPOINT __builtin_trap()
+#else
+#include <signal.h>
+#define BREAKPOINT raise(SIGTRAP)
+#endif
+
+#endif
+
+ATTRIBUTE_COLD
+ATTRIBUTE_NORETURN
+ATTRIBUTE_PRINTF(1, 2)
+void zig_panic(const char *format, ...);
+
+static inline void zig_assert(bool ok, const char *file, int line, const char *func) {
+ if (!ok) {
+ zig_panic("Assertion failed at %s:%d in %s. This is a bug in the Zig compiler.", file, line, func);
+ }
+}
+
+#ifdef _WIN32
+#define __func__ __FUNCTION__
+#endif
+
+#define zig_unreachable() zig_panic("Unreachable at %s:%d in %s. This is a bug in the Zig compiler.", __FILE__, __LINE__, __func__)
+
+// Assertions in stage1 are always on, and they call zig @panic.
+#undef assert
+#define assert(ok) zig_assert(ok, __FILE__, __LINE__, __func__)
+
+#endif