95 lines
22 KiB
HTML
95 lines
22 KiB
HTML
<!DOCTYPE html>
|
|
<html class="paged">
|
|
<head>
|
|
<title>Abstract Syntax Tree</title>
|
|
<link rel="stylesheet" type="text/css" href="/v5/static/style.css">
|
|
</head>
|
|
<body>
|
|
<div class="sidebar">
|
|
<div class="header">
|
|
<div class="logo"><a href="/v5/"><div class="image"></div><div class="name">ethers</div><div class="version">v5.0-beta</div></a></div>
|
|
</div>
|
|
<div class="toc"><div>
|
|
<div class="link title"><a href="/v5/">Documentation</a></div><div class="base show link depth-1"><a href="/v5/getting-started/">Getting Started</a></div><div class="base show link depth-1"><a href="/v5/concepts/">Ethereum Basics</a></div><div class="hide link depth-2"><a href="/v5/concepts/events/">Events</a></div><div class="hide link depth-2"><a href="/v5/concepts/gas/">Gas</a></div><div class="hide link depth-2"><a href="/v5/concepts/security/">Security</a></div><div class="base ancestor show link depth-1"><a href="/v5/api/">Application Programming Interface</a></div><div class="show link depth-2"><a href="/v5/api/contract/">Contract Interaction</a></div><div class="hide link depth-3"><a href="/v5/api/contract/contract/">Contract</a></div><div class="hide link depth-3"><a href="/v5/api/contract/contract-factory/">ContractFactory</a></div><div class="hide link depth-3"><a href="/v5/api/contract/example/">Example: ERC-20 Contract</a></div><div class="show link depth-2"><a href="/v5/api/signer/">Signers</a></div><div class="show link depth-2"><a href="/v5/api/providers/">Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/provider/">Provider</a></div><div class="hide link depth-3"><a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><div class="hide link depth-3"><a href="/v5/api/providers/api-providers/">API Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/other/">Other Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/types/">Types</a></div><div class="show link depth-2"><a href="/v5/api/utils/">Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/abi/">Application Binary Interface</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/coder/">AbiCoder</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/formats/">ABI Formats</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/fragments/">Fragments</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/interface/">Interface</a></div><div class="hide link depth-3"><a href="/v5/api/utils/address/">Addresses</a></div><div class="hide link depth-3"><a href="/v5/api/utils/bignumber/">BigNumber</a></div><div class="hide link depth-3"><a href="/v5/api/utils/bytes/">Byte Manipulation</a></div><div class="hide link depth-3"><a href="/v5/api/utils/constants/">Constants</a></div><div class="hide link depth-3"><a href="/v5/api/utils/display-logic/">Display Logic and Input</a></div><div class="hide link depth-3"><a href="/v5/api/utils/encoding/">Encoding Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/fixednumber/">FixedNumber</a></div><div class="hide link depth-3"><a href="/v5/api/utils/hashing/">Hashing Algorithms</a></div><div class="hide link depth-3"><a href="/v5/api/utils/hdnode/">HD Wallet</a></div><div class="hide link depth-3"><a href="/v5/api/utils/logger/">Logging</a></div><div class="hide link depth-3"><a href="/v5/api/utils/properties/">Property Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/signing-key/">Signing Key</a></div><div class="hide link depth-3"><a href="/v5/api/utils/strings/">Strings</a></div><div class="hide link depth-3"><a href="/v5/api/utils/transactions/">Transactions</a></div><div class="hide link depth-3"><a href="/v5/api/utils/web/">Web Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/wordlists/">Wordlists</a></div><div class="ancestor show link depth-2"><a href="/v5/api/other/">Other Libraries</a></div><div class="ancestor show link depth-3"><a href="/v5/api/other/assembly/">Assembly</a></div><div class="show link depth-4"><a href="/v5/api/other/assembly/dialect/">Ethers ASM Dialect</a></div><div class="show link depth-4"><a href="/v5/api/other/assembly/api/">Utilities</a></div><div class="myself ancestor ancestor show link depth-4"><a href="/v5/api/other/assembly/ast/">Abstract Syntax Tree</a></div><div class="show link depth-3"><a href="/v5/api/other/hardware/">Hardware Wallets</a></div><div class="show link depth-2"><a href="/v5/api/experimental/">Experimental</a></div><div class="base show link depth-1"><a href="/v5/cli/">Command Line Interfaces</a></div><div class="hide link depth-2"><a href="/v5/cli/ethers/">Sandbox Utility</a></div><div class="hide link depth-2"><a href="/v5/cli/asm/">Assembler</a></div><div class="hide link depth-2"><a href="/v5/cli/ens/">Ethereum Naming Service</a></div><div class="hide link depth-2"><a href="/v5/cli/typescript/">TypeScript</a></div><div class="hide link depth-2"><a href="/v5/cli/plugin/">Making Your Own</a></div><div class="base show link depth-1"><a href="/v5/cookbook/">Cookbook</a></div><div class="base show link depth-1"><a href="/v5/migration/">Migration Guide</a></div><div class="hide link depth-2"><a href="/v5/migration/web3/">Migration: From Web3.js</a></div><div class="hide link depth-2"><a href="/v5/migration/ethers-v4/">Migration: From Ethers v4</a></div><div class="base show link depth-1"><a href="/v5/testing/">Testing</a></div><div class="base show link depth-1"><a href="/v5/contributing/">Contributing and Hacking</a></div><div class="base show link depth-1"><a href="/v5/documentation/">Flatworm Docs</a></div><div class="base show link depth-1"><a href="/v5/license/">License and Copyright</a></div>
|
|
</div></div>
|
|
</div>
|
|
<div class="content">
|
|
<div class="breadcrumbs"><a href="/v5/">Documentation</a> » <a href="/v5/api/">API</a> » <a href="/v5/api/other/">Other Libraries</a> » <a href="/v5/api/other/assembly/">Assembly</a> » <span class="current">Abstract Syntax Tree</span></div>
|
|
|
|
<a name="asm-ast"></a><a name="asm-ast"></a><h1 class="show-anchors"><div>Abstract Syntax Tree<div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-ast"></a></div></div></h1><p>Parsing a file using the <a href="/v5/api/other/assembly/dialect/">Ethers ASM Dialect</a> will generate an Abstract Syntax Tree. The root node will always be a <a href="/v5/api/other/assembly/ast/#asm-scopenode">ScopeNode</a> whose name is <code class="inline">_</code>.</p>
|
|
|
|
<p>To parse a file into an Abstract Syntax tree, use the <a href="/v5/api/other/assembly/api/#asm-parse">parse</a> function.</p>
|
|
|
|
<a name="asm-ast--types"></a><h2 class="show-anchors"><div>Types<div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-ast--types"></a></div></div></h2>
|
|
<a name="asm-location"></a><a name="asm-ast--types--asm-location"></a><h3 class="show-anchors"><div>Location<div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-location"></a></div></div></h3>
|
|
<div class="property show-anchors"><div class="signature"><span class="method">offset</span> <span class="arrow">⇒</span> <span class="returns">number</span><div class="anchors"></div></div><div class="body"><p>The offset into the source code to the start of this node.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="method">length</span> <span class="arrow">⇒</span> <span class="returns">number</span><div class="anchors"></div></div><div class="body"><p>The length of characters in the source code to the end of this node.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="method">source</span> <span class="arrow">⇒</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>The source code of this node.</p>
|
|
|
|
</div></div><a name="asm-ast--nodes"></a><h2 class="show-anchors"><div>Nodes<div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-ast--nodes"></a></div></div></h2><p>@TODO: Place a diagram here showing the hierarchy</p>
|
|
|
|
<a name="asm-node"></a><a name="asm-ast--nodes--asm-node"></a><h3 class="show-anchors"><div>Node<div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-node"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/asm/src.ts/assembler.ts#L156">source</a></div></div></h3>
|
|
<div class="property show-anchors"><div class="signature"><span class="path">node</span><span class="symbol">.</span><span class="method">tag</span> <span class="arrow">⇒</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>A unique tag for this node for the lifetime of the process.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">node</span><span class="symbol">.</span><span class="method">location</span> <span class="arrow">⇒</span> <span class="returns"><a href="/v5/api/other/assembly/ast/#asm-location">Location</a></span><div class="anchors"></div></div><div class="body"><p>The source code and location within the source code that this node represents.</p>
|
|
|
|
</div></div><a name="asm-valuenode"></a><a name="asm-ast--nodes--asm-valuenode"></a><h3 class="show-anchors"><div>ValueNode<span class="inherits"> inherits <a href="/v5/api/other/assembly/ast/#asm-node">Node</a></span><div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-valuenode"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/asm/src.ts/assembler.ts#L213">source</a></div></div></h3><p>A <b>ValueNode</b> is a node which may manipulate the stack.</p>
|
|
|
|
<a name="asm-literalnode"></a><a name="asm-ast--nodes--asm-literalnode"></a><h3 class="show-anchors"><div>LiteralNode<span class="inherits"> inherits <a href="/v5/api/other/assembly/ast/#asm-valuenode">ValueNode</a></span><div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-literalnode"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/asm/src.ts/assembler.ts#L237">source</a></div></div></h3>
|
|
<div class="property show-anchors"><div class="signature"><span class="path">literalNode</span><span class="symbol">.</span><span class="method">value</span> <span class="arrow">⇒</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>The literal value of this node, which may be a <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a> or string of a decimal number.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">literalNode</span><span class="symbol">.</span><span class="method">verbatim</span> <span class="arrow">⇒</span> <span class="returns">boolean</span><div class="anchors"></div></div><div class="body"><p>This is true in a <a href="/v5/api/other/assembly/ast/#asm-datanode">DataNode</a> context, since in that case the value should be taken verbatim and no <code class="inline">PUSH</code> operation shoud be added, otherwise false.</p>
|
|
|
|
</div></div><a name="asm-popnode"></a><a name="asm-ast--nodes--asm-popnode"></a><h3 class="show-anchors"><div>PopNode<span class="inherits"> inherits <a href="/v5/api/other/assembly/ast/#asm-valuenode">ValueNode</a></span><div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-popnode"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/asm/src.ts/assembler.ts#L265">source</a></div></div></h3><p>A <b>PopNode</b> is used to store a place-holder for an implicit pop from the stack. It represents the code for an implicit place-holder (i.e. <code class="inline">$$</code>) or an explicit place-holder (e.g. <code class="inline">$1</code>), which indicates the expect stack position to consume.</p>
|
|
|
|
<div class="property show-anchors"><div class="signature"><span class="path">literalNode</span><span class="symbol">.</span><span class="method">index</span> <span class="arrow">⇒</span> <span class="returns">number</span><div class="anchors"></div></div><div class="body"><p>The index this <b>PopNode</b> is representing. For an implicit place-holder this is <code class="inline">0</code>.</p>
|
|
|
|
</div></div><a name="asm-linknode"></a><a name="asm-ast--nodes--asm-linknode"></a><h3 class="show-anchors"><div>LinkNode<span class="inherits"> inherits <a href="/v5/api/other/assembly/ast/#asm-valuenode">ValueNode</a></span><div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-linknode"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/asm/src.ts/assembler.ts#L282">source</a></div></div></h3><p>A <b>LinkNode</b> represents a link to another <a href="/v5/api/other/assembly/ast/#asm-node">Node</a>'s data, for example <code class="inline">$foo</code> or <code class="inline">#bar</code>.</p>
|
|
|
|
<div class="property show-anchors"><div class="signature"><span class="path">linkNode</span><span class="symbol">.</span><span class="method">label</span> <span class="arrow">⇒</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>Te name of the target node.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">linkNode</span><span class="symbol">.</span><span class="method">type</span> <span class="arrow">⇒</span> <span class="returns">"offset" | "length"</span><div class="anchors"></div></div><div class="body"><p>Whether this node is for an offset or a length value of the target node.</p>
|
|
|
|
</div></div><a name="asm-opcodenode"></a><a name="asm-ast--nodes--asm-opcodenode"></a><h3 class="show-anchors"><div>OpcodeNode<span class="inherits"> inherits <a href="/v5/api/other/assembly/ast/#asm-valuenode">ValueNode</a></span><div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-opcodenode"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/asm/src.ts/assembler.ts#L367">source</a></div></div></h3>
|
|
<div class="property show-anchors"><div class="signature"><span class="path">opcodeNode</span><span class="symbol">.</span><span class="method">opcode</span> <span class="arrow">⇒</span> <span class="returns"><a href="/v5/api/other/assembly/api/#asm-opcode">Opcode</a></span><div class="anchors"></div></div><div class="body"><p>The opcode for this Node.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">opcodeNode</span><span class="symbol">.</span><span class="method">operands</span> <span class="arrow">⇒</span> <span class="returns">Array< <a href="/v5/api/other/assembly/ast/#asm-valuenode">ValueNode</a> ></span><div class="anchors"></div></div><div class="body"><p>A list of all operands passed into this Node.</p>
|
|
|
|
</div></div><a name="asm-evaluationnode"></a><a name="asm-ast--nodes--asm-evaluationnode"></a><h3 class="show-anchors"><div>EvaluationNode<span class="inherits"> inherits <a href="/v5/api/other/assembly/ast/#asm-valuenode">ValueNode</a></span><div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-evaluationnode"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/asm/src.ts/assembler.ts#L517">source</a></div></div></h3><p>An <b>EvaluationNode</b> is used to execute code and insert the results but does not generate any output assembly, using the <code class="inline">{{! code here }}</code> syntax.</p>
|
|
|
|
<div class="property show-anchors"><div class="signature"><span class="path">literalNode</span><span class="symbol">.</span><span class="method">verbatim</span> <span class="arrow">⇒</span> <span class="returns">boolean</span><div class="anchors"></div></div><div class="body"><p>This is true in a <a href="/v5/api/other/assembly/ast/#asm-datanode">DataNode</a> context, since in that case the value should be taken verbatim and no <code class="inline">PUSH</code> operation shoud be added, otherwise false.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">evaluationNode</span><span class="symbol">.</span><span class="method">script</span> <span class="arrow">⇒</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>The code to evaluate and produce the result to use as a literal.</p>
|
|
|
|
</div></div><a name="asm-executionnode"></a><a name="asm-ast--nodes--asm-executionnode"></a><h3 class="show-anchors"><div>ExecutionNode<span class="inherits"> inherits <a href="/v5/api/other/assembly/ast/#asm-node">Node</a></span><div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-executionnode"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/asm/src.ts/assembler.ts#L546">source</a></div></div></h3><p>An <b>ExecutionNode</b> is used to execute code but does not generate any output assembly, using the <code class="inline">{{! code here }}</code> syntax.</p>
|
|
|
|
<div class="property show-anchors"><div class="signature"><span class="path">evaluationNode</span><span class="symbol">.</span><span class="method">script</span> <span class="arrow">⇒</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>The code to execute. Any result is ignored.</p>
|
|
|
|
</div></div><a name="asm-labellednode"></a><a name="asm-ast--nodes--asm-labellednode"></a><h3 class="show-anchors"><div>LabelledNode<span class="inherits"> inherits <a href="/v5/api/other/assembly/ast/#asm-node">Node</a></span><div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-labellednode"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/asm/src.ts/assembler.ts#L418">source</a></div></div></h3><p>A <b>LabelledNode</b> is used for any Node that has a name, and can therefore be targetted by a <a href="/v5/api/other/assembly/ast/#asm-linknode">LinkNode</a>.</p>
|
|
|
|
<div class="property show-anchors"><div class="signature"><span class="path">labelledNode</span><span class="symbol">.</span><span class="method">name</span> <span class="arrow">⇒</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>The name of this node.</p>
|
|
|
|
</div></div><a name="asm-labelnode"></a><a name="asm-ast--nodes--asm-labelnode"></a><h3 class="show-anchors"><div>LabelNode<span class="inherits"> inherits <a href="/v5/api/other/assembly/ast/#asm-labellednode">LabelledNode</a></span><div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-labelnode"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/asm/src.ts/assembler.ts#L429">source</a></div></div></h3><p>A <b>LabelNode</b> is used as a place to <code class="inline">JUMP</code> to by referencing it name, using <code class="inline">@myLabel:</code>. A <code class="inline">JUMPDEST</code> is automatically inserted at the bytecode offset.</p>
|
|
|
|
<a name="asm-datanode"></a><a name="asm-ast--nodes--asm-datanode"></a><h3 class="show-anchors"><div>DataNode<span class="inherits"> inherits <a href="/v5/api/other/assembly/ast/#asm-labellednode">LabelledNode</a></span><div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-datanode"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/asm/src.ts/assembler.ts#L465">source</a></div></div></h3><p>A <b>DataNode</b> allows for data to be inserted directly into the output assembly, using <code class="inline">@myData[ ... ]</code>. The data is padded if needed to ensure values that would otherwise be regarded as a <code class="inline">PUSH</code> value does not impact anything past the data.</p>
|
|
|
|
<div class="property show-anchors"><div class="signature"><span class="path">dataNode</span><span class="symbol">.</span><span class="method">data</span> <span class="arrow">⇒</span> <span class="returns">Array< <a href="/v5/api/other/assembly/ast/#asm-valuenode">ValueNode</a> ></span><div class="anchors"></div></div><div class="body"><p>The child nodes, which each represent a verbatim piece of data in insert.</p>
|
|
|
|
</div></div><a name="asm-scopenode"></a><a name="asm-ast--nodes--asm-scopenode"></a><h3 class="show-anchors"><div>ScopeNode<span class="inherits"> inherits <a href="/v5/api/other/assembly/ast/#asm-labellednode">LabelledNode</a></span><div class="anchors"><a class="self" href="/v5/api/other/assembly/ast/#asm-scopenode"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/asm/src.ts/assembler.ts#L565">source</a></div></div></h3><p>A <b>ScopeNode</b> allows a new frame of reference that all <a href="/v5/api/other/assembly/ast/#asm-linknode">LinkNode</a>'s will use when resolving offset locations, using <code class="inline">@myScope{ ... }</code>.</p>
|
|
|
|
<div class="property show-anchors"><div class="signature"><span class="path">scopeNode</span><span class="symbol">.</span><span class="method">statements</span> <span class="arrow">⇒</span> <span class="returns">Array< <a href="/v5/api/other/assembly/ast/#asm-node">Node</a> ></span><div class="anchors"></div></div><div class="body"><p>The list of child nodes for this scope.</p>
|
|
|
|
</div></div>
|
|
|
|
<div class="footer">
|
|
<div class="nav previous"><a href="/v5/api/other/assembly/api/"><span class="arrow">←</span>Utilities</a></div>
|
|
<div class="nav next"><a href="/v5/api/other/hardware/">Hardware Wallets<span class="arrow">→</span></a></div>
|
|
</div>
|
|
<div class="copyright">The content of this site is licensed under the <a href="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons License</a>. Last modified on June 12, 2020, 7:17pm.</div>
|
|
</div>
|
|
<script src="/v5/static/script.js" type="text/javascript"></script>
|
|
</body>
|
|
</html>
|