1 34 35 package org.logicalcobwebs.asm.util; 36 37 import org.logicalcobwebs.asm.CodeVisitor; 38 import org.logicalcobwebs.asm.Label; 39 import org.logicalcobwebs.asm.Attribute; 40 41 import java.util.ArrayList ; 42 import java.util.List ; 43 44 53 54 public abstract class PrintCodeVisitor implements CodeVisitor { 55 56 59 60 protected final List text; 61 62 65 66 protected final StringBuffer buf; 67 68 71 72 public final static String [] OPCODES = { 73 "NOP", 74 "ACONST_NULL", 75 "ICONST_M1", 76 "ICONST_0", 77 "ICONST_1", 78 "ICONST_2", 79 "ICONST_3", 80 "ICONST_4", 81 "ICONST_5", 82 "LCONST_0", 83 "LCONST_1", 84 "FCONST_0", 85 "FCONST_1", 86 "FCONST_2", 87 "DCONST_0", 88 "DCONST_1", 89 "BIPUSH", 90 "SIPUSH", 91 "LDC", 92 null, 93 null, 94 "ILOAD", 95 "LLOAD", 96 "FLOAD", 97 "DLOAD", 98 "ALOAD", 99 null, 100 null, 101 null, 102 null, 103 null, 104 null, 105 null, 106 null, 107 null, 108 null, 109 null, 110 null, 111 null, 112 null, 113 null, 114 null, 115 null, 116 null, 117 null, 118 null, 119 "IALOAD", 120 "LALOAD", 121 "FALOAD", 122 "DALOAD", 123 "AALOAD", 124 "BALOAD", 125 "CALOAD", 126 "SALOAD", 127 "ISTORE", 128 "LSTORE", 129 "FSTORE", 130 "DSTORE", 131 "ASTORE", 132 null, 133 null, 134 null, 135 null, 136 null, 137 null, 138 null, 139 null, 140 null, 141 null, 142 null, 143 null, 144 null, 145 null, 146 null, 147 null, 148 null, 149 null, 150 null, 151 null, 152 "IASTORE", 153 "LASTORE", 154 "FASTORE", 155 "DASTORE", 156 "AASTORE", 157 "BASTORE", 158 "CASTORE", 159 "SASTORE", 160 "POP", 161 "POP2", 162 "DUP", 163 "DUP_X1", 164 "DUP_X2", 165 "DUP2", 166 "DUP2_X1", 167 "DUP2_X2", 168 "SWAP", 169 "IADD", 170 "LADD", 171 "FADD", 172 "DADD", 173 "ISUB", 174 "LSUB", 175 "FSUB", 176 "DSUB", 177 "IMUL", 178 "LMUL", 179 "FMUL", 180 "DMUL", 181 "IDIV", 182 "LDIV", 183 "FDIV", 184 "DDIV", 185 "IREM", 186 "LREM", 187 "FREM", 188 "DREM", 189 "INEG", 190 "LNEG", 191 "FNEG", 192 "DNEG", 193 "ISHL", 194 "LSHL", 195 "ISHR", 196 "LSHR", 197 "IUSHR", 198 "LUSHR", 199 "IAND", 200 "LAND", 201 "IOR", 202 "LOR", 203 "IXOR", 204 "LXOR", 205 "IINC", 206 "I2L", 207 "I2F", 208 "I2D", 209 "L2I", 210 "L2F", 211 "L2D", 212 "F2I", 213 "F2L", 214 "F2D", 215 "D2I", 216 "D2L", 217 "D2F", 218 "I2B", 219 "I2C", 220 "I2S", 221 "LCMP", 222 "FCMPL", 223 "FCMPG", 224 "DCMPL", 225 "DCMPG", 226 "IFEQ", 227 "IFNE", 228 "IFLT", 229 "IFGE", 230 "IFGT", 231 "IFLE", 232 "IF_ICMPEQ", 233 "IF_ICMPNE", 234 "IF_ICMPLT", 235 "IF_ICMPGE", 236 "IF_ICMPGT", 237 "IF_ICMPLE", 238 "IF_ACMPEQ", 239 "IF_ACMPNE", 240 "GOTO", 241 "JSR", 242 "RET", 243 "TABLESWITCH", 244 "LOOKUPSWITCH", 245 "IRETURN", 246 "LRETURN", 247 "FRETURN", 248 "DRETURN", 249 "ARETURN", 250 "RETURN", 251 "GETSTATIC", 252 "PUTSTATIC", 253 "GETFIELD", 254 "PUTFIELD", 255 "INVOKEVIRTUAL", 256 "INVOKESPECIAL", 257 "INVOKESTATIC", 258 "INVOKEINTERFACE", 259 null, 260 "NEW", 261 "NEWARRAY", 262 "ANEWARRAY", 263 "ARRAYLENGTH", 264 "ATHROW", 265 "CHECKCAST", 266 "INSTANCEOF", 267 "MONITORENTER", 268 "MONITOREXIT", 269 null, 270 "MULTIANEWARRAY", 271 "IFNULL", 272 "IFNONNULL", 273 null, 274 null 275 }; 276 277 280 281 public PrintCodeVisitor () { 282 this.buf = new StringBuffer (); 283 this.text = new ArrayList (); 284 } 285 286 public void visitInsn (final int opcode) { 287 buf.setLength(0); 288 printInsn(opcode); 289 text.add(buf.toString()); 290 } 291 292 public void visitIntInsn (final int opcode, final int operand) { 293 buf.setLength(0); 294 printIntInsn(opcode, operand); 295 text.add(buf.toString()); 296 } 297 298 public void visitVarInsn (final int opcode, final int var) { 299 buf.setLength(0); 300 printVarInsn(opcode, var); 301 text.add(buf.toString()); 302 } 303 304 public void visitTypeInsn (final int opcode, final String desc) { 305 buf.setLength(0); 306 printTypeInsn(opcode, desc); 307 text.add(buf.toString()); 308 } 309 310 public void visitFieldInsn ( 311 final int opcode, 312 final String owner, 313 final String name, 314 final String desc) 315 { 316 buf.setLength(0); 317 printFieldInsn(opcode, owner, name, desc); 318 text.add(buf.toString()); 319 } 320 321 public void visitMethodInsn ( 322 final int opcode, 323 final String owner, 324 final String name, 325 final String desc) 326 { 327 buf.setLength(0); 328 printMethodInsn(opcode, owner, name, desc); 329 text.add(buf.toString()); 330 } 331 332 public void visitJumpInsn (final int opcode, final Label label) { 333 buf.setLength(0); 334 printJumpInsn(opcode, label); 335 text.add(buf.toString()); 336 } 337 338 public void visitLabel (final Label label) { 339 buf.setLength(0); 340 printLabel(label); 341 text.add(buf.toString()); 342 } 343 344 public void visitLdcInsn (final Object cst) { 345 buf.setLength(0); 346 printLdcInsn(cst); 347 text.add(buf.toString()); 348 } 349 350 public void visitIincInsn (final int var, final int increment) { 351 buf.setLength(0); 352 printIincInsn(var, increment); 353 text.add(buf.toString()); 354 } 355 356 public void visitTableSwitchInsn ( 357 final int min, 358 final int max, 359 final Label dflt, 360 final Label labels[]) 361 { 362 buf.setLength(0); 363 printTableSwitchInsn(min, max, dflt, labels); 364 text.add(buf.toString()); 365 } 366 367 public void visitLookupSwitchInsn ( 368 final Label dflt, 369 final int keys[], 370 final Label labels[]) 371 { 372 buf.setLength(0); 373 printLookupSwitchInsn(dflt, keys, labels); 374 text.add(buf.toString()); 375 } 376 377 public void visitMultiANewArrayInsn (final String desc, final int dims) { 378 buf.setLength(0); 379 printMultiANewArrayInsn(desc, dims); 380 text.add(buf.toString()); 381 } 382 383 public void visitTryCatchBlock ( 384 final Label start, 385 final Label end, 386 final Label handler, 387 final String type) 388 { 389 buf.setLength(0); 390 printTryCatchBlock(start, end, handler, type); 391 text.add(buf.toString()); 392 } 393 394 public void visitMaxs (final int maxStack, final int maxLocals) { 395 buf.setLength(0); 396 printMaxs(maxStack, maxLocals); 397 text.add(buf.toString()); 398 } 399 400 public void visitLocalVariable ( 401 final String name, 402 final String desc, 403 final Label start, 404 final Label end, 405 final int index) 406 { 407 buf.setLength(0); 408 printLocalVariable(name, desc, start, end, index); 409 text.add(buf.toString()); 410 } 411 412 public void visitLineNumber (final int line, final Label start) { 413 buf.setLength(0); 414 printLineNumber(line, start); 415 text.add(buf.toString()); 416 } 417 418 public void visitAttribute (final Attribute attr) { 419 buf.setLength(0); 420 printAttribute(attr); 421 text.add(buf.toString()); 422 } 423 424 430 431 public List getText () { 432 return text; 433 } 434 435 467 468 public abstract void printInsn (final int opcode); 469 470 477 478 public abstract void printIntInsn (final int opcode, final int operand); 479 480 490 491 public abstract void printVarInsn (final int opcode, final int var); 492 493 503 504 public abstract void printTypeInsn (final int opcode, final String desc); 505 506 518 519 public abstract void printFieldInsn ( 520 final int opcode, 521 final String owner, 522 final String name, 523 final String desc); 524 525 538 539 public abstract void printMethodInsn ( 540 final int opcode, 541 final String owner, 542 final String name, 543 final String desc); 544 545 557 558 public abstract void printJumpInsn (final int opcode, final Label label); 559 560 566 567 public abstract void printLabel (final Label label); 568 569 577 578 public abstract void printLdcInsn (final Object cst); 579 580 586 587 public abstract void printIincInsn (final int var, final int increment); 588 589 598 599 public abstract void printTableSwitchInsn ( 600 final int min, 601 final int max, 602 final Label dflt, 603 final Label labels[]); 604 605 613 614 public abstract void printLookupSwitchInsn ( 615 final Label dflt, 616 final int keys[], 617 final Label labels[]); 618 619 626 627 public abstract void printMultiANewArrayInsn ( 628 final String desc, 629 final int dims); 630 631 640 641 public abstract void printTryCatchBlock ( 642 final Label start, 643 final Label end, 644 final Label handler, 645 final String type); 646 647 654 655 public abstract void printMaxs (final int maxStack, final int maxLocals); 656 657 668 669 public abstract void printLocalVariable ( 670 final String name, 671 final String desc, 672 final Label start, 673 final Label end, 674 final int index); 675 676 683 684 public abstract void printLineNumber (final int line, final Label start); 685 686 691 692 public abstract void printAttribute (final Attribute attr); 693 } | Popular Tags |