| 1 | package SPVM::JIT; | ||
| 2 | |||
| 3 | 1; | ||
| 4 | |||
| 5 | =encoding utf8 | ||
| 6 | |||
| 7 | =head1 Name | ||
| 8 | |||
| 9 | SPVM::JIT - Abstract Base Class for Just-In-Time Compilation | ||
| 10 | |||
| 11 | =head1 Description | ||
| 12 | |||
| 13 | C<JIT> class in L<SPVM> is an abstract base class that defines the interface for JIT (Just-In-Time) compilation. | ||
| 14 | |||
| 15 | To use JIT features, you must use a child class that implements the methods in this class, such as C<JIT::TCC>. | ||
| 16 | |||
| 17 | =head1 Usage | ||
| 18 | |||
| 19 | use JIT::TCC; | ||
| 20 | |||
| 21 | # Use a child class like JIT::TCC | ||
| 22 | my $jit = JIT::TCC->new; | ||
| 23 | |||
| 24 | # Compile a pre-compiled C source code | ||
| 25 | my $source = "SPVMPRECOMPILE__MyClass__add(SPVM_ENV* env, SPVM_VALUE* stack) { /* ... */ }"; | ||
| 26 | $jit->compile($source); | ||
| 27 | |||
| 28 | # Get method address | ||
| 29 | my $address = $jit->get_address("MyClass", "add"); | ||
| 30 | |||
| 31 | =head1 Details | ||
| 32 | |||
| 33 | This class provides an interface to compile pre-compiled C source code into machine code at runtime. | ||
| 34 | |||
| 35 | The "pre-compiled C source code" typically refers to C code that has been generated or processed by SPVM before being passed to the JIT engine. By using JIT, you can execute these dynamic C codes for high-performance computing or runtime library integration. | ||
| 36 | |||
| 37 | This class is an abstract class. The L</"compile"> and L</"get_address"> methods must be implemented in a child class. | ||
| 38 | |||
| 39 | =head1 Instance Methods | ||
| 40 | |||
| 41 | =head2 compile | ||
| 42 | |||
| 43 | C<method compile : void ($source : string);> | ||
| 44 | |||
| 45 | An abstract method that compiles the given pre-compiled C source code into machine code. In a child class, this method must be implemented. If an error occurs during compilation, an exception is thrown. | ||
| 46 | |||
| 47 | =head2 get_address | ||
| 48 | |||
| 49 | C<method get_address : L<Address|SPVM::Address> ($class_name : string, $method_name : string);> | ||
| 50 | |||
| 51 | An abstract method that returns the memory address of a method defined by the given class name and method name. In a child class, this method must be implemented. If the method is not found, an exception is thrown. | ||
| 52 | |||
| 53 | =head1 Copyright & License | ||
| 54 | |||
| 55 | Copyright (c) 2026 Yuki Kimoto | ||
| 56 | |||
| 57 | MIT License |