Skip to content

Commit 3b1eacf

Browse files
authored
Merge pull request #11655 from ethereum/ObjectCompiler-user-src-new-test
Print source locations in AsmPrinter
2 parents c89b46c + 2ee6c7b commit 3b1eacf

File tree

34 files changed

+1320
-110
lines changed

34 files changed

+1320
-110
lines changed

libsolidity/codegen/ir/IRGenerator.cpp

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ InternalDispatchMap IRGenerator::generateInternalDispatchFunctions(ContractDefin
279279
string funName = IRNames::internalDispatch(arity);
280280
m_context.functionCollector().createFunction(funName, [&]() {
281281
Whiskers templ(R"(
282+
<sourceLocationComment>
282283
function <functionName>(fun<?+in>, <in></+in>) <?+out>-> <out></+out> {
283-
<sourceLocationComment>
284284
switch fun
285285
<#cases>
286286
case <funID>
@@ -290,6 +290,7 @@ InternalDispatchMap IRGenerator::generateInternalDispatchFunctions(ContractDefin
290290
</cases>
291291
default { <panic>() }
292292
}
293+
<sourceLocationComment>
293294
)");
294295
templ("sourceLocationComment", sourceLocationComment(_contract, m_context));
295296
templ("functionName", funName);
@@ -336,14 +337,19 @@ string IRGenerator::generateFunction(FunctionDefinition const& _function)
336337
return m_context.functionCollector().createFunction(functionName, [&]() {
337338
m_context.resetLocalVariables();
338339
Whiskers t(R"(
340+
<sourceLocationComment>
339341
function <functionName>(<params>)<?+retParams> -> <retParams></+retParams> {
340-
<sourceLocationComment>
341342
<retInit>
342343
<body>
343344
}
345+
<contractSourceLocationComment>
344346
)");
345347

346348
t("sourceLocationComment", sourceLocationComment(_function, m_context));
349+
t(
350+
"contractSourceLocationComment",
351+
sourceLocationComment(m_context.mostDerivedContract(), m_context)
352+
);
347353

348354
t("functionName", functionName);
349355
vector<string> params;
@@ -398,12 +404,13 @@ string IRGenerator::generateModifier(
398404
return m_context.functionCollector().createFunction(functionName, [&]() {
399405
m_context.resetLocalVariables();
400406
Whiskers t(R"(
407+
<sourceLocationComment>
401408
function <functionName>(<params>)<?+retParams> -> <retParams></+retParams> {
402-
<sourceLocationComment>
403409
<assignRetParams>
404410
<evalArgs>
405411
<body>
406412
}
413+
<contractSourceLocationComment>
407414
)");
408415
t("functionName", functionName);
409416
vector<string> retParamsIn;
@@ -428,6 +435,11 @@ string IRGenerator::generateModifier(
428435
);
429436
solAssert(modifier, "");
430437
t("sourceLocationComment", sourceLocationComment(*modifier, m_context));
438+
t(
439+
"contractSourceLocationComment",
440+
sourceLocationComment(m_context.mostDerivedContract(), m_context)
441+
);
442+
431443
switch (*_modifierInvocation.name().annotation().requiredLookup)
432444
{
433445
case VirtualLookup::Virtual:
@@ -478,13 +490,18 @@ string IRGenerator::generateFunctionWithModifierInner(FunctionDefinition const&
478490
return m_context.functionCollector().createFunction(functionName, [&]() {
479491
m_context.resetLocalVariables();
480492
Whiskers t(R"(
493+
<sourceLocationComment>
481494
function <functionName>(<params>)<?+retParams> -> <retParams></+retParams> {
482-
<sourceLocationComment>
483495
<assignRetParams>
484496
<body>
485497
}
498+
<contractSourceLocationComment>
486499
)");
487500
t("sourceLocationComment", sourceLocationComment(_function, m_context));
501+
t(
502+
"contractSourceLocationComment",
503+
sourceLocationComment(m_context.mostDerivedContract(), m_context)
504+
);
488505
t("functionName", functionName);
489506
vector<string> retParams;
490507
vector<string> retParamsIn;
@@ -522,12 +539,17 @@ string IRGenerator::generateGetter(VariableDeclaration const& _varDecl)
522539
solAssert(paramTypes.empty(), "");
523540
solUnimplementedAssert(type->sizeOnStack() == 1, "");
524541
return Whiskers(R"(
542+
<sourceLocationComment>
525543
function <functionName>() -> rval {
526-
<sourceLocationComment>
527544
rval := loadimmutable("<id>")
528545
}
546+
<contractSourceLocationComment>
529547
)")
530548
("sourceLocationComment", sourceLocationComment(_varDecl, m_context))
549+
(
550+
"contractSourceLocationComment",
551+
sourceLocationComment(m_context.mostDerivedContract(), m_context)
552+
)
531553
("functionName", functionName)
532554
("id", to_string(_varDecl.id()))
533555
.render();
@@ -536,12 +558,17 @@ string IRGenerator::generateGetter(VariableDeclaration const& _varDecl)
536558
{
537559
solAssert(paramTypes.empty(), "");
538560
return Whiskers(R"(
561+
<sourceLocationComment>
539562
function <functionName>() -> <ret> {
540-
<sourceLocationComment>
541563
<ret> := <constantValueFunction>()
542564
}
565+
<contractSourceLocationComment>
543566
)")
544567
("sourceLocationComment", sourceLocationComment(_varDecl, m_context))
568+
(
569+
"contractSourceLocationComment",
570+
sourceLocationComment(m_context.mostDerivedContract(), m_context)
571+
)
545572
("functionName", functionName)
546573
("constantValueFunction", IRGeneratorForStatements(m_context, m_utils).constantValueFunction(_varDecl))
547574
("ret", suffixedVariableNameList("ret_", 0, _varDecl.type()->sizeOnStack()))
@@ -653,16 +680,21 @@ string IRGenerator::generateGetter(VariableDeclaration const& _varDecl)
653680
}
654681

655682
return Whiskers(R"(
683+
<sourceLocationComment>
656684
function <functionName>(<params>) -> <retVariables> {
657-
<sourceLocationComment>
658685
<code>
659686
}
687+
<contractSourceLocationComment>
660688
)")
661689
("functionName", functionName)
662690
("params", joinHumanReadable(parameters))
663691
("retVariables", joinHumanReadable(returnVariables))
664692
("code", std::move(code))
665693
("sourceLocationComment", sourceLocationComment(_varDecl, m_context))
694+
(
695+
"contractSourceLocationComment",
696+
sourceLocationComment(m_context.mostDerivedContract(), m_context)
697+
)
666698
.render();
667699
});
668700
}
@@ -769,13 +801,15 @@ void IRGenerator::generateConstructors(ContractDefinition const& _contract)
769801
m_context.resetLocalVariables();
770802
m_context.functionCollector().createFunction(IRNames::constructor(*contract), [&]() {
771803
Whiskers t(R"(
804+
<sourceLocationComment>
772805
function <functionName>(<params><comma><baseParams>) {
773806
<evalBaseArguments>
774807
<sourceLocationComment>
775808
<?hasNextConstructor> <nextConstructor>(<nextParams>) </hasNextConstructor>
776809
<initStateVariables>
777810
<userDefinedConstructorBody>
778811
}
812+
<contractSourceLocationComment>
779813
)");
780814
vector<string> params;
781815
if (contract->constructor())
@@ -788,6 +822,10 @@ void IRGenerator::generateConstructors(ContractDefinition const& _contract)
788822
contract->location(),
789823
m_context
790824
));
825+
t(
826+
"contractSourceLocationComment",
827+
sourceLocationComment(m_context.mostDerivedContract(), m_context)
828+
);
791829

792830
t("params", joinHumanReadable(params));
793831
vector<string> baseParams = listAllParams(baseConstructorParams);

0 commit comments

Comments
 (0)