001: /*
002: *
003: *
004: * Copyright 1990-2007 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: package runtime;
028:
029: import jcc.Util;
030: import util.*;
031: import components.*;
032: import vm.*;
033: import java.io.PrintStream;
034: import java.util.Enumeration;
035: import java.util.Vector;
036: import java.util.Hashtable;
037: import jcc.Const;
038:
039: abstract public class HeaderDump {
040: char CDelim;
041: final static char DIR_DELIM = '/';
042: final static char INNER_DELIM = '$';
043:
044: public HeaderDump(char cdelim) {
045: CDelim = cdelim;
046: }
047:
048: public String filename(String classname) {
049: return Util.convertToClassName(classname);
050: }
051:
052: // this data is really per-header.
053: // it is guarded by synchronous method access
054: PrintStream o;
055: String className;
056:
057: static String strsub(String src, char substitute) {
058: return src.replace(DIR_DELIM, substitute).replace(INNER_DELIM,
059: substitute);
060: }
061:
062: protected boolean generateConsts(String classname,
063: FieldInfo fields[]) {
064: if (fields == null)
065: return false;
066: boolean didWork = false;
067: for (int i = 0; i < fields.length; i++) {
068: FieldInfo f = fields[i];
069: if (f.value == null)
070: continue; // not a constant.
071: String constName = classname + CDelim + f.name.string;
072: o.println("#undef " + constName);
073: ConstantObject v = f.value;
074: DoubleValueConstant dvc;
075: switch (v.tag) {
076: case Const.CONSTANT_FLOAT:
077: float fval = Float
078: .intBitsToFloat(((SingleValueConstant) v).value);
079: o.println("#define " + constName + " " + fval + "f");
080: break;
081: case Const.CONSTANT_DOUBLE:
082: dvc = (DoubleValueConstant) v;
083: double dval = Double
084: .longBitsToDouble((((long) (dvc.highVal)) << 32)
085: | ((long) dvc.lowVal & 0xffffffffL));
086: o.println("#define " + constName + " " + dval + "D");
087: break;
088:
089: case Const.CONSTANT_LONG:
090: dvc = (DoubleValueConstant) v;
091: long lval = (((long) (dvc.highVal)) << 32)
092: | ((long) dvc.lowVal & 0xffffffffL);
093: o.println("#define " + constName + " " + lval + "LL");
094: break;
095: case Const.CONSTANT_INTEGER:
096: int ival = ((SingleValueConstant) v).value;
097: o.println("#define " + constName + " " + ival + "L");
098: break;
099: default:
100: }
101: didWork = true;
102: }
103: return didWork;
104: }
105:
106: // returns true if anything worthwhile got written,
107: // else false.
108: abstract public boolean dumpHeader(ClassInfo c, PrintStream outfile);
109:
110: abstract public boolean dumpExternals(ClassInfo c,
111: PrintStream outfile);
112: }
|