Skip to content

Commit

Permalink
add machine readable ir_json format (vyperlang#2510)
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper authored Oct 24, 2021
1 parent cec2c53 commit 3931ba4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vyper/cli/vyper_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
opcodes - List of opcodes as a string
opcodes_runtime - List of runtime opcodes as a string
ir - Intermediate representation in LLL
ir_json - Intermediate LLL representation in JSON format
"""

combined_json_outputs = [
Expand Down Expand Up @@ -254,7 +255,7 @@ def compile_files(
output_formats = combined_json_outputs
show_version = True

translate_map = {"abi_python": "abi", "json": "abi", "ast": "ast_dict"}
translate_map = {"abi_python": "abi", "json": "abi", "ast": "ast_dict", "ir_json": "ir_dict"}
final_formats = [translate_map.get(i, i) for i in output_formats]

compiler_data = vyper.compile_codes(
Expand Down
1 change: 1 addition & 0 deletions vyper/compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"external_interface": output.build_external_interface_output,
"interface": output.build_interface_output,
"ir": output.build_ir_output,
"ir_dict": output.build_ir_dict_output,
"method_identifiers": output.build_method_identifiers_output,
# requires assembly
"abi": output.build_abi_output,
Expand Down
12 changes: 12 additions & 0 deletions vyper/compiler/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ def build_ir_output(compiler_data: CompilerData) -> LLLnode:
return compiler_data.lll_nodes


def build_ir_dict_output(compiler_data: CompilerData) -> LLLnode:
lll = compiler_data.lll_nodes

def _to_dict(lll_node):
args = lll_node.args
if len(args) > 0:
return {lll_node.value: [_to_dict(x) for x in args]}
return lll_node.value

return _to_dict(lll)


def build_method_identifiers_output(compiler_data: CompilerData) -> dict:
interface = compiler_data.vyper_module_folded._metadata["type"]
functions = interface.members.values()
Expand Down

0 comments on commit 3931ba4

Please sign in to comment.