RPNXCortado
C++23 JVM class-file, bytecode, validation, and JAR toolkit
Loading...
Searching...
No Matches
builders.hpp
Go to the documentation of this file.
1// AI Generated 2026 Ryan P. Nicholl <rnicholl@protonmail.com>
2// SPDX-License-Identifier: Apache-2.0
3
7
8#ifndef RPNX_CORTADO_BUILDERS_HPP
9#define RPNX_CORTADO_BUILDERS_HPP
10
11#include <cstddef>
12#include <cstdint>
13#include <limits>
14#include <map>
15#include <optional>
18#include <string>
19#include <string_view>
20#include <variant>
21#include <vector>
22
23namespace rpnx::cortado
24{
27 {
28 std::uint64_t value{};
29 RPNX_MEMBER_METADATA(label_owner, value);
30 };
31
33 struct label
34 {
36 std::size_t id{};
37 RPNX_MEMBER_METADATA(label, owner, id);
38 };
39
42 {
44 RPNX_MEMBER_METADATA(label_binding, value);
45 };
46
48 template < opcode Operation >
50 {
51 static constexpr opcode operation = Operation;
53 RPNX_MEMBER_METADATA(labeled_branch_instruction, target);
54 };
55
58 {
59 std::int32_t match{};
61 RPNX_MEMBER_METADATA(labeled_lookup_switch_pair, match, target);
62 };
63
66 {
68 std::int32_t low{};
69 std::vector< label > targets;
71 };
72
75 {
77 std::vector< labeled_lookup_switch_pair > pairs;
79 };
80
83 {
87 std::optional< std::string > catch_type;
88 RPNX_MEMBER_METADATA(labeled_exception_handler, start, end, handler, catch_type);
89 };
90
93 {
95 std::uint16_t line_number{};
96 RPNX_MEMBER_METADATA(labeled_line_number, start, line_number);
97 };
98
109
120
122 template < opcode Operation >
124 {
125 static constexpr opcode operation = Operation;
126 std::string owner;
127 std::string name;
128 std::string descriptor;
129 RPNX_MEMBER_METADATA(symbolic_field_instruction, owner, name, descriptor);
130 };
131
133 enum class method_owner_kind : std::uint8_t { class_, interface };
134
136 template < opcode Operation >
138 {
139 static constexpr opcode operation = Operation;
140 std::string owner;
141 std::string name;
142 std::string descriptor;
143 method_owner_kind owner_kind{method_owner_kind::class_};
145 };
146
149 {
150 std::string owner;
151 std::string name;
152 std::string descriptor;
154 };
155
157 template < opcode Operation >
159 {
160 static constexpr opcode operation = Operation;
161 std::string internal_name;
162 RPNX_MEMBER_METADATA(symbolic_class_instruction, internal_name);
163 };
164
167 {
168 std::string value;
169 RPNX_MEMBER_METADATA(symbolic_string_instruction, value);
170 };
171
173 using assembly_element = std::variant< instruction, label_binding, labeled_branch_instruction< opcode::ifeq >, labeled_branch_instruction< opcode::ifne >, labeled_branch_instruction< opcode::iflt >, labeled_branch_instruction< opcode::ifge >, labeled_branch_instruction< opcode::ifgt >, labeled_branch_instruction< opcode::ifle >, labeled_branch_instruction< opcode::if_icmpeq >, labeled_branch_instruction< opcode::if_icmpne >, labeled_branch_instruction< opcode::if_icmplt >, labeled_branch_instruction< opcode::if_icmpge >, labeled_branch_instruction< opcode::if_icmpgt >, labeled_branch_instruction< opcode::if_icmple >, labeled_branch_instruction< opcode::if_acmpeq >, labeled_branch_instruction< opcode::if_acmpne >, labeled_branch_instruction< opcode::goto_ >, labeled_branch_instruction< opcode::jsr >, labeled_branch_instruction< opcode::ifnull >, labeled_branch_instruction< opcode::ifnonnull >, labeled_tableswitch_instruction, labeled_lookupswitch_instruction, symbolic_field_instruction< opcode::getstatic >, symbolic_field_instruction< opcode::putstatic >, symbolic_field_instruction< opcode::getfield >, symbolic_field_instruction< opcode::putfield >, symbolic_method_instruction< opcode::invokevirtual >, symbolic_method_instruction< opcode::invokespecial >, symbolic_method_instruction< opcode::invokestatic >, symbolic_invokeinterface_instruction, symbolic_class_instruction< opcode::new_ >, symbolic_class_instruction< opcode::anewarray >, symbolic_class_instruction< opcode::checkcast >, symbolic_class_instruction< opcode::instanceof_ >, symbolic_string_instruction >;
174
183 {
184 public:
187
192 explicit constant_pool_builder(std::vector< constant_pool_entry > entries);
193
200
205 [[nodiscard]] constant_pool_index add_utf8(std::string_view bytes);
206
211 [[nodiscard]] constant_pool_index add_class(std::string_view internal_name);
212
217 [[nodiscard]] constant_pool_index add_string(std::string_view bytes);
218
224 [[nodiscard]] constant_pool_index add_name_and_type(std::string_view name, std::string_view descriptor);
225
232 [[nodiscard]] constant_pool_index add_fieldref(std::string_view owner, std::string_view name, std::string_view descriptor);
233
240 [[nodiscard]] constant_pool_index add_methodref(std::string_view owner, std::string_view name, std::string_view descriptor);
241
248 [[nodiscard]] constant_pool_index add_interface_methodref(std::string_view owner, std::string_view name, std::string_view descriptor);
249
255 [[nodiscard]] constant_pool_entry const& entry_at(constant_pool_index index) const;
256
262 [[nodiscard]] std::string_view utf8_at(constant_pool_index index) const;
263
267 [[nodiscard]] std::vector< constant_pool_entry > const& entries() const noexcept;
268
272 [[nodiscard]] std::vector< constant_pool_entry > build() const;
273
274 private:
275 std::vector< constant_pool_entry > m_entries;
276 std::vector< std::size_t > m_slot_to_entry{std::numeric_limits< std::size_t >::max()};
277 std::map< constant_pool_entry, constant_pool_index > m_indexes;
278 };
279
286 {
287 public:
290
295 template < typename Resolver >
296 explicit class_hierarchy_resolver_ref(Resolver& resolver) noexcept :
297 m_object(&resolver),
298 m_resolve(
299 [](void* object, std::string_view left, std::string_view right) -> std::string
300 {
301 return static_cast< Resolver* >(object)->common_superclass(left, right);
302 })
303 {
304 }
305
309 [[nodiscard]] explicit operator bool() const noexcept;
310
317 [[nodiscard]] std::string common_superclass(std::string_view left, std::string_view right) const;
318
319 private:
320 void* m_object{};
321 std::string (*m_resolve)(void*, std::string_view, std::string_view){};
322 };
323
326 {
327 std::optional< std::uint16_t > max_stack;
328 std::optional< std::uint16_t > max_locals;
331 processing_mode mode{processing_mode::strict};
333 };
334
347
356 {
357 public:
360
364 [[nodiscard]] label new_label();
365
371 auto bind(label value) -> code_builder&;
372
378
383 template < opcode Operation >
384 requires requires { instruction{simple_instruction< Operation >{}}; }
386 {
388 }
389
396 template < opcode Operation >
397 auto branch(label target) -> code_builder&
398 {
399 static_assert(Operation == opcode::ifeq || Operation == opcode::ifne || Operation == opcode::iflt || Operation == opcode::ifge || Operation == opcode::ifgt || Operation == opcode::ifle || Operation == opcode::if_icmpeq || Operation == opcode::if_icmpne || Operation == opcode::if_icmplt || Operation == opcode::if_icmpge || Operation == opcode::if_icmpgt || Operation == opcode::if_icmple || Operation == opcode::if_acmpeq || Operation == opcode::if_acmpne || Operation == opcode::goto_ || Operation == opcode::jsr || Operation == opcode::ifnull || Operation == opcode::ifnonnull, "opcode does not have a labeled 16-bit branch form");
400 require_owned_label(target);
401 m_elements.emplace_back(labeled_branch_instruction< Operation >{target});
402 return *this;
403 }
404
411 auto tableswitch(label default_target, std::int32_t low, std::vector< label > targets) -> code_builder&;
412
418 auto lookupswitch(label default_target, std::vector< labeled_lookup_switch_pair > pairs) -> code_builder&;
419
424 auto bipush(std::int8_t value) -> code_builder&;
425
430 auto sipush(std::int16_t value) -> code_builder&;
431
436 auto ldc_string(std::string value) -> code_builder&;
437
443
449
455
461
467
473
479
485
491
497
503 auto iinc(local_variable_index index, std::int16_t amount) -> code_builder&;
504
511 auto getstatic(std::string owner, std::string name, std::string descriptor) -> code_builder&;
512
519 auto putstatic(std::string owner, std::string name, std::string descriptor) -> code_builder&;
520
527 auto getfield(std::string owner, std::string name, std::string descriptor) -> code_builder&;
528
535 auto putfield(std::string owner, std::string name, std::string descriptor) -> code_builder&;
536
543 auto invokevirtual(std::string owner, std::string name, std::string descriptor) -> code_builder&;
544
552 auto invokespecial(std::string owner, std::string name, std::string descriptor, method_owner_kind owner_kind = method_owner_kind::class_) -> code_builder&;
553
561 auto invokestatic(std::string owner, std::string name, std::string descriptor, method_owner_kind owner_kind = method_owner_kind::class_) -> code_builder&;
562
569 auto invokeinterface(std::string owner, std::string name, std::string descriptor) -> code_builder&;
570
575 auto new_(std::string class_name) -> code_builder&;
576
581 auto anewarray(std::string class_name) -> code_builder&;
582
587 auto checkcast(std::string class_name) -> code_builder&;
588
593 auto instanceof_(std::string class_name) -> code_builder&;
594
602 auto add_exception_handler(label start, label end, label handler, std::optional< std::string > catch_type = std::nullopt) -> code_builder&;
603
609 auto add_line_number(label start, std::uint16_t line_number) -> code_builder&;
610
619 auto add_local_variable(label start, label end, std::string name, std::string descriptor, local_variable_index index) -> code_builder&;
620
629 auto add_local_variable_type(label start, label end, std::string name, std::string signature, local_variable_index index) -> code_builder&;
630
636
645 [[nodiscard]] code_attribute finish(code_build_context const& context, constant_pool_builder& constant_pool, class_hierarchy_resolver_ref hierarchy = {}) const;
646
650 [[nodiscard]] std::vector< assembly_element > const& elements() const noexcept;
651
652 private:
654 void require_owned_label(label value) const;
655
656 std::vector< assembly_element > m_elements;
657 std::vector< labeled_exception_handler > m_exception_handlers;
658 std::vector< labeled_line_number > m_line_numbers;
659 std::vector< labeled_local_variable > m_local_variables;
660 std::vector< labeled_local_variable_type > m_local_variable_types;
661 std::optional< stack_map_table_attribute > m_stack_map_table;
662 label_owner m_label_owner;
663 std::size_t m_next_label{};
664 };
665
673 {
674 public:
680 explicit class_file_builder(std::string_view class_name, std::string_view super_class_name = "java/lang/Object", class_file_version version = {0, 70});
681
687
691 [[nodiscard]] auto access_flags() noexcept -> class_access_flags&;
692
696 [[nodiscard]] auto version() noexcept -> class_file_version&;
697
701 [[nodiscard]] auto constant_pool() noexcept -> constant_pool_builder&;
702
707 auto add_interface(std::string_view internal_name) -> class_file_builder&;
708
712 [[nodiscard]] auto fields() noexcept -> std::vector< field_info >&;
713
717 [[nodiscard]] auto methods() noexcept -> std::vector< method_info >&;
718
722 [[nodiscard]] auto attributes() noexcept -> std::vector< class_attribute >&;
723
735 auto add_method(std::string_view name, std::string_view descriptor, method_access_flags flags, code_builder const& code, code_build_options const& options = {}, class_hierarchy_resolver_ref hierarchy = {}) -> method_info&;
736
743 auto add_field(std::string_view name, std::string_view descriptor, field_access_flags flags) -> field_info&;
744
748 [[nodiscard]] class_file build() const;
749
750 private:
751 class_file m_class;
752 constant_pool_builder m_constant_pool;
753 };
754} // namespace rpnx::cortado
755
756#endif // RPNX_CORTADO_BUILDERS_HPP
Class-file serialization, deserialization, and iterator adapters.
auto fields() noexcept -> std::vector< field_info > &
Returns the mutable exact field sequence for transformations.
auto access_flags() noexcept -> class_access_flags &
Returns the mutable class access flags.
auto add_method(std::string_view name, std::string_view descriptor, method_access_flags flags, code_builder const &code, code_build_options const &options={}, class_hierarchy_resolver_ref hierarchy={}) -> method_info &
Adds a method with a symbolic Code body.
auto add_field(std::string_view name, std::string_view descriptor, field_access_flags flags) -> field_info &
Adds a field without attributes.
auto version() noexcept -> class_file_version &
Returns the mutable class-file version.
auto add_interface(std::string_view internal_name) -> class_file_builder &
Adds an implemented or extended interface by internal class name.
class_file_builder(std::string_view class_name, std::string_view super_class_name="java/lang/Object", class_file_version version={0, 70})
Creates a new class with the supplied internal names.
auto constant_pool() noexcept -> constant_pool_builder &
Returns the shared constant-pool interner.
class_file build() const
Returns a complete exact class-file model.
auto methods() noexcept -> std::vector< method_info > &
Returns the mutable exact method sequence for transformations.
auto attributes() noexcept -> std::vector< class_attribute > &
Returns the mutable typed class-attribute sequence for transformations.
class_file_builder(class_file value)
Initializes a builder from an exact parsed class model.
Non-owning type-erased class-hierarchy resolver used for reference merges.
Definition builders.hpp:286
std::string common_superclass(std::string_view left, std::string_view right) const
Resolves the least common superclass of two internal class names.
class_hierarchy_resolver_ref()=default
Constructs an empty resolver.
class_hierarchy_resolver_ref(Resolver &resolver) noexcept
Refers to an object exposing common_superclass(string_view, string_view).
Definition builders.hpp:296
An owning symbolic JVM code builder.
Definition builders.hpp:356
std::vector< assembly_element > const & elements() const noexcept
Returns the symbolic element sequence.
auto astore(local_variable_index index) -> code_builder &
Stores a reference into a local using the shortest valid encoding.
auto iload(local_variable_index index) -> code_builder &
Loads an int from a local using the shortest valid encoding.
auto bipush(std::int8_t value) -> code_builder &
Pushes a signed byte constant.
auto invokeinterface(std::string owner, std::string name, std::string descriptor) -> code_builder &
Emits a symbolic invokeinterface instruction.
auto aload(local_variable_index index) -> code_builder &
Loads a reference 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.
code_builder()
Constructs an empty builder with a unique label-ownership token.
auto append() -> code_builder &
Appends an operand-free instruction selected at compile time.
Definition builders.hpp:385
auto checkcast(std::string class_name) -> code_builder &
Emits a symbolic checkcast instruction.
auto iinc(local_variable_index index, std::int16_t amount) -> code_builder &
Increments an int local using compact or wide form as required.
auto bind(label value) -> code_builder &
Binds a label at the current instruction position.
auto istore(local_variable_index index) -> code_builder &
Stores an int into a local using the shortest valid encoding.
auto putfield(std::string owner, std::string name, std::string descriptor) -> code_builder &
Emits a symbolic putfield instruction.
auto dload(local_variable_index index) -> code_builder &
Loads a double from a local using the shortest valid encoding.
label new_label()
Creates a fresh label owned by this builder.
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 invokevirtual(std::string owner, std::string name, std::string descriptor) -> code_builder &
Emits a symbolic invokevirtual instruction.
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 anewarray(std::string class_name) -> code_builder &
Emits a symbolic anewarray instruction.
auto instanceof_(std::string class_name) -> code_builder &
Emits a symbolic instanceof instruction.
auto tableswitch(label default_target, std::int32_t low, std::vector< label > targets) -> code_builder &
Appends a symbolic tableswitch.
auto putstatic(std::string owner, std::string name, std::string descriptor) -> code_builder &
Emits a symbolic putstatic instruction.
auto branch(label target) -> code_builder &
Appends a compile-time-typed labeled branch.
Definition builders.hpp:397
auto fstore(local_variable_index index) -> code_builder &
Stores a float into a local using the shortest valid encoding.
auto lookupswitch(label default_target, std::vector< labeled_lookup_switch_pair > pairs) -> code_builder &
Appends a symbolic lookupswitch.
auto add_line_number(label start, std::uint16_t line_number) -> code_builder &
Associates a source line with a symbolic code position.
auto getstatic(std::string owner, std::string name, std::string descriptor) -> code_builder &
Emits a symbolic getstatic 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 getfield(std::string owner, std::string name, std::string descriptor) -> code_builder &
Emits a symbolic getfield instruction.
auto set_stack_map_table(stack_map_table_attribute value) -> code_builder &
Supplies an exact StackMapTable and bypasses automatic frame generation.
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 dstore(local_variable_index index) -> code_builder &
Stores a double into 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 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 sipush(std::int16_t value) -> code_builder &
Pushes a signed short constant.
auto new_(std::string class_name) -> code_builder &
Emits a symbolic new instruction.
auto append(instruction value) -> code_builder &
Appends one exact instruction encoding.
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.
auto lstore(local_variable_index index) -> code_builder &
Stores a long into a local using the shortest valid encoding.
auto ldc_string(std::string value) -> code_builder &
Loads a string through an automatically interned ldc or ldc_w instruction.
Interns constant-pool entries while retaining deterministic first-insertion order.
Definition builders.hpp:183
constant_pool_index add_name_and_type(std::string_view name, std::string_view descriptor)
Interns a CONSTANT_NameAndType.
constant_pool_index add_interface_methodref(std::string_view owner, std::string_view name, std::string_view descriptor)
Interns a CONSTANT_InterfaceMethodref.
std::string_view utf8_at(constant_pool_index index) const
Returns modified-UTF-8 bytes by logical constant-pool index.
std::vector< constant_pool_entry > build() const
Copies the exact current entry sequence.
constant_pool_entry const & entry_at(constant_pool_index index) const
Returns an exact entry by logical constant-pool index.
constant_pool_index add_utf8(std::string_view bytes)
Interns a modified-UTF-8 byte sequence.
std::vector< constant_pool_entry > const & entries() const noexcept
Returns the exact current entry sequence.
constant_pool_index add_string(std::string_view bytes)
Interns a CONSTANT_String and its modified-UTF-8 payload.
constant_pool_index add_class(std::string_view internal_name)
Interns a CONSTANT_Class and its name.
constant_pool_index add_fieldref(std::string_view owner, std::string_view name, std::string_view descriptor)
Interns a CONSTANT_Fieldref.
constant_pool_index add_methodref(std::string_view owner, std::string_view name, std::string_view descriptor)
Interns a CONSTANT_Methodref.
constant_pool_index intern(constant_pool_entry entry)
Interns an exact constant-pool entry.
constant_pool_builder()=default
Constructs an empty constant pool.
constant_pool_builder(std::vector< constant_pool_entry > entries)
Initializes an interner from an exact existing pool.
Owning syntax trees and codecs for JVM field and method descriptors.
JVM class-file, bytecode, validation, generation, and JAR APIs.
processing_mode
Controls whether invalid-but-preservable tool input is accepted.
Definition bytecode.hpp:26
std::variant< simple_instruction< opcode::nop >, simple_instruction< opcode::aconst_null >, simple_instruction< opcode::iconst_m1 >, simple_instruction< opcode::iconst_0 >, simple_instruction< opcode::iconst_1 >, simple_instruction< opcode::iconst_2 >, simple_instruction< opcode::iconst_3 >, simple_instruction< opcode::iconst_4 >, simple_instruction< opcode::iconst_5 >, simple_instruction< opcode::lconst_0 >, simple_instruction< opcode::lconst_1 >, simple_instruction< opcode::fconst_0 >, simple_instruction< opcode::fconst_1 >, simple_instruction< opcode::fconst_2 >, simple_instruction< opcode::dconst_0 >, simple_instruction< opcode::dconst_1 >, signed_byte_instruction< opcode::bipush >, signed_short_instruction< opcode::sipush >, constant_pool_index8_instruction< opcode::ldc >, constant_pool_index16_instruction< opcode::ldc_w >, constant_pool_index16_instruction< opcode::ldc2_w >, local_instruction< opcode::iload >, local_instruction< opcode::lload >, local_instruction< opcode::fload >, local_instruction< opcode::dload >, local_instruction< opcode::aload >, simple_instruction< opcode::iload_0 >, simple_instruction< opcode::iload_1 >, simple_instruction< opcode::iload_2 >, simple_instruction< opcode::iload_3 >, simple_instruction< opcode::lload_0 >, simple_instruction< opcode::lload_1 >, simple_instruction< opcode::lload_2 >, simple_instruction< opcode::lload_3 >, simple_instruction< opcode::fload_0 >, simple_instruction< opcode::fload_1 >, simple_instruction< opcode::fload_2 >, simple_instruction< opcode::fload_3 >, simple_instruction< opcode::dload_0 >, simple_instruction< opcode::dload_1 >, simple_instruction< opcode::dload_2 >, simple_instruction< opcode::dload_3 >, simple_instruction< opcode::aload_0 >, simple_instruction< opcode::aload_1 >, simple_instruction< opcode::aload_2 >, simple_instruction< opcode::aload_3 >, simple_instruction< opcode::iaload >, simple_instruction< opcode::laload >, simple_instruction< opcode::faload >, simple_instruction< opcode::daload >, simple_instruction< opcode::aaload >, simple_instruction< opcode::baload >, simple_instruction< opcode::caload >, simple_instruction< opcode::saload >, local_instruction< opcode::istore >, local_instruction< opcode::lstore >, local_instruction< opcode::fstore >, local_instruction< opcode::dstore >, local_instruction< opcode::astore >, simple_instruction< opcode::istore_0 >, simple_instruction< opcode::istore_1 >, simple_instruction< opcode::istore_2 >, simple_instruction< opcode::istore_3 >, simple_instruction< opcode::lstore_0 >, simple_instruction< opcode::lstore_1 >, simple_instruction< opcode::lstore_2 >, simple_instruction< opcode::lstore_3 >, simple_instruction< opcode::fstore_0 >, simple_instruction< opcode::fstore_1 >, simple_instruction< opcode::fstore_2 >, simple_instruction< opcode::fstore_3 >, simple_instruction< opcode::dstore_0 >, simple_instruction< opcode::dstore_1 >, simple_instruction< opcode::dstore_2 >, simple_instruction< opcode::dstore_3 >, simple_instruction< opcode::astore_0 >, simple_instruction< opcode::astore_1 >, simple_instruction< opcode::astore_2 >, simple_instruction< opcode::astore_3 >, simple_instruction< opcode::iastore >, simple_instruction< opcode::lastore >, simple_instruction< opcode::fastore >, simple_instruction< opcode::dastore >, simple_instruction< opcode::aastore >, simple_instruction< opcode::bastore >, simple_instruction< opcode::castore >, simple_instruction< opcode::sastore >, simple_instruction< opcode::pop >, simple_instruction< opcode::pop2 >, simple_instruction< opcode::dup >, simple_instruction< opcode::dup_x1 >, simple_instruction< opcode::dup_x2 >, simple_instruction< opcode::dup2 >, simple_instruction< opcode::dup2_x1 >, simple_instruction< opcode::dup2_x2 >, simple_instruction< opcode::swap >, simple_instruction< opcode::iadd >, simple_instruction< opcode::ladd >, simple_instruction< opcode::fadd >, simple_instruction< opcode::dadd >, simple_instruction< opcode::isub >, simple_instruction< opcode::lsub >, simple_instruction< opcode::fsub >, simple_instruction< opcode::dsub >, simple_instruction< opcode::imul >, simple_instruction< opcode::lmul >, simple_instruction< opcode::fmul >, simple_instruction< opcode::dmul >, simple_instruction< opcode::idiv >, simple_instruction< opcode::ldiv >, simple_instruction< opcode::fdiv >, simple_instruction< opcode::ddiv >, simple_instruction< opcode::irem >, simple_instruction< opcode::lrem >, simple_instruction< opcode::frem >, simple_instruction< opcode::drem >, simple_instruction< opcode::ineg >, simple_instruction< opcode::lneg >, simple_instruction< opcode::fneg >, simple_instruction< opcode::dneg >, simple_instruction< opcode::ishl >, simple_instruction< opcode::lshl >, simple_instruction< opcode::ishr >, simple_instruction< opcode::lshr >, simple_instruction< opcode::iushr >, simple_instruction< opcode::lushr >, simple_instruction< opcode::iand >, simple_instruction< opcode::land >, simple_instruction< opcode::ior >, simple_instruction< opcode::lor >, simple_instruction< opcode::ixor >, simple_instruction< opcode::lxor >, iinc_instruction, simple_instruction< opcode::i2l >, simple_instruction< opcode::i2f >, simple_instruction< opcode::i2d >, simple_instruction< opcode::l2i >, simple_instruction< opcode::l2f >, simple_instruction< opcode::l2d >, simple_instruction< opcode::f2i >, simple_instruction< opcode::f2l >, simple_instruction< opcode::f2d >, simple_instruction< opcode::d2i >, simple_instruction< opcode::d2l >, simple_instruction< opcode::d2f >, simple_instruction< opcode::i2b >, simple_instruction< opcode::i2c >, simple_instruction< opcode::i2s >, simple_instruction< opcode::lcmp >, simple_instruction< opcode::fcmpl >, simple_instruction< opcode::fcmpg >, simple_instruction< opcode::dcmpl >, simple_instruction< opcode::dcmpg >, branch16_instruction< opcode::ifeq >, branch16_instruction< opcode::ifne >, branch16_instruction< opcode::iflt >, branch16_instruction< opcode::ifge >, branch16_instruction< opcode::ifgt >, branch16_instruction< opcode::ifle >, branch16_instruction< opcode::if_icmpeq >, branch16_instruction< opcode::if_icmpne >, branch16_instruction< opcode::if_icmplt >, branch16_instruction< opcode::if_icmpge >, branch16_instruction< opcode::if_icmpgt >, branch16_instruction< opcode::if_icmple >, branch16_instruction< opcode::if_acmpeq >, branch16_instruction< opcode::if_acmpne >, branch16_instruction< opcode::goto_ >, branch16_instruction< opcode::jsr >, local_instruction< opcode::ret >, tableswitch_instruction, lookupswitch_instruction, simple_instruction< opcode::ireturn >, simple_instruction< opcode::lreturn >, simple_instruction< opcode::freturn >, simple_instruction< opcode::dreturn >, simple_instruction< opcode::areturn >, simple_instruction< opcode::return_ >, constant_pool_index16_instruction< opcode::getstatic >, constant_pool_index16_instruction< opcode::putstatic >, constant_pool_index16_instruction< opcode::getfield >, constant_pool_index16_instruction< opcode::putfield >, constant_pool_index16_instruction< opcode::invokevirtual >, constant_pool_index16_instruction< opcode::invokespecial >, constant_pool_index16_instruction< opcode::invokestatic >, invokeinterface_instruction, invokedynamic_instruction, constant_pool_index16_instruction< opcode::new_ >, newarray_instruction, constant_pool_index16_instruction< opcode::anewarray >, simple_instruction< opcode::arraylength >, simple_instruction< opcode::athrow >, constant_pool_index16_instruction< opcode::checkcast >, constant_pool_index16_instruction< opcode::instanceof_ >, simple_instruction< opcode::monitorenter >, simple_instruction< opcode::monitorexit >, wide_instruction, multianewarray_instruction, branch16_instruction< opcode::ifnull >, branch16_instruction< opcode::ifnonnull >, branch32_instruction< opcode::goto_w >, branch32_instruction< opcode::jsr_w >, simple_instruction< opcode::breakpoint >, simple_instruction< opcode::impdep1 >, simple_instruction< opcode::impdep2 > > instruction
Every exact JVM instruction encoding supported by Java SE 26.
Definition bytecode.hpp:236
field_access_flags
JVM field access flags.
Definition types.hpp:67
method_owner_kind
Selects the constant-pool owner kind for a symbolic method reference.
Definition builders.hpp:133
opcode
Every defined Java SE 26 opcode, plus the three permanently reserved opcodes.
Definition bytecode.hpp:60
std::variant< utf8_constant, integer_constant, float_constant, long_constant, double_constant, class_constant, string_constant, fieldref_constant, methodref_constant, interface_methodref_constant, name_and_type_constant, method_handle_constant, method_type_constant, dynamic_constant, invoke_dynamic_constant, module_constant, package_constant > constant_pool_entry
A typed JVM constant-pool entry.
Definition types.hpp:245
class_access_flags
JVM class access flags.
Definition types.hpp:58
std::variant< instruction, label_binding, labeled_branch_instruction< opcode::ifeq >, labeled_branch_instruction< opcode::ifne >, labeled_branch_instruction< opcode::iflt >, labeled_branch_instruction< opcode::ifge >, labeled_branch_instruction< opcode::ifgt >, labeled_branch_instruction< opcode::ifle >, labeled_branch_instruction< opcode::if_icmpeq >, labeled_branch_instruction< opcode::if_icmpne >, labeled_branch_instruction< opcode::if_icmplt >, labeled_branch_instruction< opcode::if_icmpge >, labeled_branch_instruction< opcode::if_icmpgt >, labeled_branch_instruction< opcode::if_icmple >, labeled_branch_instruction< opcode::if_acmpeq >, labeled_branch_instruction< opcode::if_acmpne >, labeled_branch_instruction< opcode::goto_ >, labeled_branch_instruction< opcode::jsr >, labeled_branch_instruction< opcode::ifnull >, labeled_branch_instruction< opcode::ifnonnull >, labeled_tableswitch_instruction, labeled_lookupswitch_instruction, symbolic_field_instruction< opcode::getstatic >, symbolic_field_instruction< opcode::putstatic >, symbolic_field_instruction< opcode::getfield >, symbolic_field_instruction< opcode::putfield >, symbolic_method_instruction< opcode::invokevirtual >, symbolic_method_instruction< opcode::invokespecial >, symbolic_method_instruction< opcode::invokestatic >, symbolic_invokeinterface_instruction, symbolic_class_instruction< opcode::new_ >, symbolic_class_instruction< opcode::anewarray >, symbolic_class_instruction< opcode::checkcast >, symbolic_class_instruction< opcode::instanceof_ >, symbolic_string_instruction > assembly_element
Every element accepted by code_builder before lowering.
Definition builders.hpp:173
method_access_flags
JVM method access flags.
Definition types.hpp:76
std::variant< inner_classes_attribute, enclosing_method_attribute, synthetic_attribute, signature_attribute, source_file_attribute, source_debug_extension_attribute, deprecated_attribute, runtime_visible_annotations_attribute, runtime_invisible_annotations_attribute, runtime_visible_type_annotations_attribute, runtime_invisible_type_annotations_attribute, bootstrap_methods_attribute, module_attribute, module_packages_attribute, module_main_class_attribute, nest_host_attribute, nest_members_attribute, record_attribute, permitted_subclasses_attribute, unknown_attribute > class_attribute
Attributes valid on a ClassFile structure.
A JVM class-file version pair.
Definition types.hpp:48
An owning, typed representation of one JVM class file.
A fully typed Code attribute.
Method context needed to finalize symbolic code.
Definition builders.hpp:337
class_file_version version
Version of the class that will contain the method.
Definition builders.hpp:338
method_access_flags access_flags
Flags that determine the initial local frame.
Definition builders.hpp:342
method_descriptor descriptor
Parsed descriptor that determines parameters, return type, and slots.
Definition builders.hpp:343
std::string method_name
Method name used for constructor verification rules.
Definition builders.hpp:341
constant_pool_index super_class_index
Constant-pool index of its direct superclass, or zero for java/lang/Object.
Definition builders.hpp:340
constant_pool_index owner_class_index
Constant-pool index of the containing class.
Definition builders.hpp:339
code_build_options options
Analysis and metadata policy.
Definition builders.hpp:344
Controls automatic Code metadata generation.
Definition builders.hpp:326
std::optional< std::uint16_t > max_stack
Exact requested maximum, or no value to use the analyzed requirement.
Definition builders.hpp:327
bool generate_stack_map_table
Emit analyzed frames unless an exact table was supplied.
Definition builders.hpp:330
bool perform_dataflow_analysis
Compute stack/local requirements and verifier states.
Definition builders.hpp:329
processing_mode mode
Strictness used while encoding the assembled code.
Definition builders.hpp:331
std::optional< std::uint16_t > max_locals
Exact requested maximum, or no value to use the analyzed requirement.
Definition builders.hpp:328
A type-safe index into a JVM constant pool.
Definition types.hpp:34
A JVM field_info structure.
A label binding in symbolic code.
Definition builders.hpp:42
label value
Label bound immediately before the following symbolic instruction.
Definition builders.hpp:43
Unique ownership token for labels created by one code_builder lineage.
Definition builders.hpp:27
std::uint64_t value
Process-local lineage identifier; clients must treat it as opaque.
Definition builders.hpp:28
A symbolic bytecode position owned by one code_builder.
Definition builders.hpp:34
label_owner owner
Builder lineage that created this label.
Definition builders.hpp:35
A branch whose target is a symbolic label.
Definition builders.hpp:50
label target
Symbolic branch destination owned by the containing builder.
Definition builders.hpp:52
A symbolic exception-table range.
Definition builders.hpp:83
label handler
First instruction of the handler.
Definition builders.hpp:86
label end
Exclusive protected-range end; may bind immediately after the final instruction.
Definition builders.hpp:85
label start
Inclusive protected-range start.
Definition builders.hpp:84
std::optional< std::string > catch_type
Internal exception class name, or no value for a catch-all handler.
Definition builders.hpp:87
A symbolic source line binding.
Definition builders.hpp:93
std::uint16_t line_number
Source-file line number.
Definition builders.hpp:95
label start
Instruction at which this source line begins.
Definition builders.hpp:94
A symbolic generic local-variable signature scope.
Definition builders.hpp:112
label start
Inclusive scope start.
Definition builders.hpp:113
std::string signature
Generic field signature for the local value.
Definition builders.hpp:116
local_variable_index index
First local-variable-array slot occupied.
Definition builders.hpp:117
std::string name
Source variable name encoded into the constant pool.
Definition builders.hpp:115
A symbolic local-variable scope.
Definition builders.hpp:101
std::string descriptor
JVM field descriptor for the local value.
Definition builders.hpp:105
local_variable_index index
First local-variable-array slot occupied.
Definition builders.hpp:106
std::string name
Source variable name encoded into the constant pool.
Definition builders.hpp:104
label end
Exclusive scope end.
Definition builders.hpp:103
label start
Inclusive scope start.
Definition builders.hpp:102
One symbolic lookupswitch match and target.
Definition builders.hpp:58
std::int32_t match
Lookup key; pairs supplied to a builder must be strictly increasing.
Definition builders.hpp:59
label target
Symbolic destination for this key.
Definition builders.hpp:60
std::vector< labeled_lookup_switch_pair > pairs
Strictly increasing match/target pairs.
Definition builders.hpp:77
label default_target
Destination used when no pair matches.
Definition builders.hpp:76
std::int32_t low
Key corresponding to the first target.
Definition builders.hpp:68
label default_target
Destination for keys outside the table.
Definition builders.hpp:67
std::vector< label > targets
Consecutive targets beginning at low; must not be empty.
Definition builders.hpp:69
A JVM local-variable-array index.
Definition bytecode.hpp:30
A parsed JVM method descriptor.
A JVM method_info structure.
An instruction whose encoding contains only its opcode.
Definition bytecode.hpp:65
A symbolic class-reference instruction.
Definition builders.hpp:159
std::string internal_name
Slash-separated class name or array descriptor required by the opcode.
Definition builders.hpp:161
A symbolic field-access instruction.
Definition builders.hpp:124
std::string descriptor
JVM field descriptor.
Definition builders.hpp:128
std::string owner
Slash-separated declaring class internal name.
Definition builders.hpp:126
A symbolic interface-method invocation instruction.
Definition builders.hpp:149
std::string descriptor
JVM method descriptor used to derive the argument count.
Definition builders.hpp:152
std::string owner
Slash-separated declaring interface internal name.
Definition builders.hpp:150
std::string name
Interface method name.
Definition builders.hpp:151
A symbolic class or interface method invocation instruction.
Definition builders.hpp:138
std::string descriptor
JVM method descriptor.
Definition builders.hpp:142
std::string owner
Slash-separated declaring type internal name.
Definition builders.hpp:140
std::string name
Method name, including special JVM names where applicable.
Definition builders.hpp:141
method_owner_kind owner_kind
Constant-pool reference kind for the owner.
Definition builders.hpp:143
A symbolic string ldc instruction.
Definition builders.hpp:167
std::string value
Modified-UTF-8 string contents to intern and load.
Definition builders.hpp:168