Skip to content

Commit 4893616

Browse files
Csaba Feketeneilsf
authored andcommitted
Fixes #274 Unused subroutines no longer use variable memory
1 parent ad9b65c commit 4893616

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

source/compiler/variable.d

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class VariableCollection
199199
}
200200

201201
this.variables ~= variable;
202+
const bool isLocal = (variable.visibility == Compiler.VIS_LOCAL);
202203

203204
// Add the variable to the intermediate code
204205
if(!variable.isConst && !variable.isDynamic) {
@@ -207,7 +208,7 @@ class VariableCollection
207208
// Need one more byte for strings
208209
length += (variable.dimensions[0] * variable.dimensions[1] * variable.dimensions[2]);
209210
}
210-
string code;
211+
string code = "";
211212
if(variable.isExplicitAddr || variable.isFast) {
212213
if(variable.addressLabel != "") {
213214
code = variable.getAsmLabel() ~ " EQU " ~ variable.addressLabel ~ "\n";
@@ -217,8 +218,15 @@ class VariableCollection
217218
}
218219
}
219220
else {
220-
code = variable.getAsmLabel() ~ " DS.B " ~ to!string(length) ~ "\n";
221+
if (isLocal) {
222+
code ~= "\t IFCONST I_" ~ compiler.currentProc.getLabel() ~ "_IMPORTED\n";
223+
}
224+
code ~= variable.getAsmLabel() ~ " DS.B " ~ to!string(length) ~ "\n";
225+
if (isLocal) {
226+
code ~= "\tENDIF\n";
227+
}
221228
}
229+
222230
this.compiler.getImCode().appendSegment(IntermediateCode.VAR_SEGMENT, code);
223231
}
224232
}

0 commit comments

Comments
 (0)