diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-05-06 00:59:26 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-05-06 00:59:26 -0600 |
commit | 8e33e2828ffc62238afc32bb2593b8619f586077 (patch) | |
tree | 60158e69db97739d5e7512210f53c9d2f99fc62d /condense/StackHelper.java | |
parent | 925372248bfb45e0027cf71d8d40c26e48261ee5 (diff) |
Partial implementation for starter Condense
Diffstat (limited to 'condense/StackHelper.java')
-rw-r--r-- | condense/StackHelper.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/condense/StackHelper.java b/condense/StackHelper.java new file mode 100644 index 0000000..a0a6e2d --- /dev/null +++ b/condense/StackHelper.java @@ -0,0 +1,70 @@ +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<String, String> 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<String,String>(); + 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; + } + +} |