|
13 | 13 |
|
14 | 14 | typedef struct Context_ {
|
15 | 15 | Rewriter rewriter;
|
| 16 | + const CompilerConfig* config; |
16 | 17 | const Node* current_fn;
|
17 | 18 | Scope* scope;
|
18 | 19 | const UsesMap* scope_uses;
|
@@ -84,6 +85,11 @@ const Node* process_abstraction_body(Context* ctx, const Node* old, const Node*
|
84 | 85 |
|
85 | 86 | Node* nfn = (Node*) rewrite_node(&ctx->rewriter, ctx->current_fn);
|
86 | 87 |
|
| 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 | + } |
87 | 93 | const CFNode* n = scope_lookup(ctx->scope, old);
|
88 | 94 |
|
89 | 95 | size_t children_count = 0;
|
@@ -129,6 +135,14 @@ const Node* process_node(Context* ctx, const Node* old) {
|
129 | 135 | IrArena* a = ctx->rewriter.dst_arena;
|
130 | 136 |
|
131 | 137 | switch (old->tag) {
|
| 138 | + case NominalType_TAG: |
| 139 | + case GlobalVariable_TAG: |
| 140 | + case Constant_TAG: { |
| 141 | + Context not_a_fn_ctx = *ctx; |
| 142 | + ctx = ¬_a_fn_ctx; |
| 143 | + ctx->scope = NULL; |
| 144 | + return recreate_node_identity(&ctx->rewriter, old); |
| 145 | + } |
132 | 146 | case Function_TAG: {
|
133 | 147 | Context fn_ctx = *ctx;
|
134 | 148 | ctx = &fn_ctx;
|
@@ -174,13 +188,14 @@ const Node* process_node(Context* ctx, const Node* old) {
|
174 | 188 | KeyHash hash_node(Node**);
|
175 | 189 | bool compare_node(Node**, Node**);
|
176 | 190 |
|
177 |
| -Module* lcssa(SHADY_UNUSED const CompilerConfig* config, Module* src) { |
| 191 | +Module* lcssa(const CompilerConfig* config, Module* src) { |
178 | 192 | ArenaConfig aconfig = get_arena_config(get_module_arena(src));
|
179 | 193 | IrArena* a = new_ir_arena(aconfig);
|
180 | 194 | Module* dst = new_module(a, get_module_name(src));
|
181 | 195 |
|
182 | 196 | Context ctx = {
|
183 | 197 | .rewriter = create_rewriter(src, dst, (RewriteNodeFn) process_node),
|
| 198 | + .config = config, |
184 | 199 | .current_fn = NULL,
|
185 | 200 | .lifted_arguments = new_dict(const Node*, Nodes, (HashFn) hash_node, (CmpFn) compare_node)
|
186 | 201 | };
|
|
0 commit comments