Simplify/Fix the state_flag behaviour for code generation

This commit is contained in:
gingerBill
2021-05-01 17:42:59 +01:00
parent 327116b84b
commit 406d2ab6ba
3 changed files with 22 additions and 31 deletions
+13 -29
View File
@@ -184,7 +184,7 @@ void lb_emit_bounds_check(lbProcedure *p, Token token, lbValue index, lbValue le
if (build_context.no_bounds_check) {
return;
}
if ((p->module->state_flags & StateFlag_no_bounds_check) != 0) {
if ((p->state_flags & StateFlag_no_bounds_check) != 0) {
return;
}
@@ -209,7 +209,7 @@ void lb_emit_slice_bounds_check(lbProcedure *p, Token token, lbValue low, lbValu
if (build_context.no_bounds_check) {
return;
}
if ((p->module->state_flags & StateFlag_no_bounds_check) != 0) {
if ((p->state_flags & StateFlag_no_bounds_check) != 0) {
return;
}
@@ -3117,19 +3117,6 @@ void lb_begin_procedure_body(lbProcedure *p) {
}
}
if (p->tags != 0) {
u64 in = p->tags;
u64 out = p->module->state_flags;
if (in & ProcTag_bounds_check) {
out |= StateFlag_bounds_check;
out &= ~StateFlag_no_bounds_check;
} else if (in & ProcTag_no_bounds_check) {
out |= StateFlag_no_bounds_check;
out &= ~StateFlag_bounds_check;
}
p->module->state_flags = out;
}
p->builder = LLVMCreateBuilder();
p->decl_block = lb_create_block(p, "decls", true);
@@ -3299,7 +3286,7 @@ void lb_end_procedure_body(lbProcedure *p) {
}
p->curr_block = nullptr;
p->module->state_flags = 0;
p->state_flags = 0;
}
void lb_end_procedure(lbProcedure *p) {
LLVMDisposeBuilder(p->builder);
@@ -4821,12 +4808,12 @@ void lb_build_stmt(lbProcedure *p, Ast *node) {
LLVMSetCurrentDebugLocation2(p->builder, prev_debug_location);
});
u64 prev_state_flags = p->module->state_flags;
defer (p->module->state_flags = prev_state_flags);
u16 prev_state_flags = p->state_flags;
defer (p->state_flags = prev_state_flags);
if (node->state_flags != 0) {
u64 in = node->state_flags;
u64 out = p->module->state_flags;
u16 in = node->state_flags;
u16 out = p->state_flags;
if (in & StateFlag_bounds_check) {
out |= StateFlag_bounds_check;
@@ -4836,7 +4823,7 @@ void lb_build_stmt(lbProcedure *p, Ast *node) {
out &= ~StateFlag_bounds_check;
}
p->module->state_flags = out;
p->state_flags = out;
}
switch (node->kind) {
@@ -11014,12 +11001,12 @@ lbValue lb_emit_any_cast(lbProcedure *p, lbValue value, Type *type, TokenPos pos
lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
lbModule *m = p->module;
u64 prev_state_flags = p->module->state_flags;
defer (p->module->state_flags = prev_state_flags);
u16 prev_state_flags = p->state_flags;
defer (p->state_flags = prev_state_flags);
if (expr->state_flags != 0) {
u64 in = expr->state_flags;
u64 out = p->module->state_flags;
u16 in = expr->state_flags;
u16 out = p->state_flags;
if (in & StateFlag_bounds_check) {
out |= StateFlag_bounds_check;
@@ -11029,7 +11016,7 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
out &= ~StateFlag_bounds_check;
}
p->module->state_flags = out;
p->state_flags = out;
}
expr = unparen_expr(expr);
@@ -12844,9 +12831,6 @@ void lb_init_module(lbModule *m, Checker *c) {
m->debug_builder = LLVMCreateDIBuilder(m->mod);
}
m->state_flags = 0;
m->state_flags |= StateFlag_bounds_check;
gb_mutex_init(&m->mutex);
gbAllocator a = heap_allocator();
map_init(&m->types, a);
+1 -2
View File
@@ -85,8 +85,6 @@ struct lbModule {
LLVMModuleRef mod;
LLVMContextRef ctx;
u64 state_flags;
CheckerInfo *info;
gbMutex mutex;
@@ -210,6 +208,7 @@ enum lbProcedureFlag : u32 {
struct lbProcedure {
u32 flags;
u16 state_flags;
lbProcedure *parent;
Array<lbProcedure *> children;
+8
View File
@@ -2170,6 +2170,14 @@ Ast *parse_operand(AstFile *f, bool lhs) {
body = parse_body(f);
f->curr_proc = curr_proc;
// Apply the tags directly to the body rather than the type
if (tags & ProcTag_no_bounds_check) {
body->state_flags |= StateFlag_no_bounds_check;
}
if (tags & ProcTag_bounds_check) {
body->state_flags |= StateFlag_bounds_check;
}
return ast_proc_lit(f, type, body, tags, where_token, where_clauses);
} else if (allow_token(f, Token_do)) {
Ast *curr_proc = f->curr_proc;