Re: Problem with generating method

Rémi Forax <[email protected]>
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
On 03/21/2011 12:49 PM, [email protected] wrote:
> i succeded in creating main method, and constructor
> but now i need to create new static method
> suppose i want do method:
> static public f(int x, int y)
> {
> return x*y;
> }
>
> based on my experience with other methods i wrote:
>
> mv = cw.visitMethod( Opcodes.ACC_PUBLIC+Opcodes.ACC_STATIC,
> f,"(II)I",null,null);
> mv.visitCode();
> mv.visitVarInsn(Opcodes.ILOAD, 0);
> mv.visitVarInsn(Opcodes.ILOAD, 1);
> mv.visitInsn(Opcodes.IMUL);
> mv.visitInsn(Opcodes.RETURN);

replace RETURN by IRETURN.

> mv.visitMaxs(0, 0);
> mv.visitEnd();
>
> disassebled code for this method is looks exactly as that one created from
> source code
> bur when i try run class (without using that method)
> a get
> (class: myClass, method: f signature (II)I)  Wrong return type in function
> can somebody tells me whad did i miss
> regards

There is a magic program named Asmifier that takes a .class and generate 
the code
that will generate the same .class
http://asm.ow2.org/doc/faq.html#Q10

Also the JVM spec that describes all opcodes is here:
http://java.sun.com/docs/books/jvms/second_edition/html/Instructions.doc.html

Rémi
message-footer.txt (text/plain, 238 B)
-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.