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
| MetadataVal of metadata_value
type instr =
type instruction =
| Ret of (typ * operand) option
| UncondBranch of variable
| CondBranch of operand * variable * variable
@ -57,13 +57,13 @@ type instr =
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 prog = Prog of func_def list * metadata_map
type program = Program of function_def list * metadata_map
let string_of_variable : variable -> string = function
| Global var_id | Local var_id ->

@ -48,9 +48,9 @@ let () = try
let source_file = DB.abs_source_file_from_path filename in
let () = init_global_state source_file 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 (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
with
| UsageError msg -> print_string ("Usage error: " ^ msg ^ "\n")

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

@ -55,12 +55,12 @@ let location_of_annotation_option (metadata : LAst.metadata_map)
end
(* 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)
: 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 ->
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
begin match instr with
| Ret None -> (sil_instrs, locals)
@ -90,9 +90,9 @@ let rec trans_annotated_instrs
end
(* Update CFG and call graph with new function definition *)
let trans_func_def (cfg : Cfg.cfg) (cg: Cg.t) (metadata : LAst.metadata_map)
: LAst.func_def -> unit = function
FuncDef (func_name, ret_tp_opt, params, annotated_instrs) ->
let trans_function_def (cfg : Cfg.cfg) (cg: Cg.t) (metadata : LAst.metadata_map)
: LAst.function_def -> unit = function
FunctionDef (func_name, ret_tp_opt, params, annotated_instrs) ->
let (proc_attrs : Sil.proc_attributes) =
let open Sil in
{ 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 *)
| [] -> 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
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
Cfg.Procdesc.set_start_node procdesc start_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;
Cg.add_node cg procname
let trans_prog : LAst.prog -> Cfg.cfg * Cg.t * Sil.tenv = function
Prog (func_defs, metadata) ->
let trans_program : LAst.program -> Cfg.cfg * Cg.t * Sil.tenv = function
Program (func_defs, metadata) ->
let cfg = Cfg.Node.create_cfg () in
let cg = Cg.create () 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)

Loading…
Cancel
Save