|
RPNXCortado
C++23 JVM class-file, bytecode, validation, and JAR toolkit
|
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. | |
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.
| 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.
| start | Inclusive protected-range start label. |
| end | Exclusive protected-range end label. |
| handler | Handler entry label. |
| catch_type | Internal exception class name, or no value for catch-all. |
*this. References code_builder().
| 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.
| start | Label bound to an instruction. |
| line_number | Source line number. |
*this. References code_builder().
| 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.
| start | Inclusive scope start. |
| end | Exclusive scope end. |
| name | Source variable name. |
| descriptor | JVM field descriptor. |
| index | First local-variable-array slot. |
*this. References code_builder().
| 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.
| start | Inclusive scope start. |
| end | Exclusive scope end. |
| name | Source variable name. |
| signature | Generic field signature. |
| index | First local-variable-array slot. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::aload | ( | local_variable_index | index | ) | -> code_builder & |
Loads a reference from a local using the shortest valid encoding.
| index | Local-variable-array slot. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::anewarray | ( | std::string | class_name | ) | -> code_builder & |
Emits a symbolic anewarray instruction.
| class_name | Component class internal name or array descriptor. |
*this. References code_builder().
|
inline |
Appends an operand-free instruction selected at compile time.
| Operation | Opcode whose simple_instruction is an instruction alternative. |
*this. Definition at line 385 of file builders.hpp.
References append(), and code_builder().
Referenced by append().
| auto rpnx::cortado::code_builder::append | ( | instruction | value | ) | -> code_builder & |
Appends one exact instruction encoding.
| value | Wire-level instruction, including any explicit width or padding choice. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::astore | ( | local_variable_index | index | ) | -> code_builder & |
Stores a reference into a local using the shortest valid encoding.
| index | Local-variable-array destination slot. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::bind | ( | label | value | ) | -> code_builder & |
Binds a label at the current instruction position.
| value | Unbound label created by this builder lineage. |
*this. | assembly_error | if the label belongs to another lineage; duplicate binding is rejected by finish. |
References code_builder().
| auto rpnx::cortado::code_builder::bipush | ( | std::int8_t | value | ) | -> code_builder & |
Pushes a signed byte constant.
| value | Immediate JVM int value. |
*this. References code_builder().
|
inline |
Appends a compile-time-typed labeled branch.
| Operation | Supported conditional, goto, jsr, null-test branch opcode. |
| target | Label created by this builder lineage. |
*this. | assembly_error | if target is foreign. |
Definition at line 397 of file builders.hpp.
References code_builder().
| auto rpnx::cortado::code_builder::checkcast | ( | std::string | class_name | ) | -> code_builder & |
Emits a symbolic checkcast instruction.
| class_name | Target class internal name or array descriptor. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::dload | ( | local_variable_index | index | ) | -> code_builder & |
Loads a double from a local using the shortest valid encoding.
| index | First local-variable-array slot of the category-2 value. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::dstore | ( | local_variable_index | index | ) | -> code_builder & |
Stores a double into a local using the shortest valid encoding.
| index | First local-variable-array destination slot. |
*this. References code_builder().
|
nodiscardnoexcept |
Returns the symbolic element sequence.
|
nodiscard |
Finalizes labels, widths, constant references, and Code metadata.
| context | Containing method, class, version, and analysis policy. |
| constant_pool | Shared pool into which symbolic references and attribute names are interned. |
| hierarchy | Optional resolver used only when verifier reference merges require hierarchy knowledge. |
Code attribute. | assembly_error | if labels, control flow, limits, or explicit metadata are inconsistent. |
| unsupported_feature_error | if requested analysis needs unsupported subroutines or a missing resolver. |
| auto rpnx::cortado::code_builder::fload | ( | local_variable_index | index | ) | -> code_builder & |
Loads a float from a local using the shortest valid encoding.
| index | Local-variable-array slot. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::fstore | ( | local_variable_index | index | ) | -> code_builder & |
Stores a float into a local using the shortest valid encoding.
| index | Local-variable-array destination slot. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::getfield | ( | std::string | owner, |
| std::string | name, | ||
| std::string | descriptor ) -> code_builder & |
Emits a symbolic getfield instruction.
| owner | Declaring class internal name. |
| name | Field name. |
| descriptor | Field descriptor. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::getstatic | ( | std::string | owner, |
| std::string | name, | ||
| std::string | descriptor ) -> code_builder & |
Emits a symbolic getstatic instruction.
| owner | Declaring class internal name. |
| name | Field name. |
| descriptor | Field descriptor. |
*this. References code_builder().
| 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.
| index | Local-variable-array slot to update. |
| amount | Signed increment. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::iload | ( | local_variable_index | index | ) | -> code_builder & |
Loads an int from a local using the shortest valid encoding.
| index | Local-variable-array slot. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::instanceof_ | ( | std::string | class_name | ) | -> code_builder & |
Emits a symbolic instanceof instruction.
| class_name | Tested class internal name or array descriptor. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::invokeinterface | ( | std::string | owner, |
| std::string | name, | ||
| std::string | descriptor ) -> code_builder & |
Emits a symbolic invokeinterface instruction.
| owner | Declaring interface internal name. |
| name | Method name. |
| descriptor | Method descriptor used to calculate the encoded argument count. |
*this. References code_builder().
| 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.
| owner | Declaring type internal name. |
| name | Method name. |
| descriptor | Method descriptor. |
| owner_kind | Whether to intern a class or interface method reference. |
*this. References code_builder().
| 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.
| owner | Declaring type internal name. |
| name | Method name. |
| descriptor | Method descriptor. |
| owner_kind | Whether to intern a class or interface method reference. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::invokevirtual | ( | std::string | owner, |
| std::string | name, | ||
| std::string | descriptor ) -> code_builder & |
Emits a symbolic invokevirtual instruction.
| owner | Declaring class internal name. |
| name | Method name. |
| descriptor | Method descriptor. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::istore | ( | local_variable_index | index | ) | -> code_builder & |
Stores an int into a local using the shortest valid encoding.
| index | Local-variable-array destination slot. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::ldc_string | ( | std::string | value | ) | -> code_builder & |
Loads a string through an automatically interned ldc or ldc_w instruction.
| value | Modified-UTF-8 string contents, owned by the symbolic element. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::lload | ( | local_variable_index | index | ) | -> code_builder & |
Loads a long from a local using the shortest valid encoding.
| index | First local-variable-array slot of the category-2 value. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::lookupswitch | ( | label | default_target, |
| std::vector< labeled_lookup_switch_pair > | pairs ) -> code_builder & |
Appends a symbolic lookupswitch.
| default_target | Destination when no key matches. |
| pairs | Strictly increasing key/destination pairs. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::lstore | ( | local_variable_index | index | ) | -> code_builder & |
Stores a long into a local using the shortest valid encoding.
| index | First local-variable-array destination slot. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::new_ | ( | std::string | class_name | ) | -> code_builder & |
Emits a symbolic new instruction.
| class_name | Instantiated class internal name. |
*this. References code_builder().
|
nodiscard |
Creates a fresh label owned by this builder.
| auto rpnx::cortado::code_builder::putfield | ( | std::string | owner, |
| std::string | name, | ||
| std::string | descriptor ) -> code_builder & |
Emits a symbolic putfield instruction.
| owner | Declaring class internal name. |
| name | Field name. |
| descriptor | Field descriptor. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::putstatic | ( | std::string | owner, |
| std::string | name, | ||
| std::string | descriptor ) -> code_builder & |
Emits a symbolic putstatic instruction.
| owner | Declaring class internal name. |
| name | Field name. |
| descriptor | Field descriptor. |
*this. References code_builder().
| 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.
| value | Complete table; its name index may be replaced with the builder's interned name. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::sipush | ( | std::int16_t | value | ) | -> code_builder & |
Pushes a signed short constant.
| value | Immediate JVM int value. |
*this. References code_builder().
| auto rpnx::cortado::code_builder::tableswitch | ( | label | default_target, |
| std::int32_t | low, | ||
| std::vector< label > | targets ) -> code_builder & |
Appends a symbolic tableswitch.
| default_target | Destination for keys outside the dense table. |
| low | Key corresponding to targets.front(). |
| targets | Consecutive destinations; the sequence must be nonempty. |
*this. References code_builder().