Skip to content

Commit

Permalink
Merge pull request #1572 from Atlendis/add-via-ir-support-1477
Browse files Browse the repository at this point in the history
Add via ir support 1477
  • Loading branch information
iamdefinitelyahuman authored Mar 17, 2023
2 parents 2de6e1d + 9f399c0 commit 4e71252
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions brownie/project/compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def compile_and_format(
interface_sources: Optional[Dict[str, str]] = None,
remappings: Optional[list] = None,
optimizer: Optional[Dict] = None,
viaIR: Optional[bool] = None,
) -> Dict:
"""Compiles contracts and returns build data.
Expand All @@ -72,6 +73,7 @@ def compile_and_format(
interface_sources: dictionary of interfaces as {'path': "source code"}
remappings: list of solidity path remappings
optimizer: dictionary of solidity optimizer settings
viaIR: enable compilation pipeline to go through the Yul intermediate representation
Returns:
build data dict
Expand Down Expand Up @@ -136,6 +138,7 @@ def compile_and_format(
interface_sources=interfaces,
remappings=remappings,
optimizer=optimizer,
viaIR=viaIR,
)

output_json = compile_from_input_json(input_json, silent, allow_paths)
Expand All @@ -153,6 +156,7 @@ def generate_input_json(
interface_sources: Optional[Dict[str, str]] = None,
remappings: Optional[list] = None,
optimizer: Optional[Dict] = None,
viaIR: Optional[bool] = None,
) -> Dict:

"""Formats contracts to the standard solc input json.
Expand All @@ -166,6 +170,7 @@ def generate_input_json(
interface_sources: dictionary of interfaces as {'path': "source code"}
remappings: list of solidity path remappings
optimizer: dictionary of solidity optimizer settings
viaIR: enable compilation pipeline to go through the Yul intermediate representation
Returns: dict
"""
Expand All @@ -188,6 +193,8 @@ def generate_input_json(
if language == "Solidity":
input_json["settings"]["optimizer"] = optimizer
input_json["settings"]["remappings"] = _get_solc_remappings(remappings)
if viaIR is not None:
input_json["settings"]["viaIR"] = viaIR
input_json["sources"] = _sources_dict(contract_sources, language)

if interface_sources:
Expand Down
8 changes: 6 additions & 2 deletions brownie/project/compiler/solidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,12 @@ def _generate_coverage_data(
include_children=False,
required_offset=fn_offset,
filters={"nodeType": "FunctionDefinition"},
)[0]
revert_nodes = fn_node.children(
)
if len(fn_node) == 0:
# In Solidity >=0.8.13, with the viaIR option set, there is a dispatch
# function present in the generated bytecode
continue
revert_nodes = fn_node[0].children(
filters=(
{"nodeType": "FunctionCall", "expression.name": "revert"},
{"nodeType": "FunctionCall", "expression.name": "require"},
Expand Down
1 change: 1 addition & 0 deletions brownie/project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def _compile(self, contract_sources: Dict, compiler_config: Dict, silent: bool)
allow_paths=allow_paths,
remappings=compiler_config["solc"].get("remappings", []),
optimizer=compiler_config["solc"].get("optimizer", None),
viaIR=compiler_config["solc"].get("viaIR", None),
)
finally:
os.chdir(cwd)
Expand Down
6 changes: 6 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ Compiler settings. See :ref:`compiler settings<compile_settings>` for more infor

default value: ``null``

.. py:attribute:: viaIR
Enable solc compilation pipeline to go through the Yul Intermediate Representation to generate IR-based EVM bytecode. See the `Solidity documentation <https://docs.soliditylang.org/en/latest/ir-breaking-changes.html>`_ for breaking changes.

default value: ``false``

.. py:attribute:: optimizer
Optimizer settings to be passed to the Solidity compiler. Values given here are passed into the compiler with no reformatting. See the `Solidity documentation <https://solidity.readthedocs.io/en/latest/using-the-compiler.html#input-description>`_ for a list of possible values.
Expand Down

0 comments on commit 4e71252

Please sign in to comment.