26
26
#include < libyul/Object.h>
27
27
#include < libyul/Exceptions.h>
28
28
#include < libyul/AsmParser.h>
29
+ #include < libyul/Utilities.h>
29
30
#include < libyul/backends/evm/AbstractAssembly.h>
30
-
31
31
#include < libevmasm/SemanticInformation.h>
32
32
#include < libevmasm/Instruction.h>
33
33
@@ -46,19 +46,6 @@ using namespace solidity::util;
46
46
namespace
47
47
{
48
48
49
- void visitArguments (
50
- AbstractAssembly& _assembly,
51
- FunctionCall const & _call,
52
- function<void (Expression const &)> _visitExpression
53
- )
54
- {
55
- for (auto const & arg: _call.arguments | ranges::views::reverse)
56
- _visitExpression (arg);
57
-
58
- _assembly.setSourceLocation (_call.debugData ->location );
59
- }
60
-
61
-
62
49
pair<YulString, BuiltinFunctionForEVM> createEVMFunction (
63
50
string const & _name,
64
51
evmasm::Instruction _instruction
@@ -76,12 +63,10 @@ pair<YulString, BuiltinFunctionForEVM> createEVMFunction(
76
63
f.literalArguments .clear ();
77
64
f.instruction = _instruction;
78
65
f.generateCode = [_instruction](
79
- FunctionCall const & _call ,
66
+ FunctionCall const &,
80
67
AbstractAssembly& _assembly,
81
- BuiltinContext&,
82
- std::function<void (Expression const &)> _visitExpression
68
+ BuiltinContext&
83
69
) {
84
- visitArguments (_assembly, _call, _visitExpression);
85
70
_assembly.appendInstruction (_instruction);
86
71
};
87
72
@@ -94,7 +79,7 @@ pair<YulString, BuiltinFunctionForEVM> createFunction(
94
79
size_t _returns,
95
80
SideEffects _sideEffects,
96
81
vector<optional<LiteralKind>> _literalArguments,
97
- std::function<void (FunctionCall const &, AbstractAssembly&, BuiltinContext&, std::function< void (Expression const &)> )> _generateCode
82
+ std::function<void (FunctionCall const &, AbstractAssembly&, BuiltinContext&)> _generateCode
98
83
)
99
84
{
100
85
yulAssert (_literalArguments.size () == _params || _literalArguments.empty (), " " );
@@ -166,12 +151,10 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
166
151
builtins.emplace (createFunction (" linkersymbol" , 1 , 1 , SideEffects{}, {LiteralKind::String}, [](
167
152
FunctionCall const & _call,
168
153
AbstractAssembly& _assembly,
169
- BuiltinContext&,
170
- function<void (Expression const &)>
154
+ BuiltinContext&
171
155
) {
172
156
yulAssert (_call.arguments .size () == 1 , " " );
173
157
Expression const & arg = _call.arguments .front ();
174
- _assembly.setSourceLocation (_call.debugData ->location );
175
158
_assembly.appendLinkerSymbol (std::get<Literal>(arg).value .str ());
176
159
}));
177
160
@@ -184,24 +167,24 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
184
167
[](
185
168
FunctionCall const & _call,
186
169
AbstractAssembly& _assembly,
187
- BuiltinContext&,
188
- function<void (Expression const &)> _visitExpression
170
+ BuiltinContext&
189
171
) {
190
- visitArguments (_assembly, _call, _visitExpression);
172
+ yulAssert (_call.arguments .size () == 1 , " " );
173
+ Literal const * literal = get_if<Literal>(&_call.arguments .front ());
174
+ yulAssert (literal, " " );
175
+ _assembly.appendConstant (valueOfLiteral (*literal));
191
176
})
192
177
);
193
178
194
179
builtins.emplace (createFunction (" datasize" , 1 , 1 , SideEffects{}, {LiteralKind::String}, [](
195
180
FunctionCall const & _call,
196
181
AbstractAssembly& _assembly,
197
- BuiltinContext& _context,
198
- std::function<void (Expression const &)> const &
182
+ BuiltinContext& _context
199
183
) {
200
184
yulAssert (_context.currentObject , " No object available." );
201
185
yulAssert (_call.arguments .size () == 1 , " " );
202
186
Expression const & arg = _call.arguments .front ();
203
187
YulString dataName = std::get<Literal>(arg).value ;
204
- _assembly.setSourceLocation (_call.debugData ->location );
205
188
if (_context.currentObject ->name == dataName)
206
189
_assembly.appendAssemblySize ();
207
190
else
@@ -217,14 +200,12 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
217
200
builtins.emplace (createFunction (" dataoffset" , 1 , 1 , SideEffects{}, {LiteralKind::String}, [](
218
201
FunctionCall const & _call,
219
202
AbstractAssembly& _assembly,
220
- BuiltinContext& _context,
221
- std::function<void (Expression const &)> const &
203
+ BuiltinContext& _context
222
204
) {
223
205
yulAssert (_context.currentObject , " No object available." );
224
206
yulAssert (_call.arguments .size () == 1 , " " );
225
207
Expression const & arg = _call.arguments .front ();
226
208
YulString dataName = std::get<Literal>(arg).value ;
227
- _assembly.setSourceLocation (_call.debugData ->location );
228
209
if (_context.currentObject ->name == dataName)
229
210
_assembly.appendConstant (0 );
230
211
else
@@ -244,12 +225,10 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
244
225
SideEffects{false , true , false , false , true , SideEffects::None, SideEffects::None, SideEffects::Write},
245
226
{},
246
227
[](
247
- FunctionCall const & _call ,
228
+ FunctionCall const &,
248
229
AbstractAssembly& _assembly,
249
- BuiltinContext&,
250
- std::function<void (Expression const &)> _visitExpression
230
+ BuiltinContext&
251
231
) {
252
- visitArguments (_assembly, _call, _visitExpression);
253
232
_assembly.appendInstruction (evmasm::Instruction::CODECOPY);
254
233
}
255
234
));
@@ -262,15 +241,10 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
262
241
[](
263
242
FunctionCall const & _call,
264
243
AbstractAssembly& _assembly,
265
- BuiltinContext&,
266
- std::function<void (Expression const &)> _visitExpression
244
+ BuiltinContext&
267
245
) {
268
246
yulAssert (_call.arguments .size () == 3 , " " );
269
-
270
- _visitExpression (_call.arguments [2 ]);
271
247
YulString identifier = std::get<Literal>(_call.arguments [1 ]).value ;
272
- _visitExpression (_call.arguments [0 ]);
273
- _assembly.setSourceLocation (_call.debugData ->location );
274
248
_assembly.appendImmutableAssignment (identifier.str ());
275
249
}
276
250
));
@@ -283,11 +257,9 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
283
257
[](
284
258
FunctionCall const & _call,
285
259
AbstractAssembly& _assembly,
286
- BuiltinContext&,
287
- std::function<void (Expression const &)>
260
+ BuiltinContext&
288
261
) {
289
262
yulAssert (_call.arguments .size () == 1 , " " );
290
- _assembly.setSourceLocation (_call.debugData ->location );
291
263
_assembly.appendImmutable (std::get<Literal>(_call.arguments .front ()).value .str ());
292
264
}
293
265
));
@@ -387,15 +359,11 @@ BuiltinFunctionForEVM const* EVMDialect::verbatimFunction(size_t _arguments, siz
387
359
[=](
388
360
FunctionCall const & _call,
389
361
AbstractAssembly& _assembly,
390
- BuiltinContext&,
391
- std::function<void (Expression const &)> _visitExpression
362
+ BuiltinContext&
392
363
) {
393
364
yulAssert (_call.arguments .size () == (1 + _arguments), " " );
394
- for (Expression const & arg: _call.arguments | ranges::views::tail | ranges::views::reverse)
395
- _visitExpression (arg);
396
365
Expression const & bytecode = _call.arguments .front ();
397
366
398
- _assembly.setSourceLocation (_call.debugData ->location );
399
367
_assembly.appendVerbatim (
400
368
asBytes (std::get<Literal>(bytecode).value .str ()),
401
369
_arguments,
@@ -456,24 +424,19 @@ EVMDialectTyped::EVMDialectTyped(langutil::EVMVersion _evmVersion, bool _objectA
456
424
m_functions[" popbool" _yulstring].name = " popbool" _yulstring;
457
425
m_functions[" popbool" _yulstring].parameters = {" bool" _yulstring};
458
426
m_functions.insert (createFunction (" bool_to_u256" , 1 , 1 , {}, {}, [](
459
- FunctionCall const & _call,
460
- AbstractAssembly& _assembly,
461
- BuiltinContext&,
462
- std::function<void (Expression const &)> _visitExpression
463
- ) {
464
- visitArguments (_assembly, _call, _visitExpression);
465
- }));
427
+ FunctionCall const &,
428
+ AbstractAssembly&,
429
+ BuiltinContext&
430
+ ) {}));
466
431
m_functions[" bool_to_u256" _yulstring].parameters = {" bool" _yulstring};
467
432
m_functions[" bool_to_u256" _yulstring].returns = {" u256" _yulstring};
468
433
m_functions.insert (createFunction (" u256_to_bool" , 1 , 1 , {}, {}, [](
469
- FunctionCall const & _call ,
434
+ FunctionCall const &,
470
435
AbstractAssembly& _assembly,
471
- BuiltinContext&,
472
- std::function<void (Expression const &)> _visitExpression
436
+ BuiltinContext&
473
437
) {
474
438
// TODO this should use a Panic.
475
439
// A value larger than 1 causes an invalid instruction.
476
- visitArguments (_assembly, _call, _visitExpression);
477
440
_assembly.appendConstant (2 );
478
441
_assembly.appendInstruction (evmasm::Instruction::DUP2);
479
442
_assembly.appendInstruction (evmasm::Instruction::LT);
0 commit comments