1 cananian 1.1.2.5 // SEGMENT.java, created Tue Jul 27 12:43:42 1999 by duncan 2 cananian 1.1.2.4 // Copyright (C) 1998 Duncan Bryce <duncan@lcs.mit.edu> 3 cananian 1.1.2.4 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 duncan 1.1.2.1 package harpoon.IR.Tree; 5 duncan 1.1.2.1 6 duncan 1.1.2.1 import harpoon.ClassFile.HCodeElement; 7 cananian 1.1.2.19 import harpoon.Temp.TempMap; 8 duncan 1.1.2.1 import harpoon.Util.Util; 9 duncan 1.1.2.1 10 cananian 1.1.2.14 import java.util.Collections; 11 duncan 1.1.2.1 import java.util.Set; 12 duncan 1.1.2.1 13 duncan 1.1.2.1 /** 14 duncan 1.1.2.1 * The <code>SEGMENT</code> class is used to mark the beginning of a new 15 duncan 1.1.2.1 * section of memory. All subsequent <code>Tree</code> objects will be 16 duncan 1.1.2.1 * stored in the specified section. 17 duncan 1.1.2.1 * 18 duncan 1.1.2.1 * @author Duncan Bryce <duncan@lcs.mit.edu> 19 cananian 1.4 * @version $Id: SEGMENT.java,v 1.4 2002/04/10 03:05:45 cananian Exp $ 20 duncan 1.1.2.1 */ 21 cananian 1.1.2.11 public class SEGMENT extends Stm implements harpoon.ClassFile.HDataElement { 22 cananian 1.1.2.8 /** R/O storage for static class data (display, vmtable, etc) */ 23 duncan 1.1.2.7 public static final int CLASS = 0; 24 duncan 1.1.2.2 /** Read-only instruction memory */ 25 duncan 1.1.2.7 public static final int CODE = 1; 26 cananian 1.1.2.8 /** R/O storage for GC tables */ 27 duncan 1.1.2.7 public static final int GC = 2; 28 duncan 1.1.2.7 /** R/W memory that must be initialized before use */ 29 duncan 1.1.2.10 public static final int INIT_DATA = 3; 30 cananian 1.1.2.13 /** R/O memory that stores reflection data objects. */ 31 cananian 1.1.2.13 public static final int REFLECTION_OBJECTS = 4; 32 cananian 1.1.2.13 /** R/O memory that stores reflection tables and other non-object data. */ 33 duncan 1.1.2.10 public static final int REFLECTION_DATA = 5; 34 cananian 1.1.2.8 /** R/W storage for static aggregate data */ 35 duncan 1.1.2.10 public static final int STATIC_OBJECTS = 6; 36 cananian 1.1.2.8 /** R/W storage for static primitive data */ 37 duncan 1.1.2.10 public static final int STATIC_PRIMITIVES = 7; 38 cananian 1.1.2.8 /** R/O storage for string constant objects */ 39 duncan 1.1.2.10 public static final int STRING_CONSTANTS = 8; 40 cananian 1.1.2.8 /** R/O storage for component character arrays of statically allocated 41 cananian 1.1.2.8 * string constant objects. */ 42 duncan 1.1.2.10 public static final int STRING_DATA = 9; 43 duncan 1.1.2.7 /** Read-only memory (other than machine instructions) */ 44 duncan 1.1.2.10 public static final int TEXT = 10; 45 duncan 1.1.2.7 /** R/W memory initialized at load time to be 0 */ 46 duncan 1.1.2.10 public static final int ZERO_DATA = 11; 47 kkz 1.1.2.17 /** R/O storage for GC index */ 48 kkz 1.1.2.17 public static final int GC_INDEX = 12; 49 cananian 1.1.2.23 50 cananian 1.1.2.23 /** Converts a segtype string into its enumerated value. 51 cananian 1.1.2.23 * Returns -1 if the string does not represent a valid segtype. */ 52 cananian 1.1.2.23 public static final int encode(String segtype) { 53 cananian 1.1.2.23 segtype = segtype.intern(); 54 cananian 1.1.2.23 if (segtype=="CLASS") return CLASS; 55 cananian 1.1.2.23 if (segtype=="CODE") return CODE; 56 cananian 1.1.2.23 if (segtype=="GC") return GC; 57 cananian 1.1.2.23 if (segtype=="INIT_DATA") return INIT_DATA; 58 cananian 1.1.2.23 if (segtype=="REFLECTION_OBJECTS") return REFLECTION_OBJECTS; 59 cananian 1.1.2.23 if (segtype=="REFLECTION_DATA") return REFLECTION_DATA; 60 cananian 1.1.2.23 if (segtype=="STATIC_OBJECTS") return STATIC_OBJECTS; 61 cananian 1.1.2.23 if (segtype=="STATIC_PRIMITIVES") return STATIC_PRIMITIVES; 62 cananian 1.1.2.23 if (segtype=="STRING_CONSTANTS") return STRING_CONSTANTS; 63 cananian 1.1.2.23 if (segtype=="STRING_DATA") return STRING_DATA; 64 cananian 1.1.2.23 if (segtype=="TEXT") return TEXT; 65 cananian 1.1.2.23 if (segtype=="ZERO_DATA") return ZERO_DATA; 66 cananian 1.1.2.23 if (segtype=="GC_INDEX") return GC_INDEX; 67 cananian 1.1.2.23 return -1; 68 cananian 1.1.2.23 } 69 pnkfelix 1.1.2.6 70 pnkfelix 1.1.2.6 /** Converts a segtype into its string representation. 71 pnkfelix 1.1.2.6 */ 72 pnkfelix 1.1.2.6 public static final String decode(int segtype) { 73 pnkfelix 1.1.2.6 switch(segtype) { 74 duncan 1.1.2.9 case CLASS: return "CLASS"; 75 duncan 1.1.2.9 case CODE: return "CODE"; 76 duncan 1.1.2.9 case GC: return "GC"; 77 duncan 1.1.2.9 case INIT_DATA: return "INIT_DATA"; 78 cananian 1.1.2.13 case REFLECTION_OBJECTS: return "REFLECTION_OBJECTS"; 79 duncan 1.1.2.10 case REFLECTION_DATA: return "REFLECTION_DATA"; 80 duncan 1.1.2.9 case STATIC_OBJECTS: return "STATIC_OBJECTS"; 81 duncan 1.1.2.9 case STATIC_PRIMITIVES: return "STATIC_PRIMITIVES"; 82 duncan 1.1.2.9 case STRING_CONSTANTS: return "STRING_CONSTANTS"; 83 duncan 1.1.2.9 case STRING_DATA: return "STRING_DATA"; 84 duncan 1.1.2.9 case TEXT: return "TEXT"; 85 duncan 1.1.2.9 case ZERO_DATA: return "ZERO_DATA"; 86 kkz 1.1.2.17 case GC_INDEX: return "GC_INDEX"; 87 duncan 1.1.2.9 default: 88 cananian 1.3.2.1 assert false : "Unknown segment type "+segtype; 89 duncan 1.1.2.9 return null; 90 pnkfelix 1.1.2.6 } 91 pnkfelix 1.1.2.6 } 92 duncan 1.1.2.1 93 duncan 1.1.2.1 /** The type of segment this <code>SEGMENT</code> precedes. */ 94 duncan 1.1.2.1 public final int segtype; 95 duncan 1.1.2.1 96 duncan 1.1.2.1 /** Class constructor. 97 duncan 1.1.2.1 * <code>segtype</code> must be one the segments types specified 98 duncan 1.1.2.1 * in this class. */ 99 duncan 1.1.2.1 public SEGMENT(TreeFactory tf, HCodeElement source, int segtype) { 100 cananian 1.1.2.18 super(tf, source, 0); 101 duncan 1.1.2.1 this.segtype = segtype; 102 cananian 1.3.2.1 assert segtype>=0 && segtype<13; 103 duncan 1.1.2.1 } 104 duncan 1.1.2.1 105 duncan 1.1.2.1 public int kind() { return TreeKind.SEGMENT; } 106 duncan 1.1.2.1 107 duncan 1.1.2.3 public Stm build(TreeFactory tf, ExpList kids) { 108 duncan 1.1.2.3 return new SEGMENT(tf, this, segtype); 109 duncan 1.1.2.3 } 110 duncan 1.1.2.1 111 duncan 1.1.2.1 /** Accept a visitor */ 112 cananian 1.1.2.14 public void accept(TreeVisitor v) { v.visit(this); } 113 duncan 1.1.2.1 114 cananian 1.1.2.19 public Tree rename(TreeFactory tf, TempMap tm, CloneCallback cb) { 115 cananian 1.1.2.20 return cb.callback(this, new SEGMENT(tf, this, segtype), tm); 116 duncan 1.1.2.1 } 117 duncan 1.1.2.1 118 duncan 1.1.2.1 public String toString() { 119 duncan 1.1.2.9 return "SEGMENT<" + decode(segtype) + ">"; 120 duncan 1.1.2.1 } 121 cananian 1.2 }