Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 12 additions & 26 deletions src/cleaf.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define LOG_LIB_IMPLEMENTATION
#include "thirdparty/log.h"

#include "thirdparty/assertion.h"
#include "frontend/ast_definition.h"
#include "frontend/ast.h"
#include "frontend/ast_printer.h"
Expand Down Expand Up @@ -75,11 +76,7 @@ int main(int argc, char** argv)
build_context_t build_ctx = {0};
if (is_build_mode) {
build_ctx.registry = calloc(1, sizeof(hashmap_t));
if (!build_ctx.registry) {
error_report_general(ERROR_SEVERITY_ERROR, "out of memory");
compiler_resources_free(res);
return 1;
}
CLEAF_ASSERT(build_ctx.registry != NULL, "out of memory");
}

da_foreach(char*, it, &res->files) {
Expand Down Expand Up @@ -214,12 +211,7 @@ int main(int argc, char** argv)
}

res->hir_program = calloc(1, sizeof(IR_function_array));
if (!res->hir_program) {
error_report_general(ERROR_SEVERITY_ERROR, "out of memory");
build_context_free(&build_ctx);
compiler_resources_free(res);
return 1;
}
CLEAF_ASSERT(res->hir_program != NULL, "out of memory");

rand_t chunk_rng;
rand_init(&chunk_rng);
Expand Down Expand Up @@ -289,7 +281,8 @@ int main(int argc, char** argv)
if (log_is_dump()) {
log_section_begin("HIR");
for (size_t i = hir_before; i < res->hir_program->count; ++i) {
char* hir_text = IR_generate_string_program(res->hir_program->items[i]);
char* hir_text =
IR_generate_string_program(res->hir_program->items[i]);
fprintf(stderr, "%s", hir_text);
free(hir_text);
}
Expand All @@ -305,14 +298,13 @@ int main(int argc, char** argv)
if (decl->type != DECLARATION_FUNC) continue;

char* mangled =
IR_mangle_function_name(unit->module_name, decl->func.name);
if (!mangled) {
error_report_general(ERROR_SEVERITY_ERROR, "out of memory");
had_errors = 1;
continue;
}
IR_mangle_function_name(
unit->module_name, decl->func.name);

CLEAF_ASSERT(mangled != NULL, "out of memory");

if (!decl->func.is_internal || strcmp(mangled, "start") == 0)
if (!decl->func.is_internal ||
strcmp(mangled, "start") == 0)
target->emit_global(&module_sb, mangled);

free(mangled);
Expand Down Expand Up @@ -373,13 +365,7 @@ int main(int argc, char** argv)
}

char* base = build_object_basename(unit);
if (!base) {
error_report_general(ERROR_SEVERITY_ERROR, "out of memory");
had_errors = 1;
da_free(&module_sb);
semantic_free_program_definition(&analyzer);
continue;
}
CLEAF_ASSERT(base != NULL, "out of memory");

char asm_path[512];
snprintf(asm_path, sizeof(asm_path), "build/%s.asm", base);
Expand Down
6 changes: 2 additions & 4 deletions src/compiler/build/dep_graph.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "compiler/build/dep_graph.h"
#include "thirdparty/assertion.h"

static void dep_graph_free(dep_graph_t* graph)
{
Expand Down Expand Up @@ -45,10 +46,7 @@ bool build_dep_graph(build_context_t* ctx)
dep_graph_t graph = {0};

graph.index = calloc(1, sizeof(hashmap_t));
if (!graph.index) {
error_report_general(ERROR_SEVERITY_ERROR, "out of memory");
return false;
}
CLEAF_ASSERT(graph.index != NULL, "out of memory");

for (size_t i = 0; i < HASH_SIZE; ++i) {
hashmap_entry_t* e = ctx->registry->buckets[i];
Expand Down
22 changes: 7 additions & 15 deletions src/compiler/build/export_table.c
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
#include "export_table.h"
#include "frontend/symbols.h"
#include "thirdparty/error.h"
#include "thirdparty/assertion.h"

bool semantic_build_export_table(module_unit_t* unit)
{
unit->export_funcs = calloc(1, sizeof(hashmap_t));
if (!unit->export_funcs) {
error_report_general(ERROR_SEVERITY_ERROR, "out of memory");
return false;
}
CLEAF_ASSERT(unit->export_funcs != NULL, "out of memory");

da_foreach(declaration_t*, it, &unit->program) {
declaration_t* decl = *it;
if (decl->type != DECLARATION_FUNC) continue;
if (decl->func.is_internal) continue;

function_symbol_t* fs = calloc(1, sizeof(function_symbol_t));
if (!fs) {
error_report_general(ERROR_SEVERITY_ERROR, "out of memory");
return false;
}
CLEAF_ASSERT(fs != NULL, "out of memory");

fs->return_type.kind = decl->func.return_type.kind;
fs->params_count = decl->func.params.count;
Expand All @@ -29,13 +24,10 @@ bool semantic_build_export_table(module_unit_t* unit)
fs->params_type =
calloc(fs->params_count, sizeof(variable_symbol_t));

if (!fs->params_name || !fs->params_type) {
error_report_general(ERROR_SEVERITY_ERROR, "out of memory");
free(fs->params_name);
free(fs->params_type);
free(fs);
return false;
}

CLEAF_ASSERT(fs->params_name != NULL, "out of memory");
CLEAF_ASSERT(fs->params_type != NULL, "out of memory");

for (size_t i = 0; i < fs->params_count; ++i) {
fs->params_name[i] = decl->func.params.items[i].ident_name;
fs->params_type[i].type = decl->func.params.items[i].type;
Expand Down
17 changes: 4 additions & 13 deletions src/compiler/build/import_resolver.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "import_resolver.h"
#include "frontend/symbols.h"
#include "thirdparty/error.h"
#include "thirdparty/assertion.h"
#include <string.h>
#include <stdio.h>

Expand Down Expand Up @@ -62,10 +63,7 @@ bool semantic_resolve_imports(
semantic_analyzer_t* analyzer)
{
analyzer->imported_functions = calloc(1, sizeof(hashmap_t));
if (!analyzer->imported_functions) {
error_report_general(ERROR_SEVERITY_ERROR, "out of memory");
return false;
}
CLEAF_ASSERT(analyzer->imported_functions != NULL, "out of memory");

da_foreach(declaration_t*, it, &unit->program) {
declaration_t* decl = *it;
Expand All @@ -82,10 +80,7 @@ bool semantic_resolve_imports(
const char* qualifier = path->items[path->count - 2];

char* module_name = join_path_segments(path->items, path->count - 1);
if (!module_name) {
error_report_general(ERROR_SEVERITY_ERROR, "out of memory");
return false;
}
CLEAF_ASSERT(module_name != NULL, "out of memory");

module_unit_array* target_units =
(module_unit_array*) hashmap_get(ctx->registry, module_name);
Expand All @@ -111,11 +106,7 @@ bool semantic_resolve_imports(
}

imported_symbol_t* isym = calloc(1, sizeof(imported_symbol_t));
if (!isym) {
error_report_general(ERROR_SEVERITY_ERROR, "out of memory");
free(module_name);
return false;
}
CLEAF_ASSERT(isym != NULL, "out of memory");

isym->fs = fs;
isym->module_name = module_name;
Expand Down
Loading
Loading