Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
intellliJ code cleanup and inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
yangdanny97 committed May 31, 2019
1 parent 0a028d4 commit c05aa6e
Show file tree
Hide file tree
Showing 24 changed files with 22 additions and 118 deletions.
2 changes: 1 addition & 1 deletion src/main/java/edu/cornell/cs/cs4120/xic/ir/IRMem.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public String toString() {
}
throw new InternalCompilerError("Unknown mem type!");
}
};
}

private IRExpr expr;
private MemType memType;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/cornell/cs/cs4120/xic/ir/IRSeq.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public IRSeq(List<IRStmt> stmts) {
}

public IRSeq(List<IRStmt> stmts, boolean replaceParent) {
this.stmts = filterNulls(stmts);;
this.stmts = filterNulls(stmts);
this.replaceParent = replaceParent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import kc875.cfg.DFAFramework;
import kc875.cfg.Graph;
import kc875.utils.SetWithInf;
import kc875.utils.XiUtils;
import polyglot.util.Pair;

public class AvailableCopiesDFA extends
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.ArrayList;

import edu.cornell.cs.cs4120.util.CodeWriterSExpPrinter;
import edu.cornell.cs.cs4120.util.InternalCompilerError;
import edu.cornell.cs.cs4120.xic.ir.IRBinOp;
import edu.cornell.cs.cs4120.xic.ir.IRCJump;
Expand Down Expand Up @@ -574,7 +571,7 @@ public IRNode getCurrentInsn() {
throw new Trap("No next instruction. Forgot RETURN?");
return insn;
}
};
}

/**
* While traversing the IR tree, we require a stack in order to hold
Expand Down Expand Up @@ -626,7 +623,7 @@ public void pushValue(long value) {

public static class StackItem {
public enum Kind {
COMPUTED, MEM, TEMP, NAME;
COMPUTED, MEM, TEMP, NAME
}

public Kind type;
Expand All @@ -653,7 +650,7 @@ public StackItem(Kind type, long value, String string) {
temp = string;
else name = string;
}
};
}

public static class Trap extends RuntimeException {
private static final long serialVersionUID =
Expand All @@ -662,7 +659,7 @@ public static class Trap extends RuntimeException {
public Trap(String message) {
super(message);
}
};
}

public static class OutOfBoundTrap extends Trap {
private static final long serialVersionUID =
Expand All @@ -671,5 +668,5 @@ public static class OutOfBoundTrap extends Trap {
public OutOfBoundTrap(String message) {
super(message);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1050,17 +1050,6 @@ public List<ASMInstr> visit(IRExp node) {
return visitExpr(node.expr(), new ASMExprTemp(newTemp()));
}

/**
* Remove all non-digit characters from a string, and return the integer
* value of the result.
*
* @param s string containing one or more digit
* @return number contained within the string
*/
private static int numFromString(String s) {
return Integer.parseInt(s.replaceAll("\\D+", ""));
}

public List<ASMInstr> visit(IRFuncDecl node) {
List<ASMInstr> instrs = new ArrayList<>();
int numParams = node.getNumParams();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ private IRFuncDecl removeCommonSubExpressions(IRFuncDecl func) {
if (e instanceof IRTemp
|| e instanceof IRConst
|| tempExprMap.containsKey(e)) {
continue;
} else if (dfa.nodesUsingExpr(e).size() > 1 ) {
String tmp = newTemp();
tempExprMap.put(e, tmp);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package edu.cornell.cs.cs4120.xic.ir.visit;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import edu.cornell.cs.cs4120.util.InternalCompilerError;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.cornell.cs.cs4120.xic.ir.visit;

import edu.cornell.cs.cs4120.xic.ir.IRNode;
import edu.cornell.cs.cs4120.xic.ir.IRTemp;

import java.util.ArrayList;
import java.util.List;
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/kc875/asm/ASMInstrComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import kc875.asm.visit.ASMinstrBareVisitor;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;

public class ASMInstrComment extends ASMInstr {
private String comment;
Expand All @@ -25,7 +22,7 @@ public String toString() {
@Override
public boolean equals(Object obj) {
return obj instanceof ASMInstrComment &&
((ASMInstrComment) obj).getComment() == this.comment;
Objects.equals(((ASMInstrComment) obj).getComment(), this.comment);
}

@Override
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/kc875/asm/dfa/ASMGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,10 @@ public ASMGraph(List<ASMInstr> instrs) {
}
}

public BiMap<Node, ASMInstr> getNodeInstrMap() {
return nodeInstrMap;
}

public Node getNode(ASMInstr i) {
return nodeInstrMap.inverse().get(i);
}

public ASMInstr getInstr(Node n) {
return nodeInstrMap.get(n);
}

/**
* Check if an instruction needs a CFG edge to the instruction immediately
* following it. This is false if the instruction is non-fallthrough, e.g.
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/kc875/asm/dfa/InterferenceGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import kc875.asm.ASMExprRT;
import kc875.asm.ASMInstr;
import kc875.cfg.Graph;

import java.util.List;
import java.util.HashSet;

public class InterferenceGraph extends Graph<ASMExprRT> {
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/kc875/asm/visit/ASMDirectivesVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@ public ASMDirectivesVisitor(Map<String, List<String>> dvs) {
dispatchVectorLayouts = dvs;
}

private String returnTypeName(TypeT type) {
if (type instanceof TypeTList) {
TypeTList tuple = (TypeTList) type;
ArrayList<String> types = new ArrayList<>();
tuple.getTTauList().forEach((t) -> types.add(returnTypeName(t)));
return "t" + tuple.getLength() + String.join("", types);
} else if (type instanceof TypeTUnit) { //TypeTUnit
return "p";
} else {
return typeName(type);
}
}

private String typeName(TypeT type) {
if (type instanceof TypeTList) {
TypeTList tuple = (TypeTList) type;
Expand Down
21 changes: 0 additions & 21 deletions src/main/java/kc875/asm/visit/RegAllocationColoringVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -661,27 +661,6 @@ private boolean isMoveInstruction(ASMInstr i) {
//return i.destIsDefButNoUse();
}

//GETTERS (for testing)
public ASMGraph getCfg() {
return cfg;
}

public InterferenceGraph getInterference() {
return interference;
}

public ASMLiveVariableDFA getLiveness() {
return liveness;
}

public List<ASMInstr> getInstrs() {
return instrs;
}

public int getK() {
return K;
}

//FOR TESTING ONLY!
//USED FOR TESTING ONLY - stops after build graph step so we can test for invariants
public void buildInterferenceGraph(List<ASMInstr> instrs) {
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/kc875/asm/visit/RegAllocationOptimVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ private List<ASMInstr> allocateFunc(List<ASMInstr> instrs){
return v.allocate(instrs);
}

private void printInstrs(List<ASMInstr> instrs){
for (ASMInstr in : instrs) {
System.out.println(in);
}
System.out.println();
}
// --Commented out by Inspection START (2019-05-30 23:39):
// private void printInstrs(List<ASMInstr> instrs){
// for (ASMInstr in : instrs) {
// System.out.println(in);
// }
// System.out.println();
// }
// --Commented out by Inspection STOP (2019-05-30 23:39)
}
4 changes: 2 additions & 2 deletions src/main/java/kc875/ast/TypeTList.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public int getLength(){

@Override
public String toString() {
String s = "(" + tTauList.get(0).toString();
StringBuilder s = new StringBuilder("(" + tTauList.get(0).toString());
for (int i = 1; i < tTauList.size(); i++) {
s = s + "," + tTauList.get(i).toString();
s.append(",").append(tTauList.get(i).toString());
}
return s + ")";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public void setUp() {
availableExprsDFA = new AvailableExprsDFA(graph);
}

@After
public void tearDown() {
}

@Test
public void testExprsContainingTemp() {
IRTemp temp = new IRTemp("temp");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ public void setUp() {
livenessDFA = new LivenessDFA(graph);
}

@After
public void tearDown() {
}

private boolean twoListsEqual(List a, List b) {
return (a.size() == b.size() &&
a.containsAll(b) && b.containsAll(a));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,8 @@ OpType.MUL, new IRTemp("b"), new IRConst(4)
}

@Before
public void setUp() throws Exception {
public void setUp() {
visitor = new ASMTranslationVisitor();
}

@After
public void tearDown() throws Exception {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ public void setUp() {
cseVisitor = new CommonSubexprElimVisitor();
}

@After
public void tearDown() {
}

private boolean twoListsEqual(List a, List b) {
return (a.size() == b.size() &&
a.containsAll(b) && b.containsAll(a));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,8 @@ public void cjumpFalseNoLabelTest() {
}

@Before
public void setUp() throws Exception {
public void setUp() {
visitor = new ConstantFoldVisitor(new IRNodeFactory_c());
}

@After
public void tearDown() throws Exception {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ public void setUp() {
deadCodeElimVisitor = new DeadCodeElimVisitor();
}

@After
public void tearDown() {
}

@Test
public void sanityCheck() {
copyPropagationVisitor.run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,8 @@ public void testReordering0() {
}

@Before
public void setUp() throws Exception {
public void setUp() {
visitor = new LoweringVisitor(new IRNodeFactory_c());
}

@After
public void tearDown() throws Exception {
}
}
4 changes: 0 additions & 4 deletions src/test/java/kc875/ast/IRTranslationVisitorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public void setUp() {
l = new XiTokenLocation(0,0);
}

@After
public void tearDown() {
}

@Test
public void testFuncName0() {
TypeSymTableFunc t = new TypeSymTableFunc(
Expand Down
3 changes: 0 additions & 3 deletions src/test/java/kc875/symboltable/SymbolTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,4 @@ public void setUp() {
table = createInstance();
}

@After
public void tearDown() {
}
}

0 comments on commit c05aa6e

Please sign in to comment.