[erl-frontend] Started ErlangTranslator

Summary:
Rebar3.capture now calls into ErlangTranslator to obtain Sil. For now,
ErlangTranslator does nothing interesting.

Reviewed By: skcho

Differential Revision: D28261799

fbshipit-source-id: 0603db671
master
Radu Grigore 4 years ago committed by Facebook GitHub Bot
parent 765d45c2fd
commit e2cc723074

@ -0,0 +1,26 @@
(*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
open! IStd
module Ast = ErlangAst
let to_source_and_cfg module_ =
let source =
let extract_path = function
| {Ast.line= _; simple_form= File {path}} ->
Some path
| _ ->
None
in
match List.find_map ~f:extract_path module_ with
| None ->
SourceFile.invalid __FILE__
| Some path ->
SourceFile.create path
in
let cfg = (* TODO *) Cfg.create () in
(source, cfg)

@ -0,0 +1,10 @@
(*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
open! IStd
val to_source_and_cfg : ErlangAst.module_ -> SourceFile.t * Cfg.t

@ -16,9 +16,14 @@ let run_rebar result_dir args =
let parse_and_store result_dir =
let process json =
let _ast = ErlangJsonParser.to_module json in
(* TODO: Translate to Sil, load source, call [SourceFiles.add]. *)
()
match ErlangJsonParser.to_module json with
| None ->
false
| Some ast ->
let source_file, cfg = ErlangTranslator.to_source_and_cfg ast in
let tenv = (* TODO: types *) Tenv.Global in
SourceFiles.add source_file cfg tenv None ;
true
in
let log error = L.progress "E: %s@." error in
let read_one_ast json_file =
@ -26,7 +31,7 @@ let parse_and_store result_dir =
L.progress "P: parsing %s@." json_file ;
match Utils.read_safe_json_file json_file with
| Ok json ->
process json
if not (process json) then L.debug Capture Verbose "Failed to parse %s@." json_file
| Error error ->
log error )
in

Loading…
Cancel
Save