Homework B (benchmarks)

This commit is contained in:
Carlos Galindo 2020-01-15 22:38:07 +01:00
commit 76fbabdf53
Signed by: kauron
GPG key ID: 83E68706DEE119A3
141 changed files with 7540 additions and 2032 deletions

View file

@ -0,0 +1,38 @@
package cd.transform.optimizers;
import cd.ir.Ast.ClassDecl;
import cd.ir.Symbol.ArrayTypeSymbol;
import cd.ir.Symbol.TypeSymbol;
import cd.transform.analysis.ClassUsage;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class UnusedClassRemoval extends GlobalOptimizerVisitor<Void> {
public boolean go(List<ClassDecl> classDecls, List<TypeSymbol> typeList) {
Set<ClassDecl> used = new ClassUsage().go(classDecls);
Set<ClassDecl> toRemove = new HashSet<>(classDecls);
toRemove.removeAll(used);
// Remove classes from list of declarations
classDecls.clear();
classDecls.addAll(used);
// Remove corresponding types and array types
for (ClassDecl classDecl : toRemove) {
typeList.remove(classDecl.sym);
TypeSymbol arrayType = null;
for (TypeSymbol type : typeList) {
if (type instanceof ArrayTypeSymbol && ((ArrayTypeSymbol) type).elementType == classDecl.sym) {
arrayType = type;
break;
}
}
assert arrayType != null;
typeList.remove(arrayType);
}
return !toRemove.isEmpty();
}
}