The main idea here is that there are now 2 ways to get a stage1 zig binary: * The cmake path. Requirements: cmake, system C++ compiler, system LLVM, LLD, Clang libraries, compiled by the system C++ compiler. * The zig path. Requirements: a zig installation, system LLVM, LLD, Clang libraries, compiled by the zig installation. Note that the former can be used to now take the latter path. Removed config.h.in and config.zig.in. The build.zig script no longer is coupled to the cmake script. cmake no longer tries to determine the zig version. A build with cmake will yield a stage1 zig binary that reports 0.0.0+zig0. This is going to get reverted. `zig build` now accepts `-Dstage1` which will build the stage1 compiler, and put the stage2 backend behind a feature flag. build.zig is simplified to only support the use case of enabling LLVM support when the LLVM, LLD, and Clang libraries were built by zig. This part is probably sadly going to have to get reverted to make package maintainers happy. Zig build system addBuildOption supports a couple new types. The biggest reason to make this change is that the zig path is an attractive option for doing compiler development work on Windows. It allows people to work on the compiler without having MSVC installed, using only a .zip file that contains Zig + LLVM/LLD/Clang libraries.
82 lines
3.0 KiB
C++
82 lines
3.0 KiB
C++
/*
|
|
* Copyright (c) 2020 Andrew Kelley
|
|
*
|
|
* This file is part of zig, which is MIT licensed.
|
|
* See http://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#ifndef ZIG_HEAP_HPP
|
|
#define ZIG_HEAP_HPP
|
|
|
|
#include "util_base.hpp"
|
|
#include "mem.hpp"
|
|
|
|
namespace heap {
|
|
|
|
struct BootstrapAllocator final : mem::Allocator {
|
|
void init(const char *name);
|
|
void deinit();
|
|
void destruct(Allocator *allocator) {}
|
|
|
|
private:
|
|
ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate(const mem::TypeInfo &info, size_t count) final;
|
|
ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) final;
|
|
void *internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
|
|
void *internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
|
|
void internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) final;
|
|
};
|
|
|
|
struct CAllocator final : mem::Allocator {
|
|
void init(const char *name);
|
|
void deinit();
|
|
|
|
static CAllocator *construct(mem::Allocator *allocator, const char *name);
|
|
void destruct(mem::Allocator *allocator) final;
|
|
|
|
|
|
private:
|
|
ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate(const mem::TypeInfo &info, size_t count) final;
|
|
ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) final;
|
|
void *internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
|
|
void *internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
|
|
void internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) final;
|
|
|
|
};
|
|
|
|
//
|
|
// arena allocator
|
|
//
|
|
// - allocations are backed by the underlying allocator's memory
|
|
// - allocations are N:1 relationship to underlying allocations
|
|
// - dellocations are noops
|
|
// - deinit() releases all underlying memory
|
|
//
|
|
struct ArenaAllocator final : mem::Allocator {
|
|
void init(Allocator *backing, const char *name);
|
|
void deinit();
|
|
|
|
static ArenaAllocator *construct(mem::Allocator *allocator, mem::Allocator *backing, const char *name);
|
|
void destruct(mem::Allocator *allocator) final;
|
|
|
|
|
|
private:
|
|
ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate(const mem::TypeInfo &info, size_t count) final;
|
|
ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) final;
|
|
void *internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
|
|
void *internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
|
|
void internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) final;
|
|
|
|
struct Impl;
|
|
Impl *impl;
|
|
};
|
|
|
|
extern BootstrapAllocator bootstrap_allocator_state;
|
|
extern mem::Allocator &bootstrap_allocator;
|
|
|
|
extern CAllocator c_allocator_state;
|
|
extern mem::Allocator &c_allocator;
|
|
|
|
} // namespace heap
|
|
|
|
#endif
|