[][src]Struct c2rust_transpile::translator::Translation

pub struct Translation<'c> {
    pub ast_context: TypedAstContext,
    pub tcfg: &'c TranspilerConfig,
    pub features: RefCell<IndexSet<&'static str>>,
    pub item_store: RefCell<ItemStore>,
    pub comment_context: RefCell<CommentContext>,
    pub comment_store: RefCell<CommentStore>,
    // some fields omitted
}

Fields

ast_context: TypedAstContexttcfg: &'c TranspilerConfigfeatures: RefCell<IndexSet<&'static str>>item_store: RefCell<ItemStore>comment_context: RefCell<CommentContext>comment_store: RefCell<CommentStore>

Methods

impl<'c> Translation<'c>[src]

pub fn convert_asm(
    &self,
    ctx: ExprContext,
    span: Span,
    is_volatile: bool,
    asm: &str,
    inputs: &[AsmOperand],
    outputs: &[AsmOperand],
    clobbers: &[String]
) -> Result<Vec<Stmt>, TranslationError>
[src]

Convert an inline-assembly statement into one or more Rust statements. If inline assembly translation is not enabled this will result in an error message instead of a conversion. Because the inline assembly syntax used in C is different than the one used in Rust (Rust uses the LLVM syntax directly) the resulting translated assembly statements will be unlikely to work without further manual translation. The translator will properly translate the arguments to the assembly statement, however.

impl<'a> Translation<'a>[src]

pub fn convert_bitfield_struct_decl(
    &self,
    name: String,
    manual_alignment: Option<u64>,
    platform_byte_size: u64,
    span: Span,
    field_info: Vec<(String, CQualTypeId, Option<u64>, u64, u64)>
) -> Result<ConvertedDecl, TranslationError>
[src]

Here we output a struct derive to generate bitfield data that looks like this:

#[derive(BitfieldStruct, Clone, Copy)]
#[repr(C, align(2))]
struct Foo {
    #[bitfield(name = "bf1", ty = "libc::c_char", bits = "0..=9")]
    #[bitfield(name = "bf2", ty = "libc::c_uchar",bits = "10..=15")]
    bf1_bf2: [u8; 2],
    non_bf: u64,
    _pad: [u8; 2],
}

pub fn convert_bitfield_struct_literal(
    &self,
    name: String,
    platform_byte_size: u64,
    field_ids: &[CExprId],
    field_info: Vec<(String, CQualTypeId, Option<u64>, u64, u64)>,
    ctx: ExprContext
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

Here we output a block to generate a struct literal initializer in. It looks like this in locals and (sectioned) statics:

{
    let mut init = Foo {
        bf1_bf2: [0; 2],
        non_bf: 32,
        _pad: [0; 2],
    };
    init.set_bf1(-12);
    init.set_bf2(34);
    init
}

pub fn bitfield_zero_initializer(
    &self,
    name: String,
    field_ids: &[CDeclId],
    platform_byte_size: u64,
    is_static: bool
) -> Result<P<Expr>, TranslationError>
[src]

This method handles zero-initializing bitfield structs including bitfields & padding fields

pub fn convert_bitfield_assignment_op_with_rhs(
    &self,
    ctx: ExprContext,
    op: BinOp,
    field_name: &str,
    lhs: CExprId,
    rhs_expr: P<Expr>
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

This method handles conversion of assignment operators on bitfields. Regular fields would look like this: A) bf.a = 1; B) bf.a += 1;

However, since we need to call methods for read and write, we generate this: A) bf.set_a(1); B) bf.set_a(bf.a() + 1);

Note that B) requires NLL to be valid rust

pub fn convert_bitfield_member_expr(
    &self,
    ctx: ExprContext,
    field_name: String,
    expr_id: CExprId,
    kind: MemberKind
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

This method will convert a bitfield member one of four ways: A) bf.a() B) (*bf).a() C) bf D) (*bf)

The first two are when we know this bitfield member is going to be read from (default), possibly requiring a dereference first. The latter two are generated when we are expecting to require a write, which will need to make a method call with some input which we do not yet have access to and will have to be handled elsewhere, IE bf.set_a(1)

impl<'c> Translation<'c>[src]

pub fn convert_builtin(
    &self,
    ctx: ExprContext,
    fexp: CExprId,
    args: &[CExprId]
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

Convert a call to a builtin function to a Rust expression

impl<'c> Translation<'c>[src]

pub fn mk_int_lit(&self, ty: CQualTypeId, val: u64, base: IntBase) -> P<Expr>[src]

Generate an integer literal corresponding to the given type, value, and base.

pub fn enum_for_i64(&self, enum_type_id: CTypeId, value: i64) -> P<Expr>[src]

Given an integer value this attempts to either generate the corresponding enum variant directly, otherwise it transmutes a number to the enum type.

pub fn convert_literal(
    &self,
    is_static: bool,
    ty: CQualTypeId,
    kind: &CLiteral
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

Convert a C literal expression to a Rust expression

pub fn convert_init_list(
    &self,
    ctx: ExprContext,
    ty: CQualTypeId,
    ids: &[CExprId],
    opt_union_field_id: Option<CFieldId>
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

Convert an initialization list into an expresion. These initialization lists can be used as array literals, struct literals, and union literals in code.

impl<'c> Translation<'c>[src]

pub fn convert_main(
    &self,
    main_id: CDeclId
) -> Result<P<Item>, TranslationError>
[src]

impl<'c> Translation<'c>[src]

pub fn name_reference_write(
    &self,
    ctx: ExprContext,
    reference: CExprId
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

Get back a Rust lvalue corresponding to the expression passed in.

Do not use the output lvalue expression more than once.

pub fn name_reference_write_read(
    &self,
    ctx: ExprContext,
    reference: CExprId
) -> Result<WithStmts<(P<Expr>, P<Expr>)>, TranslationError>
[src]

Get back a Rust (lvalue, rvalue) pair corresponding to the expression passed in.

You may reuse either of these expressions.

impl<'c> Translation<'c>[src]

pub fn convert_binary_expr(
    &self,
    ctx: ExprContext,
    type_id: CQualTypeId,
    op: BinOp,
    lhs: CExprId,
    rhs: CExprId,
    opt_lhs_type_id: Option<CQualTypeId>,
    opt_res_type_id: Option<CQualTypeId>
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

pub fn convert_unary_operator(
    &self,
    ctx: ExprContext,
    name: UnOp,
    cqual_type: CQualTypeId,
    arg: CExprId,
    lrvalue: LRValue
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

impl<'c> Translation<'c>[src]

pub fn import_simd_typedef(&self, name: &str) -> bool[src]

Given the name of a typedef check if its one of the SIMD types. This function returns true when the name of the type is one that it knows how to implement and no further translation should be done.

pub fn import_simd_function(&self, name: &str) -> Result<bool, TranslationError>[src]

Determine if a particular function name is an SIMD primitive. If so an appropriate use statement is generated, true is returned, and no further processing will need to be done.

pub fn convert_simd_builtin(
    &self,
    ctx: ExprContext,
    fn_name: &str,
    args: &[CExprId]
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

Generate a call to a rust SIMD function based on a builtin function. Clang 6 only supports one of these but clang 7 converts a bunch more from "super builtins"

pub fn implicit_vector_default(
    &self,
    ctype: CTypeId,
    len: usize,
    is_static: bool
) -> Result<P<Expr>, TranslationError>
[src]

Generate a zero value to be used for initialization of a given vector type. The type is specified with the underlying element type and the number of elements in the vector.

pub fn vector_list_initializer(
    &self,
    ctx: ExprContext,
    ids: &[CExprId],
    ctype: CTypeId,
    len: usize
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

Translate a list initializer corresponding to a vector type.

pub fn convert_shuffle_vector(
    &self,
    ctx: ExprContext,
    child_expr_ids: &[CExprId]
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

Convert a shuffle operation into the equivalent Rust SIMD library calls.

Because clang implements some shuffle operations as macros around intrinsic shuffle functions, this translation works to find the high-level shuffle call corresponding to the low-level one found in the C AST.

pub fn casting_simd_builtin_call(
    &self,
    expr_id: CExprId,
    is_explicit: bool,
    kind: CastKind
) -> bool
[src]

Determine whether or not the expr in question is a SIMD call value being casted, as the builtin definition will add a superfluous cast for our purposes

impl<'c> Translation<'c>[src]

pub fn is_promoted_va_decl(&self, decl_id: CDeclId) -> bool[src]

pub fn is_copied_va_decl(&self, decl_id: CDeclId) -> bool[src]

pub fn get_promoted_va_decl(&self) -> Option<CDeclId>[src]

pub fn match_vastart(&self, expr: CExprId) -> Option<CDeclId>[src]

pub fn match_vaend(&self, expr: CExprId) -> Option<CDeclId>[src]

pub fn match_vacopy(
    &self,
    dst_expr: CExprId,
    src_expr: CExprId
) -> Option<(CDeclId, CDeclId)>
[src]

pub fn match_vapart(&self, expr: CExprId) -> Option<VaPart>[src]

pub fn convert_vaarg(
    &self,
    ctx: ExprContext,
    ty: CQualTypeId,
    val_id: CExprId
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

pub fn is_well_formed_variadic(&self, body: CStmtId) -> bool[src]

Determine if a variadic function body declares a va_list argument and contains a va_start and va_end call for that argument list. If it does, the declaration ID for that variable is registered so that the resulting Rust function can have that variable argument list variable moved up to the argument list.

impl<'c> Translation<'c>[src]

pub fn new(
    ast_context: TypedAstContext,
    tcfg: &'c TranspilerConfig,
    main_file: PathBuf
) -> Self
[src]

pub fn use_feature(&self, feature: &'static str)[src]

Called when translation makes use of a language feature that will require a feature-gate.

pub fn get_pragmas(&self) -> Vec<(&'static str, Vec<&'static str>)>[src]

pub fn panic_or_err(&self, msg: &str) -> P<Expr>[src]

pub fn panic(&self, msg: &str) -> P<Expr>[src]

pub fn is_inner_type_valist(ctxt: &TypedAstContext, qtype: CQualTypeId) -> bool[src]

Returns true iff type is a (pointer to)* the va_list structure type. Note: the logic is based on TypeConverter::convert_pointer.

pub fn convert_cfg(
    &self,
    name: &str,
    graph: Cfg<Label, StmtOrDecl>,
    store: DeclStmtStore,
    live_in: IndexSet<CDeclId>,
    cut_out_trailing_ret: bool
) -> Result<Vec<Stmt>, TranslationError>
[src]

pub fn convert_condition(
    &self,
    ctx: ExprContext,
    target: bool,
    cond_id: CExprId
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

Convert a C expression to a rust boolean expression

pub fn convert_decl_stmt(
    &self,
    ctx: ExprContext,
    decl_id: CDeclId
) -> Result<Vec<Stmt>, TranslationError>
[src]

pub fn convert_decl_stmt_info(
    &self,
    ctx: ExprContext,
    decl_id: CDeclId
) -> Result<DeclStmtInfo, TranslationError>
[src]

pub fn volatile_write(
    &self,
    lhs: &P<Expr>,
    lhs_type: CQualTypeId,
    rhs: P<Expr>
) -> Result<P<Expr>, TranslationError>
[src]

Write to a lhs that is volatile

pub fn volatile_read(
    &self,
    lhs: &P<Expr>,
    lhs_type: CQualTypeId
) -> Result<P<Expr>, TranslationError>
[src]

Read from a lhs that is volatile

pub fn compute_size_of_expr(&self, type_id: CTypeId) -> Option<P<Expr>>[src]

pub fn compute_variable_array_sizes(
    &self,
    ctx: ExprContext,
    type_id: CTypeId
) -> Result<Vec<Stmt>, TranslationError>
[src]

This generates variables that store the computed sizes of the variable-length arrays in the given type.

pub fn compute_size_of_type(
    &self,
    ctx: ExprContext,
    type_id: CTypeId
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

pub fn compute_align_of_type(
    &self,
    type_id: CTypeId,
    preferred: bool
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

pub fn convert_expr(
    &self,
    ctx: ExprContext,
    expr_id: CExprId
) -> Result<WithStmts<P<Expr>>, TranslationError>
[src]

Translate a C expression into a Rust one, possibly collecting side-effecting statements to run before the expression.

The use_ argument informs us how the C expression we are translating is used in the C program. See ExprUse for more information.

In the case that use_ is unused, all side-effecting components will be in the stmts field of the output and it is expected that the val field of the output will be ignored.

pub fn implicit_default_expr(
    &self,
    ty_id: CTypeId,
    is_static: bool
) -> Result<P<Expr>, TranslationError>
[src]

pub fn with_scope<F, A>(&self, f: F) -> A where
    F: FnOnce() -> A, 
[src]

Auto Trait Implementations

impl<'c> !Send for Translation<'c>

impl<'c> !Sync for Translation<'c>

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<E> SpecializationError for E[src]

impl<T> Erased for T[src]

impl<T> Send for T where
    T: ?Sized
[src]

impl<T> Sync for T where
    T: ?Sized
[src]

impl<T> Make for T[src]

impl<T> MaybeResult for T[src]

impl<'a, T> Captures for T where
    T: ?Sized
[src]

impl<T> Erased for T