Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any Java Bytecode Generation Guide? [closed]

we're writing some sort of compiler from Pascal to JVM Bytecode. And we've already implemented an expression tree generation, so the next step should be the creation of .class file. Can you suggest any guide/tutorial of how to generate any .class file at least from some static data? Because I've googled for 2 hours already and read JVM specification, but I really need some even simplest example to start developing the whole stuff.

like image 858
Uko Avatar asked Nov 20 '11 17:11

Uko


People also ask

How many Java opcodes are there?

Java bytecode is the instruction set of the Java virtual machine. Each bytecode is composed of one, or in some cases two bytes that represent the instruction (opcode), along with zero or more bytes for passing parameters. Currently, in Jan 2017, there are 205 opcodes in use out of 256 possible byte-long opcodes.

What is bytecode generation?

Bytecode in Java is the reason java is platform-independent, as soon as a Java program is compiled bytecode is generated. To be more precise a Java bytecode is the machine code in the form of a . class file. A bytecode in Java is the instruction set for Java Virtual Machine and acts similar to an assembler.

What are bytecode instructions in Java?

A method's bytecode stream is a sequence of instructions for the Java virtual machine. Each instruction consists of a one-byte opcode followed by zero or more operands. The opcode indicates the action to take.

Is Java bytecode executed?

Bytecode is the compiled format for Java programs. Once a Java program has been converted to bytecode, it can be transferred across a network and executed by Java Virtual Machine (JVM). Bytecode files generally have a . class extension.


1 Answers

Someone has already written a widely-used byte code generation library: CGLIB.

You'd have it knocked if you could figure out how to get your AST into CGLIB.

like image 186
duffymo Avatar answered Sep 23 '22 16:09

duffymo