⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kvmwriter.java

📁 已经移植好的java虚拟机
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                out.print("CLASS(" + c.getNativeName() + ")");            } else {                System.out.println("Unresolved class constant: "+value.toString() );		formatError = true;		out.print("UNKNOWN()");            }            break;        case Const.CONSTANT_METHOD:        case Const.CONSTANT_INTERFACEMETHOD:            if ( value.isResolved() ){                MethodInfo mi = ((MethodConstant)value).find();                ClassInfo  ci = mi.parent;                EVMClass   EVMci = (EVMClass)(ci.vmClass);		out.print("METHOD(" + EVMci.getNativeName() 			  + ", " + mi.index + ")");		if (verbose) { 		    out.print(" /* " + prettyName(mi) + " */");		}            } else {		formatError = true;		out.print("UNKNOWN()");                System.out.println("Unresolved method constant: "+value.toString() );            }            break;        case Const.CONSTANT_FIELD:            if ( value.isResolved() ){                FieldInfo fi = ((FieldConstant)value).find();                ClassInfo ci = fi.parent;                String className = ((EVMClass)(ci.vmClass)).getNativeName();		out.print("FIELD(" + className + ", " + fi.index + ")");		if (verbose) { 		    out.print(" /* " + prettyName(fi) + " */");		}	    } else {		formatError = true;		out.print("UNKNOWN()");                System.out.print("Unresolved field constant: "+value.toString() );            }            break;        default:	    formatError = true;	    out.print("UNKNOWN()");            System.out.print("ERROR: constant " + value.tag);        }    }    /*     * These are macros to encapsulate some of the messiness     * of data definitions. They are, perhaps, compiler-specific.     */    protected static String stdHeader[] = {        "#define COMPILING_ROMJAVA 1",        "",        "#include <global.h>",        "#include \"rom.h\"",        "",        "#if ROMIZING",        ""    };    protected void writeProlog(){	java.util.Date date = new java.util.Date();        out.println("/* This is a generated file.  Do not modify.");        out.println(" * Generated on " + date);        out.println(" */\n");	out.println();	out.println("#define ROM_GENERATION_DATE \"" + date + "\"");	out.println();        for ( int i = 0; i < stdHeader.length; i++ ){            out.println( stdHeader[i] );        }    }        String publicClasses[][] =               { {"JavaLangObject",    "java/lang/Object"   },                {"JavaLangClass",     "java/lang/Class"    },                 {"JavaLangString",    "java/lang/String"   },                 {"JavaLangThread",    "java/lang/Thread"   },                {"JavaLangSystem",    "java/lang/System"   },                {"JavaLangThrowable", "java/lang/Throwable"},                {"JavaLangError",     "java/lang/Error"},              };                               String publicNameTypes[][] =               { { "initNameAndType",   "<init>",   "()V"   },                { "clinitNameAndType", "<clinit>", "()V"   },                { "runNameAndType",    "run",      "()V"   },                { "mainNameAndType",   "main",     "([Ljava/lang/String;)V"}              };    String mayNotBeRenamed[] =               {                  "runCustomCode",              };    protected void writeEpilog() {                                   String epilogCode[] = {            "void InitializeROMImage() { ",            "    memcpy(" + staticStoreName + ", &" + masterStaticStoreName + ", sizeof(KVM_staticData));",            "}",            "",            "void FinalizeROMImage() { ",            "    finalizeROMHashTable(UTFStringTable, offsetof(struct UTF_Hash_Entry, next));",             "    finalizeROMHashTable(InternStringTable, offsetof(struct internedStringInstanceStruct, next));",            "    finalizeROMHashTable(ClassTable, offsetof(struct classStruct, next));",             "    KVM_staticData[0] = 0;",            "}", 	    "",             "#if INCLUDEDEBUGCODE",	    "bool_t isROMString(void *x) { ",	    "    if (x == (void *)(&stringCharArrayInternal.ofClass)) { ", 	    "        return TRUE;", 	    "    } else { ", 	    "        void *start = (void *)&stringArrayInternal[0];", 	    "        void *end = (void *)((char *)start + sizeof(stringArrayInternal));", 	    "        return x >= start && x < end;",	    "    }", 	    "}", 	    "", 	    "bool_t isROMClass(void *x) { ", 	    "    void *start = (void *)&AllClassblocks;", 	    "    void *end  = (void *)((char *)start + sizeof(AllClassblocks));",	    "    return x >= start && x < end;", 	    "}",             "#endif", 	    "",             "#endif"        };                for (int i = 0; i < publicClasses.length; i++) {            String[] pair = publicClasses[i];            String globalName = pair[0];            String className = pair[1];            ClassInfo ci = ClassInfo.lookupClass(className);            EVMClass cc = (EVMClass)ci.vmClass;            String type = cc.isArrayClass() ? "ARRAY_CLASS" : "INSTANCE_CLASS";            out.println(type + " " + globalName + " = (" + type + ")&" +			"AllClassblocks." + cc.getNativeName() + ";");        }        for (int i = 0; i < publicNameTypes.length; i++) {            String triple[] = publicNameTypes[i];            String globalName = triple[0];            String methodName = triple[1];            String methodType = triple[2];            out.println("NameTypeKey " + globalName + " = "                         + classTable.getNameAndTypeKey(methodName, methodType) + ";");        }        out.println();        for (int i = 0; i < epilogCode.length; i++) {            out.println(epilogCode[i]);        }            }    public void     writeArray(int start, int length, 	       int columns, String indent, ArrayPrinter ap) {         CCodeWriter out = this.out;        int column = 0;        out.print(indent);          for ( int i = start; ; i++ ){            if (column >= columns) {                 out.print("\n" + indent);                column = 1;            } else {                column += 1;            }            ap.print(i);            if (i < (length - 1)) {                 out.print(", ");            } else {                 out.println(ap.finalComma() ? ", " : "");                break;            }        }    }    public void     writeArray(int length, int columns, String indent, ArrayPrinter ap) { 	writeArray(0, length, columns, indent, ap);    }        public String prettyName(MethodInfo mi) { 	String name = mi.name.string;	String type = mi.type.string;	int lastParen = type.lastIndexOf(')');	StringBuffer result = new StringBuffer();		/* First, put in the result type */	if (!name.equals("<init>") && !name.equals("<clinit>")) { 	    typeName(type, lastParen + 1, result);	    result.append(' ');	}	result.append(name).append('(');	for (int index = 1; index < lastParen; ) { 	    if (index > 1) { 		result.append(", ");	    }            index = typeName(type, index, result);        }	return result.append(')').toString();    }    public String prettyName(FieldInfo fi) { 	String name = fi.name.string;	String type = fi.type.string;	StringBuffer result = new StringBuffer();	typeName(type, 0, result);	return result.append(' ').append(name).toString();    }    private int    typeName(String type, int index, StringBuffer result) {	int end;	switch(type.charAt(index)) { 	    case 'V':  result.append("void");    return index + 1;	    case 'Z':  result.append("boolean"); return index + 1;	    case 'B':  result.append("byte");    return index + 1;	    case 'S':  result.append("short");   return index + 1;  	    case 'C':  result.append("char");    return index + 1;	    case 'I':  result.append("int");     return index + 1;	    case 'J':  result.append("long");    return index + 1;	    case 'F':  result.append("float");   return index + 1;	    case 'D':  result.append("double");  return index + 1; 	    case 'L': { 		end = type.indexOf(';', index) + 1;		String className = type.substring(index + 1, end - 1);		if (className.startsWith("java/lang/")) { 		    className = className.substring(10);		}		result.append(className.replace('/', '.'));		return end;	    }	    case '[': { 		end = typeName(type, index + 1, result);		result.append("[]");		return end;	    }	    default:		System.err.println("Unrecognized character");		result.append("XXXX");		return index + 1;	}    }    public void printSpaceStats( java.io.PrintStream o ){        ClassClass classes[] = ClassClass.getClassVector( classMaker );        o.println(Localizer.getString("cwriter.total_classes", Integer.toString(classes.length)));        o.println(Localizer.getString("cwriter.method_blocks", Integer.toString(nmethods)));        o.println(Localizer.getString("cwriter.bytes_java_code", Integer.toString(ncodebytes)));        o.println(Localizer.getString("cwriter.catch_frames", Integer.toString(ncatchframes)));        o.println(Localizer.getString("cwriter.field_blocks", Integer.toString(nfields)));        o.println(Localizer.getString("cwriter.constant_pool_entries", Integer.toString(nconstants)));        o.println(Localizer.getString("cwriter.java_strings",Integer.toString(njavastrings)));    }        abstract public static class ArrayPrinter {         abstract void print(int index);        boolean finalComma() { return false; }    }    public static class ArrayEqual {         Object array;        ArrayEqual(byte[] x) { this.array = x; }        public int hashCode() {             byte[] a = (byte[])array;            int total = 0;            for (int i = 0; i < a.length; i++) {                 total = (total * 3) + a[i];            }            return total;        }        public boolean equals(Object y) {             if (this.getClass() != y.getClass()) {                 return false;            }            byte[] a = (byte[])array;            byte[] b = (byte[])((ArrayEqual)y).array;            if (a.length != b.length) {                 return false;            }            for (int i = 0; i < a.length; i++) {                 if (a[i] != b[i]) {                     return false;                }            }            return true;        }    }    // Allow code and methods to be broken up into smaller pieces, if    // necessary    class SectionCounter { 	int maxOffset;	int offset, totalLength;	boolean inDefinitions;	int section;	SectionCounter(int maxOffset) { 	    this.maxOffset = maxOffset; 	}		public static final boolean Definition = true;	public static final boolean Initialization = false;	public void startFirstSection(boolean inDefinitions) { 	    this.inDefinitions = inDefinitions;	    offset = 0;	    totalLength = 0;	    section = 1;	    startSection();	}		public void endLastSection() { 	    endSection(true);	}	public void notNextSection(int thisLength) { 	    // Indicate that we're adding a small item, that	    // for padding purposes or otherwise, must remain with the	    // previous section.	    offset += thisLength;	}	public void maybeNextSection(int thisLength) { 	    // Start a new section, if necessary	    if (offset + thisLength > maxOffset) { 		endSection(false);		section++;		startSection();	    }	    offset += thisLength;	}	private void startSection() { 	    // Start a new section	    out.println(inDefinitions ? "\tstruct {" : "\t{");	}	private void endSection(boolean last) { 	    // End the current section.  What is the purpose of "dummy"?	    // 	    // PalmMain.c adds two bytes to the end of each resource, and	    // modifies the size to reflect this.  There might be some	    // ambiguity as to whether a specific address is the end of	    // one resource, or the beginning of the next.  So we put a	    // little bit of space between the resources to make sure that	    // there is no ambiguity.	    if (inDefinitions) { 		out.println("\t} section" + section + ";");		if (!last) { 		    out.println("\tlong dummy" + section + ";");		}	    } else { 		String info = 		    "/* section " + section + " (size " + offset + ") */";		if (!last) { 		    out.println("\t}, " + info);		    out.println("\t0, /* dummy separator */");		} else { 		    out.println("\t} " + info);		}	    }	    totalLength += offset;	    offset = 0;	}		int getSection() { return section; }	int getOffset() { return offset; }	int getTotalLength() { return totalLength; }	void printRelocationInfo(String structure, String name) { 	    out.println("#define NUMBER_OF_" + name + "_RESOURCES " + section);	    out.println("#define ALL_" + name + "_RESOURCES  \\");	    for (int i = 1; i <= section; i++) { 		out.println("\t\tSTRUCTURE_ENTRY(" + structure + ".section" 			    + i + ")" + (i == section ? "" : ", \\"));	    }	}    }    // Here so that PALMWriter can override it.    protected void writeRelocationFile(ClassClass classes[]) {     }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -