jawa.attributes.code module¶
-
class
jawa.attributes.code.
CodeAttribute
(table, name_index=None)[source]¶ Bases:
jawa.attribute.Attribute
A CodeAttribute contains the executable bytecode of a single method.
As a quick example, lets make a “HelloWorld” class with a single method that simply returns when it’s called:
from jawa import ClassFile from jawa.util.bytecode import Instruction cf = ClassFile.create('HelloWorld') main = cf.methods.create( # The name of the method 'main', # The signature of the method '([Ljava/lang/String;)V', # Tell Jawa to automatically create an empty CodeAttribute for # us to use. code=True ) main.code.max_locals = 1 main.access_flags.acc_static = True main.code.assemble([ Instruction.from_mnemonic('return') ]) # Save it to disk so we can run it with the JVM. with open('HelloWorld.class', 'wb') as fout: cf.save(fout)
-
ADDED_IN
= '1.0.2'¶
-
MINIMUM_CLASS_VERSION
= (45, 3)¶
-
assemble
(code)[source]¶ Assembles an iterable of
Instruction
objects into a method’s code body.
-
disassemble
(*, transforms=None) → Iterator[jawa.util.bytecode.Instruction][source]¶ Disassembles this method, yielding an iterable of
Instruction
objects.
-