module Newspeak: sig .. end
Newspeak is a language designed for the purpose of static analysis.
It was designed with these features in mind:
- precise: its semantics is precisely defined,
(see Newspeak, Doubleplussimple Minilang for Goodthinkful Static
Analysis of C for a thorough and formal description. Available from
www.penjili.org)
- simple: its primitives are as few, as standard and as concise as
possible,
- minimal: no language primitive or fragment of primitive should be
expressible as a combination of other primitives,
- explicit: primitives are context-free, i.e. all semantic information
needed to execute it are readily available,
- analysis-friendly: annotations useless for execution are added to allow
a static analysis tool to perform correctness checks,
- architecture-independent: all architecture or compiler dependent features
(size of types, offsets of structure fields, order of executions, ...)
are made explicit byt the translation to Newspeak,
- expressive: it should be possible to translate most C programs into
Newspeak.
Newspeak can be seen as a kind of high-level assembly language with
annotations for analysis.
The type of Newspeak programs, types, statements and expressions are
described in this module.
Additionnally, some functions to create, manipulate, export and display
Newspeak programs are provided.
Types
module Nat: sig .. end
type t = file list * prog * size_t
type prog = globals * (fid, fundec) Hashtbl.t * specs
type globals = (string, gdecl) Hashtbl.t
type gdecl = typ * init_t
type fundec = ftyp * blk
type specs = assertion list
type assertion = spec_token list
type spec_token =
| |
SymbolToken of char |
| |
IdentToken of string |
| |
VarToken of string |
| |
CstToken of cte |
type stmtkind =
type stmt = stmtkind * location
type blk = stmt list
type lval =
type exp =
type cte =
| |
CInt of Nat.t |
| |
CFloat of (float * string) |
| |
Nil |
type unop =
type binop =
type fn =
type typ =
type field = offset * typ
type scalar_t =
type init_t =
type ftyp = typ list * typ option
type lbl = int
type vid = int
type fid = string
type file = string
type ikind = sign_t * size_t
type sign_t =
type size_t = int
type offset = int
type length = int
type bounds = Nat.t * Nat.t
type location = string * int * int
val zero : exp
val one : exp
val zero_f : exp
val unknown_loc : location
val dummy_loc : string -> location
val domain_of_typ : sign_t * size_t -> bounds
val belongs : Nat.t -> bounds -> bool
val contains : bounds -> bounds -> bool
val negate : exp -> exp
val exp_of_int : int -> exp
val simplify_gotos : blk -> blk
val normalize_loops : blk -> blk
val simplify : blk -> blk
val simplify_exp : exp -> exp
Display
val string_of_loc : location -> string
Raises Invalid_argument "Newspeak.string_of_loc: unknown location"
if the file name is unknown
val string_of_bounds : bounds -> string
string_of_bounds r returns the string representation of range r.
val string_of_cte : cte -> string
string_of_cte c returns the string representation of constant c.
val string_of_scalar : scalar_t -> string
val string_of_typ : typ -> string
val string_of_ftyp : ftyp -> string
val string_of_exp : exp -> string
val string_of_lval : lval -> string
val string_of_stmt : stmt -> string
val string_of_blk : blk -> string
string_of_block blk returns the string representation of block blk.
val dump : t -> unit
val dump_prog : prog -> unit
val dump_globals : globals -> unit
dump_globals glbdecls prints the global definitions glbdecls to
standard output.
val dump_fundec : string -> fundec -> unit
val string_of_binop : binop -> string
class visitor : object .. end
val visit_fun : visitor -> fid -> fundec -> unit
val visit_glb : visitor -> string -> gdecl -> unit
val visit : visitor -> prog -> unit
class builder : object .. end
val build : builder -> prog -> prog
val build_gdecl : builder -> gdecl -> gdecl
val write : string -> t -> unit
val read : string -> t
read name retrieves the list of file names, program and size of
pointers from a .npk file.
Raises Invalid_argument if the input file is not a valid .npk file, or its
newspeak version is not the same as this file's.
name : file name of the .npk file to read
val write_hdr : Pervasives.out_channel ->
string list * (string, gdecl) Hashtbl.t * specs *
size_t -> unit
val write_fun : Pervasives.out_channel -> fid -> fundec -> unit
val size_of_scalar : size_t -> scalar_t -> size_t
val size_of : size_t -> typ -> size_t
val bind_var : string -> typ -> blk -> stmtkind
bind_var x t blk encloses the block blk with the declaration of
variable x of type t and then binds all occurances of x as a global
variable in blk.
val build_call : fid -> ftyp -> exp list -> blk
build_call f ft args builds the call to function f of type ft with
arguments args.
Raises Invalid_argument "Newspeak.build_call: non scalar argument" if
some argument is not of scalar type
val build_main_call : size_t -> ftyp -> string list -> blk
build_main_call ptr_sz ft params returns a block
of newspeak code to call the main function with parameters params.
ptr_sz : the size of pointers
val create_cstr : string -> string -> string * gdecl
type alt_stmtkind =
type alt_blk = (alt_stmtkind * location) list
val convert_loops : blk -> alt_blk
val max_ikind : ikind -> ikind -> ikind
val collect_fid_addrof : prog -> fid list
returns the list of all function identifiers that are stored as function
pointers in the program.