Build on macOS again, fix the package and playground CI jobs

macOS: the self-hosted compiler backend and its file, process and timer
modules called Linux-only libc (__errno_location, pipe2, statx,
clock_nanosleep, sched_getaffinity, Linux open flags and clock ids), and
the checked bootstrap C was generated for Linux only. std/process_run_linux,
std/file_tree_linux, std/timer_linux and cmd/compiler_backend_process gain
Darwin branches (pipe + FD_CLOEXEC, __error, fstatat with the 64-bit-inode
record, nanosleep, CLOCK_MONOTONIC 6, Darwin open flags and sysconf name),
and open/fcntl take their mode as a variadic argument as Apple's arm64 ABI
requires. Darwin's $INODE64 symbols are resolved at run time, so one seed
serves Apple Silicon and Intel. bootstrap/darwin holds the Darwin copies of
the three platform modules, generated with the Darwin defines; the Makefile
selects them on a Darwin host, passes ZIRAN_DEFINES when generating those
modules, and check-bootstrap/update-bootstrap cover them.

Package jobs: check.yml ran the deleted test_native_package.sh wrapper; it
now runs scripts/test_native_package.zi directly.

Site: the browser playground linked the deleted cmd/zi2zx/zir_asm_lower.c
and missed ZxExecBuild's debug argument; it now compiles the checked Ziran
lowering from bootstrap/compiler_zir_lower.

The widget table generator measures native ZX, the default on Linux
x86-64 and AArch64, labels the column accordingly and records host load.
This commit is contained in:
waozi committed 2026-11-16 00:25:27 -03:00
1 parent c97860d964
commit 2b49d83b60
52 files changed
+17071 -285

No files matched your search

+3 -1
View File
@@ -143,7 +143,9 @@ jobs:
- name: Test every backend from source and saved IR with the current compiler
working-directory: package
run: |
sh "$GITHUB_WORKSPACE/scripts/test_native_package.sh" \
"$GITHUB_WORKSPACE/build/bin/ziran" run --target=c \
--root "$GITHUB_WORKSPACE/scripts" --module-path "$GITHUB_WORKSPACE/tests" \
"$GITHUB_WORKSPACE/scripts/test_native_package.zi" -- \
--ziran "$GITHUB_WORKSPACE/build/bin/ziran" \
--tools "$GITHUB_WORKSPACE/build/bin" \
--source "tests/${{ matrix.package }}_test.zi" \
+32 -9
View File
@@ -144,8 +144,11 @@ SERVICES_READY := $(SERVICES_C)/.generated
LINK_C := $(BUILD_DIR)/compiler-link
LINK_READY := $(LINK_C)/.generated
endif
# The seed's file, process and timer modules are generated per platform:
# Darwin's copies come from the same sources with the Darwin defines.
BOOTSTRAP_PLATFORM := $(if $(DARWIN_TARGET),bootstrap/darwin,bootstrap)
ifeq ($(BOOTSTRAP),1)
RUNTIME_EMIT_C := bootstrap/compiler_runtime_emit
RUNTIME_EMIT_C := $(BOOTSTRAP_PLATFORM)/compiler_runtime_emit
RUNTIME_EMIT_READY := $(RUNTIME_EMIT_C)/compiler_runtime_emit.c $(RUNTIME_EMIT_C)/compiler_runtime_emit.h \
$(RUNTIME_EMIT_C)/file.c $(RUNTIME_EMIT_C)/file.h $(RUNTIME_EMIT_C)/file_linux.c $(RUNTIME_EMIT_C)/file_linux.h \
$(RUNTIME_EMIT_C)/c_string.c $(RUNTIME_EMIT_C)/c_string.h $(RUNTIME_EMIT_C)/result.h \
@@ -164,8 +167,8 @@ endif
override CFLAGS += -I$(IR_C) -I$(SCANNER_C) -I$(TEXT_C) -I$(SOURCE_C) -I$(DECLARATION_C) -I$(ENUM_C) -I$(TYPE_C) -I$(EXPRESSION_C) -I$(STATEMENT_C) -I$(PROOF_KERNEL_C) -I$(PROOF_C) -I$(BUNDLE_C) -I$(LAW_C) -I$(SERVICES_C) -I$(LINK_C)
override CFLAGS += -I$(RUNTIME_EMIT_C)
ifeq ($(BOOTSTRAP),1)
BACKEND_CACHE_C := bootstrap/compiler_backend_cache
BACKEND_PROCESS_C := bootstrap/compiler_backend_process
BACKEND_CACHE_C := $(BOOTSTRAP_PLATFORM)/compiler_backend_cache
BACKEND_PROCESS_C := $(BOOTSTRAP_PLATFORM)/compiler_backend_process
BACKEND_CACHE_READY := $(filter %.c %.h,$(wildcard $(BACKEND_CACHE_C)/*))
BACKEND_PROCESS_READY := $(filter %.c %.h,$(wildcard $(BACKEND_PROCESS_C)/*))
else
@@ -179,8 +182,9 @@ $(BACKEND_PROCESS_C)/%.c $(BACKEND_PROCESS_C)/%.h: $(BACKEND_PROCESS_C)/.generat
@test -f $@
endif
BACKEND_PROCESS_FILES := $(filter %.c %.h,$(wildcard $(BACKEND_PROCESS_C)/*))
BACKEND_BOOTSTRAP_FILES := $(filter %.c %.h,$(wildcard bootstrap/compiler_backend_cache/*)) \
$(filter %.c %.h,$(wildcard bootstrap/compiler_backend_process/*))
BACKEND_BOOTSTRAP_FILES := $(filter %.c %.h,$(wildcard $(BOOTSTRAP_PLATFORM)/compiler_backend_cache/*)) \
$(filter %.c %.h,$(wildcard $(BOOTSTRAP_PLATFORM)/compiler_backend_process/*)) \
$(filter %.c %.h,$(wildcard $(BOOTSTRAP_PLATFORM)/compiler_runtime_emit/*))
ifeq ($(BOOTSTRAP),1)
NATIVE_NAMES_C := bootstrap/compiler_native_names
NATIVE_NAMES_READY := $(NATIVE_NAMES_C)/compiler_native_names.c $(NATIVE_NAMES_C)/compiler_native_names.h
@@ -571,14 +575,14 @@ $(BUILD_DIR)/runtime_headers.c: scripts/embed_headers.sh $(RUNTIME_HEADERS) forc
$(RUNTIME_EMIT_C)/.generated: cmd/compiler_runtime_emit.zi std/file.zi std/file_linux.zi \
std/c_string.zi std/result.zi std/vec.zi $(BOOTSTRAP_BIN)
$(BOOTSTRAP_BIN) --no-main --root cmd --module-path std \
$(BOOTSTRAP_BIN) --no-main $(ZIRAN_DEFINES) --root cmd --module-path std \
-o $(RUNTIME_EMIT_C) cmd/compiler_runtime_emit.zi
touch $@
$(BACKEND_CACHE_C)/.generated: cmd/compiler_backend_cache.zi std/file.zi std/file_linux.zi \
std/file_tree_linux.zi std/environment.zi std/environment_linux.zi std/c_string.zi std/vec.zi \
std/text_tools.zi std/sort.zi std/process_run_linux.zi std/byte_text_linux.zi $(BOOTSTRAP_BIN)
$(BOOTSTRAP_BIN) --no-main --root cmd --module-path std \
$(BOOTSTRAP_BIN) --no-main $(ZIRAN_DEFINES) --root cmd --module-path std \
-o $(BACKEND_CACHE_C) cmd/compiler_backend_cache.zi
touch $@
@@ -586,7 +590,7 @@ $(BACKEND_PROCESS_C)/.generated: cmd/compiler_backend_process.zi cmd/compiler_ba
std/file.zi std/file_linux.zi std/file_tree_linux.zi std/environment.zi std/environment_linux.zi \
std/c_string.zi std/vec.zi std/text_tools.zi std/sort.zi std/timer_linux.zi \
std/process_run_linux.zi std/byte_text_linux.zi $(BOOTSTRAP_BIN)
$(BOOTSTRAP_BIN) --no-main --root cmd --module-path std \
$(BOOTSTRAP_BIN) --no-main $(ZIRAN_DEFINES) --root cmd --module-path std \
-o $(BACKEND_PROCESS_C) cmd/compiler_backend_process.zi
touch $@
@@ -758,13 +762,25 @@ BOOTSTRAP_MODULES := scan text source declaration enum type expression statement
GENERATE_BOOTSTRAP = env -u DISPLAY -u WAYLAND_DISPLAY $(BIN_DIR)/zi2c --no-main --root cmd \
-o $(BUILD_DIR)/bootstrap-check cmd/compiler_$$module.zi
BOOTSTRAP_MODULES += parse
# Darwin's seed copies of the platform modules, generated with the defines a
# Darwin host passes; one copy serves Apple Silicon and Intel.
DARWIN_BOOTSTRAP_MODULES := runtime_emit backend_cache backend_process
GENERATE_DARWIN_BOOTSTRAP = env -u DISPLAY -u WAYLAND_DISPLAY $(BIN_DIR)/zi2c --no-main \
--target-os macos --define __APPLE__ --define __aarch64__ --root cmd \
-o $(BUILD_DIR)/bootstrap-check-darwin cmd/compiler_$$module.zi
check-bootstrap: $(BIN_DIR)/zi2c
@set -e; for module in $(BOOTSTRAP_MODULES); do \
$(GENERATE_BOOTSTRAP); \
for file in $$(find bootstrap/compiler_$$module -maxdepth 1 -type f ! -name '*.o' ! -name '*.d' ! -name '.build.lock' -printf '%f\n' | sort); do \
cmp bootstrap/compiler_$$module/$$file $(BUILD_DIR)/bootstrap-check/$$file; \
done; \
done; echo "bootstrap matches: $(BOOTSTRAP_MODULES)"
done; \
for module in $(DARWIN_BOOTSTRAP_MODULES); do \
$(GENERATE_DARWIN_BOOTSTRAP); \
for file in $$(find bootstrap/compiler_$$module -maxdepth 1 -type f ! -name '*.o' ! -name '*.d' ! -name '.build.lock' -printf '%f\n' | sort); do \
cmp bootstrap/darwin/compiler_$$module/$$file $(BUILD_DIR)/bootstrap-check-darwin/$$file; \
done; \
done; echo "bootstrap matches: $(BOOTSTRAP_MODULES); darwin: $(DARWIN_BOOTSTRAP_MODULES)"
update-bootstrap: $(BIN_DIR)/zi2c
@set -e; for module in $(BOOTSTRAP_MODULES); do \
@@ -785,6 +801,13 @@ update-bootstrap: $(BIN_DIR)/zi2c
for file in $$files; do \
cp $(BUILD_DIR)/bootstrap-check/$$file bootstrap/compiler_$$module/; \
done; \
done; \
for module in $(DARWIN_BOOTSTRAP_MODULES); do \
$(GENERATE_DARWIN_BOOTSTRAP); \
mkdir -p bootstrap/darwin/compiler_$$module; \
for file in $$(find bootstrap/compiler_$$module -maxdepth 1 -type f ! -name '*.o' ! -name '*.d' ! -name '.build.lock' -printf '%f\n'); do \
cp $(BUILD_DIR)/bootstrap-check-darwin/$$file bootstrap/darwin/compiler_$$module/; \
done; \
done
endif
@@ -28,7 +28,7 @@ static inline int32_t ZiShrS32(int32_t a, uint64_t s, int w) {
}
#endif
#endif
__type_c53c2d7c4913dc02 zir_g_b176900cac1241ec = {0};
__type_c53c2d7c4913dc02 zir_g_45df0357d1607758 = {0};
int32_t
compiler_backend_process_WorkerLimit(void)
@@ -75,7 +75,7 @@ compiler_backend_process_WorkerLimit(void)
int32_t
compiler_backend_process_BuildLock(String directory)
{
zir_8a167d86ad221008_Results__string__bool results_1_ = compiler_backend_process_PathJoin(directory, StringLiteral(".build.lock"));
zir_e4358493ea4607d1_Results__string__bool results_1_ = compiler_backend_process_PathJoin(directory, StringLiteral(".build.lock"));
String lock_path = results_1_.value_0;
bool made = results_1_.value_1;
if (!made) {
@@ -96,7 +96,7 @@ compiler_backend_process_BuildLock(String directory)
}
return cleanup_return_0;
}
int32_t descriptor = zir_f_1cd1ecb166af98b1_OpenLock(&(name[0]), 393282, 384);
int32_t descriptor = zir_f_1cd1ecb166af98b1_OpenLock(&(name[0]), 393282, 384LL);
if (descriptor < 0) {
int32_t cleanup_return_1 = -1;
{
@@ -391,7 +391,7 @@ compiler_backend_process_PathName(String value)
return StringRange(value, (int64_t)at, (int64_t)(int64_t)(value).length);
}
zir_8a167d86ad221008_Results__string__bool
zir_e4358493ea4607d1_Results__string__bool
compiler_backend_process_PathJoin(String left, String right)
{
__type_838711075b90279a bytes = {0};
@@ -413,7 +413,7 @@ compiler_backend_process_PathJoin(String left, String right)
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
zir_8a167d86ad221008_Results__string__bool value_5 = (zir_8a167d86ad221008_Results__string__bool){.value_0 = StringLiteral(""), .value_1 = false};
zir_e4358493ea4607d1_Results__string__bool value_5 = (zir_e4358493ea4607d1_Results__string__bool){.value_0 = StringLiteral(""), .value_1 = false};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
@@ -434,7 +434,7 @@ compiler_backend_process_PathJoin(String left, String right)
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
zir_8a167d86ad221008_Results__string__bool value_9 = (zir_8a167d86ad221008_Results__string__bool){.value_0 = StringLiteral(""), .value_1 = false};
zir_e4358493ea4607d1_Results__string__bool value_9 = (zir_e4358493ea4607d1_Results__string__bool){.value_0 = StringLiteral(""), .value_1 = false};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
@@ -459,7 +459,7 @@ compiler_backend_process_PathJoin(String left, String right)
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
zir_8a167d86ad221008_Results__string__bool value_12 = (zir_8a167d86ad221008_Results__string__bool){.value_0 = StringLiteral(""), .value_1 = false};
zir_e4358493ea4607d1_Results__string__bool value_12 = (zir_e4358493ea4607d1_Results__string__bool){.value_0 = StringLiteral(""), .value_1 = false};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
@@ -473,7 +473,7 @@ compiler_backend_process_PathJoin(String left, String right)
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
zir_8a167d86ad221008_Results__string__bool value_15 = (zir_8a167d86ad221008_Results__string__bool){.value_0 = result, .value_1 = true};
zir_e4358493ea4607d1_Results__string__bool value_15 = (zir_e4358493ea4607d1_Results__string__bool){.value_0 = result, .value_1 = true};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
@@ -481,7 +481,7 @@ compiler_backend_process_PathJoin(String left, String right)
return value_15;
}
zir_8a167d86ad221008_Results__string__bool
zir_e4358493ea4607d1_Results__string__bool
compiler_backend_process_PathSuffix(String value, String suffix)
{
__type_838711075b90279a bytes = {0};
@@ -519,7 +519,7 @@ compiler_backend_process_PathSuffix(String value, String suffix)
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
zir_8a167d86ad221008_Results__string__bool value_8 = (zir_8a167d86ad221008_Results__string__bool){.value_0 = StringLiteral(""), .value_1 = false};
zir_e4358493ea4607d1_Results__string__bool value_8 = (zir_e4358493ea4607d1_Results__string__bool){.value_0 = StringLiteral(""), .value_1 = false};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
@@ -533,7 +533,7 @@ compiler_backend_process_PathSuffix(String value, String suffix)
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
zir_8a167d86ad221008_Results__string__bool value_11 = (zir_8a167d86ad221008_Results__string__bool){.value_0 = result, .value_1 = true};
zir_e4358493ea4607d1_Results__string__bool value_11 = (zir_e4358493ea4607d1_Results__string__bool){.value_0 = result, .value_1 = true};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
@@ -1105,7 +1105,7 @@ compiler_backend_process_FinishCompile(String out, String name, bool forced_lang
value_5: ;
}
String entry_name = value_4;
zir_8a167d86ad221008_Results__string__bool results_2_ = compiler_backend_process_PathJoin(out, entry_name);
zir_e4358493ea4607d1_Results__string__bool results_2_ = compiler_backend_process_PathJoin(out, entry_name);
String path = results_2_.value_0;
bool made = results_2_.value_1;
if (!made) {
@@ -1130,7 +1130,7 @@ compiler_backend_process_FinishCompile(String out, String name, bool forced_lang
return false;
}
compiler_backend_process_SortPaths(files);
zir_8a167d86ad221008_Results__string__bool results_3_ = compiler_backend_process_PathJoin(out, StringLiteral(".objects"));
zir_e4358493ea4607d1_Results__string__bool results_3_ = compiler_backend_process_PathJoin(out, StringLiteral(".objects"));
String object_directory = results_3_.value_0;
bool made = results_3_.value_1;
if (!made) {
@@ -1199,7 +1199,7 @@ compiler_backend_process_FinishCompile(String out, String name, bool forced_lang
Results__pu8__bool
compiler_backend_process_ObjectPath(String out, String relative)
{
zir_8a167d86ad221008_Results__string__bool results_5_ = compiler_backend_process_PathJoin(out, StringLiteral(".objects"));
zir_e4358493ea4607d1_Results__string__bool results_5_ = compiler_backend_process_PathJoin(out, StringLiteral(".objects"));
String root = results_5_.value_0;
bool root_ok = results_5_.value_1;
if (!root_ok) {
@@ -1213,7 +1213,7 @@ compiler_backend_process_ObjectPath(String out, String relative)
}
return cleanup_return_0;
}
zir_8a167d86ad221008_Results__string__bool results_6_ = compiler_backend_process_PathJoin(root, relative_object);
zir_e4358493ea4607d1_Results__string__bool results_6_ = compiler_backend_process_PathJoin(root, relative_object);
String joined = results_6_.value_0;
bool made = results_6_.value_1;
if (!made) {
@@ -1581,7 +1581,7 @@ compiler_backend_process_CompileAndLink(String out, String name, bool forced_lan
added = true;
}
String object = compiler_backend_process_CText(ZIRAN_VEC_INDEX((*(objects)).data, (*(objects)).count, index));
zir_8a167d86ad221008_Results__string__bool results_7_ = compiler_backend_process_PathSuffix(object, StringLiteral(".d"));
zir_e4358493ea4607d1_Results__string__bool results_7_ = compiler_backend_process_PathSuffix(object, StringLiteral(".d"));
String dependency = results_7_.value_0;
bool dependency_ok = results_7_.value_1;
if (dependency_ok) {
@@ -1642,7 +1642,7 @@ compiler_backend_process_CompileAndLink(String out, String name, bool forced_lan
added = value_38;
}
if (added) {
zir_8a167d86ad221008_Results__string__bool results_8_ = compiler_backend_process_PathSuffix(object, StringLiteral(".inputs"));
zir_e4358493ea4607d1_Results__string__bool results_8_ = compiler_backend_process_PathSuffix(object, StringLiteral(".inputs"));
String inputs = results_8_.value_0;
bool inputs_ok = results_8_.value_1;
if (inputs_ok) {
@@ -2133,7 +2133,7 @@ compiler_backend_process_LinkOwnedObjects(String out, String name, bool forced_l
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
return false;
}
zir_8a167d86ad221008_Results__string__bool results_9_ = compiler_backend_process_PathJoin(link_directory, name);
zir_e4358493ea4607d1_Results__string__bool results_9_ = compiler_backend_process_PathJoin(link_directory, name);
String temporary = results_9_.value_0;
bool temporary_ok = results_9_.value_1;
if (!temporary_ok) {
@@ -2290,7 +2290,7 @@ compiler_backend_process_ReleaseBuildValues(__type_21092c8252d3dcaa* base, __typ
bool
compiler_backend_process_MoveLinkOutput(String directory, String out, String name)
{
zir_8a167d86ad221008_Results__string__bool results_10_ = compiler_backend_process_PathJoin(directory, name);
zir_e4358493ea4607d1_Results__string__bool results_10_ = compiler_backend_process_PathJoin(directory, name);
String temporary_path = results_10_.value_0;
bool temporary_ok = results_10_.value_1;
if (!temporary_ok) {
@@ -2341,10 +2341,10 @@ compiler_backend_process_MoveLinkOutput(String directory, String out, String nam
if (StringEqual(entry_name, StringLiteral(".")) || StringEqual(entry_name, StringLiteral("..")) || StringEqual(entry_name, name)) {
continue;
}
zir_8a167d86ad221008_Results__string__bool results_11_ = compiler_backend_process_PathJoin(directory, entry_name);
zir_e4358493ea4607d1_Results__string__bool results_11_ = compiler_backend_process_PathJoin(directory, entry_name);
String source = results_11_.value_0;
bool source_ok = results_11_.value_1;
zir_8a167d86ad221008_Results__string__bool results_12_ = compiler_backend_process_PathJoin(out, entry_name);
zir_e4358493ea4607d1_Results__string__bool results_12_ = compiler_backend_process_PathJoin(out, entry_name);
String destination = results_12_.value_0;
bool destination_ok = results_12_.value_1;
moved = source_ok && destination_ok && RenamePath(source, destination);
@@ -2360,7 +2360,7 @@ compiler_backend_process_MoveLinkOutput(String directory, String out, String nam
}
return cleanup_return_2;
}
zir_8a167d86ad221008_Results__string__bool results_13_ = compiler_backend_process_PathJoin(out, name);
zir_e4358493ea4607d1_Results__string__bool results_13_ = compiler_backend_process_PathJoin(out, name);
String final = results_13_.value_0;
bool final_ok = results_13_.value_1;
if (!final_ok) {
@@ -2648,7 +2648,7 @@ compiler_backend_process_ErrnoValue(void)
void
compiler_backend_process_SetCloexec(int32_t descriptor)
{
zir_f_1cd1ecb166af98b1_FcntlCloexec(descriptor, 2, 1);
zir_f_1cd1ecb166af98b1_FcntlCloexec(descriptor, 2, 1LL);
}
void
@@ -2759,8 +2759,8 @@ compiler_backend_process_ProfileEnd(String phase, uint64_t started)
uint8_t*
compiler_backend_process_ProfileName(String name)
{
for (int64_t it_index = 0LL; it_index < zir_g_b176900cac1241ec.count; it_index++) {
String value = ZIRAN_VEC_INDEX((zir_g_b176900cac1241ec).data, (zir_g_b176900cac1241ec).count, it_index);
for (int64_t it_index = 0LL; it_index < zir_g_45df0357d1607758.count; it_index++) {
String value = ZIRAN_VEC_INDEX((zir_g_45df0357d1607758).data, (zir_g_45df0357d1607758).count, it_index);
if (StringEqual(value, name)) {
OwnedText* descriptor = (OwnedText*)(&(value));
return descriptor->data;
@@ -2773,10 +2773,10 @@ compiler_backend_process_ProfileName(String name)
String owned = compiler_backend_process_CText(pointer);
String value_0 = owned;
bool value_1 = false;
void *value_2 = ZirVecGrow((void *)(zir_g_b176900cac1241ec).data, &(zir_g_b176900cac1241ec).capacity, (zir_g_b176900cac1241ec).count, sizeof(*(zir_g_b176900cac1241ec).data));
void *value_2 = ZirVecGrow((void *)(zir_g_45df0357d1607758).data, &(zir_g_45df0357d1607758).capacity, (zir_g_45df0357d1607758).count, sizeof(*(zir_g_45df0357d1607758).data));
if (value_2 != NULL) {
(zir_g_b176900cac1241ec).data = (String *)value_2;
(zir_g_b176900cac1241ec).data[(zir_g_b176900cac1241ec).count++] = value_0;
(zir_g_45df0357d1607758).data = (String *)value_2;
(zir_g_45df0357d1607758).data[(zir_g_45df0357d1607758).count++] = value_0;
value_1 = true;
}
if (!value_1) {
@@ -27,6 +27,7 @@ extern "C" {
#define LockCreate 64
#define LockCloseOnExec 131072
#define LockNoFollow 262144
#define ProcessorsOnline 84
#define AffinityBytes 128
#define ToolLogMaximum 4095
#ifndef ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
@@ -36,7 +37,7 @@ typedef struct __type_838711075b90279a __type_838711075b90279a;
typedef struct Job Job;
typedef struct SlotOutput SlotOutput;
typedef struct PendingOutput PendingOutput;
typedef struct zir_8a167d86ad221008_Results__string__bool zir_8a167d86ad221008_Results__string__bool;
typedef struct zir_e4358493ea4607d1_Results__string__bool zir_e4358493ea4607d1_Results__string__bool;
typedef struct Results__pu8__bool Results__pu8__bool;
typedef struct DiagnosticSpan DiagnosticSpan;
typedef struct PollRecord PollRecord;
@@ -82,7 +83,7 @@ struct PendingOutput {
__type_838711075b90279a output;
};
struct zir_8a167d86ad221008_Results__string__bool {
struct zir_e4358493ea4607d1_Results__string__bool {
String value_0;
bool value_1;
};
@@ -142,7 +143,7 @@ struct __type_6f55d821d15c8cbf {
int64_t capacity;
};
#endif
extern __type_c53c2d7c4913dc02 zir_g_b176900cac1241ec;
extern __type_c53c2d7c4913dc02 zir_g_45df0357d1607758;
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_SysconfByName_6b580cc2
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_SysconfByName_6b580cc2
#ifdef __APPLE__
@@ -221,18 +222,14 @@ zir_f_1cd1ecb166af98b1_MakeDirectory(uint8_t* path, int32_t mode)
return zir_foreign_zir_f_1cd1ecb166af98b1_MakeDirectory(path, mode);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_OpenLock_a91c4ec7
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_OpenLock_a91c4ec7
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_OpenLock_e4db28c4
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_OpenLock_e4db28c4
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_OpenLock(uint8_t* path, int32_t flags, uint32_t mode) __asm__("_open");
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_OpenLock(uint8_t* path, int32_t flags, ...) __asm__("_open");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_OpenLock(uint8_t* path, int32_t flags, uint32_t mode) __asm__("open");
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_OpenLock(uint8_t* path, int32_t flags, ...) __asm__("open");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_OpenLock(uint8_t* path, int32_t flags, uint32_t mode)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_OpenLock(path, flags, mode);
}
#define zir_f_1cd1ecb166af98b1_OpenLock zir_foreign_zir_f_1cd1ecb166af98b1_OpenLock
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FlockLock_d74aed45
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FlockLock_d74aed45
@@ -260,18 +257,14 @@ zir_f_1cd1ecb166af98b1_PipeRaw(int32_t* fds)
return zir_foreign_zir_f_1cd1ecb166af98b1_PipeRaw(fds);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FcntlCloexec_deab14bf
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FcntlCloexec_deab14bf
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FcntlCloexec_b27e2197
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FcntlCloexec_b27e2197
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_FcntlCloexec(int32_t descriptor, int32_t command, int32_t value) __asm__("_fcntl");
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_FcntlCloexec(int32_t descriptor, int32_t command, ...) __asm__("_fcntl");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_FcntlCloexec(int32_t descriptor, int32_t command, int32_t value) __asm__("fcntl");
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_FcntlCloexec(int32_t descriptor, int32_t command, ...) __asm__("fcntl");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_FcntlCloexec(int32_t descriptor, int32_t command, int32_t value)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_FcntlCloexec(descriptor, command, value);
}
#define zir_f_1cd1ecb166af98b1_FcntlCloexec zir_foreign_zir_f_1cd1ecb166af98b1_FcntlCloexec
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ForkRaw_b09b1e28
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ForkRaw_b09b1e28
@@ -543,8 +536,8 @@ bool compiler_backend_process_TextStartsWith(String value, String prefix);
bool compiler_backend_process_TextEndsWith(String value, String suffix);
bool compiler_backend_process_TextContains(String value, String piece);
String compiler_backend_process_PathName(String value);
zir_8a167d86ad221008_Results__string__bool compiler_backend_process_PathJoin(String left, String right);
zir_8a167d86ad221008_Results__string__bool compiler_backend_process_PathSuffix(String value, String suffix);
zir_e4358493ea4607d1_Results__string__bool compiler_backend_process_PathJoin(String left, String right);
zir_e4358493ea4607d1_Results__string__bool compiler_backend_process_PathSuffix(String value, String suffix);
void compiler_backend_process_ReleaseOwnedText(String value);
uint8_t* compiler_backend_process_AllocateText(String value);
String compiler_backend_process_CText(uint8_t* value);
@@ -10,19 +10,6 @@
#include "c_string.h"
#include "byte_text_linux.h"
#include "sort.h"
#ifndef ZIR_FOREIGN_zir_f_0ee210116da2a0c9_StatxRaw_bab3b2e7
#define ZIR_FOREIGN_zir_f_0ee210116da2a0c9_StatxRaw_bab3b2e7
#ifdef __APPLE__
int32_t zir_foreign_zir_f_0ee210116da2a0c9_StatxRaw(int32_t directory, uint8_t* path, int32_t flags, uint32_t mask, StatxRecord* output) __asm__("_statx");
#else
int32_t zir_foreign_zir_f_0ee210116da2a0c9_StatxRaw(int32_t directory, uint8_t* path, int32_t flags, uint32_t mask, StatxRecord* output) __asm__("statx");
#endif
static int32_t
zir_f_0ee210116da2a0c9_StatxRaw(int32_t directory, uint8_t* path, int32_t flags, uint32_t mask, StatxRecord* output)
{
return zir_foreign_zir_f_0ee210116da2a0c9_StatxRaw(directory, path, flags, mask, output);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_0ee210116da2a0c9_MakeDirectoryRaw_9266eb24
#define ZIR_FOREIGN_zir_f_0ee210116da2a0c9_MakeDirectoryRaw_9266eb24
#ifdef __APPLE__
@@ -88,18 +75,14 @@ zir_f_0ee210116da2a0c9_ChangeFileModeRaw(int32_t fd, uint32_t mode)
return zir_foreign_zir_f_0ee210116da2a0c9_ChangeFileModeRaw(fd, mode);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_0ee210116da2a0c9_OpenRaw_6d3762f4
#define ZIR_FOREIGN_zir_f_0ee210116da2a0c9_OpenRaw_6d3762f4
#ifndef ZIR_FOREIGN_zir_f_0ee210116da2a0c9_OpenRaw_e4db28c4
#define ZIR_FOREIGN_zir_f_0ee210116da2a0c9_OpenRaw_e4db28c4
#ifdef __APPLE__
int32_t zir_foreign_zir_f_0ee210116da2a0c9_OpenRaw(uint8_t* path, int32_t flags, int32_t mode) __asm__("_open");
int32_t zir_foreign_zir_f_0ee210116da2a0c9_OpenRaw(uint8_t* path, int32_t flags, ...) __asm__("_open");
#else
int32_t zir_foreign_zir_f_0ee210116da2a0c9_OpenRaw(uint8_t* path, int32_t flags, int32_t mode) __asm__("open");
int32_t zir_foreign_zir_f_0ee210116da2a0c9_OpenRaw(uint8_t* path, int32_t flags, ...) __asm__("open");
#endif
static int32_t
zir_f_0ee210116da2a0c9_OpenRaw(uint8_t* path, int32_t flags, int32_t mode)
{
return zir_foreign_zir_f_0ee210116da2a0c9_OpenRaw(path, flags, mode);
}
#define zir_f_0ee210116da2a0c9_OpenRaw zir_foreign_zir_f_0ee210116da2a0c9_OpenRaw
#endif
#ifndef ZIR_FOREIGN_zir_f_0ee210116da2a0c9_CloseRaw_d6ec0c1e
#define ZIR_FOREIGN_zir_f_0ee210116da2a0c9_CloseRaw_d6ec0c1e
@@ -231,19 +214,6 @@ zir_f_0ee210116da2a0c9_ProcessIdRaw(void)
return zir_foreign_zir_f_0ee210116da2a0c9_ProcessIdRaw();
}
#endif
#ifndef ZIR_FOREIGN_zir_f_0ee210116da2a0c9_ErrnoRaw_40ae2072
#define ZIR_FOREIGN_zir_f_0ee210116da2a0c9_ErrnoRaw_40ae2072
#ifdef __APPLE__
int32_t* zir_foreign_zir_f_0ee210116da2a0c9_ErrnoRaw(void) __asm__("___errno_location");
#else
int32_t* zir_foreign_zir_f_0ee210116da2a0c9_ErrnoRaw(void) __asm__("__errno_location");
#endif
static int32_t*
zir_f_0ee210116da2a0c9_ErrnoRaw(void)
{
return zir_foreign_zir_f_0ee210116da2a0c9_ErrnoRaw();
}
#endif
#ifndef ZIR_FOREIGN_zir_f_0ee210116da2a0c9_FreeOwnedRaw_c75930da
#define ZIR_FOREIGN_zir_f_0ee210116da2a0c9_FreeOwnedRaw_c75930da
#ifdef __APPLE__
@@ -283,6 +253,32 @@ zir_f_0ee210116da2a0c9_ReadLinkRaw(uint8_t* path, uint8_t* output, size_t capaci
return zir_foreign_zir_f_0ee210116da2a0c9_ReadLinkRaw(path, output, capacity);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_0ee210116da2a0c9_StatxRaw_bab3b2e7
#define ZIR_FOREIGN_zir_f_0ee210116da2a0c9_StatxRaw_bab3b2e7
#ifdef __APPLE__
int32_t zir_foreign_zir_f_0ee210116da2a0c9_StatxRaw(int32_t directory, uint8_t* path, int32_t flags, uint32_t mask, StatxRecord* output) __asm__("_statx");
#else
int32_t zir_foreign_zir_f_0ee210116da2a0c9_StatxRaw(int32_t directory, uint8_t* path, int32_t flags, uint32_t mask, StatxRecord* output) __asm__("statx");
#endif
static int32_t
zir_f_0ee210116da2a0c9_StatxRaw(int32_t directory, uint8_t* path, int32_t flags, uint32_t mask, StatxRecord* output)
{
return zir_foreign_zir_f_0ee210116da2a0c9_StatxRaw(directory, path, flags, mask, output);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_0ee210116da2a0c9_ErrnoRaw_40ae2072
#define ZIR_FOREIGN_zir_f_0ee210116da2a0c9_ErrnoRaw_40ae2072
#ifdef __APPLE__
int32_t* zir_foreign_zir_f_0ee210116da2a0c9_ErrnoRaw(void) __asm__("___errno_location");
#else
int32_t* zir_foreign_zir_f_0ee210116da2a0c9_ErrnoRaw(void) __asm__("__errno_location");
#endif
static int32_t*
zir_f_0ee210116da2a0c9_ErrnoRaw(void)
{
return zir_foreign_zir_f_0ee210116da2a0c9_ErrnoRaw();
}
#endif
#ifndef ZIRAN_MAYBE_UNUSED
#if defined(__GNUC__) || defined(__clang__)
#define ZIRAN_MAYBE_UNUSED __attribute__((unused))
@@ -290,6 +286,8 @@ zir_f_0ee210116da2a0c9_ReadLinkRaw(uint8_t* path, uint8_t* output, size_t capaci
#define ZIRAN_MAYBE_UNUSED
#endif
#endif
static PathKind file_tree_linux_PathKindOf(int32_t mode) ZIRAN_MAYBE_UNUSED;
static bool file_tree_linux_ReadPathInfo(uint8_t* name, int32_t flags, PathInfo* info) ZIRAN_MAYBE_UNUSED;
static void file_tree_linux_ReleaseOwnedText(String text) ZIRAN_MAYBE_UNUSED;
static Text file_tree_linux_CopyText(Slice bytes) ZIRAN_MAYBE_UNUSED;
static void file_tree_linux_ReleaseNames(__type_c53c2d7c4913dc02* names, int64_t from) ZIRAN_MAYBE_UNUSED;
@@ -297,6 +295,94 @@ static bool file_tree_linux_CopyTreeNewContents(String source, String target, in
static bool file_tree_linux_CopyLink(String source, String target) ZIRAN_MAYBE_UNUSED;
static bool file_tree_linux_MatchAt(String name, int64_t at, String pattern, int64_t from) ZIRAN_MAYBE_UNUSED;
static PathKind
file_tree_linux_PathKindOf(int32_t mode)
{
int32_t type = (int32_t)((uint32_t)mode & 61440u);
if (type == 32768) {
return PathKind_File;
}
if (type == 16384) {
return PathKind_Directory;
}
if (type == 40960) {
return PathKind_Link;
}
return PathKind_Other;
}
static bool
file_tree_linux_ReadPathInfo(uint8_t* name, int32_t flags, PathInfo* info)
{
StatxRecord record = {0};
if (zir_f_0ee210116da2a0c9_StatxRaw(-100, name, flags, 2047, &(record)) != 0) {
return false;
}
uint32_t* value_0 = &(info->metadata_mask);
(*value_0) = (uint32_t)((record.words)[0]);
int32_t mode = (int32_t)(((uint64_t)((uint64_t)(((record.words)[3] >> 32)) & UINT64_C(65535))));
PathKind* value_1 = &(info->kind);
int32_t value_2 = mode;
PathKind value_3 = (PathKind)(0);
{
int32_t mode = value_2;
int32_t type = (int32_t)((uint32_t)mode & 61440u);
if (type == 32768) {
value_3 = PathKind_File;
goto value_4;
}
if (type == 16384) {
value_3 = PathKind_Directory;
goto value_4;
}
if (type == 40960) {
value_3 = PathKind_Link;
goto value_4;
}
value_3 = PathKind_Other;
value_4: ;
}
(*value_1) = value_3;
uint32_t* value_5 = &(info->owner_uid);
(*value_5) = (uint32_t)(((record.words)[2] >> 32));
int32_t* value_6 = &(info->mode);
(*value_6) = (int32_t)((uint32_t)mode & 4095u);
if (((uint32_t)((uint32_t)(info->metadata_mask) & 512u)) != 0) {
int64_t* value_7 = &(info->size);
(*value_7) = (int64_t)((record.words)[5]);
}
if (((uint32_t)((uint32_t)(info->metadata_mask) & 256u)) != 0) {
uint64_t* value_8 = &(info->inode);
(*value_8) = (record.words)[4];
}
uint32_t modified_fraction = (uint32_t)((record.words)[15]);
uint32_t changed_fraction = (uint32_t)((record.words)[13]);
if (((uint32_t)((uint32_t)(info->metadata_mask) & 64u)) != 0 && modified_fraction < 1000000000) {
int64_t* value_9 = &(info->modified);
(*value_9) = (int64_t)((record.words)[14]);
uint32_t* value_10 = &(info->modified_nanoseconds);
(*value_10) = modified_fraction;
}
if (((uint32_t)((uint32_t)(info->metadata_mask) & 128u)) != 0 && changed_fraction < 1000000000) {
int64_t* value_11 = &(info->changed);
(*value_11) = (int64_t)((record.words)[12]);
uint32_t* value_12 = &(info->changed_nanoseconds);
(*value_12) = changed_fraction;
}
uint32_t* value_13 = &(info->device_major);
(*value_13) = (uint32_t)((record.words)[17]);
uint32_t* value_14 = &(info->device_minor);
(*value_14) = (uint32_t)(((record.words)[17] >> 32));
bool* value_15 = &(info->identity_valid);
bool value_16 = ((uint32_t)((uint32_t)(info->metadata_mask) & 961u)) == 961;
if (value_16) {
int64_t value_17 = info->size;
value_16 = (value_17 >= 0LL);
}
(*value_15) = value_16 && modified_fraction < 1000000000 && changed_fraction < 1000000000;
return true;
}
PathQueryResult
file_tree_linux_PathQuery(String path, bool follow_links)
{
@@ -313,7 +399,6 @@ file_tree_linux_PathQuery(String path, bool follow_links)
(*value_3) = 22;
return result;
}
StatxRecord record = {0};
int32_t value_4 = 0;
if (follow_links) {
value_4 = 0;
@@ -321,70 +406,20 @@ file_tree_linux_PathQuery(String path, bool follow_links)
value_4 = 256;
}
int32_t flags = value_4;
if (zir_f_0ee210116da2a0c9_StatxRaw(-100, &(name[0]), flags, 2047, &(record)) != 0) {
int32_t* value_5 = &(result.error);
int32_t* value_6 = zir_f_0ee210116da2a0c9_ErrnoRaw();
(*value_5) = *(value_6);
bool* value_7 = &(result.missing);
(*value_7) = result.error == 2 || result.error == 20;
PathInfo info = {0};
bool value_5 = file_tree_linux_ReadPathInfo(&(name[0]), flags, &(info));
if (!value_5) {
int32_t* value_6 = &(result.error);
int32_t* value_7 = zir_f_0ee210116da2a0c9_ErrnoRaw();
(*value_6) = *(value_7);
bool* value_8 = &(result.missing);
(*value_8) = result.error == 2 || result.error == 20;
return result;
}
PathInfo info = {0};
uint32_t* value_8 = &(info.metadata_mask);
(*value_8) = (uint32_t)((record.words)[0]);
int32_t mode = (int32_t)(((uint64_t)((uint64_t)(((record.words)[3] >> 32)) & UINT64_C(65535))));
int32_t type = (int32_t)((uint32_t)mode & 61440u);
PathKind* value_9 = &(info.kind);
(*value_9) = PathKind_Other;
if (type == 32768) {
PathKind* value_10 = &(info.kind);
(*value_10) = PathKind_File;
}
if (type == 16384) {
PathKind* value_11 = &(info.kind);
(*value_11) = PathKind_Directory;
}
if (type == 40960) {
PathKind* value_12 = &(info.kind);
(*value_12) = PathKind_Link;
}
uint32_t* value_13 = &(info.owner_uid);
(*value_13) = (uint32_t)(((record.words)[2] >> 32));
int32_t* value_14 = &(info.mode);
(*value_14) = (int32_t)((uint32_t)mode & 4095u);
if (((uint32_t)((uint32_t)(info.metadata_mask) & 512u)) != 0) {
int64_t* value_15 = &(info.size);
(*value_15) = (int64_t)((record.words)[5]);
}
if (((uint32_t)((uint32_t)(info.metadata_mask) & 256u)) != 0) {
uint64_t* value_16 = &(info.inode);
(*value_16) = (record.words)[4];
}
uint32_t modified_fraction = (uint32_t)((record.words)[15]);
uint32_t changed_fraction = (uint32_t)((record.words)[13]);
if (((uint32_t)((uint32_t)(info.metadata_mask) & 64u)) != 0 && modified_fraction < 1000000000) {
int64_t* value_17 = &(info.modified);
(*value_17) = (int64_t)((record.words)[14]);
uint32_t* value_18 = &(info.modified_nanoseconds);
(*value_18) = modified_fraction;
}
if (((uint32_t)((uint32_t)(info.metadata_mask) & 128u)) != 0 && changed_fraction < 1000000000) {
int64_t* value_19 = &(info.changed);
(*value_19) = (int64_t)((record.words)[12]);
uint32_t* value_20 = &(info.changed_nanoseconds);
(*value_20) = changed_fraction;
}
uint32_t* value_21 = &(info.device_major);
(*value_21) = (uint32_t)((record.words)[17]);
uint32_t* value_22 = &(info.device_minor);
(*value_22) = (uint32_t)(((record.words)[17] >> 32));
bool* value_23 = &(info.identity_valid);
bool value_24 = ((uint32_t)((uint32_t)(info.metadata_mask) & 961u)) == 961 && info.size >= 0LL && modified_fraction < 1000000000;
(*value_23) = value_24 && changed_fraction < 1000000000;
PathInfo* value_25 = &(result.info);
(*value_25) = info;
bool* value_26 = &(result.valid);
(*value_26) = true;
PathInfo* value_9 = &(result.info);
(*value_9) = info;
bool* value_10 = &(result.valid);
(*value_10) = true;
return result;
}
@@ -1838,7 +1873,7 @@ file_tree_linux_LockPath(String path, bool exclusive, bool wait)
if (!value_1) {
return -1;
}
int32_t fd = zir_f_0ee210116da2a0c9_OpenRaw(&(name[0]), 525377, 420);
int32_t fd = zir_f_0ee210116da2a0c9_OpenRaw(&(name[0]), 525377, 420LL);
if (fd < 0) {
return -1;
}
@@ -24,10 +24,19 @@ extern "C" {
#define BASIC_STATS 2047
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
#define zir_d_11bac2ddd8e54187 577
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
#define zir_d_8ded2ea5c118fc54 1089
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
#define zir_d_ba4d3510d74f83d1 524288
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
#define EXISTS 17
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
#define zir_d_01152c6c26cea146 4
#define zir_d_e772df0ce0bb1f83 4
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
typedef struct StatxRecord StatxRecord;
@@ -31,19 +31,6 @@ zir_f_eb6527159f8585fd_ForkRaw(void)
return zir_foreign_zir_f_eb6527159f8585fd_ForkRaw();
}
#endif
#ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_Pipe2Raw_7c968992
#define ZIR_FOREIGN_zir_f_eb6527159f8585fd_Pipe2Raw_7c968992
#ifdef __APPLE__
int32_t zir_foreign_zir_f_eb6527159f8585fd_Pipe2Raw(int32_t* fds, int32_t flags) __asm__("_pipe2");
#else
int32_t zir_foreign_zir_f_eb6527159f8585fd_Pipe2Raw(int32_t* fds, int32_t flags) __asm__("pipe2");
#endif
static int32_t
zir_f_eb6527159f8585fd_Pipe2Raw(int32_t* fds, int32_t flags)
{
return zir_foreign_zir_f_eb6527159f8585fd_Pipe2Raw(fds, flags);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_DupRaw_8536fc2b
#define ZIR_FOREIGN_zir_f_eb6527159f8585fd_DupRaw_8536fc2b
#ifdef __APPLE__
@@ -96,18 +83,14 @@ zir_f_eb6527159f8585fd_WriteRaw(int32_t fd, uint8_t* input, size_t count)
return zir_foreign_zir_f_eb6527159f8585fd_WriteRaw(fd, input, count);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_OpenRaw_6d3762f4
#define ZIR_FOREIGN_zir_f_eb6527159f8585fd_OpenRaw_6d3762f4
#ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_OpenRaw_e4db28c4
#define ZIR_FOREIGN_zir_f_eb6527159f8585fd_OpenRaw_e4db28c4
#ifdef __APPLE__
int32_t zir_foreign_zir_f_eb6527159f8585fd_OpenRaw(uint8_t* path, int32_t flags, int32_t mode) __asm__("_open");
int32_t zir_foreign_zir_f_eb6527159f8585fd_OpenRaw(uint8_t* path, int32_t flags, ...) __asm__("_open");
#else
int32_t zir_foreign_zir_f_eb6527159f8585fd_OpenRaw(uint8_t* path, int32_t flags, int32_t mode) __asm__("open");
int32_t zir_foreign_zir_f_eb6527159f8585fd_OpenRaw(uint8_t* path, int32_t flags, ...) __asm__("open");
#endif
static int32_t
zir_f_eb6527159f8585fd_OpenRaw(uint8_t* path, int32_t flags, int32_t mode)
{
return zir_foreign_zir_f_eb6527159f8585fd_OpenRaw(path, flags, mode);
}
#define zir_f_eb6527159f8585fd_OpenRaw zir_foreign_zir_f_eb6527159f8585fd_OpenRaw
#endif
#ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_ExecRaw_efd664fc
#define ZIR_FOREIGN_zir_f_eb6527159f8585fd_ExecRaw_efd664fc
@@ -213,19 +196,6 @@ zir_f_eb6527159f8585fd_SessionRaw(void)
return zir_foreign_zir_f_eb6527159f8585fd_SessionRaw();
}
#endif
#ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_ErrnoRaw_40ae2072
#define ZIR_FOREIGN_zir_f_eb6527159f8585fd_ErrnoRaw_40ae2072
#ifdef __APPLE__
int32_t* zir_foreign_zir_f_eb6527159f8585fd_ErrnoRaw(void) __asm__("___errno_location");
#else
int32_t* zir_foreign_zir_f_eb6527159f8585fd_ErrnoRaw(void) __asm__("__errno_location");
#endif
static int32_t*
zir_f_eb6527159f8585fd_ErrnoRaw(void)
{
return zir_foreign_zir_f_eb6527159f8585fd_ErrnoRaw();
}
#endif
#ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_SignalRaw_f23e3d88
#define ZIR_FOREIGN_zir_f_eb6527159f8585fd_SignalRaw_f23e3d88
#ifdef __APPLE__
@@ -239,6 +209,32 @@ zir_f_eb6527159f8585fd_SignalRaw(int32_t signal_number, SignalHandler handler)
return zir_foreign_zir_f_eb6527159f8585fd_SignalRaw(signal_number, handler);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_Pipe2Raw_7c968992
#define ZIR_FOREIGN_zir_f_eb6527159f8585fd_Pipe2Raw_7c968992
#ifdef __APPLE__
int32_t zir_foreign_zir_f_eb6527159f8585fd_Pipe2Raw(int32_t* fds, int32_t flags) __asm__("_pipe2");
#else
int32_t zir_foreign_zir_f_eb6527159f8585fd_Pipe2Raw(int32_t* fds, int32_t flags) __asm__("pipe2");
#endif
static int32_t
zir_f_eb6527159f8585fd_Pipe2Raw(int32_t* fds, int32_t flags)
{
return zir_foreign_zir_f_eb6527159f8585fd_Pipe2Raw(fds, flags);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_ErrnoRaw_40ae2072
#define ZIR_FOREIGN_zir_f_eb6527159f8585fd_ErrnoRaw_40ae2072
#ifdef __APPLE__
int32_t* zir_foreign_zir_f_eb6527159f8585fd_ErrnoRaw(void) __asm__("___errno_location");
#else
int32_t* zir_foreign_zir_f_eb6527159f8585fd_ErrnoRaw(void) __asm__("__errno_location");
#endif
static int32_t*
zir_f_eb6527159f8585fd_ErrnoRaw(void)
{
return zir_foreign_zir_f_eb6527159f8585fd_ErrnoRaw();
}
#endif
#ifndef ZIRAN_MAYBE_UNUSED
#if defined(__GNUC__) || defined(__clang__)
#define ZIRAN_MAYBE_UNUSED __attribute__((unused))
@@ -485,7 +481,7 @@ process_run_linux_Child(ProcessOptions options, Prepared* prepared, int32_t stat
int64_t offset = value_2;
value_3 = &(ZIRAN_VEC_INDEX((prepared->bytes).data, (prepared->bytes).count, offset));
}
int32_t fd = zir_f_eb6527159f8585fd_OpenRaw(value_3, 0, 0);
int32_t fd = zir_f_eb6527159f8585fd_OpenRaw(value_3, 0, 0LL);
bool value_5 = fd < 0;
if (value_5 || zir_f_eb6527159f8585fd_DupRaw(fd, 0) < 0) {
failed = true;
@@ -520,7 +516,7 @@ process_run_linux_Child(ProcessOptions options, Prepared* prepared, int32_t stat
int64_t offset = value_10;
value_11 = &(ZIRAN_VEC_INDEX((prepared->bytes).data, (prepared->bytes).count, offset));
}
int32_t fd = zir_f_eb6527159f8585fd_OpenRaw(value_11, (int32_t)((uint32_t)flags | 524288u), 420);
int32_t fd = zir_f_eb6527159f8585fd_OpenRaw(value_11, (int32_t)((uint32_t)flags | 524288u), 420LL);
bool value_13 = fd < 0;
if (value_13 || zir_f_eb6527159f8585fd_DupRaw(fd, 1) < 0) {
failed = true;
@@ -546,7 +542,7 @@ process_run_linux_Child(ProcessOptions options, Prepared* prepared, int32_t stat
int64_t offset = value_17;
value_18 = &(ZIRAN_VEC_INDEX((prepared->bytes).data, (prepared->bytes).count, offset));
}
int32_t fd = zir_f_eb6527159f8585fd_OpenRaw(value_18, 524865, 420);
int32_t fd = zir_f_eb6527159f8585fd_OpenRaw(value_18, 524865, 420LL);
bool value_20 = fd < 0;
if (value_20 || zir_f_eb6527159f8585fd_DupRaw(fd, 2) < 0) {
failed = true;
@@ -12,10 +12,16 @@
extern "C" {
#endif
#ifdef ZIRAN_PROCESS_RUN_LINUX_H_PRIVATE
#define CLOSE_ON_EXEC 524288
#define zir_d_2d0217dcdaf8a169 524288
#endif
#ifdef ZIRAN_PROCESS_RUN_LINUX_H_PRIVATE
#define zir_d_f22e9a1471997af5 4
#define zir_d_d5d6994db6c75d28 577
#endif
#ifdef ZIRAN_PROCESS_RUN_LINUX_H_PRIVATE
#define zir_d_2e3bcc0fa2017199 1089
#endif
#ifdef ZIRAN_PROCESS_RUN_LINUX_H_PRIVATE
#define zir_d_ed0a0fdef7fd3c5a 4
#endif
typedef struct ProcessArgumentSlot ProcessArgumentSlot;
typedef struct ProcessOptions ProcessOptions;
@@ -9,6 +9,7 @@
#ifdef __cplusplus
extern "C" {
#endif
#define MONOTONIC_CLOCK 1
typedef struct zir_9339a8296a493286_ClockValue zir_9339a8296a493286_ClockValue;
struct zir_9339a8296a493286_ClockValue {
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,574 @@
/* Generated by zi2c from compiler_backend_cache.zi. */
#ifndef ZIRAN_COMPILER_BACKEND_CACHE_H
#define ZIRAN_COMPILER_BACKEND_CACHE_H
#include <stdbool.h>
#include "zir_string.h"
#include "zir_slice.h"
#include "file.h"
#include "vec.h"
#include "file_tree_linux.h"
#include "environment.h"
#include "text_tools.h"
#include "sort.h"
#include "process_run_linux.h"
#include "c_string.h"
#ifdef __cplusplus
extern "C" {
#endif
#define ItemMaximum 16384
#define ProbeMaximum 65536
#define PathMaximum 4096
#define CacheMagic "Ziran C cache 1\n"
#define IdentitySeed "Ziran native object cache 4"
typedef struct Digest Digest;
#ifndef ZIRAN_CONCRETE_FORWARD___type_c53c2d7c4913dc02
#define ZIRAN_CONCRETE_FORWARD___type_c53c2d7c4913dc02
typedef struct __type_c53c2d7c4913dc02 __type_c53c2d7c4913dc02;
#endif
typedef struct Fingerprint Fingerprint;
#ifndef ZIRAN_CONCRETE_FORWARD___type_d5737c4838766181
#define ZIRAN_CONCRETE_FORWARD___type_d5737c4838766181
typedef struct __type_d5737c4838766181 __type_d5737c4838766181;
#endif
typedef struct BuildCache BuildCache;
typedef struct ClockValue ClockValue;
typedef struct HashState HashState;
typedef struct ByteView ByteView;
typedef struct View View;
#ifndef ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
#define ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
typedef struct __type_838711075b90279a __type_838711075b90279a;
#endif
struct Digest {
uint8_t bytes[32];
};
#ifndef ZIRAN_CONCRETE___type_c53c2d7c4913dc02
#define ZIRAN_CONCRETE___type_c53c2d7c4913dc02
struct __type_c53c2d7c4913dc02 {
String* data;
int64_t count;
int64_t capacity;
};
#endif
struct Fingerprint {
String path;
String parent;
Digest digest;
PathInfo info;
bool unsafe;
__type_c53c2d7c4913dc02 probes;
bool directory;
bool recent;
};
#ifndef ZIRAN_CONCRETE___type_d5737c4838766181
#define ZIRAN_CONCRETE___type_d5737c4838766181
struct __type_d5737c4838766181 {
Fingerprint* data;
int64_t count;
int64_t capacity;
};
#endif
struct BuildCache {
Digest identity;
__type_c53c2d7c4913dc02 roots;
String output;
String executable;
int64_t started_seconds;
int64_t started_nanoseconds;
__type_d5737c4838766181 files;
__type_d5737c4838766181 candidates;
bool piped;
};
struct ClockValue {
ptrdiff_t seconds;
ptrdiff_t nanoseconds;
};
struct HashState {
uint8_t bytes[128];
};
struct ByteView {
uint8_t* data;
int64_t count;
};
struct View {
uint8_t* data;
size_t count;
};
#ifndef ZIRAN_CONCRETE___type_838711075b90279a
#define ZIRAN_CONCRETE___type_838711075b90279a
struct __type_838711075b90279a {
uint8_t* data;
int64_t count;
int64_t capacity;
};
#endif
extern __type_c53c2d7c4913dc02 ProfileNames;
#ifndef ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_ClockRaw_b5740b84
#define ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_ClockRaw_b5740b84
#ifdef __APPLE__
int32_t zir_foreign_zir_f_36a3c20ab8e249b6_ClockRaw(int32_t clock, ClockValue* value) __asm__("_clock_gettime");
#else
int32_t zir_foreign_zir_f_36a3c20ab8e249b6_ClockRaw(int32_t clock, ClockValue* value) __asm__("clock_gettime");
#endif
static int32_t
zir_f_36a3c20ab8e249b6_ClockRaw(int32_t clock, ClockValue* value)
{
return zir_foreign_zir_f_36a3c20ab8e249b6_ClockRaw(clock, value);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_ShaBegin_6c69662e
#define ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_ShaBegin_6c69662e
#ifdef __APPLE__
void zir_foreign_zir_f_36a3c20ab8e249b6_ShaBegin(void* hash) __asm__("_Sha256Begin");
#else
void zir_foreign_zir_f_36a3c20ab8e249b6_ShaBegin(void* hash) __asm__("Sha256Begin");
#endif
static void
zir_f_36a3c20ab8e249b6_ShaBegin(void* hash)
{
zir_foreign_zir_f_36a3c20ab8e249b6_ShaBegin(hash);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_ShaAdd_a910f077
#define ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_ShaAdd_a910f077
#ifdef __APPLE__
void zir_foreign_zir_f_36a3c20ab8e249b6_ShaAdd(void* hash, uint8_t* bytes, size_t count) __asm__("_Sha256Add");
#else
void zir_foreign_zir_f_36a3c20ab8e249b6_ShaAdd(void* hash, uint8_t* bytes, size_t count) __asm__("Sha256Add");
#endif
static void
zir_f_36a3c20ab8e249b6_ShaAdd(void* hash, uint8_t* bytes, size_t count)
{
zir_foreign_zir_f_36a3c20ab8e249b6_ShaAdd(hash, bytes, count);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_ShaEnd_1d78bba0
#define ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_ShaEnd_1d78bba0
#ifdef __APPLE__
void zir_foreign_zir_f_36a3c20ab8e249b6_ShaEnd(void* hash, uint8_t* output) __asm__("_Sha256End");
#else
void zir_foreign_zir_f_36a3c20ab8e249b6_ShaEnd(void* hash, uint8_t* output) __asm__("Sha256End");
#endif
static void
zir_f_36a3c20ab8e249b6_ShaEnd(void* hash, uint8_t* output)
{
zir_foreign_zir_f_36a3c20ab8e249b6_ShaEnd(hash, output);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_AllocateRaw_0c09ffff
#define ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_AllocateRaw_0c09ffff
#ifdef __APPLE__
void* zir_foreign_zir_f_36a3c20ab8e249b6_AllocateRaw(size_t count, size_t size) __asm__("_calloc");
#else
void* zir_foreign_zir_f_36a3c20ab8e249b6_AllocateRaw(size_t count, size_t size) __asm__("calloc");
#endif
static void*
zir_f_36a3c20ab8e249b6_AllocateRaw(size_t count, size_t size)
{
return zir_foreign_zir_f_36a3c20ab8e249b6_AllocateRaw(count, size);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_FreeOwned_c75930da
#define ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_FreeOwned_c75930da
#ifdef __APPLE__
void zir_foreign_zir_f_36a3c20ab8e249b6_FreeOwned(void* memory) __asm__("_free");
#else
void zir_foreign_zir_f_36a3c20ab8e249b6_FreeOwned(void* memory) __asm__("free");
#endif
static void
zir_f_36a3c20ab8e249b6_FreeOwned(void* memory)
{
zir_foreign_zir_f_36a3c20ab8e249b6_FreeOwned(memory);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_ProfileCountForeign_c5a6224b
#define ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_ProfileCountForeign_c5a6224b
#ifdef __APPLE__
void zir_foreign_zir_f_36a3c20ab8e249b6_ProfileCountForeign(uint8_t* name) __asm__("_ProfileCount");
#else
void zir_foreign_zir_f_36a3c20ab8e249b6_ProfileCountForeign(uint8_t* name) __asm__("ProfileCount");
#endif
static void
zir_f_36a3c20ab8e249b6_ProfileCountForeign(uint8_t* name)
{
zir_foreign_zir_f_36a3c20ab8e249b6_ProfileCountForeign(name);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_OwnProcessId_bd88b581
#define ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_OwnProcessId_bd88b581
#ifdef __APPLE__
int32_t zir_foreign_zir_f_36a3c20ab8e249b6_OwnProcessId(void) __asm__("_getpid");
#else
int32_t zir_foreign_zir_f_36a3c20ab8e249b6_OwnProcessId(void) __asm__("getpid");
#endif
static int32_t
zir_f_36a3c20ab8e249b6_OwnProcessId(void)
{
return zir_foreign_zir_f_36a3c20ab8e249b6_OwnProcessId();
}
#endif
#ifndef ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_CurrentDirectory_a9b77685
#define ZIR_FOREIGN_zir_f_36a3c20ab8e249b6_CurrentDirectory_a9b77685
#ifdef __APPLE__
uint8_t* zir_foreign_zir_f_36a3c20ab8e249b6_CurrentDirectory(uint8_t* output, size_t size) __asm__("_getcwd");
#else
uint8_t* zir_foreign_zir_f_36a3c20ab8e249b6_CurrentDirectory(uint8_t* output, size_t size) __asm__("getcwd");
#endif
static uint8_t*
zir_f_36a3c20ab8e249b6_CurrentDirectory(uint8_t* output, size_t size)
{
return zir_foreign_zir_f_36a3c20ab8e249b6_CurrentDirectory(output, size);
}
#endif
HashState compiler_backend_cache_HashNew(void);
void compiler_backend_cache_HashByte(HashState* hash, uint8_t value);
void compiler_backend_cache_HashBytes(HashState* hash, String value);
void compiler_backend_cache_HashInteger(HashState* hash, uint64_t value);
void compiler_backend_cache_HashText(HashState* hash, String value);
void compiler_backend_cache_HashFinish(HashState* hash, Digest* output);
void compiler_backend_cache_ProfileCount(String name);
uint8_t* compiler_backend_cache_ProfileName(String name);
Slice compiler_backend_cache_BytesFromPointer(uint8_t* data, uint64_t count);
String compiler_backend_cache_Owned(String value);
void compiler_backend_cache_Release(String value);
bool compiler_backend_cache_SameText(String left, String right);
bool compiler_backend_cache_HasPrefix(String value, String prefix);
bool compiler_backend_cache_HasSuffix(String value, String suffix);
bool compiler_backend_cache_Contains(String value, String piece);
String compiler_backend_cache_TextName(String value);
String compiler_backend_cache_JoinTemporary(String left, String right);
String compiler_backend_cache_JoinPath(String left, String right);
bool compiler_backend_cache_AppendOwned(__type_c53c2d7c4913dc02* values, String value);
void compiler_backend_cache_ClearNames(__type_c53c2d7c4913dc02* values);
String compiler_backend_cache_Executable(String command);
bool compiler_backend_cache_Runnable(String path);
String compiler_backend_cache_Resolved(String path);
bool compiler_backend_cache_NativeImage(String path);
bool compiler_backend_cache_PairedArgument(String value);
bool compiler_backend_cache_RequestedPipe(Slice arguments);
bool compiler_backend_cache_UnsupportedEffects(void);
bool compiler_backend_cache_SupportedArguments(Slice arguments);
bool compiler_backend_cache_SupportedOption(String value);
int64_t compiler_backend_cache_FileFind(BuildCache* cache, String path, bool directory);
int64_t compiler_backend_cache_FileAdd(BuildCache* cache, String path, bool directory);
int64_t compiler_backend_cache_ProbeLiteral(String text, int64_t start, String* name);
int64_t compiler_backend_cache_Minimum(int64_t left, int64_t right);
bool compiler_backend_cache_UnsafeText(String text);
bool compiler_backend_cache_ProbeNames(String text, __type_c53c2d7c4913dc02* names);
int64_t compiler_backend_cache_FileDigest(BuildCache* cache, String path);
bool compiler_backend_cache_OlderThanBuild(BuildCache* cache, PathInfo info, bool changed);
int64_t compiler_backend_cache_SpellingDigest(BuildCache* cache, String spelling, String root);
bool compiler_backend_cache_EnvironmentEntries(Slice bytes, __type_c53c2d7c4913dc02* entries);
bool compiler_backend_cache_CompilerEnvironment(String entry);
bool compiler_backend_cache_HashEnvironment(HashState* hash);
__type_838711075b90279a compiler_backend_cache_Probe(Slice arguments, bool piped);
bool compiler_backend_cache_HashProbeOutput(HashState* hash, String text);
bool compiler_backend_cache_JoinProbeVersions(__type_c53c2d7c4913dc02* lines);
BuildCache* compiler_backend_cache_Open(Slice arguments, String output, String executable);
void compiler_backend_cache_HashSnapshot(HashState* hash, PathInfo info);
String compiler_backend_cache_ToolFromLine(String line);
bool compiler_backend_cache_ParseProbe(BuildCache* cache, HashState* hash, String text, bool piped);
bool compiler_backend_cache_SpellingKey(BuildCache* cache, HashState* hash, String spelling, __type_c53c2d7c4913dc02* parents, bool* recordable);
bool compiler_backend_cache_LookupDigest(BuildCache* cache, __type_c53c2d7c4913dc02* dependencies, Digest* output, bool recording);
bool compiler_backend_cache_ReadDependencies(String object, __type_c53c2d7c4913dc02* dependencies);
bool compiler_backend_cache_ReadInteger(Slice bytes, int64_t* offset, uint32_t* output);
bool compiler_backend_cache_ReadDigest(Slice bytes, int64_t* offset, Digest* output);
bool compiler_backend_cache_SameDigest(Digest left, Digest right);
bool compiler_backend_cache_Piped(BuildCache* cache);
bool compiler_backend_cache_Hit(BuildCache* cache, String object);
bool compiler_backend_cache_AppendBytes(__type_838711075b90279a* output, Slice bytes);
bool compiler_backend_cache_AppendText(__type_838711075b90279a* output, String value);
bool compiler_backend_cache_AppendDigest(__type_838711075b90279a* output, Digest value);
bool compiler_backend_cache_AppendCount(__type_838711075b90279a* output, uint32_t value);
bool compiler_backend_cache_AppendNumber(__type_838711075b90279a* output, int64_t value);
String compiler_backend_cache_TemporaryInputPath(String object, int64_t attempt);
void compiler_backend_cache_Record(BuildCache* cache, String object, String source);
void compiler_backend_cache_ReleaseFingerprints(__type_d5737c4838766181* values);
void compiler_backend_cache_Close(BuildCache* cache);
/* Small procedures other modules inline; compiler_backend_cache.c defines them. */
#if !defined(__cplusplus) && !defined(ZIRAN_COMPILER_BACKEND_CACHE_H_SOURCE) && !defined(ZIRAN_NO_HEADER_INLINE)
#include "zir_vec.h"
#include <stdbool.h>
#include "zir_string.h"
#ifndef ZIRAN_HELPER_ZiShl32
#define ZIRAN_HELPER_ZiShl32
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__OPTIMIZE__)
#define ZiShl32(a, s, w) __extension__ ({ uint32_t __zi_a = (a); uint64_t __zi_s = (s); if(__zi_s >= (uint64_t)(w)) abort(); (uint32_t)(__zi_a << __zi_s); })
#else
static inline uint32_t ZiShl32(uint32_t a, uint64_t s, int w) {
if(s >= (uint64_t)w) abort();
return (uint32_t)(a << s);
}
#endif
#endif
static inline void compiler_backend_cache_HashBytes_ziran_inline(HashState* hash, String value);
#define compiler_backend_cache_HashBytes(...) compiler_backend_cache_HashBytes_ziran_inline(__VA_ARGS__)
static inline void compiler_backend_cache_HashText_ziran_inline(HashState* hash, String value);
#define compiler_backend_cache_HashText(...) compiler_backend_cache_HashText_ziran_inline(__VA_ARGS__)
static inline Slice compiler_backend_cache_BytesFromPointer_ziran_inline(uint8_t* data, uint64_t count);
#define compiler_backend_cache_BytesFromPointer(...) compiler_backend_cache_BytesFromPointer_ziran_inline(__VA_ARGS__)
static inline String compiler_backend_cache_Owned_ziran_inline(String value);
#define compiler_backend_cache_Owned(...) compiler_backend_cache_Owned_ziran_inline(__VA_ARGS__)
static inline bool compiler_backend_cache_SameText_ziran_inline(String left, String right);
#define compiler_backend_cache_SameText(...) compiler_backend_cache_SameText_ziran_inline(__VA_ARGS__)
static inline bool compiler_backend_cache_HasPrefix_ziran_inline(String value, String prefix);
#define compiler_backend_cache_HasPrefix(...) compiler_backend_cache_HasPrefix_ziran_inline(__VA_ARGS__)
static inline bool compiler_backend_cache_HasSuffix_ziran_inline(String value, String suffix);
#define compiler_backend_cache_HasSuffix(...) compiler_backend_cache_HasSuffix_ziran_inline(__VA_ARGS__)
static inline bool compiler_backend_cache_Contains_ziran_inline(String value, String piece);
#define compiler_backend_cache_Contains(...) compiler_backend_cache_Contains_ziran_inline(__VA_ARGS__)
static inline bool compiler_backend_cache_Runnable_ziran_inline(String path);
#define compiler_backend_cache_Runnable(...) compiler_backend_cache_Runnable_ziran_inline(__VA_ARGS__)
static inline int64_t compiler_backend_cache_FileFind_ziran_inline(BuildCache* cache, String path, bool directory);
#define compiler_backend_cache_FileFind(...) compiler_backend_cache_FileFind_ziran_inline(__VA_ARGS__)
static inline int64_t compiler_backend_cache_Minimum_ziran_inline(int64_t left, int64_t right);
#define compiler_backend_cache_Minimum(...) compiler_backend_cache_Minimum_ziran_inline(__VA_ARGS__)
static inline bool compiler_backend_cache_OlderThanBuild_ziran_inline(BuildCache* cache, PathInfo info, bool changed);
#define compiler_backend_cache_OlderThanBuild(...) compiler_backend_cache_OlderThanBuild_ziran_inline(__VA_ARGS__)
static inline void compiler_backend_cache_HashSnapshot_ziran_inline(HashState* hash, PathInfo info);
#define compiler_backend_cache_HashSnapshot(...) compiler_backend_cache_HashSnapshot_ziran_inline(__VA_ARGS__)
static inline bool compiler_backend_cache_ReadInteger_ziran_inline(Slice bytes, int64_t* offset, uint32_t* output);
#define compiler_backend_cache_ReadInteger(...) compiler_backend_cache_ReadInteger_ziran_inline(__VA_ARGS__)
static inline bool compiler_backend_cache_ReadDigest_ziran_inline(Slice bytes, int64_t* offset, Digest* output);
#define compiler_backend_cache_ReadDigest(...) compiler_backend_cache_ReadDigest_ziran_inline(__VA_ARGS__)
static inline bool compiler_backend_cache_SameDigest_ziran_inline(Digest left, Digest right);
#define compiler_backend_cache_SameDigest(...) compiler_backend_cache_SameDigest_ziran_inline(__VA_ARGS__)
static inline bool compiler_backend_cache_Piped_ziran_inline(BuildCache* cache);
#define compiler_backend_cache_Piped(...) compiler_backend_cache_Piped_ziran_inline(__VA_ARGS__)
static inline void
compiler_backend_cache_HashBytes_ziran_inline(HashState* hash, String value)
{
for (int64_t it_index = 0LL; it_index < (int64_t)(value).length; it_index++) {
uint8_t byte = (uint8_t)value.data[it_index];
compiler_backend_cache_HashByte(hash, byte);
}
}
static inline void
compiler_backend_cache_HashText_ziran_inline(HashState* hash, String value)
{
compiler_backend_cache_HashInteger(hash, (uint64_t)((int64_t)(value).length));
for (int64_t it_index = 0LL; it_index < (int64_t)(value).length; it_index++) {
uint8_t byte = (uint8_t)value.data[it_index];
compiler_backend_cache_HashByte(hash, byte);
}
}
static inline Slice
compiler_backend_cache_BytesFromPointer_ziran_inline(uint8_t* data, uint64_t count)
{
Slice result = {0};
if (data == ((void *)0)) {
return result;
}
ByteView* descriptor = (ByteView*)(&(result));
uint8_t** value_0 = &(descriptor->data);
(*value_0) = data;
int64_t* value_1 = &(descriptor->count);
(*value_1) = (int64_t)(count);
return result;
}
static inline String
compiler_backend_cache_Owned_ziran_inline(String value)
{
return vec_TextDetach(vec_TextCopy(value));
}
static inline bool
compiler_backend_cache_SameText_ziran_inline(String left, String right)
{
return StringEqual(left, right);
}
static inline bool
compiler_backend_cache_HasPrefix_ziran_inline(String value, String prefix)
{
return text_tools_TextHasPrefix(value, prefix);
}
static inline bool
compiler_backend_cache_HasSuffix_ziran_inline(String value, String suffix)
{
return text_tools_TextHasSuffix(value, suffix);
}
static inline bool
compiler_backend_cache_Contains_ziran_inline(String value, String piece)
{
return text_tools_TextContains(value, piece);
}
static inline bool
compiler_backend_cache_Runnable_ziran_inline(String path)
{
PathInfo info = file_tree_linux_PathStatus(path, true);
return ((PathKind)(info.kind)) == ((PathKind)(1)) && ((int32_t)((uint32_t)(info.mode) & 73u)) != 0;
}
static inline int64_t
compiler_backend_cache_FileFind_ziran_inline(BuildCache* cache, String path, bool directory)
{
if (directory) {
{
int64_t range_first_1 = 0LL;
int64_t range_last_1 = (int64_t)((uint64_t)(cache->candidates.count) - UINT64_C(1));
int64_t index = range_first_1;
if (index <= range_last_1) for (;;) {
if (StringEqual((ZIRAN_VEC_INDEX((cache->candidates).data, (cache->candidates).count, index)).path, path)) {
return index;
}
if (index == range_last_1) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
} else {
{
int64_t range_first_8 = 0LL;
int64_t range_last_8 = (int64_t)((uint64_t)(cache->files.count) - UINT64_C(1));
int64_t index = range_first_8;
if (index <= range_last_8) for (;;) {
if (StringEqual((ZIRAN_VEC_INDEX((cache->files).data, (cache->files).count, index)).path, path)) {
return index;
}
if (index == range_last_8) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
}
return -1LL;
}
static inline int64_t
compiler_backend_cache_Minimum_ziran_inline(int64_t left, int64_t right)
{
int64_t value_0 = 0;
if (left < right) {
value_0 = left;
} else {
value_0 = right;
}
return value_0;
}
static inline bool
compiler_backend_cache_OlderThanBuild_ziran_inline(BuildCache* cache, PathInfo info, bool changed)
{
int64_t value_0 = 0;
if (changed) {
value_0 = info.changed;
} else {
value_0 = info.modified;
}
int64_t seconds = value_0;
uint32_t value_1 = 0;
if (changed) {
value_1 = info.changed_nanoseconds;
} else {
value_1 = info.modified_nanoseconds;
}
uint32_t nanoseconds = value_1;
int64_t value_2 = cache->started_seconds;
if (seconds != value_2) {
int64_t value_3 = cache->started_seconds;
return seconds < value_3;
}
int64_t value_4 = (int64_t)(nanoseconds);
int64_t value_5 = cache->started_nanoseconds;
return value_4 < value_5;
}
static inline void
compiler_backend_cache_HashSnapshot_ziran_inline(HashState* hash, PathInfo info)
{
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.device_major));
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.device_minor));
compiler_backend_cache_HashInteger(hash, info.inode);
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.mode));
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.size));
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.modified));
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.modified_nanoseconds));
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.changed));
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.changed_nanoseconds));
}
static inline bool
compiler_backend_cache_ReadInteger_ziran_inline(Slice bytes, int64_t* offset, uint32_t* output)
{
int64_t value_0 = (int64_t)((uint64_t)(*(offset)) + UINT64_C(4));
int64_t value_1 = (int64_t)(bytes).length;
if (value_0 > value_1) {
return false;
}
uint32_t value = 0;
for (int64_t index = 0LL; index <= 3LL; index++) {
uint8_t value_2 = ((uint8_t *)bytes.data)[SliceIndex(bytes, (int64_t)((int64_t)((uint64_t)(*(offset)) + (uint64_t)index)))];
uint32_t value_3 = ZiShl32((uint32_t)(value_2), (uint64_t)((uint32_t)(((int64_t)(UINT64_C(8) * (uint64_t)index)))), 32);
value = (uint32_t)((uint32_t)value | (uint32_t)value_3);
}
int64_t* value_4 = &((*(offset)));
(*value_4) = (int64_t)((uint64_t)((*value_4)) + UINT64_C(4));
uint32_t* value_5 = &((*(output)));
(*value_5) = value;
return true;
}
static inline bool
compiler_backend_cache_ReadDigest_ziran_inline(Slice bytes, int64_t* offset, Digest* output)
{
int64_t value_0 = (int64_t)((uint64_t)(*(offset)) + UINT64_C(32));
int64_t value_1 = (int64_t)(bytes).length;
if (value_0 > value_1) {
return false;
}
for (int64_t index = 0LL; index <= 31LL; index++) {
uint8_t* value_2 = &(output->bytes[index]);
uint8_t value_3 = ((uint8_t *)bytes.data)[SliceIndex(bytes, (int64_t)((int64_t)((uint64_t)(*(offset)) + (uint64_t)index)))];
(*value_2) = value_3;
}
int64_t* value_4 = &((*(offset)));
(*value_4) = (int64_t)((uint64_t)((*value_4)) + UINT64_C(32));
return true;
}
static inline bool
compiler_backend_cache_SameDigest_ziran_inline(Digest left, Digest right)
{
for (int64_t index = 0LL; index <= 31LL; index++) {
if ((left.bytes)[index] != (right.bytes)[index]) {
return false;
}
}
return true;
}
static inline bool
compiler_backend_cache_Piped_ziran_inline(BuildCache* cache)
{
return cache != ((void *)0) && cache->piped;
}
#endif
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_COMPILER_BACKEND_CACHE_H */
@@ -0,0 +1,47 @@
/* Generated by zi2c from byte_text_linux.zi. */
#include "zir_string_types.h"
#include "byte_text_linux.h"
String
TextFromBytes(Slice buffer)
{
Slice value_0 = buffer;
return StringView((const char *)(value_0).data, (size_t)(value_0).length);
}
Slice
BytesFromPointer(uint8_t* data, uint64_t count)
{
Slice result = {0};
if (data == ((void *)0) || count > 9223372036854775807ULL) {
return result;
}
ByteDescriptor* descriptor = (ByteDescriptor*)(&(result));
uint8_t** value_0 = &(descriptor->data);
(*value_0) = data;
int64_t* value_1 = &(descriptor->length);
(*value_1) = (int64_t)(count);
return result;
}
String
TextFromCString(uint8_t* value)
{
if (value == ((void *)0)) {
return StringLiteral("");
}
uint64_t length = 0ULL;
while (value[length] != 0) {
if (length >= 9223372036854775807ULL) {
return StringLiteral("");
}
length = (uint64_t)((uint64_t)length + UINT64_C(1));
}
String result = StringLiteral("");
TextDescriptor* descriptor = (TextDescriptor*)(&(result));
uint8_t** value_0 = &(descriptor->data);
(*value_0) = value;
size_t* value_1 = &(descriptor->length);
(*value_1) = (size_t)(length);
return result;
}
@@ -0,0 +1,31 @@
/* Generated by zi2c from byte_text_linux.zi. */
#ifndef ZIRAN_BYTE_TEXT_LINUX_H
#define ZIRAN_BYTE_TEXT_LINUX_H
#include "zir_string_types.h"
#include "zir_slice.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct TextDescriptor TextDescriptor;
typedef struct ByteDescriptor ByteDescriptor;
struct TextDescriptor {
uint8_t* data;
size_t length;
};
struct ByteDescriptor {
uint8_t* data;
int64_t length;
};
String TextFromBytes(Slice buffer);
Slice BytesFromPointer(uint8_t* data, uint64_t count);
String TextFromCString(uint8_t* value);
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_BYTE_TEXT_LINUX_H */
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,683 @@
/* Generated by zi2c from compiler_backend_process.zi. */
#ifndef ZIRAN_COMPILER_BACKEND_PROCESS_H
#define ZIRAN_COMPILER_BACKEND_PROCESS_H
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_bounds.h"
#include "zir_slice.h"
#include "file.h"
#include "vec.h"
#include "file_tree_linux.h"
#include "environment.h"
#include "text_tools.h"
#include "sort.h"
#include "timer_linux.h"
#include "c_string.h"
#include "compiler_backend_cache.h"
#ifdef __cplusplus
extern "C" {
#endif
#define WorkerMemory 512
#define WorkerMaximum 16
#define ArgumentMaximum 1024
#define TextMaximum 4096
#define LockReadWrite 2
#define LockCreate 512
#define LockCloseOnExec 16777216
#define LockNoFollow 256
#define ProcessorsOnline 58
#define AffinityBytes 128
#define ToolLogMaximum 4095
#ifndef ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
#define ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
typedef struct __type_838711075b90279a __type_838711075b90279a;
#endif
typedef struct Job Job;
typedef struct SlotOutput SlotOutput;
typedef struct PendingOutput PendingOutput;
typedef struct zir_e4358493ea4607d1_Results__string__bool zir_e4358493ea4607d1_Results__string__bool;
typedef struct Results__pu8__bool Results__pu8__bool;
typedef struct DiagnosticSpan DiagnosticSpan;
typedef struct PollRecord PollRecord;
typedef struct OwnedText OwnedText;
typedef struct CapturePointer CapturePointer;
#ifndef ZIRAN_CONCRETE_FORWARD___type_c53c2d7c4913dc02
#define ZIRAN_CONCRETE_FORWARD___type_c53c2d7c4913dc02
typedef struct __type_c53c2d7c4913dc02 __type_c53c2d7c4913dc02;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_21092c8252d3dcaa
#define ZIRAN_CONCRETE_FORWARD___type_21092c8252d3dcaa
typedef struct __type_21092c8252d3dcaa __type_21092c8252d3dcaa;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_6f55d821d15c8cbf
#define ZIRAN_CONCRETE_FORWARD___type_6f55d821d15c8cbf
typedef struct __type_6f55d821d15c8cbf __type_6f55d821d15c8cbf;
#endif
#ifndef ZIRAN_CONCRETE___type_838711075b90279a
#define ZIRAN_CONCRETE___type_838711075b90279a
struct __type_838711075b90279a {
uint8_t* data;
int64_t count;
int64_t capacity;
};
#endif
struct Job {
int32_t process;
int32_t descriptor;
__type_838711075b90279a output;
bool finished;
bool ok;
};
struct SlotOutput {
int64_t file;
bool running;
};
struct PendingOutput {
int64_t file;
__type_838711075b90279a output;
};
struct zir_e4358493ea4607d1_Results__string__bool {
String value_0;
bool value_1;
};
struct Results__pu8__bool {
uint8_t* value_0;
bool value_1;
};
struct DiagnosticSpan {
uint8_t* context;
int32_t file;
int32_t line;
int32_t column;
int32_t end_line;
int32_t end_column;
};
struct PollRecord {
int32_t descriptor;
int16_t events;
int16_t revents;
};
struct OwnedText {
uint8_t* data;
size_t length;
};
struct CapturePointer {
uint8_t* value;
};
#ifndef ZIRAN_CONCRETE___type_c53c2d7c4913dc02
#define ZIRAN_CONCRETE___type_c53c2d7c4913dc02
struct __type_c53c2d7c4913dc02 {
String* data;
int64_t count;
int64_t capacity;
};
#endif
#ifndef ZIRAN_CONCRETE___type_21092c8252d3dcaa
#define ZIRAN_CONCRETE___type_21092c8252d3dcaa
struct __type_21092c8252d3dcaa {
uint8_t** data;
int64_t count;
int64_t capacity;
};
#endif
#ifndef ZIRAN_CONCRETE___type_6f55d821d15c8cbf
#define ZIRAN_CONCRETE___type_6f55d821d15c8cbf
struct __type_6f55d821d15c8cbf {
PendingOutput* data;
int64_t count;
int64_t capacity;
};
#endif
extern __type_c53c2d7c4913dc02 zir_g_45df0357d1607758;
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_SysconfByName_6b580cc2
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_SysconfByName_6b580cc2
#ifdef __APPLE__
int64_t zir_foreign_zir_f_1cd1ecb166af98b1_SysconfByName(int32_t name) __asm__("_sysconf");
#else
int64_t zir_foreign_zir_f_1cd1ecb166af98b1_SysconfByName(int32_t name) __asm__("sysconf");
#endif
static int64_t
zir_f_1cd1ecb166af98b1_SysconfByName(int32_t name)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_SysconfByName(name);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_OpenReadFile_a94da530
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_OpenReadFile_a94da530
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_OpenReadFile(uint8_t* path) __asm__("_open");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_OpenReadFile(uint8_t* path) __asm__("open");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_OpenReadFile(uint8_t* path)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_OpenReadFile(path);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_CloseDescriptor_d6ec0c1e
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_CloseDescriptor_d6ec0c1e
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_CloseDescriptor(int32_t descriptor) __asm__("_close");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_CloseDescriptor(int32_t descriptor) __asm__("close");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_CloseDescriptor(int32_t descriptor)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_CloseDescriptor(descriptor);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ReadDescriptor_7d19ba22
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ReadDescriptor_7d19ba22
#ifdef __APPLE__
int64_t zir_foreign_zir_f_1cd1ecb166af98b1_ReadDescriptor(int32_t descriptor, uint8_t* output, size_t count) __asm__("_read");
#else
int64_t zir_foreign_zir_f_1cd1ecb166af98b1_ReadDescriptor(int32_t descriptor, uint8_t* output, size_t count) __asm__("read");
#endif
static int64_t
zir_f_1cd1ecb166af98b1_ReadDescriptor(int32_t descriptor, uint8_t* output, size_t count)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_ReadDescriptor(descriptor, output, count);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_MakeDirectory_a57b07a1
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_MakeDirectory_a57b07a1
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_MakeDirectory(uint8_t* path, int32_t mode) __asm__("_mkdir");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_MakeDirectory(uint8_t* path, int32_t mode) __asm__("mkdir");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_MakeDirectory(uint8_t* path, int32_t mode)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_MakeDirectory(path, mode);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_OpenLock_e4db28c4
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_OpenLock_e4db28c4
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_OpenLock(uint8_t* path, int32_t flags, ...) __asm__("_open");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_OpenLock(uint8_t* path, int32_t flags, ...) __asm__("open");
#endif
#define zir_f_1cd1ecb166af98b1_OpenLock zir_foreign_zir_f_1cd1ecb166af98b1_OpenLock
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FlockLock_d74aed45
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FlockLock_d74aed45
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_FlockLock(int32_t descriptor, int32_t operation) __asm__("_flock");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_FlockLock(int32_t descriptor, int32_t operation) __asm__("flock");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_FlockLock(int32_t descriptor, int32_t operation)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_FlockLock(descriptor, operation);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_PipeRaw_bab5570c
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_PipeRaw_bab5570c
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_PipeRaw(int32_t* fds) __asm__("_pipe");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_PipeRaw(int32_t* fds) __asm__("pipe");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_PipeRaw(int32_t* fds)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_PipeRaw(fds);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FcntlCloexec_b27e2197
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FcntlCloexec_b27e2197
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_FcntlCloexec(int32_t descriptor, int32_t command, ...) __asm__("_fcntl");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_FcntlCloexec(int32_t descriptor, int32_t command, ...) __asm__("fcntl");
#endif
#define zir_f_1cd1ecb166af98b1_FcntlCloexec zir_foreign_zir_f_1cd1ecb166af98b1_FcntlCloexec
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ForkRaw_b09b1e28
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ForkRaw_b09b1e28
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_ForkRaw(void) __asm__("_fork");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_ForkRaw(void) __asm__("fork");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_ForkRaw(void)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_ForkRaw();
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_DupRaw_8536fc2b
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_DupRaw_8536fc2b
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_DupRaw(int32_t source, int32_t destination) __asm__("_dup2");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_DupRaw(int32_t source, int32_t destination) __asm__("dup2");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_DupRaw(int32_t source, int32_t destination)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_DupRaw(source, destination);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ExitChild_da83199a
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ExitChild_da83199a
#ifdef __APPLE__
void zir_foreign_zir_f_1cd1ecb166af98b1_ExitChild(int32_t code) __asm__("__exit");
#else
void zir_foreign_zir_f_1cd1ecb166af98b1_ExitChild(int32_t code) __asm__("_exit");
#endif
static void
zir_f_1cd1ecb166af98b1_ExitChild(int32_t code)
{
zir_foreign_zir_f_1cd1ecb166af98b1_ExitChild(code);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_WaitRaw_0257cbb4
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_WaitRaw_0257cbb4
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_WaitRaw(int32_t process, int32_t* status, int32_t options) __asm__("_waitpid");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_WaitRaw(int32_t process, int32_t* status, int32_t options) __asm__("waitpid");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_WaitRaw(int32_t process, int32_t* status, int32_t options)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_WaitRaw(process, status, options);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ErrnoLocation_a87bf2d8
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ErrnoLocation_a87bf2d8
#ifdef __APPLE__
int32_t* zir_foreign_zir_f_1cd1ecb166af98b1_ErrnoLocation(void) __asm__("___error");
#else
int32_t* zir_foreign_zir_f_1cd1ecb166af98b1_ErrnoLocation(void) __asm__("__error");
#endif
static int32_t*
zir_f_1cd1ecb166af98b1_ErrnoLocation(void)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_ErrnoLocation();
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_AllocateRaw_0c09ffff
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_AllocateRaw_0c09ffff
#ifdef __APPLE__
void* zir_foreign_zir_f_1cd1ecb166af98b1_AllocateRaw(size_t count, size_t size) __asm__("_calloc");
#else
void* zir_foreign_zir_f_1cd1ecb166af98b1_AllocateRaw(size_t count, size_t size) __asm__("calloc");
#endif
static void*
zir_f_1cd1ecb166af98b1_AllocateRaw(size_t count, size_t size)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_AllocateRaw(count, size);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FreeRaw_c75930da
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FreeRaw_c75930da
#ifdef __APPLE__
void zir_foreign_zir_f_1cd1ecb166af98b1_FreeRaw(void* memory) __asm__("_free");
#else
void zir_foreign_zir_f_1cd1ecb166af98b1_FreeRaw(void* memory) __asm__("free");
#endif
static void
zir_f_1cd1ecb166af98b1_FreeRaw(void* memory)
{
zir_foreign_zir_f_1cd1ecb166af98b1_FreeRaw(memory);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FlushStreams_e871adfd
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_FlushStreams_e871adfd
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_FlushStreams(void* file) __asm__("_fflush");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_FlushStreams(void* file) __asm__("fflush");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_FlushStreams(void* file)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_FlushStreams(file);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_DiagnosticJsonEnabled_e175c060
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_DiagnosticJsonEnabled_e175c060
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_DiagnosticJsonEnabled(void) __asm__("_DiagnosticJsonEnabled");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_DiagnosticJsonEnabled(void) __asm__("DiagnosticJsonEnabled");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_DiagnosticJsonEnabled(void)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_DiagnosticJsonEnabled();
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_GeneratedOutputPath_ee884a36
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_GeneratedOutputPath_ee884a36
#ifdef __APPLE__
uint8_t* zir_foreign_zir_f_1cd1ecb166af98b1_GeneratedOutputPath(int64_t index) __asm__("_GeneratedOutputPath");
#else
uint8_t* zir_foreign_zir_f_1cd1ecb166af98b1_GeneratedOutputPath(int64_t index) __asm__("GeneratedOutputPath");
#endif
static uint8_t*
zir_f_1cd1ecb166af98b1_GeneratedOutputPath(int64_t index)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_GeneratedOutputPath(index);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ToolchainIncludeDirectory_96d5cefc
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ToolchainIncludeDirectory_96d5cefc
#ifdef __APPLE__
uint8_t* zir_foreign_zir_f_1cd1ecb166af98b1_ToolchainIncludeDirectory(void) __asm__("_ToolchainIncludeDirectory");
#else
uint8_t* zir_foreign_zir_f_1cd1ecb166af98b1_ToolchainIncludeDirectory(void) __asm__("ToolchainIncludeDirectory");
#endif
static uint8_t*
zir_f_1cd1ecb166af98b1_ToolchainIncludeDirectory(void)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_ToolchainIncludeDirectory();
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ProfileStart_b892bac9
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ProfileStart_b892bac9
#ifdef __APPLE__
uint64_t zir_foreign_zir_f_1cd1ecb166af98b1_ProfileStart(void) __asm__("_ProfileStart");
#else
uint64_t zir_foreign_zir_f_1cd1ecb166af98b1_ProfileStart(void) __asm__("ProfileStart");
#endif
static uint64_t
zir_f_1cd1ecb166af98b1_ProfileStart(void)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_ProfileStart();
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ProfileEndForeign_ae202c81
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ProfileEndForeign_ae202c81
#ifdef __APPLE__
void zir_foreign_zir_f_1cd1ecb166af98b1_ProfileEndForeign(uint8_t* phase, uint64_t started) __asm__("_ProfileEnd");
#else
void zir_foreign_zir_f_1cd1ecb166af98b1_ProfileEndForeign(uint8_t* phase, uint64_t started) __asm__("ProfileEnd");
#endif
static void
zir_f_1cd1ecb166af98b1_ProfileEndForeign(uint8_t* phase, uint64_t started)
{
zir_foreign_zir_f_1cd1ecb166af98b1_ProfileEndForeign(phase, started);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ProfileCountForeign_c5a6224b
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ProfileCountForeign_c5a6224b
#ifdef __APPLE__
void zir_foreign_zir_f_1cd1ecb166af98b1_ProfileCountForeign(uint8_t* counter) __asm__("_ProfileCount");
#else
void zir_foreign_zir_f_1cd1ecb166af98b1_ProfileCountForeign(uint8_t* counter) __asm__("ProfileCount");
#endif
static void
zir_f_1cd1ecb166af98b1_ProfileCountForeign(uint8_t* counter)
{
zir_foreign_zir_f_1cd1ecb166af98b1_ProfileCountForeign(counter);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_PollRaw_7bcba4aa
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_PollRaw_7bcba4aa
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_PollRaw(PollRecord* fds, uint64_t count, int32_t timeout) __asm__("_poll");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_PollRaw(PollRecord* fds, uint64_t count, int32_t timeout) __asm__("poll");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_PollRaw(PollRecord* fds, uint64_t count, int32_t timeout)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_PollRaw(fds, count, timeout);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_WriteDescriptor_7e695fb1
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_WriteDescriptor_7e695fb1
#ifdef __APPLE__
int64_t zir_foreign_zir_f_1cd1ecb166af98b1_WriteDescriptor(int32_t descriptor, uint8_t* output, size_t count) __asm__("_write");
#else
int64_t zir_foreign_zir_f_1cd1ecb166af98b1_WriteDescriptor(int32_t descriptor, uint8_t* output, size_t count) __asm__("write");
#endif
static int64_t
zir_f_1cd1ecb166af98b1_WriteDescriptor(int32_t descriptor, uint8_t* output, size_t count)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_WriteDescriptor(descriptor, output, count);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ExecRaw_8f11e3e3
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_ExecRaw_8f11e3e3
#ifdef __APPLE__
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_ExecRaw(uint8_t* path, CapturePointer* arguments) __asm__("_execvp");
#else
int32_t zir_foreign_zir_f_1cd1ecb166af98b1_ExecRaw(uint8_t* path, CapturePointer* arguments) __asm__("execvp");
#endif
static int32_t
zir_f_1cd1ecb166af98b1_ExecRaw(uint8_t* path, CapturePointer* arguments)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_ExecRaw(path, arguments);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_Strerror_202dd881
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_Strerror_202dd881
#ifdef __APPLE__
uint8_t* zir_foreign_zir_f_1cd1ecb166af98b1_Strerror(int32_t number) __asm__("_strerror");
#else
uint8_t* zir_foreign_zir_f_1cd1ecb166af98b1_Strerror(int32_t number) __asm__("strerror");
#endif
static uint8_t*
zir_f_1cd1ecb166af98b1_Strerror(int32_t number)
{
return zir_foreign_zir_f_1cd1ecb166af98b1_Strerror(number);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_WarningForeign_c8d79e7f
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_WarningForeign_c8d79e7f
#ifdef __APPLE__
void zir_foreign_zir_f_1cd1ecb166af98b1_WarningForeign(DiagnosticSpan span, uint8_t* code, uint8_t* format, uint8_t* value) __asm__("_Warning");
#else
void zir_foreign_zir_f_1cd1ecb166af98b1_WarningForeign(DiagnosticSpan span, uint8_t* code, uint8_t* format, uint8_t* value) __asm__("Warning");
#endif
static void
zir_f_1cd1ecb166af98b1_WarningForeign(DiagnosticSpan span, uint8_t* code, uint8_t* format, uint8_t* value)
{
zir_foreign_zir_f_1cd1ecb166af98b1_WarningForeign(span, code, format, value);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_DiagnosticTargetForeign_848c5de5
#define ZIR_FOREIGN_zir_f_1cd1ecb166af98b1_DiagnosticTargetForeign_848c5de5
#ifdef __APPLE__
void zir_foreign_zir_f_1cd1ecb166af98b1_DiagnosticTargetForeign(DiagnosticSpan span, uint8_t* code, uint8_t* target, uint8_t* capability, uint8_t* format, uint8_t* first, uint8_t* second) __asm__("_DiagnosticTarget");
#else
void zir_foreign_zir_f_1cd1ecb166af98b1_DiagnosticTargetForeign(DiagnosticSpan span, uint8_t* code, uint8_t* target, uint8_t* capability, uint8_t* format, uint8_t* first, uint8_t* second) __asm__("DiagnosticTarget");
#endif
static void
zir_f_1cd1ecb166af98b1_DiagnosticTargetForeign(DiagnosticSpan span, uint8_t* code, uint8_t* target, uint8_t* capability, uint8_t* format, uint8_t* first, uint8_t* second)
{
zir_foreign_zir_f_1cd1ecb166af98b1_DiagnosticTargetForeign(span, code, target, capability, format, first, second);
}
#endif
int32_t compiler_backend_process_WorkerLimit(void);
int32_t compiler_backend_process_BuildLock(String directory);
void compiler_backend_process_ReleasePointerVector(__type_21092c8252d3dcaa* values);
Job compiler_backend_process_StartJob(Slice commands, bool capture, bool report_error);
bool compiler_backend_process_WaitJob(Job* job);
void compiler_backend_process_FreeJob(Job* job);
bool compiler_backend_process_TextStartsWith(String value, String prefix);
bool compiler_backend_process_TextEndsWith(String value, String suffix);
bool compiler_backend_process_TextContains(String value, String piece);
String compiler_backend_process_PathName(String value);
zir_e4358493ea4607d1_Results__string__bool compiler_backend_process_PathJoin(String left, String right);
zir_e4358493ea4607d1_Results__string__bool compiler_backend_process_PathSuffix(String value, String suffix);
void compiler_backend_process_ReleaseOwnedText(String value);
uint8_t* compiler_backend_process_AllocateText(String value);
String compiler_backend_process_CText(uint8_t* value);
void compiler_backend_process_FreePointers(__type_21092c8252d3dcaa values);
bool compiler_backend_process_PrepareArguments(Slice arguments, __type_21092c8252d3dcaa* pointers);
bool compiler_backend_process_WordsInto(String value, __type_21092c8252d3dcaa* output);
bool compiler_backend_process_EnvironmentWords(String name, __type_21092c8252d3dcaa* output);
bool compiler_backend_process_AddCArgument(__type_21092c8252d3dcaa* output, String flag, String value);
bool compiler_backend_process_AddSource(__type_21092c8252d3dcaa* files, String path);
bool compiler_backend_process_CompileExecutable(String out, String name, bool threads, bool release);
bool compiler_backend_process_FinishCompile(String out, String name, bool forced_language, __type_21092c8252d3dcaa* base, __type_21092c8252d3dcaa* tail, __type_21092c8252d3dcaa* files, __type_21092c8252d3dcaa* objects, __type_838711075b90279a* log);
Results__pu8__bool compiler_backend_process_ObjectPath(String out, String relative);
void compiler_backend_process_SortPaths(__type_21092c8252d3dcaa* values);
bool compiler_backend_process_PathBefore(String left, String right);
void compiler_backend_process_ReapJob(Job* job);
void compiler_backend_process_StoreJob(Job* target, Job value);
void compiler_backend_process_PollSlots(Slice jobs, Slice slots, bool* failed);
bool compiler_backend_process_CompileAndLink(String out, String name, bool forced_language, __type_21092c8252d3dcaa* base, __type_21092c8252d3dcaa* tail, __type_21092c8252d3dcaa* files, __type_21092c8252d3dcaa* objects, __type_838711075b90279a* log);
__type_c53c2d7c4913dc02 compiler_backend_process_PointerTexts(__type_21092c8252d3dcaa* source);
__type_c53c2d7c4913dc02 compiler_backend_process_CloneTexts(__type_21092c8252d3dcaa* source);
void compiler_backend_process_FreeArguments(__type_c53c2d7c4913dc02* values);
bool compiler_backend_process_AddDependencyArguments(__type_c53c2d7c4913dc02* arguments, String dependency);
bool compiler_backend_process_AddObjectArguments(__type_c53c2d7c4913dc02* arguments, String source, String object);
bool compiler_backend_process_AddTextArgument(__type_c53c2d7c4913dc02* output, String flag, String value);
bool compiler_backend_process_AppendLog(__type_838711075b90279a* log, Slice output);
bool compiler_backend_process_LinkOwnedObjects(String out, String name, bool forced_language, __type_21092c8252d3dcaa* base, __type_21092c8252d3dcaa* tail, __type_21092c8252d3dcaa* files, __type_21092c8252d3dcaa* objects, __type_838711075b90279a* log, BuildCache* cache);
void compiler_backend_process_ReleaseBuildValues(__type_21092c8252d3dcaa* base, __type_21092c8252d3dcaa* tail, __type_21092c8252d3dcaa* files, __type_21092c8252d3dcaa* objects, __type_838711075b90279a* log);
bool compiler_backend_process_MoveLinkOutput(String directory, String out, String name);
void compiler_backend_process_ReportToolchain(String out, __type_838711075b90279a* log, bool ok);
void compiler_backend_process_Report(bool ok, String code, String message);
int64_t compiler_backend_process_AffinityCpus(void);
int64_t compiler_backend_process_AvailableMemory(void);
int64_t compiler_backend_process_NumberText(String value);
String compiler_backend_process_CTextN(uint8_t* value, int64_t length);
bool compiler_backend_process_CreateDirectories(String path);
int32_t compiler_backend_process_ErrnoValue(void);
void compiler_backend_process_SetCloexec(int32_t descriptor);
void compiler_backend_process_FinishStatus(Job* job, int32_t status);
bool compiler_backend_process_ReadJobOutput(Job* job);
void compiler_backend_process_ExecChild(uint8_t* path, CapturePointer* arguments, bool report_error);
void compiler_backend_process_ProfileCount(String counter);
void compiler_backend_process_ProfileEnd(String phase, uint64_t started);
uint8_t* compiler_backend_process_ProfileName(String name);
/* Small procedures other modules inline; compiler_backend_process.c defines them. */
#if !defined(__cplusplus) && !defined(ZIRAN_COMPILER_BACKEND_PROCESS_H_SOURCE) && !defined(ZIRAN_NO_HEADER_INLINE)
#include "zir_vec.h"
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_bounds.h"
#ifndef ZIRAN_HELPER_ZiShrS32
#define ZIRAN_HELPER_ZiShrS32
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__OPTIMIZE__)
#define ZiShrS32(a, s, w) __extension__ ({ int32_t __zi_a = (a); uint64_t __zi_s = (s); if(__zi_s >= (uint64_t)(w)) abort(); __zi_a < 0 ? ~(~__zi_a >> __zi_s) : __zi_a >> __zi_s; })
#else
static inline int32_t ZiShrS32(int32_t a, uint64_t s, int w) {
if(s >= (uint64_t)w) abort();
return a < 0 ? ~(~a >> s) : a >> s;
}
#endif
#endif
static inline void compiler_backend_process_SortPaths_ziran_inline(__type_21092c8252d3dcaa* values);
#define compiler_backend_process_SortPaths(...) compiler_backend_process_SortPaths_ziran_inline(__VA_ARGS__)
static inline bool compiler_backend_process_PathBefore_ziran_inline(String left, String right);
#define compiler_backend_process_PathBefore(...) compiler_backend_process_PathBefore_ziran_inline(__VA_ARGS__)
static inline int64_t compiler_backend_process_NumberText_ziran_inline(String value);
#define compiler_backend_process_NumberText(...) compiler_backend_process_NumberText_ziran_inline(__VA_ARGS__)
static inline void compiler_backend_process_FinishStatus_ziran_inline(Job* job, int32_t status);
#define compiler_backend_process_FinishStatus(...) compiler_backend_process_FinishStatus_ziran_inline(__VA_ARGS__)
static inline void
compiler_backend_process_SortPaths_ziran_inline(__type_21092c8252d3dcaa* values)
{
{
int64_t range_first_0 = 1LL;
int64_t range_last_0 = (int64_t)((uint64_t)(values->count) - UINT64_C(1));
int64_t at = range_first_0;
if (at <= range_last_0) for (;;) {
uint8_t* value = ZIRAN_VEC_INDEX((*(values)).data, (*(values)).count, at);
int64_t before = (int64_t)((uint64_t)at - UINT64_C(1));
while (true) {
bool value_0 = before >= 0LL;
if (value_0) {
String value_1 = compiler_backend_process_CText(value);
bool value_2 = compiler_backend_process_PathBefore(value_1, compiler_backend_process_CText(ZIRAN_VEC_INDEX((*(values)).data, (*(values)).count, before)));
value_0 = value_2;
}
if (!value_0) { break; }
uint8_t** value_3 = &(ZIRAN_VEC_INDEX(((*(values))).data, ((*(values))).count, ((int64_t)((uint64_t)before + UINT64_C(1)))));
(*value_3) = ZIRAN_VEC_INDEX((*(values)).data, (*(values)).count, before);
before = (int64_t)((uint64_t)before - UINT64_C(1));
}
uint8_t** value_4 = &(ZIRAN_VEC_INDEX(((*(values))).data, ((*(values))).count, ((int64_t)((uint64_t)before + UINT64_C(1)))));
(*value_4) = value;
if (at == range_last_0) {
break;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
}
}
static inline bool
compiler_backend_process_PathBefore_ziran_inline(String left, String right)
{
int64_t value_0 = 0;
if ((int64_t)(left).length < (int64_t)(right).length) {
value_0 = (int64_t)(left).length;
} else {
value_0 = (int64_t)(right).length;
}
int64_t count = value_0;
{
int64_t range_first_1 = 0LL;
int64_t range_last_1 = (int64_t)((uint64_t)count - UINT64_C(1));
int64_t at = range_first_1;
if (at <= range_last_1) for (;;) {
if ((uint8_t)ZIRAN_INDEX(left.data, left.length, at) != (uint8_t)ZIRAN_INDEX(right.data, right.length, at)) {
return (uint8_t)ZIRAN_INDEX(left.data, left.length, at) < (uint8_t)ZIRAN_INDEX(right.data, right.length, at);
}
if (at == range_last_1) {
break;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
}
return (int64_t)(left).length < (int64_t)(right).length;
}
static inline int64_t
compiler_backend_process_NumberText_ziran_inline(String value)
{
int64_t result = 0LL;
for (int64_t it_index = 0LL; it_index < (int64_t)(value).length; it_index++) {
uint8_t byte = (uint8_t)value.data[it_index];
result = (int64_t)(((uint64_t)result * UINT64_C(10)) + (uint64_t)(((uint8_t)((uint32_t)byte - 48u))));
}
return result;
}
static inline void
compiler_backend_process_FinishStatus_ziran_inline(Job* job, int32_t status)
{
bool* value_0 = &(job->finished);
(*value_0) = true;
bool* value_1 = &(job->ok);
bool value_2 = ((int32_t)((uint32_t)status & 127u)) == 0 && ((int32_t)((uint32_t)((ZiShrS32(status, (uint64_t)(8), 32))) & 255u)) == 0;
(*value_1) = value_2;
}
#endif
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_COMPILER_BACKEND_PROCESS_H */
@@ -0,0 +1,15 @@
/* Generated by zi2c from environment.zi. */
#ifndef ZIRAN_ENVIRONMENT_H
#define ZIRAN_ENVIRONMENT_H
#include "environment_linux.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_ENVIRONMENT_H */
@@ -0,0 +1,191 @@
/* Generated by zi2c from environment_linux.zi. */
#define ZIRAN_ENVIRONMENT_LINUX_H_SOURCE 1
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_bounds.h"
#include "environment_linux.h"
#include "c_string.h"
#include "byte_text_linux.h"
#include "number_text.h"
#include "result.h"
__type_6c5c09809af9b2be
environment_linux_BoundedHostText(uint8_t* value, Slice output)
{
__type_6c5c09809af9b2be result = {0};
if (value == ((void *)0)) {
EnvironmentFailure* value_0 = &(result.error);
(*value_0) = EnvironmentFailure_Unset;
return result;
}
int64_t index = 0LL;
while (index < (int64_t)(output).length && value[index] != 0) {
uint8_t* value_1 = &(((uint8_t *)output.data)[index]);
(*value_1) = value[index];
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
if (index == (int64_t)(output).length && value[index] != 0) {
EnvironmentFailure* value_2 = &(result.error);
(*value_2) = EnvironmentFailure_TooLong;
return result;
}
bool* value_3 = &(result.is_ok);
(*value_3) = true;
String* value_4 = &(result.value);
Slice value_5 = output;
(*value_4) = TextFromBytes(SliceRange(value_5, (int64_t)0LL, (int64_t)index, sizeof(uint8_t)));
return result;
}
__type_6c5c09809af9b2be
EnvironmentRead(String name, Slice output)
{
__type_6c5c09809af9b2be result = {0};
uint8_t buffer[256] = {0};
bool value_0 = (int64_t)(name).length == 0LL;
if (!value_0) {
Slice value_1 = {buffer, 256};
bool value_2 = CopyCString(name, value_1);
value_0 = !value_2;
}
if (value_0) {
EnvironmentFailure* value_3 = &(result.error);
(*value_3) = EnvironmentFailure_InvalidName;
return result;
}
result = environment_linux_BoundedHostText(zir_f_65e9ad6d46228d2f_EnvironmentValueRaw(&(buffer[0])), output);
if (result.is_ok && (int64_t)(result.value).length == 0LL) {
bool* value_4 = &(result.is_ok);
(*value_4) = false;
EnvironmentFailure* value_5 = &(result.error);
(*value_5) = EnvironmentFailure_Empty;
}
return result;
}
__type_2327be0556361c2c
EnvironmentRange(String name, int64_t minimum, int64_t maximum, Slice input)
{
__type_2327be0556361c2c result = {0};
if (minimum > maximum) {
EnvironmentFailure* value_0 = &(result.error);
(*value_0) = EnvironmentFailure_OutOfRange;
return result;
}
__type_6c5c09809af9b2be text = EnvironmentRead(name, input);
if (!text.is_ok) {
EnvironmentFailure* value_1 = &(result.error);
(*value_1) = (EnvironmentFailure)(text.error);
return result;
}
int64_t at = 0LL;
bool negative = (uint8_t)ZIRAN_INDEX(text.value.data, text.value.length, 0) == 45;
if (negative) {
at = 1LL;
}
if (at == (int64_t)(text.value).length) {
EnvironmentFailure* value_2 = &(result.error);
(*value_2) = EnvironmentFailure_NotNumber;
return result;
}
uint64_t magnitude = 0ULL;
uint64_t value_3 = 0;
if (negative) {
value_3 = 9223372036854775808ULL;
} else {
value_3 = 9223372036854775807ULL;
}
uint64_t limit = value_3;
while (at < (int64_t)(text.value).length) {
uint8_t byte = (uint8_t)ZIRAN_INDEX(text.value.data, text.value.length, at);
if (byte < 48 || byte > 57) {
EnvironmentFailure* value_4 = &(result.error);
(*value_4) = EnvironmentFailure_NotNumber;
return result;
}
uint64_t digit = (uint64_t)(((uint8_t)((uint32_t)byte - 48u)));
uint64_t value_5 = ((uint64_t)((uint64_t)limit - (uint64_t)digit)) / 10ULL;
if (magnitude > value_5) {
EnvironmentFailure* value_6 = &(result.error);
(*value_6) = EnvironmentFailure_OutOfRange;
return result;
}
magnitude = (uint64_t)(((uint64_t)magnitude * UINT64_C(10)) + (uint64_t)digit);
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
int64_t value = (int64_t)(magnitude);
if (negative) {
value = (int64_t)(UINT64_C(0) - (uint64_t)value);
}
if (value < minimum || value > maximum) {
EnvironmentFailure* value_7 = &(result.error);
(*value_7) = EnvironmentFailure_OutOfRange;
return result;
}
bool* value_8 = &(result.is_ok);
(*value_8) = true;
int64_t* value_9 = &(result.value);
(*value_9) = value;
return result;
}
__type_4289a23f77d76d0a
ArgumentRead(int32_t argc, uint8_t** argv, int32_t index, Slice output)
{
__type_4289a23f77d76d0a result = {0};
if (argv == ((void *)0) || index < 0 || index >= argc) {
ArgumentFailure* value_0 = &(result.error);
(*value_0) = ArgumentFailure_InvalidIndex;
return result;
}
uint8_t* value = argv[index];
if (value == ((void *)0)) {
ArgumentFailure* value_1 = &(result.error);
(*value_1) = ArgumentFailure_NullArgument;
return result;
}
int64_t at = 0LL;
while (at < (int64_t)(output).length && value[at] != 0) {
uint8_t* value_2 = &(((uint8_t *)output.data)[at]);
(*value_2) = value[at];
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
if (at == (int64_t)(output).length && value[at] != 0) {
ArgumentFailure* value_3 = &(result.error);
(*value_3) = ArgumentFailure_TooLong;
return result;
}
bool* value_4 = &(result.is_ok);
(*value_4) = true;
String* value_5 = &(result.value);
Slice value_6 = output;
(*value_5) = TextFromBytes(SliceRange(value_6, (int64_t)0LL, (int64_t)at, sizeof(uint8_t)));
return result;
}
String
environment_linux_EnvironmentText(String name)
{
uint8_t buffer[256] = {0};
Slice value_0 = {buffer, 256};
bool value_1 = CopyCString(name, value_0);
if (!value_1) {
return StringLiteral("");
}
return TextFromCString(zir_f_65e9ad6d46228d2f_EnvironmentValueRaw(&(buffer[0])));
}
int64_t
environment_linux_EnvironmentNumber(String name, int64_t fallback)
{
Results__s64__s64 results_1_ = IntegerPrefix(environment_linux_EnvironmentText(name));
int64_t value = results_1_.value_0;
int64_t count = results_1_.value_1;
int64_t value_2 = 0;
if (count > 0LL) {
value_2 = value;
} else {
value_2 = fallback;
}
return value_2;
}
@@ -0,0 +1,120 @@
/* Generated by zi2c from environment_linux.zi. */
#ifndef ZIRAN_ENVIRONMENT_LINUX_H
#define ZIRAN_ENVIRONMENT_LINUX_H
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_slice.h"
#include "c_string.h"
#include "byte_text_linux.h"
#include "number_text.h"
#include "result.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef int64_t EnvironmentFailure;
typedef int64_t ArgumentFailure;
#ifndef ZIRAN_CONCRETE_FORWARD___type_6c5c09809af9b2be
#define ZIRAN_CONCRETE_FORWARD___type_6c5c09809af9b2be
typedef struct __type_6c5c09809af9b2be __type_6c5c09809af9b2be;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_2327be0556361c2c
#define ZIRAN_CONCRETE_FORWARD___type_2327be0556361c2c
typedef struct __type_2327be0556361c2c __type_2327be0556361c2c;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_4289a23f77d76d0a
#define ZIRAN_CONCRETE_FORWARD___type_4289a23f77d76d0a
typedef struct __type_4289a23f77d76d0a __type_4289a23f77d76d0a;
#endif
enum {
EnvironmentFailure_None = 0,
EnvironmentFailure_InvalidName = 1,
EnvironmentFailure_Unset = 2,
EnvironmentFailure_Empty = 3,
EnvironmentFailure_TooLong = 4,
EnvironmentFailure_NotNumber = 5,
EnvironmentFailure_OutOfRange = 6,
};
enum {
ArgumentFailure_None = 0,
ArgumentFailure_InvalidIndex = 1,
ArgumentFailure_NullArgument = 2,
ArgumentFailure_TooLong = 3,
};
#ifndef ZIRAN_CONCRETE___type_6c5c09809af9b2be
#define ZIRAN_CONCRETE___type_6c5c09809af9b2be
struct __type_6c5c09809af9b2be {
bool is_ok;
String value;
EnvironmentFailure error;
};
#endif
#ifndef ZIRAN_CONCRETE___type_2327be0556361c2c
#define ZIRAN_CONCRETE___type_2327be0556361c2c
struct __type_2327be0556361c2c {
bool is_ok;
int64_t value;
EnvironmentFailure error;
};
#endif
#ifndef ZIRAN_CONCRETE___type_4289a23f77d76d0a
#define ZIRAN_CONCRETE___type_4289a23f77d76d0a
struct __type_4289a23f77d76d0a {
bool is_ok;
String value;
ArgumentFailure error;
};
#endif
#ifndef ZIR_FOREIGN_zir_f_65e9ad6d46228d2f_EnvironmentValueRaw_40be1ae7
#define ZIR_FOREIGN_zir_f_65e9ad6d46228d2f_EnvironmentValueRaw_40be1ae7
#ifdef __APPLE__
uint8_t* zir_foreign_zir_f_65e9ad6d46228d2f_EnvironmentValueRaw(uint8_t* name) __asm__("_getenv");
#else
uint8_t* zir_foreign_zir_f_65e9ad6d46228d2f_EnvironmentValueRaw(uint8_t* name) __asm__("getenv");
#endif
static uint8_t*
zir_f_65e9ad6d46228d2f_EnvironmentValueRaw(uint8_t* name)
{
return zir_foreign_zir_f_65e9ad6d46228d2f_EnvironmentValueRaw(name);
}
#endif
__type_6c5c09809af9b2be environment_linux_BoundedHostText(uint8_t* value, Slice output);
__type_6c5c09809af9b2be EnvironmentRead(String name, Slice output);
__type_2327be0556361c2c EnvironmentRange(String name, int64_t minimum, int64_t maximum, Slice input);
__type_4289a23f77d76d0a ArgumentRead(int32_t argc, uint8_t** argv, int32_t index, Slice output);
String environment_linux_EnvironmentText(String name);
int64_t environment_linux_EnvironmentNumber(String name, int64_t fallback);
/* Small procedures other modules inline; environment_linux.c defines them. */
#if !defined(__cplusplus) && !defined(ZIRAN_ENVIRONMENT_LINUX_H_SOURCE) && !defined(ZIRAN_NO_HEADER_INLINE)
#include "zir_string_types.h"
static inline int64_t environment_linux_EnvironmentNumber_ziran_inline(String name, int64_t fallback);
#define environment_linux_EnvironmentNumber(...) environment_linux_EnvironmentNumber_ziran_inline(__VA_ARGS__)
static inline int64_t
environment_linux_EnvironmentNumber_ziran_inline(String name, int64_t fallback)
{
Results__s64__s64 results_1_ = IntegerPrefix(environment_linux_EnvironmentText(name));
int64_t value = results_1_.value_0;
int64_t count = results_1_.value_1;
int64_t value_2 = 0;
if (count > 0LL) {
value_2 = value;
} else {
value_2 = fallback;
}
return value_2;
}
#endif
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_ENVIRONMENT_LINUX_H */
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,254 @@
/* Generated by zi2c from file_tree_linux.zi. */
#ifndef ZIRAN_FILE_TREE_LINUX_H
#define ZIRAN_FILE_TREE_LINUX_H
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_slice.h"
#include "c_string.h"
#include "byte_text_linux.h"
#include "sort.h"
#include "file_linux.h"
#include "vec.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
#define CURRENT_DIRECTORY -2
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
#define NO_FOLLOW 32
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
#define zir_d_cb9b6d141a80fe4d 1537
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
#define zir_d_c3b8f5002e71e19e 521
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
#define zir_d_6c04178f7065919f 16777216
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
#define EXISTS 17
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
#define zir_d_e772df0ce0bb1f83 4
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
typedef struct StatRecord StatRecord;
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
typedef struct StatEntry StatEntry;
#endif
typedef uint8_t PathKind;
typedef struct PathInfo PathInfo;
typedef struct PathQueryResult PathQueryResult;
#ifndef ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
#define ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
typedef struct __type_838711075b90279a __type_838711075b90279a;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_c53c2d7c4913dc02
#define ZIRAN_CONCRETE_FORWARD___type_c53c2d7c4913dc02
typedef struct __type_c53c2d7c4913dc02 __type_c53c2d7c4913dc02;
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
typedef int32_t (*StatAt)(int32_t, uint8_t*, StatRecord*, int32_t);
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
struct StatRecord {
int32_t device;
uint16_t mode;
uint16_t links;
uint64_t inode;
uint32_t owner_uid;
uint32_t group_id;
int32_t special_device;
int32_t padding;
int64_t accessed;
int64_t accessed_nanoseconds;
int64_t modified;
int64_t modified_nanoseconds;
int64_t changed;
int64_t changed_nanoseconds;
int64_t born;
int64_t born_nanoseconds;
int64_t size;
int64_t blocks;
int32_t block_size;
uint32_t flags;
uint32_t generation;
int32_t spare;
int64_t reserved[8];
};
#endif
#ifdef ZIRAN_FILE_TREE_LINUX_H_PRIVATE
struct StatEntry {
StatAt call;
};
#endif
enum {
PathKind_Missing = 0,
PathKind_File = 1,
PathKind_Directory = 2,
PathKind_Link = 3,
PathKind_Other = 4,
};
struct PathInfo {
PathKind kind;
uint32_t owner_uid;
int32_t mode;
int64_t size;
int64_t modified;
uint32_t modified_nanoseconds;
uint32_t metadata_mask;
bool identity_valid;
uint64_t inode;
int64_t changed;
uint32_t changed_nanoseconds;
uint32_t device_major;
uint32_t device_minor;
};
struct PathQueryResult {
PathInfo info;
bool valid;
bool missing;
int32_t error;
};
#ifndef ZIRAN_CONCRETE___type_838711075b90279a
#define ZIRAN_CONCRETE___type_838711075b90279a
struct __type_838711075b90279a {
uint8_t* data;
int64_t count;
int64_t capacity;
};
#endif
#ifndef ZIRAN_CONCRETE___type_c53c2d7c4913dc02
#define ZIRAN_CONCRETE___type_c53c2d7c4913dc02
struct __type_c53c2d7c4913dc02 {
String* data;
int64_t count;
int64_t capacity;
};
#endif
PathQueryResult file_tree_linux_PathQuery(String path, bool follow_links);
PathInfo file_tree_linux_PathStatus(String path, bool follow_links);
PathInfo file_tree_linux_FileSnapshot(String path);
bool file_tree_linux_SameFileSnapshot(PathInfo left, PathInfo right);
bool file_tree_linux_IsFile(String path);
bool file_tree_linux_IsDirectory(String path);
bool file_tree_linux_SetPathMode(String path, int32_t mode);
Text file_tree_linux_JoinPath(String directory, String name);
String file_tree_linux_PathName(String path);
String file_tree_linux_PathParent(String path);
String file_tree_linux_PathSuffix(String path);
String file_tree_linux_PathStem(String path);
Text file_tree_linux_ResolvePath(String path);
Text file_tree_linux_CreateTemporaryDirectory(String parent, String prefix);
Text file_tree_linux_WorkingDirectory(void);
bool file_tree_linux_CreateDirectories(String path, int32_t mode);
void file_tree_linux_FreeDirectoryNames(__type_c53c2d7c4913dc02* names);
bool file_tree_linux_ListDirectory(String path, __type_c53c2d7c4913dc02* names);
bool file_tree_linux_RemoveTree(String path);
bool file_tree_linux_CopyFile(String source, String target);
bool file_tree_linux_CopyTree(String source, String target);
bool file_tree_linux_CopySymbolicLink(String source, String target);
bool file_tree_linux_CopyFileNew(String source, String target);
bool file_tree_linux_CopyTreeNew(String source, String target);
bool file_tree_linux_ReplaceFile(String path, String text);
int32_t file_tree_linux_LockPath(String path, bool exclusive, bool wait);
void file_tree_linux_UnlockPath(int32_t fd);
bool file_tree_linux_MatchName(String name, String pattern);
/* Small procedures other modules inline; file_tree_linux.c defines them. */
#if !defined(__cplusplus) && !defined(ZIRAN_FILE_TREE_LINUX_H_SOURCE) && !defined(ZIRAN_NO_HEADER_INLINE)
#include "zir_vec.h"
#include <stdbool.h>
#include "zir_string_types.h"
static inline PathInfo file_tree_linux_PathStatus_ziran_inline(String path, bool follow_links);
#define file_tree_linux_PathStatus(...) file_tree_linux_PathStatus_ziran_inline(__VA_ARGS__)
static inline PathInfo file_tree_linux_FileSnapshot_ziran_inline(String path);
#define file_tree_linux_FileSnapshot(...) file_tree_linux_FileSnapshot_ziran_inline(__VA_ARGS__)
static inline bool file_tree_linux_SameFileSnapshot_ziran_inline(PathInfo left, PathInfo right);
#define file_tree_linux_SameFileSnapshot(...) file_tree_linux_SameFileSnapshot_ziran_inline(__VA_ARGS__)
static inline bool file_tree_linux_IsFile_ziran_inline(String path);
#define file_tree_linux_IsFile(...) file_tree_linux_IsFile_ziran_inline(__VA_ARGS__)
static inline bool file_tree_linux_IsDirectory_ziran_inline(String path);
#define file_tree_linux_IsDirectory(...) file_tree_linux_IsDirectory_ziran_inline(__VA_ARGS__)
static inline PathInfo
file_tree_linux_PathStatus_ziran_inline(String path, bool follow_links)
{
PathQueryResult value_0 = file_tree_linux_PathQuery(path, follow_links);
return value_0.info;
}
static inline PathInfo
file_tree_linux_FileSnapshot_ziran_inline(String path)
{
String value_0 = path;
PathInfo value_1 = {0};
{
String path = value_0;
bool follow_links = false;
PathQueryResult value_3 = file_tree_linux_PathQuery(path, follow_links);
value_1 = value_3.info;
}
PathInfo result = value_1;
if (((PathKind)(result.kind)) != PathKind_File) {
bool* value_4 = &(result.identity_valid);
(*value_4) = false;
}
return result;
}
static inline bool
file_tree_linux_SameFileSnapshot_ziran_inline(PathInfo left, PathInfo right)
{
bool value_0 = left.identity_valid && right.identity_valid && ((PathKind)(left.kind)) == PathKind_File && ((PathKind)(right.kind)) == PathKind_File;
bool value_1 = value_0 && left.device_major == right.device_major && left.device_minor == right.device_minor && left.inode == right.inode;
bool value_2 = value_1 && left.size == right.size && left.modified == right.modified && left.modified_nanoseconds == right.modified_nanoseconds;
return value_2 && left.changed == right.changed && left.changed_nanoseconds == right.changed_nanoseconds;
}
static inline bool
file_tree_linux_IsFile_ziran_inline(String path)
{
String value_0 = path;
PathInfo value_1 = {0};
{
String path = value_0;
bool follow_links = true;
PathQueryResult value_3 = file_tree_linux_PathQuery(path, follow_links);
value_1 = value_3.info;
}
return ((PathKind)(value_1.kind)) == PathKind_File;
}
static inline bool
file_tree_linux_IsDirectory_ziran_inline(String path)
{
String value_0 = path;
PathInfo value_1 = {0};
{
String path = value_0;
bool follow_links = true;
PathQueryResult value_3 = file_tree_linux_PathQuery(path, follow_links);
value_1 = value_3.info;
}
return ((PathKind)(value_1.kind)) == PathKind_Directory;
}
#endif
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_FILE_TREE_LINUX_H */
@@ -0,0 +1,186 @@
/* Generated by zi2c from number_text.zi. */
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_bounds.h"
#include "number_text.h"
#ifndef ZIRAN_HELPER_SignedBits
#define ZIRAN_HELPER_SignedBits
/* SignedBits reads the low w bits of x as a signed number. */
static inline int64_t SignedBits(uint64_t x, int w) {
uint64_t mask = w == 64 ? UINT64_MAX : (UINT64_C(1) << w) - 1;
x &= mask;
return x <= (mask >> 1) ? (int64_t)x : -1 - (int64_t)(mask - x);
}
#endif
#ifndef ZIRAN_HELPER_FloatToInt
#define ZIRAN_HELPER_FloatToInt
/* FloatToInt converts x to a w-bit integer, aborting when it does not fit. */
static inline uint64_t FloatToInt(double x, int w, int sign) {
/* Powers of two are exact in double, including the unsigned 64-bit bound. */
double bound = w - sign == 64 ? 18446744073709551616.0 :
(double)(UINT64_C(1) << (w - sign));
if(!(x >= (sign ? -bound : 0) && x < bound)) abort();
return sign ? (uint64_t)(int64_t)x : (uint64_t)x;
}
#endif
#ifndef ZIRAN_HELPER_ZiDivS64
#define ZIRAN_HELPER_ZiDivS64
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__OPTIMIZE__)
#define ZiDivS64(a, b, min) __extension__ ({ int64_t __zi_a = (a), __zi_b = (b); if(!__zi_b) abort(); __zi_b == -1 ? (__zi_a == (min) ? __zi_a : -__zi_a) : __zi_a / __zi_b; })
#else
static inline int64_t ZiDivS64(int64_t a, int64_t b, int64_t min) {
if(!b) abort();
if(b == -1) return a == min ? a : -a;
return a / b;
}
#endif
#endif
#ifndef ZIRAN_HELPER_ZiRemS64
#define ZIRAN_HELPER_ZiRemS64
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__OPTIMIZE__)
#define ZiRemS64(a, b) __extension__ ({ int64_t __zi_a = (a), __zi_b = (b); if(!__zi_b) abort(); __zi_b == -1 ? 0 : __zi_a % __zi_b; })
#else
static inline int64_t ZiRemS64(int64_t a, int64_t b) {
if(!b) abort();
return b == -1 ? 0 : a % b;
}
#endif
#endif
#include "text_buffer.h"
String
FormatInteger(int64_t value, Slice output)
{
int64_t end = (int64_t)((uint64_t)((int64_t)(output).length) - UINT64_C(1));
uint8_t* value_0 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)end)]);
(*value_0) = 0;
bool negative = value < 0LL;
int64_t remaining = value;
if (negative) {
remaining = (int64_t)(UINT64_C(0) - (uint64_t)value);
}
if (remaining == 0LL) {
end = (int64_t)((uint64_t)end - UINT64_C(1));
uint8_t* value_1 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)end)]);
(*value_1) = 48;
}
while (remaining > 0LL) {
end = (int64_t)((uint64_t)end - UINT64_C(1));
uint8_t* value_2 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)end)]);
(*value_2) = (uint8_t)(((int32_t)(48u + (uint32_t)((remaining % 10LL)))));
remaining = remaining / 10LL;
}
if (negative) {
end = (int64_t)((uint64_t)end - UINT64_C(1));
uint8_t* value_3 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)end)]);
(*value_3) = 45;
}
Slice value_4 = output;
return TextUntilNul(SliceRange(value_4, (int64_t)end, (int64_t)(int64_t)(output).length, sizeof(uint8_t)));
}
Results__s64__s64
IntegerPrefix(String text)
{
int64_t at = 0LL;
bool negative = (int64_t)(text).length > 0LL && (uint8_t)ZIRAN_INDEX(text.data, text.length, 0) == 45;
if (negative) {
at = 1LL;
}
int64_t start = at;
int64_t value = 0LL;
while (at < (int64_t)(text).length && (uint8_t)ZIRAN_INDEX(text.data, text.length, at) >= 48 && (uint8_t)ZIRAN_INDEX(text.data, text.length, at) <= 57) {
if ((int64_t)((uint64_t)at - (uint64_t)start) >= 18LL) {
return (Results__s64__s64){.value_0 = 0LL, .value_1 = 0LL};
}
value = (int64_t)(((uint64_t)value * UINT64_C(10)) + (uint64_t)(((uint8_t)((uint32_t)((uint8_t)text.data[at]) - 48u))));
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
if (at == start) {
return (Results__s64__s64){.value_0 = 0LL, .value_1 = 0LL};
}
if (negative) {
value = (int64_t)(UINT64_C(0) - (uint64_t)value);
}
return (Results__s64__s64){.value_0 = value, .value_1 = at};
}
String
FormatDecimal(double value, int32_t places, Slice output)
{
int32_t digits = places;
if (digits < 0) {
digits = 0;
}
if (digits > 9) {
digits = 9;
}
int64_t scale = 1LL;
int32_t step = 0;
while (step < digits) {
scale = (int64_t)((uint64_t)scale * UINT64_C(10));
step = (int32_t)((uint32_t)step + 1u);
}
double scaled = value * (double)(scale);
if (value < 0.0) {
scaled = scaled - 0.5;
} else {
scaled = scaled + 0.5;
}
int64_t units = (int64_t)SignedBits(FloatToInt(scaled, 64, 1), 64);
bool negative = units < 0LL;
int64_t remaining = units;
if (negative) {
remaining = (int64_t)(UINT64_C(0) - (uint64_t)units);
}
int64_t whole = ZiDivS64(remaining, scale, INT64_MIN);
int64_t fraction = ZiRemS64(remaining, scale);
int64_t end = (int64_t)((uint64_t)((int64_t)(output).length) - UINT64_C(1));
uint8_t* value_0 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)end)]);
(*value_0) = 0;
int32_t kept = digits;
while (true) {
bool value_1 = kept > 0;
if (value_1) {
int64_t value_2 = fraction % 10LL;
value_1 = (value_2 == 0LL);
}
if (!value_1) { break; }
fraction = fraction / 10LL;
kept = (int32_t)((uint32_t)kept - 1u);
}
if (kept > 0) {
step = 0;
while (step < kept) {
end = (int64_t)((uint64_t)end - UINT64_C(1));
uint8_t* value_3 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)end)]);
(*value_3) = (uint8_t)(((int32_t)(48u + (uint32_t)((fraction % 10LL)))));
fraction = fraction / 10LL;
step = (int32_t)((uint32_t)step + 1u);
}
end = (int64_t)((uint64_t)end - UINT64_C(1));
uint8_t* value_4 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)end)]);
(*value_4) = 46;
}
if (whole == 0LL) {
end = (int64_t)((uint64_t)end - UINT64_C(1));
uint8_t* value_5 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)end)]);
(*value_5) = 48;
}
while (whole > 0LL) {
end = (int64_t)((uint64_t)end - UINT64_C(1));
uint8_t* value_6 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)end)]);
(*value_6) = (uint8_t)(((int32_t)(48u + (uint32_t)((whole % 10LL)))));
whole = whole / 10LL;
}
if (negative && units != 0LL) {
end = (int64_t)((uint64_t)end - UINT64_C(1));
uint8_t* value_7 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)end)]);
(*value_7) = 45;
}
Slice value_8 = output;
return TextUntilNul(SliceRange(value_8, (int64_t)end, (int64_t)(int64_t)(output).length, sizeof(uint8_t)));
}
@@ -0,0 +1,26 @@
/* Generated by zi2c from number_text.zi. */
#ifndef ZIRAN_NUMBER_TEXT_H
#define ZIRAN_NUMBER_TEXT_H
#include "zir_string_types.h"
#include "zir_slice.h"
#include "text_buffer.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct Results__s64__s64 Results__s64__s64;
struct Results__s64__s64 {
int64_t value_0;
int64_t value_1;
};
String FormatInteger(int64_t value, Slice output);
Results__s64__s64 IntegerPrefix(String text);
String FormatDecimal(double value, int32_t places, Slice output);
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_NUMBER_TEXT_H */
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,125 @@
/* Generated by zi2c from process_run_linux.zi. */
#ifndef ZIRAN_PROCESS_RUN_LINUX_H
#define ZIRAN_PROCESS_RUN_LINUX_H
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_slice.h"
#include "c_string.h"
#include "vec.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ZIRAN_PROCESS_RUN_LINUX_H_PRIVATE
#define zir_d_73216da6995ce4a3 16777216
#endif
#ifdef ZIRAN_PROCESS_RUN_LINUX_H_PRIVATE
#define zir_d_1bf5ef17752ba062 1537
#endif
#ifdef ZIRAN_PROCESS_RUN_LINUX_H_PRIVATE
#define zir_d_e81c7645e39d2e5f 521
#endif
#ifdef ZIRAN_PROCESS_RUN_LINUX_H_PRIVATE
#define zir_d_ed0a0fdef7fd3c5a 4
#endif
typedef struct ProcessArgumentSlot ProcessArgumentSlot;
typedef struct ProcessOptions ProcessOptions;
#ifndef ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
#define ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
typedef struct __type_838711075b90279a __type_838711075b90279a;
#endif
typedef struct ProcessRun ProcessRun;
#ifndef ZIRAN_CONCRETE_FORWARD___type_01e5ac0505e23acf
#define ZIRAN_CONCRETE_FORWARD___type_01e5ac0505e23acf
typedef struct __type_01e5ac0505e23acf __type_01e5ac0505e23acf;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_1f00ef809eed7c2e
#define ZIRAN_CONCRETE_FORWARD___type_1f00ef809eed7c2e
typedef struct __type_1f00ef809eed7c2e __type_1f00ef809eed7c2e;
#endif
#ifdef ZIRAN_PROCESS_RUN_LINUX_H_PRIVATE
typedef struct Prepared Prepared;
#endif
#ifdef ZIRAN_PROCESS_RUN_LINUX_H_PRIVATE
typedef void (*SignalHandler)(int32_t);
#endif
struct ProcessArgumentSlot {
uint8_t* value;
};
struct ProcessOptions {
Slice arguments;
String directory;
Slice environment;
String input_path;
String output_path;
bool append_output;
String error_path;
bool merge_error;
bool capture_output;
bool new_session;
};
#ifndef ZIRAN_CONCRETE___type_838711075b90279a
#define ZIRAN_CONCRETE___type_838711075b90279a
struct __type_838711075b90279a {
uint8_t* data;
int64_t count;
int64_t capacity;
};
#endif
struct ProcessRun {
int32_t pid;
int32_t code;
bool started;
bool finished;
__type_838711075b90279a output;
};
#ifndef ZIRAN_CONCRETE___type_01e5ac0505e23acf
#define ZIRAN_CONCRETE___type_01e5ac0505e23acf
struct __type_01e5ac0505e23acf {
ProcessArgumentSlot* data;
int64_t count;
int64_t capacity;
};
#endif
#ifndef ZIRAN_CONCRETE___type_1f00ef809eed7c2e
#define ZIRAN_CONCRETE___type_1f00ef809eed7c2e
struct __type_1f00ef809eed7c2e {
int64_t* data;
int64_t count;
int64_t capacity;
};
#endif
#ifdef ZIRAN_PROCESS_RUN_LINUX_H_PRIVATE
struct Prepared {
__type_838711075b90279a bytes;
__type_01e5ac0505e23acf arguments;
__type_1f00ef809eed7c2e argument_offsets;
__type_1f00ef809eed7c2e names;
__type_1f00ef809eed7c2e values;
int64_t directory;
int64_t input;
int64_t output;
int64_t error;
};
#endif
bool process_run_linux_StartProcess(ProcessOptions options, ProcessRun* run);
bool process_run_linux_PollProcess(ProcessRun* run);
bool process_run_linux_WaitProcess(ProcessRun* run);
bool process_run_linux_SignalProcess(ProcessRun* run, int32_t signal_number, bool whole_group);
bool process_run_linux_RunProcess(ProcessOptions options, ProcessRun* run);
void process_run_linux_CatchTermination(void);
bool process_run_linux_TerminationRequested(void);
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_PROCESS_RUN_LINUX_H */
@@ -0,0 +1,68 @@
/* Generated by zi2c from sort.zi. */
#include <stdbool.h>
#include "zir_string_types.h"
#include "sort.h"
#ifndef ZIRAN_MAYBE_UNUSED
#if defined(__GNUC__) || defined(__clang__)
#define ZIRAN_MAYBE_UNUSED __attribute__((unused))
#else
#define ZIRAN_MAYBE_UNUSED
#endif
#endif
static bool sort_TextBefore(String a, String b) ZIRAN_MAYBE_UNUSED;
static void sort_TextSiftDown(Slice values, int64_t root, int64_t end) ZIRAN_MAYBE_UNUSED;
static bool
sort_TextBefore(String a, String b)
{
int64_t index = 0LL;
while (index < (int64_t)(a).length && index < (int64_t)(b).length) {
if ((uint8_t)a.data[index] != (uint8_t)b.data[index]) {
return (uint8_t)a.data[index] < (uint8_t)b.data[index];
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
return (int64_t)(a).length < (int64_t)(b).length;
}
static void
sort_TextSiftDown(Slice values, int64_t root, int64_t end)
{
int64_t parent = root;
while ((int64_t)(((uint64_t)parent * UINT64_C(2)) + UINT64_C(1)) < end) {
int64_t child = (int64_t)(((uint64_t)parent * UINT64_C(2)) + UINT64_C(1));
if ((int64_t)((uint64_t)child + UINT64_C(1)) < end && sort_TextBefore(((String *)values.data)[SliceIndex(values, (int64_t)child)], ((String *)values.data)[SliceIndex(values, (int64_t)((int64_t)((uint64_t)child + UINT64_C(1))))])) {
child = (int64_t)((uint64_t)child + UINT64_C(1));
}
bool value_0 = sort_TextBefore(((String *)values.data)[SliceIndex(values, (int64_t)parent)], ((String *)values.data)[SliceIndex(values, (int64_t)child)]);
if (!value_0) {
return;
}
String saved = ((String *)values.data)[SliceIndex(values, (int64_t)parent)];
String* value_1 = &(((String *)values.data)[SliceIndex(values, (int64_t)parent)]);
(*value_1) = ((String *)values.data)[SliceIndex(values, (int64_t)child)];
String* value_2 = &(((String *)values.data)[SliceIndex(values, (int64_t)child)]);
(*value_2) = saved;
parent = child;
}
}
void
sort_SortText(Slice values)
{
int64_t start = (int64_t)(values).length / 2LL;
while (start > 0LL) {
start = (int64_t)((uint64_t)start - UINT64_C(1));
sort_TextSiftDown(values, start, (int64_t)(values).length);
}
int64_t end = (int64_t)(values).length;
while (end > 1LL) {
end = (int64_t)((uint64_t)end - UINT64_C(1));
String saved = ((String *)values.data)[SliceIndex(values, (int64_t)0)];
String* value_0 = &(((String *)values.data)[SliceIndex(values, (int64_t)0)]);
(*value_0) = ((String *)values.data)[SliceIndex(values, (int64_t)end)];
String* value_1 = &(((String *)values.data)[SliceIndex(values, (int64_t)end)]);
(*value_1) = saved;
sort_TextSiftDown(values, 0LL, end);
}
}
@@ -0,0 +1,16 @@
/* Generated by zi2c from sort.zi. */
#ifndef ZIRAN_SORT_H
#define ZIRAN_SORT_H
#include "zir_slice.h"
#ifdef __cplusplus
extern "C" {
#endif
void sort_SortText(Slice values);
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_SORT_H */
@@ -0,0 +1,18 @@
/* Generated by zi2c from text_buffer.zi. */
#include "zir_string_types.h"
#include "text_buffer.h"
String
TextUntilNul(Slice buffer)
{
int64_t index = 0LL;
while (index < (int64_t)(buffer).length) {
if (((uint8_t *)buffer.data)[index] == 0) {
Slice value_0 = buffer;
Slice value_1 = SliceRange(value_0, (int64_t)0LL, (int64_t)index, sizeof(uint8_t));
return StringView((const char *)(value_1).data, (size_t)(value_1).length);
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
return StringLiteral("");
}
@@ -0,0 +1,17 @@
/* Generated by zi2c from text_buffer.zi. */
#ifndef ZIRAN_TEXT_BUFFER_H
#define ZIRAN_TEXT_BUFFER_H
#include "zir_string_types.h"
#include "zir_slice.h"
#ifdef __cplusplus
extern "C" {
#endif
String TextUntilNul(Slice buffer);
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_TEXT_BUFFER_H */
@@ -0,0 +1,643 @@
/* Generated by zi2c from text_tools.zi. */
#define ZIRAN_TEXT_TOOLS_H_SOURCE 1
#include <stdbool.h>
#include "zir_bounds.h"
#include "zir_string.h"
#include "zir_vec.h"
#include "text_tools.h"
int64_t
text_tools_TextFind(String text, String needle, int64_t from)
{
if (from < 0LL) {
return -1LL;
}
int64_t last = (int64_t)((uint64_t)((int64_t)(text).length) - (uint64_t)((int64_t)(needle).length));
int64_t at = from;
while (at <= last) {
int64_t index = 0LL;
while (index < (int64_t)(needle).length && (uint8_t)ZIRAN_INDEX(text.data, text.length, ((int64_t)((uint64_t)at + (uint64_t)index))) == (uint8_t)ZIRAN_INDEX(needle.data, needle.length, index)) {
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
if (index == (int64_t)(needle).length) {
return at;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
return -1LL;
}
int64_t
text_tools_TextFindLast(String text, String needle)
{
int64_t at = (int64_t)((uint64_t)((int64_t)(text).length) - (uint64_t)((int64_t)(needle).length));
while (at >= 0LL) {
int64_t index = 0LL;
while (index < (int64_t)(needle).length && (uint8_t)ZIRAN_INDEX(text.data, text.length, ((int64_t)((uint64_t)at + (uint64_t)index))) == (uint8_t)ZIRAN_INDEX(needle.data, needle.length, index)) {
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
if (index == (int64_t)(needle).length) {
return at;
}
at = (int64_t)((uint64_t)at - UINT64_C(1));
}
return -1LL;
}
bool
text_tools_TextContains(String text, String needle)
{
int64_t value_0 = text_tools_TextFind(text, needle, 0LL);
return value_0 >= 0LL;
}
bool
text_tools_TextHasPrefix(String text, String prefix)
{
if ((int64_t)(prefix).length > (int64_t)(text).length) {
return false;
}
return StringEqual(StringRange(text, (int64_t)0LL, (int64_t)(int64_t)(prefix).length), prefix);
}
bool
text_tools_TextHasSuffix(String text, String suffix)
{
if ((int64_t)(suffix).length > (int64_t)(text).length) {
return false;
}
return StringEqual(StringRange(text, (int64_t)((int64_t)((uint64_t)((int64_t)(text).length) - (uint64_t)((int64_t)(suffix).length))), (int64_t)(int64_t)(text).length), suffix);
}
bool
text_tools_TextIsSpace(uint8_t byte)
{
return byte == 32 || (byte >= 9 && byte <= 13);
}
String
text_tools_TextTrim(String text)
{
int64_t start = 0LL;
int64_t end = (int64_t)(text).length;
while (true) {
bool value_0 = start < end;
if (value_0) {
uint8_t value_1 = (uint8_t)ZIRAN_INDEX(text.data, text.length, start);
bool value_2 = false;
{
uint8_t byte = value_1;
value_2 = byte == 32 || (byte >= 9 && byte <= 13);
}
value_0 = value_2;
}
if (!value_0) { break; }
start = (int64_t)((uint64_t)start + UINT64_C(1));
}
while (true) {
bool value_4 = end > start;
if (value_4) {
uint8_t value_5 = (uint8_t)ZIRAN_INDEX(text.data, text.length, ((int64_t)((uint64_t)end - UINT64_C(1))));
bool value_6 = false;
{
uint8_t byte = value_5;
value_6 = byte == 32 || (byte >= 9 && byte <= 13);
}
value_4 = value_6;
}
if (!value_4) { break; }
end = (int64_t)((uint64_t)end - UINT64_C(1));
}
return StringRange(text, (int64_t)start, (int64_t)end);
}
String
text_tools_TextTrimEnd(String text)
{
int64_t end = (int64_t)(text).length;
while (true) {
bool value_0 = end > 0LL;
if (value_0) {
uint8_t value_1 = (uint8_t)ZIRAN_INDEX(text.data, text.length, ((int64_t)((uint64_t)end - UINT64_C(1))));
bool value_2 = false;
{
uint8_t byte = value_1;
value_2 = byte == 32 || (byte >= 9 && byte <= 13);
}
value_0 = value_2;
}
if (!value_0) { break; }
end = (int64_t)((uint64_t)end - UINT64_C(1));
}
return StringRange(text, (int64_t)0LL, (int64_t)end);
}
__type_c53c2d7c4913dc02
text_tools_TextSplit(String text, String separator)
{
__type_c53c2d7c4913dc02 pieces = {0};
__type_c53c2d7c4913dc02* value_0 = &pieces;
if ((int64_t)(separator).length == 0LL) {
String value_1 = text;
bool value_2 = false;
void *value_3 = ZirVecGrow((void *)(pieces).data, &(pieces).capacity, (pieces).count, sizeof(*(pieces).data));
if (value_3 != NULL) {
(pieces).data = (String *)value_3;
(pieces).data[(pieces).count++] = value_1;
value_2 = true;
}
(void)value_2;
__type_c53c2d7c4913dc02 value_4 = pieces;
pieces.data = NULL;
pieces.capacity = 0;
pieces.count = 0;
__type_c53c2d7c4913dc02 value_5 = value_4;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_5;
}
int64_t start = 0LL;
int64_t at = text_tools_TextFind(text, separator, 0LL);
while (at >= 0LL) {
String value_6 = StringRange(text, (int64_t)start, (int64_t)at);
bool value_7 = false;
void *value_8 = ZirVecGrow((void *)(pieces).data, &(pieces).capacity, (pieces).count, sizeof(*(pieces).data));
if (value_8 != NULL) {
(pieces).data = (String *)value_8;
(pieces).data[(pieces).count++] = value_6;
value_7 = true;
}
(void)value_7;
start = (int64_t)((uint64_t)at + (uint64_t)((int64_t)(separator).length));
at = text_tools_TextFind(text, separator, start);
}
String value_9 = StringRange(text, (int64_t)start, (int64_t)(int64_t)(text).length);
bool value_10 = false;
void *value_11 = ZirVecGrow((void *)(pieces).data, &(pieces).capacity, (pieces).count, sizeof(*(pieces).data));
if (value_11 != NULL) {
(pieces).data = (String *)value_11;
(pieces).data[(pieces).count++] = value_9;
value_10 = true;
}
(void)value_10;
__type_c53c2d7c4913dc02 value_12 = pieces;
pieces.data = NULL;
pieces.capacity = 0;
pieces.count = 0;
__type_c53c2d7c4913dc02 value_13 = value_12;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_13;
}
__type_c53c2d7c4913dc02
text_tools_TextLines(String text)
{
__type_c53c2d7c4913dc02 lines = {0};
__type_c53c2d7c4913dc02* value_0 = &lines;
int64_t start = 0LL;
int64_t at = 0LL;
while (at < (int64_t)(text).length) {
uint8_t byte = (uint8_t)ZIRAN_INDEX(text.data, text.length, at);
if (byte == 10 || byte == 13) {
String value_1 = StringRange(text, (int64_t)start, (int64_t)at);
bool value_2 = false;
void *value_3 = ZirVecGrow((void *)(lines).data, &(lines).capacity, (lines).count, sizeof(*(lines).data));
if (value_3 != NULL) {
(lines).data = (String *)value_3;
(lines).data[(lines).count++] = value_1;
value_2 = true;
}
(void)value_2;
if (byte == 13 && (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(text).length && (uint8_t)ZIRAN_INDEX(text.data, text.length, ((int64_t)((uint64_t)at + UINT64_C(1)))) == 10) {
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
start = (int64_t)((uint64_t)at + UINT64_C(1));
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
if (start < (int64_t)(text).length) {
String value_4 = StringRange(text, (int64_t)start, (int64_t)(int64_t)(text).length);
bool value_5 = false;
void *value_6 = ZirVecGrow((void *)(lines).data, &(lines).capacity, (lines).count, sizeof(*(lines).data));
if (value_6 != NULL) {
(lines).data = (String *)value_6;
(lines).data[(lines).count++] = value_4;
value_5 = true;
}
(void)value_5;
}
__type_c53c2d7c4913dc02 value_7 = lines;
lines.data = NULL;
lines.capacity = 0;
lines.count = 0;
__type_c53c2d7c4913dc02 value_8 = value_7;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_8;
}
Text
text_tools_TextReplace(String text, String old, String new)
{
if ((int64_t)(old).length == 0LL) {
return vec_TextCopy(text);
}
int64_t at = text_tools_TextFind(text, old, 0LL);
if (at < 0LL) {
return vec_TextCopy(text);
}
__type_838711075b90279a result = {0};
__type_838711075b90279a* value_0 = &result;
int64_t start = 0LL;
while (at >= 0LL) {
bool value_1 = false;
if ((StringRange(text, (int64_t)start, (int64_t)at)).length == 0) {
value_1 = true;
} else {
void *value_2 = ZirVecReserve((void *)(result).data, &(result).capacity, (result).count, (int64_t)(StringRange(text, (int64_t)start, (int64_t)at)).length, sizeof(*(result).data));
if (value_2 != NULL) {
(result).data = (uint8_t *)value_2;
memcpy((result).data + (result).count, (StringRange(text, (int64_t)start, (int64_t)at)).data, (size_t)(StringRange(text, (int64_t)start, (int64_t)at)).length);
(result).count += (int64_t)(StringRange(text, (int64_t)start, (int64_t)at)).length;
value_1 = true;
}
}
(void)value_1;
bool value_3 = false;
if ((new).length == 0) {
value_3 = true;
} else {
void *value_4 = ZirVecReserve((void *)(result).data, &(result).capacity, (result).count, (int64_t)(new).length, sizeof(*(result).data));
if (value_4 != NULL) {
(result).data = (uint8_t *)value_4;
memcpy((result).data + (result).count, (new).data, (size_t)(new).length);
(result).count += (int64_t)(new).length;
value_3 = true;
}
}
(void)value_3;
start = (int64_t)((uint64_t)at + (uint64_t)((int64_t)(old).length));
at = text_tools_TextFind(text, old, start);
}
bool value_5 = false;
if ((StringRange(text, (int64_t)start, (int64_t)(int64_t)(text).length)).length == 0) {
value_5 = true;
} else {
void *value_6 = ZirVecReserve((void *)(result).data, &(result).capacity, (result).count, (int64_t)(StringRange(text, (int64_t)start, (int64_t)(int64_t)(text).length)).length, sizeof(*(result).data));
if (value_6 != NULL) {
(result).data = (uint8_t *)value_6;
memcpy((result).data + (result).count, (StringRange(text, (int64_t)start, (int64_t)(int64_t)(text).length)).data, (size_t)(StringRange(text, (int64_t)start, (int64_t)(int64_t)(text).length)).length);
(result).count += (int64_t)(StringRange(text, (int64_t)start, (int64_t)(int64_t)(text).length)).length;
value_5 = true;
}
}
(void)value_5;
__type_838711075b90279a value_7 = result;
result.data = NULL;
result.capacity = 0;
result.count = 0;
Text value_8 = vec_TextFromBuilder(value_7);
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_8;
}
Text
text_tools_TextJoin(Slice parts, String separator)
{
__type_838711075b90279a result = {0};
__type_838711075b90279a* value_0 = &result;
int64_t index = 0LL;
while (index < (int64_t)(parts).length) {
if (index > 0LL) {
bool value_1 = false;
if ((separator).length == 0) {
value_1 = true;
} else {
void *value_2 = ZirVecReserve((void *)(result).data, &(result).capacity, (result).count, (int64_t)(separator).length, sizeof(*(result).data));
if (value_2 != NULL) {
(result).data = (uint8_t *)value_2;
memcpy((result).data + (result).count, (separator).data, (size_t)(separator).length);
(result).count += (int64_t)(separator).length;
value_1 = true;
}
}
(void)value_1;
}
bool value_3 = false;
if ((((String *)parts.data)[index]).length == 0) {
value_3 = true;
} else {
void *value_4 = ZirVecReserve((void *)(result).data, &(result).capacity, (result).count, (int64_t)(((String *)parts.data)[index]).length, sizeof(*(result).data));
if (value_4 != NULL) {
(result).data = (uint8_t *)value_4;
memcpy((result).data + (result).count, (((String *)parts.data)[index]).data, (size_t)(((String *)parts.data)[index]).length);
(result).count += (int64_t)(((String *)parts.data)[index]).length;
value_3 = true;
}
}
(void)value_3;
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
__type_838711075b90279a value_5 = result;
result.data = NULL;
result.capacity = 0;
result.count = 0;
Text value_6 = vec_TextFromBuilder(value_5);
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_6;
}
Text
text_tools_TextLower(String text)
{
__type_838711075b90279a result = {0};
__type_838711075b90279a* value_0 = &result;
for (int64_t it_index = 0LL; it_index < (int64_t)(text).length; it_index++) {
uint8_t it = (uint8_t)text.data[it_index];
uint8_t byte = it;
if (byte >= 65 && byte <= 90) {
byte = (uint8_t)((uint32_t)byte + 32u);
}
uint8_t value_1 = byte;
bool value_2 = false;
void *value_3 = ZirVecGrow((void *)(result).data, &(result).capacity, (result).count, sizeof(*(result).data));
if (value_3 != NULL) {
(result).data = (uint8_t *)value_3;
(result).data[(result).count++] = value_1;
value_2 = true;
}
(void)value_2;
}
__type_838711075b90279a value_4 = result;
result.data = NULL;
result.capacity = 0;
result.count = 0;
Text value_5 = vec_TextFromBuilder(value_4);
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_5;
}
bool
text_tools_TextIsDecimal(String text)
{
if ((int64_t)(text).length == 0LL) {
return false;
}
for (int64_t it_index = 0LL; it_index < (int64_t)(text).length; it_index++) {
uint8_t it = (uint8_t)text.data[it_index];
if (it < 48 || it > 57) {
return false;
}
}
return true;
}
bool
text_tools_TextIsLowerHex(String text)
{
if ((int64_t)(text).length == 0LL) {
return false;
}
for (int64_t it_index = 0LL; it_index < (int64_t)(text).length; it_index++) {
uint8_t it = (uint8_t)text.data[it_index];
if (!((it >= 48 && it <= 57) || (it >= 97 && it <= 102))) {
return false;
}
}
return true;
}
bool
text_tools_TextOnly(String text, String allowed)
{
if ((int64_t)(text).length == 0LL) {
return false;
}
int64_t at = 0LL;
while (at < (int64_t)(text).length) {
int64_t value_0 = text_tools_TextFind(allowed, StringRange(text, (int64_t)at, (int64_t)((int64_t)((uint64_t)at + UINT64_C(1)))), 0LL);
if (value_0 < 0LL) {
return false;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
return true;
}
Results__s64__bool
text_tools_TextInteger(String text)
{
if ((int64_t)(text).length == 0LL) {
return (Results__s64__bool){.value_0 = 0LL, .value_1 = false};
}
bool negative = (uint8_t)text.data[0] == 45;
int64_t value_2 = 0;
if (negative || (uint8_t)text.data[0] == 43) {
value_2 = 1LL;
} else {
value_2 = 0LL;
}
int64_t start = value_2;
if (start == (int64_t)(text).length || (int64_t)((uint64_t)((int64_t)(text).length) - (uint64_t)start) > 18LL) {
return (Results__s64__bool){.value_0 = 0LL, .value_1 = false};
}
int64_t value = 0LL;
int64_t at = start;
while (at < (int64_t)(text).length) {
uint8_t byte = (uint8_t)text.data[at];
if (byte < 48 || byte > 57) {
return (Results__s64__bool){.value_0 = 0LL, .value_1 = false};
}
value = (int64_t)(((uint64_t)value * UINT64_C(10)) + (uint64_t)(((uint8_t)((uint32_t)byte - 48u))));
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
int64_t value_3 = 0;
if (negative) {
value_3 = (int64_t)(UINT64_C(0) - (uint64_t)value);
} else {
value_3 = value;
}
return (Results__s64__bool){.value_0 = value_3, .value_1 = true};
}
int32_t
text_tools_TextHexDigit(uint8_t byte)
{
if (byte >= 48 && byte <= 57) {
return (int32_t)(((uint8_t)((uint32_t)byte - 48u)));
}
if (byte >= 97 && byte <= 102) {
return (int32_t)((uint32_t)(((uint8_t)((uint32_t)byte - 97u))) + 10u);
}
if (byte >= 65 && byte <= 70) {
return (int32_t)((uint32_t)(((uint8_t)((uint32_t)byte - 65u))) + 10u);
}
return -1;
}
bool
text_tools_TextHexDecodeInto(String value, __type_838711075b90279a* output, int64_t max_bytes)
{
bool value_0 = max_bytes < 0LL;
if (!value_0) {
int64_t value_1 = (int64_t)(value).length % 2LL;
value_0 = (value_1 != 0LL);
}
if (value_0) {
return false;
}
int64_t decoded_count = (int64_t)(value).length / 2LL;
if (decoded_count > max_bytes) {
return false;
}
__type_838711075b90279a decoded = {0};
__type_838711075b90279a* value_2 = &decoded;
int64_t at = 0LL;
while (at < (int64_t)(value).length) {
uint8_t value_3 = (uint8_t)ZIRAN_INDEX(value.data, value.length, at);
int32_t value_4 = 0;
{
uint8_t byte = value_3;
if (byte >= 48 && byte <= 57) {
value_4 = (int32_t)(((uint8_t)((uint32_t)byte - 48u)));
goto value_5;
}
if (byte >= 97 && byte <= 102) {
value_4 = (int32_t)((uint32_t)(((uint8_t)((uint32_t)byte - 97u))) + 10u);
goto value_5;
}
if (byte >= 65 && byte <= 70) {
value_4 = (int32_t)((uint32_t)(((uint8_t)((uint32_t)byte - 65u))) + 10u);
goto value_5;
}
value_4 = -1;
value_5: ;
}
int32_t high = value_4;
uint8_t value_6 = (uint8_t)ZIRAN_INDEX(value.data, value.length, ((int64_t)((uint64_t)at + UINT64_C(1))));
int32_t value_7 = 0;
{
uint8_t byte = value_6;
if (byte >= 48 && byte <= 57) {
value_7 = (int32_t)(((uint8_t)((uint32_t)byte - 48u)));
goto value_8;
}
if (byte >= 97 && byte <= 102) {
value_7 = (int32_t)((uint32_t)(((uint8_t)((uint32_t)byte - 97u))) + 10u);
goto value_8;
}
if (byte >= 65 && byte <= 70) {
value_7 = (int32_t)((uint32_t)(((uint8_t)((uint32_t)byte - 65u))) + 10u);
goto value_8;
}
value_7 = -1;
value_8: ;
}
int32_t low = value_7;
bool value_9 = high < 0 || low < 0;
if (!value_9) {
uint8_t value_10 = (uint8_t)(((int32_t)(((uint32_t)high * 16u) + (uint32_t)low)));
bool value_11 = false;
void *value_12 = ZirVecGrow((void *)(decoded).data, &(decoded).capacity, (decoded).count, sizeof(*(decoded).data));
if (value_12 != NULL) {
(decoded).data = (uint8_t *)value_12;
(decoded).data[(decoded).count++] = value_10;
value_11 = true;
}
value_9 = !value_11;
}
if (value_9) {
free((decoded).data);
(decoded).data = NULL;
decoded.capacity = 0;
decoded.count = 0;
bool value_13 = false;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_13;
}
at = (int64_t)((uint64_t)at + UINT64_C(2));
}
Slice value_14 = {(decoded).data, (decoded).count};
Slice value_15 = SliceRange(value_14, 0LL, decoded.count, sizeof(*(decoded).data));
bool value_16 = false;
if ((StringView((const char *)(value_15).data, (size_t)(value_15).length)).length == 0) {
value_16 = true;
} else {
void *value_17 = ZirVecReserve((void *)((*(output))).data, &((*(output))).capacity, ((*(output))).count, (int64_t)(StringView((const char *)(value_15).data, (size_t)(value_15).length)).length, sizeof(*((*(output))).data));
if (value_17 != NULL) {
((*(output))).data = (uint8_t *)value_17;
memcpy(((*(output))).data + ((*(output))).count, (StringView((const char *)(value_15).data, (size_t)(value_15).length)).data, (size_t)(StringView((const char *)(value_15).data, (size_t)(value_15).length)).length);
((*(output))).count += (int64_t)(StringView((const char *)(value_15).data, (size_t)(value_15).length)).length;
value_16 = true;
}
}
bool appended = value_16;
free((decoded).data);
(decoded).data = NULL;
decoded.capacity = 0;
decoded.count = 0;
bool value_18 = appended;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_18;
}
Text
text_tools_TextHex(Slice bytes)
{
String digits = StringLiteral("0123456789abcdef");
__type_838711075b90279a result = {0};
__type_838711075b90279a* value_0 = &result;
for (int64_t it_index = 0LL; it_index < (int64_t)(bytes).length; it_index++) {
uint8_t it = ((uint8_t *)bytes.data)[it_index];
uint8_t value_1 = (uint8_t)ZIRAN_INDEX(digits.data, digits.length, ((uint8_t)(it >> 4)));
bool value_2 = false;
void *value_3 = ZirVecGrow((void *)(result).data, &(result).capacity, (result).count, sizeof(*(result).data));
if (value_3 != NULL) {
(result).data = (uint8_t *)value_3;
(result).data[(result).count++] = value_1;
value_2 = true;
}
(void)value_2;
uint8_t value_4 = (uint8_t)ZIRAN_INDEX(digits.data, digits.length, ((uint8_t)((uint32_t)it & 15u)));
bool value_5 = false;
void *value_6 = ZirVecGrow((void *)(result).data, &(result).capacity, (result).count, sizeof(*(result).data));
if (value_6 != NULL) {
(result).data = (uint8_t *)value_6;
(result).data[(result).count++] = value_4;
value_5 = true;
}
(void)value_5;
}
__type_838711075b90279a value_7 = result;
result.data = NULL;
result.capacity = 0;
result.count = 0;
Text value_8 = vec_TextFromBuilder(value_7);
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_8;
}
@@ -0,0 +1,189 @@
/* Generated by zi2c from text_tools.zi. */
#ifndef ZIRAN_TEXT_TOOLS_H
#define ZIRAN_TEXT_TOOLS_H
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_bounds.h"
#include "zir_slice.h"
#include "vec.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct Results__s64__bool Results__s64__bool;
#ifndef ZIRAN_CONCRETE_FORWARD___type_c53c2d7c4913dc02
#define ZIRAN_CONCRETE_FORWARD___type_c53c2d7c4913dc02
typedef struct __type_c53c2d7c4913dc02 __type_c53c2d7c4913dc02;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
#define ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
typedef struct __type_838711075b90279a __type_838711075b90279a;
#endif
struct Results__s64__bool {
int64_t value_0;
bool value_1;
};
#ifndef ZIRAN_CONCRETE___type_c53c2d7c4913dc02
#define ZIRAN_CONCRETE___type_c53c2d7c4913dc02
struct __type_c53c2d7c4913dc02 {
String* data;
int64_t count;
int64_t capacity;
};
#endif
#ifndef ZIRAN_CONCRETE___type_838711075b90279a
#define ZIRAN_CONCRETE___type_838711075b90279a
struct __type_838711075b90279a {
uint8_t* data;
int64_t count;
int64_t capacity;
};
#endif
int64_t text_tools_TextFind(String text, String needle, int64_t from);
int64_t text_tools_TextFindLast(String text, String needle);
bool text_tools_TextContains(String text, String needle);
bool text_tools_TextHasPrefix(String text, String prefix);
bool text_tools_TextHasSuffix(String text, String suffix);
bool text_tools_TextIsSpace(uint8_t byte);
String text_tools_TextTrim(String text);
String text_tools_TextTrimEnd(String text);
__type_c53c2d7c4913dc02 text_tools_TextSplit(String text, String separator);
__type_c53c2d7c4913dc02 text_tools_TextLines(String text);
Text text_tools_TextReplace(String text, String old, String new);
Text text_tools_TextJoin(Slice parts, String separator);
Text text_tools_TextLower(String text);
bool text_tools_TextIsDecimal(String text);
bool text_tools_TextIsLowerHex(String text);
bool text_tools_TextOnly(String text, String allowed);
Results__s64__bool text_tools_TextInteger(String text);
int32_t text_tools_TextHexDigit(uint8_t byte);
bool text_tools_TextHexDecodeInto(String value, __type_838711075b90279a* output, int64_t max_bytes);
Text text_tools_TextHex(Slice bytes);
/* Small procedures other modules inline; text_tools.c defines them. */
#if !defined(__cplusplus) && !defined(ZIRAN_TEXT_TOOLS_H_SOURCE) && !defined(ZIRAN_NO_HEADER_INLINE)
#include "zir_vec.h"
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_bounds.h"
static inline int64_t text_tools_TextFind_ziran_inline(String text, String needle, int64_t from);
#define text_tools_TextFind(...) text_tools_TextFind_ziran_inline(__VA_ARGS__)
static inline int64_t text_tools_TextFindLast_ziran_inline(String text, String needle);
#define text_tools_TextFindLast(...) text_tools_TextFindLast_ziran_inline(__VA_ARGS__)
static inline bool text_tools_TextContains_ziran_inline(String text, String needle);
#define text_tools_TextContains(...) text_tools_TextContains_ziran_inline(__VA_ARGS__)
static inline bool text_tools_TextIsSpace_ziran_inline(uint8_t byte);
#define text_tools_TextIsSpace(...) text_tools_TextIsSpace_ziran_inline(__VA_ARGS__)
static inline bool text_tools_TextIsDecimal_ziran_inline(String text);
#define text_tools_TextIsDecimal(...) text_tools_TextIsDecimal_ziran_inline(__VA_ARGS__)
static inline bool text_tools_TextIsLowerHex_ziran_inline(String text);
#define text_tools_TextIsLowerHex(...) text_tools_TextIsLowerHex_ziran_inline(__VA_ARGS__)
static inline int32_t text_tools_TextHexDigit_ziran_inline(uint8_t byte);
#define text_tools_TextHexDigit(...) text_tools_TextHexDigit_ziran_inline(__VA_ARGS__)
static inline int64_t
text_tools_TextFind_ziran_inline(String text, String needle, int64_t from)
{
if (from < 0LL) {
return -1LL;
}
int64_t last = (int64_t)((uint64_t)((int64_t)(text).length) - (uint64_t)((int64_t)(needle).length));
int64_t at = from;
while (at <= last) {
int64_t index = 0LL;
while (index < (int64_t)(needle).length && (uint8_t)ZIRAN_INDEX(text.data, text.length, ((int64_t)((uint64_t)at + (uint64_t)index))) == (uint8_t)ZIRAN_INDEX(needle.data, needle.length, index)) {
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
if (index == (int64_t)(needle).length) {
return at;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
return -1LL;
}
static inline int64_t
text_tools_TextFindLast_ziran_inline(String text, String needle)
{
int64_t at = (int64_t)((uint64_t)((int64_t)(text).length) - (uint64_t)((int64_t)(needle).length));
while (at >= 0LL) {
int64_t index = 0LL;
while (index < (int64_t)(needle).length && (uint8_t)ZIRAN_INDEX(text.data, text.length, ((int64_t)((uint64_t)at + (uint64_t)index))) == (uint8_t)ZIRAN_INDEX(needle.data, needle.length, index)) {
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
if (index == (int64_t)(needle).length) {
return at;
}
at = (int64_t)((uint64_t)at - UINT64_C(1));
}
return -1LL;
}
static inline bool
text_tools_TextContains_ziran_inline(String text, String needle)
{
int64_t value_0 = text_tools_TextFind(text, needle, 0LL);
return value_0 >= 0LL;
}
static inline bool
text_tools_TextIsSpace_ziran_inline(uint8_t byte)
{
return byte == 32 || (byte >= 9 && byte <= 13);
}
static inline bool
text_tools_TextIsDecimal_ziran_inline(String text)
{
if ((int64_t)(text).length == 0LL) {
return false;
}
for (int64_t it_index = 0LL; it_index < (int64_t)(text).length; it_index++) {
uint8_t it = (uint8_t)text.data[it_index];
if (it < 48 || it > 57) {
return false;
}
}
return true;
}
static inline bool
text_tools_TextIsLowerHex_ziran_inline(String text)
{
if ((int64_t)(text).length == 0LL) {
return false;
}
for (int64_t it_index = 0LL; it_index < (int64_t)(text).length; it_index++) {
uint8_t it = (uint8_t)text.data[it_index];
if (!((it >= 48 && it <= 57) || (it >= 97 && it <= 102))) {
return false;
}
}
return true;
}
static inline int32_t
text_tools_TextHexDigit_ziran_inline(uint8_t byte)
{
if (byte >= 48 && byte <= 57) {
return (int32_t)(((uint8_t)((uint32_t)byte - 48u)));
}
if (byte >= 97 && byte <= 102) {
return (int32_t)((uint32_t)(((uint8_t)((uint32_t)byte - 97u))) + 10u);
}
if (byte >= 65 && byte <= 70) {
return (int32_t)((uint32_t)(((uint8_t)((uint32_t)byte - 65u))) + 10u);
}
return -1;
}
#endif
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_TEXT_TOOLS_H */
@@ -0,0 +1,105 @@
/* Generated by zi2c from timer_linux.zi. */
#define ZIRAN_TIMER_LINUX_H_SOURCE 1
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "timer_linux.h"
int32_t
timer_linux_ClockSleepRaw(int32_t clock, int32_t flags, zir_9339a8296a493286_ClockValue* request, zir_9339a8296a493286_ClockValue* remaining)
{
(void)clock;
(void)flags;
if (zir_f_9bb5b5b3425765c7_SleepRaw(request, remaining) == 0) {
return 0;
}
int32_t* value_0 = zir_f_9bb5b5b3425765c7_ErrnoRaw();
return *(value_0);
}
int64_t
MonotonicNanoseconds(void)
{
zir_9339a8296a493286_ClockValue value = {0};
if (zir_f_9bb5b5b3425765c7_ClockGetTimeRaw(6, &(value)) != 0) {
return -1LL;
}
int64_t seconds = (int64_t)(value.seconds);
int64_t nanoseconds = (int64_t)(value.nanoseconds);
if (seconds < 0LL || nanoseconds < 0LL || nanoseconds > 999999999LL || seconds > 9223372036LL || (seconds == 9223372036LL && nanoseconds > 854775807LL)) {
return -1LL;
}
return (int64_t)(((uint64_t)seconds * UINT64_C(1000000000)) + (uint64_t)nanoseconds);
}
int64_t
MonotonicMilliseconds(void)
{
zir_9339a8296a493286_ClockValue value[1] = {0};
if (zir_f_9bb5b5b3425765c7_ClockGetTimeRaw(6, &(value[0])) != 0) {
return -1LL;
}
int64_t seconds = (int64_t)((value[0]).seconds);
int64_t nanoseconds = (int64_t)((value[0]).nanoseconds);
if (nanoseconds < 0LL || nanoseconds > 999999999LL) {
return -1LL;
}
if (seconds > 9223372036854775LL || seconds < 0LL) {
return -1LL;
}
return (int64_t)(((uint64_t)seconds * UINT64_C(1000)) + (uint64_t)((nanoseconds / 1000000LL)));
}
zir_9339a8296a493286_ClockValue
timer_linux_MakeClockValue(int64_t milliseconds)
{
zir_9339a8296a493286_ClockValue value = {0};
if (milliseconds < 0LL) {
return value;
}
ptrdiff_t* value_0 = &(value.seconds);
(*value_0) = (ptrdiff_t)((milliseconds / 1000LL));
ptrdiff_t* value_1 = &(value.nanoseconds);
(*value_1) = (ptrdiff_t)(((int64_t)((uint64_t)((milliseconds % 1000LL)) * UINT64_C(1000000))));
return value;
}
bool
SleepMilliseconds(int64_t milliseconds)
{
if (milliseconds < 0LL || milliseconds > 86400000LL) {
return false;
}
zir_9339a8296a493286_ClockValue request[1] = {0};
zir_9339a8296a493286_ClockValue remaining[1] = {0};
zir_9339a8296a493286_ClockValue* value_0 = &(request[0]);
int64_t value_1 = milliseconds;
zir_9339a8296a493286_ClockValue value_2 = {0};
{
int64_t milliseconds = value_1;
zir_9339a8296a493286_ClockValue value = {0};
if (milliseconds < 0LL) {
value_2 = value;
goto value_3;
}
ptrdiff_t* value_4 = &(value.seconds);
(*value_4) = (ptrdiff_t)((milliseconds / 1000LL));
ptrdiff_t* value_5 = &(value.nanoseconds);
(*value_5) = (ptrdiff_t)(((int64_t)((uint64_t)((milliseconds % 1000LL)) * UINT64_C(1000000))));
value_2 = value;
value_3: ;
}
(*value_0) = value_2;
while ((request[0]).seconds > 0 || (request[0]).nanoseconds > 0) {
int32_t status = timer_linux_ClockSleepRaw(6, 0, &(request[0]), &(remaining[0]));
if (status == 0) {
return true;
}
if (status != 4) {
return false;
}
zir_9339a8296a493286_ClockValue* value_6 = &(request[0]);
(*value_6) = (remaining)[0];
}
return true;
}
@@ -0,0 +1,90 @@
/* Generated by zi2c from timer_linux.zi. */
#ifndef ZIRAN_TIMER_LINUX_H
#define ZIRAN_TIMER_LINUX_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MONOTONIC_CLOCK 6
typedef struct zir_9339a8296a493286_ClockValue zir_9339a8296a493286_ClockValue;
struct zir_9339a8296a493286_ClockValue {
ptrdiff_t seconds;
ptrdiff_t nanoseconds;
};
#ifndef ZIR_FOREIGN_zir_f_9bb5b5b3425765c7_ClockGetTimeRaw_a884510c
#define ZIR_FOREIGN_zir_f_9bb5b5b3425765c7_ClockGetTimeRaw_a884510c
#ifdef __APPLE__
int32_t zir_foreign_zir_f_9bb5b5b3425765c7_ClockGetTimeRaw(int32_t clock, zir_9339a8296a493286_ClockValue* value) __asm__("_clock_gettime");
#else
int32_t zir_foreign_zir_f_9bb5b5b3425765c7_ClockGetTimeRaw(int32_t clock, zir_9339a8296a493286_ClockValue* value) __asm__("clock_gettime");
#endif
static int32_t
zir_f_9bb5b5b3425765c7_ClockGetTimeRaw(int32_t clock, zir_9339a8296a493286_ClockValue* value)
{
return zir_foreign_zir_f_9bb5b5b3425765c7_ClockGetTimeRaw(clock, value);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_9bb5b5b3425765c7_SleepRaw_e809afdd
#define ZIR_FOREIGN_zir_f_9bb5b5b3425765c7_SleepRaw_e809afdd
#ifdef __APPLE__
int32_t zir_foreign_zir_f_9bb5b5b3425765c7_SleepRaw(zir_9339a8296a493286_ClockValue* request, zir_9339a8296a493286_ClockValue* remaining) __asm__("_nanosleep");
#else
int32_t zir_foreign_zir_f_9bb5b5b3425765c7_SleepRaw(zir_9339a8296a493286_ClockValue* request, zir_9339a8296a493286_ClockValue* remaining) __asm__("nanosleep");
#endif
static int32_t
zir_f_9bb5b5b3425765c7_SleepRaw(zir_9339a8296a493286_ClockValue* request, zir_9339a8296a493286_ClockValue* remaining)
{
return zir_foreign_zir_f_9bb5b5b3425765c7_SleepRaw(request, remaining);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_9bb5b5b3425765c7_ErrnoRaw_a87bf2d8
#define ZIR_FOREIGN_zir_f_9bb5b5b3425765c7_ErrnoRaw_a87bf2d8
#ifdef __APPLE__
int32_t* zir_foreign_zir_f_9bb5b5b3425765c7_ErrnoRaw(void) __asm__("___error");
#else
int32_t* zir_foreign_zir_f_9bb5b5b3425765c7_ErrnoRaw(void) __asm__("__error");
#endif
static int32_t*
zir_f_9bb5b5b3425765c7_ErrnoRaw(void)
{
return zir_foreign_zir_f_9bb5b5b3425765c7_ErrnoRaw();
}
#endif
int32_t timer_linux_ClockSleepRaw(int32_t clock, int32_t flags, zir_9339a8296a493286_ClockValue* request, zir_9339a8296a493286_ClockValue* remaining);
int64_t MonotonicNanoseconds(void);
int64_t MonotonicMilliseconds(void);
zir_9339a8296a493286_ClockValue timer_linux_MakeClockValue(int64_t milliseconds);
bool SleepMilliseconds(int64_t milliseconds);
/* Small procedures other modules inline; timer_linux.c defines them. */
#if !defined(__cplusplus) && !defined(ZIRAN_TIMER_LINUX_H_SOURCE) && !defined(ZIRAN_NO_HEADER_INLINE)
#include <stdint.h>
#include <stddef.h>
static inline zir_9339a8296a493286_ClockValue timer_linux_MakeClockValue_ziran_inline(int64_t milliseconds);
#define timer_linux_MakeClockValue(...) timer_linux_MakeClockValue_ziran_inline(__VA_ARGS__)
static inline zir_9339a8296a493286_ClockValue
timer_linux_MakeClockValue_ziran_inline(int64_t milliseconds)
{
zir_9339a8296a493286_ClockValue value = {0};
if (milliseconds < 0LL) {
return value;
}
ptrdiff_t* value_0 = &(value.seconds);
(*value_0) = (ptrdiff_t)((milliseconds / 1000LL));
ptrdiff_t* value_1 = &(value.nanoseconds);
(*value_1) = (ptrdiff_t)(((int64_t)((uint64_t)((milliseconds % 1000LL)) * UINT64_C(1000000))));
return value;
}
#endif
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_TIMER_LINUX_H */
@@ -0,0 +1,27 @@
/* Generated by zi2c from c_string.zi. */
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_bounds.h"
#include "c_string.h"
bool
CopyCString(String value, Slice output)
{
int32_t length = (int32_t)((int64_t)(value).length);
if (length >= (int32_t)((int64_t)(output).length)) {
return false;
}
int32_t index = 0;
while (index < length) {
uint8_t byte = (uint8_t)ZIRAN_INDEX(value.data, value.length, index);
if (byte == 0) {
return false;
}
uint8_t* value_0 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)index)]);
(*value_0) = byte;
index = (int32_t)((uint32_t)index + 1u);
}
uint8_t* value_1 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)length)]);
(*value_1) = 0;
return true;
}
@@ -0,0 +1,18 @@
/* Generated by zi2c from c_string.zi. */
#ifndef ZIRAN_C_STRING_H
#define ZIRAN_C_STRING_H
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_slice.h"
#ifdef __cplusplus
extern "C" {
#endif
bool CopyCString(String value, Slice output);
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_C_STRING_H */
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,166 @@
/* Generated by zi2c from compiler_runtime_emit.zi. */
#ifndef ZIRAN_COMPILER_RUNTIME_EMIT_H
#define ZIRAN_COMPILER_RUNTIME_EMIT_H
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_slice.h"
#include "file.h"
#include "vec.h"
#ifdef __cplusplus
extern "C" {
#endif
#define IncludePrefix "#include \""
#ifdef ZIRAN_COMPILER_RUNTIME_EMIT_H_PRIVATE
#define SimdOpsName "ziran_simd_ops.h"
#endif
typedef struct RuntimeHeader RuntimeHeader;
typedef struct SimdNames SimdNames;
typedef struct ZirSimdUses ZirSimdUses;
#ifndef ZIRAN_CONCRETE_FORWARD___type_c53c2d7c4913dc02
#define ZIRAN_CONCRETE_FORWARD___type_c53c2d7c4913dc02
typedef struct __type_c53c2d7c4913dc02 __type_c53c2d7c4913dc02;
#endif
typedef struct GeneratedPathStore GeneratedPathStore;
#ifdef ZIRAN_COMPILER_RUNTIME_EMIT_H_PRIVATE
typedef struct TextDescriptor TextDescriptor;
#endif
#ifdef ZIRAN_COMPILER_RUNTIME_EMIT_H_PRIVATE
typedef struct ByteDescriptor ByteDescriptor;
#endif
#ifdef ZIRAN_COMPILER_RUNTIME_EMIT_H_PRIVATE
typedef struct Segment Segment;
#endif
typedef struct zir_8e7ef9a1e6f28a8e_Results__string__bool zir_8e7ef9a1e6f28a8e_Results__string__bool;
#ifndef ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
#define ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
typedef struct __type_838711075b90279a __type_838711075b90279a;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_9626e91dad9499a3
#define ZIRAN_CONCRETE_FORWARD___type_9626e91dad9499a3
typedef struct __type_9626e91dad9499a3 __type_9626e91dad9499a3;
#endif
#ifdef ZIRAN_COMPILER_RUNTIME_EMIT_H_PRIVATE
#ifndef ZIRAN_CONCRETE_FORWARD___type_2f893a38d978b828
#define ZIRAN_CONCRETE_FORWARD___type_2f893a38d978b828
typedef struct __type_2f893a38d978b828 __type_2f893a38d978b828;
#endif
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_1f00ef809eed7c2e
#define ZIRAN_CONCRETE_FORWARD___type_1f00ef809eed7c2e
typedef struct __type_1f00ef809eed7c2e __type_1f00ef809eed7c2e;
#endif
struct RuntimeHeader {
const char * name;
const char * text;
uint32_t includes;
};
struct SimdNames {
const char ** text;
size_t* length;
size_t count;
size_t capacity;
size_t* slots;
size_t slot_count;
};
struct ZirSimdUses {
SimdNames names;
int32_t header;
};
#ifndef ZIRAN_CONCRETE___type_c53c2d7c4913dc02
#define ZIRAN_CONCRETE___type_c53c2d7c4913dc02
struct __type_c53c2d7c4913dc02 {
String* data;
int64_t count;
int64_t capacity;
};
#endif
struct GeneratedPathStore {
__type_c53c2d7c4913dc02 paths;
};
#ifdef ZIRAN_COMPILER_RUNTIME_EMIT_H_PRIVATE
struct TextDescriptor {
uint8_t* data;
size_t length;
};
#endif
#ifdef ZIRAN_COMPILER_RUNTIME_EMIT_H_PRIVATE
struct ByteDescriptor {
uint8_t* data;
int64_t length;
};
#endif
#ifdef ZIRAN_COMPILER_RUNTIME_EMIT_H_PRIVATE
struct Segment {
int64_t helper;
int64_t start;
int64_t length;
int64_t next;
};
#endif
struct zir_8e7ef9a1e6f28a8e_Results__string__bool {
String value_0;
bool value_1;
};
#ifndef ZIRAN_CONCRETE___type_838711075b90279a
#define ZIRAN_CONCRETE___type_838711075b90279a
struct __type_838711075b90279a {
uint8_t* data;
int64_t count;
int64_t capacity;
};
#endif
#ifndef ZIRAN_CONCRETE___type_9626e91dad9499a3
#define ZIRAN_CONCRETE___type_9626e91dad9499a3
struct __type_9626e91dad9499a3 {
bool* data;
int64_t count;
int64_t capacity;
};
#endif
#ifdef ZIRAN_COMPILER_RUNTIME_EMIT_H_PRIVATE
#ifndef ZIRAN_CONCRETE___type_2f893a38d978b828
#define ZIRAN_CONCRETE___type_2f893a38d978b828
struct __type_2f893a38d978b828 {
Segment* data;
int64_t count;
int64_t capacity;
};
#endif
#endif
#ifndef ZIRAN_CONCRETE___type_1f00ef809eed7c2e
#define ZIRAN_CONCRETE___type_1f00ef809eed7c2e
struct __type_1f00ef809eed7c2e {
int64_t* data;
int64_t count;
int64_t capacity;
};
#endif
extern GeneratedPathStore GeneratedPaths;
bool compiler_runtime_emit_RecordPath(String path);
bool compiler_runtime_emit_RecordPathC(uint8_t* path);
int64_t compiler_runtime_emit_GeneratedPathCount(void);
uint8_t* compiler_runtime_emit_GeneratedPath(int64_t index);
bool compiler_runtime_emit_IsRuntimeHeader(String name);
bool compiler_runtime_emit_EmitRuntimeHeaders(String out_dir, String generated_path, ZirSimdUses* simd, SimdNames* used);
bool compiler_runtime_emit_EmitSimdOps(String out_dir, ZirSimdUses* uses);
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_COMPILER_RUNTIME_EMIT_H */
@@ -0,0 +1,381 @@
/* Generated by zi2c from file.zi. */
#define ZIRAN_FILE_H_SOURCE 1
#include <stdbool.h>
#include "zir_bounds.h"
#include "zir_string.h"
#include "zir_vec.h"
#include "file.h"
#include "result.h"
bool
file_FilePathText(String text)
{
int64_t at = 0LL;
while (at < (int64_t)(text).length) {
uint8_t first = (uint8_t)ZIRAN_INDEX(text.data, text.length, at);
if (first < 128) {
at = (int64_t)((uint64_t)at + UINT64_C(1));
continue;
}
int64_t count = 0LL;
uint32_t codepoint = 0;
uint32_t minimum = 0;
if (first >= 194 && first <= 223) {
count = 1LL;
codepoint = (uint32_t)(((uint8_t)((uint32_t)first & 31u)));
minimum = 128;
} else if (first >= 224 && first <= 239) {
count = 2LL;
codepoint = (uint32_t)(((uint8_t)((uint32_t)first & 15u)));
minimum = 2048;
} else if (first >= 240 && first <= 244) {
count = 3LL;
codepoint = (uint32_t)(((uint8_t)((uint32_t)first & 7u)));
minimum = 65536;
} else {
return false;
}
if ((int64_t)((uint64_t)at + (uint64_t)count) >= (int64_t)(text).length) {
return false;
}
int64_t index = 1LL;
while (index <= count) {
uint8_t part = (uint8_t)ZIRAN_INDEX(text.data, text.length, ((int64_t)((uint64_t)at + (uint64_t)index)));
if (part < 128 || part > 191) {
return false;
}
codepoint = (uint32_t)(((uint32_t)codepoint << 6) | (uint32_t)(((uint8_t)((uint32_t)part & 63u))));
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
if (codepoint < minimum || codepoint > 1114111 || (codepoint >= 55296 && codepoint <= 57343)) {
return false;
}
at = (int64_t)((uint64_t)at + ((uint64_t)count + UINT64_C(1)));
}
return true;
}
__type_d6f9b1b7c4ee2d51
ReadEntireFileCapped(String path, int64_t maximum)
{
__type_d6f9b1b7c4ee2d51 result = {0};
if (maximum < 0LL) {
FileReadFailure* value_0 = &(result.error);
(*value_0) = FileReadFailure_InvalidLimit;
return result;
}
bool value_1 = (int64_t)(path).length == 0LL || (int64_t)(path).length >= 4096LL;
if (!value_1) {
bool value_2 = file_FilePathText(path);
value_1 = !value_2;
}
bool invalid_path = value_1;
for (int64_t it_index = 0LL; it_index < (int64_t)(path).length; it_index++) {
uint8_t byte = (uint8_t)path.data[it_index];
if (byte == 0) {
invalid_path = true;
}
}
if (invalid_path) {
FileReadFailure* value_3 = &(result.error);
(*value_3) = FileReadFailure_InvalidPath;
return result;
}
FileHandle file = OpenRead(path);
if (!file.valid) {
FileReadFailure* value_4 = &(result.error);
bool value_5 = PathExists(path);
FileReadFailure value_6 = (FileReadFailure)(0);
if (value_5) {
value_6 = FileReadFailure_ReadError;
} else {
value_6 = FileReadFailure_NotFound;
}
(*value_4) = value_6;
return result;
}
__type_838711075b90279a bytes = {0};
__type_838711075b90279a* value_7 = &bytes;
uint8_t chunk[4096] = {0};
int64_t offset = 0LL;
while (true) {
int64_t allowed = (int64_t)((uint64_t)maximum - (uint64_t)offset);
Slice value_8 = {chunk, 4096};
int64_t value_9 = 0;
if (allowed < 4096LL) {
value_9 = (int64_t)((uint64_t)allowed + UINT64_C(1));
} else {
value_9 = 4096LL;
}
int64_t count = ReadAt(file, SliceRange(value_8, (int64_t)0LL, (int64_t)value_9, sizeof(uint8_t)), offset);
if (count < 0LL) {
CloseFile(file);
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
FileReadFailure* value_10 = &(result.error);
(*value_10) = FileReadFailure_ReadError;
__type_d6f9b1b7c4ee2d51 value_11 = result;
free((*value_7).data);
(*value_7).data = NULL;
(*value_7).capacity = 0;
(*value_7).count = 0;
return value_11;
}
if (count == 0LL) {
break;
}
if (count > allowed) {
CloseFile(file);
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
FileReadFailure* value_12 = &(result.error);
(*value_12) = FileReadFailure_TooLarge;
__type_d6f9b1b7c4ee2d51 value_13 = result;
free((*value_7).data);
(*value_7).data = NULL;
(*value_7).capacity = 0;
(*value_7).count = 0;
return value_13;
}
int64_t i = 0LL;
while (i < count) {
uint8_t value_14 = ZIRAN_INDEX(chunk, 4096, i);
bool value_15 = false;
void *value_16 = ZirVecGrow((void *)(bytes).data, &(bytes).capacity, (bytes).count, sizeof(*(bytes).data));
if (value_16 != NULL) {
(bytes).data = (uint8_t *)value_16;
(bytes).data[(bytes).count++] = value_14;
value_15 = true;
}
(void)value_15;
i = (int64_t)((uint64_t)i + UINT64_C(1));
}
offset = (int64_t)((uint64_t)offset + (uint64_t)count);
}
bool value_17 = CloseFile(file);
if (!value_17) {
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
FileReadFailure* value_18 = &(result.error);
(*value_18) = FileReadFailure_ReadError;
__type_d6f9b1b7c4ee2d51 value_19 = result;
free((*value_7).data);
(*value_7).data = NULL;
(*value_7).capacity = 0;
(*value_7).count = 0;
return value_19;
}
bool* value_20 = &(result.is_ok);
(*value_20) = true;
String* value_21 = &(result.value);
String value_22 = {NULL, 0};
value_22.data = (bytes).count > 0 ? (const char *)(bytes).data : "";
value_22.length = (size_t)(bytes).count;
if ((bytes).count == 0) free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
(*value_21) = value_22;
__type_d6f9b1b7c4ee2d51 value_23 = result;
free((*value_7).data);
(*value_7).data = NULL;
(*value_7).capacity = 0;
(*value_7).count = 0;
return value_23;
}
__type_86107481102e856b
ReadFileIntoCapped(String path, int64_t maximum, __type_838711075b90279a* bytes)
{
__type_86107481102e856b result = {0};
if (bytes == ((void *)0)) {
FileReadFailure* value_0 = &(result.error);
(*value_0) = FileReadFailure_ReadError;
return result;
}
__type_d6f9b1b7c4ee2d51 read = ReadEntireFileCapped(path, maximum);
if (!read.is_ok) {
FileReadFailure* value_1 = &(result.error);
(*value_1) = (FileReadFailure)(read.error);
return result;
}
int64_t start = (*(bytes)).count;
{
String value_2 = read.value;
String loop_view_11 = StringRange(value_2, (int64_t)0, (int64_t)value_2.length);
int64_t loop_count_11 = (int64_t)(loop_view_11).length;
int64_t loop_cursor_11 = 0LL;
while (loop_cursor_11 < loop_count_11) {
int64_t loop_index_11 = loop_cursor_11;
uint8_t byte = (uint8_t)loop_view_11.data[loop_index_11];
uint8_t value_3 = byte;
bool value_4 = false;
void *value_5 = ZirVecGrow((void *)((*(bytes))).data, &((*(bytes))).capacity, ((*(bytes))).count, sizeof(*((*(bytes))).data));
if (value_5 != NULL) {
((*(bytes))).data = (uint8_t *)value_5;
((*(bytes))).data[((*(bytes))).count++] = value_3;
value_4 = true;
}
if (!value_4) {
int64_t value_7 = start;
bool value_8 = false;
if (value_7 >= 0) {
value_8 = value_7 <= ((*(bytes))).capacity;
if (!value_8) {
void *value_9 = ZirVecReserve((void *)((*(bytes))).data, &((*(bytes))).capacity, ((*(bytes))).count, value_7 - ((*(bytes))).count, sizeof(*((*(bytes))).data));
if (value_9 != NULL) { ((*(bytes))).data = (uint8_t *)value_9; value_8 = true; }
}
if (value_8) {
if (value_7 > ((*(bytes))).count) memset(((*(bytes))).data + ((*(bytes))).count, 0, (size_t)(value_7 - ((*(bytes))).count) * sizeof(*((*(bytes))).data));
((*(bytes))).count = value_7;
}
}
(void)value_8;
FileReadFailure* value_11 = &(result.error);
(*value_11) = FileReadFailure_ReadError;
return result;
}
loop_cursor_11 = (int64_t)((uint64_t)loop_cursor_11 + UINT64_C(1));
}
}
bool* value_12 = &(result.is_ok);
(*value_12) = true;
int64_t* value_13 = &(result.value);
(*value_13) = (int64_t)(read.value).length;
return result;
}
zir_970088bc989040e5_Results__string__bool
file_ReadEntireFile(String path)
{
FileHandle file = OpenRead(path);
if (!file.valid) {
return (zir_970088bc989040e5_Results__string__bool){.value_0 = StringLiteral(""), .value_1 = false};
}
__type_838711075b90279a bytes = {0};
__type_838711075b90279a* value_2 = &bytes;
uint8_t chunk[4096] = {0};
int64_t offset = 0LL;
while (true) {
Slice value_3 = {chunk, 4096};
int64_t count = ReadAt(file, value_3, offset);
if (count < 0LL) {
CloseFile(file);
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
zir_970088bc989040e5_Results__string__bool value_4 = (zir_970088bc989040e5_Results__string__bool){.value_0 = StringLiteral(""), .value_1 = false};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_4;
}
if (count == 0LL) {
break;
}
int64_t i = 0LL;
while (i < count) {
uint8_t value_5 = ZIRAN_INDEX(chunk, 4096, i);
bool value_6 = false;
void *value_7 = ZirVecGrow((void *)(bytes).data, &(bytes).capacity, (bytes).count, sizeof(*(bytes).data));
if (value_7 != NULL) {
(bytes).data = (uint8_t *)value_7;
(bytes).data[(bytes).count++] = value_5;
value_6 = true;
}
(void)value_6;
i = (int64_t)((uint64_t)i + UINT64_C(1));
}
offset = (int64_t)((uint64_t)offset + (uint64_t)count);
}
CloseFile(file);
zir_970088bc989040e5_Results__string__bool value_8 = {0};
String value_9 = {NULL, 0};
value_9.data = (bytes).count > 0 ? (const char *)(bytes).data : "";
value_9.length = (size_t)(bytes).count;
if ((bytes).count == 0) free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
value_8.value_0 = value_9;
value_8.value_1 = true;
zir_970088bc989040e5_Results__string__bool value_10 = value_8;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_10;
}
bool
file_ReadFileInto(String path, __type_838711075b90279a* bytes)
{
FileHandle file = OpenRead(path);
if (!file.valid) {
return false;
}
uint8_t chunk[4096] = {0};
int64_t offset = 0LL;
while (true) {
Slice value_0 = {chunk, 4096};
int64_t count = ReadAt(file, value_0, offset);
if (count < 0LL) {
CloseFile(file);
return false;
}
if (count == 0LL) {
break;
}
int64_t i = 0LL;
while (i < count) {
uint8_t value_1 = ZIRAN_INDEX(chunk, 4096, i);
bool value_2 = false;
void *value_3 = ZirVecGrow((void *)((*(bytes))).data, &((*(bytes))).capacity, ((*(bytes))).count, sizeof(*((*(bytes))).data));
if (value_3 != NULL) {
((*(bytes))).data = (uint8_t *)value_3;
((*(bytes))).data[((*(bytes))).count++] = value_1;
value_2 = true;
}
(void)value_2;
i = (int64_t)((uint64_t)i + UINT64_C(1));
}
offset = (int64_t)((uint64_t)offset + (uint64_t)count);
}
CloseFile(file);
return true;
}
bool
file_WriteEntireFile(String path, String text)
{
FileHandle file = OpenReplace(path);
if (!file.valid) {
return false;
}
uint8_t chunk[4096] = {0};
int64_t offset = 0LL;
while (offset < (int64_t)(text).length) {
int64_t count = 0LL;
while (count < 4096LL && (int64_t)((uint64_t)offset + (uint64_t)count) < (int64_t)(text).length) {
uint8_t* value_0 = &(chunk[count]);
(*value_0) = (uint8_t)ZIRAN_INDEX(text.data, text.length, ((int64_t)((uint64_t)offset + (uint64_t)count)));
count = (int64_t)((uint64_t)count + UINT64_C(1));
}
Slice value_1 = {chunk, 4096};
int64_t value_2 = WriteAt(file, SliceRange(value_1, (int64_t)0LL, (int64_t)count, sizeof(uint8_t)), offset);
if (value_2 != count) {
CloseFile(file);
return false;
}
offset = (int64_t)((uint64_t)offset + (uint64_t)count);
}
return CloseFile(file);
}
@@ -0,0 +1,140 @@
/* Generated by zi2c from file.zi. */
#ifndef ZIRAN_FILE_H
#define ZIRAN_FILE_H
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_bounds.h"
#include "zir_slice.h"
#include "file_linux.h"
#include "vec.h"
#include "result.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef int64_t FileReadFailure;
typedef struct zir_970088bc989040e5_Results__string__bool zir_970088bc989040e5_Results__string__bool;
#ifndef ZIRAN_CONCRETE_FORWARD___type_d6f9b1b7c4ee2d51
#define ZIRAN_CONCRETE_FORWARD___type_d6f9b1b7c4ee2d51
typedef struct __type_d6f9b1b7c4ee2d51 __type_d6f9b1b7c4ee2d51;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
#define ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
typedef struct __type_838711075b90279a __type_838711075b90279a;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_86107481102e856b
#define ZIRAN_CONCRETE_FORWARD___type_86107481102e856b
typedef struct __type_86107481102e856b __type_86107481102e856b;
#endif
enum {
FileReadFailure_None = 0,
FileReadFailure_InvalidLimit = 1,
FileReadFailure_InvalidPath = 2,
FileReadFailure_NotFound = 3,
FileReadFailure_TooLarge = 4,
FileReadFailure_ReadError = 5,
};
struct zir_970088bc989040e5_Results__string__bool {
String value_0;
bool value_1;
};
#ifndef ZIRAN_CONCRETE___type_d6f9b1b7c4ee2d51
#define ZIRAN_CONCRETE___type_d6f9b1b7c4ee2d51
struct __type_d6f9b1b7c4ee2d51 {
bool is_ok;
String value;
FileReadFailure error;
};
#endif
#ifndef ZIRAN_CONCRETE___type_838711075b90279a
#define ZIRAN_CONCRETE___type_838711075b90279a
struct __type_838711075b90279a {
uint8_t* data;
int64_t count;
int64_t capacity;
};
#endif
#ifndef ZIRAN_CONCRETE___type_86107481102e856b
#define ZIRAN_CONCRETE___type_86107481102e856b
struct __type_86107481102e856b {
bool is_ok;
int64_t value;
FileReadFailure error;
};
#endif
bool file_FilePathText(String text);
__type_d6f9b1b7c4ee2d51 ReadEntireFileCapped(String path, int64_t maximum);
__type_86107481102e856b ReadFileIntoCapped(String path, int64_t maximum, __type_838711075b90279a* bytes);
zir_970088bc989040e5_Results__string__bool file_ReadEntireFile(String path);
bool file_ReadFileInto(String path, __type_838711075b90279a* bytes);
bool file_WriteEntireFile(String path, String text);
/* Small procedures other modules inline; file.c defines them. */
#if !defined(__cplusplus) && !defined(ZIRAN_FILE_H_SOURCE) && !defined(ZIRAN_NO_HEADER_INLINE)
#include "zir_vec.h"
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_bounds.h"
static inline bool file_FilePathText_ziran_inline(String text);
#define file_FilePathText(...) file_FilePathText_ziran_inline(__VA_ARGS__)
static inline bool
file_FilePathText_ziran_inline(String text)
{
int64_t at = 0LL;
while (at < (int64_t)(text).length) {
uint8_t first = (uint8_t)ZIRAN_INDEX(text.data, text.length, at);
if (first < 128) {
at = (int64_t)((uint64_t)at + UINT64_C(1));
continue;
}
int64_t count = 0LL;
uint32_t codepoint = 0;
uint32_t minimum = 0;
if (first >= 194 && first <= 223) {
count = 1LL;
codepoint = (uint32_t)(((uint8_t)((uint32_t)first & 31u)));
minimum = 128;
} else if (first >= 224 && first <= 239) {
count = 2LL;
codepoint = (uint32_t)(((uint8_t)((uint32_t)first & 15u)));
minimum = 2048;
} else if (first >= 240 && first <= 244) {
count = 3LL;
codepoint = (uint32_t)(((uint8_t)((uint32_t)first & 7u)));
minimum = 65536;
} else {
return false;
}
if ((int64_t)((uint64_t)at + (uint64_t)count) >= (int64_t)(text).length) {
return false;
}
int64_t index = 1LL;
while (index <= count) {
uint8_t part = (uint8_t)ZIRAN_INDEX(text.data, text.length, ((int64_t)((uint64_t)at + (uint64_t)index)));
if (part < 128 || part > 191) {
return false;
}
codepoint = (uint32_t)(((uint32_t)codepoint << 6) | (uint32_t)(((uint8_t)((uint32_t)part & 63u))));
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
if (codepoint < minimum || codepoint > 1114111 || (codepoint >= 55296 && codepoint <= 57343)) {
return false;
}
at = (int64_t)((uint64_t)at + ((uint64_t)count + UINT64_C(1)));
}
return true;
}
#endif
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_FILE_H */
@@ -0,0 +1,801 @@
/* Generated by zi2c from file_linux.zi. */
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_bounds.h"
#define ZIRAN_FILE_LINUX_H_PRIVATE 1
#include "file_linux.h"
#undef ZIRAN_FILE_LINUX_H_PRIVATE
#include "c_string.h"
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_ReadLinkRaw_133b334a
#define ZIR_FOREIGN_zir_f_76512f487eef232a_ReadLinkRaw_133b334a
#ifdef __APPLE__
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_ReadLinkRaw(uint8_t* path, uint8_t* output, size_t capacity) __asm__("_readlink");
#else
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_ReadLinkRaw(uint8_t* path, uint8_t* output, size_t capacity) __asm__("readlink");
#endif
static ptrdiff_t
zir_f_76512f487eef232a_ReadLinkRaw(uint8_t* path, uint8_t* output, size_t capacity)
{
return zir_foreign_zir_f_76512f487eef232a_ReadLinkRaw(path, output, capacity);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_OpenRaw_e4db28c4
#define ZIR_FOREIGN_zir_f_76512f487eef232a_OpenRaw_e4db28c4
#ifdef __APPLE__
int32_t zir_foreign_zir_f_76512f487eef232a_OpenRaw(uint8_t* path, int32_t flags, ...) __asm__("_open");
#else
int32_t zir_foreign_zir_f_76512f487eef232a_OpenRaw(uint8_t* path, int32_t flags, ...) __asm__("open");
#endif
#define zir_f_76512f487eef232a_OpenRaw zir_foreign_zir_f_76512f487eef232a_OpenRaw
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_CloseRaw_d6ec0c1e
#define ZIR_FOREIGN_zir_f_76512f487eef232a_CloseRaw_d6ec0c1e
#ifdef __APPLE__
int32_t zir_foreign_zir_f_76512f487eef232a_CloseRaw(int32_t fd) __asm__("_close");
#else
int32_t zir_foreign_zir_f_76512f487eef232a_CloseRaw(int32_t fd) __asm__("close");
#endif
static int32_t
zir_f_76512f487eef232a_CloseRaw(int32_t fd)
{
return zir_foreign_zir_f_76512f487eef232a_CloseRaw(fd);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_ReadRaw_bf7cf6fc
#define ZIR_FOREIGN_zir_f_76512f487eef232a_ReadRaw_bf7cf6fc
#ifdef __APPLE__
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_ReadRaw(int32_t fd, uint8_t* output, size_t count) __asm__("_read");
#else
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_ReadRaw(int32_t fd, uint8_t* output, size_t count) __asm__("read");
#endif
static ptrdiff_t
zir_f_76512f487eef232a_ReadRaw(int32_t fd, uint8_t* output, size_t count)
{
return zir_foreign_zir_f_76512f487eef232a_ReadRaw(fd, output, count);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_WriteRaw_06f26813
#define ZIR_FOREIGN_zir_f_76512f487eef232a_WriteRaw_06f26813
#ifdef __APPLE__
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_WriteRaw(int32_t fd, uint8_t* input, size_t count) __asm__("_write");
#else
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_WriteRaw(int32_t fd, uint8_t* input, size_t count) __asm__("write");
#endif
static ptrdiff_t
zir_f_76512f487eef232a_WriteRaw(int32_t fd, uint8_t* input, size_t count)
{
return zir_foreign_zir_f_76512f487eef232a_WriteRaw(fd, input, count);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_DarwinLibrary_f67cc6a7
#define ZIR_FOREIGN_zir_f_76512f487eef232a_DarwinLibrary_f67cc6a7
#ifdef __APPLE__
void* zir_foreign_zir_f_76512f487eef232a_DarwinLibrary(uint8_t* path, int32_t flags) __asm__("_dlopen");
#else
void* zir_foreign_zir_f_76512f487eef232a_DarwinLibrary(uint8_t* path, int32_t flags) __asm__("dlopen");
#endif
static void*
zir_f_76512f487eef232a_DarwinLibrary(uint8_t* path, int32_t flags)
{
return zir_foreign_zir_f_76512f487eef232a_DarwinLibrary(path, flags);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_DarwinSymbol_0fc766c9
#define ZIR_FOREIGN_zir_f_76512f487eef232a_DarwinSymbol_0fc766c9
#ifdef __APPLE__
void* zir_foreign_zir_f_76512f487eef232a_DarwinSymbol(void* library, uint8_t* name) __asm__("_dlsym");
#else
void* zir_foreign_zir_f_76512f487eef232a_DarwinSymbol(void* library, uint8_t* name) __asm__("dlsym");
#endif
static void*
zir_f_76512f487eef232a_DarwinSymbol(void* library, uint8_t* name)
{
return zir_foreign_zir_f_76512f487eef232a_DarwinSymbol(library, name);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_DarwinLibraryClose_96a6e553
#define ZIR_FOREIGN_zir_f_76512f487eef232a_DarwinLibraryClose_96a6e553
#ifdef __APPLE__
int32_t zir_foreign_zir_f_76512f487eef232a_DarwinLibraryClose(void* library) __asm__("_dlclose");
#else
int32_t zir_foreign_zir_f_76512f487eef232a_DarwinLibraryClose(void* library) __asm__("dlclose");
#endif
static int32_t
zir_f_76512f487eef232a_DarwinLibraryClose(void* library)
{
return zir_foreign_zir_f_76512f487eef232a_DarwinLibraryClose(library);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_DarwinAllocate_0c09ffff
#define ZIR_FOREIGN_zir_f_76512f487eef232a_DarwinAllocate_0c09ffff
#ifdef __APPLE__
void* zir_foreign_zir_f_76512f487eef232a_DarwinAllocate(size_t count, size_t size) __asm__("_calloc");
#else
void* zir_foreign_zir_f_76512f487eef232a_DarwinAllocate(size_t count, size_t size) __asm__("calloc");
#endif
static void*
zir_f_76512f487eef232a_DarwinAllocate(size_t count, size_t size)
{
return zir_foreign_zir_f_76512f487eef232a_DarwinAllocate(count, size);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_DarwinFree_c75930da
#define ZIR_FOREIGN_zir_f_76512f487eef232a_DarwinFree_c75930da
#ifdef __APPLE__
void zir_foreign_zir_f_76512f487eef232a_DarwinFree(void* value) __asm__("_free");
#else
void zir_foreign_zir_f_76512f487eef232a_DarwinFree(void* value) __asm__("free");
#endif
static void
zir_f_76512f487eef232a_DarwinFree(void* value)
{
zir_foreign_zir_f_76512f487eef232a_DarwinFree(value);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_DarwinCopy_d3838e83
#define ZIR_FOREIGN_zir_f_76512f487eef232a_DarwinCopy_d3838e83
#ifdef __APPLE__
void* zir_foreign_zir_f_76512f487eef232a_DarwinCopy(void* output, void* value, size_t count) __asm__("_memcpy");
#else
void* zir_foreign_zir_f_76512f487eef232a_DarwinCopy(void* output, void* value, size_t count) __asm__("memcpy");
#endif
static void*
zir_f_76512f487eef232a_DarwinCopy(void* output, void* value, size_t count)
{
return zir_foreign_zir_f_76512f487eef232a_DarwinCopy(output, value, count);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_DirectoryErrno_a87bf2d8
#define ZIR_FOREIGN_zir_f_76512f487eef232a_DirectoryErrno_a87bf2d8
#ifdef __APPLE__
int32_t* zir_foreign_zir_f_76512f487eef232a_DirectoryErrno(void) __asm__("___error");
#else
int32_t* zir_foreign_zir_f_76512f487eef232a_DirectoryErrno(void) __asm__("__error");
#endif
static int32_t*
zir_f_76512f487eef232a_DirectoryErrno(void)
{
return zir_foreign_zir_f_76512f487eef232a_DirectoryErrno();
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_SeekRaw_6ab0c034
#define ZIR_FOREIGN_zir_f_76512f487eef232a_SeekRaw_6ab0c034
#ifdef __APPLE__
int64_t zir_foreign_zir_f_76512f487eef232a_SeekRaw(int32_t fd, int64_t offset, int32_t origin) __asm__("_lseek");
#else
int64_t zir_foreign_zir_f_76512f487eef232a_SeekRaw(int32_t fd, int64_t offset, int32_t origin) __asm__("lseek");
#endif
static int64_t
zir_f_76512f487eef232a_SeekRaw(int32_t fd, int64_t offset, int32_t origin)
{
return zir_foreign_zir_f_76512f487eef232a_SeekRaw(fd, offset, origin);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_ReadAtRaw_c0d26f21
#define ZIR_FOREIGN_zir_f_76512f487eef232a_ReadAtRaw_c0d26f21
#ifdef __APPLE__
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_ReadAtRaw(int32_t fd, uint8_t* output, size_t count, int64_t offset) __asm__("_pread");
#else
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_ReadAtRaw(int32_t fd, uint8_t* output, size_t count, int64_t offset) __asm__("pread");
#endif
static ptrdiff_t
zir_f_76512f487eef232a_ReadAtRaw(int32_t fd, uint8_t* output, size_t count, int64_t offset)
{
return zir_foreign_zir_f_76512f487eef232a_ReadAtRaw(fd, output, count, offset);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_WriteAtRaw_b81fa0e4
#define ZIR_FOREIGN_zir_f_76512f487eef232a_WriteAtRaw_b81fa0e4
#ifdef __APPLE__
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_WriteAtRaw(int32_t fd, uint8_t* input, size_t count, int64_t offset) __asm__("_pwrite");
#else
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_WriteAtRaw(int32_t fd, uint8_t* input, size_t count, int64_t offset) __asm__("pwrite");
#endif
static ptrdiff_t
zir_f_76512f487eef232a_WriteAtRaw(int32_t fd, uint8_t* input, size_t count, int64_t offset)
{
return zir_foreign_zir_f_76512f487eef232a_WriteAtRaw(fd, input, count, offset);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_MakeDirectoryRaw_a57b07a1
#define ZIR_FOREIGN_zir_f_76512f487eef232a_MakeDirectoryRaw_a57b07a1
#ifdef __APPLE__
int32_t zir_foreign_zir_f_76512f487eef232a_MakeDirectoryRaw(uint8_t* path, int32_t mode) __asm__("_mkdir");
#else
int32_t zir_foreign_zir_f_76512f487eef232a_MakeDirectoryRaw(uint8_t* path, int32_t mode) __asm__("mkdir");
#endif
static int32_t
zir_f_76512f487eef232a_MakeDirectoryRaw(uint8_t* path, int32_t mode)
{
return zir_foreign_zir_f_76512f487eef232a_MakeDirectoryRaw(path, mode);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_UnlinkRaw_1f92ad9b
#define ZIR_FOREIGN_zir_f_76512f487eef232a_UnlinkRaw_1f92ad9b
#ifdef __APPLE__
int32_t zir_foreign_zir_f_76512f487eef232a_UnlinkRaw(uint8_t* path) __asm__("_unlink");
#else
int32_t zir_foreign_zir_f_76512f487eef232a_UnlinkRaw(uint8_t* path) __asm__("unlink");
#endif
static int32_t
zir_f_76512f487eef232a_UnlinkRaw(uint8_t* path)
{
return zir_foreign_zir_f_76512f487eef232a_UnlinkRaw(path);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_LinkRaw_7acc0972
#define ZIR_FOREIGN_zir_f_76512f487eef232a_LinkRaw_7acc0972
#ifdef __APPLE__
int32_t zir_foreign_zir_f_76512f487eef232a_LinkRaw(uint8_t* source, uint8_t* destination) __asm__("_link");
#else
int32_t zir_foreign_zir_f_76512f487eef232a_LinkRaw(uint8_t* source, uint8_t* destination) __asm__("link");
#endif
static int32_t
zir_f_76512f487eef232a_LinkRaw(uint8_t* source, uint8_t* destination)
{
return zir_foreign_zir_f_76512f487eef232a_LinkRaw(source, destination);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_RenameAtRaw_57868d39
#define ZIR_FOREIGN_zir_f_76512f487eef232a_RenameAtRaw_57868d39
#ifdef __APPLE__
int32_t zir_foreign_zir_f_76512f487eef232a_RenameAtRaw(int32_t old_directory, uint8_t* source, int32_t new_directory, uint8_t* destination) __asm__("_renameat");
#else
int32_t zir_foreign_zir_f_76512f487eef232a_RenameAtRaw(int32_t old_directory, uint8_t* source, int32_t new_directory, uint8_t* destination) __asm__("renameat");
#endif
static int32_t
zir_f_76512f487eef232a_RenameAtRaw(int32_t old_directory, uint8_t* source, int32_t new_directory, uint8_t* destination)
{
return zir_foreign_zir_f_76512f487eef232a_RenameAtRaw(old_directory, source,
new_directory, destination);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_RenameAt2Raw_fbf775a7
#define ZIR_FOREIGN_zir_f_76512f487eef232a_RenameAt2Raw_fbf775a7
#ifdef __APPLE__
int32_t zir_foreign_zir_f_76512f487eef232a_RenameAt2Raw(int32_t old_directory, uint8_t* source, int32_t new_directory, uint8_t* destination, uint32_t flags) __asm__("_renameatx_np");
#else
int32_t zir_foreign_zir_f_76512f487eef232a_RenameAt2Raw(int32_t old_directory, uint8_t* source, int32_t new_directory, uint8_t* destination, uint32_t flags) __asm__("renameatx_np");
#endif
static int32_t
zir_f_76512f487eef232a_RenameAt2Raw(int32_t old_directory, uint8_t* source, int32_t new_directory, uint8_t* destination, uint32_t flags)
{
return zir_foreign_zir_f_76512f487eef232a_RenameAt2Raw(old_directory, source,
new_directory, destination, flags);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_SyncRaw_6212288d
#define ZIR_FOREIGN_zir_f_76512f487eef232a_SyncRaw_6212288d
#ifdef __APPLE__
int32_t zir_foreign_zir_f_76512f487eef232a_SyncRaw(int32_t fd) __asm__("_fsync");
#else
int32_t zir_foreign_zir_f_76512f487eef232a_SyncRaw(int32_t fd) __asm__("fsync");
#endif
static int32_t
zir_f_76512f487eef232a_SyncRaw(int32_t fd)
{
return zir_foreign_zir_f_76512f487eef232a_SyncRaw(fd);
}
#endif
#ifndef ZIRAN_MAYBE_UNUSED
#if defined(__GNUC__) || defined(__clang__)
#define ZIRAN_MAYBE_UNUSED __attribute__((unused))
#else
#define ZIRAN_MAYBE_UNUSED
#endif
#endif
static bool file_linux_DarwinResolve(void* library, String name, void* slot) ZIRAN_MAYBE_UNUSED;
static void* file_linux_OpenDirectoryRaw(uint8_t* path) ZIRAN_MAYBE_UNUSED;
static DirectoryMetadata* file_linux_ReadDirectoryRaw(void* directory) ZIRAN_MAYBE_UNUSED;
static int32_t file_linux_CloseDirectoryRaw(void* directory) ZIRAN_MAYBE_UNUSED;
static int32_t file_linux_OpenPath(uint8_t* path, int32_t flags, int32_t mode) ZIRAN_MAYBE_UNUSED;
static FileHandle file_linux_OpenWithFlags(String path, int32_t flags) ZIRAN_MAYBE_UNUSED;
static bool
file_linux_DarwinResolve(void* library, String name, void* slot)
{
uint8_t bytes[64] = {0};
Slice value_0 = {bytes, 64};
bool value_1 = CopyCString(name, value_0);
if (!value_1) {
return false;
}
void* symbol = zir_f_76512f487eef232a_DarwinSymbol(library, &(bytes[0]));
if (symbol == ((void *)0)) {
return false;
}
zir_f_76512f487eef232a_DarwinCopy(slot, (void*)(&(symbol)), sizeof(void *));
return true;
}
static void*
file_linux_OpenDirectoryRaw(uint8_t* path)
{
void* value_0 = zir_f_76512f487eef232a_DarwinAllocate(1, sizeof(DarwinDirectory));
DarwinDirectory* search = (DarwinDirectory*)(value_0);
if (search == ((void *)0)) {
return (void *)0;
}
void** value_1 = &(search->library);
void* value_2 = zir_f_76512f487eef232a_DarwinLibrary((void *)0, 2);
(*value_1) = value_2;
bool valid = search->library != ((void *)0);
if (valid) {
bool value_3 = file_linux_DarwinResolve(search->library, StringLiteral("opendir$INODE64"), (void*)(&(search->open)));
bool value_4 = value_3 && file_linux_DarwinResolve(search->library, StringLiteral("readdir$INODE64"), (void*)(&(search->read)));
bool value_5 = value_4;
if (!value_5) {
bool value_6 = file_linux_DarwinResolve(search->library, StringLiteral("opendir"), (void*)(&(search->open)));
bool value_7 = value_6 && file_linux_DarwinResolve(search->library, StringLiteral("readdir"), (void*)(&(search->read)));
value_5 = value_7;
}
valid = value_5;
bool value_8 = valid;
valid = value_8 && file_linux_DarwinResolve(search->library, StringLiteral("closedir"), (void*)(&(search->close)));
}
if (valid) {
void** value_9 = &(search->directory);
DarwinOpenDirectory value_10 = search->open;
void* value_11 = value_10(path);
(*value_9) = value_11;
valid = search->directory != ((void *)0);
}
if (!valid) {
if (search->library != ((void *)0)) {
zir_f_76512f487eef232a_DarwinLibraryClose(search->library);
}
zir_f_76512f487eef232a_DarwinFree((void*)(search));
return (void *)0;
}
return (void*)(search);
}
static DirectoryMetadata*
file_linux_ReadDirectoryRaw(void* directory)
{
DarwinDirectory* search = (DarwinDirectory*)(directory);
DarwinReadDirectory value_0 = search->read;
return value_0(search->directory);
}
static int32_t
file_linux_CloseDirectoryRaw(void* directory)
{
DarwinDirectory* search = (DarwinDirectory*)(directory);
DarwinCloseDirectory value_0 = search->close;
int32_t status = value_0(search->directory);
zir_f_76512f487eef232a_DarwinLibraryClose(search->library);
zir_f_76512f487eef232a_DarwinFree((void*)(search));
return status;
}
static int32_t
file_linux_OpenPath(uint8_t* path, int32_t flags, int32_t mode)
{
int32_t native_flags = (int32_t)((uint32_t)flags & 3u);
if (((int32_t)((uint32_t)flags & 64u)) != 0) {
native_flags = (int32_t)((uint32_t)native_flags | 512u);
}
if (((int32_t)((uint32_t)flags & 128u)) != 0) {
native_flags = (int32_t)((uint32_t)native_flags | 2048u);
}
if (((int32_t)((uint32_t)flags & 512u)) != 0) {
native_flags = (int32_t)((uint32_t)native_flags | 1024u);
}
if (((int32_t)((uint32_t)flags & 65536u)) != 0) {
native_flags = (int32_t)((uint32_t)native_flags | 1048576u);
}
if (((int32_t)((uint32_t)flags & 2097152u)) != 0) {
native_flags = (int32_t)((uint32_t)native_flags | 32768u);
}
return zir_f_76512f487eef232a_OpenRaw(path, native_flags, mode);
}
static FileHandle
file_linux_OpenWithFlags(String path, int32_t flags)
{
FileHandle result = {0};
uint8_t name[4096] = {0};
Slice value_0 = {name, 4096};
bool value_1 = CopyCString(path, value_0);
if (!value_1) {
return result;
}
int32_t* value_2 = &(result.fd);
(*value_2) = file_linux_OpenPath(&(name[0]), flags, 420);
bool* value_3 = &(result.valid);
(*value_3) = result.fd >= 0;
return result;
}
FileHandle
OpenRead(String path)
{
return file_linux_OpenWithFlags(path, 0);
}
FileHandle
OpenUpdate(String path)
{
return file_linux_OpenWithFlags(path, 66);
}
FileHandle
OpenWrite(String path)
{
return file_linux_OpenWithFlags(path, 1);
}
FileHandle
OpenReplace(String path)
{
return file_linux_OpenWithFlags(path, 577);
}
FileHandle
OpenNew(String path)
{
return file_linux_OpenWithFlags(path, 193);
}
FileHandle
OpenExclusivePrivate(String path)
{
FileHandle result = {0};
uint8_t name[4096] = {0};
Slice value_0 = {name, 4096};
bool value_1 = CopyCString(path, value_0);
if (!value_1) {
return result;
}
int32_t* value_2 = &(result.fd);
(*value_2) = file_linux_OpenPath(&(name[0]), 193, 384);
bool* value_3 = &(result.valid);
(*value_3) = result.fd >= 0;
return result;
}
bool
RemoveFile(String path)
{
uint8_t name[4096] = {0};
Slice value_0 = {name, 4096};
bool value_1 = CopyCString(path, value_0);
if (!value_1) {
return false;
}
return zir_f_76512f487eef232a_UnlinkRaw(&(name[0])) == 0;
}
bool
PathIsLink(String path)
{
uint8_t name[4096] = {0};
Slice value_0 = {name, 4096};
bool value_1 = CopyCString(path, value_0);
if (!value_1) {
return false;
}
uint8_t byte = 0;
return zir_f_76512f487eef232a_ReadLinkRaw(&(name[0]), &(byte), 1) > 0;
}
bool
PathExists(String path)
{
uint8_t name[4096] = {0};
Slice value_0 = {name, 4096};
bool value_1 = CopyCString(path, value_0);
if (!value_1) {
return false;
}
int32_t fd = file_linux_OpenPath(&(name[0]), 2097152, 0);
if (fd < 0) {
return false;
}
return zir_f_76512f487eef232a_CloseRaw(fd) == 0;
}
bool
file_linux_DirectoryExists(String path)
{
uint8_t name[4096] = {0};
Slice value_0 = {name, 4096};
bool value_1 = CopyCString(path, value_0);
if (!value_1) {
return false;
}
int32_t fd = file_linux_OpenPath(&(name[0]), 2162688, 0);
if (fd < 0) {
return false;
}
return zir_f_76512f487eef232a_CloseRaw(fd) == 0;
}
bool
RenamePath(String source, String destination)
{
uint8_t old_name[4096] = {0};
uint8_t new_name[4096] = {0};
Slice value_0 = {old_name, 4096};
bool value_1 = CopyCString(source, value_0);
bool value_2 = !value_1;
if (!value_2) {
Slice value_3 = {new_name, 4096};
bool value_4 = CopyCString(destination, value_3);
value_2 = !value_4;
}
if (value_2) {
return false;
}
return zir_f_76512f487eef232a_RenameAtRaw(-2, &(old_name[0]), -2, &(new_name[0])) == 0;
}
bool
RenameNoReplace(String source, String destination)
{
uint8_t old_name[4096] = {0};
uint8_t new_name[4096] = {0};
Slice value_0 = {old_name, 4096};
bool value_1 = CopyCString(source, value_0);
bool value_2 = !value_1;
if (!value_2) {
Slice value_3 = {new_name, 4096};
bool value_4 = CopyCString(destination, value_3);
value_2 = !value_4;
}
if (value_2) {
return false;
}
return zir_f_76512f487eef232a_RenameAt2Raw(-2, &(old_name[0]), -2, &(new_name[0]), 4) == 0;
}
bool
LinkFile(String source, String destination)
{
uint8_t old_name[4096] = {0};
uint8_t new_name[4096] = {0};
Slice value_0 = {old_name, 4096};
bool value_1 = CopyCString(source, value_0);
bool value_2 = !value_1;
if (!value_2) {
Slice value_3 = {new_name, 4096};
bool value_4 = CopyCString(destination, value_3);
value_2 = !value_4;
}
if (value_2) {
return false;
}
return zir_f_76512f487eef232a_LinkRaw(&(old_name[0]), &(new_name[0])) == 0;
}
bool
CreateDirectory(String path)
{
uint8_t name[4096] = {0};
Slice value_0 = {name, 4096};
bool value_1 = CopyCString(path, value_0);
if (!value_1) {
return false;
}
if (zir_f_76512f487eef232a_MakeDirectoryRaw(&(name[0]), 493) == 0) {
return true;
}
return file_linux_DirectoryExists(path);
}
bool
CreatePrivateDirectory(String path)
{
uint8_t name[4096] = {0};
Slice value_0 = {name, 4096};
bool value_1 = CopyCString(path, value_0);
if (!value_1) {
return false;
}
if (zir_f_76512f487eef232a_MakeDirectoryRaw(&(name[0]), 448) == 0) {
return true;
}
return file_linux_DirectoryExists(path);
}
int64_t
FileSize(FileHandle file)
{
if (!file.valid) {
return -1LL;
}
return zir_f_76512f487eef232a_SeekRaw(file.fd, 0LL, 2);
}
int64_t
ReadAt(FileHandle file, Slice output, int64_t offset)
{
if (!file.valid || offset < 0LL) {
return -1LL;
}
if ((int64_t)(output).length == 0LL) {
return 0LL;
}
ptrdiff_t value_0 = zir_f_76512f487eef232a_ReadAtRaw(file.fd, &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)0)]), (size_t)((int64_t)(output).length), offset);
return (int64_t)(value_0);
}
int64_t
WriteAt(FileHandle file, Slice input, int64_t offset)
{
if (!file.valid || offset < 0LL) {
return -1LL;
}
if ((int64_t)(input).length == 0LL) {
return 0LL;
}
ptrdiff_t value_0 = zir_f_76512f487eef232a_WriteAtRaw(file.fd, &(((uint8_t *)input.data)[SliceIndex(input, (int64_t)0)]), (size_t)((int64_t)(input).length), offset);
return (int64_t)(value_0);
}
int64_t
WriteTextAt(FileHandle file, String input, int64_t offset)
{
if (!file.valid || offset < 0LL) {
return -1LL;
}
int64_t length = (int64_t)(input).length;
if (length > (int64_t)(UINT64_C(9223372036854775807) - (uint64_t)offset)) {
return -1LL;
}
int64_t written = 0LL;
while (written < length) {
uint8_t buffer[4096] = {0};
int64_t count = (int64_t)((uint64_t)length - (uint64_t)written);
if (count > 4096LL) {
count = 4096LL;
}
int64_t index = 0LL;
while (index < count) {
uint8_t* value_0 = &(ZIRAN_INDEX(buffer, sizeof(buffer) / sizeof(buffer[0]), index));
(*value_0) = (uint8_t)ZIRAN_INDEX(input.data, input.length, ((int64_t)((uint64_t)written + (uint64_t)index)));
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
Slice value_1 = {buffer, 4096};
int64_t result = WriteAt(file, SliceRange(value_1, (int64_t)0LL, (int64_t)count, sizeof(uint8_t)), (int64_t)((uint64_t)offset + (uint64_t)written));
if (result <= 0LL) {
return -1LL;
}
written = (int64_t)((uint64_t)written + (uint64_t)result);
}
return written;
}
bool
CloseFile(FileHandle file)
{
if (!file.valid) {
return false;
}
return zir_f_76512f487eef232a_CloseRaw(file.fd) == 0;
}
bool
SyncFile(FileHandle file)
{
if (!file.valid) {
return false;
}
return zir_f_76512f487eef232a_SyncRaw(file.fd) == 0;
}
int64_t
Read(FileHandle file, Slice output)
{
if (!file.valid || (int64_t)(output).length > 2147483647LL) {
return -1LL;
}
if ((int64_t)(output).length == 0LL) {
return 0LL;
}
ptrdiff_t value_0 = zir_f_76512f487eef232a_ReadRaw(file.fd, &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)0)]), (size_t)((int64_t)(output).length));
return (int64_t)(value_0);
}
int64_t
Write(FileHandle file, Slice input)
{
if (!file.valid || (int64_t)(input).length > 2147483647LL) {
return -1LL;
}
if ((int64_t)(input).length == 0LL) {
return 0LL;
}
ptrdiff_t value_0 = zir_f_76512f487eef232a_WriteRaw(file.fd, &(((uint8_t *)input.data)[SliceIndex(input, (int64_t)0)]), (size_t)((int64_t)(input).length));
return (int64_t)(value_0);
}
DirectoryCursor
OpenDirectory(String path)
{
DirectoryCursor result = {0};
uint8_t name[4096] = {0};
Slice value_0 = {name, 4096};
bool value_1 = CopyCString(path, value_0);
if (!value_1) {
return result;
}
void** value_2 = &(result.storage);
(*value_2) = file_linux_OpenDirectoryRaw(&(name[0]));
bool* value_3 = &(result.valid);
(*value_3) = result.storage != ((void *)0);
return result;
}
DirectoryEntry
NextDirectoryEntry(DirectoryCursor* cursor)
{
DirectoryEntry result = {0};
if (cursor == ((void *)0) || !cursor->valid || cursor->failed) {
return result;
}
if (cursor->storage == ((void *)0)) {
bool* value_0 = &(cursor->failed);
(*value_0) = true;
return result;
}
int32_t* value_1 = zir_f_76512f487eef232a_DirectoryErrno();
int32_t* value_2 = &((*(value_1)));
(*value_2) = 0;
DirectoryMetadata* entry = file_linux_ReadDirectoryRaw(cursor->storage);
if (entry == ((void *)0)) {
bool* value_3 = &(cursor->failed);
int32_t* value_4 = zir_f_76512f487eef232a_DirectoryErrno();
(*value_3) = *(value_4) != 0;
return result;
}
int32_t index = 0;
while (ZIRAN_INDEX(entry->name, 1024, index) != 0) {
if (index >= 255) {
bool* value_5 = &(cursor->failed);
(*value_5) = true;
return result;
}
uint8_t* value_6 = &(ZIRAN_INDEX(result.name, sizeof(result.name) / sizeof(result.name[0]), index));
(*value_6) = ZIRAN_INDEX(entry->name, 1024, index);
index = (int32_t)((uint32_t)index + 1u);
}
int32_t* value_7 = &(result.name_count);
(*value_7) = index;
bool* value_8 = &(result.valid);
(*value_8) = true;
DirectoryKind* value_9 = &(result.kind);
(*value_9) = DirectoryKind_Other;
if (entry->kind == 0) {
DirectoryKind* value_10 = &(result.kind);
(*value_10) = DirectoryKind_Unknown;
}
if (entry->kind == 4) {
DirectoryKind* value_11 = &(result.kind);
(*value_11) = DirectoryKind_Directory;
}
if (entry->kind == 8) {
DirectoryKind* value_12 = &(result.kind);
(*value_12) = DirectoryKind_Regular;
}
if (entry->kind == 10) {
DirectoryKind* value_13 = &(result.kind);
(*value_13) = DirectoryKind_Link;
}
return result;
}
bool
CloseDirectory(DirectoryCursor* cursor)
{
if (cursor == ((void *)0) || !cursor->valid) {
return false;
}
int32_t status = file_linux_CloseDirectoryRaw(cursor->storage);
void** value_0 = &(cursor->storage);
(*value_0) = (void *)0;
bool* value_1 = &(cursor->valid);
(*value_1) = false;
return status == 0;
}
@@ -0,0 +1,110 @@
/* Generated by zi2c from file_linux.zi. */
#ifndef ZIRAN_FILE_LINUX_H
#define ZIRAN_FILE_LINUX_H
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_slice.h"
#include "c_string.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ZIRAN_FILE_LINUX_H_PRIVATE
typedef struct DirectoryMetadata DirectoryMetadata;
#endif
#ifdef ZIRAN_FILE_LINUX_H_PRIVATE
typedef struct DarwinDirectory DarwinDirectory;
#endif
typedef struct FileHandle FileHandle;
typedef struct DirectoryCursor DirectoryCursor;
typedef uint8_t DirectoryKind;
typedef struct DirectoryEntry DirectoryEntry;
#ifdef ZIRAN_FILE_LINUX_H_PRIVATE
typedef void* (*DarwinOpenDirectory)(uint8_t*);
#endif
#ifdef ZIRAN_FILE_LINUX_H_PRIVATE
typedef DirectoryMetadata* (*DarwinReadDirectory)(void*);
#endif
#ifdef ZIRAN_FILE_LINUX_H_PRIVATE
typedef int32_t (*DarwinCloseDirectory)(void*);
#endif
#ifdef ZIRAN_FILE_LINUX_H_PRIVATE
struct DirectoryMetadata {
uint64_t inode;
int64_t offset;
uint16_t record_length;
uint16_t name_length;
uint8_t kind;
uint8_t name[1024];
};
#endif
#ifdef ZIRAN_FILE_LINUX_H_PRIVATE
struct DarwinDirectory {
void* library;
void* directory;
DarwinOpenDirectory open;
DarwinReadDirectory read;
DarwinCloseDirectory close;
};
#endif
struct FileHandle {
int32_t fd;
bool valid;
};
struct DirectoryCursor {
void* storage;
bool valid;
bool failed;
};
enum {
DirectoryKind_Unknown = 0,
DirectoryKind_Directory = 4,
DirectoryKind_Regular = 8,
DirectoryKind_Link = 10,
DirectoryKind_Other = 255,
};
struct DirectoryEntry {
uint8_t name[256];
int32_t name_count;
bool valid;
DirectoryKind kind;
};
FileHandle OpenRead(String path);
FileHandle OpenUpdate(String path);
FileHandle OpenWrite(String path);
FileHandle OpenReplace(String path);
FileHandle OpenNew(String path);
FileHandle OpenExclusivePrivate(String path);
bool RemoveFile(String path);
bool PathIsLink(String path);
bool PathExists(String path);
bool file_linux_DirectoryExists(String path);
bool RenamePath(String source, String destination);
bool RenameNoReplace(String source, String destination);
bool LinkFile(String source, String destination);
bool CreateDirectory(String path);
bool CreatePrivateDirectory(String path);
int64_t FileSize(FileHandle file);
int64_t ReadAt(FileHandle file, Slice output, int64_t offset);
int64_t WriteAt(FileHandle file, Slice input, int64_t offset);
int64_t WriteTextAt(FileHandle file, String input, int64_t offset);
bool CloseFile(FileHandle file);
bool SyncFile(FileHandle file);
int64_t Read(FileHandle file, Slice output);
int64_t Write(FileHandle file, Slice input);
DirectoryCursor OpenDirectory(String path);
DirectoryEntry NextDirectoryEntry(DirectoryCursor* cursor);
bool CloseDirectory(DirectoryCursor* cursor);
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_FILE_LINUX_H */
@@ -0,0 +1,14 @@
/* Generated by zi2c from result.zi. */
#ifndef ZIRAN_RESULT_H
#define ZIRAN_RESULT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_RESULT_H */
@@ -0,0 +1,79 @@
/* Generated by zi2c from vec.zi. */
#include <stdbool.h>
#include "zir_string_types.h"
#include <stdlib.h>
#include <string.h>
#include "zir_vec.h"
#include "vec.h"
Text
vec_TextCopy(String value)
{
Text text = {0};
bool value_0 = false;
if ((value).length == 0) {
value_0 = true;
} else {
void *value_1 = ZirVecReserve((void *)(text.bytes).data, &(text.bytes).capacity, (text.bytes).count, (int64_t)(value).length, sizeof(*(text.bytes).data));
if (value_1 != NULL) {
(text.bytes).data = (uint8_t *)value_1;
memcpy((text.bytes).data + (text.bytes).count, (value).data, (size_t)(value).length);
(text.bytes).count += (int64_t)(value).length;
value_0 = true;
}
}
if (!value_0) {
Text value_2 = (Text){0};
free((text).bytes.data);
(text).bytes.data = NULL;
(text).bytes.capacity = 0;
(text).bytes.count = 0;
return value_2;
}
Text value_3 = text;
(text).bytes.data = NULL;
(text).bytes.capacity = 0;
(text).bytes.count = 0;
Text value_4 = value_3;
free((text).bytes.data);
(text).bytes.data = NULL;
(text).bytes.capacity = 0;
(text).bytes.count = 0;
return value_4;
}
Text
vec_TextFromBuilder(__type_838711075b90279a bytes)
{
__type_838711075b90279a* value_0 = &bytes;
Text value_1 = {0};
__type_838711075b90279a value_2 = bytes;
bytes.data = NULL;
bytes.capacity = 0;
bytes.count = 0;
value_1.bytes = value_2;
Text value_3 = value_1;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_3;
}
String
vec_TextDetach(Text text)
{
String value_0 = {NULL, 0};
value_0.data = (text.bytes).count > 0 ? (const char *)(text.bytes).data : "";
value_0.length = (size_t)(text.bytes).count;
if ((text.bytes).count == 0) free((text.bytes).data);
(text.bytes).data = NULL;
text.bytes.capacity = 0;
text.bytes.count = 0;
String value_1 = value_0;
free((text).bytes.data);
(text).bytes.data = NULL;
(text).bytes.capacity = 0;
(text).bytes.count = 0;
return value_1;
}
@@ -0,0 +1,36 @@
/* Generated by zi2c from vec.zi. */
#ifndef ZIRAN_VEC_H
#define ZIRAN_VEC_H
#include "zir_string_types.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
#define ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
typedef struct __type_838711075b90279a __type_838711075b90279a;
#endif
typedef struct Text Text;
#ifndef ZIRAN_CONCRETE___type_838711075b90279a
#define ZIRAN_CONCRETE___type_838711075b90279a
struct __type_838711075b90279a {
uint8_t* data;
int64_t count;
int64_t capacity;
};
#endif
struct Text {
__type_838711075b90279a bytes;
};
Text vec_TextCopy(String value);
Text vec_TextFromBuilder(__type_838711075b90279a bytes);
String vec_TextDetach(Text text);
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_VEC_H */
+36 -16
View File
@@ -14,9 +14,18 @@ WorkerMaximum :: 16
ArgumentMaximum :: 1024
TextMaximum :: 4096
LockReadWrite :: 2
LockCreate :: 64
LockCloseOnExec :: 131072
LockNoFollow :: 262144
// Darwin numbers its open flags and sysconf names differently.
#if #defined(__APPLE__) {
LockCreate :: 512
LockCloseOnExec :: 16777216
LockNoFollow :: 256
ProcessorsOnline :: 58
} else {
LockCreate :: 64
LockCloseOnExec :: 131072
LockNoFollow :: 262144
ProcessorsOnline :: 84
}
AffinityBytes :: 128
Job :: struct {
process: s32
@@ -34,7 +43,7 @@ PendingOutput :: struct {
output: Vectors.Vec(u8)
}
WorkerLimit :: () -> s32 {
online := SysconfByName(84)
online := SysconfByName(ProcessorsOnline)
affinity := AffinityCpus()
cpus := ifx affinity > 0 && (online <= 0 || affinity < online) then affinity else online
workers := ifx cpus > 1 then cpus / 2 else 1
@@ -752,16 +761,21 @@ DiagnosticSpan :: struct {
}
AffinityCpus :: () -> s64 {
online := SysconfByName(84)
mask: [AffinityBytes]u8
if SchedGetAffinity(0, AffinityBytes, *mask[0]) != 0 { return online }
count: s64 = 0
for byte: mask {
for bit: 0..7 {
if (byte & (cast(u8)1 << cast(u8)bit)) != 0 { count += 1 }
online := SysconfByName(ProcessorsOnline)
// Darwin has no CPU affinity masks.
#if #defined(__APPLE__) {
return online
} else {
mask: [AffinityBytes]u8
if SchedGetAffinity(0, AffinityBytes, *mask[0]) != 0 { return online }
count: s64 = 0
for byte: mask {
for bit: 0..7 {
if (byte & (cast(u8)1 << cast(u8)bit)) != 0 { count += 1 }
}
}
return count
}
return count
}
AvailableMemory :: () -> s64 {
@@ -818,20 +832,26 @@ libc :: #system_library "libc";
compiler :: #system_library "ziran";
SysconfByName :: (name: s32) -> s64 #foreign libc "sysconf";
SchedGetAffinity :: (process: s32, size: usize, mask: *u8) -> s32 #foreign libc "sched_getaffinity";
#if !#defined(__APPLE__) {
SchedGetAffinity :: (process: s32, size: usize, mask: *u8) -> s32 #foreign libc "sched_getaffinity";
}
OpenReadFile :: (path: *u8) -> s32 #foreign libc "open";
CloseDescriptor :: (descriptor: s32) -> s32 #foreign libc "close";
ReadDescriptor :: (descriptor: s32, output: *u8, count: usize) -> s64 #foreign libc "read";
MakeDirectory :: (path: *u8, mode: s32) -> s32 #foreign libc "mkdir";
OpenLock :: (path: *u8, flags: s32, mode: u32) -> s32 #foreign libc "open";
OpenLock :: (path: *u8, flags: s32, mode: ..any) -> s32 #foreign libc "open";
FlockLock :: (descriptor: s32, operation: s32) -> s32 #foreign libc "flock";
PipeRaw :: (fds: *s32) -> s32 #foreign libc "pipe";
FcntlCloexec :: (descriptor: s32, command: s32, value: s32) -> s32 #foreign libc "fcntl";
FcntlCloexec :: (descriptor: s32, command: s32, value: ..any) -> s32 #foreign libc "fcntl";
ForkRaw :: () -> s32 #foreign libc "fork";
DupRaw :: (source: s32, destination: s32) -> s32 #foreign libc "dup2";
ExitChild :: (code: s32) -> void #foreign libc "_exit";
WaitRaw :: (process: s32, status: *s32, options: s32) -> s32 #foreign libc "waitpid";
ErrnoLocation :: () -> *s32 #foreign libc "__errno_location";
#if #defined(__APPLE__) {
ErrnoLocation :: () -> *s32 #foreign libc "__error";
} else {
ErrnoLocation :: () -> *s32 #foreign libc "__errno_location";
}
AllocateRaw :: (count: usize, size: usize) -> *void #foreign libc "calloc";
FreeRaw :: (memory: *void) #foreign libc "free";
FlushStreams :: (file: *void) -> s32 #foreign libc "fflush";
+4 -3
View File
@@ -85,10 +85,11 @@ main :: (argc: s32, argv: **u8) -> s32 {
command: Vec(string)
// The lowering compiles into the page beside libziran, whose engine
// and optimizer it uses under the engine's private names.
fixed: [28]string = .[emcc, "-O2", "-std=c11", "-D_GNU_SOURCE", "-Iinclude", "-Icmd/zir",
fixed: [30]string = .[emcc, "-O2", "-std=c11", "-D_GNU_SOURCE", "-Iinclude", "-Icmd/zir",
"-include", JoinPath(build, "compiler-runtime/engine_names.h"),
"-Ibootstrap/compiler_ir", "-Icmd/zi2zx", "-iquote", JoinPath(build, "compiler-runtime"),
"web/playground.c", "web/bundle.c", "cmd/zi2zx/zir_asm_lower.c", "cmd/zi2zx/zx_exec_run.c",
"-Ibootstrap/compiler_ir", "-Ibootstrap/compiler_services", "-Ibootstrap/compiler_zir_lower",
"-Icmd/zi2zx", "-iquote", JoinPath(build, "compiler-runtime"),
"web/playground.c", "web/bundle.c", "bootstrap/compiler_zir_lower/compiler_zir_lower.c", "cmd/zi2zx/zx_exec_run.c",
JoinPath(build, "libziran.a"), "-lm",
"-sMEMORY64=2", "-sMODULARIZE=1", "-sEXPORT_NAME=createPlayground",
"-sEXPORTED_FUNCTIONS=_RunSource,_BuildBundle", "-sEXPORTED_RUNTIME_METHODS=FS,ccall",
+16 -4
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
"""Measure an ordinary library's manifest-defined entries on desktop C, Go and ZX.
"""Measure an ordinary library's manifest-defined entries on desktop C, Go and native ZX.
Library behavior and host bindings stay upstream. Publish the exact checked IR,
generated files, source fixtures and raw samples, without adding compiler cases.
@@ -9,6 +9,7 @@ from datetime import datetime, timezone
import html
import json
from pathlib import Path
import platform
import re
import shutil
import statistics
@@ -26,6 +27,10 @@ def public(path):
return platforms.public(path)
def loadavg():
return Path('/proc/loadavg').read_text().split()[:3]
def archive(directory, output):
with zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED) as bundle:
for path in sorted(directory.rglob('*')):
@@ -80,6 +85,7 @@ def build(project, manifest_path, samples, revision=None):
'dirty_inputs': False if revision else
bool(run(['git', 'status', '--porcelain', '--', 'src', 'tests', 'ziran.toml', 'ziran.lock'])),
'measured_at': datetime.now(timezone.utc).isoformat(), 'host': base.cpu_name(),
'hostname': platform.node(), 'loadavg_before': loadavg(),
'versions': {'cc': run(['cc', '--version']).splitlines()[0], 'go': run(['go', 'version'])},
'methodology': manifest['methodology'] + ' Symmetric 1.5×IQR filtering excludes outliers from the median; raw samples and excluded indices are retained.', 'samples': samples,
'sources': archive(source_dir, OUTPUT / 'sources.zip'),
@@ -94,7 +100,12 @@ def build(project, manifest_path, samples, revision=None):
['scripts/site_library_targets.py', 'scripts/site_target_platforms.py', 'scripts/benchmark_samples.py',
'bench/site_target_host.c', 'bench/site_target_host.go']}, 'examples': []}
runner = WORK / 'zx-runner'
# The runner's Auto policy runs ZX as native code on Linux x86-64 and
# AArch64; a native gap fails instantiation and never falls back to the
# instruction engine, so a completed measurement is a native one.
assert platform.system() == 'Linux' and platform.machine() in ('x86_64', 'aarch64'), 'native ZX needs Linux x86-64 or AArch64'
platforms.runtime_build('cc', base.REPO / 'build/libziran.a', runner)
data['zx_backend'] = 'native'
for case in manifest['cases']:
row = {**case, 'module': module, 'stdout': '', 'targets': {}}
entry = f'{module}:{case["entry"]}'
@@ -137,9 +148,10 @@ def build(project, manifest_path, samples, revision=None):
cell['download'] = archive(public_dir, OUTPUT / case['id'] / (target + '.zip')) if target != 'zx' else emitted[0]
data['examples'].append(row)
assert data['compiler']['library_sha256'] == base.sha(base.REPO / 'build/libziran.a'), 'Runtime changed during measurement'
data['loadavg_after'] = loadavg()
(OUTPUT / 'matrix.json').write_text(json.dumps(data, indent=2) + '\n')
render(data, write=True)
print(f'{len(data["examples"])} library entries: C, Go and portable ZX executed; every batch verified')
print(f'{len(data["examples"])} library entries: C, Go and native ZX executed; every batch verified')
def render(data, write=False):
@@ -149,7 +161,7 @@ def render(data, write=False):
f'<span class="matrix-state is-ok">Verified</span><strong class="matrix-value">'
f'{base.format_time(cell["measurement"]["execution_ms"])}</strong></a></td>' for cell in row['targets'].values())
rows.append(f'<tr><th scope="row">{html.escape(row["title"])}</th>{cells}</tr>')
content = '<div class="matrix-scroll" tabindex="0" role="region" aria-label="Desktop widget comparison"><table class="target-matrix library-matrix"><caption class="sr-only">Desktop widget scenarios compiled to C, Go and portable ZX</caption><thead><tr><th scope="col">Two-frame scenario</th><th scope="col">C<small>cc -O2</small></th><th scope="col">Go<small>native</small></th><th scope="col">ZX<small>portable VM</small></th></tr></thead><tbody>' + ''.join(rows) + '</tbody></table></div>'
content = '<div class="matrix-scroll" tabindex="0" role="region" aria-label="Desktop widget comparison"><table class="target-matrix library-matrix"><caption class="sr-only">Desktop widget scenarios compiled to C, Go and ZX run as native code</caption><thead><tr><th scope="col">Two-frame scenario</th><th scope="col">C<small>cc -O2</small></th><th scope="col">Go<small>native</small></th><th scope="col">ZX<small>native</small></th></tr></thead><tbody>' + ''.join(rows) + '</tbody></table></div>'
page = base.SITE / 'targets.html'
original = page.read_text()
result = re.sub(r'(?s)(<!-- generated:' + MARKER + r' -->).*?(<!-- /generated:' + MARKER + r' -->)', lambda m: m[1] + '\n' + content + '\n' + m[2], original)
@@ -161,7 +173,7 @@ def render(data, write=False):
def check():
data = json.loads((OUTPUT / 'matrix.json').read_text())
assert data['schema_version'] == 1 and data['samples'] >= 3
assert data['schema_version'] == 1 and data['samples'] >= 3 and data.get('zx_backend') == 'native'
for name, digest in data['harnesses'].items():
assert base.sha(base.REPO / name) == digest, f'Stale library harness: {name}'
files = [data['sources'], data['checked_ir']]
+6 -8
View File
@@ -346,7 +346,8 @@ DirectoryMetadata :: struct {
WriteRaw :: (fd: s32, input: *u8, count: usize) -> isize #foreign libc "write";
#if #defined(__APPLE__) {
// Intel Darwin versions its 64-bit directory symbols; Apple Silicon
// uses their plain names. Resolve the matching ABI once per cursor.
// has only their plain names, with the same record. Resolve the
// matching ABI once per cursor, so one build serves both CPUs.
DarwinOpenDirectory :: #type (path: *u8) -> *void #c_call;
DarwinReadDirectory :: #type (directory: *void) -> *DirectoryMetadata #c_call;
DarwinCloseDirectory :: #type (directory: *void) -> s32 #c_call;
@@ -377,13 +378,10 @@ DirectoryMetadata :: struct {
search.library = DarwinLibrary(null, 2)
valid := search.library != null
if valid {
#if #defined(__x86_64__) {
valid = DarwinResolve(search.library, "opendir$INODE64", cast(*void)(*search.open)) &&
DarwinResolve(search.library, "readdir$INODE64", cast(*void)(*search.read))
} else {
valid = DarwinResolve(search.library, "opendir", cast(*void)(*search.open)) &&
DarwinResolve(search.library, "readdir", cast(*void)(*search.read))
}
valid = (DarwinResolve(search.library, "opendir$INODE64", cast(*void)(*search.open)) &&
DarwinResolve(search.library, "readdir$INODE64", cast(*void)(*search.read))) ||
(DarwinResolve(search.library, "opendir", cast(*void)(*search.open)) &&
DarwinResolve(search.library, "readdir", cast(*void)(*search.read)))
valid = valid && DarwinResolve(search.library, "closedir", cast(*void)(*search.close))
}
if valid { search.directory = search.open(path); valid = search.directory != null }
+136 -40
View File
@@ -12,7 +12,7 @@
//
// PathStatus reads a path's kind, owner, permission bits, size and modification
// time with statx, whose record has one layout on every little-endian Linux
// architecture.
// architecture, or on Darwin with fstatat's 64-bit-inode record.
#import "c_string"
#import "byte_text_linux"
#import "sort"
@@ -21,13 +21,12 @@ using Vectors :: #import "vec"
#scope_file
libc :: #system_library "libc";
StatxRaw :: (directory: s32, path: *u8, flags: s32, mask: u32, output: *StatxRecord) -> s32 #foreign libc "statx";
MakeDirectoryRaw :: (path: *u8, mode: u32) -> s32 #foreign libc "mkdir";
RemoveDirectoryRaw :: (path: *u8) -> s32 #foreign libc "rmdir";
UnlinkRaw :: (path: *u8) -> s32 #foreign libc "unlink";
ChangeModeRaw :: (path: *u8, mode: u32) -> s32 #foreign libc "chmod";
ChangeFileModeRaw :: (fd: s32, mode: u32) -> s32 #foreign libc "fchmod";
OpenRaw :: (path: *u8, flags: s32, mode: s32) -> s32 #foreign libc "open";
OpenRaw :: (path: *u8, flags: s32, mode: ..any) -> s32 #foreign libc "open";
CloseRaw :: (fd: s32) -> s32 #foreign libc "close";
FlockRaw :: (fd: s32, operation: s32) -> s32 #foreign libc "flock";
FsyncRaw :: (fd: s32) -> s32 #foreign libc "fsync";
@@ -38,19 +37,143 @@ TemporaryDirectoryRaw :: (template: *u8) -> *u8 #foreign libc "mkdtemp";
EffectiveUserRaw :: () -> u32 #foreign libc "geteuid";
WorkingDirectoryRaw :: (output: *u8, size: usize) -> *u8 #foreign libc "getcwd";
ProcessIdRaw :: () -> s32 #foreign libc "getpid";
ErrnoRaw :: () -> *s32 #foreign libc "__errno_location";
FreeOwnedRaw :: (memory: *void) #foreign libc "free";
SymbolicLinkRaw :: (target: *u8, path: *u8) -> s32 #foreign libc "symlink";
ReadLinkRaw :: (path: *u8, output: *u8, capacity: usize) -> isize #foreign libc "readlink";
StatxRecord :: struct { words: [32]u64 }
CURRENT_DIRECTORY :: -100;
NO_FOLLOW :: 256;
BASIC_STATS :: 2047;
#if #defined(__APPLE__) {
ErrnoRaw :: () -> *s32 #foreign libc "__error";
// Darwin's stat record with 64-bit inodes: Intel exports it under the
// $INODE64 symbol names, Apple Silicon under the plain ones.
StatRecord :: struct {
device: s32
mode: u16
links: u16
inode: u64
owner_uid: u32
group_id: u32
special_device: s32
padding: s32
accessed: s64
accessed_nanoseconds: s64
modified: s64
modified_nanoseconds: s64
changed: s64
changed_nanoseconds: s64
born: s64
born_nanoseconds: s64
size: s64
blocks: s64
block_size: s32
flags: u32
generation: u32
spare: s32
reserved: [8]s64
}
StatAt :: #type (directory: s32, path: *u8, output: *StatRecord, flags: s32) -> s32 #c_call;
StatEntry :: struct { call: StatAt }
LibraryRaw :: (path: *u8, flags: s32) -> *void #foreign libc "dlopen";
SymbolRaw :: (library: *void, name: *u8) -> *void #foreign libc "dlsym";
CopyBytesRaw :: (output: *void, value: *void, count: usize) -> *void #foreign libc "memcpy";
StatAtRaw :: (directory: s32, path: *u8, output: *StatRecord, flags: s32) -> s32 {
library := LibraryRaw(null, 2)
if library == null { return -1 }
names := string.["fstatat$INODE64", "fstatat"]
for candidate: names {
bytes: [32]u8
if !CopyCString(candidate, bytes[:]) { return -1 }
symbol := SymbolRaw(library, *bytes[0])
if symbol != null {
entry: StatEntry
unused CopyBytesRaw(cast(*void)(*entry.call), cast(*void)(*symbol), size_of(*void))
return entry.call(directory, path, output, flags)
}
}
return -1
}
CURRENT_DIRECTORY :: -2;
NO_FOLLOW :: 32;
WRITE_TRUNCATE :: 1537;
WRITE_APPEND :: 521;
CLOSE_ON_EXEC :: 16777216;
} else {
StatxRaw :: (directory: s32, path: *u8, flags: s32, mask: u32, output: *StatxRecord) -> s32 #foreign libc "statx";
ErrnoRaw :: () -> *s32 #foreign libc "__errno_location";
StatxRecord :: struct { words: [32]u64 }
CURRENT_DIRECTORY :: -100;
NO_FOLLOW :: 256;
BASIC_STATS :: 2047;
WRITE_TRUNCATE :: 577;
WRITE_APPEND :: 1089;
CLOSE_ON_EXEC :: 524288;
}
EXISTS :: 17;
INTERRUPTED :: 4;
PathKindOf :: (mode: s32) -> PathKind {
type := mode & 61440
if type == 32768 { return .File }
if type == 16384 { return .Directory }
if type == 40960 { return .Link }
return .Other
}
#if #defined(__APPLE__) {
ReadPathInfo :: (name: *u8, flags: s32, info: *PathInfo) -> bool {
record: StatRecord
if StatAtRaw(CURRENT_DIRECTORY, name, *record, flags) != 0 { return false }
mode := cast(s32)record.mode
info.kind = PathKindOf(mode)
info.owner_uid = record.owner_uid
info.mode = mode & 4095
info.size = record.size
info.inode = record.inode
// Darwin always fills the basic fields, so report statx's basic mask.
info.metadata_mask = 2047
valid_times := record.modified_nanoseconds >= 0 && record.modified_nanoseconds < 1000000000 &&
record.changed_nanoseconds >= 0 && record.changed_nanoseconds < 1000000000
if valid_times {
info.modified = record.modified
info.modified_nanoseconds = cast(u32)record.modified_nanoseconds
info.changed = record.changed
info.changed_nanoseconds = cast(u32)record.changed_nanoseconds
}
device := cast(u32)record.device
info.device_major = (device >> 24) & 255
info.device_minor = device & 16777215
info.identity_valid = valid_times && info.size >= 0
return true
}
} else {
ReadPathInfo :: (name: *u8, flags: s32, info: *PathInfo) -> bool {
record: StatxRecord
if StatxRaw(CURRENT_DIRECTORY, name, flags, BASIC_STATS, *record) != 0 { return false }
info.metadata_mask = cast(u32)record.words[0]
mode := cast(s32)((record.words[3] >> 32) & 65535)
info.kind = PathKindOf(mode)
info.owner_uid = cast(u32)(record.words[2] >> 32)
info.mode = mode & 4095
if (info.metadata_mask & 512) != 0 { info.size = cast(s64)record.words[5] }
if (info.metadata_mask & 256) != 0 { info.inode = record.words[4] }
modified_fraction := cast(u32)record.words[15]
changed_fraction := cast(u32)record.words[13]
if (info.metadata_mask & 64) != 0 && modified_fraction < 1000000000 {
info.modified = cast(s64)record.words[14]
info.modified_nanoseconds = modified_fraction
}
if (info.metadata_mask & 128) != 0 && changed_fraction < 1000000000 {
info.changed = cast(s64)record.words[12]
info.changed_nanoseconds = changed_fraction
}
// Device identifiers are statx stx_dev fields (not the rdev fields).
info.device_major = cast(u32)record.words[17]
info.device_minor = cast(u32)(record.words[17] >> 32)
info.identity_valid = (info.metadata_mask & 961) == 961 && info.size >= 0 &&
modified_fraction < 1000000000 && changed_fraction < 1000000000
return true
}
}
#scope_export
PathKind :: enum u8 { Missing :: 0; File :: 1; Directory :: 2; Link :: 3; Other :: 4; }
@@ -93,40 +216,13 @@ PathQuery :: (path: string, follow_links: bool = true) -> PathQueryResult {
result.error = 22 // EINVAL
return result
}
record: StatxRecord
flags: s32 = ifx follow_links then 0 else NO_FOLLOW
if StatxRaw(CURRENT_DIRECTORY, *name[0], flags, BASIC_STATS, *record) != 0 {
info: PathInfo
if !ReadPathInfo(*name[0], flags, *info) {
result.error = <<ErrnoRaw()
result.missing = result.error == 2 || result.error == 20 // ENOENT / ENOTDIR
return result
}
info: PathInfo
info.metadata_mask = cast(u32)record.words[0]
mode := cast(s32)((record.words[3] >> 32) & 65535)
type := mode & 61440
info.kind = .Other
if type == 32768 { info.kind = .File }
if type == 16384 { info.kind = .Directory }
if type == 40960 { info.kind = .Link }
info.owner_uid = cast(u32)(record.words[2] >> 32)
info.mode = mode & 4095
if (info.metadata_mask & 512) != 0 { info.size = cast(s64)record.words[5] }
if (info.metadata_mask & 256) != 0 { info.inode = record.words[4] }
modified_fraction := cast(u32)record.words[15]
changed_fraction := cast(u32)record.words[13]
if (info.metadata_mask & 64) != 0 && modified_fraction < 1000000000 {
info.modified = cast(s64)record.words[14]
info.modified_nanoseconds = modified_fraction
}
if (info.metadata_mask & 128) != 0 && changed_fraction < 1000000000 {
info.changed = cast(s64)record.words[12]
info.changed_nanoseconds = changed_fraction
}
// Device identifiers are statx stx_dev fields (not the rdev fields).
info.device_major = cast(u32)record.words[17]
info.device_minor = cast(u32)(record.words[17] >> 32)
info.identity_valid = (info.metadata_mask & 961) == 961 && info.size >= 0 &&
modified_fraction < 1000000000 && changed_fraction < 1000000000
result.info = info
result.valid = true
return result
@@ -526,7 +622,7 @@ ReplaceFile :: (path: string, text: string) -> bool {
final: [4096]u8
if !CopyCString(temporary, name[:]) || !CopyCString(path, final[:]) { return false }
mode: s32 = ifx previous.kind == .File then previous.mode else 420
fd := OpenRaw(*name[0], 577 | 524288, mode)
fd := OpenRaw(*name[0], WRITE_TRUNCATE | CLOSE_ON_EXEC, mode)
if fd < 0 { return false }
chunk: [65536]u8
written: s64 = 0
@@ -557,7 +653,7 @@ ReplaceFile :: (path: string, text: string) -> bool {
LockPath :: (path: string, exclusive: bool = true, wait: bool = true) -> s32 {
name: [4096]u8
if !CopyCString(path, name[:]) { return -1 }
fd := OpenRaw(*name[0], 1 | 64 | 1024 | 524288, 420)
fd := OpenRaw(*name[0], WRITE_APPEND | CLOSE_ON_EXEC, 420)
if fd < 0 { return -1 }
operation: s32 = ifx exclusive then 2 else 1
if !wait { operation |= 4 }
+25 -6
View File
@@ -23,12 +23,11 @@ using Vectors :: #import "vec"
#scope_file
libc :: #system_library "libc";
ForkRaw :: () -> s32 #foreign libc "fork";
Pipe2Raw :: (fds: *s32, flags: s32) -> s32 #foreign libc "pipe2";
DupRaw :: (source: s32, destination: s32) -> s32 #foreign libc "dup2";
CloseRaw :: (fd: s32) -> s32 #foreign libc "close";
ReadRaw :: (fd: s32, output: *u8, count: usize) -> isize #foreign libc "read";
WriteRaw :: (fd: s32, input: *u8, count: usize) -> isize #foreign libc "write";
OpenRaw :: (path: *u8, flags: s32, mode: s32) -> s32 #foreign libc "open";
OpenRaw :: (path: *u8, flags: s32, mode: ..any) -> s32 #foreign libc "open";
ExecRaw :: (path: *u8, arguments: *ProcessArgumentSlot) -> s32 #foreign libc "execvp";
ExitRaw :: (code: s32) -> void #foreign libc "_exit";
WaitRaw :: (pid: s32, status: *s32, options: s32) -> s32 #foreign libc "waitpid";
@@ -37,11 +36,31 @@ ChangeDirectoryRaw :: (path: *u8) -> s32 #foreign libc "chdir";
SetEnvironmentRaw :: (name: *u8, value: *u8, overwrite: s32) -> s32 #foreign libc "setenv";
UnsetEnvironmentRaw :: (name: *u8) -> s32 #foreign libc "unsetenv";
SessionRaw :: () -> s32 #foreign libc "setsid";
ErrnoRaw :: () -> *s32 #foreign libc "__errno_location";
SignalHandler :: #type (signal_number: s32) -> void #c_call;
SignalRaw :: (signal_number: s32, handler: SignalHandler) -> SignalHandler #foreign libc "signal";
CLOSE_ON_EXEC :: 524288;
#if #defined(__APPLE__) {
// Darwin has no pipe2: both ends become close-on-exec before any fork.
PipeRaw :: (fds: *s32) -> s32 #foreign libc "pipe";
FcntlRaw :: (fd: s32, command: s32, value: ..any) -> s32 #foreign libc "fcntl";
Pipe2Raw :: (fds: *s32, flags: s32) -> s32 {
if PipeRaw(fds) != 0 { return -1 }
for end: 0..1 {
if FcntlRaw(fds[end], 2, 1) != 0 { CloseRaw(fds[0]); CloseRaw(fds[1]); return -1 }
}
return 0
}
ErrnoRaw :: () -> *s32 #foreign libc "__error";
CLOSE_ON_EXEC :: 16777216;
WRITE_TRUNCATE :: 1537;
WRITE_APPEND :: 521;
} else {
Pipe2Raw :: (fds: *s32, flags: s32) -> s32 #foreign libc "pipe2";
ErrnoRaw :: () -> *s32 #foreign libc "__errno_location";
CLOSE_ON_EXEC :: 524288;
WRITE_TRUNCATE :: 577;
WRITE_APPEND :: 1089;
}
INTERRUPTED :: 4;
#scope_export
@@ -182,14 +201,14 @@ Child :: (options: ProcessOptions, prepared: *Prepared, status: s32, capture: s3
if !failed && capture >= 0 {
if DupRaw(capture, 1) < 0 { failed = true }
} else if !failed && prepared.output >= 0 {
flags: s32 = ifx options.append_output then 1089 else 577
flags: s32 = ifx options.append_output then WRITE_APPEND else WRITE_TRUNCATE
fd := OpenRaw(At(prepared, prepared.output), flags | CLOSE_ON_EXEC, 420)
if fd < 0 || DupRaw(fd, 1) < 0 { failed = true }
}
if !failed && options.merge_error {
if DupRaw(1, 2) < 0 { failed = true }
} else if !failed && prepared.error >= 0 {
fd := OpenRaw(At(prepared, prepared.error), 577 | CLOSE_ON_EXEC, 420)
fd := OpenRaw(At(prepared, prepared.error), WRITE_TRUNCATE | CLOSE_ON_EXEC, 420)
if fd < 0 || DupRaw(fd, 2) < 0 { failed = true }
}
if !failed && prepared.directory >= 0 && ChangeDirectoryRaw(At(prepared, prepared.directory)) != 0 { failed = true }
+18 -5
View File
@@ -78,15 +78,28 @@
}
ClockGetTimeRaw :: (clock: s32, value: *ClockValue) -> s32 #foreign libc "clock_gettime";
ClockSleepRaw :: (clock: s32, flags: s32, request: *ClockValue,
remaining: *ClockValue) -> s32 #foreign libc "clock_nanosleep";
#if #defined(__APPLE__) {
// Darwin numbers CLOCK_MONOTONIC 6 and has no clock_nanosleep;
// nanosleep reports EINTR through errno instead of its result.
MONOTONIC_CLOCK :: 6;
SleepRaw :: (request: *ClockValue, remaining: *ClockValue) -> s32 #foreign libc "nanosleep";
ErrnoRaw :: () -> *s32 #foreign libc "__error";
ClockSleepRaw :: (clock: s32, flags: s32, request: *ClockValue, remaining: *ClockValue) -> s32 {
if SleepRaw(request, remaining) == 0 { return 0 }
return <<ErrnoRaw()
}
} else {
MONOTONIC_CLOCK :: 1;
ClockSleepRaw :: (clock: s32, flags: s32, request: *ClockValue,
remaining: *ClockValue) -> s32 #foreign libc "clock_nanosleep";
}
// Nanosecond resolution for profiling short operations. -1 reports a failed
// clock or a value outside the signed nanosecond range.
#program_export
MonotonicNanoseconds :: () -> s64 {
value: ClockValue
if ClockGetTimeRaw(1, *value) != 0 { return -1 }
if ClockGetTimeRaw(MONOTONIC_CLOCK, *value) != 0 { return -1 }
seconds := cast(s64)value.seconds; nanoseconds := cast(s64)value.nanoseconds
if seconds < 0 || nanoseconds < 0 || nanoseconds > 999999999 ||
seconds > 9223372036 ||
@@ -97,7 +110,7 @@
#program_export
MonotonicMilliseconds :: () -> s64 {
value: [1]ClockValue
if ClockGetTimeRaw(1, *value[0]) != 0 { return -1 }
if ClockGetTimeRaw(MONOTONIC_CLOCK, *value[0]) != 0 { return -1 }
seconds := cast(s64)value[0].seconds; nanoseconds := cast(s64)value[0].nanoseconds
if nanoseconds < 0 || nanoseconds > 999999999 {
return -1
@@ -129,7 +142,7 @@
remaining: [1]ClockValue
request[0] = MakeClockValue(milliseconds)
while request[0].seconds > 0 || request[0].nanoseconds > 0 {
status: s32 = ClockSleepRaw(1, 0, *request[0], *remaining[0])
status: s32 = ClockSleepRaw(MONOTONIC_CLOCK, 0, *request[0], *remaining[0])
if status == 0 { return true }
if status != 4 { return false }
request[0] = remaining[0]
+1 -1
View File
@@ -72,7 +72,7 @@ BuildBundle(const char *root, const char *search, const char *inputs,
merged.modules[at++] = set.programs[p]->modules[m];
ZirProgram *program = &merged;
if(!LinkImports(&program, 1)) goto done;
bytes = ZxExecBuild(&merged, entry_module, entry_function, (Slice){0}, &size);
bytes = ZxExecBuild(&merged, entry_module, entry_function, (Slice){0}, 0, &size);
if(bytes == NULL) goto done;
file = fopen(output, "wb");
if(file == NULL || fwrite(bytes, 1, size, file) != size) goto done;
+1 -1
View File
@@ -80,7 +80,7 @@ int RunSource(void)
goto done;
}
report_stage("build");
bytes = ZxExecBuild(&merged, "playground", entry, (Slice){0}, &size);
bytes = ZxExecBuild(&merged, "playground", entry, (Slice){0}, 0, &size);
if(bytes == NULL || (bundle = BundleOpenBytes(bytes, size)) == NULL)
goto done;
report_stage("run");