Renamed some types and variables for consistency.

master
Rohan Jacob-Rao 10 years ago
parent 204c585abf
commit e127255f60

@ -46,7 +46,7 @@ and metadata_component =
| TypOperand of typ option * operand | TypOperand of typ option * operand
| MetadataVal of metadata_value | MetadataVal of metadata_value
type instr = type instruction =
| Ret of (typ * operand) option | Ret of (typ * operand) option
| UncondBranch of variable | UncondBranch of variable
| CondBranch of operand * variable * variable | CondBranch of operand * variable * variable
@ -57,13 +57,13 @@ type instr =
type annotation = Annotation of int type annotation = Annotation of int
type annotated_instr = instr * annotation option type annotated_instruction = instruction * annotation option
type func_def = FuncDef of variable * typ option * (typ * string) list * annotated_instr list type function_def = FunctionDef of variable * typ option * (typ * string) list * annotated_instruction list
type metadata_map = metadata_component list MetadataMap.t type metadata_map = metadata_component list MetadataMap.t
type prog = Prog of func_def list * metadata_map type program = Program of function_def list * metadata_map
let string_of_variable : variable -> string = function let string_of_variable : variable -> string = function
| Global var_id | Local var_id -> | Global var_id | Local var_id ->

@ -48,9 +48,9 @@ let () = try
let source_file = DB.abs_source_file_from_path filename in let source_file = DB.abs_source_file_from_path filename in
let () = init_global_state source_file in let () = init_global_state source_file in
let lexbuf = Lexing.from_channel (open_in filename) in let lexbuf = Lexing.from_channel (open_in filename) in
let prog = LParser.prog LLexer.token lexbuf in let prog = LParser.program LLexer.token lexbuf in
(* let pretty = LPretty.pretty_prog prog in *) (* let pretty = LPretty.pretty_prog prog in *)
let (cfg, cg, tenv) = LTrans.trans_prog prog in let (cfg, cg, tenv) = LTrans.trans_program prog in
store_icfg tenv cg cfg source_file; store_tenv tenv store_icfg tenv cg cfg source_file; store_tenv tenv
with with
| UsageError msg -> print_string ("Usage error: " ^ msg ^ "\n") | UsageError msg -> print_string ("Usage error: " ^ msg ^ "\n")

@ -146,20 +146,20 @@
%token EOF %token EOF
%start prog %start program
%type <LAst.prog> prog %type <LAst.program> program
%type <LAst.func_def> func_def %type <LAst.function_def> function_def
%type <LAst.typ option> ret_typ %type <LAst.typ option> ret_typ
%type <LAst.typ> typ %type <LAst.typ> typ
%% %%
prog: program:
| targets defs = func_def* opt_mappings = metadata_def* EOF { | targets func_defs = function_def* opt_mappings = metadata_def* EOF {
let mappings = list_flatten_options opt_mappings in let mappings = list_flatten_options opt_mappings in
let add_mapping map (metadata_id, components) = MetadataMap.add metadata_id components map in let add_mapping map (metadata_id, components) = MetadataMap.add metadata_id components map in
let metadata_map = list_fold_left add_mapping MetadataMap.empty mappings in let metadata_map = list_fold_left add_mapping MetadataMap.empty mappings in
Prog (defs, metadata_map) } Program (func_defs, metadata_map) }
targets: targets:
| { (None, None) } | { (None, None) }
@ -193,10 +193,10 @@ metadata_value:
| str = METADATA_STRING { MetadataString str } | str = METADATA_STRING { MetadataString str }
| components = metadata_node { MetadataNode components } | components = metadata_node { MetadataNode components }
func_def: function_def:
| DEFINE ret_tp = ret_typ name = variable LPAREN | DEFINE ret_tp = ret_typ name = variable LPAREN
params = separated_list(COMMA, pair(first_class_typ, IDENT)) RPAREN attribute_group* params = separated_list(COMMA, pair(first_class_typ, IDENT)) RPAREN attribute_group*
annotated_instrs = block { FuncDef (name, ret_tp, params, annotated_instrs) } annotated_instrs = block { FunctionDef (name, ret_tp, params, annotated_instrs) }
attribute_group: attribute_group:
| i = ATTRIBUTE_GROUP { i } | i = ATTRIBUTE_GROUP { i }
@ -241,16 +241,16 @@ ptr_typ:
| tp = typ STAR { tp } | tp = typ STAR { tp }
block: block:
| LBRACE annotated_instrs = annotated_instr* RBRACE { list_flatten_options annotated_instrs } | LBRACE annotated_instrs = annotated_instruction* RBRACE { list_flatten_options annotated_instrs }
annotated_instr: annotated_instruction:
| instruction = real_instr anno = annotation? { Some (instruction, anno) } | instr = real_instruction anno = annotation? { Some (instr, anno) }
| debug_instr annotation? { None } | debug_instruction annotation? { None }
annotation: annotation:
| COMMA DEBUG_ANNOTATION i = NUMBERED_METADATA { Annotation i } | COMMA DEBUG_ANNOTATION i = NUMBERED_METADATA { Annotation i }
real_instr: real_instruction:
(* terminator instructions *) (* terminator instructions *)
| RET tp = typ op = operand { Ret (Some (tp, op)) } | RET tp = typ op = operand { Ret (Some (tp, op)) }
| RET VOID { Ret None } | RET VOID { Ret None }
@ -263,11 +263,11 @@ real_instr:
(* don't yet know why val_tp and ptr_tp would be different *) (* don't yet know why val_tp and ptr_tp would be different *)
| variable EQUALS binop { Binop } | variable EQUALS binop { Binop }
debug_instr: debug_instruction:
| CALL VOID DBG_DECLARE LPAREN separated_list(COMMA, metadata_component) RPAREN { () } | CALL VOID DBG_DECLARE LPAREN separated_list(COMMA, metadata_component) RPAREN { () }
align: align:
| COMMA ALIGN sz = CONSTANT_INT { sz } | COMMA ALIGN width = CONSTANT_INT { width }
binop: binop:
| ADD arith_options binop_args { () } | ADD arith_options binop_args { () }

@ -55,12 +55,12 @@ let location_of_annotation_option (metadata : LAst.metadata_map)
end end
(* Generate list of SIL instructions and list of local variables *) (* Generate list of SIL instructions and list of local variables *)
let rec trans_annotated_instrs let rec trans_annotated_instructions
(cfg : Cfg.cfg) (procdesc : Cfg.Procdesc.t) (metadata : LAst.metadata_map) (cfg : Cfg.cfg) (procdesc : Cfg.Procdesc.t) (metadata : LAst.metadata_map)
: LAst.annotated_instr list -> Sil.instr list * (Mangled.t * Sil.typ) list = function : LAst.annotated_instruction list -> Sil.instr list * (Mangled.t * Sil.typ) list = function
| [] -> ([], []) | [] -> ([], [])
| (instr, anno) :: t -> | (instr, anno) :: t ->
let (sil_instrs, locals) = trans_annotated_instrs cfg procdesc metadata t in let (sil_instrs, locals) = trans_annotated_instructions cfg procdesc metadata t in
let location = location_of_annotation_option metadata anno in let location = location_of_annotation_option metadata anno in
begin match instr with begin match instr with
| Ret None -> (sil_instrs, locals) | Ret None -> (sil_instrs, locals)
@ -90,9 +90,9 @@ let rec trans_annotated_instrs
end end
(* Update CFG and call graph with new function definition *) (* Update CFG and call graph with new function definition *)
let trans_func_def (cfg : Cfg.cfg) (cg: Cg.t) (metadata : LAst.metadata_map) let trans_function_def (cfg : Cfg.cfg) (cg: Cg.t) (metadata : LAst.metadata_map)
: LAst.func_def -> unit = function : LAst.function_def -> unit = function
FuncDef (func_name, ret_tp_opt, params, annotated_instrs) -> FunctionDef (func_name, ret_tp_opt, params, annotated_instrs) ->
let (proc_attrs : Sil.proc_attributes) = let (proc_attrs : Sil.proc_attributes) =
let open Sil in let open Sil in
{ access = Sil.Default; { access = Sil.Default;
@ -133,7 +133,7 @@ let trans_func_def (cfg : Cfg.cfg) (cg: Cg.t) (metadata : LAst.metadata_map)
(* link all nodes in a chain for now *) (* link all nodes in a chain for now *)
| [] -> Cfg.Node.set_succs_exn start_node [exit_node] [exit_node] | [] -> Cfg.Node.set_succs_exn start_node [exit_node] [exit_node]
| nd :: nds -> Cfg.Node.set_succs_exn start_node [nd] [exit_node]; link_nodes nd nds in | nd :: nds -> Cfg.Node.set_succs_exn start_node [nd] [exit_node]; link_nodes nd nds in
let (sil_instrs, locals) = trans_annotated_instrs cfg procdesc metadata annotated_instrs in let (sil_instrs, locals) = trans_annotated_instructions cfg procdesc metadata annotated_instrs in
let nodes = list_map (node_of_sil_instr cfg procdesc) sil_instrs in let nodes = list_map (node_of_sil_instr cfg procdesc) sil_instrs in
Cfg.Procdesc.set_start_node procdesc start_node; Cfg.Procdesc.set_start_node procdesc start_node;
Cfg.Procdesc.set_exit_node procdesc exit_node; Cfg.Procdesc.set_exit_node procdesc exit_node;
@ -141,10 +141,10 @@ let trans_func_def (cfg : Cfg.cfg) (cg: Cg.t) (metadata : LAst.metadata_map)
Cfg.Node.add_locals_ret_declaration start_node locals; Cfg.Node.add_locals_ret_declaration start_node locals;
Cg.add_node cg procname Cg.add_node cg procname
let trans_prog : LAst.prog -> Cfg.cfg * Cg.t * Sil.tenv = function let trans_program : LAst.program -> Cfg.cfg * Cg.t * Sil.tenv = function
Prog (func_defs, metadata) -> Program (func_defs, metadata) ->
let cfg = Cfg.Node.create_cfg () in let cfg = Cfg.Node.create_cfg () in
let cg = Cg.create () in let cg = Cg.create () in
let tenv = Sil.create_tenv () in let tenv = Sil.create_tenv () in
list_iter (trans_func_def cfg cg metadata) func_defs; list_iter (trans_function_def cfg cg metadata) func_defs;
(cfg, cg, tenv) (cfg, cg, tenv)

Loading…
Cancel
Save