RPNXCortado
C++23 JVM class-file, bytecode, validation, and JAR toolkit
Loading...
Searching...
No Matches
rpnx::cortado::code_builder Class Reference

An owning symbolic JVM code builder. More...

#include <builders.hpp>

Public Member Functions

 code_builder ()
 Constructs an empty builder with a unique label-ownership token.
 
label new_label ()
 Creates a fresh label owned by this builder.
 
auto bind (label value) -> code_builder &
 Binds a label at the current instruction position.
 
auto append (instruction value) -> code_builder &
 Appends one exact instruction encoding.
 
template<opcode Operation>
requires requires { instruction{simple_instruction< Operation >{}}; }
auto append () -> code_builder &
 Appends an operand-free instruction selected at compile time.
 
template<opcode Operation>
auto branch (label target) -> code_builder &
 Appends a compile-time-typed labeled branch.
 
auto tableswitch (label default_target, std::int32_t low, std::vector< label > targets) -> code_builder &
 Appends a symbolic tableswitch.
 
auto lookupswitch (label default_target, std::vector< labeled_lookup_switch_pair > pairs) -> code_builder &
 Appends a symbolic lookupswitch.
 
auto bipush (std::int8_t value) -> code_builder &
 Pushes a signed byte constant.
 
auto sipush (std::int16_t value) -> code_builder &
 Pushes a signed short constant.
 
auto ldc_string (std::string value) -> code_builder &
 Loads a string through an automatically interned ldc or ldc_w instruction.
 
auto iload (local_variable_index index) -> code_builder &
 Loads an int from a local using the shortest valid encoding.
 
auto lload (local_variable_index index) -> code_builder &
 Loads a long from a local using the shortest valid encoding.
 
auto fload (local_variable_index index) -> code_builder &
 Loads a float from a local using the shortest valid encoding.
 
auto dload (local_variable_index index) -> code_builder &
 Loads a double from a local using the shortest valid encoding.
 
auto aload (local_variable_index index) -> code_builder &
 Loads a reference from a local using the shortest valid encoding.
 
auto istore (local_variable_index index) -> code_builder &
 Stores an int into a local using the shortest valid encoding.
 
auto lstore (local_variable_index index) -> code_builder &
 Stores a long into a local using the shortest valid encoding.
 
auto fstore (local_variable_index index) -> code_builder &
 Stores a float into a local using the shortest valid encoding.
 
auto dstore (local_variable_index index) -> code_builder &
 Stores a double into a local using the shortest valid encoding.
 
auto astore (local_variable_index index) -> code_builder &
 Stores a reference into a local using the shortest valid encoding.
 
auto iinc (local_variable_index index, std::int16_t amount) -> code_builder &
 Increments an int local using compact or wide form as required.
 
auto getstatic (std::string owner, std::string name, std::string descriptor) -> code_builder &
 Emits a symbolic getstatic instruction.
 
auto putstatic (std::string owner, std::string name, std::string descriptor) -> code_builder &
 Emits a symbolic putstatic instruction.
 
auto getfield (std::string owner, std::string name, std::string descriptor) -> code_builder &
 Emits a symbolic getfield instruction.
 
auto putfield (std::string owner, std::string name, std::string descriptor) -> code_builder &
 Emits a symbolic putfield instruction.
 
auto invokevirtual (std::string owner, std::string name, std::string descriptor) -> code_builder &
 Emits a symbolic invokevirtual instruction.
 
auto invokespecial (std::string owner, std::string name, std::string descriptor, method_owner_kind owner_kind=method_owner_kind::class_) -> code_builder &
 Emits a symbolic invokespecial instruction.
 
auto invokestatic (std::string owner, std::string name, std::string descriptor, method_owner_kind owner_kind=method_owner_kind::class_) -> code_builder &
 Emits a symbolic invokestatic instruction.
 
auto invokeinterface (std::string owner, std::string name, std::string descriptor) -> code_builder &
 Emits a symbolic invokeinterface instruction.
 
auto new_ (std::string class_name) -> code_builder &
 Emits a symbolic new instruction.
 
auto anewarray (std::string class_name) -> code_builder &
 Emits a symbolic anewarray instruction.
 
auto checkcast (std::string class_name) -> code_builder &
 Emits a symbolic checkcast instruction.
 
auto instanceof_ (std::string class_name) -> code_builder &
 Emits a symbolic instanceof instruction.
 
auto add_exception_handler (label start, label end, label handler, std::optional< std::string > catch_type=std::nullopt) -> code_builder &
 Adds a symbolic exception-table range.
 
auto add_line_number (label start, std::uint16_t line_number) -> code_builder &
 Associates a source line with a symbolic code position.
 
auto add_local_variable (label start, label end, std::string name, std::string descriptor, local_variable_index index) -> code_builder &
 Adds a symbolic LocalVariableTable scope.
 
auto add_local_variable_type (label start, label end, std::string name, std::string signature, local_variable_index index) -> code_builder &
 Adds a symbolic LocalVariableTypeTable scope.
 
auto set_stack_map_table (stack_map_table_attribute value) -> code_builder &
 Supplies an exact StackMapTable and bypasses automatic frame generation.
 
code_attribute finish (code_build_context const &context, constant_pool_builder &constant_pool, class_hierarchy_resolver_ref hierarchy={}) const
 Finalizes labels, widths, constant references, and Code metadata.
 
std::vector< assembly_element > const & elements () const noexcept
 Returns the symbolic element sequence.
 

Detailed Description

An owning symbolic JVM code builder.

Mutating operations return *this for fluent construction. Labels are builder-lineage values: using a foreign label or binding one twice is an assembly error. Copying a builder preserves its lineage so labels remain meaningful in the copy.

Definition at line 355 of file builders.hpp.

Member Function Documentation

◆ add_exception_handler()

auto rpnx::cortado::code_builder::add_exception_handler ( label start,
label end,
label handler,
std::optional< std::string > catch_type = std::nullopt ) -> code_builder &

Adds a symbolic exception-table range.

Parameters
startInclusive protected-range start label.
endExclusive protected-range end label.
handlerHandler entry label.
catch_typeInternal exception class name, or no value for catch-all.
Returns
*this.

References code_builder().

◆ add_line_number()

auto rpnx::cortado::code_builder::add_line_number ( label start,
std::uint16_t line_number ) -> code_builder &

Associates a source line with a symbolic code position.

Parameters
startLabel bound to an instruction.
line_numberSource line number.
Returns
*this.

References code_builder().

◆ add_local_variable()

auto rpnx::cortado::code_builder::add_local_variable ( label start,
label end,
std::string name,
std::string descriptor,
local_variable_index index ) -> code_builder &

Adds a symbolic LocalVariableTable scope.

Parameters
startInclusive scope start.
endExclusive scope end.
nameSource variable name.
descriptorJVM field descriptor.
indexFirst local-variable-array slot.
Returns
*this.

References code_builder().

◆ add_local_variable_type()

auto rpnx::cortado::code_builder::add_local_variable_type ( label start,
label end,
std::string name,
std::string signature,
local_variable_index index ) -> code_builder &

Adds a symbolic LocalVariableTypeTable scope.

Parameters
startInclusive scope start.
endExclusive scope end.
nameSource variable name.
signatureGeneric field signature.
indexFirst local-variable-array slot.
Returns
*this.

References code_builder().

◆ aload()

auto rpnx::cortado::code_builder::aload ( local_variable_index index) -> code_builder &

Loads a reference from a local using the shortest valid encoding.

Parameters
indexLocal-variable-array slot.
Returns
*this.

References code_builder().

◆ anewarray()

auto rpnx::cortado::code_builder::anewarray ( std::string class_name) -> code_builder &

Emits a symbolic anewarray instruction.

Parameters
class_nameComponent class internal name or array descriptor.
Returns
*this.

References code_builder().

◆ append() [1/2]

template<opcode Operation>
requires requires { instruction{simple_instruction< Operation >{}}; }
auto rpnx::cortado::code_builder::append ( ) -> code_builder&
inline

Appends an operand-free instruction selected at compile time.

Template Parameters
OperationOpcode whose simple_instruction is an instruction alternative.
Returns
*this.

Definition at line 385 of file builders.hpp.

References append(), and code_builder().

Referenced by append().

◆ append() [2/2]

auto rpnx::cortado::code_builder::append ( instruction value) -> code_builder &

Appends one exact instruction encoding.

Parameters
valueWire-level instruction, including any explicit width or padding choice.
Returns
*this.

References code_builder().

◆ astore()

auto rpnx::cortado::code_builder::astore ( local_variable_index index) -> code_builder &

Stores a reference into a local using the shortest valid encoding.

Parameters
indexLocal-variable-array destination slot.
Returns
*this.

References code_builder().

◆ bind()

auto rpnx::cortado::code_builder::bind ( label value) -> code_builder &

Binds a label at the current instruction position.

Parameters
valueUnbound label created by this builder lineage.
Returns
*this.
Exceptions
assembly_errorif the label belongs to another lineage; duplicate binding is rejected by finish.

References code_builder().

◆ bipush()

auto rpnx::cortado::code_builder::bipush ( std::int8_t value) -> code_builder &

Pushes a signed byte constant.

Parameters
valueImmediate JVM int value.
Returns
*this.

References code_builder().

◆ branch()

template<opcode Operation>
auto rpnx::cortado::code_builder::branch ( label target) -> code_builder&
inline

Appends a compile-time-typed labeled branch.

Template Parameters
OperationSupported conditional, goto, jsr, null-test branch opcode.
Parameters
targetLabel created by this builder lineage.
Returns
*this.
Exceptions
assembly_errorif target is foreign.

Definition at line 397 of file builders.hpp.

References code_builder().

◆ checkcast()

auto rpnx::cortado::code_builder::checkcast ( std::string class_name) -> code_builder &

Emits a symbolic checkcast instruction.

Parameters
class_nameTarget class internal name or array descriptor.
Returns
*this.

References code_builder().

◆ dload()

auto rpnx::cortado::code_builder::dload ( local_variable_index index) -> code_builder &

Loads a double from a local using the shortest valid encoding.

Parameters
indexFirst local-variable-array slot of the category-2 value.
Returns
*this.

References code_builder().

◆ dstore()

auto rpnx::cortado::code_builder::dstore ( local_variable_index index) -> code_builder &

Stores a double into a local using the shortest valid encoding.

Parameters
indexFirst local-variable-array destination slot.
Returns
*this.

References code_builder().

◆ elements()

std::vector< assembly_element > const & rpnx::cortado::code_builder::elements ( ) const
nodiscardnoexcept

Returns the symbolic element sequence.

Returns
Non-owning reference valid for this builder's lifetime or until mutation.

◆ finish()

code_attribute rpnx::cortado::code_builder::finish ( code_build_context const & context,
constant_pool_builder & constant_pool,
class_hierarchy_resolver_ref hierarchy = {} ) const
nodiscard

Finalizes labels, widths, constant references, and Code metadata.

Parameters
contextContaining method, class, version, and analysis policy.
constant_poolShared pool into which symbolic references and attribute names are interned.
hierarchyOptional resolver used only when verifier reference merges require hierarchy knowledge.
Returns
Complete typed Code attribute.
Exceptions
assembly_errorif labels, control flow, limits, or explicit metadata are inconsistent.
unsupported_feature_errorif requested analysis needs unsupported subroutines or a missing resolver.

◆ fload()

auto rpnx::cortado::code_builder::fload ( local_variable_index index) -> code_builder &

Loads a float from a local using the shortest valid encoding.

Parameters
indexLocal-variable-array slot.
Returns
*this.

References code_builder().

◆ fstore()

auto rpnx::cortado::code_builder::fstore ( local_variable_index index) -> code_builder &

Stores a float into a local using the shortest valid encoding.

Parameters
indexLocal-variable-array destination slot.
Returns
*this.

References code_builder().

◆ getfield()

auto rpnx::cortado::code_builder::getfield ( std::string owner,
std::string name,
std::string descriptor ) -> code_builder &

Emits a symbolic getfield instruction.

Parameters
ownerDeclaring class internal name.
nameField name.
descriptorField descriptor.
Returns
*this.

References code_builder().

◆ getstatic()

auto rpnx::cortado::code_builder::getstatic ( std::string owner,
std::string name,
std::string descriptor ) -> code_builder &

Emits a symbolic getstatic instruction.

Parameters
ownerDeclaring class internal name.
nameField name.
descriptorField descriptor.
Returns
*this.

References code_builder().

◆ iinc()

auto rpnx::cortado::code_builder::iinc ( local_variable_index index,
std::int16_t amount ) -> code_builder &

Increments an int local using compact or wide form as required.

Parameters
indexLocal-variable-array slot to update.
amountSigned increment.
Returns
*this.

References code_builder().

◆ iload()

auto rpnx::cortado::code_builder::iload ( local_variable_index index) -> code_builder &

Loads an int from a local using the shortest valid encoding.

Parameters
indexLocal-variable-array slot.
Returns
*this.

References code_builder().

◆ instanceof_()

auto rpnx::cortado::code_builder::instanceof_ ( std::string class_name) -> code_builder &

Emits a symbolic instanceof instruction.

Parameters
class_nameTested class internal name or array descriptor.
Returns
*this.

References code_builder().

◆ invokeinterface()

auto rpnx::cortado::code_builder::invokeinterface ( std::string owner,
std::string name,
std::string descriptor ) -> code_builder &

Emits a symbolic invokeinterface instruction.

Parameters
ownerDeclaring interface internal name.
nameMethod name.
descriptorMethod descriptor used to calculate the encoded argument count.
Returns
*this.

References code_builder().

◆ invokespecial()

auto rpnx::cortado::code_builder::invokespecial ( std::string owner,
std::string name,
std::string descriptor,
method_owner_kind owner_kind = method_owner_kind::class_ ) -> code_builder &

Emits a symbolic invokespecial instruction.

Parameters
ownerDeclaring type internal name.
nameMethod name.
descriptorMethod descriptor.
owner_kindWhether to intern a class or interface method reference.
Returns
*this.

References code_builder().

◆ invokestatic()

auto rpnx::cortado::code_builder::invokestatic ( std::string owner,
std::string name,
std::string descriptor,
method_owner_kind owner_kind = method_owner_kind::class_ ) -> code_builder &

Emits a symbolic invokestatic instruction.

Parameters
ownerDeclaring type internal name.
nameMethod name.
descriptorMethod descriptor.
owner_kindWhether to intern a class or interface method reference.
Returns
*this.

References code_builder().

◆ invokevirtual()

auto rpnx::cortado::code_builder::invokevirtual ( std::string owner,
std::string name,
std::string descriptor ) -> code_builder &

Emits a symbolic invokevirtual instruction.

Parameters
ownerDeclaring class internal name.
nameMethod name.
descriptorMethod descriptor.
Returns
*this.

References code_builder().

◆ istore()

auto rpnx::cortado::code_builder::istore ( local_variable_index index) -> code_builder &

Stores an int into a local using the shortest valid encoding.

Parameters
indexLocal-variable-array destination slot.
Returns
*this.

References code_builder().

◆ ldc_string()

auto rpnx::cortado::code_builder::ldc_string ( std::string value) -> code_builder &

Loads a string through an automatically interned ldc or ldc_w instruction.

Parameters
valueModified-UTF-8 string contents, owned by the symbolic element.
Returns
*this.

References code_builder().

◆ lload()

auto rpnx::cortado::code_builder::lload ( local_variable_index index) -> code_builder &

Loads a long from a local using the shortest valid encoding.

Parameters
indexFirst local-variable-array slot of the category-2 value.
Returns
*this.

References code_builder().

◆ lookupswitch()

auto rpnx::cortado::code_builder::lookupswitch ( label default_target,
std::vector< labeled_lookup_switch_pair > pairs ) -> code_builder &

Appends a symbolic lookupswitch.

Parameters
default_targetDestination when no key matches.
pairsStrictly increasing key/destination pairs.
Returns
*this.

References code_builder().

◆ lstore()

auto rpnx::cortado::code_builder::lstore ( local_variable_index index) -> code_builder &

Stores a long into a local using the shortest valid encoding.

Parameters
indexFirst local-variable-array destination slot.
Returns
*this.

References code_builder().

◆ new_()

auto rpnx::cortado::code_builder::new_ ( std::string class_name) -> code_builder &

Emits a symbolic new instruction.

Parameters
class_nameInstantiated class internal name.
Returns
*this.

References code_builder().

◆ new_label()

label rpnx::cortado::code_builder::new_label ( )
nodiscard

Creates a fresh label owned by this builder.

Returns
Unbound symbolic position unique within this builder lineage.

◆ putfield()

auto rpnx::cortado::code_builder::putfield ( std::string owner,
std::string name,
std::string descriptor ) -> code_builder &

Emits a symbolic putfield instruction.

Parameters
ownerDeclaring class internal name.
nameField name.
descriptorField descriptor.
Returns
*this.

References code_builder().

◆ putstatic()

auto rpnx::cortado::code_builder::putstatic ( std::string owner,
std::string name,
std::string descriptor ) -> code_builder &

Emits a symbolic putstatic instruction.

Parameters
ownerDeclaring class internal name.
nameField name.
descriptorField descriptor.
Returns
*this.

References code_builder().

◆ set_stack_map_table()

auto rpnx::cortado::code_builder::set_stack_map_table ( stack_map_table_attribute value) -> code_builder &

Supplies an exact StackMapTable and bypasses automatic frame generation.

Parameters
valueComplete table; its name index may be replaced with the builder's interned name.
Returns
*this.

References code_builder().

◆ sipush()

auto rpnx::cortado::code_builder::sipush ( std::int16_t value) -> code_builder &

Pushes a signed short constant.

Parameters
valueImmediate JVM int value.
Returns
*this.

References code_builder().

◆ tableswitch()

auto rpnx::cortado::code_builder::tableswitch ( label default_target,
std::int32_t low,
std::vector< label > targets ) -> code_builder &

Appends a symbolic tableswitch.

Parameters
default_targetDestination for keys outside the dense table.
lowKey corresponding to targets.front().
targetsConsecutive destinations; the sequence must be nonempty.
Returns
*this.

References code_builder().


The documentation for this class was generated from the following file: