pub struct Context<'ctx> { /* private fields */ }
Expand description
Wrapper around a GCC JIT context object that keeps the state of the JIT compiler. In GCCJIT, this object is responsible for all memory management of JIT data structures, and as such anything made from this context must have a lifetime strictly less than this object.
It’s possible to create a child context from a parent context. In that case, the child context must have a lifetime strictly less than the parent context.
Implementations§
source§impl<'ctx> Context<'ctx>
impl<'ctx> Context<'ctx>
sourcepub fn set_program_name<S: AsRef<str>>(&self, name: S)
pub fn set_program_name<S: AsRef<str>>(&self, name: S)
Sets the program name reported by the JIT.
pub fn add_command_line_option<S: AsRef<str>>(&self, name: S)
pub fn add_driver_option<S: AsRef<str>>(&self, name: S)
sourcepub fn set_optimization_level(&self, level: OptimizationLevel)
pub fn set_optimization_level(&self, level: OptimizationLevel)
Sets the optimization level that the JIT compiler will use. The higher the optimization level, the longer compilation will take.
pub fn set_debug_info(&self, value: bool)
pub fn set_keep_intermediates(&self, value: bool)
pub fn set_print_errors_to_stderr(&self, enabled: bool)
pub fn set_dump_everything(&self, value: bool)
pub fn set_dump_initial_gimple(&self, value: bool)
sourcepub fn set_dump_code_on_compile(&self, value: bool)
pub fn set_dump_code_on_compile(&self, value: bool)
When set to true, dumps the code that the JIT generates to standard out during compilation.
pub fn set_allow_unreachable_blocks(&self, value: bool)
sourcepub fn compile(&self) -> CompileResult
pub fn compile(&self) -> CompileResult
Compiles the context and returns a CompileResult that contains the means to access functions and globals that have currently been JIT compiled.
sourcepub fn compile_to_file<S: AsRef<str>>(&self, kind: OutputKind, file: S)
pub fn compile_to_file<S: AsRef<str>>(&self, kind: OutputKind, file: S)
Compiles the context and saves the result to a file. The type of the file is controlled by the OutputKind parameter.
sourcepub fn new_child_context<'b>(&'b self) -> Context<'b>
pub fn new_child_context<'b>(&'b self) -> Context<'b>
Creates a new child context from this context. The child context is a fully-featured context, but it has a lifetime that is strictly less than the lifetime that spawned it.
pub fn new_case<S: ToRValue<'ctx>, T: ToRValue<'ctx>>( &self, min_value: S, max_value: T, dest_block: Block<'ctx> ) -> Case<'ctx>
sourcepub fn new_location<'a, S: AsRef<str>>(
&'a self,
filename: S,
line: i32,
col: i32
) -> Location<'a>
pub fn new_location<'a, S: AsRef<str>>( &'a self, filename: S, line: i32, col: i32 ) -> Location<'a>
Creates a new location for use by gdb when debugging a JIT compiled program. The filename, line, and col are used by gdb to “show” your source when in a debugger.
pub fn new_global<'a, S: AsRef<str>>( &self, loc: Option<Location<'a>>, kind: GlobalKind, ty: Type<'a>, name: S ) -> LValue<'a>
sourcepub fn new_type<'a, T: Typeable>(&'a self) -> Type<'a>
pub fn new_type<'a, T: Typeable>(&'a self) -> Type<'a>
Constructs a new type for any type that implements the Typeable trait. This library only provides a handful of implementations of Typeable for some primitive types - utilizers of this library are encouraged to provide their own types that implement Typeable for ease of type creation.
pub fn new_c_type<'a>(&'a self, c_type: CType) -> Type<'a>
pub fn new_int_type<'a>(&'a self, num_bytes: i32, signed: bool) -> Type<'a>
sourcepub fn new_field<'a, S: AsRef<str>>(
&'a self,
loc: Option<Location<'a>>,
ty: Type<'a>,
name: S
) -> Field<'a>
pub fn new_field<'a, S: AsRef<str>>( &'a self, loc: Option<Location<'a>>, ty: Type<'a>, name: S ) -> Field<'a>
Constructs a new field with an optional source location, type, and name. This field can be used to compose unions or structs.
sourcepub fn new_array_type<'a>(
&'a self,
loc: Option<Location<'a>>,
ty: Type<'a>,
num_elements: u64
) -> Type<'a>
pub fn new_array_type<'a>( &'a self, loc: Option<Location<'a>>, ty: Type<'a>, num_elements: u64 ) -> Type<'a>
Constructs a new array type with a given base element type and a size.
pub fn new_vector_type<'a>(&'a self, ty: Type<'a>, num_units: u64) -> Type<'a>
sourcepub fn new_struct_type<'a, S: AsRef<str>>(
&'a self,
loc: Option<Location<'a>>,
name: S,
fields: &[Field<'a>]
) -> Struct<'a>
pub fn new_struct_type<'a, S: AsRef<str>>( &'a self, loc: Option<Location<'a>>, name: S, fields: &[Field<'a>] ) -> Struct<'a>
Constructs a new struct type with the given name, optional source location, and a list of fields. The returned struct is concrete and new fields cannot be added to it.
sourcepub fn new_opaque_struct_type<'a, S: AsRef<str>>(
&'a self,
loc: Option<Location<'a>>,
name: S
) -> Struct<'a>
pub fn new_opaque_struct_type<'a, S: AsRef<str>>( &'a self, loc: Option<Location<'a>>, name: S ) -> Struct<'a>
Constructs a new struct type whose fields are not known. Fields can be added to this struct later, but only once.
sourcepub fn new_union_type<'a, S: AsRef<str>>(
&'a self,
loc: Option<Location<'a>>,
name: S,
fields: &[Field<'a>]
) -> Type<'a>
pub fn new_union_type<'a, S: AsRef<str>>( &'a self, loc: Option<Location<'a>>, name: S, fields: &[Field<'a>] ) -> Type<'a>
Creates a new union type from a set of fields.
sourcepub fn new_function_pointer_type<'a>(
&'a self,
loc: Option<Location<'a>>,
return_type: Type<'a>,
param_types: &[Type<'a>],
is_variadic: bool
) -> Type<'a>
pub fn new_function_pointer_type<'a>( &'a self, loc: Option<Location<'a>>, return_type: Type<'a>, param_types: &[Type<'a>], is_variadic: bool ) -> Type<'a>
Creates a new function pointer type with the given return type parameter types, and an optional location. The last flag can make the function variadic, although Rust can’t really handle the varargs calling convention.
sourcepub fn new_function<'a, S: AsRef<str>>(
&'a self,
loc: Option<Location<'a>>,
kind: FunctionType,
return_ty: Type<'a>,
params: &[Parameter<'a>],
name: S,
is_variadic: bool
) -> Function<'a>
pub fn new_function<'a, S: AsRef<str>>( &'a self, loc: Option<Location<'a>>, kind: FunctionType, return_ty: Type<'a>, params: &[Parameter<'a>], name: S, is_variadic: bool ) -> Function<'a>
Creates a new function with the given function kind, return type, parameters, name, and whether or not the function is variadic.
sourcepub fn new_binary_op<'a, L: ToRValue<'a>, R: ToRValue<'a>>(
&'a self,
loc: Option<Location<'a>>,
op: BinaryOp,
ty: Type<'a>,
left: L,
right: R
) -> RValue<'a>
pub fn new_binary_op<'a, L: ToRValue<'a>, R: ToRValue<'a>>( &'a self, loc: Option<Location<'a>>, op: BinaryOp, ty: Type<'a>, left: L, right: R ) -> RValue<'a>
Creates a new binary operation between two RValues and produces a new RValue.
sourcepub fn new_unary_op<'a, T: ToRValue<'a>>(
&'a self,
loc: Option<Location<'a>>,
op: UnaryOp,
ty: Type<'a>,
target: T
) -> RValue<'a>
pub fn new_unary_op<'a, T: ToRValue<'a>>( &'a self, loc: Option<Location<'a>>, op: UnaryOp, ty: Type<'a>, target: T ) -> RValue<'a>
Creates a unary operation on one RValue and produces a result RValue.
pub fn new_comparison<'a, L: ToRValue<'a>, R: ToRValue<'a>>( &'a self, loc: Option<Location<'a>>, op: ComparisonOp, left: L, right: R ) -> RValue<'a>
sourcepub fn new_call<'a>(
&'a self,
loc: Option<Location<'a>>,
func: Function<'a>,
args: &[RValue<'a>]
) -> RValue<'a>
pub fn new_call<'a>( &'a self, loc: Option<Location<'a>>, func: Function<'a>, args: &[RValue<'a>] ) -> RValue<'a>
Creates a function call to a function object with a given number of parameters. The RValue that is returned is the result of the function call. Note that due to the way that Rust’s generics work, it is currently not possible to be generic over different types of arguments (RValues together with LValues and Parameters, for example), so in order to mix the types of the arguments it may be necessary to call to_rvalue() before calling this function.
sourcepub fn new_call_through_ptr<'a, F: ToRValue<'a>>(
&'a self,
loc: Option<Location<'a>>,
fun_ptr: F,
args: &[RValue<'a>]
) -> RValue<'a>
pub fn new_call_through_ptr<'a, F: ToRValue<'a>>( &'a self, loc: Option<Location<'a>>, fun_ptr: F, args: &[RValue<'a>] ) -> RValue<'a>
Creates an indirect function call that dereferences a function pointer and attempts to invoke it with the given arguments. The RValue that is returned is the result of the function call.
sourcepub fn new_cast<'a, T: ToRValue<'a>>(
&'a self,
loc: Option<Location<'a>>,
value: T,
dest_type: Type<'a>
) -> RValue<'a>
pub fn new_cast<'a, T: ToRValue<'a>>( &'a self, loc: Option<Location<'a>>, value: T, dest_type: Type<'a> ) -> RValue<'a>
Cast an RValue to a specific type. I don’t know what happens when the cast fails yet.
sourcepub fn new_bitcast<'a, T: ToRValue<'a>>(
&'a self,
loc: Option<Location<'a>>,
value: T,
dest_type: Type<'a>
) -> RValue<'a>
pub fn new_bitcast<'a, T: ToRValue<'a>>( &'a self, loc: Option<Location<'a>>, value: T, dest_type: Type<'a> ) -> RValue<'a>
Bitcast an RValue to a specific type.
sourcepub fn new_array_access<'a, A: ToRValue<'a>, I: ToRValue<'a>>(
&'a self,
loc: Option<Location<'a>>,
array_ptr: A,
index: I
) -> LValue<'a>
pub fn new_array_access<'a, A: ToRValue<'a>, I: ToRValue<'a>>( &'a self, loc: Option<Location<'a>>, array_ptr: A, index: I ) -> LValue<'a>
Creates an LValue from an array pointer and an offset. The LValue can be the target of an assignment, or it can be converted into an RValue (i.e. loaded).
sourcepub fn new_rvalue_from_long<'a>(
&'a self,
ty: Type<'a>,
value: i64
) -> RValue<'a>
pub fn new_rvalue_from_long<'a>( &'a self, ty: Type<'a>, value: i64 ) -> RValue<'a>
Creates a new RValue from a given long value.
pub fn new_rvalue_from_vector<'a>( &'a self, loc: Option<Location<'a>>, vec_type: Type<'a>, elements: &[RValue<'a>] ) -> RValue<'a>
pub fn new_struct_constructor<'a>( &'a self, loc: Option<Location<'a>>, struct_type: Type<'a>, fields: Option<&[Field<'a>]>, values: &[RValue<'a>] ) -> RValue<'a>
pub fn new_array_constructor<'a>( &'a self, loc: Option<Location<'a>>, array_type: Type<'a>, elements: &[RValue<'a>] ) -> RValue<'a>
sourcepub fn new_rvalue_from_int<'a>(&'a self, ty: Type<'a>, value: i32) -> RValue<'a>
pub fn new_rvalue_from_int<'a>(&'a self, ty: Type<'a>, value: i32) -> RValue<'a>
Creates a new RValue from a given int value.
sourcepub fn new_rvalue_from_double<'a>(
&'a self,
ty: Type<'a>,
value: f64
) -> RValue<'a>
pub fn new_rvalue_from_double<'a>( &'a self, ty: Type<'a>, value: f64 ) -> RValue<'a>
Creates a new RValue from a given double value.
sourcepub fn new_rvalue_zero<'a>(&'a self, ty: Type<'a>) -> RValue<'a>
pub fn new_rvalue_zero<'a>(&'a self, ty: Type<'a>) -> RValue<'a>
Creates a zero element for a given type.
sourcepub fn new_rvalue_one<'a>(&'a self, ty: Type<'a>) -> RValue<'a>
pub fn new_rvalue_one<'a>(&'a self, ty: Type<'a>) -> RValue<'a>
Creates a one element for a given type.
sourcepub fn new_rvalue_from_ptr<'a>(
&'a self,
ty: Type<'a>,
value: *mut ()
) -> RValue<'a>
pub fn new_rvalue_from_ptr<'a>( &'a self, ty: Type<'a>, value: *mut () ) -> RValue<'a>
Creates an RValue for a raw pointer. This function requires that the lifetime of the pointer be greater than that of the jitted program.
sourcepub fn new_string_literal<'a, S: AsRef<str>>(&'a self, value: S) -> RValue<'a>
pub fn new_string_literal<'a, S: AsRef<str>>(&'a self, value: S) -> RValue<'a>
Creates a string literal RValue.
sourcepub fn dump_reproducer_to_file<S: AsRef<str>>(&self, path: S)
pub fn dump_reproducer_to_file<S: AsRef<str>>(&self, path: S)
Dumps a small C file to the path that can be used to reproduce a series of API calls. You should only ever need to call this if you are debugging an issue in gccjit itself or this library.
pub fn dump_to_file<S: AsRef<str>>(&self, path: S, update_locations: bool)
sourcepub fn new_parameter<'a, S: AsRef<str>>(
&'a self,
loc: Option<Location<'a>>,
ty: Type<'a>,
name: S
) -> Parameter<'a>
pub fn new_parameter<'a, S: AsRef<str>>( &'a self, loc: Option<Location<'a>>, ty: Type<'a>, name: S ) -> Parameter<'a>
Creates a new parameter with a given type, name, and location.
sourcepub fn get_builtin_function<'a, S: AsRef<str>>(
&'a self,
name: S
) -> Function<'a>
pub fn get_builtin_function<'a, S: AsRef<str>>( &'a self, name: S ) -> Function<'a>
Get a builtin function from gcc. It’s not clear what functions are builtin and you’ll likely need to consult the GCC internal docs for a full list.