text stringlengths 0 601k |
|---|
let ret = incr arg_idx ; match ! return_type with | TUnknown -> <: expr < return_unknown ( ) , Dummy >> | TInt32 -> <: expr < return_int $ ExInt ( Loc . ghost , string_of_int ( ! arg_idx ) ) $ " " , Vector . int32 >> | TInt64 -> <: expr < return_int $ ExInt ( Loc . ghost , string_of_int ( ! arg_idx ) ) $ " " , Vector .... |
let t = List . fold_left ( fun seed p -> match p with | ( PaId ( _ , i ) ) -> let value = ( Hashtbl . find ! current_args ( string_of_ident i ) ) in TApp ( value . var_type , seed ) | PaTyc ( _ , i , t ) -> ktyp_of_typ t | _ -> assert false ) ! return_type ( List . rev args ) in |
let task_manager = ( if Fastflow . fastflow then Fastflow . print_task args name _loc else <: expr < Obj . magic None ) >> in { nb_args = 0 ; cuda_val " " ; = opencl_val " " ; = typ = t } ; <: str_item < |
let $ id : name $ = let open Kirc in let a = { fun_name = $ str : string_of_ident name ; $ ml_fun = $ gen_args ; $ funbody = $ gen_body2 ; $ fun_ret = $ ret ; $ fastflow_acc = $ task_manager ; $ fun_extensions = [ | $ match ! extensions with | [ ] -> <: expr <>> } in a ; ; >> ] ] ; k_patt : [ [ l = patt -> l | " " ; ->... |
let gen_body2 = <: expr < spoc_gen_kernel $ n_body2 $ $ b_body $>> in |
let gen_args = parse_args ! args gen_body in |
let ret = incr arg_idx ; match ! return_type with | TUnknown -> <: expr < return_unknown ( ) , Dummy >> | TInt32 -> <: expr < return_int $ ExInt ( Loc . ghost , string_of_int ( ! arg_idx ) ) $ " " , Vector . int32 >> | TInt64 -> <: expr < return_int $ ExInt ( Loc . ghost , string_of_int ( ! arg_idx ) ) $ " " , Vector .... |
let full_typ = List . fold_left ( fun seed p -> match p with | ( PaId ( _ , i ) ) -> let value = ( Hashtbl . find ! current_args ( string_of_ident i ) ) in TApp ( value . var_type , seed ) | PaTyc ( _ , p , t ) -> TApp ( ktyp_of_typ t , seed ) | _ -> assert false ) ! return_type ( List . rev ! args ) in |
let funv = { nb_args = 0 ; cuda_val " " ; = opencl_val " " ; = typ = full_typ } in |
let local = Hashtbl . fold ( fun key ( funv , stri , _ ) init -> <: str_item < <: str_item <>> in |
let task_manager = ( if Fastflow . fastflow then Fastflow . print_task ! args ( gen_ano_f _loc ) _loc else <: expr < Obj . magic None ) >> in |
let a = <: expr < let open Kirc in let local_function = { fun_name " " ; = ml_fun = $ gen_args ; $ fun_ret = $ ret ; $ fastflow_acc = $ task_manager ; $ fun_extensions = [ | $ match ! extensions with | t [ ] :: -> t | _ -> exSem_of_list ! extensions ] ; $| } |
let module Local_funs = struct $ local $ end $ a $>> in { t = full_typ ; e = Fun ( _loc , res , full_typ , funv , ! lifted ) ; loc = _loc } ] [ " " ; $$ e = expr ; " ; ; " ; " " $$ -> { t = TUnknown ; e = Nat ( _loc , e ) ; loc = _loc } ] [ " if " ; cond = SELF ; " then " ; cons1 = SELF ; " else " ; cons2 = SELF -> { t... |
type customtypes = | KRecord of ctyp list * ident list * bool list | KSum of ( string * ctyp option ) list |
type memspace = | Local | Global | Shared | Any |
type ktyp = | TUnknown | TUnit | TInt32 | TInt64 | TFloat32 | TFloat64 | TBool | TAny | TVec of ktyp | TArr of ( ktyp * memspace ) | TApp of ktyp * ktyp | Custom of customtypes * string |
let rec ktyp_to_string = function | TUnit -> " unit " | TInt32 -> " int32 " | TInt64 -> " int64 " | TFloat32 -> " float32 " | TFloat64 -> " float64 " | TUnknown -> " unknown " | TAny -> " any " | TBool -> " bool " | TVec k -> ( ktyp_to_string k ) " ^ vector " | TArr ( k , m ) -> ( ktyp_to_string k ) " ^ array " | TApp ... |
let ex32 = let _loc = Loc . ghost in <: expr < ExFloat32 >> |
let ex64 = let _loc = Loc . ghost in <: expr < ExFloat64 >> |
let extensions = ref [ ex32 ] |
type var = { n : int ; mutable var_type : ktyp ; mutable is_mutable : bool ; mutable read_only : bool ; mutable write_only : bool ; mutable is_global : bool ; } |
let new_kernel = ref false |
type cfun = { nb_args : int ; cuda_val : string ; opencl_val : string ; typ : ktyp } |
type k_expr = | Open of Loc . t * ident * kexpr | App of Loc . t * kexpr * kexpr list | Acc of Loc . t * kexpr * kexpr | VecSet of Loc . t * kexpr * kexpr | VecGet of Loc . t * kexpr * kexpr | ArrSet of Loc . t * kexpr * kexpr | ArrGet of Loc . t * kexpr * kexpr | Seq of Loc . t * kexpr * kexpr | Fun of Loc . t * expr ... |
let rec is_unknown t = let rec app_return_type = function | TApp ( _ , ( TApp ( a , b ) ) ) -> app_return_type b | TApp ( _ , b ) -> is_unknown b | a -> is_unknown a in match t with | TUnknown | TVec TUnknown | TArr ( TUnknown , _ ) | TVec TAny -> true | TApp ( a , b ) -> app_return_type b | _ -> false |
let update_type value t = match t , value . t with | TUnknown , t -> ( ) | _ , TUnknown -> ( value . t <- t ; retype := true ) | TVec TUnknown , TVec _ -> ( ) | TArr ( TUnknown , _ ) , TArr _ -> ( ) | TVec t , TVec TUnknown -> ( value . t <- t ; retype := true ) | TArr ( t , _ ) , TArr ( TUnknown , _ ) -> ( value . t <... |
let rec string_of_ident i = let aux = function | <: ident < $ lid : s $ >> -> s | <: ident < $ uid : s $ >> -> s | <: ident < $ i1 . $$ i2 $ >> -> " " ^ ( string_of_ident i1 ) ^ " . " ^ ( string_of_ident i2 ) | <: ident < $ i1 ( $$ i2 ) $ >> -> " " ^ ( string_of_ident i1 ) ^ " " ^ ( string_of_ident i2 ) | _ -> assert f... |
let k_expr_to_string = function | App ( _ , { t = _ ; e = Id ( l , s ) ; loc = _ } , _ ) -> ( " App " ( ^ string_of_ident s ) ) | App _ -> " App " | Acc _ -> " Acc " | VecSet _ -> " VecSet " | VecGet _ -> " VecGet " | ArrSet _ -> " ArrSet " | ArrGet _ -> " ArrGet " | Seq _ -> " Seq " | Bind _ -> " Bind " | Fun _ -> " F... |
let expr_of_patt p = match p with | PaId ( l , i ) -> ExId ( l , i ) | _ -> raise ArgumentError |
type spoc_module = { mod_name : string ; mod_constants : ( ktyp * string * string * string ) list ; mod_functions : ( ktyp * string * int * string * string ) list ; mod_modules : ( string , spoc_module ) Hashtbl . t } |
let return_type = ref TUnknown |
let arg_idx = ref 0 |
let args ( ) = let ( tbl : ( string , var ) Hashtbl . t ) = Hashtbl . create 10 in tbl |
type recrd_field = { id : int ; name : string ; field : string ; mutable ctyps : string list ; } |
type cstr = { id : int ; name : string ; mutable nb_args : int ; mutable ctyp : string ; typ : customtypes } |
type localfun = cfun * str_item * string list |
let current_args = ref ( args ( ) ) |
let intrinsics_fun = ref ( ( Hashtbl . create 100 ) ( : string , cfun ) Hashtbl . t ) |
let global_fun = ref ( ( Hashtbl . create 10 ) ( : string , cfun ) Hashtbl . t ) |
let local_fun : ( ( ( string , localfun ) Hashtbl . t ) ref ) = ref ( Hashtbl . create 10 ) |
let intrinsics_const = ref ( ( Hashtbl . create 100 ) ( : string , cfun ) Hashtbl . t ) |
let constructors = ref ( ( Hashtbl . create 10 ) ( : string , cstr ) Hashtbl . t ) |
let rec_fields = ref ( ( Hashtbl . create 10 ) ( : string , recrd_field ) Hashtbl . t ) |
let custom_types ( ( : string , customtypes ) Hashtbl . t ) = Hashtbl . create 10 |
let ( arg_list : Camlp4 . PreCast . Syntax . Ast . expr list ref ) = ref [ ] |
let n_lifted_vals = ref 0 |
let rec ktyp_of_typ = function | <: ctyp < unit >> -> TUnit | <: ctyp < int >> | <: ctyp < int32 >> -> TInt32 | <: ctyp < int64 >> -> TInt64 | <: ctyp < float >> | <: ctyp < float32 >> -> TFloat32 | <: ctyp < float64 >> -> TFloat64 | <: ctyp < $ x $ vector >> -> TVec ( ktyp_of_typ x ) | <: ctyp < $ x $ array >> -> TArr... |
let new_arg_of_patt p = match p with | <: patt < $ lid : x $ >> -> let i = ! arg_idx in incr arg_idx ; Hashtbl . add ! current_args x { n = i ; var_type = TUnknown ; is_mutable = false ; read_only = false ; write_only = false ; is_global = false ; } ; | <: patt < ( $ lid : x $ : $ t ) $ >> -> let i = ! arg_idx in incr ... |
let std = { mod_name = " Std " ; mod_constants = [ ( TInt32 , " thread_idx_x " , " threadIdx . x " , " ( get_local_id ( 0 ) ) " ) ; ( TInt32 , " thread_idx_y " , " threadIdx . y " , " ( get_local_id ( 1 ) ) " ) ; ( TInt32 , " thread_idx_z " , " threadIdx . z " , " ( get_local_id ( 2 ) ) " ) ; ( TInt32 , " block_idx_x "... |
let vector { = mod_name = " Vector " ; mod_constants = [ ] ; mod_functions = [ ( TApp ( TVec TAny , TInt32 ) , " length " , 1 , " SAREK_VEC_LENGTH " , " SAREK_VEC_LENGTH " ) ; ] ; mod_modules = Hashtbl . create 0 } |
let mathf32 = { mod_name = " Float32 " ; mod_constants = [ ( TFloat32 , " zero " , " 0 . f " , " 0 . f " ) ; ( TFloat32 , " one " , " 1 . f " , " 1 . f " ) ; ] ; mod_functions = [ ( TApp ( ( TApp ( TFloat32 , TFloat32 ) ) , TFloat32 ) , " add " , 2 , " spoc_fadd " , " spoc_fadd " ) ; ( TApp ( ( TApp ( TFloat32 , TFloat... |
let mathf64 = { mod_name = " Float64 " ; mod_constants = [ ( TFloat64 , " zero " , " 0 . " , " 0 . " ) ; ( TFloat64 , " one " , " 1 . " , " 1 . " ) ; ] ; mod_functions = [ ( TApp ( ( TApp ( TFloat64 , TFloat64 ) ) , TFloat64 ) , " add " , 2 , " spoc_dadd " , " spoc_dadd " ) ; ( TApp ( ( TApp ( TFloat64 , TFloat64 ) ) ,... |
let math = { mod_name = " Math " ; mod_constants = [ ] ; mod_functions = [ ( TApp ( ( TApp ( TInt32 , TInt32 ) ) , TInt32 ) , " pow " , 2 , " spoc_powint " , " spoc_powint " ) ; ( TApp ( ( TApp ( TInt32 , TInt32 ) ) , TInt32 ) , " logical_and " , 2 , " logical_and " , " logical_and " ) ; ( TApp ( ( TApp ( TInt32 , TInt... |
let modules = let m = Hashtbl . create 10 in Hashtbl . add m std . mod_name std ; Hashtbl . add m vector . mod_name vector ; Hashtbl . add m math . mod_name math ; m |
let open_module m_ident _loc = my_eprintf ( Printf . sprintf " !! opening module % s \ n " %! m_ident ) ; ( match m_ident with | " Float64 " -> if not ( List . mem ex64 ! extensions ) then ( extensions := ex64 :: ! extensions ; Printf . eprintf " % s \ n " %! ( " \ 027 [ 32m Warning \ 027 [ 00m : kernel uses " ^ " \ 02... |
let ctype_of_sarek_type = function | " int32 " -> " int " | " int64 " -> " long " | " int " -> " int " | " float " | " float32 " -> " float " | " float64 " -> " double " | a -> " struct " ^ a " ^ _sarek " |
let mltype_of_sarek_type = function | " int32 " -> " int " | " int64 " -> " int " | " int " -> " int " | " float32 " -> " float " | " float64 " -> " float " | a -> a |
let rec string_of_ctyp = function | Ast . TyArr ( _loc , t1 , t2 ) -> ( string_of_ctyp t1 ) ^ | ( Ast . TyId ( _ , Ast . IdLid ( _ , s ) ) ) -> s | ( Ast . TyId ( _ , Ast . IdUid ( _ , s ) ) ) -> s | Ast . TyApp ( _ , t1 , t2 ) -> ( string_of_ctyp t1 ) ^ | TyCol ( l , t1 , t2 ) -> string_of_ctyp t2 | _ -> failwith " er... |
let sarek_types_tbl = Hashtbl . create 10 |
let get_sarek_name t = match t with | " int " | " int32 " -> " int32_t " | " int64 " -> " long " | " float " | " float32 " -> " float " | " float64 " -> " double " | _ -> try Hashtbl . find sarek_types_tbl t with | _ -> my_eprintf t ; assert false | Constr ( s , _ ) -> let cstr = Hashtbl . find ! constructors s in cstr... |
let createReportingDescriptor categoryInformation : ReportingDescriptor . t = { ruleId = categoryInformation . ruleId ; ruleName = categoryInformation . name ; helpUri = categoryInformation . helpUri ; help = { text = categoryInformation . helpText } ; shortDescription = { text = categoryInformation . shortDescription ... |
let transformToReportingDescriptor ( id : String . t ) = createReportingDescriptor ( getRuleInformation id ) |
let goblintTool : Tool . t = { driver = { name = " Goblint " ; fullName = " Goblint static analyser " ; informationUri = " https :// goblint . in . tum . de / home " ; organization = " TUM - i2 and UTartu - SWS " ; version = Version . goblint ; rules = List . map transformToReportingDescriptor ( List . map ( fun rule -... |
let getCategoryInformationID ( tags : Messages . Tags . t ) = let getCWE ( tag : Messages . Tag . t ) = match tag with | CWE cwe -> Some cwe ; | Category cat -> None ; in match List . filter_map getCWE tags with | cwe :: _ -> string_of_int cwe ; | [ ] -> match tags with | [ ] -> " " | x :: xs -> match x with | Category... |
let location_of_cil_location ( { file ; line ; column ; endLine ; endColumn ; _ } : Cil . location ) : Location . t = { physicalLocation = { artifactLocation = { uri = file } ; region = { startLine = line ; startColumn = if column >= 0 then Some column else None ; endLine ; endColumn = if endColumn >= 0 then Some endCo... |
let result_of_message ( message : Messages . Message . t ) : Result . t list = let ruleId = ( getRuleInformation ( getCategoryInformationID message . tags ) ) . ruleId in let ( kind , level ) = match message . severity with | Error -> ( " fail " , " error " ) | Warning -> ( " fail " , " warning " ) | Info -> ( " inform... |
let files_of_message ( message : Messages . Message . t ) : string list = let piece_file ( piece : Messages . Piece . t ) = match piece . loc with | Some loc -> Some loc . file | None -> None in match message . multipiece with | Single piece -> Option . map_default List . singleton [ ] ( piece_file piece ) | Group { pi... |
let artifacts_of_messages ( messages : Messages . Message . t list ) : Artifact . t list = messages |> List . enum |> Enum . map files_of_message |> Enum . map List . enum |> Enum . flatten |> Enum . uniq |> Enum . map ( fun file -> { Artifact . location = { uri = file } ; } ) |> List . of_enum |
let to_yojson messages = SarifLog . to_yojson { version = " 2 . 1 . 0 " ; schema = " https :// schemastore . azurewebsites . net / schemas / json / sarif - 2 . 1 . 0 - rtm . 5 . json " ; runs = [ { invocations = [ { commandLine = Goblintutil . command_line ; executionSuccessful = true ; } ] ; artifacts = artifacts_of_m... |
type categoryInformation = { name : string ; ruleId : string ; helpText : string ; shortDescription : string ; helpUri : string ; longDescription : string ; } |
let unknownRule = { name " = Unknown " ; ruleId " = GO000 " ; helpText " " ; = shortDescription " " ; = helpUri " = https :// goblint . in . tum . de / home " ; longDescription " " ; = } |
let rules = [ { name " = Assert " ; ruleId " = GO0001 " ; helpText " = Assert Error " ; shortDescription " = This is an internal Goblint Category " ; helpUri " = https :// goblint . in . tum . de / home " ; longDescription " " ; = } ; { name " = Analyzer " ; ruleId " = GO0002 " ; helpText " = Analyzer Error " ; shortDe... |
let getRuleInformation ( searchName : string ) = match List . find_opt ( fun rule -> rule . name = searchName ) rules with | None -> unknownRule ; | Some rule -> rule |
module Invocation = struct type t = { commandLine : string ; executionSuccessful : bool ; } [ @@ deriving to_yojson ] end |
module Region = struct type t = { startLine : int ; startColumn : int option [ @ default None ] ; endLine : int ; endColumn : int option [ @ default None ] ; } [ @@ deriving to_yojson , eq ] end |
module ArtifactLocation = struct type t = { uri : string ; } [ @@ deriving to_yojson , eq ] end |
module PhysicalLocation = struct type t = { artifactLocation : ArtifactLocation . t ; region : Region . t ; } [ @@ deriving to_yojson , eq ] end |
module Artifact = struct type t = { location : ArtifactLocation . t ; } [ @@ deriving to_yojson ] end |
module Location = struct type t = { physicalLocation : PhysicalLocation . t ; } [ @@ deriving to_yojson , eq ] end |
module Message = struct type t = { text : string ; } [ @@ deriving to_yojson ] end |
module ReportingDescriptor = struct type t = { ruleId : string ; [ @ key " id " ] ruleName : string ; [ @ key " name " ] helpUri : string ; help : Message . t ; shortDescription : Message . t ; fullDescription : Message . t ; } [ @@ deriving to_yojson ] end |
module ToolComponent = struct type t = { name : string ; fullName : string ; informationUri : string ; organization : string ; version : string ; rules : ReportingDescriptor . t list ; } [ @@ deriving to_yojson ] end |
module Tool = struct type t = { driver : ToolComponent . t ; } [ @@ deriving to_yojson ] end |
module Result = struct type t = { ruleId : string ; kind : string ; level : string ; message : Message . t ; locations : Location . t list [ @ default [ ] ] ; relatedLocations : Location . t list [ @ default [ ] ] ; } [ @@ deriving to_yojson ] end |
module Run = struct type t = { tool : Tool . t ; defaultSourceLanguage : string ; invocations : Invocation . t list ; artifacts : Artifact . t list ; results : ( Result . t [ @ to_yojson result_to_yojson ] ) list ; } [ @@ deriving to_yojson ] end |
module SarifLog = struct type t = { version : string ; schema : string [ @ key " $ schema " ] ; runs : Run . t list ; } [ @@ deriving to_yojson ] end |
let unsatured_arb = of_option_arb @@ QCheck . map of_int_opt QCheck . int |
let t_arb : may_saturate t QCheck . arbitrary = QCheck . frequency [ ( 1 , QCheck . always saturated ) ; ( 4 , unsatured_arb ) ] |
let test_add_commutes = QCheck . Test . make ~ name " : t1 + t2 = t2 + t1 " ( QCheck . pair t_arb t_arb ) ( fun ( t1 , t2 ) -> let t1_plus_t2 = add t1 t2 in let t2_plus_t1 = add t2 t1 in qcheck_eq ~ pp t1_plus_t2 t2_plus_t1 ) |
let test_mul_commutes = QCheck . Test . make ~ name " : t1 * t2 = t2 * t1 " ( QCheck . pair t_arb t_arb ) ( fun ( t1 , t2 ) -> let t1_times_t2 = mul t1 t2 in let t2_times_t1 = mul t2 t1 in qcheck_eq ~ pp t1_times_t2 t2_times_t1 ) |
let test_add_zero = QCheck . Test . make ~ name " : t + 0 = t " t_arb ( fun t -> let t_plus_zero = add t zero in qcheck_eq ' ~ pp ~ expected : t ~ actual : t_plus_zero ( ) ) |
let test_add_neq = QCheck . Test . make ~ name " : t1 + t2 >= t1 " ( QCheck . pair t_arb t_arb ) ( fun ( t1 , t2 ) -> let t1_plus_t2 = add t1 t2 in t1_plus_t2 >= t1 ) |
let test_mul_one = let one = safe_int 1 in QCheck . Test . make ~ name " : t * 1 = t " t_arb ( fun t -> let t_times_one = mul t one in qcheck_eq ' ~ pp ~ expected : t ~ actual : t_times_one ( ) ) |
let test_mul_zero = QCheck . Test . make ~ name " : t * 0 = 0 " t_arb ( fun t -> let t_times_zero = mul t zero in qcheck_eq ' ~ pp ~ expected : zero ~ actual : t_times_zero ( ) ) |
let test_sub_zero = QCheck . Test . make ~ name " : t - 0 = t " t_arb ( fun t -> let t_sub_zero = sub t zero in qcheck_eq ' ~ pp ~ expected : t ~ actual : t_sub_zero ( ) ) |
let test_sub_itself = QCheck . Test . make ~ name " : t - t = 0 " t_arb ( fun t -> let t_sub_t = sub t t in qcheck_eq ' ~ pp ~ expected : zero ~ actual : t_sub_t ( ) ) |
let test_sub_neq = QCheck . Test . make ~ name " : t1 - t2 <= t1 " ( QCheck . pair t_arb t_arb ) ( fun ( t1 , t2 ) -> let t1_minus_t2 = sub t1 t2 in t1_minus_t2 <= t1 ) |
let test_add_sub = QCheck . Test . make ~ name " ( : t1 + t2 ) - t2 <= t1 " ( QCheck . pair t_arb t_arb ) ( fun ( t1 , t2 ) -> let lhs = sub ( add t1 t2 ) t2 in lhs <= t1 ) |
let test_sub_add = QCheck . Test . make ~ name " ( : t1 - t2 ) + t2 >= t1 " ( QCheck . pair t_arb t_arb ) ( fun ( t1 , t2 ) -> let lhs = add ( sub t1 t2 ) t2 in lhs >= t1 ) |
let test_leq_saturated = QCheck . Test . make ~ name " : t <= saturated " t_arb ( fun t -> saturated >= t ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.