1 pnkfelix 1.1.2.1 // NameMap.java, created Fri Aug  6 17:41:55 1999 by pnkfelix
  2 pnkfelix 1.1.2.1 // Copyright (C) 1999 Felix S. Klock II <pnkfelix@mit.edu>
  3 pnkfelix 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details.
  4 pnkfelix 1.1.2.1 package harpoon.Backend.Maps;
  5 pnkfelix 1.1.2.1 
  6 pnkfelix 1.1.2.1 import harpoon.ClassFile.HClass;
  7 cananian 1.1.2.4 import harpoon.ClassFile.HField;
  8 cananian 1.1.2.4 import harpoon.ClassFile.HMethod;
  9 pnkfelix 1.1.2.1 
 10 cananian 1.1.2.5 import harpoon.Temp.Label;
 11 pnkfelix 1.1.2.1 /**
 12 cananian 1.1.2.4  * <code>NameMap</code> gives a translation from methods, classes,
 13 cananian 1.1.2.4  * and fields to unique string labels legal in assembly code.
 14 pnkfelix 1.1.2.1  * 
 15 cananian 1.1.2.4  * @author  C. Scott Ananian <cananian@alumni.princeton.edu>
 16 salcianu 1.3      * @version $Id: NameMap.java,v 1.3 2003/04/19 01:03:54 salcianu Exp $
 17 pnkfelix 1.1.2.1  */
 18 salcianu 1.3     public abstract class NameMap implements java.io.Serializable {
 19 cananian 1.1.2.8     /** Maps a C function name to the appropriate label string.  For
 20 cananian 1.1.2.8      *  many platforms, the label string has an underscore prepended.
 21 cananian 1.1.2.8      *  For others, the label string is the function name exactly. */
 22 cananian 1.1.2.8     public abstract String c_function_name(String function_name);
 23 cananian 1.1.2.8 
 24 cananian 1.1.2.4     /** Mangle a method name. */
 25 cananian 1.1.2.4     public String mangle(HMethod hm) { return mangle(hm, null); }
 26 cananian 1.1.2.4     /** Mangle a method name, adding a uniqueness suffix.
 27 cananian 1.1.2.4      *  The generated string is guaranteed not to conflict with
 28 cananian 1.1.2.4      *  any other mangled string from a different method, field,
 29 cananian 1.1.2.4      *  or class, or any other mangled string from this method
 30 cananian 1.1.2.4      *  with a different suffix. The suffix may be <code>null</code>;
 31 cananian 1.1.2.4      *  the string returned in this case is idential to that
 32 cananian 1.1.2.4      *  obtained by a call to <code>mangle(hm)</code> (with no
 33 cananian 1.1.2.4      *  specified suffix). */
 34 cananian 1.1.2.4     public abstract String mangle(HMethod hm, String suffix);
 35 pnkfelix 1.1.2.2 
 36 cananian 1.1.2.4     /** Mangle a field name. */
 37 cananian 1.1.2.4     public String mangle(HField hf) { return mangle(hf, null); }
 38 cananian 1.1.2.4     /** Mangle a field name, adding a uniqueness suffix.
 39 cananian 1.1.2.4      *  The generated string is guaranteed not to conflict with
 40 cananian 1.1.2.4      *  any other mangled string from a different method, field,
 41 cananian 1.1.2.4      *  or class, or any other mangled string from this field
 42 cananian 1.1.2.4      *  with a different suffix. The suffix may be <code>null</code>;
 43 cananian 1.1.2.4      *  the string returned in this case is idential to that
 44 cananian 1.1.2.4      *  obtained by a call to <code>mangle(hf)</code> (with no
 45 cananian 1.1.2.4      *  specified suffix). */
 46 cananian 1.1.2.4     public abstract String mangle(HField hf, String suffix);
 47 pnkfelix 1.1.2.1 
 48 cananian 1.1.2.4     /** Mangle a class name. */
 49 cananian 1.1.2.4     public String mangle(HClass hc) { return mangle(hc, null); }
 50 cananian 1.1.2.4     /** Mangle a class name, adding a uniqueness suffix.
 51 cananian 1.1.2.4      *  The generated string is guaranteed not to conflict with
 52 cananian 1.1.2.4      *  any other mangled string from a different method, field,
 53 cananian 1.1.2.4      *  or class, or any other mangled string from this class
 54 cananian 1.1.2.4      *  with a different suffix. The suffix may be <code>null</code>;
 55 cananian 1.1.2.4      *  the string returned in this case is idential to that
 56 cananian 1.1.2.4      *  obtained by a call to <code>mangle(hf)</code> (with no
 57 cananian 1.1.2.4      *  specified suffix). */
 58 cananian 1.1.2.4     public abstract String mangle(HClass hc, String suffix);
 59 pnkfelix 1.1.2.1 
 60 cananian 1.1.2.4     /** Mangle a reference to a string constant. */
 61 cananian 1.1.2.4     public String mangle(String string_constant) {
 62 cananian 1.1.2.4         return mangle(string_constant, null);
 63 pnkfelix 1.1.2.1     }
 64 cananian 1.1.2.4     /** Mangle a reference to a string constant, adding a uniqueness
 65 cananian 1.1.2.4      *  suffix.  The generated string is guaranteed not to conflict
 66 cananian 1.1.2.4      *  with any other mangled string from any method, field, class,
 67 cananian 1.1.2.4      *  or string constant reference, or any other mangled reference
 68 cananian 1.1.2.4      *  to this string constant with a different suffix.  The suffix
 69 cananian 1.1.2.4      *  may be <code>null</code>; the string returned in this case is
 70 cananian 1.1.2.4      *  idential to that obtained by a call to
 71 cananian 1.1.2.4      *  <code>mangle(string_constant)</code> (with no specified
 72 cananian 1.1.2.4      *  suffix). */
 73 cananian 1.1.2.4     public abstract String mangle(String string_constant, String suffix);
 74 cananian 1.1.2.5 
 75 cananian 1.1.2.5     // CONVENIENCE CLASSES FOR COMMON CASES:
 76 cananian 1.1.2.5     /** Maps an <code>HClass</code> to a <code>Label</code> representing the 
 77 cananian 1.1.2.5      *  location of its class pointer  */
 78 cananian 1.1.2.5     public Label label(HClass hc) { return new Label(mangle(hc)); }
 79 cananian 1.1.2.6     /** Maps an <code>HClass</code> to a <code>Label</code> representing the
 80 cananian 1.1.2.6      *  class data structure associated with the given suffix. */
 81 cananian 1.1.2.6     public Label label(HClass hc, String suffix)
 82 cananian 1.1.2.6     { return new Label(mangle(hc, suffix)); }
 83 cananian 1.1.2.5     /** Maps a static <code>HField</code> to a <code>Label</code>. */
 84 cananian 1.1.2.5     public Label label(HField hf) { return new Label(mangle(hf)); }
 85 cananian 1.1.2.7     /** Maps an <code>HField</code> to a <code>Label</code> representing the
 86 cananian 1.1.2.7      *  field information structure associated with the given suffix. */
 87 cananian 1.1.2.7     public Label label(HField hf, String suffix)
 88 cananian 1.1.2.7     { return new Label(mangle(hf, suffix)); }
 89 cananian 1.1.2.5     /** Maps an <code>HMethod</code> to a <code>Label</code>. Note that
 90 cananian 1.1.2.5      *  the method does not have to be static or final; in many cases we
 91 cananian 1.1.2.5      *  can determine the identity of a virtual function exactly using 
 92 cananian 1.1.2.5      *  type information, and <code>label()</code> should return a
 93 cananian 1.1.2.5      *  <code>Label</code> we can use to take advantage of this information. */
 94 cananian 1.1.2.5     public Label label(HMethod hm) { return new Label(mangle(hm)); }
 95 cananian 1.1.2.7     /** Maps an <code>HMethod</code> to a <code>Label</code> representing the
 96 cananian 1.1.2.7      *  method information structure associated with the given suffix. */
 97 cananian 1.1.2.7     public Label label(HMethod hm, String suffix)
 98 cananian 1.1.2.7     { return new Label(mangle(hm, suffix)); }
 99 cananian 1.1.2.5     /** Maps a <code>String</code> constant to a <code>Label</code>. */
100 cananian 1.1.2.5     public Label label(String stringConstant) { return new Label(mangle(stringConstant)); }
101 cananian 1.1.2.6     /** Maps a <code>String</code> constant to a <code>Label</code>
102 cananian 1.1.2.6      *  representing the string data structure associated with the given
103 cananian 1.1.2.6      *  suffix. */
104 cananian 1.1.2.6     public Label label(String stringConstant, String suffix)
105 cananian 1.1.2.6     { return new Label(mangle(stringConstant, suffix)); }
106 cananian 1.2     }