void write(ClassEnv e, CodeAttr ce, DataOutputStream out) throws IOException, jasError { if (wide) { target.writeWideOffset(ce, source, out); } else { int offset = ce.getPc(target); if (source != null) offset -= ce.getPc(source); if (offset > 32767 || offset < -32768) throw new jasError("reference from line " + ref + " exceed size for short"); target.writeOffset(ce, source, out); } }
int size(ClassEnv ce, CodeAttr code) throws jasError { int sz = 8; // 4 + 4 + padding + jumptable int source_pc = code.getPc(source); if (((source_pc + 1) % 4) != 0) { // need padding sz += (4 - ((source_pc + 1) % 4)); } if (jmp != null) { sz += 8 * (jmp.length); } return sz; }
public static void main(String argv[]) throws jasError, IOException { // CodeAttr's contain the body of // a method. CodeAttr init = new CodeAttr(); init.addInsn(new Insn(opc_aload_0)); init.addInsn(new Insn(opc_invokenonvirtual, new MethodCP("java/lang/Object", "<init>", "()V"))); init.addInsn(new Insn(opc_return)); // ClassEnv's are used as a container // to hold all information about a class. ClassEnv nclass = new ClassEnv(); nclass.setClass(new ClassCP("out")); nclass.setSuperClass(new ClassCP("java/lang/Object")); // Add the init code to the class. nclass.addMethod((short) ACC_PUBLIC, "<init>", "()V", init, null); // write it all out nclass.write(new DataOutputStream(new FileOutputStream("out.class"))); }
int size(ClassEnv ce, CodeAttr code) throws jasError // the *real* reason for making it a // method.. { int sz = 12; // 4+4+4+jmptable+padding... int source_pc = code.getPc(source); if (((source_pc + 1) % 4) != 0) { // need padding sz += (4 - ((source_pc + 1) % 4)); } if (jmp != null) { sz += 4 * (jmp.length); } return sz; }
void write(ClassEnv e, CodeAttr ce, DataOutputStream out) throws IOException, jasError { int pad; int source_pc = ce.getPc(source); if (((source_pc + 1) % 4) != 0) { // need padding pad = (4 - ((source_pc + 1) % 4)); for (int x = 0; x < pad; x++) out.writeByte(0); } dflt.writeWideOffset(ce, source, out); out.writeInt(min); out.writeInt(max); int cnt = jmp.length; for (int x = 0; x < cnt; x++) { jmp[x].writeWideOffset(ce, source, out); } }
public void emitTestIf(Variable incoming, Declaration decl, Compilation comp) { CodeAttr code = comp.getCode(); if (incoming != null) code.emitLoad(incoming); if (decl != null) { code.emitDup(); decl.compileStore(comp); } comp.compileConstant(this); code.emitSwap(); code.emitInvokeVirtual(isInstanceMethod); code.emitIfIntNotZero(); }
void write(ClassEnv e, CodeAttr ce, DataOutputStream out) throws IOException, jasError { int pad; int source_pc = ce.getPc(source); if (((source_pc + 1) % 4) != 0) { // need padding pad = (4 - ((source_pc + 1) % 4)); for (int x = 0; x < pad; x++) out.writeByte(0); } // write offset to default // as a 4 byte signed value dflt.writeWideOffset(ce, source, out); if (jmp == null) { out.writeInt(0); } else { out.writeInt(jmp.length); for (int x = 0; x < jmp.length; x++) { out.writeInt(match[x]); jmp[x].writeWideOffset(ce, source, out); } } }