sophia/docs/aeso_compiler.md
Gaith Hallak c395849684
Introduce debugging symbols (#424)
* Add fann type and to_fann fun

* Add fann() to funcall

* Add fann() to closure

* Add fann() to set_state

* Add fann() to remote_u

* Add fann() to remote

* Add fann() to proj

* Add fann() to set_proj

* Add fann() to def and def_u

* Add fann() to op

* Add fann() to let

* Add fann() to lam

* Add fann() to builtin_u

* Add missing functions specs

* Dead code removal

* Fix the spec for compute_state_layout

* Add fann() to var

* Add fann() to switch

* Add fann() to lit and get_state

* Add fann() to builtin

* Add fann() to con

* Add fann() to tuple

* Add fann() to nil

* Fix missing fann() in tuple fexpr()

* Add dbgloc instruction to fate

* Add instructions lines to the debugging result

* Fix compiler tests

* Fix calldata tests

* Rname Ann to FAnn when the type is fann()

* Add line to fann()

* Change attributes for DBGLOC instruction

* Add file to fann()

* Add file to aeso_syntax:ann()

* Fix dialyzer warning

* Remove fann() from fsplit_pat() and fpat()

* Fill out empty fann() when possible

* Save debug locations for child contracts

* Include DBGLOC instructions in the compiler output

* Return an empty string instead of no_file atom

* Wrap args of DBGLOC in immediate tuple

* Upgrade aebytecode ref in rebar.config

* Add DBG_DEF and DBG_UNDEF

* Do not DBG_DEF vars with % prefix

* Do not use DBG_DEF and DBG_UNDEF on args

* Fix dbg_undef for args

* Rename DBGLOC to DBG_LOC

* Remove column from DBG_LOC

* Add missing dbg_loc in to_scode1

* Keep a single DBG_LOC instruction per line

* Remove col from fann

* Add DBG_LOC op to step at function sig

* Remove the variable-register map from debug output

* Use get_value/3 to handle default

* Use lookup instead of lookup_all

* List only needed attributes

* Make debug ops impure

* Split complicated code and add comment

* Fix annotations

* Fix indenting

* Remove dbg_loc before closure

* Add dbg_loc in to_scode

* Add DBG_CALL and DBG_RETURN

* Separate the split at CALL_T and loop

* Revert "Separate the split at CALL_T and loop"

This reverts commit 4ea823a7ca798c756b20cee32f928f41092c4959.

* Revert "Add DBG_CALL and DBG_RETURN"

This reverts commit c406c6feb09b6a5bb859c38d634f08208c901e5a.

* Disable tail call optimization for better debug call stack

* Rename env.debug to env.debug_info

* Upgrade aebytecode: Add DBG_CONTRACT

* Add DBG_CONTRACT instruction

* Check if a var name is fresh in separate function

* Add DBG_CONTRACT and DBG_LOC before DBG_DEF

* Save fresh names of pattern variables

* Implement fsplit_pat_vars for assign

* Set fann for switches

* Revert "Save fresh names of pattern variables"

This reverts commit d2473f982996336131477df2b2115c04a55a62cb.

* Add DBG_DEF for switch pattern vars

* Fix the inability to pattern match constructors

* Upgrade aebytecode dep

* Upgrade aebytecode dep

* Update the lock file

* Add annotations to fexpr var

* Fix issues with pretty-printing of fexprs

* Use FAnn instead of get_fann(Body)

* Upgrade aebytecode version

* Fix pp_fpat

* Fix pattern matching on fpat

* Update rename when a new rename comes up

* Upgrade aebytecode

* Remove the getopt dep

* Fix calldata tests

* Remove file committed by mistake

* Remove location anns from contract call type
2023-06-13 14:36:48 +03:00

2.4 KiB

aeso_compiler

Module

aeso_compiler

The Sophia compiler

Description

This module provides the interface to the standard Sophia compiler. It returns the compiled module in a map which can then be loaded.

Types

contract_string() = string() | binary()
contract_map() = #{bytecode => binary(),
                   compiler_version => binary(),
                   contract_souce => string(),
                   type_info => type_info()}
type_info()
errorstring() = binary()

Exports

file(File)

file(File, Options) -> CompRet

from_string(ContractString, Options) -> CompRet

Types

ContractString = contract_string()
Options = [Option]
CompRet = {ok,ContractMap} | {error,ErrorString}
ContractMap = contract_map()
ErrorString = errorstring()

Compile a contract defined in a file or in a string.

The pp_ options all print to standard output the following:

pp_sophia_code - print the input Sophia code.

pp_ast - print the AST of the code

pp_types - print information about the types

pp_typed_ast - print the AST with type information at each node

pp_assembler - print the generated assembler code

The option include_child_contract_symbols includes the symbols of child contracts functions in the generated fate code. It is turned off by default to avoid making contracts bigger on chain.

Options to control which compiler optimizations should run:

By default all optimizations are turned on, to disable an optimization, it should be explicitly set to false and passed as a compiler option.

List of optimizations:

  • optimize_inliner
  • optimize_inline_local_functions
  • optimize_bind_subexpressions
  • optimize_let_floating
  • optimize_simplifier
  • optimize_drop_unused_lets
  • optimize_push_consume
  • optimize_one_shot_var
  • optimize_write_to_dead_var
  • optimize_inline_switch_target
  • optimize_swap_push
  • optimize_swap_pop
  • optimize_swap_write
  • optimize_constant_propagation
  • optimize_prune_impossible_branches
  • optimize_single_successful_branch
  • optimize_inline_store
  • optimize_float_switch_bod

check_call(ContractString, Options) -> CheckRet

Types

ContractString = string() | binary()
CheckRet = {ok,string(),{Types,Type | any()},Terms} | {error,Term}
Types = [Type]
Type = term()

Check a call in contract through the __call function.

version() -> {ok, Version} | {error, term()}

Types

Version = binary()

Get the current version of the Sophia compiler.