Skip to content

Commit

Permalink
[swift] Llair to Textual: add proc descs to the Textual Modules
Browse files Browse the repository at this point in the history
Summary: We have most parts of the procdescs now, so we can add them to the modules.

Reviewed By: davidpichardie

Differential Revision: D69779021

fbshipit-source-id: 54d67bc1e2dff5d25d32df2d8da7ddf50f83057c
  • Loading branch information
dulmarod authored and facebook-github-bot committed Feb 19, 2025
1 parent 1dfc049 commit 00469da
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions infer/src/swift/Llair2Textual.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ let translate_llair_globals globals =
List.map ~f:to_textual_global globals


type partial_proc_desc =
{ params: Textual.VarName.t list
; locals: Textual.VarName.t list
; procdecl: Textual.ProcDecl.t
; start: Textual.NodeName.t
; nodes: Textual.Node.t list }

let to_qualified_proc_name ?loc func_name =
let func_name = FuncName.name func_name in
let loc = Option.map ~f:to_textual_loc loc in
Expand All @@ -62,7 +55,11 @@ let to_formals func =


let to_locals func =
let to_textual_local local = reg_to_var_name local in
let to_textual_local local =
let local_name = reg_to_var_name local in
let typ = reg_to_annot_typ local in
(local_name, typ)
in
let locals = Reg.Set.to_list func.Llair.locals in
List.map ~f:to_textual_local locals

Expand Down Expand Up @@ -166,7 +163,7 @@ let func_to_nodes func =

let translate_llair_functions functions =
let function_to_formal proc_descs (func_name, func) =
let formals, formals_types = to_formals func in
let formals_, formals_types = to_formals func in
let locals = to_locals func in
let qualified_name = to_qualified_proc_name func_name ~loc:func.Llair.loc in
let result_type = to_result_type func_name in
Expand All @@ -175,7 +172,13 @@ let translate_llair_functions functions =
{qualified_name; result_type; attributes= []; formals_types= Some formals_types}
in
let nodes = func_to_nodes func in
{params= formals; locals; procdecl; start= block_to_node_name func.Llair.entry; nodes}
Textual.ProcDesc.
{ params= formals_
; locals
; procdecl
; start= block_to_node_name func.Llair.entry
; nodes
; exit_loc= Unknown (* TODO: get this location *) }
:: proc_descs
in
let values = FuncName.Map.to_list functions in
Expand All @@ -186,14 +189,20 @@ let translate sourcefile (llair_program : Llair.Program.t) : Textual.Module.t =
let globals = translate_llair_globals llair_program.Llair.globals in
(* We'll build the procdesc partially until we have all the pieces required in Textual
and can add them to the list of declarations *)
let partial_procs = translate_llair_functions llair_program.Llair.functions in
let proc_decls = List.map ~f:(fun {procdecl} -> Textual.Module.Procdecl procdecl) partial_procs in
let proc_descs = translate_llair_functions llair_program.Llair.functions in
let proc_decls =
List.map ~f:(fun Textual.ProcDesc.{procdecl} -> Textual.Module.Procdecl procdecl) proc_descs
in
let proc_desc_declarations =
List.map ~f:(fun proc_desc -> Textual.Module.Proc proc_desc) proc_descs
in
let globals = List.map ~f:(fun global -> Textual.Module.Global global) globals in
let structs =
List.map
~f:(fun (_, struct_) -> Textual.Module.Struct struct_)
(Textual.TypeName.Map.bindings !Llair2TextualType.structMap)
in
let decls = List.append proc_decls globals in
let decls = List.append decls proc_desc_declarations in
let decls = List.append decls structs in
Textual.Module.{attrs= []; decls; sourcefile}

0 comments on commit 00469da

Please sign in to comment.