Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
/ bcb Public archive

A framework for generating java bytecode

License

Notifications You must be signed in to change notification settings

IBM/bcb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bytecode Builder

BCB is a framework for generating java bytecode. The goal of this project is to simplify java bytecode generation.

Project Layout

  • bcb - the core bcb project

  • examples - bcb code generation examples

Fused-Multiple-Add (FMA) Example

public class Test {
    public static void main(String[] args) {
        BCBMethod method = BCBMethod.builder()
                .name("Test")
                .declaringClass("TestClass")
                .returnType(Type.FLOAT_TYPE)
                .arg("a", Type.FLOAT_TYPE)
                .arg("b", Type.FLOAT_TYPE)
                .arg("c", Type.FLOAT_TYPE)
                .body(
                        ret(
                                add(
                                        mul(
                                                load("a"),
                                                load("b")
                                        ),
                                        load("c")
                                )
                        )
                ).build();

        final MethodHandle fmaMethodHandle = method.toMethodHandle();

        System.out.println(fmaMethodHandle.invoke(2, 2, 6));
    }
}

Generated bytecode (from javap)

public class TestClass {
  public static float Test(float, float);
    Code:
       0: fload_0
       1: fload_1
       2: fmul
       3: fload_0
       4: fload_1
       5: fmul
       6: fadd
       7: freturn
}

About

A framework for generating java bytecode

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages