Skip to content

Commit afbbf08

Browse files
committed
added extra diagnostic stuff to lcssa
1 parent 538ea80 commit afbbf08

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/shady/passes/lcssa.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
typedef struct Context_ {
1515
Rewriter rewriter;
16+
const CompilerConfig* config;
1617
const Node* current_fn;
1718
Scope* scope;
1819
const UsesMap* scope_uses;
@@ -84,6 +85,11 @@ const Node* process_abstraction_body(Context* ctx, const Node* old, const Node*
8485

8586
Node* nfn = (Node*) rewrite_node(&ctx->rewriter, ctx->current_fn);
8687

88+
if (!ctx->scope) {
89+
error_print("LCSSA: Trying to process an abstraction that's not part of a function ('%s')!", get_abstraction_name(old));
90+
log_module(ERROR, ctx->config, ctx->rewriter.src_module);
91+
error_die();
92+
}
8793
const CFNode* n = scope_lookup(ctx->scope, old);
8894

8995
size_t children_count = 0;
@@ -129,6 +135,14 @@ const Node* process_node(Context* ctx, const Node* old) {
129135
IrArena* a = ctx->rewriter.dst_arena;
130136

131137
switch (old->tag) {
138+
case NominalType_TAG:
139+
case GlobalVariable_TAG:
140+
case Constant_TAG: {
141+
Context not_a_fn_ctx = *ctx;
142+
ctx = &not_a_fn_ctx;
143+
ctx->scope = NULL;
144+
return recreate_node_identity(&ctx->rewriter, old);
145+
}
132146
case Function_TAG: {
133147
Context fn_ctx = *ctx;
134148
ctx = &fn_ctx;
@@ -174,13 +188,14 @@ const Node* process_node(Context* ctx, const Node* old) {
174188
KeyHash hash_node(Node**);
175189
bool compare_node(Node**, Node**);
176190

177-
Module* lcssa(SHADY_UNUSED const CompilerConfig* config, Module* src) {
191+
Module* lcssa(const CompilerConfig* config, Module* src) {
178192
ArenaConfig aconfig = get_arena_config(get_module_arena(src));
179193
IrArena* a = new_ir_arena(aconfig);
180194
Module* dst = new_module(a, get_module_name(src));
181195

182196
Context ctx = {
183197
.rewriter = create_rewriter(src, dst, (RewriteNodeFn) process_node),
198+
.config = config,
184199
.current_fn = NULL,
185200
.lifted_arguments = new_dict(const Node*, Nodes, (HashFn) hash_node, (CmpFn) compare_node)
186201
};

0 commit comments

Comments
 (0)