Struct gccjit::Context

source ·
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>

source

pub fn set_program_name<S: AsRef<str>>(&self, name: S)

Sets the program name reported by the JIT.

source

pub fn add_command_line_option<S: AsRef<str>>(&self, name: S)

source

pub fn add_driver_option<S: AsRef<str>>(&self, name: S)

source

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.

source

pub fn set_debug_info(&self, value: bool)

source

pub fn set_keep_intermediates(&self, value: bool)

source

pub fn set_print_errors_to_stderr(&self, enabled: bool)

source

pub fn set_dump_everything(&self, value: bool)

source

pub fn set_dump_initial_gimple(&self, value: bool)

source

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.

source

pub fn set_allow_unreachable_blocks(&self, value: bool)

source

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.

source

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.

source

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.

source

pub fn new_case<S: ToRValue<'ctx>, T: ToRValue<'ctx>>( &self, min_value: S, max_value: T, dest_block: Block<'ctx> ) -> Case<'ctx>

source

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.

source

pub fn new_global<'a, S: AsRef<str>>( &self, loc: Option<Location<'a>>, kind: GlobalKind, ty: Type<'a>, name: S ) -> LValue<'a>

source

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.

source

pub fn new_c_type<'a>(&'a self, c_type: CType) -> Type<'a>

source

pub fn new_int_type<'a>(&'a self, num_bytes: i32, signed: bool) -> Type<'a>

source

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.

source

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.

source

pub fn new_vector_type<'a>(&'a self, ty: Type<'a>, num_units: u64) -> Type<'a>

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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>

source

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.

source

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.

source

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.

source

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.

source

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).

source

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.

source

pub fn new_rvalue_from_vector<'a>( &'a self, loc: Option<Location<'a>>, vec_type: Type<'a>, elements: &[RValue<'a>] ) -> RValue<'a>

source

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>

source

pub fn new_array_constructor<'a>( &'a self, loc: Option<Location<'a>>, array_type: Type<'a>, elements: &[RValue<'a>] ) -> RValue<'a>

source

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.

source

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.

source

pub fn new_rvalue_zero<'a>(&'a self, ty: Type<'a>) -> RValue<'a>

Creates a zero element for a given type.

source

pub fn new_rvalue_one<'a>(&'a self, ty: Type<'a>) -> RValue<'a>

Creates a one element for a given type.

source

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.

source

pub fn new_null<'a>(&'a self, ty: Type<'a>) -> RValue<'a>

Creates a null RValue.

source

pub fn new_string_literal<'a, S: AsRef<str>>(&'a self, value: S) -> RValue<'a>

Creates a string literal RValue.

source

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.

source

pub fn dump_to_file<S: AsRef<str>>(&self, path: S, update_locations: bool)

source

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.

source

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.

source

pub fn get_first_error(&self) -> Result<Option<&'ctx str>, Utf8Error>

source

pub fn get_last_error(&self) -> Result<Option<&'ctx str>, Utf8Error>

source

pub fn set_logfile<S: AsRef<str>>(&self, _logfile: S)

source

pub fn add_top_level_asm(&self, loc: Option<Location<'ctx>>, asm_stmts: &str)

Trait Implementations§

source§

impl<'ctx> Debug for Context<'ctx>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Context<'static>

source§

fn default() -> Context<'static>

Returns the “default value” for a type. Read more
source§

impl<'ctx> Drop for Context<'ctx>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'ctx> RefUnwindSafe for Context<'ctx>

§

impl<'ctx> !Send for Context<'ctx>

§

impl<'ctx> !Sync for Context<'ctx>

§

impl<'ctx> Unpin for Context<'ctx>

§

impl<'ctx> UnwindSafe for Context<'ctx>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.