package condense; import misc.*; import cs132.vapor.ast.VFunction; import cs132.vapor.ast.VMemRef; import java.util.*; public class StackHelper { private int in; private int out; private int local; private int frame_size; private HashMap idx_to_addr; public StackHelper(VFunction.Stack s) { this.in = s.in; this.out = s.out; this.local = s.local; this.frame_size = this.stackFrameFormula(); this.idx_to_addr = new HashMap(); MinimalLogger.info(String.format("Found in:%d out:%d local%d framesize:%d...", this.in, this.out, this.local, this.frame_size)); String key; String value; int loc; for (int i = 0; i < this.local; ++i) { // locals loc = (( -i - 1 ) * 4) - 8; key = String.format("Local[%d]", i); value = String.format("%d($fp)", loc); this.idx_to_addr.put(key, value); } for (int i = 0; i < this.out; ++i) { // out loc = ((this.out + this.local + 2) - i) * -4; key = String.format("Out[%d]", i); value = String.format("%d($fp)", loc); this.idx_to_addr.put(key, value); } for (int i = 0; i < this.in; ++i) { // in loc = i * 4; key = String.format("In[%d]", i); value = String.format("%d($fp)", loc); this.idx_to_addr.put(key, value); } MinimalLogger.info(String.format("Mapping: %s", this.idx_to_addr.toString())); } public String get(VMemRef.Stack m) { String key = String.format("%s[%d]", m.region, m.index); MinimalLogger.severe(key); return this.idx_to_addr.get(key); } public int getFrameSize() { return this.frame_size; } private int stackFrameFormula() { return (this.out + this.local + 2) * 4; } }