package frama-c
- Customization
- Values for manipulating globals
- Values for manipulating initializers
- Values for manipulating types
- Values for manipulating expressions
- Values for manipulating attributes
- Const Attribute
- Volatile Attribute
- Ghost Attribute
- The visitor
- Visitor mechanism
- Utility functions
- Debugging support
- Renaming
- Optimization Passes
- Machine dependency
- An Interpreter for constructing CIL constructs
- Misc
Install
dune-project
Dependency
Authors
-
MMichele Alberti
-
TThibaud Antignac
-
GGergö Barany
-
PPatrick Baudin
-
TThibaut Benjamin
-
AAllan Blanchard
-
LLionel Blatter
-
FFrançois Bobot
-
RRichard Bonichon
-
QQuentin Bouillaguet
-
DDavid Bühler
-
ZZakaria Chihani
-
LLoïc Correnson
-
JJulien Crétin
-
PPascal Cuoq
-
ZZaynah Dargaye
-
BBasile Desloges
-
JJean-Christophe Filliâtre
-
PPhilippe Herrmann
-
MMaxime Jacquemin
-
FFlorent Kirchner
-
AAlexander Kogtenkov
-
TTristan Le Gall
-
JJean-Christophe Léchenet
-
MMatthieu Lemerre
-
DDara Ly
-
DDavid Maison
-
CClaude Marché
-
AAndré Maroneze
-
TThibault Martin
-
FFonenantsoa Maurica
-
MMelody Méaulle
-
BBenjamin Monate
-
YYannick Moy
-
PPierre Nigron
-
AAnne Pacalet
-
VValentin Perrelle
-
GGuillaume Petiot
-
DDario Pinto
-
VVirgile Prevosto
-
AArmand Puccetti
-
FFélix Ridoux
-
VVirgile Robles
-
JJan Rochel
-
MMuriel Roger
-
JJulien Signoles
-
NNicolas Stouls
-
KKostyantyn Vorobyov
-
BBoris Yakobowski
Maintainers
Sources
sha256=29612882330ecb6eddd0b4ca3afc0492b70d0feb3379a1b8e893194c6e173983
doc/frama-c.kernel/Frama_c_kernel/Cil/index.html
Module Frama_c_kernel.Cil
CIL main API.
CIL original API documentation is available as an html version at http://manju.cs.berkeley.edu/cil.
val initCIL : initLogicBuiltins:(unit -> unit) -> Cil_types.mach -> unitCall this function to perform some initialization, and only after you have set Cil.msvcMode. initLogicBuiltins is the function to call to init logic builtins. The Machdeps argument is a description of the hardware platform and of the compiler used.
Customization
type theMachine = private {mutable useLogicalOperators : bool;(*Whether to use the logical operands LAnd and LOr. By default, do not use them because they are unlike other expressions and do not evaluate both of their operands
*)mutable theMachine : Cil_types.mach;mutable lowerConstants : bool;(*Do lower constants (default true)
*)mutable insertImplicitCasts : bool;(*Do insert implicit casts (default true)
*)mutable stringLiteralType : Cil_types.typ;mutable upointKind : Cil_types.ikind;(*An unsigned integer type that fits pointers.
*)mutable upointType : Cil_types.typ;mutable wcharKind : Cil_types.ikind;(*An integer type that fits wchar_t.
*)mutable wcharType : Cil_types.typ;mutable ptrdiffKind : Cil_types.ikind;(*An integer type that fits ptrdiff_t.
*)mutable ptrdiffType : Cil_types.typ;mutable typeOfSizeOf : Cil_types.typ;(*An integer type that is the type of sizeof.
*)mutable kindOfSizeOf : Cil_types.ikind;
}val theMachine : theMachineCurrent machine description
val selfMachine : State.tval selfMachine_is_computed : ?project:Project.project -> unit -> boolwhether current project has set its machine description.
After a call to this function, empty compinfos are allowed by the kernel, this must be used as a configuration step equivalent to a machdep, except that it is not a user configuration.
Note that if the selected machdep is GCC or MSVC, this call has no effect as these modes already allow empty compinfos.
whether we accept empty struct. Implied by Cil.msvcMode and Cil.gccMode, and can be forced by Cil.set_acceptEmptyCompinfo otherwise.
allowed_machdep "machdep family" provides a standard message for features only allowed for a particular machdep.
Values for manipulating globals
val emptyFunctionFromVI : Cil_types.varinfo -> Cil_types.fundecMake an empty function from an existing global varinfo.
val emptyFunction : string -> Cil_types.fundecMake an empty function
val setFormals : Cil_types.fundec -> Cil_types.varinfo list -> unitUpdate the formals of a fundec and make sure that the function type has the same information. Will copy the name as well into the type.
val getReturnType : Cil_types.typ -> Cil_types.typTakes as input a function type (or a typename on it) and return its return type.
val setReturnTypeVI : Cil_types.varinfo -> Cil_types.typ -> unitChange the return type of the function passed as 1st argument to be the type passed as 2nd argument.
val setReturnType : Cil_types.fundec -> Cil_types.typ -> unitval setFunctionType : Cil_types.fundec -> Cil_types.typ -> unitSet the types of arguments and results as given by the function type * passed as the second argument. Will not copy the names from the function * type to the formals
val setFunctionTypeMakeFormals : Cil_types.fundec -> Cil_types.typ -> unitSet the type of the function and make formal arguments for them
val setMaxId : Cil_types.fundec -> unitUpdate the smaxid after you have populated with locals and formals * (unless you constructed those using Cil.makeLocalVar or * Cil.makeTempVar.
val selfFormalsDecl : State.tstate of the table associating formals to each prototype.
val makeFormalsVarDecl :
?ghost:bool ->
(string * Cil_types.typ * Cil_types.attributes) ->
Cil_types.varinfocreates a new varinfo for the parameter of a prototype. By default, this formal variable is not ghost.
val setFormalsDecl : Cil_types.varinfo -> Cil_types.typ -> unitUpdate the formals of a function declaration from its identifier and its type. For a function definition, use Cil.setFormals. Do nothing if the type is not a function type or if the list of argument is empty.
val removeFormalsDecl : Cil_types.varinfo -> unitremove a binding from the table.
val unsafeSetFormalsDecl : Cil_types.varinfo -> Cil_types.varinfo list -> unitreplace formals of a function declaration with the given list of varinfo.
val iterFormalsDecl :
(Cil_types.varinfo -> Cil_types.varinfo list -> unit) ->
unititerate the given function on declared prototypes.
val getFormalsDecl : Cil_types.varinfo -> Cil_types.varinfo listGet the formals of a function declaration registered with Cil.setFormalsDecl.
val dummyFile : Cil_types.fileA dummy file
val iterGlobals : Cil_types.file -> (Cil_types.global -> unit) -> unitIterate over all globals, including the global initializer
val foldGlobals : Cil_types.file -> ('a -> Cil_types.global -> 'a) -> 'a -> 'aFold over all globals, including the global initializer
val mapGlobals :
Cil_types.file ->
(Cil_types.global -> Cil_types.global) ->
unitMap over all globals, including the global initializer and change things in place
val findOrCreateFunc :
Cil_types.file ->
string ->
Cil_types.typ ->
Cil_types.varinfoFind a function or function prototype with the given name in the file. * If it does not exist, create a prototype with the given type, and return * the new varinfo. This is useful when you need to call a libc function * whose prototype may or may not already exist in the file. * * Because the new prototype is added to the start of the file, you shouldn't * refer to any struct or union types in the function type.
val new_exp : loc:Cil_types.location -> Cil_types.exp_node -> Cil_types.expcreates an expression with a fresh id
val copy_exp : Cil_types.exp -> Cil_types.expperforms a deep copy of an expression (especially, avoid eid sharing).
val dummy_exp : Cil_types.exp_node -> Cil_types.expcreates an expression with a dummy id. Use with caution, i.e. not on expressions that may be put in the AST.
val is_case_label : Cil_types.label -> boolReturn true on case and default labels, false otherwise.
val pushGlobal :
Cil_types.global ->
types:Cil_types.global list ref ->
variables:Cil_types.global list ref ->
unitCIL keeps the types at the beginning of the file and the variables at the * end of the file. This function will take a global and add it to the * corresponding stack. Its operation is actually more complicated because if * the global declares a type that contains references to variables (e.g. in * sizeof in an array length) then it will also add declarations for the * variables to the types stack
val invalidStmt : Cil_types.stmtAn empty statement. Used in pretty printing
val range_loc : Cil_types.location -> Cil_types.location -> Cil_types.locationReturns a location that ranges over the two locations in arguments.
Values for manipulating initializers
val makeZeroInit : loc:Cil_types.location -> Cil_types.typ -> Cil_types.initMake a initializer for zero-ing a data type
val foldLeftCompound :
implicit:bool ->
doinit:(Cil_types.offset -> Cil_types.init -> Cil_types.typ -> 'a -> 'a) ->
ct:Cil_types.typ ->
initl:(Cil_types.offset * Cil_types.init) list ->
acc:'a ->
'aFold over the list of initializers in a Compound (not also the nested * ones). doinit is called on every present initializer, even if it is of * compound type. The parameters of doinit are: the offset in the compound * (this is Field(f,NoOffset) or Index(i,NoOffset)), the initializer * value, expected type of the initializer value, accumulator. In the case of * arrays there might be missing zero-initializers at the end of the list. * These are scanned only if implicit is true. This is much like * List.fold_left except we also pass the type of the initializer.
* This is a good way to use it to scan even nested initializers :
let rec myInit (lv: lval) (i: init) (acc: 'a) : 'a =
match i with
| SingleInit e -> (* ... do something with [lv] and [e] and [acc] ... *)
| CompoundInit (ct, initl) ->
foldLeftCompound ~implicit:false
~doinit:(fun off' i' _typ acc' ->
myInit (addOffsetLval off' lv) i' acc')
~ct
~initl
~accValues for manipulating types
val voidType : Cil_types.typvoid
val isVoidType : Cil_types.typ -> boolis the given type "void"?
val isVoidPtrType : Cil_types.typ -> boolis the given type "void *"?
val intType : Cil_types.typint
val uintType : Cil_types.typunsigned int
val shortType : Cil_types.typshort
val ushortType : Cil_types.typunsigned short
val longType : Cil_types.typlong
val longLongType : Cil_types.typlong long
val ulongType : Cil_types.typunsigned long
val ulongLongType : Cil_types.typunsigned long long
val int16_t : unit -> Cil_types.typAny signed integer type of size 16 bits. It is equivalent to the ISO C int16_t type but without using the corresponding header. Must only be called if such type exists in the current architecture.
val int32_t : unit -> Cil_types.typAny signed integer type of size 32 bits. It is equivalent to the ISO C int32_t type but without using the corresponding header. Must only be called if such type exists in the current architecture.
val int64_t : unit -> Cil_types.typAny signed integer type of size 64 bits. It is equivalent to the ISO C int64_t type but without using the corresponding header. Must only be called if such type exists in the current architecture.
val uint16_t : unit -> Cil_types.typAny unsigned integer type of size 16 bits. It is equivalent to the ISO C uint16_t type but without using the corresponding header. Must only be called if such type exists in the current architecture.
val uint32_t : unit -> Cil_types.typAny unsigned integer type of size 32 bits. It is equivalent to the ISO C uint32_t type but without using the corresponding header. Must only be called if such type exists in the current architecture.
val uint64_t : unit -> Cil_types.typAny unsigned integer type of size 64 bits. It is equivalent to the ISO C uint64_t type but without using the corresponding header. Must only be called if such type exists in the current architecture.
val charType : Cil_types.typchar
val scharType : Cil_types.typval ucharType : Cil_types.typval charPtrType : Cil_types.typchar *
val scharPtrType : Cil_types.typval ucharPtrType : Cil_types.typval charConstPtrType : Cil_types.typchar const *
val voidPtrType : Cil_types.typvoid *
val voidConstPtrType : Cil_types.typvoid const *
val intPtrType : Cil_types.typint *
val uintPtrType : Cil_types.typunsigned int *
val floatType : Cil_types.typfloat
val doubleType : Cil_types.typdouble
val longDoubleType : Cil_types.typlong double
val isSignedInteger : Cil_types.typ -> boolval isUnsignedInteger : Cil_types.typ -> boolThis is a constant used as the name of an unnamed bitfield. These fields do not participate in initialization and their name is not printed.
val compFullName : Cil_types.compinfo -> stringGet the full name of a comp, including the 'struct' or 'union' prefix
val isCompleteType : ?allowZeroSizeArrays:bool -> Cil_types.typ -> boolReturns true if this is a complete type. This means that sizeof(t) makes sense. Incomplete types are not yet defined structures and empty arrays.
val lvalue_conversion : Cil_types.typ -> (Cil_types.typ, string) resultPerforms lvalue-conversion on the type and returns the converted type, or Error if the type is incomplete and not an array type.
val is_variably_modified_type : Cil_types.typ -> booltrue iff the given type is variably modified, i.e., an array with variable size (VLA), or a composite type containing such an array.
val has_flexible_array_member : Cil_types.typ -> booltrue iff the given type is a struct whose last field is a flexible array member. When in gcc mode, a zero-sized array is identified with a FAM for this purpose.
true iff the given type has flexible array member, in GCC/MSVC mode, this function mode recursively searches in the type of the last field.
val unrollType : Cil_types.typ -> Cil_types.typUnroll a type until it exposes a non * TNamed. Will collect all attributes appearing in TNamed!!!
val unrollTypeDeep : Cil_types.typ -> Cil_types.typUnroll all the TNamed in a type (even under type constructors such as * TPtr, TFun or TArray. Does not unroll the types of fields in TComp * types. Will collect all attributes
val separateStorageModifiers :
Cil_types.attribute list ->
Cil_types.attribute list * Cil_types.attribute listSeparate out the storage-modifier name attributes
val arithmeticConversion : Cil_types.typ -> Cil_types.typ -> Cil_types.typreturns the type of the result of an arithmetic operator applied to values of the corresponding input types.
val integralPromotion : Cil_types.typ -> Cil_types.typperforms the usual integral promotions mentioned in C reference manual.
val isAnyCharType : Cil_types.typ -> boolTrue if the argument is a character type (i.e. plain, signed or unsigned)
val isCharType : Cil_types.typ -> boolTrue if the argument is a plain character type (but neither signed char nor unsigned char).
val isShortType : Cil_types.typ -> boolTrue if the argument is a short type (i.e. signed or unsigned)
val isAnyCharPtrType : Cil_types.typ -> boolTrue if the argument is a pointer to a character type (i.e. plain, signed or unsigned).
val isCharPtrType : Cil_types.typ -> boolTrue if the argument is a pointer to a plain character type (but neither signed char nor unsigned char).
val isCharConstPtrType : Cil_types.typ -> boolTrue if the argument is a pointer to a constant character type, e.g. a string literal.
val isAnyCharArrayType : Cil_types.typ -> boolTrue if the argument is an array of a character type (i.e. plain, signed or unsigned)
val isCharArrayType : Cil_types.typ -> boolTrue if the argument is an array of a character type (i.e. plain, signed or unsigned)
val isIntegralType : Cil_types.typ -> boolTrue if the argument is an integral type (i.e. integer or enum)
val isBoolType : Cil_types.typ -> boolTrue if the argument is _Bool
val isLogicPureBooleanType : Cil_types.logic_type -> boolTrue if the argument is _Bool or boolean.
val isIntegralOrPointerType : Cil_types.typ -> boolTrue if the argument is an integral or pointer type.
val isLogicIntegralType : Cil_types.logic_type -> boolTrue if the argument is an integral type (i.e. integer or enum), either C or mathematical one.
val isLogicBooleanType : Cil_types.logic_type -> boolTrue if the argument is a boolean type, either integral C type or mathematical boolean one.
val isFloatingType : Cil_types.typ -> boolTrue if the argument is a floating point type.
val isLogicFloatType : Cil_types.logic_type -> boolTrue if the argument is a floating point type.
val isLogicRealOrFloatType : Cil_types.logic_type -> boolTrue if the argument is a C floating point type or logic 'real' type.
val isLogicRealType : Cil_types.logic_type -> boolTrue if the argument is the logic 'real' type.
val isArithmeticType : Cil_types.typ -> boolTrue if the argument is an arithmetic type (i.e. integer, enum or floating point
val isScalarType : Cil_types.typ -> boolTrue if the argument is a scalar type (i.e. integral, enum, floating point or pointer
val isArithmeticOrPointerType : Cil_types.typ -> boolalias of isScalarType.
val isLogicArithmeticType : Cil_types.logic_type -> boolTrue if the argument is a logic arithmetic type (i.e. integer, enum or floating point, either C or mathematical one.
val isFunctionType : Cil_types.typ -> boolTrue if the argument is a function type
val isLogicFunctionType : Cil_types.logic_type -> boolTrue if the argument is the logic function type. Expands the logic type definition if necessary.
val isPointerType : Cil_types.typ -> boolTrue if the argument is a pointer type.
val isFunPtrType : Cil_types.typ -> boolTrue if the argument is a function pointer type.
val isLogicFunPtrType : Cil_types.logic_type -> boolTrue if the argument is the logic function pointer type. Expands the logic type definition if necessary.
val isTransparentUnion : Cil_types.typ -> Cil_types.fieldinfo optionCheck if a type is a transparent union, and return the first field
val isTypeTagType : Cil_types.logic_type -> boolTrue if the argument is the type for reified C types.
val isVariadicListType : Cil_types.typ -> boolTrue if the argument denotes the type of ... in a variadic function.
val argsToList :
(string * Cil_types.typ * Cil_types.attributes) list option ->
(string * Cil_types.typ * Cil_types.attributes) listObtain the argument list ( if None).
val argsToPairOfLists :
(string * Cil_types.typ * Cil_types.attributes) list option ->
(string * Cil_types.typ * Cil_types.attributes) list
* (string * Cil_types.typ * Cil_types.attributes) listObtain the argument lists (non-ghost, ghosts) (, if None)
val isArrayType : Cil_types.typ -> boolTrue if the argument is an array type
val isUnsizedArrayType : Cil_types.typ -> boolTrue if the argument is an array type without size
val isSizedArrayType : Cil_types.typ -> boolTrue if the argument is a sized array type
val isStructType : Cil_types.typ -> boolTrue if the argument is a struct
val isUnionType : Cil_types.typ -> boolTrue if the argument is a union type
val isStructOrUnionType : Cil_types.typ -> boolTrue if the argument is a struct or union type
possible causes for raising Cil.LenOfArray
val pp_incorrect_array_length :
Format.formatter ->
incorrect_array_length ->
unitexception LenOfArray of incorrect_array_lengthRaised when Cil.lenOfArray fails either because the length is None, * because it is a non-constant expression, or because it overflows an int.
val lenOfArray : Cil_types.exp option -> intCall to compute the array length as present in the array type, to an * integer. Raises Cil.LenOfArray if not able to compute the length, such * as when there is no length or the length is not a constant.
val lenOfArray64 : Cil_types.exp option -> Integer.tval getCompField : Cil_types.compinfo -> string -> Cil_types.fieldinfoReturn a named fieldinfo in compinfo, or raise Not_found
val existsType : (Cil_types.typ -> existsAction) -> Cil_types.typ -> boolScans a type by applying the function on all elements. When the function returns ExistsTrue, the scan stops with true. When the function returns ExistsFalse then the current branch is not scanned anymore. Care is taken to apply the function only once on each composite type, thus avoiding circularity. When the function returns ExistsMaybe then the types that construct the current type are scanned (e.g. the base type for TPtr and TArray, the type of fields for a TComp, etc).
val splitFunctionType :
Cil_types.typ ->
Cil_types.typ
* (string * Cil_types.typ * Cil_types.attributes) list option
* bool
* Cil_types.attributesGiven a function type split it into return type, * arguments, is_vararg and attributes. An error is raised if the type is not * a function type
val splitFunctionTypeVI :
Cil_types.varinfo ->
Cil_types.typ
* (string * Cil_types.typ * Cil_types.attributes) list option
* bool
* Cil_types.attributesSame as Cil.splitFunctionType but takes a varinfo. Prints a nicer * error message if the varinfo is not for a function
type combineWhat = | CombineFundef of bool(*The new definition is for a function definition. The old is for a prototype. arg is
*)truefor an old-style declaration.| CombineFunarg of bool(*Comparing a function argument type with an old prototype argument. arg is
*)truefor an old-style declaration, which triggers some ad hoc treatment in GCC mode.| CombineFunret(*Comparing the return of a function with that from an old prototype
*)| CombineOther
Used in combineTypes and combineTypesGen to indicate what we want to combine.
val combineAttributes :
combineWhat ->
Cil_types.attribute list ->
Cil_types.attributes ->
Cil_types.attributescombineAttributes what olda a combines the attributes in olda and a according to what:
- if
what == CombineFunarg, then override old attributes; this is used to ensure that attributes from formal argument types in a function definition are not mixed with attributes from arguments in other (compatible, but with different qualifiers) declarations; - else, perform the union of old and new attributes.
type combineFunction = {typ_combine : combineFunction -> bool -> combineWhat -> Cil_types.typ -> Cil_types.typ -> Cil_types.typ;(*
*)boolis about strictness in return context. SeeStrictReturnTypesincombineTypeGenenum_combine : combineFunction -> Cil_types.enuminfo -> Cil_types.enuminfo -> Cil_types.enuminfo;comp_combine : combineFunction -> Cil_types.compinfo -> Cil_types.compinfo -> Cil_types.compinfo;name_combine : combineFunction -> combineWhat -> Cil_types.typeinfo -> Cil_types.typeinfo -> Cil_types.typeinfo;
}combineFunction contains information on how enum, struct/union and typedef are to be handled when combining with combineTypes and combineTypesGen. In pratice, the first argument of each field is a recursive definition.
val combineTypesGen :
?emitwith:(Log.event -> unit) ->
combineFunction ->
?strictInteger:bool ->
?strictReturnTypes:bool ->
combineWhat ->
Cil_types.typ ->
Cil_types.typ ->
Cil_types.typcombineTypesGen combF combW oldt newt Combine oldt and newt accordingly to combF, combW indicates what we are combinining.
Warning : this is not commutative. Indeed, excluding enum, struct/union and typedef which depend on combF, the resulting type is as close as possible to newt.
strictInteger is true (default) if two integers with same size and sign but with different types cannot be combined. A warning is sent if it is false and the compatibility is machine-dependent.
strictReturnTypes is false (default) if a non-void type is compatible with void in a return case.
Notice that the ~emitwith action is called iff a warning is logged.
val combineTypes :
?strictReturnTypes:bool ->
combineWhat ->
Cil_types.typ ->
Cil_types.typ ->
Cil_types.typSpecialized verison of combineTypesGen, we suppore here that if two global symbols are equal, then they are the same object.
type qualifier_check_context = | Identical(*Identical qualifiers.
*)| IdenticalToplevel(*Ignore at toplevel, use Identical when going under a pointer.
*)| Covariant(*First type can have const-qualifications the second doesn't have.
*)| CovariantToplevel(*Accepts everything for current type, use Covariant when going under a pointer.
*)| Contravariant(*Second type can have const-qualifications the first doesn't have.
*)| ContravariantToplevel(*Accepts everything for current type, use Contravariant when going under a pointer.
*)
How type qualifiers must be checked when checking for types compatibility with areCompatibleTypes and compatibleTypes.
val areCompatibleTypes :
?strictReturnTypes:bool ->
?context:qualifier_check_context ->
Cil_types.typ ->
Cil_types.typ ->
boolareCompatibleTypes returns true if two types are compatible. context indicates how check the compatibility of qualifiers. Other arguments are the same than combineTypes.
val compatibleTypes :
?strictReturnTypes:bool ->
?context:qualifier_check_context ->
Cil_types.typ ->
Cil_types.typ ->
Cil_types.typSame as areCompatibleTypes old newt but combine oldt and newt. context does not impact the qualifiers of the result.
LVALUES
val makeVarinfo :
?source:bool ->
?temp:bool ->
?referenced:bool ->
?ghost:bool ->
?loc:Cil_datatype.Location.t ->
bool ->
bool ->
string ->
Cil_types.typ ->
Cil_types.varinfoMake a varinfo. Use this (rarely) to make a raw varinfo. Use other functions to make locals (Cil.makeLocalVar or Cil.makeFormalVar or Cil.makeTempVar) and globals (Cil.makeGlobalVar). Note that this function will assign a new identifier. The temp argument defaults to false, and corresponds to the vtemp field in type Cil_types.varinfo. The source argument defaults to true, and corresponds to the field vsource . The referenced argument defaults to false, and corresponds to the field vreferenced . The ghost argument defaults to false, and corresponds to the field vghost . The loc argument defaults to Location.unknown, and corresponds to the field vdecl . The first unnamed argument specifies whether the varinfo is for a global and the second is for formals.
val makeFormalVar :
Cil_types.fundec ->
?ghost:bool ->
?where:string ->
?loc:Cil_datatype.Location.t ->
string ->
Cil_types.typ ->
Cil_types.varinfoMake a formal variable for a function declaration. Insert it in both the sformals and the type of the function. You can optionally specify where to insert this one. If where = "^" then it is inserted first. If where = "$" then it is inserted last. Otherwise where must be the name of a formal after which to insert this. By default it is inserted at the end.
The ghost parameter indicates if the variable should be inserted in the list of formals or ghost formals. By default, it takes the ghost status of the function where the formal is inserted. Note that:
- specifying ghost to false if the function is ghost leads to an error
- when
whereis specified, its status must be the same as the formal to insert (else, it cannot be found in the list of ghost or non ghost formals)
val makeLocalVar :
Cil_types.fundec ->
?scope:Cil_types.block ->
?temp:bool ->
?referenced:bool ->
?insert:bool ->
?ghost:bool ->
?loc:Cil_datatype.Location.t ->
string ->
Cil_types.typ ->
Cil_types.varinfoMake a local variable and add it to a function's slocals and to the given block (only if insert = true, which is the default). Make sure you know what you are doing if you set insert=false. temp is passed to Cil.makeVarinfo. The variable is attached to the toplevel block if scope is not specified. If the name passed as argument already exists within the function, a fresh name will be generated for the varinfo.
val refresh_local_name : Cil_types.fundec -> Cil_types.varinfo -> unitif needed, rename the given varinfo so that its vname does not clash with the one of a local or formal variable of the given function.
val makeTempVar :
Cil_types.fundec ->
?insert:bool ->
?ghost:bool ->
?name:string ->
?descr:string ->
?descrpure:bool ->
?loc:Cil_datatype.Location.t ->
Cil_types.typ ->
Cil_types.varinfoMake a temporary variable and add it to a function's slocals. The name of the temporary variable will be generated based on the given name hint so that to avoid conflicts with other locals. Optionally, you can give the variable a description of its contents and its location. Temporary variables are always considered as generated variables. If insert is true (the default), the variable will be inserted among other locals of the function. The value for insert should only be changed if you are completely sure this is not useful.
val makeGlobalVar :
?source:bool ->
?temp:bool ->
?referenced:bool ->
?ghost:bool ->
?loc:Cil_datatype.Location.t ->
string ->
Cil_types.typ ->
Cil_types.varinfoMake a global variable. Your responsibility to make sure that the name is unique. source defaults to true. temp defaults to false.
val copyVarinfo : Cil_types.varinfo -> string -> Cil_types.varinfoMake a shallow copy of a varinfo and assign a new identifier. If the original varinfo has an associated logic var, it is copied too and associated to the copied varinfo
val update_var_type : Cil_types.varinfo -> Cil_types.typ -> unitChanges the type of a varinfo and of its associated logic var if any.
val isBitfield : Cil_types.lval -> boolIs an lvalue a bitfield?
val lastOffset : Cil_types.offset -> Cil_types.offsetReturns the last offset in the chain.
val addOffsetLval : Cil_types.offset -> Cil_types.lval -> Cil_types.lvalAdd an offset at the end of an lvalue. Make sure the type of the lvalue * and the offset are compatible.
val addOffset : Cil_types.offset -> Cil_types.offset -> Cil_types.offsetaddOffset o1 o2 adds o1 to the end of o2.
val removeOffsetLval : Cil_types.lval -> Cil_types.lval * Cil_types.offsetRemove ONE offset from the end of an lvalue. Returns the lvalue with the * trimmed offset and the final offset. If the final offset is NoOffset * then the original lval did not have an offset.
val removeOffset : Cil_types.offset -> Cil_types.offset * Cil_types.offsetRemove ONE offset from the end of an offset sequence. Returns the * trimmed offset and the final offset. If the final offset is NoOffset * then the original lval did not have an offset.
val typeOfLval : Cil_types.lval -> Cil_types.typCompute the type of an lvalue
val typeOfLhost : Cil_types.lhost -> Cil_types.typCompute the type of an lhost (with no offset)
val typeOfTermLval : Cil_types.term_lval -> Cil_types.logic_typeEquivalent to typeOfLval for terms.
val typeOffset : Cil_types.typ -> Cil_types.offset -> Cil_types.typCompute the type of an offset from a base type
val typeTermOffset :
Cil_types.logic_type ->
Cil_types.term_offset ->
Cil_types.logic_typeEquivalent to typeOffset for terms.
val typeOfInit : Cil_types.init -> Cil_types.typCompute the type of an initializer
val is_modifiable_lval : Cil_types.lval -> boolindicates whether the given lval is a modifiable lvalue in the sense of the C standard 6.3.2.1§1.
Values for manipulating expressions
val zero : loc:Cil_datatype.Location.t -> Cil_types.exp0
val one : loc:Cil_datatype.Location.t -> Cil_types.exp1
val mone : loc:Cil_datatype.Location.t -> Cil_types.exp-1
val kinteger64 :
loc:Cil_types.location ->
?repr:string ->
?kind:Cil_types.ikind ->
Integer.t ->
Cil_types.expConstruct an integer of a given kind without literal representation. Truncate the integer if kind is given, and the integer does not fit inside the type. The integer can have an optional literal representation repr.
val kinteger :
loc:Cil_types.location ->
Cil_types.ikind ->
int ->
Cil_types.expConstruct an integer of a given kind. Converts the integer to int64 and * then uses kinteger64. This might truncate the value if you use a kind * that cannot represent the given integer. This can only happen for one of * the Char or Short kinds
val integer : loc:Cil_types.location -> int -> Cil_types.expConstruct an integer of kind IInt. You can use this always since the OCaml integers are 31 bits and are guaranteed to fit in an IInt
val kfloat :
loc:Cil_types.location ->
Cil_types.fkind ->
float ->
Cil_types.expConstructs a floating point constant.
val isInteger : Cil_types.exp -> Integer.t optionTrue if the given expression is a (possibly cast'ed) character or an integer constant
val isConstant :
?is_varinfo_cst:(Cil_types.varinfo -> bool) ->
Cil_types.exp ->
boolTrue if the expression is a compile-time constant. is_varinfo_cst indicates whether a variable should be considered as having a constant content. Defaults to false.
val isIntegerConstant :
?is_varinfo_cst:(Cil_types.varinfo -> bool) ->
Cil_types.exp ->
boolTrue if the expression is a compile-time integer constant
val isConstantOffset :
?is_varinfo_cst:(Cil_types.varinfo -> bool) ->
Cil_types.offset ->
boolTrue if the given offset contains only field names or constant indices.
val isZero : Cil_types.exp -> boolTrue if the given expression is a (possibly cast'ed) integer or character constant with value zero
val is_nullptr : Cil_types.exp -> boolTrue if the given expression is a null pointer, i.e. 0, (void * )0, which are the two null pointer constants in the standard, or the cast of a null pointer (constant or not) into a pointer type.
val isLogicZero : Cil_types.term -> boolTrue if the term is the constant 0
val isLogicNull : Cil_types.term -> boolTrue if the given term is \null or a constant null pointer
val no_op_coerce : Cil_types.logic_type -> Cil_types.term -> boolno_op_coerce typ term is true iff converting term to typ does not modify its value.
val reduce_multichar : Cil_types.typ -> int64 list -> int64gives the value of a wide char literal.
val interpret_character_constant :
int64 list ->
Cil_types.constant * Cil_types.typgives the value of a char literal.
val charConstToInt : char -> Integer.tGiven the character c in a (CChr c), sign-extend it to 32 bits. (This is the official way of interpreting character constants, according to ISO C 6.4.4.4.10, which says that character constants are chars cast to ints) Returns CInt64(sign-extended c, IInt, None)
val charConstToIntConstant : char -> Cil_types.constantval constFold : bool -> Cil_types.exp -> Cil_types.expDo constant folding on an expression. If the first argument is true then will also compute compiler-dependent expressions such as sizeof. See also Cil.constFoldVisitor, which will run constFold on all expressions in a given AST node.
val constFoldToInt : ?machdep:bool -> Cil_types.exp -> Integer.t optionDo constant folding on the given expression, just as constFold would. The resulting integer value, if the const-folding was complete, is returned. The machdep optional parameter, which is set to true by default, forces the simplification of architecture-dependent expressions.
val constFoldTermNodeAtTop : Cil_types.term_node -> Cil_types.term_nodeDo constant folding on an term at toplevel only. This uses compiler-dependent informations and will remove all sizeof and alignof.
val constFoldTerm : bool -> Cil_types.term -> Cil_types.termDo constant folding on an term. If the first argument is true then will also compute compiler-dependent expressions such as sizeof and alignof.
val constFoldOffset : bool -> Cil_types.offset -> Cil_types.offsetDo constant folding on a Cil_types.offset. If the second argument is true then will also compute compiler-dependent expressions such as sizeof.
val constFoldBinOp :
loc:Cil_types.location ->
bool ->
Cil_types.binop ->
Cil_types.exp ->
Cil_types.exp ->
Cil_types.typ ->
Cil_types.expDo constant folding on a binary operation. The bulk of the work done by constFold is done here. If the second argument is true then will also compute compiler-dependent expressions such as sizeof.
val compareConstant : Cil_types.constant -> Cil_types.constant -> booltrue if the two constant are equal.
val sameSizeInt : ?machdep:bool -> Cil_types.ikind -> Cil_types.ikind -> booltrue if two kinds have the same size independently of the machine.
val same_int64 : ?machdep:bool -> Cil_types.exp -> Cil_types.exp -> booltrue if the result of two expressions are two equal integers.
val increm : Cil_types.exp -> int -> Cil_types.expIncrement an expression. Can be arithmetic or pointer type
val increm64 : Cil_types.exp -> Integer.t -> Cil_types.expIncrement an expression. Can be arithmetic or pointer type
val var : Cil_types.varinfo -> Cil_types.lvalMakes an lvalue out of a given variable
val evar : ?loc:Cil_types.location -> Cil_types.varinfo -> Cil_types.expCreates an expr representing the variable.
val mkAddrOf : loc:Cil_types.location -> Cil_types.lval -> Cil_types.expMake an AddrOf. Given an lvalue of type T will give back an expression of type ptr(T). It optimizes somewhat expressions like "& v" and "& v0"
val mkAddrOfVi : Cil_types.varinfo -> Cil_types.expCreates an expression corresponding to "&v".
val mkAddrOrStartOf : loc:Cil_types.location -> Cil_types.lval -> Cil_types.expLike mkAddrOf except if the type of lval is an array then it uses StartOf. This is the right operation for getting a pointer to the start of the storage denoted by lval.
val mkMem : addr:Cil_types.exp -> off:Cil_types.offset -> Cil_types.lvalMake a Mem, while optimizing AddrOf. The type of the addr must be TPtr(t) and the type of the resulting lval is t. Note that in CIL the implicit conversion between an array and the pointer to the first element does not apply. You must do the conversion yourself using StartOf
val mkBinOp :
loc:Cil_types.location ->
Cil_types.binop ->
Cil_types.exp ->
Cil_types.exp ->
Cil_types.expmakes a binary operation and performs const folding. Inserts casts between arithmetic types as needed, or between pointer types, but do not attempt to cast pointer to int or vice-versa. Use appropriate binop (PlusPI & friends) for that.
val mkBinOp_safe_ptr_cmp :
loc:Cil_types.location ->
Cil_types.binop ->
Cil_types.exp ->
Cil_types.exp ->
Cil_types.expval mkTermMem :
addr:Cil_types.term ->
off:Cil_types.term_offset ->
Cil_types.term_lvalEquivalent to mkMem for terms.
val mkString : loc:Cil_types.location -> string -> Cil_types.expMake an expression that is a string constant (of pointer type)
val need_cast : ?force:bool -> Cil_types.typ -> Cil_types.typ -> booltrue if both types are not equivalent. if force is true, returns true whenever both types are not equal (modulo typedefs). If force is false (the default), other equivalences are considered, in particular between an enum and its representative integer type.
val typeForInsertedCast :
(Cil_types.exp -> Cil_types.typ -> Cil_types.typ -> Cil_types.typ) reftypeForInsertedCast expr original_type destination_type returns the type into which expr, which has type original_type and whose type must be converted into destination_type, must be casted.
By default, returns destination_type.
This applies only to implicit casts. Casts already present in the source code are exempt from this hook.
val checkCast :
?context:qualifier_check_context ->
?nullptr_cast:bool ->
?fromsource:bool ->
Cil_types.typ ->
Cil_types.typ ->
unitcheckCast context fromsource nullptr_cast oldt newt emits a warning or an error if the cast from oldt to newt is invalid (does nothing otherwise). nullptr_cast is true iff the expression being casted is a null pointer. Default is false. fromsource is false (default) if the cast is not present in the source code. Check areCompatibleTypes documentation for context.
Suspicious cases that only emit a warning:
- Implicit cast from a pointer to an integer.
- Cast from a pointer to a function type to another pointer to a function type when the function types are not compatible.
- Cast from an array to a pointer/array when types are not compatible.
- Cast, in both directions, between pointer to an object type and pointer to a function type.
val mkCastTGen :
?check:bool ->
?context:qualifier_check_context ->
?fromsource:bool ->
?force:bool ->
oldt:Cil_types.typ ->
newt:Cil_types.typ ->
Cil_types.exp ->
Cil_types.typ * Cil_types.expGeneric version of Cil.mkCastT. Construct a cast when having the old type of the expression. fromsource is false (default) if the cast is not present in the source code. If check is true (default), we check that the cast is valid, emitting an error or warning if the cast is invalid. If the new type is the same as the old type, then no cast is added, unless force is true (default is false). Cast from oldt to newt, returning the new type and the new expression.
val mkCastT :
?check:bool ->
?force:bool ->
oldt:Cil_types.typ ->
newt:Cil_types.typ ->
Cil_types.exp ->
Cil_types.expConstruct a cast when having the old type of the expression. If the new type is the same as the old type, then no cast is added, unless force is true (default is false). Emit an error or warning if check is true and the cast is invalid.
val mkCast :
?check:bool ->
?force:bool ->
newt:Cil_types.typ ->
Cil_types.exp ->
Cil_types.expLike Cil.mkCastT, but uses typeOf to get oldt.
val stripTermCasts : Cil_types.term -> Cil_types.termEquivalent to stripCasts for terms.
val stripCasts : Cil_types.exp -> Cil_types.expRemoves casts from this expression, but ignores casts within other expression constructs. So we delete the (A) and (B) casts from "(A)(B)(x + (C)y)", but leave the (C) cast.
val typeOf : Cil_types.exp -> Cil_types.typCompute the type of an expression.
val typeOf_pointed : Cil_types.typ -> Cil_types.typReturns the type pointed by the given type. Asserts it is a pointer type.
val typeOf_array_elem : Cil_types.typ -> Cil_types.typReturns the type of the array elements of the given type. Asserts it is an array type.
val is_fully_arithmetic : Cil_types.typ -> boolReturns true whenever the type contains only arithmetic types
val parseInt : string -> Integer.tConvert a string representing a C integer literal to an Integer. Handles the prefixes 0x and 0 and the suffixes L, U, UL, LL, ULL.
Like parseInt, but returns Error message in case of failure, instead of aborting Frama-C.
val parseIntExp : loc:Cil_types.location -> string -> Cil_types.expLike parseInt, but converts to an expression.
val parseIntExpRes :
loc:Cil_types.location ->
string ->
(Cil_types.exp, string) resultLike parseIntExp, but returns Error message in case of failure, instead of aborting Frama-C.
val parseIntLogic : loc:Cil_types.location -> string -> Cil_types.termLike parseInt, but converts to a logic term.
val appears_in_expr : Cil_types.varinfo -> Cil_types.exp -> boolValues for manipulating statements
val mkStmt :
?ghost:bool ->
?valid_sid:bool ->
?sattr:Cil_types.attributes ->
Cil_types.stmtkind ->
Cil_types.stmtConstruct a statement, given its kind. Initialize the sid field to -1 if valid_sid is false (the default), or to a valid sid if valid_sid is true, and labels, succs and preds to the empty list
val mkStmtCfg :
before:bool ->
new_stmtkind:Cil_types.stmtkind ->
ref_stmt:Cil_types.stmt ->
Cil_types.stmtval mkBlock : Cil_types.stmt list -> Cil_types.blockConstruct a block with no attributes, given a list of statements
val mkBlockNonScoping : Cil_types.stmt list -> Cil_types.blockConstruct a non-scoping block, i.e. a block that is not used to determine the end of scope of local variables. Hence, the blocals of such a block must always be empty.
val mkStmtCfgBlock : Cil_types.stmt list -> Cil_types.stmtConstruct a block with no attributes, given a list of statements and wrap it into the Cfg.
val mkStmtOneInstr :
?ghost:bool ->
?valid_sid:bool ->
?sattr:Cil_types.attributes ->
Cil_types.instr ->
Cil_types.stmtConstruct a statement consisting of just one instruction See Cil.mkStmt for the signification of the optional args.
Try to compress statements so as to get maximal basic blocks. * use this instead of List.@ because you get fewer basic blocks
val mkEmptyStmt :
?ghost:bool ->
?valid_sid:bool ->
?sattr:Cil_types.attributes ->
?loc:Cil_types.location ->
unit ->
Cil_types.stmtReturns an empty statement (of kind Instr). See mkStmt for ghost and valid_sid arguments.
val dummyInstr : Cil_types.instrA instr to serve as a placeholder
val dummyStmt : Cil_types.stmtA statement consisting of just dummyInstr.
val mkPureExprInstr :
fundec:Cil_types.fundec ->
scope:Cil_types.block ->
?loc:Cil_types.location ->
Cil_types.exp ->
Cil_types.instrCreate an instruction equivalent to a pure expression. The new instruction corresponds to the initialization of a new fresh variable, i.e. int tmp = exp. The scope of this fresh variable is determined by the block given in argument, that is the instruction must be placed directly (modulo non-scoping blocks) inside this block.
val mkPureExpr :
?ghost:bool ->
?valid_sid:bool ->
fundec:Cil_types.fundec ->
?loc:Cil_types.location ->
Cil_types.exp ->
Cil_types.stmtCreate an instruction as above, enclosed in a block of a single (Instr) statement, which will be the scope of the fresh variable holding the value of the expression.
See Cil.mkStmt for information about ghost and valid_sid, and Cil.mkPureExprInstr for information about loc.
val mkLoop :
?sattr:Cil_types.attributes ->
guard:Cil_types.exp ->
body:Cil_types.stmt list ->
unit ->
Cil_types.stmt listMake a loop. Can contain Break or Continue. The kind of loop (while, for, dowhile) is given by sattr (none by default). Use Cil.mkWhile for a While loop.
val mkForIncr :
?sattr:Cil_types.attributes ->
iter:Cil_types.varinfo ->
first:Cil_types.exp ->
stopat:Cil_types.exp ->
incr:Cil_types.exp ->
body:Cil_types.stmt list ->
unit ->
Cil_types.stmt listMake a for loop for(i=start; i<past; i += incr) { ... }. The body can contain Break but not Continue. Can be used with i a pointer or an integer. Start and done must have the same type but incr must be an integer
val mkFor :
?sattr:Cil_types.attributes ->
start:Cil_types.stmt list ->
guard:Cil_types.exp ->
next:Cil_types.stmt list ->
body:Cil_types.stmt list ->
unit ->
Cil_types.stmt listMake a for loop for(start; guard; next) { ... }. The body can contain Break but not Continue !!!
val mkWhile :
?sattr:Cil_types.attributes ->
guard:Cil_types.exp ->
body:Cil_types.stmt list ->
unit ->
Cil_types.stmt listMake a while loop.
val mkDoWhile :
?sattr:Cil_types.attributes ->
body:Cil_types.stmt list ->
guard:Cil_types.exp ->
unit ->
Cil_types.stmt listMake a do ... while loop.
val block_from_unspecified_sequence :
(Cil_types.stmt
* Cil_types.lval list
* Cil_types.lval list
* Cil_types.lval list
* Cil_types.stmt ref list)
list ->
Cil_types.blockcreates a block with empty attributes from an unspecified sequence.
val treat_constructor_as_func :
(Cil_types.lval option ->
Cil_types.exp ->
Cil_types.exp list ->
Cil_types.location ->
'a) ->
Cil_types.varinfo ->
Cil_types.varinfo ->
Cil_types.exp list ->
Cil_types.constructor_kind ->
Cil_types.location ->
'atreat_constructor_as_func action v f args kind loc calls action with the parameters corresponding to the call to f, of kind kind, initializing v with arguments args.
val find_def_stmt : Cil_types.block -> Cil_types.varinfo -> Cil_types.stmtfind_def_stmt b v returns the Local_init instruction within b that initializes v. v must have its vdefined field set to true, and be among b.blocals.
val has_extern_local_init : Cil_types.block -> boolreturns true iff the given non-scoping block contains local init statements (thus of locals belonging to an outer block), either directly or within a non-scoping block or undefined sequence.labels
val is_ghost_else : Cil_types.block -> boolreturns true iff the given block is a ghost else block.
Values for manipulating attributes
type attributeClass = | AttrName of bool(*Attribute of a name. If argument is true and we are on MSVC then the attribute is printed using __declspec as part of the storage specifier
*)| AttrFunType of bool(*Attribute of a function type. If argument is true and we are on MSVC then the attribute is printed just before the function name
*)| AttrType(*Attribute of a type
*)
Various classes of attributes
val registerAttribute : string -> attributeClass -> unitAdd a new attribute with a specified class
val attributeClass : string -> attributeClassReturn the class of an attributes.
val partitionAttributes :
default:attributeClass ->
Cil_types.attributes ->
Cil_types.attribute list
* Cil_types.attribute list
* Cil_types.attribute listPartition the attributes into classes:name attributes, function type, and type attributes
val addAttribute :
Cil_types.attribute ->
Cil_types.attributes ->
Cil_types.attributesAdd an attribute. Maintains the attributes in sorted order of the second argument. The attribute is not added if it is already there.
val addAttributes :
Cil_types.attribute list ->
Cil_types.attributes ->
Cil_types.attributesAdd a list of attributes. Maintains the attributes in sorted order. The second argument must be sorted, but not necessarily the first
val dropAttribute : string -> Cil_types.attributes -> Cil_types.attributesRemove all attributes with the given name. Maintains the attributes in sorted order.
val dropAttributes :
string list ->
Cil_types.attributes ->
Cil_types.attributesRemove all attributes with names appearing in the string list. * Maintains the attributes in sorted order
A varinfo marked with this attribute is known to be a ghost formal.
a formal marked with this attribute is known to be a pointer to an object being initialized by the current function, which can thus assign any sub-object regardless of const status.
a field struct marked with this attribute is known to be mutable, i.e. it can be modified even on a const object.
A block marked with this attribute is known to be inlined, i.e. it replaces a call to an inline function.
val is_initialized : Cil_types.exp -> booltrue if the underlying left-value of the given expression is allowed to be assigned to thanks to a frama_c_init_obj attribute.
val is_mutable_or_initialized : Cil_types.lval -> booltrue if the given lval is allowed to be assigned to thanks to a frama_c_init_obj or a frama_c_mutable attribute.
val isGhostFormalVarinfo : Cil_types.varinfo -> booltrue if the given varinfo is a ghost formal variable.
val isGhostFormalVarDecl :
(string * Cil_types.typ * Cil_types.attributes) ->
booltrue if the given formal declaration corresponds to a ghost formal variable.
val isGlobalInitConst : Cil_types.varinfo -> booltrue iff the given variable is a const global variable with non extern storage.
val typeDeepDropAllAttributes : Cil_types.typ -> Cil_types.typRemove any attribute appearing somewhere in the fully expanded version of the type.
val filterAttributes : string -> Cil_types.attributes -> Cil_types.attributesRetains attributes with the given name
val hasAttribute : string -> Cil_types.attributes -> boolTrue if the named attribute appears in the attribute list. The list of attributes must be sorted.
val attributeName : Cil_types.attribute -> stringReturns the name of an attribute.
val findAttribute :
string ->
Cil_types.attribute list ->
Cil_types.attrparam listReturns the list of parameters associated to an attribute. The list is empty if there is no such attribute or it has no parameters at all.
val typeAttrs : Cil_types.typ -> Cil_types.attribute listReturns all the attributes contained in a type. This requires a traversal of the type structure, in case of composite, enumeration and named types
val typeAttr : Cil_types.typ -> Cil_types.attribute listReturns the attributes of a type.
val setTypeAttrs : Cil_types.typ -> Cil_types.attributes -> Cil_types.typSets the attributes of the type to the given list. Previous attributes are discarded.
val typeAddAttributes :
?combine:
(Cil_types.attribute list -> Cil_types.attributes -> Cil_types.attributes) ->
Cil_types.attribute list ->
Cil_types.typ ->
Cil_types.typAdd some attributes to a type. combine explains how to combine attributes. Default is addAttributes.
val typeRemoveAttributes : string list -> Cil_types.typ -> Cil_types.typRemove all attributes with the given names from a type. Note that this does not remove attributes from typedef and tag definitions, just from their uses (unfolding the type definition when needed). It only removes attributes of topmost type, i.e. does not recurse under pointers, arrays, ...
val typeRemoveAllAttributes : Cil_types.typ -> Cil_types.typsame as above, but remove any existing attribute from the type.
val typeRemoveAttributesDeep : string list -> Cil_types.typ -> Cil_types.typSame as typeRemoveAttributes, but recursively removes the given attributes from inner types as well. Mainly useful to check whether two types are equal modulo some attributes. See also typeDeepDropAllAttributes, which will strip every single attribute from a type.
val typeHasAttribute : string -> Cil_types.typ -> boolDoes the type have the given attribute. Does not recurse through pointer types, nor inside function prototypes.
val typeHasQualifier : string -> Cil_types.typ -> boolDoes the type have the given qualifier. Handles the case of arrays, for which the qualifiers are actually carried by the type of the elements. It is always correct to call this function instead of typeHasAttribute. For l-values, both functions return the same results, as l-values cannot have array type.
val typeHasAttributeMemoryBlock : string -> Cil_types.typ -> booltypeHasAttributeMemoryBlock attr t is true iff at least one component of an object of type t has attribute attr. In other words, it searches for attr under aggregates, but not under pointers.
val type_remove_qualifier_attributes : Cil_types.typ -> Cil_types.typRemove all attributes relative to const, volatile and restrict attributes
val type_remove_qualifier_attributes_deep : Cil_types.typ -> Cil_types.typremove also qualifiers under Ptr and Arrays
val type_remove_attributes_for_c_cast : Cil_types.typ -> Cil_types.typRemove all attributes relative to const, volatile and restrict attributes when building a C cast
val type_remove_attributes_for_logic_type : Cil_types.typ -> Cil_types.typRemove all attributes relative to const, volatile and restrict attributes when building a logic cast
val filter_qualifier_attributes : Cil_types.attributes -> Cil_types.attributesretains attributes corresponding to type qualifiers (6.7.3)
val splitArrayAttributes :
Cil_types.attributes ->
Cil_types.attributes * Cil_types.attributesgiven some attributes on an array type, split them into those that belong to the type of the elements of the array (currently, qualifiers such as const and volatile), and those that must remain on the array, in that order
Name of the attribute that is automatically inserted (with an AINT size argument when querying the type of a field that is a bitfield
Name of the attribute that is inserted when generating a name for a varinfo representing an anonymous function parameter.
val anonymous_attribute : Cil_types.attributeattribute identifying anonymous function parameters
val expToAttrParam : Cil_types.exp -> Cil_types.attrparamConvert an expression into an attrparam, if possible. Otherwise raise NotAnAttrParam with the offending subexpression
val global_annotation_attributes :
Cil_types.global_annotation ->
Cil_types.attributesReturn the attributes of the global annotation, if any.
val global_attributes : Cil_types.global -> Cil_types.attributesReturn the attributes of the global, if any.
val is_in_libc : Cil_types.attributes -> boolWhether the given attributes contain libc indicators.
val global_is_in_libc : Cil_types.global -> boolWhether the given global contains libc indicators.
exception NotAnAttrParam of Cil_types.expConst Attribute
val isConstType : Cil_types.typ -> boolCheck for "const" qualifier from the type of an l-value (do not follow pointer)
Volatile Attribute
val isVolatileType : Cil_types.typ -> boolCheck for "volatile" qualifier from the type of an l-value (do not follow pointer)
val isVolatileLogicType : Cil_types.logic_type -> boolCheck for "volatile" qualifier from a logic type
val isVolatileLval : Cil_types.lval -> boolCheck if the l-value has a volatile part
val isVolatileTermLval : Cil_types.term_lval -> boolCheck if the l-value has a volatile part
Ghost Attribute
val isGhostType : Cil_types.typ -> boolCheck for "ghost" qualifier from the type of an l-value (do not follow pointer)
val isWFGhostType : Cil_types.typ -> boolCheck if the received type is well-formed according to \ghost semantics, that is once the type is not ghost anymore, \ghost cannot appear again.
val typeAddGhost : Cil_types.typ -> Cil_types.typAdd the ghost attribute to a type (does nothing if the type is alreay ghost)
The visitor
type 'a visitAction = | SkipChildren(*Do not visit the children. Return the node as it is.
*)| DoChildren(*Continue with the children of this node. Rebuild the node on return if any of the children changes (use == test).
*)| DoChildrenPost of 'a -> 'a(*visit the children, and apply the given function to the result.
*)| JustCopy(*visit the children, but only to make the necessary copies (only useful for copy visitor).
*)| JustCopyPost of 'a -> 'a(*same as JustCopy + applies the given function to the result.
*)| ChangeTo of 'a(*Replace the expression with the given one.
*)| ChangeToPost of 'a * 'a -> 'a(*applies the expression to the function and gives back the result. Useful to insert some actions in an inheritance chain.
*)| ChangeDoChildrenPost of 'a * 'a -> 'a(*First consider that the entire exp is replaced by the first parameter. Then continue with the children. On return rebuild the node if any of the children has changed and then apply the function on the node.
*)
Different visiting actions. 'a will be instantiated with exp, instr, etc.
val mk_behavior :
?name:string ->
?assumes:Cil_types.identified_predicate list ->
?requires:Cil_types.identified_predicate list ->
?post_cond:(Cil_types.termination_kind * Cil_types.identified_predicate) list ->
?assigns:Cil_types.assigns ->
?allocation:Cil_types.allocation ->
?extended:Cil_types.acsl_extension list ->
unit ->
Cil_types.behaviorreturns a dummy behavior with the default name Cil.default_behavior_name. invariant: b_assumes must always be empty for behavior named Cil.default_behavior_name
val is_default_behavior : Cil_types.behavior -> boolval find_default_behavior : Cil_types.funspec -> Cil_types.funbehavior optionval find_default_requires :
Cil_types.behavior list ->
Cil_types.identified_predicate listVisitor mechanism
Visitor class
class type cilVisitor = object ... endA visitor interface for traversing CIL trees. Create instantiations of this type by specializing the class nopCilVisitor. Each of the specialized visiting functions can also call the queueInstr to specify that some instructions should be inserted before the current statement. Use syntax like self#queueInstr to call a method associated with the current object.
class genericCilVisitor : Visitor_behavior.t -> cilVisitorgeneric visitor, parameterized by its copying behavior. Traverses the CIL tree without modifying anything
class nopCilVisitor : cilVisitorDefault in place visitor doing nothing and operating on current project.
Generic visit functions
val doVisit :
'visitor ->
'visitor ->
('a -> 'a) ->
('a -> 'a visitAction) ->
('visitor -> 'a -> 'a) ->
'a ->
'adoVisit vis deepCopyVisitor copy action children node visits a node (or its copy according to the result of copy) and if needed its children. Do not use it if you don't understand Cil visitor mechanism
val doVisitList :
'visitor ->
'visitor ->
('a -> 'a) ->
('a -> 'a list visitAction) ->
('visitor -> 'a -> 'a) ->
'a ->
'a listsame as above, but can return a list of nodes
Visitor's entry points
val visitCilFileCopy : cilVisitor -> Cil_types.file -> Cil_types.fileVisit a file. This will re-cons all globals TWICE (so that it is * tail-recursive). Use Cil.visitCilFileSameGlobals if your visitor will * not change the list of globals.
val visitCilFile : cilVisitor -> Cil_types.file -> unitSame thing, but the result is ignored. The given visitor must thus be an inplace visitor. Nothing is done if the visitor is a copy visitor.
val visitCilFileSameGlobals : cilVisitor -> Cil_types.file -> unitA visitor for the whole file that does not *physically* change the globals (but maybe changes things inside the globals through side-effects). Use this function instead of Cil.visitCilFile whenever appropriate because it is more efficient for long files.
val visitCilFileFunctions : cilVisitor -> Cil_types.file -> unitSame as Cil.visitCilFileSameGlobals, but only visits function definitions (i.e. behaves as if all globals but GFun return SkipChildren).
val visitCilGlobal : cilVisitor -> Cil_types.global -> Cil_types.global listVisit a global
val visitCilFunction : cilVisitor -> Cil_types.fundec -> Cil_types.fundecVisit a function definition
val visitCilExpr : cilVisitor -> Cil_types.exp -> Cil_types.expval visitCilEnumInfo : cilVisitor -> Cil_types.enuminfo -> Cil_types.enuminfoval visitCilLval : cilVisitor -> Cil_types.lval -> Cil_types.lvalVisit an lvalue
val visitCilOffset : cilVisitor -> Cil_types.offset -> Cil_types.offsetVisit an lvalue or recursive offset
val visitCilInitOffset : cilVisitor -> Cil_types.offset -> Cil_types.offsetVisit an initializer offset
val visitCilLocal_init :
cilVisitor ->
Cil_types.varinfo ->
Cil_types.local_init ->
Cil_types.local_initVisit a local initializer (with the local being initialized).
val visitCilInstr : cilVisitor -> Cil_types.instr -> Cil_types.instr listVisit an instruction
val visitCilStmt : cilVisitor -> Cil_types.stmt -> Cil_types.stmtVisit a statement
val visitCilBlock : cilVisitor -> Cil_types.block -> Cil_types.blockVisit a block
val transient_block : Cil_types.block -> Cil_types.blockMark the given block as candidate to be flattened into its parent block, after returning from its visit. This is not systematic, as the environment might prevent it (e.g. if the preceding statement is a statement contract or a slicing/pragma annotation, or if there are labels involved). Use that whenever you're creating a block in order to hold multiple statements as a result of visiting a single statement. If the block contains local variables, it will not be marked as transient, since removing it will change the scope of those variables.
val is_transient_block : Cil_types.block -> booltells whether the block has been marked as transient
val flatten_transient_sub_blocks : Cil_types.block -> Cil_types.blockflatten_transient_sub_blocks b flattens all direct sub-blocks of b that have been marked as cleanable, whenever possible
val visitCilType : cilVisitor -> Cil_types.typ -> Cil_types.typVisit a type
val visitCilVarDecl : cilVisitor -> Cil_types.varinfo -> Cil_types.varinfoVisit a variable declaration
val visitCilInit :
cilVisitor ->
Cil_types.varinfo ->
Cil_types.offset ->
Cil_types.init ->
Cil_types.initVisit an initializer, pass also the global to which this belongs and the * offset.
val visitCilAttributes :
cilVisitor ->
Cil_types.attribute list ->
Cil_types.attribute listVisit a list of attributes
val visitCilAnnotation :
cilVisitor ->
Cil_types.global_annotation ->
Cil_types.global_annotationval visitCilCodeAnnotation :
cilVisitor ->
Cil_types.code_annotation ->
Cil_types.code_annotationval visitCilDeps : cilVisitor -> Cil_types.deps -> Cil_types.depsval visitCilFrom : cilVisitor -> Cil_types.from -> Cil_types.fromval visitCilAssigns : cilVisitor -> Cil_types.assigns -> Cil_types.assignsval visitCilFrees :
cilVisitor ->
Cil_types.identified_term list ->
Cil_types.identified_term listval visitCilAllocates :
cilVisitor ->
Cil_types.identified_term list ->
Cil_types.identified_term listval visitCilAllocation :
cilVisitor ->
Cil_types.allocation ->
Cil_types.allocationval visitCilFunspec : cilVisitor -> Cil_types.funspec -> Cil_types.funspecval visitCilBehavior :
cilVisitor ->
Cil_types.funbehavior ->
Cil_types.funbehaviorval visitCilBehaviors :
cilVisitor ->
Cil_types.funbehavior list ->
Cil_types.funbehavior listval visitCilExtended :
cilVisitor ->
Cil_types.acsl_extension ->
Cil_types.acsl_extensionvisit an extended clause of a behavior.
val visitCilModelInfo :
cilVisitor ->
Cil_types.model_info ->
Cil_types.model_infoval visitCilLogicType :
cilVisitor ->
Cil_types.logic_type ->
Cil_types.logic_typeval visitCilIdPredicate :
cilVisitor ->
Cil_types.identified_predicate ->
Cil_types.identified_predicateval visitCilPredicateNode :
cilVisitor ->
Cil_types.predicate_node ->
Cil_types.predicate_nodeval visitCilPredicate :
cilVisitor ->
Cil_types.predicate ->
Cil_types.predicateval visitCilPredicates :
cilVisitor ->
Cil_types.identified_predicate list ->
Cil_types.identified_predicate listval visitCilTerm : cilVisitor -> Cil_types.term -> Cil_types.termval visitCilIdTerm :
cilVisitor ->
Cil_types.identified_term ->
Cil_types.identified_termvisit identified_term.
val visitCilTermLval : cilVisitor -> Cil_types.term_lval -> Cil_types.term_lvalvisit term_lval.
val visitCilTermLhost :
cilVisitor ->
Cil_types.term_lhost ->
Cil_types.term_lhostval visitCilTermOffset :
cilVisitor ->
Cil_types.term_offset ->
Cil_types.term_offsetval visitCilLogicInfo :
cilVisitor ->
Cil_types.logic_info ->
Cil_types.logic_infoval visitCilLogicVarUse :
cilVisitor ->
Cil_types.logic_var ->
Cil_types.logic_varval visitCilLogicVarDecl :
cilVisitor ->
Cil_types.logic_var ->
Cil_types.logic_varVisiting children of a node
val childrenBehavior :
cilVisitor ->
Cil_types.funbehavior ->
Cil_types.funbehaviorUtility functions
val is_skip : Cil_types.stmtkind -> boolval constFoldVisitor : bool -> cilVisitorA visitor that does constant folding. Pass as argument whether you want machine specific simplifications to be done, or not.
Debugging support
module CurrentLoc : State_builder.Ref with type data = Cil_types.locationA reference to the current location. If you are careful to set this to * the current location then you can use some built-in logging functions that * will print the location.
val pp_thisloc : Format.formatter -> unitPretty-print (Cil.CurrentLoc.get ())
val empty_funspec : unit -> Cil_types.funspecval is_empty_funspec : Cil_types.funspec -> boolval is_empty_behavior : Cil_types.funbehavior -> boolRenaming
See also the Alpha module for other renaming operations.
val uniqueVarNames : Cil_types.file -> unitAssign unique names to local variables. This might be necessary after you transformed the code and added or renamed some new variables. Names are not used by CIL internally, but once you print the file out the compiler downstream might be confused. You might have added a new global that happens to have the same name as a local in some function. Rename the local to ensure that there would never be confusion. Or, viceversa, you might have added a local with a name that conflicts with a global
Optimization Passes
val peepHole2 :
aggressive:bool ->
((Cil_types.stmt * Cil_types.stmt) -> Cil_types.stmt list option) ->
Cil_types.stmt list ->
Cil_types.stmt listA peephole optimizer that processes two adjacent statements and possibly replaces them both. If some replacement happens and aggressive is true, then the new statements are themselves subject to optimization. Each statement in the list is optimized independently.
val peepHole1 :
(Cil_types.instr -> Cil_types.instr list option) ->
Cil_types.stmt list ->
unitSimilar to peepHole2 except that the optimization window consists of one statement, not two
Machine dependency
exception SizeOfError of string * Cil_types.typRaised when one of the SizeOf/AlignOf functions cannot compute the size of a type. This can happen because the type contains array-length expressions that we don't know how to compute or because it is a type whose size is not defined (e.g. TFun or an undefined compinfo). The string is an explanation of the error
val unsignedVersionOf : Cil_types.ikind -> Cil_types.ikindGive the unsigned kind corresponding to any integer kind
val intKindForSize : int -> bool -> Cil_types.ikindThe signed integer kind for a given size (unsigned if second argument * is true). Raises Not_found if no such kind exists
val floatKindForSize : int -> Cil_types.fkindThe float kind for a given size. Raises Not_found * if no such kind exists
val bitsSizeOf : Cil_types.typ -> intThe size of a type, in bits. Trailing padding is added for structs and * arrays. Raises Cil.SizeOfError when it cannot compute the size. This * function is architecture dependent, so you should only call this after you * call Cil.initCIL. Remember that on GCC sizeof(void) is 1!
val bytesSizeOf : Cil_types.typ -> intThe size of a type, in bytes. Raises Cil.SizeOfError when it cannot compute the size.
val bytesSizeOfInt : Cil_types.ikind -> intReturns the number of bytes (resp. bits) to represent the given integer kind depending on the current machdep.
val bitsSizeOfInt : Cil_types.ikind -> intval isSigned : Cil_types.ikind -> boolReturns the signedness of the given integer kind depending on the current machdep.
val bitsSizeOfBitfield : Cil_types.typ -> intReturns the size of the given type, in bits. If this is the type of an lvalue which is a bitfield, the size of the bitfield is returned.
val selfTypSize : State.tCache for sizeof
val rank : Cil_types.ikind -> intReturns a unique number representing the integer conversion rank.
val intTypeIncluded : Cil_types.ikind -> Cil_types.ikind -> boolintTypeIncluded i1 i2 returns true iff the range of values representable in i1 is included in the one of i2
val frank : Cil_types.fkind -> intReturns a unique number representing the floating-point conversion rank.
val truncateInteger64 : Cil_types.ikind -> Integer.t -> Integer.t * boolRepresents an integer as for a given kind. * Returns a flag saying whether the value was changed * during truncation (because it was too large to fit in k).
val max_signed_number : int -> Integer.tReturns the maximal value representable in a signed integer type of the given size (in bits)
val min_signed_number : int -> Integer.tReturns the smallest value representable in a signed integer type of the given size (in bits)
val max_unsigned_number : int -> Integer.tReturns the maximal value representable in a unsigned integer type of the given size (in bits)
val fitsInInt : Cil_types.ikind -> Integer.t -> boolTrue if the integer fits within the kind's range
val isFiniteFloat : Cil_types.fkind -> float -> boolTrue if the float is finite for the kind's range
val isExactFloat : Cil_types.fkind -> Cil_types.logic_real -> boolTrue if the real constant is an exact float for the given type
raised by intKindForValue.
val intKindForValue : Integer.t -> bool -> Cil_types.ikindval sizeOf : loc:Cil_types.location -> Cil_types.typ -> Cil_types.expThe size of a type, in bytes. Returns a constant expression or a "sizeof" * expression if it cannot compute the size. This function is architecture * dependent, so you should only call this after you call Cil.initCIL.
val bytesAlignOf : Cil_types.typ -> intThe minimum alignment (in bytes) for a type. This function is * architecture dependent, so you should only call this after you call * Cil.initCIL. * Raises SizeOfError when it cannot compute the alignment.
val intOfAttrparam : Cil_types.attrparam -> int optionintOfAttrparam a tries to const-fold a into a numeric value. Returns Some n if it succeeds, None otherwise.
val bitsOffset : Cil_types.typ -> Cil_types.offset -> int * intGive a type of a base and an offset, returns the number of bits from the * base address and the width (also expressed in bits) for the subobject * denoted by the offset. Raises Cil.SizeOfError when it cannot compute * the size. This function is architecture dependent, so you should only call * this after you call Cil.initCIL.
val fieldBitsOffset : Cil_types.fieldinfo -> int * intGive a field, returns the number of bits from the structure or union * containing the field and the width (also expressed in bits) for the subobject * denoted by the field. Raises Cil.SizeOfError when it cannot compute * the size. This function is architecture dependent, so you should only call * this after you call Cil.initCIL.
Like map but each call can return a list. Try not to make a copy of the list
sm: return true if the first is a prefix of the second string
An Interpreter for constructing CIL constructs
type formatArg = | Fe of Cil_types.exp| Feo of Cil_types.exp option(*For array lengths
*)| Fu of Cil_types.unop| Fb of Cil_types.binop| Fk of Cil_types.ikind| FE of Cil_types.exp list(*For arguments in a function call
*)| Ff of string * Cil_types.typ * Cil_types.attributes(*For a formal argument
*)| FF of (string * Cil_types.typ * Cil_types.attributes) list(*For formal argument lists
*)| Fva of bool(*For the ellipsis in a function type
*)| Fv of Cil_types.varinfo| Fl of Cil_types.lval| Flo of Cil_types.lval option| Fo of Cil_types.offset| Fc of Cil_types.compinfo| Fi of Cil_types.instr| FI of Cil_types.instr list| Ft of Cil_types.typ| Fd of int| Fg of string| Fs of Cil_types.stmt| FS of Cil_types.stmt list| FA of Cil_types.attributes| Fp of Cil_types.attrparam| FP of Cil_types.attrparam list| FX of string
The type of argument for the interpreter
val d_formatarg : Format.formatter -> formatArg -> unitMisc
val stmt_of_instr_list :
?loc:Cil_types.location ->
Cil_types.instr list ->
Cil_types.stmtkindif the list has 2 elements or more, it will return a block with bscoping=false
val cvar_to_lvar : Cil_types.varinfo -> Cil_types.logic_varConvert a C variable into the corresponding logic variable. The returned logic variable is unique for a given C variable.
val cvar_to_term :
loc:Cil_types.location ->
Cil_types.varinfo ->
Cil_types.termConvert a C variable into a logic term.
val make_temp_logic_var : Cil_types.logic_type -> Cil_types.logic_varMake a temporary variable to use in annotations
val lzero : ?loc:Cil_types.location -> unit -> Cil_types.termThe constant logic term zero.
val lone : ?loc:Cil_types.location -> unit -> Cil_types.termThe constant logic term 1.
val lmone : ?loc:Cil_types.location -> unit -> Cil_types.termThe constant logic term -1.
val lconstant : ?loc:Cil_types.location -> Integer.t -> Cil_types.termThe given constant logic term
val close_predicate : Cil_types.predicate -> Cil_types.predicateBind all free variables with an universal quantifier
val extract_varinfos_from_exp : Cil_types.exp -> Cil_datatype.Varinfo.Set.textract varinfo elements from an exp
val extract_varinfos_from_lval : Cil_types.lval -> Cil_datatype.Varinfo.Set.textract varinfo elements from an lval
val extract_free_logicvars_from_term :
Cil_types.term ->
Cil_datatype.Logic_var.Set.textract logic_var elements from a term
val extract_free_logicvars_from_predicate :
Cil_types.predicate ->
Cil_datatype.Logic_var.Set.textract logic_var elements from a predicate
val extract_labels_from_annot :
Cil_types.code_annotation ->
Cil_datatype.Logic_label.Set.textract logic_label elements from a code_annotation
val extract_labels_from_term : Cil_types.term -> Cil_datatype.Logic_label.Set.textract logic_label elements from a term
val extract_labels_from_pred :
Cil_types.predicate ->
Cil_datatype.Logic_label.Set.textract logic_label elements from a pred
val extract_stmts_from_labels :
Cil_datatype.Logic_label.Set.t ->
Cil_datatype.Stmt.Set.textract stmt elements from logic_label elements
val create_alpha_renaming :
Cil_types.varinfo list ->
Cil_types.varinfo list ->
cilVisitorcreates a visitor that will replace in place uses of var in the first list by their counterpart in the second list.
val separate_switch_succs :
Cil_types.stmt ->
Cil_types.stmt list * Cil_types.stmtProvided s is a switch, separate_switch_succs s returns the subset of s.succs that correspond to the Case labels of s, and a "default statement" that either corresponds to the Default label, or to the syntactic successor of s if there is no default label. Note that this "default statement" can thus appear in the returned list.
val separate_if_succs : Cil_types.stmt -> Cil_types.stmt * Cil_types.stmtProvided s is a if, separate_if_succs s splits the successors of s according to the truth value of the condition. The first element of the pair is the successor statement if the condition is true, and the second if the condition is false.
- Customization
- Values for manipulating globals
- Values for manipulating initializers
- Values for manipulating types
- Values for manipulating expressions
- Values for manipulating attributes
- Const Attribute
- Volatile Attribute
- Ghost Attribute
- The visitor
- Visitor mechanism
- Utility functions
- Debugging support
- Renaming
- Optimization Passes
- Machine dependency
- An Interpreter for constructing CIL constructs
- Misc