Files
ziran/bootstrap/compiler_backend_process/compiler_backend_process.c
T
waozi 436d73cf3a Regenerate the bootstrap without the TinyCC guard
The checked-arithmetic helpers every generated module carries no longer
test __TINYC__.
2026-11-15 21:56:20 -03:00

2789 lines
106 KiB
C

/* Generated by zi2c from compiler_backend_process.zi. */
#define ZIRAN_COMPILER_BACKEND_PROCESS_H_SOURCE 1
#include <stdbool.h>
#include "zir_bounds.h"
#include "zir_string.h"
#include "zir_vec.h"
#include "compiler_backend_process.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
#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
__type_c53c2d7c4913dc02 zir_g_b176900cac1241ec = {0};
int32_t
compiler_backend_process_WorkerLimit(void)
{
int64_t online = zir_f_1cd1ecb166af98b1_SysconfByName(84);
int64_t affinity = compiler_backend_process_AffinityCpus();
int64_t value_0 = 0;
if (affinity > 0LL && (online <= 0LL || affinity < online)) {
value_0 = affinity;
} else {
value_0 = online;
}
int64_t cpus = value_0;
int64_t value_1 = 0;
if (cpus > 1LL) {
value_1 = cpus / 2LL;
} else {
value_1 = 1LL;
}
int64_t workers = value_1;
int64_t requested = environment_linux_EnvironmentNumber(StringLiteral("ZIRAN_JOBS"), workers);
if (requested > 0LL && requested < workers) {
workers = requested;
}
int64_t memory = compiler_backend_process_AvailableMemory();
if (memory >= 0LL) {
int64_t capacity = memory / 512LL;
if (capacity > 0LL && capacity < workers) {
workers = capacity;
}
if (capacity <= 0LL) {
workers = 1LL;
}
}
int64_t value_2 = 0;
if (workers < 16LL) {
value_2 = workers;
} else {
value_2 = 16LL;
}
return (int32_t)(value_2);
}
int32_t
compiler_backend_process_BuildLock(String directory)
{
zir_8a167d86ad221008_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) {
return -1;
}
uint8_t name[4096] = {0};
bool value_2 = compiler_backend_process_CreateDirectories(directory);
bool value_3 = !value_2;
if (!value_3) {
Slice value_4 = {name, 4096};
bool value_5 = CopyCString(lock_path, value_4);
value_3 = !value_5;
}
if (value_3) {
int32_t cleanup_return_0 = -1;
{
compiler_backend_process_ReleaseOwnedText(lock_path);
}
return cleanup_return_0;
}
int32_t descriptor = zir_f_1cd1ecb166af98b1_OpenLock(&(name[0]), 393282, 384);
if (descriptor < 0) {
int32_t cleanup_return_1 = -1;
{
compiler_backend_process_ReleaseOwnedText(lock_path);
}
return cleanup_return_1;
}
PathInfo info = file_tree_linux_PathStatus(lock_path, false);
if (((PathKind)(info.kind)) != ((PathKind)(1))) {
zir_f_1cd1ecb166af98b1_CloseDescriptor(descriptor);
int32_t cleanup_return_2 = -1;
{
compiler_backend_process_ReleaseOwnedText(lock_path);
}
return cleanup_return_2;
}
if (zir_f_1cd1ecb166af98b1_FlockLock(descriptor, 2) != 0) {
zir_f_1cd1ecb166af98b1_CloseDescriptor(descriptor);
int32_t cleanup_return_3 = -1;
{
compiler_backend_process_ReleaseOwnedText(lock_path);
}
return cleanup_return_3;
}
int32_t cleanup_return_4 = descriptor;
{
compiler_backend_process_ReleaseOwnedText(lock_path);
}
return cleanup_return_4;
}
void
compiler_backend_process_ReleasePointerVector(__type_21092c8252d3dcaa* values)
{
__type_21092c8252d3dcaa owned = {0};
__type_21092c8252d3dcaa* value_0 = &owned;
__type_21092c8252d3dcaa value_1 = owned;
owned = (*(values));
(*(values)) = value_1;
for (int64_t it_index = 0LL; it_index < owned.count; it_index++) {
uint8_t* value = ZIRAN_VEC_INDEX((owned).data, (owned).count, it_index);
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(value));
}
free((owned).data);
(owned).data = NULL;
owned.capacity = 0;
owned.count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
}
Job
compiler_backend_process_StartJob(Slice commands, bool capture, bool report_error)
{
Job result = {0};
int32_t* value_0 = &(result.process);
(*value_0) = -1;
int32_t* value_1 = &(result.descriptor);
(*value_1) = -1;
__type_21092c8252d3dcaa pointers = {0};
__type_21092c8252d3dcaa* value_2 = &pointers;
bool value_3 = (int64_t)(commands).length == 0LL || (int64_t)(commands).length > 1023LL;
if (!value_3) {
bool value_4 = compiler_backend_process_PrepareArguments(commands, &(pointers));
value_3 = !value_4;
}
if (value_3) {
__type_21092c8252d3dcaa value_5 = pointers;
pointers.data = NULL;
pointers.capacity = 0;
pointers.count = 0;
compiler_backend_process_FreePointers(value_5);
Job value_6 = result;
(result).output.data = NULL;
(result).output.capacity = 0;
(result).output.count = 0;
Job value_7 = value_6;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((result).output.data);
(result).output.data = NULL;
(result).output.capacity = 0;
(result).output.count = 0;
return value_7;
}
int32_t pipes[2] = {-1, -1};
if (capture && zir_f_1cd1ecb166af98b1_PipeRaw(&(pipes[0])) != 0) {
__type_21092c8252d3dcaa value_8 = pointers;
pointers.data = NULL;
pointers.capacity = 0;
pointers.count = 0;
compiler_backend_process_FreePointers(value_8);
Job value_9 = result;
(result).output.data = NULL;
(result).output.capacity = 0;
(result).output.count = 0;
Job value_10 = value_9;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((result).output.data);
(result).output.data = NULL;
(result).output.capacity = 0;
(result).output.count = 0;
return value_10;
}
if (capture) {
compiler_backend_process_SetCloexec((pipes)[0]);
compiler_backend_process_SetCloexec((pipes)[1]);
}
zir_f_1cd1ecb166af98b1_FlushStreams((void *)0);
int32_t process = zir_f_1cd1ecb166af98b1_ForkRaw();
if (process == 0) {
if (capture) {
zir_f_1cd1ecb166af98b1_CloseDescriptor((pipes)[0]);
}
if (capture) {
bool value_11 = zir_f_1cd1ecb166af98b1_DupRaw((pipes)[1], 1) < 0;
if (value_11 || zir_f_1cd1ecb166af98b1_DupRaw((pipes)[1], 2) < 0) {
zir_f_1cd1ecb166af98b1_ExitChild(127);
}
if ((pipes)[1] > 2) {
zir_f_1cd1ecb166af98b1_CloseDescriptor((pipes)[1]);
}
}
CapturePointer slots[1024] = {0};
{
int64_t range_first_32 = 0LL;
int64_t range_last_32 = (int64_t)((uint64_t)(pointers.count) - UINT64_C(1));
int64_t index = range_first_32;
if (index <= range_last_32) for (;;) {
uint8_t** value_12 = &((ZIRAN_INDEX(slots, sizeof(slots) / sizeof(slots[0]), index)).value);
(*value_12) = ZIRAN_VEC_INDEX((pointers).data, (pointers).count, index);
if (index == range_last_32) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
compiler_backend_process_ExecChild((slots[0]).value, &(slots[0]), report_error);
zir_f_1cd1ecb166af98b1_ExitChild(127);
}
if (capture) {
zir_f_1cd1ecb166af98b1_CloseDescriptor((pipes)[1]);
}
__type_21092c8252d3dcaa value_13 = pointers;
pointers.data = NULL;
pointers.capacity = 0;
pointers.count = 0;
compiler_backend_process_FreePointers(value_13);
if (process < 0) {
if (capture) {
zir_f_1cd1ecb166af98b1_CloseDescriptor((pipes)[0]);
}
Job value_14 = result;
(result).output.data = NULL;
(result).output.capacity = 0;
(result).output.count = 0;
Job value_15 = value_14;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((result).output.data);
(result).output.data = NULL;
(result).output.capacity = 0;
(result).output.count = 0;
return value_15;
}
compiler_backend_process_ProfileCount(StringLiteral("native_process_fork"));
compiler_backend_process_ProfileCount(StringLiteral("native_process_poll"));
int32_t* value_16 = &(result.process);
(*value_16) = process;
int32_t* value_17 = &(result.descriptor);
int32_t value_18 = 0;
if (capture) {
value_18 = (pipes)[0];
} else {
value_18 = -1;
}
(*value_17) = value_18;
Job value_19 = result;
(result).output.data = NULL;
(result).output.capacity = 0;
(result).output.count = 0;
Job value_20 = value_19;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((result).output.data);
(result).output.data = NULL;
(result).output.capacity = 0;
(result).output.count = 0;
return value_20;
}
bool
compiler_backend_process_WaitJob(Job* job)
{
while (job->descriptor >= 0) {
bool value_0 = compiler_backend_process_ReadJobOutput(job);
if (!value_0) {
bool* value_1 = &(job->ok);
(*value_1) = false;
}
}
if (job->finished) {
return job->ok;
}
int32_t status = 0;
int32_t waited = 0;
waited = zir_f_1cd1ecb166af98b1_WaitRaw(job->process, &(status), 0);
while (waited < 0 && compiler_backend_process_ErrnoValue() == 4) {
waited = zir_f_1cd1ecb166af98b1_WaitRaw(job->process, &(status), 0);
}
if (waited != job->process) {
bool* value_2 = &(job->finished);
(*value_2) = true;
bool* value_3 = &(job->ok);
(*value_3) = false;
return false;
}
Job* value_4 = job;
int32_t value_5 = status;
{
Job* job = value_4;
int32_t status = value_5;
bool* value_7 = &(job->finished);
(*value_7) = true;
bool* value_8 = &(job->ok);
bool value_9 = ((int32_t)((uint32_t)status & 127u)) == 0 && ((int32_t)((uint32_t)((ZiShrS32(status, (uint64_t)(8), 32))) & 255u)) == 0;
(*value_8) = value_9;
}
return job->ok;
}
void
compiler_backend_process_FreeJob(Job* job)
{
if (job->descriptor >= 0) {
zir_f_1cd1ecb166af98b1_CloseDescriptor(job->descriptor);
int32_t* value_0 = &(job->descriptor);
(*value_0) = -1;
}
free((job->output).data);
(job->output).data = NULL;
job->output.capacity = 0;
job->output.count = 0;
}
bool
compiler_backend_process_TextStartsWith(String value, String prefix)
{
return (int64_t)(prefix).length <= (int64_t)(value).length && StringEqual(StringRange(value, (int64_t)0LL, (int64_t)(int64_t)(prefix).length), prefix);
}
bool
compiler_backend_process_TextEndsWith(String value, String suffix)
{
return (int64_t)(suffix).length <= (int64_t)(value).length && StringEqual(StringRange(value, (int64_t)((int64_t)((uint64_t)((int64_t)(value).length) - (uint64_t)((int64_t)(suffix).length))), (int64_t)(int64_t)(value).length), suffix);
}
bool
compiler_backend_process_TextContains(String value, String piece)
{
int64_t at = 0LL;
if ((int64_t)(piece).length == 0LL) {
return true;
}
while ((int64_t)((uint64_t)at + (uint64_t)((int64_t)(piece).length)) <= (int64_t)(value).length) {
if (StringEqual(StringRange(value, (int64_t)at, (int64_t)((int64_t)((uint64_t)at + (uint64_t)((int64_t)(piece).length)))), piece)) {
return true;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
return false;
}
String
compiler_backend_process_PathName(String value)
{
int64_t at = (int64_t)(value).length;
while (at > 0LL && (uint8_t)ZIRAN_INDEX(value.data, value.length, ((int64_t)((uint64_t)at - UINT64_C(1)))) != 47) {
at = (int64_t)((uint64_t)at - UINT64_C(1));
}
return StringRange(value, (int64_t)at, (int64_t)(int64_t)(value).length);
}
zir_8a167d86ad221008_Results__string__bool
compiler_backend_process_PathJoin(String left, String right)
{
__type_838711075b90279a bytes = {0};
__type_838711075b90279a* value_2 = &bytes;
bool value_3 = false;
if ((left).length == 0) {
value_3 = true;
} else {
void *value_4 = ZirVecReserve((void *)(bytes).data, &(bytes).capacity, (bytes).count, (int64_t)(left).length, sizeof(*(bytes).data));
if (value_4 != NULL) {
(bytes).data = (uint8_t *)value_4;
memcpy((bytes).data + (bytes).count, (left).data, (size_t)(left).length);
(bytes).count += (int64_t)(left).length;
value_3 = true;
}
}
if (!value_3) {
free((bytes).data);
(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};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_5;
}
if ((int64_t)(left).length > 0LL && (uint8_t)ZIRAN_INDEX(left.data, left.length, ((int64_t)((uint64_t)((int64_t)(left).length) - UINT64_C(1)))) != 47) {
uint8_t value_6 = 47;
bool value_7 = false;
void *value_8 = ZirVecGrow((void *)(bytes).data, &(bytes).capacity, (bytes).count, sizeof(*(bytes).data));
if (value_8 != NULL) {
(bytes).data = (uint8_t *)value_8;
(bytes).data[(bytes).count++] = value_6;
value_7 = true;
}
if (!value_7) {
free((bytes).data);
(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};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_9;
}
}
bool value_10 = false;
if ((right).length == 0) {
value_10 = true;
} else {
void *value_11 = ZirVecReserve((void *)(bytes).data, &(bytes).capacity, (bytes).count, (int64_t)(right).length, sizeof(*(bytes).data));
if (value_11 != NULL) {
(bytes).data = (uint8_t *)value_11;
memcpy((bytes).data + (bytes).count, (right).data, (size_t)(right).length);
(bytes).count += (int64_t)(right).length;
value_10 = true;
}
}
if (!value_10) {
free((bytes).data);
(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};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_12;
}
Slice value_13 = {(bytes).data, (bytes).count};
Slice value_14 = SliceRange(value_13, 0LL, bytes.count, sizeof(*(bytes).data));
String result = vec_TextDetach(vec_TextCopy(StringView((const char *)(value_14).data, (size_t)(value_14).length)));
free((bytes).data);
(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};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_15;
}
zir_8a167d86ad221008_Results__string__bool
compiler_backend_process_PathSuffix(String value, String suffix)
{
__type_838711075b90279a bytes = {0};
__type_838711075b90279a* value_2 = &bytes;
bool value_3 = false;
if ((value).length == 0) {
value_3 = true;
} else {
void *value_4 = ZirVecReserve((void *)(bytes).data, &(bytes).capacity, (bytes).count, (int64_t)(value).length, sizeof(*(bytes).data));
if (value_4 != NULL) {
(bytes).data = (uint8_t *)value_4;
memcpy((bytes).data + (bytes).count, (value).data, (size_t)(value).length);
(bytes).count += (int64_t)(value).length;
value_3 = true;
}
}
bool value_5 = !value_3;
if (!value_5) {
bool value_6 = false;
if ((suffix).length == 0) {
value_6 = true;
} else {
void *value_7 = ZirVecReserve((void *)(bytes).data, &(bytes).capacity, (bytes).count, (int64_t)(suffix).length, sizeof(*(bytes).data));
if (value_7 != NULL) {
(bytes).data = (uint8_t *)value_7;
memcpy((bytes).data + (bytes).count, (suffix).data, (size_t)(suffix).length);
(bytes).count += (int64_t)(suffix).length;
value_6 = true;
}
}
value_5 = !value_6;
}
if (value_5) {
free((bytes).data);
(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};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_8;
}
Slice value_9 = {(bytes).data, (bytes).count};
Slice value_10 = SliceRange(value_9, 0LL, bytes.count, sizeof(*(bytes).data));
String result = vec_TextDetach(vec_TextCopy(StringView((const char *)(value_10).data, (size_t)(value_10).length)));
free((bytes).data);
(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};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_11;
}
void
compiler_backend_process_ReleaseOwnedText(String value)
{
if ((int64_t)(value).length == 0LL) {
return;
}
OwnedText* descriptor = (OwnedText*)(&(value));
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(descriptor->data));
}
uint8_t*
compiler_backend_process_AllocateText(String value)
{
void* memory = zir_f_1cd1ecb166af98b1_AllocateRaw(1, (size_t)(((int64_t)((uint64_t)((int64_t)(value).length) + UINT64_C(1)))));
if (memory == ((void *)0)) {
return (void *)0;
}
uint8_t* target = (uint8_t*)(memory);
{
int64_t range_first_5 = 0LL;
int64_t range_last_5 = (int64_t)((uint64_t)((int64_t)(value).length) - UINT64_C(1));
int64_t index = range_first_5;
if (index <= range_last_5) for (;;) {
uint8_t* value_0 = &(target[index]);
(*value_0) = (uint8_t)value.data[index];
if (index == range_last_5) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
uint8_t* value_1 = &(target[(int64_t)(value).length]);
(*value_1) = 0;
return target;
}
String
compiler_backend_process_CText(uint8_t* value)
{
String result = StringLiteral("");
if (value == ((void *)0)) {
return result;
}
int64_t length = 0LL;
while (value[length] != 0) {
length = (int64_t)((uint64_t)length + UINT64_C(1));
}
OwnedText* descriptor = (OwnedText*)(&(result));
uint8_t** value_0 = &(descriptor->data);
(*value_0) = value;
size_t* value_1 = &(descriptor->length);
(*value_1) = (size_t)(length);
return result;
}
void
compiler_backend_process_FreePointers(__type_21092c8252d3dcaa values)
{
__type_21092c8252d3dcaa* value_0 = &values;
{
Slice value_1 = {(values).data, (values).count};
Slice value_2 = SliceRange(value_1, 0LL, values.count, sizeof(*(values).data));
Slice loop_view_0 = value_2;
int64_t loop_count_0 = (int64_t)(loop_view_0).length;
int64_t loop_cursor_0 = 0LL;
while (loop_cursor_0 < loop_count_0) {
int64_t loop_index_0 = loop_cursor_0;
uint8_t* value = ((uint8_t* *)loop_view_0.data)[loop_index_0];
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(value));
loop_cursor_0 = (int64_t)((uint64_t)loop_cursor_0 + UINT64_C(1));
}
}
free((values).data);
(values).data = NULL;
values.capacity = 0;
values.count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
}
bool
compiler_backend_process_PrepareArguments(Slice arguments, __type_21092c8252d3dcaa* pointers)
{
for (int64_t it_index = 0LL; it_index < (int64_t)(arguments).length; it_index++) {
String argument = ((String *)arguments.data)[it_index];
uint8_t* value = compiler_backend_process_AllocateText(argument);
bool value_0 = value == ((void *)0);
bool value_1 = value_0;
if (!value_1) {
uint8_t* value_2 = value;
bool value_3 = false;
void *value_4 = ZirVecGrow((void *)((*(pointers))).data, &((*(pointers))).capacity, ((*(pointers))).count, sizeof(*((*(pointers))).data));
if (value_4 != NULL) {
((*(pointers))).data = (uint8_t* *)value_4;
((*(pointers))).data[((*(pointers))).count++] = value_2;
value_3 = true;
}
value_1 = !value_3;
}
if (value_1) {
return false;
}
}
uint8_t* value_5 = (void *)0;
bool value_6 = false;
void *value_7 = ZirVecGrow((void *)((*(pointers))).data, &((*(pointers))).capacity, ((*(pointers))).count, sizeof(*((*(pointers))).data));
if (value_7 != NULL) {
((*(pointers))).data = (uint8_t* *)value_7;
((*(pointers))).data[((*(pointers))).count++] = value_5;
value_6 = true;
}
return value_6;
}
bool
compiler_backend_process_WordsInto(String value, __type_21092c8252d3dcaa* output)
{
int64_t start = -1LL;
int64_t at = 0LL;
while (at <= (int64_t)(value).length) {
bool space = at == (int64_t)(value).length || (uint8_t)ZIRAN_INDEX(value.data, value.length, at) == 32 || (uint8_t)ZIRAN_INDEX(value.data, value.length, at) == 9;
if (!space && start < 0LL) {
start = at;
}
if (space && start >= 0LL) {
uint8_t* word = compiler_backend_process_AllocateText(StringRange(value, (int64_t)start, (int64_t)at));
bool value_0 = word == ((void *)0);
bool value_1 = value_0;
if (!value_1) {
uint8_t* value_2 = word;
bool value_3 = false;
void *value_4 = ZirVecGrow((void *)((*(output))).data, &((*(output))).capacity, ((*(output))).count, sizeof(*((*(output))).data));
if (value_4 != NULL) {
((*(output))).data = (uint8_t* *)value_4;
((*(output))).data[((*(output))).count++] = value_2;
value_3 = true;
}
value_1 = !value_3;
}
if (value_1) {
return false;
}
start = -1LL;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
return true;
}
bool
compiler_backend_process_EnvironmentWords(String name, __type_21092c8252d3dcaa* output)
{
String value = environment_linux_EnvironmentText(name);
return compiler_backend_process_WordsInto(value, output);
}
bool
compiler_backend_process_AddCArgument(__type_21092c8252d3dcaa* output, String flag, String value)
{
uint8_t* left = compiler_backend_process_AllocateText(flag);
bool value_0 = left == ((void *)0);
bool value_1 = value_0;
if (!value_1) {
uint8_t* value_2 = left;
bool value_3 = false;
void *value_4 = ZirVecGrow((void *)((*(output))).data, &((*(output))).capacity, ((*(output))).count, sizeof(*((*(output))).data));
if (value_4 != NULL) {
((*(output))).data = (uint8_t* *)value_4;
((*(output))).data[((*(output))).count++] = value_2;
value_3 = true;
}
value_1 = !value_3;
}
if (value_1) {
return false;
}
if ((int64_t)(value).length == 0LL) {
return true;
}
uint8_t* right = compiler_backend_process_AllocateText(value);
bool value_5 = right != ((void *)0);
bool value_6 = value_5;
if (value_6) {
uint8_t* value_7 = right;
bool value_8 = false;
void *value_9 = ZirVecGrow((void *)((*(output))).data, &((*(output))).capacity, ((*(output))).count, sizeof(*((*(output))).data));
if (value_9 != NULL) {
((*(output))).data = (uint8_t* *)value_9;
((*(output))).data[((*(output))).count++] = value_7;
value_8 = true;
}
value_6 = value_8;
}
return value_6;
}
bool
compiler_backend_process_AddSource(__type_21092c8252d3dcaa* files, String path)
{
String value_0 = StringLiteral(".c");
bool value_1 = false;
{
String value = path;
String suffix = value_0;
value_1 = (int64_t)(suffix).length <= (int64_t)(value).length && StringEqual(StringRange(value, (int64_t)((int64_t)((uint64_t)((int64_t)(value).length) - (uint64_t)((int64_t)(suffix).length))), (int64_t)(int64_t)(value).length), suffix);
}
if (!value_1) {
return true;
}
{
int64_t range_first_3 = 0LL;
int64_t range_last_3 = (int64_t)((uint64_t)(files->count) - UINT64_C(1));
int64_t index = range_first_3;
if (index <= range_last_3) for (;;) {
if (StringEqual(compiler_backend_process_CText(ZIRAN_VEC_INDEX((*(files)).data, (*(files)).count, index)), path)) {
return true;
}
if (index == range_last_3) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
uint8_t* value = compiler_backend_process_AllocateText(path);
bool value_3 = value != ((void *)0);
bool value_4 = value_3;
if (value_4) {
uint8_t* value_5 = value;
bool value_6 = false;
void *value_7 = ZirVecGrow((void *)((*(files))).data, &((*(files))).capacity, ((*(files))).count, sizeof(*((*(files))).data));
if (value_7 != NULL) {
((*(files))).data = (uint8_t* *)value_7;
((*(files))).data[((*(files))).count++] = value_5;
value_6 = true;
}
value_4 = value_6;
}
return value_4;
}
bool
compiler_backend_process_CompileExecutable(String out, String name, bool threads, bool release)
{
__type_21092c8252d3dcaa files = {0};
__type_21092c8252d3dcaa* value_0 = &files;
__type_21092c8252d3dcaa objects = {0};
__type_21092c8252d3dcaa* value_1 = &objects;
__type_21092c8252d3dcaa base = {0};
__type_21092c8252d3dcaa* value_2 = &base;
__type_21092c8252d3dcaa tail = {0};
__type_21092c8252d3dcaa* value_3 = &tail;
__type_838711075b90279a log = {0};
__type_838711075b90279a* value_4 = &log;
bool ok = false;
(void)ok;
String compiler_name = environment_linux_EnvironmentText(StringLiteral("CC"));
if ((int64_t)(compiler_name).length == 0LL) {
compiler_name = StringLiteral("cc");
}
String flags = environment_linux_EnvironmentText(StringLiteral("CFLAGS"));
if ((int64_t)(flags).length == 0LL) {
String value_5 = StringView(NULL, 0);
if (release) {
value_5 = StringLiteral("-O3 -flto=auto");
} else {
value_5 = StringLiteral("-O3");
}
flags = value_5;
}
bool value_6 = compiler_backend_process_WordsInto(compiler_name, &(base));
bool value_7 = !value_6;
if (!value_7) {
bool value_8 = compiler_backend_process_WordsInto(flags, &(base));
value_7 = !value_8;
}
if (value_7) {
compiler_backend_process_ReleaseBuildValues(&(base), &(tail), &(files), &(objects), &(log));
bool value_9 = false;
free((*value_4).data);
(*value_4).data = NULL;
(*value_4).capacity = 0;
(*value_4).count = 0;
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_9;
}
bool forced_language = false;
{
Slice value_10 = {(base).data, (base).count};
Slice value_11 = SliceRange(value_10, 0LL, base.count, sizeof(*(base).data));
Slice loop_view_19 = value_11;
int64_t loop_count_19 = (int64_t)(loop_view_19).length;
int64_t loop_cursor_19 = 0LL;
while (loop_cursor_19 < loop_count_19) {
int64_t loop_index_19 = loop_cursor_19;
uint8_t* argument = ((uint8_t* *)loop_view_19.data)[loop_index_19];
if (compiler_backend_process_TextContains(compiler_backend_process_CText(argument), StringLiteral("-x"))) {
forced_language = true;
}
loop_cursor_19 = (int64_t)((uint64_t)loop_cursor_19 + UINT64_C(1));
}
}
String compiler = compiler_backend_process_CText(ZIRAN_VEC_INDEX((base).data, (base).count, 0));
String tool = compiler_backend_process_PathName(compiler);
bool value_12 = compiler_backend_process_TextContains(tool, StringLiteral("gcc"));
bool value_13 = value_12 || compiler_backend_process_TextContains(tool, StringLiteral("clang"));
bool value_14 = value_13 || StringEqual(tool, StringLiteral("cc"));
bool value_15 = value_14;
if (value_15) {
bool value_16 = compiler_backend_process_TextContains(tool, StringLiteral("tcc"));
value_15 = !value_16;
}
if (value_15) {
bool value_17 = compiler_backend_process_AddCArgument(&(base), StringLiteral("-Wno-psabi"), StringLiteral(""));
if (!value_17) {
compiler_backend_process_ReleaseBuildValues(&(base), &(tail), &(files), &(objects), &(log));
bool value_18 = false;
free((*value_4).data);
(*value_4).data = NULL;
(*value_4).capacity = 0;
(*value_4).count = 0;
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_18;
}
}
String value_19 = StringLiteral("LDFLAGS");
__type_21092c8252d3dcaa* value_20 = &(tail);
bool value_21 = false;
{
String name = value_19;
__type_21092c8252d3dcaa* output = value_20;
String value = environment_linux_EnvironmentText(name);
value_21 = compiler_backend_process_WordsInto(value, output);
}
bool value_23 = !value_21;
if (!value_23) {
String value_24 = StringLiteral("LDLIBS");
__type_21092c8252d3dcaa* value_25 = &(tail);
bool value_26 = false;
{
String name = value_24;
__type_21092c8252d3dcaa* output = value_25;
String value = environment_linux_EnvironmentText(name);
value_26 = compiler_backend_process_WordsInto(value, output);
}
value_23 = !value_26;
}
if (value_23) {
compiler_backend_process_ReleaseBuildValues(&(base), &(tail), &(files), &(objects), &(log));
bool value_28 = false;
free((*value_4).data);
(*value_4).data = NULL;
(*value_4).capacity = 0;
(*value_4).count = 0;
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_28;
}
bool value_29 = compiler_backend_process_AddCArgument(&(base), StringLiteral("-I"), out);
if (!value_29) {
compiler_backend_process_ReleaseBuildValues(&(base), &(tail), &(files), &(objects), &(log));
bool value_30 = false;
free((*value_4).data);
(*value_4).data = NULL;
(*value_4).capacity = 0;
(*value_4).count = 0;
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_30;
}
bool value_31 = threads;
bool value_32 = value_31;
if (value_32) {
bool value_33 = compiler_backend_process_AddCArgument(&(base), StringLiteral("-pthread"), StringLiteral(""));
value_32 = !value_33;
}
if (value_32) {
compiler_backend_process_ReleaseBuildValues(&(base), &(tail), &(files), &(objects), &(log));
bool value_34 = false;
free((*value_4).data);
(*value_4).data = NULL;
(*value_4).capacity = 0;
(*value_4).count = 0;
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_34;
}
uint8_t* include = zir_f_1cd1ecb166af98b1_ToolchainIncludeDirectory();
bool value_35 = include != ((void *)0);
bool value_36 = value_35;
if (value_36) {
bool value_37 = compiler_backend_process_AddCArgument(&(base), StringLiteral("-I"), compiler_backend_process_CText(include));
value_36 = !value_37;
}
if (value_36) {
compiler_backend_process_ReleaseBuildValues(&(base), &(tail), &(files), &(objects), &(log));
bool value_38 = false;
free((*value_4).data);
(*value_4).data = NULL;
(*value_4).capacity = 0;
(*value_4).count = 0;
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_38;
}
bool value_39 = compiler_backend_process_FinishCompile(out, name, forced_language, &(base), &(tail), &(files), &(objects), &(log));
free((*value_4).data);
(*value_4).data = NULL;
(*value_4).capacity = 0;
(*value_4).count = 0;
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_39;
}
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)
{
int64_t index = 0LL;
bool added = false;
while (true) {
uint8_t* generated = zir_f_1cd1ecb166af98b1_GeneratedOutputPath(index);
if (generated == ((void *)0)) {
break;
}
added = compiler_backend_process_AddSource(files, compiler_backend_process_CText(generated));
if (!added) {
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
return false;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
DirectoryCursor cursor = OpenDirectory(out);
if (!cursor.valid) {
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
return false;
}
bool listed = true;
while (true) {
DirectoryEntry entry = NextDirectoryEntry(&(cursor));
if (!entry.valid) {
break;
}
uint8_t* value_2 = &(entry.name[0]);
int64_t value_3 = (int64_t)(entry.name_count);
String value_4 = StringView(NULL, 0);
{
uint8_t* value = value_2;
int64_t length = value_3;
String result = StringLiteral("");
if (value == ((void *)0)) {
value_4 = result;
goto value_5;
}
OwnedText* descriptor = (OwnedText*)(&(result));
uint8_t** value_6 = &(descriptor->data);
(*value_6) = value;
size_t* value_7 = &(descriptor->length);
(*value_7) = (size_t)(length);
value_4 = result;
value_5: ;
}
String entry_name = value_4;
zir_8a167d86ad221008_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) {
listed = false;
break;
}
added = compiler_backend_process_AddSource(files, path);
compiler_backend_process_ReleaseOwnedText(path);
if (!added) {
listed = false;
break;
}
}
CloseDirectory(&(cursor));
bool value_8 = !listed;
if (!value_8) {
int64_t value_9 = files->count;
value_8 = (value_9 == 0LL);
}
if (value_8) {
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
return false;
}
compiler_backend_process_SortPaths(files);
zir_8a167d86ad221008_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) {
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
return false;
}
bool created = CreateDirectory(object_directory);
compiler_backend_process_ReleaseOwnedText(object_directory);
if (!created) {
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
return false;
}
{
int64_t range_first_59 = 0LL;
int64_t range_last_59 = (int64_t)((uint64_t)(files->count) - UINT64_C(1));
int64_t index = range_first_59;
if (index <= range_last_59) for (;;) {
String source = compiler_backend_process_CText(ZIRAN_VEC_INDEX((*(files)).data, (*(files)).count, index));
bool value_10 = false;
{
String value = source;
String prefix = out;
value_10 = (int64_t)(prefix).length <= (int64_t)(value).length && StringEqual(StringRange(value, (int64_t)0LL, (int64_t)(int64_t)(prefix).length), prefix);
}
if (!value_10 || (int64_t)(source).length <= (int64_t)(out).length || (uint8_t)ZIRAN_INDEX(source.data, source.length, (int64_t)(out).length) != 47) {
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
return false;
}
String relative = StringRange(source, (int64_t)((int64_t)((uint64_t)((int64_t)(out).length) + UINT64_C(1))), (int64_t)(int64_t)(source).length);
Results__pu8__bool results_4_ = compiler_backend_process_ObjectPath(out, relative);
uint8_t* object = results_4_.value_0;
bool object_ok = results_4_.value_1;
if (!object_ok || object == ((void *)0)) {
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
return false;
}
uint8_t* value_12 = object;
bool value_13 = false;
void *value_14 = ZirVecGrow((void *)((*(objects))).data, &((*(objects))).capacity, ((*(objects))).count, sizeof(*((*(objects))).data));
if (value_14 != NULL) {
((*(objects))).data = (uint8_t* *)value_14;
((*(objects))).data[((*(objects))).count++] = value_12;
value_13 = true;
}
if (!value_13) {
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(object));
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
return false;
}
uint8_t* parent = object;
String directory_name = file_tree_linux_PathParent(compiler_backend_process_CText(parent));
bool value_15 = compiler_backend_process_CreateDirectories(directory_name);
if (!value_15) {
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
return false;
}
if (index == range_last_59) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
return compiler_backend_process_CompileAndLink(out, name, forced_language, base, tail, files, objects, log);
}
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"));
String root = results_5_.value_0;
bool root_ok = results_5_.value_1;
if (!root_ok) {
return (Results__pu8__bool){.value_0 = (void *)0, .value_1 = false};
}
String relative_object = compiler_backend_cache_JoinTemporary(relative, StringLiteral(".o"));
if ((int64_t)(relative_object).length == 0LL) {
Results__pu8__bool cleanup_return_0 = {.value_0 = (void *)0, .value_1 = false};
{
compiler_backend_process_ReleaseOwnedText(root);
}
return cleanup_return_0;
}
zir_8a167d86ad221008_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) {
Results__pu8__bool cleanup_return_1 = {.value_0 = (void *)0, .value_1 = false};
{
compiler_backend_process_ReleaseOwnedText(relative_object);
}
{
compiler_backend_process_ReleaseOwnedText(root);
}
return cleanup_return_1;
}
uint8_t* result = compiler_backend_process_AllocateText(joined);
compiler_backend_process_ReleaseOwnedText(joined);
Results__pu8__bool cleanup_return_2 = {.value_0 = result, .value_1 = result != ((void *)0)};
{
compiler_backend_process_ReleaseOwnedText(relative_object);
}
{
compiler_backend_process_ReleaseOwnedText(root);
}
return cleanup_return_2;
}
void
compiler_backend_process_SortPaths(__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));
}
}
}
bool
compiler_backend_process_PathBefore(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;
}
void
compiler_backend_process_ReapJob(Job* job)
{
if (job->finished || job->process < 0) {
return;
}
int32_t status = 0;
int32_t waited = zir_f_1cd1ecb166af98b1_WaitRaw(job->process, &(status), 1);
if (waited == job->process) {
Job* value_0 = job;
int32_t value_1 = status;
{
Job* job = value_0;
int32_t status = value_1;
bool* value_3 = &(job->finished);
(*value_3) = true;
bool* value_4 = &(job->ok);
bool value_5 = ((int32_t)((uint32_t)status & 127u)) == 0 && ((int32_t)((uint32_t)((ZiShrS32(status, (uint64_t)(8), 32))) & 255u)) == 0;
(*value_4) = value_5;
}
} else if (waited < 0 && compiler_backend_process_ErrnoValue() != 4) {
bool* value_6 = &(job->finished);
(*value_6) = true;
bool* value_7 = &(job->ok);
(*value_7) = false;
}
}
void
compiler_backend_process_StoreJob(Job* target, Job value)
{
int32_t* value_0 = &(target->process);
(*value_0) = value.process;
int32_t* value_1 = &(target->descriptor);
(*value_1) = value.descriptor;
bool* value_2 = &(target->finished);
(*value_2) = value.finished;
bool* value_3 = &(target->ok);
(*value_3) = value.ok;
__type_838711075b90279a value_4 = target->output;
target->output = value.output;
value.output = value_4;
free((value).output.data);
(value).output.data = NULL;
(value).output.capacity = 0;
(value).output.count = 0;
}
void
compiler_backend_process_PollSlots(Slice jobs, Slice slots, bool* failed)
{
PollRecord pollers[16] = {0};
int64_t numbered[16] = {0};
int64_t count = 0LL;
bool finished = false;
bool unreaped = false;
{
int64_t range_first_5 = 0LL;
int64_t range_last_5 = 15LL;
int64_t slot = range_first_5;
if (slot <= range_last_5) for (;;) {
if (!(((SlotOutput *)slots.data)[SliceIndex(slots, (int64_t)slot)]).running) {
if (slot == range_last_5) {
break;
}
slot = (int64_t)((uint64_t)slot + UINT64_C(1));
continue;
}
if ((((Job *)jobs.data)[SliceIndex(jobs, (int64_t)slot)]).descriptor >= 0) {
PollRecord* value_0 = &(ZIRAN_INDEX(pollers, sizeof(pollers) / sizeof(pollers[0]), count));
(*value_0) = (PollRecord){.descriptor = (((Job *)jobs.data)[SliceIndex(jobs, (int64_t)slot)]).descriptor, .events = 1, .revents = 0};
int64_t* value_1 = &(ZIRAN_INDEX(numbered, sizeof(numbered) / sizeof(numbered[0]), count));
(*value_1) = slot;
count = (int64_t)((uint64_t)count + UINT64_C(1));
} else {
compiler_backend_process_ReapJob(&(((Job *)jobs.data)[SliceIndex(jobs, (int64_t)slot)]));
if ((((Job *)jobs.data)[SliceIndex(jobs, (int64_t)slot)]).finished) {
finished = true;
} else {
unreaped = true;
}
}
if (slot == range_last_5) {
break;
}
slot = (int64_t)((uint64_t)slot + UINT64_C(1));
}
}
if (finished) {
return;
}
if (count > 0LL) {
int32_t value_2 = 0;
if (unreaped) {
value_2 = 1;
} else {
value_2 = -1;
}
int32_t ready = zir_f_1cd1ecb166af98b1_PollRaw(&(pollers[0]), (uint64_t)(count), value_2);
if (ready < 0 && compiler_backend_process_ErrnoValue() != 4) {
bool* value_3 = &((*(failed)));
(*value_3) = true;
}
{
int64_t range_first_32 = 0LL;
int64_t range_last_32 = (int64_t)((uint64_t)count - UINT64_C(1));
int64_t index = range_first_32;
if (index <= range_last_32) for (;;) {
int64_t slot = ZIRAN_INDEX(numbered, 16, index);
if ((ZIRAN_INDEX(pollers, sizeof(pollers) / sizeof(pollers[0]), index)).revents == 0 || !(((SlotOutput *)slots.data)[SliceIndex(slots, (int64_t)slot)]).running) {
if (index == range_last_32) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
continue;
}
bool value_4 = compiler_backend_process_ReadJobOutput(&(((Job *)jobs.data)[SliceIndex(jobs, (int64_t)slot)]));
if (!value_4) {
bool* value_5 = &((*(failed)));
(*value_5) = true;
compiler_backend_process_ReapJob(&(((Job *)jobs.data)[SliceIndex(jobs, (int64_t)slot)]));
} else {
compiler_backend_process_ReapJob(&(((Job *)jobs.data)[SliceIndex(jobs, (int64_t)slot)]));
}
if (index == range_last_32) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
} else {
SleepMilliseconds(1LL);
}
}
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 base_text = compiler_backend_process_PointerTexts(base);
__type_c53c2d7c4913dc02* value_2 = &base_text;
Slice value_3 = {(base_text).data, (base_text).count};
bool requested_pipe = compiler_backend_cache_RequestedPipe(SliceRange(value_3, 0LL, base_text.count, sizeof(*(base_text).data)));
Slice value_4 = {(base_text).data, (base_text).count};
BuildCache* cache = compiler_backend_cache_Open(SliceRange(value_4, 0LL, base_text.count, sizeof(*(base_text).data)), out, name);
free((base_text).data);
(base_text).data = NULL;
base_text.capacity = 0;
base_text.count = 0;
int32_t workers = compiler_backend_process_WorkerLimit();
int64_t value_5 = (int64_t)(workers);
int64_t value_6 = files->count;
if (value_5 > value_6) {
workers = (int32_t)(files->count);
}
{
int32_t range_first_8 = 0;
int32_t range_last_8 = (int32_t)((uint32_t)workers - 1u);
int32_t slot = range_first_8;
if (slot <= range_last_8) for (;;) {
compiler_backend_process_ProfileCount(StringLiteral("native_worker_slots"));
if (slot == range_last_8) {
break;
}
slot = (int32_t)((uint32_t)slot + 1u);
}
}
uint64_t identity_started = zir_f_1cd1ecb166af98b1_ProfileStart();
compiler_backend_process_ProfileEnd(StringLiteral("native.toolchain"), identity_started);
uint64_t objects_started = zir_f_1cd1ecb166af98b1_ProfileStart();
__type_6f55d821d15c8cbf outputs = {0};
__type_6f55d821d15c8cbf* value_7 = &outputs;
bool outputs_ready = true;
bool capture = zir_f_1cd1ecb166af98b1_DiagnosticJsonEnabled() != 0;
bool compile_ok = true;
SlotOutput slots[16] = {0};
Job jobs[16] = {0};
{
int64_t range_first_20 = 0LL;
int64_t range_last_20 = 15LL;
int64_t index = range_first_20;
if (index <= range_last_20) for (;;) {
int64_t* value_8 = &((slots[index]).file);
(*value_8) = -1LL;
bool* value_9 = &((slots[index]).running);
(*value_9) = false;
int32_t* value_10 = &((jobs[index]).process);
(*value_10) = -1;
int32_t* value_11 = &((jobs[index]).descriptor);
(*value_11) = -1;
if (index == range_last_20) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
int64_t next_file = 0LL;
int64_t running = 0LL;
if (capture) {
int64_t value_13 = files->count;
bool value_14 = false;
if (value_13 >= 0) {
value_14 = value_13 <= (outputs).capacity;
if (!value_14) {
void *value_15 = ZirVecReserve((void *)(outputs).data, &(outputs).capacity, (outputs).count, value_13 - (outputs).count, sizeof(*(outputs).data));
if (value_15 != NULL) { (outputs).data = (PendingOutput *)value_15; value_14 = true; }
}
if (value_14) {
for (int64_t value_16 = value_13; value_16 < (outputs).count; ++value_16) {
free(((outputs).data[value_16]).output.data);
((outputs).data[value_16]).output.data = NULL;
((outputs).data[value_16]).output.capacity = 0;
((outputs).data[value_16]).output.count = 0;
}
if (value_13 > (outputs).count) memset((outputs).data + (outputs).count, 0, (size_t)(value_13 - (outputs).count) * sizeof(*(outputs).data));
(outputs).count = value_13;
}
}
outputs_ready = value_14;
}
if (!outputs_ready) {
compile_ok = false;
}
while (true) {
bool value_17 = running > 0LL;
if (!value_17) {
bool value_18 = compile_ok;
if (value_18) {
int64_t value_19 = files->count;
value_18 = (next_file < value_19);
}
value_17 = value_18;
}
if (!value_17) { break; }
{
int64_t range_first_35 = 0LL;
int64_t range_last_35 = (int64_t)((uint64_t)(workers) - UINT64_C(1));
int64_t slot = range_first_35;
if (slot <= range_last_35) for (;;) {
bool value_20 = !compile_ok;
if (!value_20) {
int64_t value_21 = files->count;
value_20 = (next_file >= value_21);
}
bool value_22 = value_20;
if (!value_22) {
int64_t value_23 = (ZIRAN_INDEX(slots, sizeof(slots) / sizeof(slots[0]), slot)).file;
value_22 = (value_23 >= 0LL);
}
if (value_22) {
if (slot == range_last_35) {
break;
}
slot = (int64_t)((uint64_t)slot + UINT64_C(1));
continue;
}
while (true) {
int64_t value_24 = files->count;
bool value_25 = next_file < value_24;
if (!(value_25 && compiler_backend_cache_Hit(cache, compiler_backend_process_CText(ZIRAN_VEC_INDEX((*(objects)).data, (*(objects)).count, next_file))))) { break; }
compiler_backend_process_ProfileCount(StringLiteral("native_object_reuse"));
next_file = (int64_t)((uint64_t)next_file + UINT64_C(1));
}
int64_t value_26 = files->count;
if (next_file >= value_26) {
break;
}
int64_t index = next_file;
next_file = (int64_t)((uint64_t)next_file + UINT64_C(1));
compiler_backend_process_ProfileCount(StringLiteral("native_object_compile"));
__type_c53c2d7c4913dc02 arguments = compiler_backend_process_CloneTexts(base);
__type_c53c2d7c4913dc02* value_27 = &arguments;
bool value_28 = compiler_backend_cache_Piped(cache);
bool piped = value_28 && !requested_pipe;
bool added = false;
bool started = false;
if (piped) {
added = compiler_backend_process_AddTextArgument(&(arguments), StringLiteral("-pipe"), StringLiteral(""));
if (added) {
compiler_backend_process_ProfileCount(StringLiteral("native_object_pipe"));
}
} else {
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"));
String dependency = results_7_.value_0;
bool dependency_ok = results_7_.value_1;
if (dependency_ok) {
RemoveFile(dependency);
if (cache != ((void *)0)) {
__type_c53c2d7c4913dc02* value_29 = &(arguments);
String value_30 = dependency;
bool value_31 = false;
{
__type_c53c2d7c4913dc02* arguments = value_29;
String dependency = value_30;
bool value_33 = compiler_backend_process_AddTextArgument(arguments, StringLiteral("-MD"), StringLiteral(""));
if (!value_33) {
value_31 = false;
goto value_32;
}
bool value_34 = compiler_backend_process_AddTextArgument(arguments, StringLiteral("-MF"), dependency);
if (!value_34) {
value_31 = false;
goto value_32;
}
value_31 = compiler_backend_process_AddTextArgument(arguments, StringLiteral("-MT"), StringLiteral("ziran-cache"));
value_32: ;
}
(void)value_31;
compiler_backend_process_ReleaseOwnedText(dependency);
} else {
compiler_backend_process_ReleaseOwnedText(dependency);
}
}
if (added) {
__type_c53c2d7c4913dc02* value_35 = &(arguments);
String value_36 = compiler_backend_process_CText(ZIRAN_VEC_INDEX((*(files)).data, (*(files)).count, index));
String value_37 = object;
bool value_38 = false;
{
__type_c53c2d7c4913dc02* arguments = value_35;
String source = value_36;
String object = value_37;
bool value_40 = compiler_backend_process_AddTextArgument(arguments, StringLiteral("-c"), StringLiteral(""));
if (!value_40) {
value_38 = false;
goto value_39;
}
bool value_41 = compiler_backend_process_AddTextArgument(arguments, source, StringLiteral(""));
if (!value_41) {
value_38 = false;
goto value_39;
}
bool value_42 = compiler_backend_process_AddTextArgument(arguments, StringLiteral("-o"), StringLiteral(""));
if (!value_42) {
value_38 = false;
goto value_39;
}
value_38 = compiler_backend_process_AddTextArgument(arguments, object, StringLiteral(""));
value_39: ;
}
added = value_38;
}
if (added) {
zir_8a167d86ad221008_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) {
RemoveFile(inputs);
compiler_backend_process_ReleaseOwnedText(inputs);
} else {
added = false;
}
}
if (added) {
RemoveFile(object);
Slice value_43 = {(arguments).data, (arguments).count};
Job job = compiler_backend_process_StartJob(SliceRange(value_43, 0LL, arguments.count, sizeof(*(arguments).data)), capture, true);
Job value_44 = job;
(job).output.data = NULL;
(job).output.capacity = 0;
(job).output.count = 0;
compiler_backend_process_StoreJob(&(ZIRAN_INDEX(jobs, sizeof(jobs) / sizeof(jobs[0]), slot)), value_44);
if ((ZIRAN_INDEX(jobs, sizeof(jobs) / sizeof(jobs[0]), slot)).process >= 0) {
int64_t* value_45 = &((ZIRAN_INDEX(slots, sizeof(slots) / sizeof(slots[0]), slot)).file);
(*value_45) = index;
bool* value_46 = &((ZIRAN_INDEX(slots, sizeof(slots) / sizeof(slots[0]), slot)).running);
(*value_46) = true;
running = (int64_t)((uint64_t)running + UINT64_C(1));
started = true;
}
free((job).output.data);
(job).output.data = NULL;
(job).output.capacity = 0;
(job).output.count = 0;
}
compiler_backend_process_FreeArguments(&(arguments));
if (!added || !started) {
compile_ok = false;
free((*value_27).data);
(*value_27).data = NULL;
(*value_27).capacity = 0;
(*value_27).count = 0;
break;
}
if (slot == range_last_35) {
free((*value_27).data);
(*value_27).data = NULL;
(*value_27).capacity = 0;
(*value_27).count = 0;
break;
}
slot = (int64_t)((uint64_t)slot + UINT64_C(1));
free((*value_27).data);
(*value_27).data = NULL;
(*value_27).capacity = 0;
(*value_27).count = 0;
}
}
if (running == 0LL) {
break;
}
bool poll_failed = false;
Slice value_47 = {jobs, 16};
Slice value_48 = {slots, 16};
compiler_backend_process_PollSlots(value_47, value_48, &(poll_failed));
if (poll_failed) {
compile_ok = false;
}
{
int64_t range_first_116 = 0LL;
int64_t range_last_116 = 15LL;
int64_t slot = range_first_116;
if (slot <= range_last_116) for (;;) {
if (!(slots[slot]).running) {
if (slot == range_last_116) {
break;
}
slot = (int64_t)((uint64_t)slot + UINT64_C(1));
continue;
}
bool finished = (jobs[slot]).finished;
if (finished && !(jobs[slot]).ok) {
compile_ok = false;
}
String object = StringLiteral("");
if (finished) {
object = compiler_backend_process_CText(ZIRAN_VEC_INDEX((*(objects)).data, (*(objects)).count, (slots[slot]).file));
PathInfo info = file_tree_linux_PathStatus(object, false);
if ((jobs[slot]).ok && (!info.identity_valid || ((PathKind)(info.kind)) != ((PathKind)(1)) || info.size <= 0LL)) {
bool* value_49 = &((jobs[slot]).ok);
(*value_49) = false;
compile_ok = false;
}
if ((jobs[slot]).ok && cache != ((void *)0)) {
uint64_t record_started = zir_f_1cd1ecb166af98b1_ProfileStart();
compiler_backend_cache_Record(cache, object, compiler_backend_process_CText(ZIRAN_VEC_INDEX((*(files)).data, (*(files)).count, (slots[slot]).file)));
compiler_backend_process_ProfileEnd(StringLiteral("native.cache.record"), record_started);
}
}
if (finished) {
if (capture && outputs_ready) {
PendingOutput* saved = &(ZIRAN_VEC_INDEX((outputs).data, (outputs).count, (slots[slot]).file));
__type_838711075b90279a value_50 = saved->output;
saved->output = (jobs[slot]).output;
(jobs[slot]).output = value_50;
}
Job* job = &(jobs[slot]);
compiler_backend_process_FreeJob(job);
int64_t* value_51 = &((slots[slot]).file);
(*value_51) = -1LL;
bool* value_52 = &((slots[slot]).running);
(*value_52) = false;
running = (int64_t)((uint64_t)running - UINT64_C(1));
}
if (slot == range_last_116) {
break;
}
slot = (int64_t)((uint64_t)slot + UINT64_C(1));
}
}
}
if (capture && outputs_ready) {
{
int64_t range_first_152 = 0LL;
int64_t range_last_152 = (int64_t)((uint64_t)(files->count) - UINT64_C(1));
int64_t index = range_first_152;
if (index <= range_last_152) for (;;) {
PendingOutput* saved = &(ZIRAN_VEC_INDEX((outputs).data, (outputs).count, index));
int64_t value_53 = saved->output.count;
if (value_53 > 0LL) {
Slice value_54 = {(saved->output).data, (saved->output).count};
compiler_backend_process_AppendLog(log, SliceRange(value_54, 0LL, saved->output.count, sizeof(*(saved->output).data)));
}
free((saved->output).data);
(saved->output).data = NULL;
saved->output.capacity = 0;
saved->output.count = 0;
if (index == range_last_152) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
}
for (int64_t value_55 = 0; value_55 < (outputs).count; ++value_55) {
free(((outputs).data[value_55]).output.data);
((outputs).data[value_55]).output.data = NULL;
((outputs).data[value_55]).output.capacity = 0;
((outputs).data[value_55]).output.count = 0;
}
free((outputs).data);
(outputs).data = NULL;
outputs.capacity = 0;
outputs.count = 0;
compiler_backend_process_ProfileEnd(StringLiteral("native.objects"), objects_started);
{
int64_t range_first_162 = 0LL;
int64_t range_last_162 = 15LL;
int64_t slot = range_first_162;
if (slot <= range_last_162) for (;;) {
int64_t value_56 = (slots[slot]).file;
if (value_56 >= 0LL) {
Job* job = &(jobs[slot]);
compiler_backend_process_FreeJob(job);
}
int64_t* value_57 = &((slots[slot]).file);
(*value_57) = -1LL;
bool* value_58 = &((slots[slot]).running);
(*value_58) = false;
if (slot == range_last_162) {
break;
}
slot = (int64_t)((uint64_t)slot + UINT64_C(1));
}
}
if (!compile_ok) {
compiler_backend_cache_Close(cache);
compiler_backend_process_ReportToolchain(out, log, false);
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
bool value_59 = false;
for (size_t value_60 = 0; value_60 < sizeof(jobs) / sizeof((jobs)[0]); ++value_60) {
free(((jobs)[value_60]).output.data);
((jobs)[value_60]).output.data = NULL;
((jobs)[value_60]).output.capacity = 0;
((jobs)[value_60]).output.count = 0;
}
for (int64_t value_61 = 0; value_61 < ((*value_7)).count; ++value_61) {
free((((*value_7)).data[value_61]).output.data);
(((*value_7)).data[value_61]).output.data = NULL;
(((*value_7)).data[value_61]).output.capacity = 0;
(((*value_7)).data[value_61]).output.count = 0;
}
free((*value_7).data);
(*value_7).data = NULL;
(*value_7).capacity = 0;
(*value_7).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_59;
}
bool value_62 = compiler_backend_process_LinkOwnedObjects(out, name, forced_language, base, tail, files, objects, log, cache);
for (size_t value_63 = 0; value_63 < sizeof(jobs) / sizeof((jobs)[0]); ++value_63) {
free(((jobs)[value_63]).output.data);
((jobs)[value_63]).output.data = NULL;
((jobs)[value_63]).output.capacity = 0;
((jobs)[value_63]).output.count = 0;
}
for (int64_t value_64 = 0; value_64 < ((*value_7)).count; ++value_64) {
free((((*value_7)).data[value_64]).output.data);
(((*value_7)).data[value_64]).output.data = NULL;
(((*value_7)).data[value_64]).output.capacity = 0;
(((*value_7)).data[value_64]).output.count = 0;
}
free((*value_7).data);
(*value_7).data = NULL;
(*value_7).capacity = 0;
(*value_7).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_62;
}
__type_c53c2d7c4913dc02
compiler_backend_process_PointerTexts(__type_21092c8252d3dcaa* source)
{
__type_21092c8252d3dcaa values = {0};
__type_21092c8252d3dcaa* value_0 = &values;
__type_21092c8252d3dcaa value_1 = values;
values = (*(source));
(*(source)) = value_1;
__type_c53c2d7c4913dc02 result = {0};
__type_c53c2d7c4913dc02* value_2 = &result;
for (int64_t it_index = 0LL; it_index < values.count; it_index++) {
uint8_t* value = ZIRAN_VEC_INDEX((values).data, (values).count, it_index);
String value_3 = compiler_backend_process_CText(value);
String value_4 = value_3;
bool value_5 = false;
void *value_6 = ZirVecGrow((void *)(result).data, &(result).capacity, (result).count, sizeof(*(result).data));
if (value_6 != NULL) {
(result).data = (String *)value_6;
(result).data[(result).count++] = value_4;
value_5 = true;
}
(void)value_5;
}
__type_21092c8252d3dcaa value_7 = values;
values = (*(source));
(*(source)) = value_7;
__type_c53c2d7c4913dc02 value_8 = result;
result.data = NULL;
result.capacity = 0;
result.count = 0;
__type_c53c2d7c4913dc02 value_9 = value_8;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_9;
}
__type_c53c2d7c4913dc02
compiler_backend_process_CloneTexts(__type_21092c8252d3dcaa* source)
{
__type_21092c8252d3dcaa values = {0};
__type_21092c8252d3dcaa* value_0 = &values;
__type_21092c8252d3dcaa value_1 = values;
values = (*(source));
(*(source)) = value_1;
__type_c53c2d7c4913dc02 result = {0};
__type_c53c2d7c4913dc02* value_2 = &result;
for (int64_t it_index = 0LL; it_index < values.count; it_index++) {
uint8_t* value = ZIRAN_VEC_INDEX((values).data, (values).count, it_index);
uint8_t* owned_text = compiler_backend_process_AllocateText(compiler_backend_process_CText(value));
bool value_3 = owned_text == ((void *)0);
bool value_4 = value_3;
if (!value_4) {
String value_5 = compiler_backend_process_CText(owned_text);
String value_6 = value_5;
bool value_7 = false;
void *value_8 = ZirVecGrow((void *)(result).data, &(result).capacity, (result).count, sizeof(*(result).data));
if (value_8 != NULL) {
(result).data = (String *)value_8;
(result).data[(result).count++] = value_6;
value_7 = true;
}
value_4 = !value_7;
}
if (value_4) {
if (owned_text != ((void *)0)) {
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(owned_text));
}
compiler_backend_process_FreeArguments(&(result));
__type_c53c2d7c4913dc02 value_9 = (__type_c53c2d7c4913dc02){0};
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_9;
}
}
__type_21092c8252d3dcaa value_10 = values;
values = (*(source));
(*(source)) = value_10;
__type_c53c2d7c4913dc02 value_11 = result;
result.data = NULL;
result.capacity = 0;
result.count = 0;
__type_c53c2d7c4913dc02 value_12 = value_11;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_12;
}
void
compiler_backend_process_FreeArguments(__type_c53c2d7c4913dc02* values)
{
__type_c53c2d7c4913dc02 owned = {0};
__type_c53c2d7c4913dc02* value_0 = &owned;
__type_c53c2d7c4913dc02 value_1 = owned;
owned = (*(values));
(*(values)) = value_1;
for (int64_t it_index = 0LL; it_index < owned.count; it_index++) {
String value = ZIRAN_VEC_INDEX((owned).data, (owned).count, it_index);
compiler_backend_process_ReleaseOwnedText(value);
}
free((owned).data);
(owned).data = NULL;
owned.capacity = 0;
owned.count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
}
bool
compiler_backend_process_AddDependencyArguments(__type_c53c2d7c4913dc02* arguments, String dependency)
{
bool value_0 = compiler_backend_process_AddTextArgument(arguments, StringLiteral("-MD"), StringLiteral(""));
if (!value_0) {
return false;
}
bool value_1 = compiler_backend_process_AddTextArgument(arguments, StringLiteral("-MF"), dependency);
if (!value_1) {
return false;
}
return compiler_backend_process_AddTextArgument(arguments, StringLiteral("-MT"), StringLiteral("ziran-cache"));
}
bool
compiler_backend_process_AddObjectArguments(__type_c53c2d7c4913dc02* arguments, String source, String object)
{
bool value_0 = compiler_backend_process_AddTextArgument(arguments, StringLiteral("-c"), StringLiteral(""));
if (!value_0) {
return false;
}
bool value_1 = compiler_backend_process_AddTextArgument(arguments, source, StringLiteral(""));
if (!value_1) {
return false;
}
bool value_2 = compiler_backend_process_AddTextArgument(arguments, StringLiteral("-o"), StringLiteral(""));
if (!value_2) {
return false;
}
return compiler_backend_process_AddTextArgument(arguments, object, StringLiteral(""));
}
bool
compiler_backend_process_AddTextArgument(__type_c53c2d7c4913dc02* output, String flag, String value)
{
uint8_t* left = compiler_backend_process_AllocateText(flag);
if (left == ((void *)0)) {
return false;
}
String value_0 = compiler_backend_process_CText(left);
String value_1 = value_0;
bool value_2 = false;
void *value_3 = ZirVecGrow((void *)((*(output))).data, &((*(output))).capacity, ((*(output))).count, sizeof(*((*(output))).data));
if (value_3 != NULL) {
((*(output))).data = (String *)value_3;
((*(output))).data[((*(output))).count++] = value_1;
value_2 = true;
}
if (!value_2) {
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(left));
return false;
}
if ((int64_t)(value).length == 0LL) {
return true;
}
uint8_t* right = compiler_backend_process_AllocateText(value);
if (right == ((void *)0)) {
return false;
}
String value_4 = compiler_backend_process_CText(right);
String value_5 = value_4;
bool value_6 = false;
void *value_7 = ZirVecGrow((void *)((*(output))).data, &((*(output))).capacity, ((*(output))).count, sizeof(*((*(output))).data));
if (value_7 != NULL) {
((*(output))).data = (String *)value_7;
((*(output))).data[((*(output))).count++] = value_5;
value_6 = true;
}
return value_6;
}
bool
compiler_backend_process_AppendLog(__type_838711075b90279a* log, Slice output)
{
bool value_0 = (int64_t)(output).length == 0LL;
if (!value_0) {
int64_t value_1 = log->count;
value_0 = (value_1 > 4095LL);
}
if (value_0) {
return true;
}
int64_t value_2 = log->count;
if (value_2 > 0LL && ZIRAN_VEC_INDEX((*(log)).data, (*(log)).count, ((int64_t)((uint64_t)(log->count) - UINT64_C(1)))) != 10) {
uint8_t value_3 = 10;
bool value_4 = false;
void *value_5 = ZirVecGrow((void *)((*(log))).data, &((*(log))).capacity, ((*(log))).count, sizeof(*((*(log))).data));
if (value_5 != NULL) {
((*(log))).data = (uint8_t *)value_5;
((*(log))).data[((*(log))).count++] = value_3;
value_4 = true;
}
if (!value_4) {
return false;
}
}
for (int64_t it_index = 0LL; it_index < (int64_t)(output).length; it_index++) {
uint8_t byte = ((uint8_t *)output.data)[it_index];
int64_t value_6 = log->count;
if (value_6 > 4095LL) {
return true;
}
if (byte == 0) {
uint8_t value_7 = 63;
bool value_8 = false;
void *value_9 = ZirVecGrow((void *)((*(log))).data, &((*(log))).capacity, ((*(log))).count, sizeof(*((*(log))).data));
if (value_9 != NULL) {
((*(log))).data = (uint8_t *)value_9;
((*(log))).data[((*(log))).count++] = value_7;
value_8 = true;
}
if (!value_8) {
return false;
}
} else {
uint8_t value_10 = byte;
bool value_11 = false;
void *value_12 = ZirVecGrow((void *)((*(log))).data, &((*(log))).capacity, ((*(log))).count, sizeof(*((*(log))).data));
if (value_12 != NULL) {
((*(log))).data = (uint8_t *)value_12;
((*(log))).data[((*(log))).count++] = value_10;
value_11 = true;
}
if (!value_11) {
return false;
}
}
}
return true;
}
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)
{
String link_directory = vec_TextDetach(file_tree_linux_CreateTemporaryDirectory(out, name));
if ((int64_t)(link_directory).length == 0LL) {
compiler_backend_cache_Close(cache);
compiler_backend_process_ReportToolchain(out, log, false);
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);
String temporary = results_9_.value_0;
bool temporary_ok = results_9_.value_1;
if (!temporary_ok) {
file_tree_linux_RemoveTree(link_directory);
compiler_backend_cache_Close(cache);
compiler_backend_process_ReportToolchain(out, log, false);
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
bool cleanup_return_0 = false;
{
compiler_backend_process_ReleaseOwnedText(link_directory);
}
return cleanup_return_0;
}
__type_c53c2d7c4913dc02 arguments = compiler_backend_process_CloneTexts(base);
__type_c53c2d7c4913dc02* value_2 = &arguments;
__type_21092c8252d3dcaa tail_values = {0};
__type_21092c8252d3dcaa* value_3 = &tail_values;
__type_21092c8252d3dcaa value_4 = tail_values;
tail_values = (*(tail));
(*(tail)) = value_4;
bool ok = true;
bool added = false;
if (forced_language) {
added = compiler_backend_process_AddTextArgument(&(arguments), StringLiteral("-x"), StringLiteral("none"));
ok = added;
}
{
int64_t range_first_30 = 0LL;
int64_t range_last_30 = (int64_t)((uint64_t)(objects->count) - UINT64_C(1));
int64_t index = range_first_30;
if (index <= range_last_30) for (;;) {
if (ok) {
added = compiler_backend_process_AddTextArgument(&(arguments), compiler_backend_process_CText(ZIRAN_VEC_INDEX((*(objects)).data, (*(objects)).count, index)), StringLiteral(""));
ok = added;
}
if (index == range_last_30) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
if (ok) {
added = compiler_backend_process_AddTextArgument(&(arguments), StringLiteral("-o"), temporary);
ok = added;
}
{
Slice value_5 = {(tail_values).data, (tail_values).count};
Slice value_6 = SliceRange(value_5, 0LL, tail_values.count, sizeof(*(tail_values).data));
Slice loop_view_40 = value_6;
int64_t loop_count_40 = (int64_t)(loop_view_40).length;
int64_t loop_cursor_40 = 0LL;
while (loop_cursor_40 < loop_count_40) {
int64_t loop_index_40 = loop_cursor_40;
uint8_t* value = ((uint8_t* *)loop_view_40.data)[loop_index_40];
if (ok) {
added = compiler_backend_process_AddTextArgument(&(arguments), compiler_backend_process_CText(value), StringLiteral(""));
ok = added;
}
loop_cursor_40 = (int64_t)((uint64_t)loop_cursor_40 + UINT64_C(1));
}
}
__type_21092c8252d3dcaa value_7 = tail_values;
tail_values = (*(tail));
(*(tail)) = value_7;
if (ok) {
added = compiler_backend_process_AddTextArgument(&(arguments), StringLiteral("-lm"), StringLiteral(""));
ok = added;
}
if (!ok) {
compiler_backend_process_FreeArguments(&(arguments));
file_tree_linux_RemoveTree(link_directory);
compiler_backend_cache_Close(cache);
compiler_backend_process_ReportToolchain(out, log, false);
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
bool cleanup_return_1 = false;
{
compiler_backend_process_ReleaseOwnedText(temporary);
}
{
compiler_backend_process_ReleaseOwnedText(link_directory);
}
bool value_8 = cleanup_return_1;
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_8;
}
uint64_t link_started = zir_f_1cd1ecb166af98b1_ProfileStart();
Slice value_9 = {(arguments).data, (arguments).count};
bool value_10 = zir_f_1cd1ecb166af98b1_DiagnosticJsonEnabled() != 0;
Job job = compiler_backend_process_StartJob(SliceRange(value_9, 0LL, arguments.count, sizeof(*(arguments).data)), value_10, true);
compiler_backend_process_FreeArguments(&(arguments));
bool value_11 = job.process >= 0;
bool linked = value_11 && compiler_backend_process_WaitJob(&(job));
__type_838711075b90279a* value_12 = log;
Slice value_13 = {(job.output).data, (job.output).count};
compiler_backend_process_AppendLog(value_12, SliceRange(value_13, 0LL, job.output.count, sizeof(*(job.output).data)));
compiler_backend_process_FreeJob(&(job));
bool value_14 = linked;
bool value_15 = value_14;
if (value_15) {
bool value_16 = compiler_backend_process_MoveLinkOutput(link_directory, out, name);
value_15 = !value_16;
}
if (value_15) {
linked = false;
}
file_tree_linux_RemoveTree(link_directory);
compiler_backend_cache_Close(cache);
compiler_backend_process_ProfileEnd(StringLiteral("native.link"), link_started);
compiler_backend_process_ReportToolchain(out, log, linked);
compiler_backend_process_ReleaseBuildValues(base, tail, files, objects, log);
bool cleanup_return_2 = linked;
{
compiler_backend_process_ReleaseOwnedText(temporary);
}
{
compiler_backend_process_ReleaseOwnedText(link_directory);
}
bool value_17 = cleanup_return_2;
free((job).output.data);
(job).output.data = NULL;
(job).output.capacity = 0;
(job).output.count = 0;
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_17;
}
void
compiler_backend_process_ReleaseBuildValues(__type_21092c8252d3dcaa* base, __type_21092c8252d3dcaa* tail, __type_21092c8252d3dcaa* files, __type_21092c8252d3dcaa* objects, __type_838711075b90279a* log)
{
compiler_backend_process_ReleasePointerVector(base);
compiler_backend_process_ReleasePointerVector(tail);
compiler_backend_process_ReleasePointerVector(files);
compiler_backend_process_ReleasePointerVector(objects);
free(((*(log))).data);
((*(log))).data = NULL;
(*(log)).capacity = 0;
(*(log)).count = 0;
}
bool
compiler_backend_process_MoveLinkOutput(String directory, String out, String name)
{
zir_8a167d86ad221008_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) {
return false;
}
PathInfo executable = file_tree_linux_PathStatus(temporary_path, false);
if (((PathKind)(executable.kind)) != ((PathKind)(1)) || executable.size <= 0LL || ((int32_t)((uint32_t)(executable.mode) & 73u)) == 0) {
bool cleanup_return_0 = false;
{
compiler_backend_process_ReleaseOwnedText(temporary_path);
}
return cleanup_return_0;
}
DirectoryCursor cursor = OpenDirectory(directory);
if (!cursor.valid) {
bool cleanup_return_1 = false;
{
compiler_backend_process_ReleaseOwnedText(temporary_path);
}
return cleanup_return_1;
}
bool moved = true;
while (moved) {
DirectoryEntry entry = NextDirectoryEntry(&(cursor));
if (!entry.valid) {
break;
}
uint8_t* value_2 = &(entry.name[0]);
int64_t value_3 = (int64_t)(entry.name_count);
String value_4 = StringView(NULL, 0);
{
uint8_t* value = value_2;
int64_t length = value_3;
String result = StringLiteral("");
if (value == ((void *)0)) {
value_4 = result;
goto value_5;
}
OwnedText* descriptor = (OwnedText*)(&(result));
uint8_t** value_6 = &(descriptor->data);
(*value_6) = value;
size_t* value_7 = &(descriptor->length);
(*value_7) = (size_t)(length);
value_4 = result;
value_5: ;
}
String entry_name = value_4;
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);
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);
String destination = results_12_.value_0;
bool destination_ok = results_12_.value_1;
moved = source_ok && destination_ok && RenamePath(source, destination);
compiler_backend_process_ReleaseOwnedText(source);
compiler_backend_process_ReleaseOwnedText(destination);
}
bool failed = cursor.failed;
CloseDirectory(&(cursor));
if (!moved || failed) {
bool cleanup_return_2 = false;
{
compiler_backend_process_ReleaseOwnedText(temporary_path);
}
return cleanup_return_2;
}
zir_8a167d86ad221008_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) {
bool cleanup_return_3 = false;
{
compiler_backend_process_ReleaseOwnedText(temporary_path);
}
return cleanup_return_3;
}
bool cleanup_return_4 = RenamePath(temporary_path, final);
{
compiler_backend_process_ReleaseOwnedText(final);
}
{
compiler_backend_process_ReleaseOwnedText(temporary_path);
}
return cleanup_return_4;
}
void
compiler_backend_process_ReportToolchain(String out, __type_838711075b90279a* log, bool ok)
{
bool value_0 = ok;
if (value_0) {
int64_t value_1 = log->count;
value_0 = (value_1 == 0LL);
}
if (value_0) {
free(((*(log))).data);
((*(log))).data = NULL;
(*(log)).capacity = 0;
(*(log)).count = 0;
return;
}
int64_t value_2 = log->count;
bool truncated = value_2 > 4095LL;
int64_t value_3 = 0;
if (truncated) {
value_3 = 4095LL;
} else {
value_3 = log->count;
}
int64_t kept = value_3;
__type_838711075b90279a text = {0};
__type_838711075b90279a* value_4 = &text;
if (!ok) {
compiler_backend_cache_AppendText(&(text), StringLiteral("compiling "));
compiler_backend_cache_AppendText(&(text), out);
compiler_backend_cache_AppendText(&(text), StringLiteral(" failed"));
if (kept > 0LL) {
compiler_backend_cache_AppendText(&(text), StringLiteral(": "));
}
}
{
int64_t range_first_15 = 0LL;
int64_t range_last_15 = (int64_t)((uint64_t)kept - UINT64_C(1));
int64_t index = range_first_15;
if (index <= range_last_15) for (;;) {
uint8_t value_5 = ZIRAN_VEC_INDEX((*(log)).data, (*(log)).count, index);
bool value_6 = false;
void *value_7 = ZirVecGrow((void *)(text).data, &(text).capacity, (text).count, sizeof(*(text).data));
if (value_7 != NULL) {
(text).data = (uint8_t *)value_7;
(text).data[(text).count++] = value_5;
value_6 = true;
}
if (!value_6) {
free(((*(log))).data);
((*(log))).data = NULL;
(*(log)).capacity = 0;
(*(log)).count = 0;
{
free((text).data);
(text).data = NULL;
text.capacity = 0;
text.count = 0;
}
free((*value_4).data);
(*value_4).data = NULL;
(*value_4).capacity = 0;
(*value_4).count = 0;
return;
}
if (index == range_last_15) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
free(((*(log))).data);
((*(log))).data = NULL;
(*(log)).capacity = 0;
(*(log)).count = 0;
if (truncated) {
compiler_backend_cache_AppendText(&(text), StringLiteral(" [output truncated]"));
}
Slice value_8 = {(text).data, (text).count};
Slice value_9 = SliceRange(value_8, 0LL, text.count, sizeof(*(text).data));
compiler_backend_process_Report(ok, StringLiteral("zir_c.toolchain"), StringView((const char *)(value_9).data, (size_t)(value_9).length));
{
free((text).data);
(text).data = NULL;
text.capacity = 0;
text.count = 0;
}
free((*value_4).data);
(*value_4).data = NULL;
(*value_4).capacity = 0;
(*value_4).count = 0;
}
void
compiler_backend_process_Report(bool ok, String code, String message)
{
uint8_t* message_pointer = compiler_backend_process_AllocateText(message);
uint8_t* empty = compiler_backend_process_AllocateText(StringLiteral(""));
uint8_t* code_pointer = compiler_backend_process_AllocateText(code);
if (message_pointer != ((void *)0) && empty != ((void *)0) && code_pointer != ((void *)0)) {
if (ok) {
uint8_t* format = compiler_backend_process_AllocateText(StringLiteral("%s"));
if (format != ((void *)0)) {
zir_f_1cd1ecb166af98b1_WarningForeign((DiagnosticSpan){0}, code_pointer, format, message_pointer);
}
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(format));
} else {
uint8_t* target = compiler_backend_process_AllocateText(StringLiteral("c"));
uint8_t* capability = compiler_backend_process_AllocateText(StringLiteral("toolchain.native"));
uint8_t* format = compiler_backend_process_AllocateText(StringLiteral("%s%s"));
if (target != ((void *)0) && capability != ((void *)0) && format != ((void *)0)) {
zir_f_1cd1ecb166af98b1_DiagnosticTargetForeign((DiagnosticSpan){0}, code_pointer, target, capability, format, message_pointer, empty);
}
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(target));
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(capability));
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(format));
}
}
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(message_pointer));
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(empty));
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(code_pointer));
}
int64_t
compiler_backend_process_AffinityCpus(void)
{
int64_t online = zir_f_1cd1ecb166af98b1_SysconfByName(84);
uint8_t mask[128] = {0};
if (zir_f_1cd1ecb166af98b1_SchedGetAffinity(0, 128, &(mask[0])) != 0) {
return online;
}
int64_t count = 0LL;
for (int64_t it_index = 0LL; it_index < 128; it_index++) {
uint8_t byte = (mask)[it_index];
for (int64_t bit = 0LL; bit <= 7LL; bit++) {
if (((uint8_t)((uint32_t)byte & (uint32_t)(((uint8_t)ZiShl32(1, (uint64_t)((uint8_t)(bit)), 8))))) != 0) {
count = (int64_t)((uint64_t)count + UINT64_C(1));
}
}
}
return count;
}
int64_t
compiler_backend_process_AvailableMemory(void)
{
uint8_t name[64] = {0};
Slice value_0 = {name, 64};
bool value_1 = CopyCString(StringLiteral("/proc/meminfo"), value_0);
if (!value_1) {
return -1LL;
}
int32_t descriptor = zir_f_1cd1ecb166af98b1_OpenReadFile(&(name[0]));
if (descriptor < 0) {
return -1LL;
}
uint8_t bytes[4096] = {0};
int64_t count = zir_f_1cd1ecb166af98b1_ReadDescriptor(descriptor, &(bytes[0]), 4095);
zir_f_1cd1ecb166af98b1_CloseDescriptor(descriptor);
if (count <= 0LL) {
return -1LL;
}
uint8_t* value_2 = &(bytes[0]);
String value_3 = StringView(NULL, 0);
{
uint8_t* value = value_2;
int64_t length = count;
String result = StringLiteral("");
if (value == ((void *)0)) {
value_3 = result;
goto value_4;
}
OwnedText* descriptor = (OwnedText*)(&(result));
uint8_t** value_5 = &(descriptor->data);
(*value_5) = value;
size_t* value_6 = &(descriptor->length);
(*value_6) = (size_t)(length);
value_3 = result;
value_4: ;
}
String text = value_3;
int64_t at = text_tools_TextFind(text, StringLiteral("MemAvailable:"), 0LL);
if (at < 0LL) {
return -1LL;
}
at = (int64_t)((uint64_t)at + UINT64_C(13));
while (at < (int64_t)(text).length && ((uint8_t)ZIRAN_INDEX(text.data, text.length, at) == 32 || (uint8_t)ZIRAN_INDEX(text.data, text.length, at) == 9)) {
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
int64_t start = at;
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) {
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
if (at == start) {
return -1LL;
}
int64_t value = compiler_backend_process_NumberText(StringRange(text, (int64_t)start, (int64_t)at));
return value / 1024LL;
}
int64_t
compiler_backend_process_NumberText(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;
}
String
compiler_backend_process_CTextN(uint8_t* value, int64_t length)
{
String result = StringLiteral("");
if (value == ((void *)0)) {
return result;
}
OwnedText* descriptor = (OwnedText*)(&(result));
uint8_t** value_0 = &(descriptor->data);
(*value_0) = value;
size_t* value_1 = &(descriptor->length);
(*value_1) = (size_t)(length);
return result;
}
bool
compiler_backend_process_CreateDirectories(String path)
{
uint8_t name[4096] = {0};
bool value_0 = (int64_t)(path).length >= 4096LL;
if (!value_0) {
Slice value_1 = {name, 4096};
bool value_2 = CopyCString(path, value_1);
value_0 = !value_2;
}
if (value_0) {
return false;
}
int64_t at = 1LL;
while (at < (int64_t)(path).length) {
if ((name)[at] != 47) {
at = (int64_t)((uint64_t)at + UINT64_C(1));
continue;
}
uint8_t* value_3 = &(name[at]);
(*value_3) = 0;
int32_t status = zir_f_1cd1ecb166af98b1_MakeDirectory(&(name[0]), 493);
if (status != 0 && compiler_backend_process_ErrnoValue() != 17) {
return false;
}
uint8_t* value_4 = &(name[at]);
(*value_4) = 47;
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
int32_t status = zir_f_1cd1ecb166af98b1_MakeDirectory(&(name[0]), 493);
return status == 0 || compiler_backend_process_ErrnoValue() == 17;
}
int32_t
compiler_backend_process_ErrnoValue(void)
{
int32_t* value_0 = zir_f_1cd1ecb166af98b1_ErrnoLocation();
return *(value_0);
}
void
compiler_backend_process_SetCloexec(int32_t descriptor)
{
zir_f_1cd1ecb166af98b1_FcntlCloexec(descriptor, 2, 1);
}
void
compiler_backend_process_FinishStatus(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;
}
bool
compiler_backend_process_ReadJobOutput(Job* job)
{
uint8_t bytes[4096] = {0};
int64_t count = 0;
count = zir_f_1cd1ecb166af98b1_ReadDescriptor(job->descriptor, &(bytes[0]), 4096);
while (count < 0LL && compiler_backend_process_ErrnoValue() == 4) {
count = zir_f_1cd1ecb166af98b1_ReadDescriptor(job->descriptor, &(bytes[0]), 4096);
}
if (count < 0LL) {
zir_f_1cd1ecb166af98b1_CloseDescriptor(job->descriptor);
int32_t* value_0 = &(job->descriptor);
(*value_0) = -1;
return false;
}
if (count == 0LL) {
zir_f_1cd1ecb166af98b1_CloseDescriptor(job->descriptor);
int32_t* value_1 = &(job->descriptor);
(*value_1) = -1;
return true;
}
int64_t index = 0LL;
while (index < count) {
uint8_t value_2 = ZIRAN_INDEX(bytes, 4096, index);
bool value_3 = false;
void *value_4 = ZirVecGrow((void *)(job->output).data, &(job->output).capacity, (job->output).count, sizeof(*(job->output).data));
if (value_4 != NULL) {
(job->output).data = (uint8_t *)value_4;
(job->output).data[(job->output).count++] = value_2;
value_3 = true;
}
if (!value_3) {
return false;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
return true;
}
void
compiler_backend_process_ExecChild(uint8_t* path, CapturePointer* arguments, bool report_error)
{
if (zir_f_1cd1ecb166af98b1_ExecRaw(path, arguments) == 0) {
return;
}
if (report_error) {
String prefix = StringLiteral("cannot run ");
String value = compiler_backend_process_CText(path);
uint8_t* prefix_message = compiler_backend_process_AllocateText(prefix);
uint8_t* path_message = compiler_backend_process_AllocateText(value);
uint8_t* reason = zir_f_1cd1ecb166af98b1_Strerror(compiler_backend_process_ErrnoValue());
String reason_text = compiler_backend_process_CText(reason);
uint8_t* separator = compiler_backend_process_AllocateText(StringLiteral(": "));
uint8_t* ending = compiler_backend_process_AllocateText(StringLiteral("\n"));
if (prefix_message != ((void *)0)) {
zir_f_1cd1ecb166af98b1_WriteDescriptor(2, prefix_message, (size_t)((int64_t)(prefix).length));
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(prefix_message));
}
if (path_message != ((void *)0)) {
zir_f_1cd1ecb166af98b1_WriteDescriptor(2, path_message, (size_t)((int64_t)(value).length));
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(path_message));
}
if (separator != ((void *)0)) {
zir_f_1cd1ecb166af98b1_WriteDescriptor(2, separator, (size_t)(2LL));
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(separator));
}
if (reason != ((void *)0)) {
zir_f_1cd1ecb166af98b1_WriteDescriptor(2, reason, (size_t)((int64_t)(reason_text).length));
}
if (ending != ((void *)0)) {
zir_f_1cd1ecb166af98b1_WriteDescriptor(2, ending, (size_t)(1LL));
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(ending));
}
}
}
void
compiler_backend_process_ProfileCount(String counter)
{
uint8_t* value = compiler_backend_process_ProfileName(counter);
if (value != ((void *)0)) {
zir_f_1cd1ecb166af98b1_ProfileCountForeign(value);
}
}
void
compiler_backend_process_ProfileEnd(String phase, uint64_t started)
{
uint8_t* value = compiler_backend_process_ProfileName(phase);
if (value == ((void *)0)) {
return;
}
zir_f_1cd1ecb166af98b1_ProfileEndForeign(value, 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);
if (StringEqual(value, name)) {
OwnedText* descriptor = (OwnedText*)(&(value));
return descriptor->data;
}
}
uint8_t* pointer = compiler_backend_process_AllocateText(name);
if (pointer == ((void *)0)) {
return (void *)0;
}
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));
if (value_2 != NULL) {
(zir_g_b176900cac1241ec).data = (String *)value_2;
(zir_g_b176900cac1241ec).data[(zir_g_b176900cac1241ec).count++] = value_0;
value_1 = true;
}
if (!value_1) {
zir_f_1cd1ecb166af98b1_FreeRaw((void*)(pointer));
return (void *)0;
}
OwnedText* descriptor = (OwnedText*)(&(owned));
return descriptor->data;
}