1 cananian 1.1.4.1 // DefaultFrame.java, created Mon Feb 15 3:36:39 1999 by duncan 2 cananian 1.1.4.1 // Copyright (C) 1998 Duncan Bryce <duncan@lcs.mit.edu> 3 cananian 1.1.4.1 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 cananian 1.1.4.1 package harpoon.Interpret.Tree; 5 cananian 1.1.4.1 6 cananian 1.1.4.1 import harpoon.Analysis.ClassHierarchy; 7 kkz 1.1.4.12 import harpoon.Backend.Generic.GCInfo; 8 cananian 1.1.4.1 import harpoon.Backend.Generic.InstrBuilder; 9 pnkfelix 1.1.4.8 import harpoon.Backend.Generic.TempBuilder; 10 cananian 1.1.4.3 import harpoon.Backend.Generic.LocationFactory; 11 cananian 1.1.4.1 import harpoon.Backend.Generic.RegFileInfo; 12 cananian 1.1.4.1 import harpoon.Backend.Generic.Runtime; 13 cananian 1.1.4.1 import harpoon.ClassFile.HCodeElement; 14 cananian 1.1.4.15 import harpoon.ClassFile.HCodeFactory; 15 cananian 1.1.4.7 import harpoon.ClassFile.HMethod; 16 cananian 1.1.4.9 import harpoon.ClassFile.Linker; 17 cananian 1.1.4.1 import harpoon.IR.Assem.Instr; 18 cananian 1.1.4.1 import harpoon.IR.Assem.InstrEdge; 19 cananian 1.1.4.1 import harpoon.IR.Assem.InstrMEM; 20 cananian 1.1.4.1 import harpoon.IR.Assem.InstrLABEL; 21 cananian 1.1.4.1 import harpoon.IR.Assem.InstrFactory; 22 cananian 1.1.4.1 import harpoon.IR.Tree.Exp; 23 cananian 1.1.4.1 import harpoon.IR.Tree.CONST; 24 cananian 1.1.4.1 import harpoon.IR.Tree.MEM; 25 cananian 1.1.4.1 import harpoon.IR.Tree.MOVE; 26 cananian 1.1.4.1 import harpoon.IR.Tree.NAME; 27 cananian 1.1.4.1 import harpoon.IR.Tree.SEQ; 28 cananian 1.1.4.1 import harpoon.IR.Tree.Stm; 29 cananian 1.1.4.1 import harpoon.IR.Tree.TEMP; 30 cananian 1.1.4.1 import harpoon.IR.Tree.TreeFactory; 31 cananian 1.1.4.1 import harpoon.IR.Tree.Type; 32 cananian 1.1.4.1 import harpoon.Temp.CloningTempMap; 33 cananian 1.1.4.1 import harpoon.Temp.Label; 34 cananian 1.1.4.1 import harpoon.Temp.Temp; 35 cananian 1.1.4.1 import harpoon.Temp.TempFactory; 36 cananian 1.1.4.1 import harpoon.Util.Util; 37 cananian 1.1.4.1 38 cananian 1.1.4.1 import java.util.List; 39 cananian 1.1.4.1 import java.util.Iterator; 40 cananian 1.1.4.1 import java.util.Map; 41 cananian 1.1.4.1 import java.util.Set; 42 cananian 1.1.4.1 43 cananian 1.1.4.1 /** 44 cananian 1.1.4.1 * The DefaultFrame class implements the abstract methods of the 45 cananian 1.1.4.1 * Frame class. It is intended mostly for testing purposes, and 46 cananian 1.1.4.1 * will have to be fixed up a bit if needed for general use. 47 cananian 1.1.4.1 * 48 cananian 1.1.4.1 * @author Duncan Bryce <duncan@lcs.mit.edu> 49 cananian 1.4 * @version $Id: DefaultFrame.java,v 1.4 2002/04/10 03:05:56 cananian Exp $ 50 cananian 1.1.4.1 */ 51 cananian 1.1.4.1 public class DefaultFrame extends harpoon.Backend.Generic.Frame 52 cananian 1.1.4.1 implements AllocationInfo { 53 cananian 1.1.4.1 54 cananian 1.1.4.1 private ClassHierarchy m_classHierarchy; 55 cananian 1.1.4.1 private AllocationStrategy m_allocator; 56 cananian 1.1.4.1 private Temp m_nextPtr; 57 cananian 1.1.4.1 private Temp m_memLimit; 58 cananian 1.1.4.1 private OffsetMap m_offsetMap; 59 cananian 1.1.4.1 private Runtime m_runtime; 60 cananian 1.1.4.1 private TempFactory m_tempFactory; 61 cananian 1.1.4.1 private static Temp[] registers; 62 cananian 1.1.4.1 private static TempFactory regTempFactory; 63 cananian 1.1.4.9 private final Linker linker; 64 cananian 1.1.4.1 65 cananian 1.1.4.1 static { 66 cananian 1.1.4.1 regTempFactory = new TempFactory() { 67 cananian 1.1.4.1 private int i = 0; 68 cananian 1.1.4.1 private final String scope = "registers"; 69 cananian 1.1.4.1 private final String[] names = {"r0", "r1", "r2", "r3", "r4", "r5", 70 cananian 1.1.4.1 "r6", "r7", "r8", "r9", "r10", 71 cananian 1.1.4.1 "fp", "ip", "sp", "lr", "pc"}; 72 cananian 1.1.4.1 73 cananian 1.1.4.1 public String getScope() { return scope; } 74 cananian 1.1.4.1 protected synchronized String getUniqueID(String suggestion) { 75 cananian 1.3.2.1 assert i < names.length : "Don't use the "+ 76 cananian 1.3.2.1 "TempFactory of Register bound Temps"; 77 cananian 1.1.4.1 i++; 78 cananian 1.1.4.1 return names[i-1]; 79 cananian 1.1.4.1 } 80 cananian 1.1.4.1 }; 81 cananian 1.1.4.1 registers = new Temp[16]; 82 cananian 1.1.4.1 for (int i = 0; i < 16; i++) { 83 cananian 1.1.4.1 registers[i] = new Temp(regTempFactory); 84 cananian 1.1.4.1 } 85 cananian 1.1.4.1 } 86 cananian 1.1.4.1 87 cananian 1.1.4.1 88 cananian 1.1.4.7 public DefaultFrame(HMethod main, ClassHierarchy ch, OffsetMap map, AllocationStrategy st) { 89 cananian 1.1.4.9 linker = main.getDeclaringClass().getLinker(); 90 cananian 1.1.4.1 m_classHierarchy = ch; 91 cananian 1.1.4.1 m_allocator = st==null?new DefaultAllocationStrategy(this):st; 92 cananian 1.1.4.1 m_tempFactory = Temp.tempFactory(""); 93 cananian 1.1.4.1 m_nextPtr = new Temp(m_tempFactory); 94 cananian 1.1.4.1 m_memLimit = new Temp(m_tempFactory); 95 cananian 1.1.4.1 if (map==null) throw new Error("Must specify OffsetMap"); 96 cananian 1.1.4.1 else m_offsetMap = map; 97 cananian 1.1.4.18 m_runtime = new harpoon.Backend.Runtime1.Runtime(this, null, main, false); 98 cananian 1.1.4.18 setClassHierarchy(ch); 99 cananian 1.1.4.1 } 100 kkz 1.1.4.12 101 cananian 1.1.4.9 public Linker getLinker() { return linker; } 102 cananian 1.1.4.9 103 cananian 1.1.4.1 /** Returns a <code>Tree.Exp</code> object which represents a pointer 104 cananian 1.1.4.1 * to a newly allocated block of memory, of the specified size. 105 cananian 1.1.4.1 * Generates code to handle garbage collection, and OutOfMemory errors. 106 cananian 1.1.4.1 */ 107 cananian 1.1.4.1 public Exp memAlloc(Exp size) { 108 cananian 1.1.4.1 return m_allocator.memAlloc(size); 109 cananian 1.1.4.1 } 110 cananian 1.1.4.1 111 cananian 1.1.4.1 public OffsetMap getOffsetMap() { 112 cananian 1.1.4.1 return m_offsetMap; 113 cananian 1.1.4.1 } 114 cananian 1.1.4.1 public Runtime getRuntime() { 115 cananian 1.1.4.1 return m_runtime; 116 cananian 1.1.4.1 } 117 cananian 1.1.4.1 118 cananian 1.1.4.1 public boolean pointersAreLong() { 119 cananian 1.1.4.1 return false; 120 cananian 1.1.4.1 } 121 cananian 1.1.4.1 122 cananian 1.1.4.1 public TempFactory tempFactory() { 123 cananian 1.1.4.1 return m_tempFactory; 124 cananian 1.1.4.1 } 125 cananian 1.1.4.1 126 cananian 1.1.4.1 public Stm procPrologue(TreeFactory tf, HCodeElement src, 127 cananian 1.1.4.1 Temp[] paramdsts, int[] paramtypes) { 128 cananian 1.3.2.1 assert tf != null : "tf is null"; 129 cananian 1.1.4.1 Stm prologue = null; 130 cananian 1.1.4.1 Stm move = null; 131 cananian 1.1.4.1 int i = 0; 132 cananian 1.1.4.1 for (i = 0; i < paramdsts.length && i < 16; i++) { 133 cananian 1.1.4.1 move = new MOVE(tf, src, 134 cananian 1.1.4.1 new TEMP(tf, src, paramtypes[i], paramdsts[i]), 135 cananian 1.1.4.1 new TEMP(tf, src, paramtypes[i], registers[i])); 136 cananian 1.1.4.1 if (prologue == null) { 137 cananian 1.1.4.1 prologue = move; 138 cananian 1.1.4.1 } else { 139 cananian 1.1.4.1 prologue = new SEQ(tf, src, move, prologue); 140 cananian 1.1.4.1 } 141 cananian 1.1.4.1 } 142 cananian 1.1.4.1 return prologue; 143 cananian 1.1.4.1 } 144 cananian 1.1.4.1 145 cananian 1.1.4.1 public Instr procLiveOnExit(Instr body) { 146 cananian 1.1.4.1 return body; 147 cananian 1.1.4.1 } 148 cananian 1.1.4.1 149 cananian 1.1.4.1 public Instr procAssemDirectives(Instr body) { 150 cananian 1.3.2.1 assert body != null; 151 cananian 1.1.4.1 152 cananian 1.1.4.1 HCodeElement src = body; 153 cananian 1.1.4.1 InstrFactory inf = ((Instr)src).getFactory(); 154 cananian 1.1.4.1 Instr dir1, dir2, dir3, dir4; 155 cananian 1.1.4.1 156 cananian 1.1.4.1 dir1 = new Instr(inf, src, ".text", null, null); 157 cananian 1.1.4.1 dir2 = new Instr(inf, src, ".align 0", null, null); 158 cananian 1.1.4.1 dir3 = new Instr(inf, src, ".global " + 159 cananian 1.1.4.1 inf.getMethod().getName() + ":", null, null); 160 cananian 1.1.4.1 dir4 = new Instr(inf, src, inf.getMethod().getName() + ":", 161 cananian 1.1.4.1 null, null); 162 cananian 1.1.4.1 163 cananian 1.1.4.1 dir1.insertAt(new InstrEdge(body.getPrev(), body)); 164 cananian 1.1.4.1 dir2.insertAt(new InstrEdge(dir1, body)); 165 cananian 1.1.4.1 dir3.insertAt(new InstrEdge(dir2, body)); 166 cananian 1.1.4.1 dir4.insertAt(new InstrEdge(dir3, body)); 167 cananian 1.1.4.1 return dir1; 168 cananian 1.1.4.1 } 169 cananian 1.1.4.1 170 cananian 1.1.4.1 /* Implementation of the DefaultAllocationInfo interface. 171 cananian 1.1.4.1 * NOTE that this is not really a realistic implementation, 172 cananian 1.1.4.1 * rather, it is a placeholder that allows me to test other 173 cananian 1.1.4.1 * parts of the code. 174 cananian 1.1.4.1 */ 175 cananian 1.1.4.1 public Label exitOutOfMemory() { return new Label("RUNTIME_OOM"); } 176 cananian 1.1.4.1 public Label GC() { return new Label("RUNTIME_GC"); } 177 cananian 1.1.4.1 public Temp getMemLimit() { return m_memLimit; } 178 cananian 1.1.4.1 public Temp getNextPtr() { return m_nextPtr; } 179 cananian 1.1.4.1 180 cananian 1.1.4.1 181 cananian 1.1.4.1 /** Not implemented. */ 182 cananian 1.1.4.1 public harpoon.Backend.Generic.CodeGen getCodeGen() { 183 cananian 1.3.2.1 assert false : "DefaultFrame.getCodeGen() Not implemented"; 184 cananian 1.1.4.1 return null; 185 cananian 1.1.4.1 } 186 cananian 1.1.4.1 187 cananian 1.1.4.1 /** Stub added by FSK. */ 188 cananian 1.1.4.1 public InstrBuilder getInstrBuilder() { 189 pnkfelix 1.1.4.8 return null; 190 pnkfelix 1.1.4.8 } 191 pnkfelix 1.1.4.8 /** Stub added by FSK. */ 192 pnkfelix 1.1.4.8 public TempBuilder getTempBuilder() { 193 cananian 1.1.4.3 return null; 194 cananian 1.1.4.3 } 195 cananian 1.1.4.3 /** Stub added by CSA. */ 196 cananian 1.1.4.3 public LocationFactory getLocationFactory() { 197 cananian 1.1.4.1 return null; 198 cananian 1.1.4.1 } 199 cananian 1.1.4.1 /** Stub added by FSK. */ 200 cananian 1.1.4.1 public RegFileInfo getRegFileInfo() { 201 cananian 1.1.4.1 return m_regfileinfo; 202 cananian 1.1.4.1 } 203 cananian 1.1.4.1 private final RegFileInfo m_regfileinfo = new RegFileInfo() { 204 cananian 1.1.4.1 public Set liveOnExit() { return java.util.Collections.EMPTY_SET; } 205 cananian 1.3.2.1 public Set callerSave() { assert false : "die"; return null; } 206 cananian 1.3.2.1 public Set calleeSave() { assert false : "die"; return null; } 207 cananian 1.1.4.1 public TempFactory regTempFactory() { return regTempFactory; } 208 pnkfelix 1.1.4.16 public boolean isRegister(Temp t) { 209 pnkfelix 1.1.4.16 return t.tempFactory() == regTempFactory(); 210 pnkfelix 1.1.4.16 } 211 cananian 1.1.4.1 public Iterator suggestRegAssignment(Temp t, Map regfile) { 212 cananian 1.1.4.1 /* stub */ 213 cananian 1.1.4.1 return null; 214 cananian 1.1.4.1 } 215 cananian 1.1.4.1 public Temp[] getAllRegisters() { 216 cananian 1.1.4.1 return (Temp[]) Util.safeCopy(Temp.arrayFactory, registers); 217 cananian 1.1.4.1 } 218 cananian 1.1.4.1 public Temp[] getGeneralRegisters() { 219 cananian 1.1.4.1 return (Temp[]) Util.safeCopy(Temp.arrayFactory, registers); 220 cananian 1.1.4.1 } 221 cananian 1.1.4.1 public Temp FP() { 222 cananian 1.1.4.1 return getRegister(2); 223 cananian 1.1.4.1 } 224 cananian 1.1.4.1 }; 225 kkz 1.1.4.13 /** There are no plans to ever have the <code>Tree</code> 226 kkz 1.1.4.13 interpreter support <code>GCInfo</code>, so 227 kkz 1.1.4.13 <code>getGCInfo</code> will always return null. 228 kkz 1.1.4.13 */ 229 kkz 1.1.4.12 public GCInfo getGCInfo() { 230 kkz 1.1.4.13 return null; 231 kkz 1.1.4.12 } 232 cananian 1.1.4.15 public HCodeFactory getCodeFactory(HCodeFactory hcf) { return null; } 233 cananian 1.1.4.1 } 234 cananian 1.1.4.1 235 cananian 1.1.4.1 236 cananian 1.1.4.1 237 cananian 1.1.4.1 238 cananian 1.1.4.1 239 cananian 1.2