Skip to content

Commit d1cbd8d

Browse files
clonkercameel
authored andcommitted
interpreter uses yul AST instead of separate block and dialect
1 parent e134620 commit d1cbd8d

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

test/libyul/YulInterpreterTest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ std::string YulInterpreterTest::interpret(std::shared_ptr<Object const> const& _
8080
{
8181
Interpreter::run(
8282
state,
83-
*_object->dialect(),
84-
_object->code()->root(),
83+
*_object->code(),
8584
/*disableExternalCalls=*/ !m_simulateExternalCallsToSelf,
8685
/*disableMemoryTracing=*/ false
8786
);

test/tools/yulInterpreter/Inspector.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ using namespace solidity::yul::test;
3131
namespace
3232
{
3333

34-
void printVariable(YulString const& _name, u256 const& _value)
34+
void printVariable(std::string_view const _name, u256 const& _value)
3535
{
36-
std::cout << "\t" << _name.str() << " = " << _value.str();
36+
std::cout << "\t" << _name << " = " << _value.str();
3737

3838
if (_value != 0)
3939
std::cout << " (" << toCompactHexWithPrefix(_value) << ")";
@@ -46,17 +46,16 @@ void printVariable(YulString const& _name, u256 const& _value)
4646
void InspectedInterpreter::run(
4747
std::shared_ptr<Inspector> _inspector,
4848
InterpreterState& _state,
49-
Dialect const& _dialect,
50-
Block const& _ast,
49+
AST const& _ast,
5150
bool _disableExternalCalls,
5251
bool _disableMemoryTrace
5352
)
5453
{
5554
Scope scope;
56-
InspectedInterpreter{_inspector, _state, _dialect, scope, _disableExternalCalls, _disableMemoryTrace}(_ast);
55+
InspectedInterpreter{_inspector, _state, _ast.dialect(), scope, _disableExternalCalls, _disableMemoryTrace}(_ast.root());
5756
}
5857

59-
Inspector::NodeAction Inspector::queryUser(langutil::DebugData const& _data, std::map<YulString, u256> const& _variables)
58+
Inspector::NodeAction Inspector::queryUser(langutil::DebugData const& _data, std::map<YulName, u256> const& _variables)
6059
{
6160
if (m_stepMode == NodeAction::RunNode)
6261
{
@@ -99,7 +98,7 @@ Inspector::NodeAction Inspector::queryUser(langutil::DebugData const& _data, std
9998
else if (input == "variables" || input == "v")
10099
{
101100
for (auto &&[yulStr, val]: _variables)
102-
printVariable(yulStr, val);
101+
printVariable(yulStr.str(), val);
103102
std::cout << std::endl;
104103
}
105104
else if (
@@ -120,7 +119,7 @@ Inspector::NodeAction Inspector::queryUser(langutil::DebugData const& _data, std
120119
for (auto &&[yulStr, val]: _variables)
121120
if (yulStr.str() == varname)
122121
{
123-
printVariable(yulStr, val);
122+
printVariable(varname, val);
124123
found = true;
125124
break;
126125
}

test/tools/yulInterpreter/Inspector.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ class InspectedInterpreter: public Interpreter
103103
static void run(
104104
std::shared_ptr<Inspector> _inspector,
105105
InterpreterState& _state,
106-
Dialect const& _dialect,
107-
Block const& _ast,
106+
AST const& _ast,
108107
bool _disableExternalCalls,
109108
bool _disableMemoryTracing
110109
);

test/tools/yulInterpreter/Interpreter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,13 @@ void InterpreterState::dumpTraceAndState(std::ostream& _out, bool _disableMemory
109109

110110
void Interpreter::run(
111111
InterpreterState& _state,
112-
Dialect const& _dialect,
113-
Block const& _ast,
112+
AST const& _ast,
114113
bool _disableExternalCalls,
115114
bool _disableMemoryTrace
116115
)
117116
{
118117
Scope scope;
119-
Interpreter{_state, _dialect, scope, _disableExternalCalls, _disableMemoryTrace}(_ast);
118+
Interpreter{_state, _ast.dialect(), scope, _disableExternalCalls, _disableMemoryTrace}(_ast.root());
120119
}
121120

122121
void Interpreter::operator()(ExpressionStatement const& _expressionStatement)

test/tools/yulInterpreter/Interpreter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#pragma once
2323

2424
#include <libyul/ASTForward.h>
25+
#include <libyul/backends/evm/EVMDialect.h>
2526
#include <libyul/optimiser/ASTWalker.h>
2627

2728
#include <libevmasm/Instruction.h>
@@ -162,8 +163,7 @@ class Interpreter: public ASTWalker
162163
/// activated e.g., Redundant store eliminator, Equal store eliminator.
163164
static void run(
164165
InterpreterState& _state,
165-
Dialect const& _dialect,
166-
Block const& _ast,
166+
AST const& _ast,
167167
bool _disableExternalCalls,
168168
bool _disableMemoryTracing
169169
);

0 commit comments

Comments
 (0)