[clang] Add process ast as a new capture action, separated from capture and linting

Summary: We should be able to run this processing ast steps without running linters or capture. This also adds a new module ProcessAST to do the processing, Capture.ml should not know anything else than calling the respective modules for capture, linting or processing.

Reviewed By: ngorogiannis

Differential Revision: D17501453

fbshipit-source-id: 30adba5b1
master
Dulma Churchill 5 years ago committed by Facebook Github Bot
parent d55f5c02d5
commit 667ce92864

@ -1552,6 +1552,10 @@ INTERNAL OPTIONS
--per-procedure-parallelism. If 0 is specified, each file is
divided into --jobs groups of procedures.
--no-process-clang-ast
Deactivates: process the ast to emit some info about the file (Not
available for Java) (Conversely: --process-clang-ast)
--procs-csv file
Write statistics for each procedure in CSV format to a file

@ -32,7 +32,7 @@ type stats_kind = Time of Mtime_clock.counter * Unix.process_times | Memory | Ti
type stats_type =
| ClangLinters of SourceFile.t
| ClangFrontend of SourceFile.t
| ClangFrontendLinters of SourceFile.t
| ClangProcessAST of SourceFile.t
| JavaFrontend of SourceFile.t
| TotalFrontend
| Backend of SourceFile.t
@ -43,7 +43,7 @@ type stats_type =
let source_file_of_stats_type = function
| ClangLinters source_file
| ClangFrontend source_file
| ClangFrontendLinters source_file
| ClangProcessAST source_file
| JavaFrontend source_file
| Backend source_file ->
Some source_file
@ -64,19 +64,9 @@ let relative_path_of_stats_type stats_type =
in
let dirname =
match stats_type with
| ClangLinters _ ->
| ClangLinters _ | ClangFrontend _ | ClangProcessAST _ | JavaFrontend _ | TotalFrontend ->
Config.frontend_stats_dir_name
| ClangFrontend _ ->
Config.frontend_stats_dir_name
| ClangFrontendLinters _ ->
Config.frontend_stats_dir_name
| JavaFrontend _ ->
Config.frontend_stats_dir_name
| TotalFrontend ->
Config.frontend_stats_dir_name
| Backend _ ->
Config.backend_stats_dir_name
| TotalBackend ->
| Backend _ | TotalBackend ->
Config.backend_stats_dir_name
| Reporting ->
Config.reporting_stats_dir_name
@ -91,8 +81,8 @@ let string_of_stats_type = function
"linters"
| ClangFrontend _ ->
"clang_frontend"
| ClangFrontendLinters _ ->
"clang_frontend_and_linters"
| ClangProcessAST _ ->
"clang_process_ast"
| JavaFrontend _ ->
"java_frontend"
| TotalFrontend ->

@ -16,7 +16,7 @@ type stats_kind = Time of Mtime_clock.counter * Unix.process_times | Memory | Ti
type stats_type =
| ClangLinters of SourceFile.t
| ClangFrontend of SourceFile.t
| ClangFrontendLinters of SourceFile.t
| ClangProcessAST of SourceFile.t
| JavaFrontend of SourceFile.t
| TotalFrontend
| Backend of SourceFile.t

@ -48,10 +48,6 @@ let equal_analyzer = [%compare.equal: analyzer]
let string_to_analyzer = [("checkers", Checkers); ("linters", Linters)]
let clang_frontend_action_symbols =
[("lint", `Lint); ("capture", `Capture); ("lint_and_capture", `Lint_and_capture)]
let ml_bucket_symbols =
[ ("all", `MLeak_all)
; ("cf", `MLeak_cf)
@ -1027,13 +1023,6 @@ and clang_blacklisted_flags_with_arg =
and clang_compilation_dbs = ref []
and clang_frontend_action =
CLOpt.mk_symbol_opt ~long:"" ~deprecated:["-clang-frontend-action"]
~in_help:InferCommand.[(Capture, manual_clang); (Run, manual_clang)]
(* doc only shows up in deprecation warnings *)
"use --capture and --linters instead" ~symbols:clang_frontend_action_symbols
and clang_ignore_regex =
CLOpt.mk_string_opt ~long:"clang-ignore-regex" ~meta:"dir_OCaml_regex"
"The files in this regex will be ignored in the compilation process and an empty file will be \
@ -1914,6 +1903,12 @@ and procedures_source_file =
output of $(b,--procedures)"
and process_clang_ast =
CLOpt.mk_bool ~long:"process-clang-ast"
~default:true (* To be made false after this is deployed *)
"process the ast to emit some info about the file (Not available for Java)"
and procs_csv =
CLOpt.mk_path_opt ~deprecated:["procs"] ~long:"procs-csv" ~meta:"file"
"Write statistics for each procedure in CSV format to a file"
@ -2767,16 +2762,7 @@ and bufferoverrun = !bufferoverrun
and call_graph_schedule = !call_graph_schedule
and capture =
(* take `--clang-frontend-action` as the source of truth as long as that option exists *)
match !clang_frontend_action with
| Some (`Capture | `Lint_and_capture) ->
true
| Some `Lint ->
false
| None ->
!capture
and capture = !capture
and capture_blacklist = !capture_blacklist
@ -2949,16 +2935,7 @@ and join_cond = !join_cond
and linter = !linter
and linters =
(* take `--clang-frontend-action` as the source of truth as long as that option exists *)
match !clang_frontend_action with
| Some (`Lint | `Lint_and_capture) ->
true
| Some `Capture ->
false
| None ->
!linters
and linters = !linters
and linters_def_file = !linters_def_file
@ -3064,6 +3041,8 @@ and[@warning "-32"] procedures_per_process = !procedures_per_process
and procedures_source_file = !procedures_source_file
and process_clang_ast = !process_clang_ast
and progress_bar =
if !progress_bar then
match !progress_bar_style with
@ -3286,8 +3265,10 @@ and xcpretty = !xcpretty
let captured_dir = results_dir ^/ captured_dir_name
let clang_frontend_action_string =
String.concat ~sep:" and "
((if capture then ["translating"] else []) @ if linters then ["linting"] else [])
let text = if capture then ["translating"] else [] in
let text = if linters then "linting" :: text else text in
let text = if process_clang_ast then "processing" :: text else text in
String.concat ~sep:", " text
(* Specify treatment of dynamic dispatch in Java code: false 'none' treats dynamic dispatch as

@ -286,8 +286,6 @@ val clang_blacklisted_flags : string list
val clang_blacklisted_flags_with_arg : string list
val clang_frontend_action_string : string
val clang_ignore_regex : string option
val clang_isystem_to_override_regex : Str.regexp option
@ -544,6 +542,10 @@ val procedures_name : bool
val procedures_source_file : bool
val process_clang_ast : bool
val clang_frontend_action_string : string
val procs_csv : string option
val profiler_samples : string option

@ -22,17 +22,15 @@ let validate_decl_from_channel chan =
Clang_ast_b.read_decl chan
(**FIXME(T54413835): Make the perf stats in the frontend work when one runs more than one frontend action *)
let register_perf_stats_report source_file =
let stats_type =
match (Config.capture, Config.linters) with
| true, true ->
PerfStats.ClangFrontendLinters source_file
| true, false ->
PerfStats.ClangFrontend source_file
| false, true ->
PerfStats.ClangLinters source_file
| false, false ->
Logging.(die UserError) "Clang frontend should be run in capture and/or linters mode."
if Config.capture then PerfStats.ClangFrontend source_file
else if Config.linters then PerfStats.ClangLinters source_file
else if Config.process_clang_ast then PerfStats.ClangProcessAST source_file
else
Logging.(die UserError)
"Clang frontend should be run in capture, linters or process AST mode."
in
PerfStats.register_report_at_exit stats_type
@ -95,15 +93,13 @@ let run_clang_frontend ast_source =
Format.fprintf fmt "stdin of %a" SourceFile.pp trans_unit_ctx.CFrontend_config.source_file
in
ClangPointers.populate_all_tables ast_decl ;
L.(debug Capture Quiet) "Clang frontend action is %s@\n" Config.clang_frontend_action_string ;
L.(debug Capture Medium)
"Start %s of AST from %a@\n" Config.clang_frontend_action_string pp_ast_filename ast_source ;
"Start %s the AST of %a@\n" Config.clang_frontend_action_string pp_ast_filename ast_source ;
if Config.linters then AL.do_frontend_checks trans_unit_ctx ast_decl ;
if Config.export_changed_functions then
ProcessAST.export_changed_functions trans_unit_ctx ast_decl ;
if Config.process_clang_ast then ProcessAST.process_ast trans_unit_ctx ast_decl ;
if Config.capture then CFrontend.do_source_file trans_unit_ctx ast_decl ;
L.(debug Capture Medium)
"End %s of AST file %a... OK!@\n" Config.clang_frontend_action_string pp_ast_filename
"End %s the AST of file %a... OK!@\n" Config.clang_frontend_action_string pp_ast_filename
ast_source ;
print_elapsed ()

@ -21,3 +21,7 @@ let export_changed_functions trans_unit_ctx ast_decl =
~f
in
call_f ()
let process_ast trans_unit_ctx ast_decl =
if Config.export_changed_functions then export_changed_functions trans_unit_ctx ast_decl

@ -6,5 +6,4 @@
*)
open! IStd
val export_changed_functions :
CFrontend_config.translation_unit_context -> Clang_ast_t.decl -> unit
val process_ast : CFrontend_config.translation_unit_context -> Clang_ast_t.decl -> unit

Loading…
Cancel
Save