001: /*
002: * @(#)CVMOffsetsHeader.java 1.15 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package runtime;
029:
030: import consts.Const;
031: import jcc.Util;
032: import util.*;
033: import components.*;
034: import vm.*;
035: import java.io.PrintStream;
036: import java.util.Enumeration;
037: import java.util.Vector;
038: import java.util.Hashtable;
039:
040: public class CVMOffsetsHeader extends HeaderDump {
041:
042: private String cdelimClassName = null;
043:
044: public CVMOffsetsHeader() {
045: super ('_');
046: }
047:
048: private void prolog() {
049: o
050: .println("/* DO NOT EDIT THIS FILE - it is machine generated */\n"
051: + "#include \"javavm/include/defs.h\"\n"
052: + "#include \"javavm/include/objects.h\"\n"
053: + "#include \"javavm/include/classes.h\"\n");
054: o.println("/* Header for class " + className + " */\n");
055: String includeName = "_CVM_OFFSETS_" + cdelimClassName;
056: o.println("#ifndef " + includeName);
057: o.println("#define " + includeName + "\n");
058: }
059:
060: private void epilog() {
061: o.println("\n#endif");
062: }
063:
064: synchronized public boolean dumpHeader(ClassInfo c,
065: PrintStream outfile) {
066: boolean didWork = false;
067: o = outfile;
068: className = c.className;
069: cdelimClassName = strsub(className, CDelim);
070: prolog();
071: // Note: Should deal with > 255 fields.
072: // Today is not that day. Just do the simple case.
073: FieldInfo m[] = c.fields;
074: if ((m == null) || (m.length == 0)) {
075: outfile.println("/* No fields for class " + cdelimClassName
076: + " */\n");
077: return true;
078: }
079: int nfields = m.length;
080: String prefix = "CVMoffsetOf" + cdelimClassName + "_";
081: for (int i = 0; i < nfields; i++) {
082: FieldInfo f = m[i];
083: // static members use simple byte offset
084: // instance members include size of header info
085: if (!f.isStaticMember()) {
086: didWork = true;
087: outfile.print("#define ");
088: outfile.print(prefix + f.name.string + " \t");
089: outfile.println("CVM_FIELD_OFFSET(" + f.instanceOffset
090: + ")");
091: }
092: }
093: if (!didWork) {
094: outfile.println("/* No instance fields for class "
095: + cdelimClassName + " */\n");
096: }
097: epilog();
098: return true;
099: }
100:
101: }
|