Merge branch 'print-cst-ast' into 'dev'
Print different stages from command line. See merge request ligolang/ligo!341
This commit is contained in:
commit
b8af818457
@ -138,6 +138,57 @@ let compile_file =
|
|||||||
let doc = "Subcommand: compile a contract." in
|
let doc = "Subcommand: compile a contract." in
|
||||||
(Term.ret term , Term.info ~doc cmdname)
|
(Term.ret term , Term.info ~doc cmdname)
|
||||||
|
|
||||||
|
let print_cst =
|
||||||
|
let f source_file syntax display_format = (
|
||||||
|
toplevel ~display_format @@
|
||||||
|
let%bind pp = Compile.Of_source.pretty_print source_file (Syntax_name syntax) in
|
||||||
|
ok @@ Format.asprintf "%s \n" (Buffer.contents pp)
|
||||||
|
)
|
||||||
|
in
|
||||||
|
let term = Term.(const f $ source_file 0 $ syntax $ display_format) in
|
||||||
|
let cmdname = "print-cst" in
|
||||||
|
let doc = "Subcommand: print the cst. Warning: intended for development of LIGO and can break at any time." in
|
||||||
|
(Term.ret term, Term.info ~doc cmdname)
|
||||||
|
|
||||||
|
let print_ast =
|
||||||
|
let f source_file syntax display_format = (
|
||||||
|
toplevel ~display_format @@
|
||||||
|
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
|
||||||
|
ok @@ Format.asprintf "%a\n" Compile.Of_simplified.pretty_print simplified
|
||||||
|
)
|
||||||
|
in
|
||||||
|
let term = Term.(const f $ source_file 0 $ syntax $ display_format) in
|
||||||
|
let cmdname = "print-ast" in
|
||||||
|
let doc = "Subcommand: print the ast. Warning: intended for development of LIGO and can break at any time." in
|
||||||
|
(Term.ret term, Term.info ~doc cmdname)
|
||||||
|
|
||||||
|
let print_typed_ast =
|
||||||
|
let f source_file syntax display_format = (
|
||||||
|
toplevel ~display_format @@
|
||||||
|
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
|
||||||
|
let%bind typed,_ = Compile.Of_simplified.compile simplified in
|
||||||
|
ok @@ Format.asprintf "%a\n" Compile.Of_typed.pretty_print typed
|
||||||
|
)
|
||||||
|
in
|
||||||
|
let term = Term.(const f $ source_file 0 $ syntax $ display_format) in
|
||||||
|
let cmdname = "print-typed-ast" in
|
||||||
|
let doc = "Subcommand: print the typed ast. Warning: intended for development of LIGO and can break at any time." in
|
||||||
|
(Term.ret term, Term.info ~doc cmdname)
|
||||||
|
|
||||||
|
let print_mini_c =
|
||||||
|
let f source_file syntax display_format = (
|
||||||
|
toplevel ~display_format @@
|
||||||
|
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
|
||||||
|
let%bind typed,_ = Compile.Of_simplified.compile simplified in
|
||||||
|
let%bind mini_c = Compile.Of_typed.compile typed in
|
||||||
|
ok @@ Format.asprintf "%a\n" Compile.Of_mini_c.pretty_print mini_c
|
||||||
|
)
|
||||||
|
in
|
||||||
|
let term = Term.(const f $ source_file 0 $ syntax $ display_format) in
|
||||||
|
let cmdname = "print-mini-c" in
|
||||||
|
let doc = "Subcommand: print mini c. Warning: intended for development of LIGO and can break at any time." in
|
||||||
|
(Term.ret term, Term.info ~doc cmdname)
|
||||||
|
|
||||||
let measure_contract =
|
let measure_contract =
|
||||||
let f source_file entry_point syntax display_format =
|
let f source_file entry_point syntax display_format =
|
||||||
toplevel ~display_format @@
|
toplevel ~display_format @@
|
||||||
@ -371,4 +422,8 @@ let run ?argv () =
|
|||||||
run_function ;
|
run_function ;
|
||||||
evaluate_value ;
|
evaluate_value ;
|
||||||
dump_changelog ;
|
dump_changelog ;
|
||||||
|
print_cst ;
|
||||||
|
print_ast ;
|
||||||
|
print_typed_ast ;
|
||||||
|
print_mini_c
|
||||||
]
|
]
|
||||||
|
@ -47,6 +47,22 @@ let%expect_test _ =
|
|||||||
measure-contract
|
measure-contract
|
||||||
Subcommand: measure a contract's compiled size in bytes.
|
Subcommand: measure a contract's compiled size in bytes.
|
||||||
|
|
||||||
|
print-ast
|
||||||
|
Subcommand: print the ast. Warning: intended for development of
|
||||||
|
LIGO and can break at any time.
|
||||||
|
|
||||||
|
print-cst
|
||||||
|
Subcommand: print the cst. Warning: intended for development of
|
||||||
|
LIGO and can break at any time.
|
||||||
|
|
||||||
|
print-mini-c
|
||||||
|
Subcommand: print mini c. Warning: intended for development of
|
||||||
|
LIGO and can break at any time.
|
||||||
|
|
||||||
|
print-typed-ast
|
||||||
|
Subcommand: print the typed ast. Warning: intended for development
|
||||||
|
of LIGO and can break at any time.
|
||||||
|
|
||||||
run-function
|
run-function
|
||||||
Subcommand: run a function with the given parameter.
|
Subcommand: run a function with the given parameter.
|
||||||
|
|
||||||
@ -104,6 +120,22 @@ let%expect_test _ =
|
|||||||
measure-contract
|
measure-contract
|
||||||
Subcommand: measure a contract's compiled size in bytes.
|
Subcommand: measure a contract's compiled size in bytes.
|
||||||
|
|
||||||
|
print-ast
|
||||||
|
Subcommand: print the ast. Warning: intended for development of
|
||||||
|
LIGO and can break at any time.
|
||||||
|
|
||||||
|
print-cst
|
||||||
|
Subcommand: print the cst. Warning: intended for development of
|
||||||
|
LIGO and can break at any time.
|
||||||
|
|
||||||
|
print-mini-c
|
||||||
|
Subcommand: print mini c. Warning: intended for development of
|
||||||
|
LIGO and can break at any time.
|
||||||
|
|
||||||
|
print-typed-ast
|
||||||
|
Subcommand: print the typed ast. Warning: intended for development
|
||||||
|
of LIGO and can break at any time.
|
||||||
|
|
||||||
run-function
|
run-function
|
||||||
Subcommand: run a function with the given parameter.
|
Subcommand: run a function with the given parameter.
|
||||||
|
|
||||||
|
@ -133,3 +133,41 @@ let parsify_string = fun (syntax : v_syntax) source_filename ->
|
|||||||
let%bind parsified = parsify source_filename in
|
let%bind parsified = parsify source_filename in
|
||||||
let%bind applied = Self_ast_simplified.all_program parsified in
|
let%bind applied = Self_ast_simplified.all_program parsified in
|
||||||
ok applied
|
ok applied
|
||||||
|
|
||||||
|
let pretty_print_pascaligo = fun source ->
|
||||||
|
let%bind ast = Parser.Pascaligo.parse_file source in
|
||||||
|
let buffer = Buffer.create 59 in
|
||||||
|
let state = Parser.Pascaligo.ParserLog.mk_state
|
||||||
|
~offsets:true
|
||||||
|
~mode:`Byte
|
||||||
|
~buffer in
|
||||||
|
Parser.Pascaligo.ParserLog.pp_ast state ast;
|
||||||
|
ok buffer
|
||||||
|
|
||||||
|
let pretty_print_cameligo = fun source ->
|
||||||
|
let%bind ast = Parser.Cameligo.parse_file source in
|
||||||
|
let buffer = Buffer.create 59 in
|
||||||
|
let state = Parser.Cameligo.ParserLog.mk_state
|
||||||
|
~offsets:true
|
||||||
|
~mode:`Byte
|
||||||
|
~buffer in
|
||||||
|
Parser.Cameligo.ParserLog.pp_ast state ast;
|
||||||
|
ok buffer
|
||||||
|
|
||||||
|
let pretty_print_reasonligo = fun source ->
|
||||||
|
let%bind ast = Parser.Reasonligo.parse_file source in
|
||||||
|
let buffer = Buffer.create 59 in
|
||||||
|
let state = Parser.Reasonligo.ParserLog.mk_state
|
||||||
|
~offsets:true
|
||||||
|
~mode:`Byte
|
||||||
|
~buffer in
|
||||||
|
Parser.Reasonligo.ParserLog.pp_ast state ast;
|
||||||
|
ok buffer
|
||||||
|
|
||||||
|
let pretty_print = fun syntax source_filename ->
|
||||||
|
let%bind v_syntax = syntax_to_variant syntax (Some source_filename) in
|
||||||
|
(match v_syntax with
|
||||||
|
| Pascaligo -> pretty_print_pascaligo
|
||||||
|
| Cameligo -> pretty_print_cameligo
|
||||||
|
| ReasonLIGO -> pretty_print_reasonligo)
|
||||||
|
source_filename
|
@ -32,3 +32,6 @@ let aggregate_and_compile_contract = fun (program : Types.program) name ->
|
|||||||
|
|
||||||
let aggregate_and_compile_expression = fun program exp ->
|
let aggregate_and_compile_expression = fun program exp ->
|
||||||
aggregate_and_compile program (ExpressionForm exp)
|
aggregate_and_compile program (ExpressionForm exp)
|
||||||
|
|
||||||
|
let pretty_print program =
|
||||||
|
Mini_c.PP.program program
|
@ -18,3 +18,6 @@ let apply (entry_point : string) (param : Ast_simplified.expression) : Ast_simpl
|
|||||||
{ expression = Ast_simplified.E_application (entry_point_var, param) ;
|
{ expression = Ast_simplified.E_application (entry_point_var, param) ;
|
||||||
location = Virtual "generated application" } in
|
location = Virtual "generated application" } in
|
||||||
ok applied
|
ok applied
|
||||||
|
|
||||||
|
let pretty_print formatter (program : Ast_simplified.program) =
|
||||||
|
Ast_simplified.PP.program formatter program
|
@ -18,3 +18,6 @@ let compile_contract_input : string -> string -> v_syntax -> Ast_simplified.expr
|
|||||||
fun storage parameter syntax ->
|
fun storage parameter syntax ->
|
||||||
let%bind (storage,parameter) = bind_map_pair (compile_expression syntax) (storage,parameter) in
|
let%bind (storage,parameter) = bind_map_pair (compile_expression syntax) (storage,parameter) in
|
||||||
ok @@ Ast_simplified.e_pair storage parameter
|
ok @@ Ast_simplified.e_pair storage parameter
|
||||||
|
|
||||||
|
let pretty_print source_filename syntax =
|
||||||
|
Helpers.pretty_print syntax source_filename
|
@ -22,3 +22,6 @@ let assert_equal_contract_type : check_type -> string -> Ast_typed.program -> As
|
|||||||
| _ -> dummy_fail
|
| _ -> dummy_fail
|
||||||
)
|
)
|
||||||
| _ -> dummy_fail )
|
| _ -> dummy_fail )
|
||||||
|
|
||||||
|
let pretty_print ppf program =
|
||||||
|
Ast_typed.PP.program ppf program
|
Loading…
Reference in New Issue
Block a user