Only list used source names.

This commit is contained in:
chriseth
2021-09-06 18:33:05 +02:00
parent 4615e62514
commit f14b7598c7
28 changed files with 87 additions and 83 deletions
+3 -2
View File
@@ -127,9 +127,10 @@ string IRNames::zeroValue(Type const& _type, string const& _variableName)
return "zero_" + _type.identifier() + _variableName;
}
string sourceLocationComment(langutil::SourceLocation const& _location, IRGenerationContext const& _context)
string sourceLocationComment(langutil::SourceLocation const& _location, IRGenerationContext& _context)
{
solAssert(_location.sourceName, "");
_context.markSourceUsed(*_location.sourceName);
return "/// @src "
+ to_string(_context.sourceIndices().at(*_location.sourceName))
+ ":"
@@ -138,7 +139,7 @@ string sourceLocationComment(langutil::SourceLocation const& _location, IRGenera
+ to_string(_location.end);
}
string sourceLocationComment(ASTNode const& _node, IRGenerationContext const& _context)
string sourceLocationComment(ASTNode const& _node, IRGenerationContext& _context)
{
return sourceLocationComment(_node.location(), _context);
}
+2 -2
View File
@@ -73,8 +73,8 @@ struct IRNames
* @returns a source location comment in the form of
* `/// @src <sourceIndex>:<locationStart>:<locationEnd>`.
*/
std::string sourceLocationComment(langutil::SourceLocation const& _location, IRGenerationContext const& _context);
std::string sourceLocationComment(ASTNode const& _node, IRGenerationContext const& _context);
std::string sourceLocationComment(langutil::SourceLocation const& _location, IRGenerationContext& _context);
std::string sourceLocationComment(ASTNode const& _node, IRGenerationContext& _context);
}
@@ -166,6 +166,8 @@ public:
void copyFunctionIDsFrom(IRGenerationContext const& _other);
std::map<std::string, unsigned> const& sourceIndices() const { return m_sourceIndices; }
void markSourceUsed(std::string const& _name) { m_usedSourceNames.insert(_name); }
std::set<std::string> const& usedSourceNames() const { return m_usedSourceNames; }
bool immutableRegistered(VariableDeclaration const& _varDecl) const { return m_immutableVariables.count(&_varDecl); }
@@ -175,6 +177,7 @@ private:
RevertStrings m_revertStrings;
OptimiserSettings m_optimiserSettings;
std::map<std::string, unsigned> m_sourceIndices;
std::set<std::string> m_usedSourceNames;
ContractDefinition const* m_mostDerivedContract = nullptr;
std::map<VariableDeclaration const*, IRVariable> m_localVariables;
/// Memory offsets reserved for the values of immutable variables during contract creation.
+16 -16
View File
@@ -131,12 +131,21 @@ string IRGenerator::generate(
subObjectsSources += _otherYulSources.at(subObject);
return subObjectsSources;
};
auto formatUseSrcMap = [](IRGenerationContext const& _context) -> string
{
return joinHumanReadable(
ranges::views::transform(_context.usedSourceNames(), [_context](string const& _sourceName) {
return to_string(_context.sourceIndices().at(_sourceName)) + ":" + escapeAndQuoteString(_sourceName);
}),
", "
);
};
Whiskers t(R"(
/// @use-src <useSrcMapCreation>
object "<CreationObject>" {
code {
<sourceLocationComment>
<sourceLocationCommentCreation>
<memoryInitCreation>
<callValueCheck>
<?library>
@@ -150,7 +159,7 @@ string IRGenerator::generate(
/// @use-src <useSrcMapDeployed>
object "<DeployedObject>" {
code {
<sourceLocationComment>
<sourceLocationCommentDeployed>
<memoryInitDeployed>
<?library>
let called_via_delegatecall := iszero(eq(loadimmutable("<library_address>"), address()))
@@ -169,19 +178,8 @@ string IRGenerator::generate(
for (VariableDeclaration const* var: ContractType(_contract).immutableVariables())
m_context.registerImmutableVariable(*var);
auto invertedSourceIndicies = invertMap(m_context.sourceIndices());
string useSrcMap = joinHumanReadable(
ranges::views::transform(invertedSourceIndicies, [](auto&& _pair) {
return to_string(_pair.first) + ":" + escapeAndQuoteString(_pair.second);
}),
", "
);
t("useSrcMapCreation", useSrcMap);
t("sourceLocationComment", sourceLocationComment(_contract));
t("CreationObject", IRNames::creationObject(_contract));
t("sourceLocationCommentCreation", sourceLocationComment(_contract));
t("library", _contract.isLibrary());
FunctionDefinition const* constructor = _contract.constructor();
@@ -211,6 +209,7 @@ string IRGenerator::generate(
// This has to be called only after all other code generation for the creation object is complete.
bool creationInvolvesAssembly = m_context.inlineAssemblySeen();
t("memoryInitCreation", memoryInit(!creationInvolvesAssembly));
t("useSrcMapCreation", formatUseSrcMap(m_context));
resetContext(_contract, ExecutionContext::Deployed);
@@ -220,8 +219,8 @@ string IRGenerator::generate(
m_context.initializeInternalDispatch(move(internalDispatchMap));
// Do not register immutables to avoid assignment.
t("useSrcMapDeployed", useSrcMap);
t("DeployedObject", IRNames::deployedObject(_contract));
t("sourceLocationCommentDeployed", sourceLocationComment(_contract));
t("library_address", IRNames::libraryAddressImmutable());
t("dispatch", dispatchRoutine(_contract));
set<FunctionDefinition const*> deployedFunctionList = generateQueuedFunctions();
@@ -231,6 +230,7 @@ string IRGenerator::generate(
t("metadataName", yul::Object::metadataName());
t("cborMetadata", toHex(_cborMetadata));
t("useSrcMapDeployed", formatUseSrcMap(m_context));
// This has to be called only after all other code generation for the deployed object is complete.
bool deployedInvolvesAssembly = m_context.inlineAssemblySeen();
@@ -1073,7 +1073,7 @@ void IRGenerator::resetContext(ContractDefinition const& _contract, ExecutionCon
m_context.addStateVariable(*get<0>(var), get<1>(var), get<2>(var));
}
string IRGenerator::sourceLocationComment(ASTNode const& _node) const
string IRGenerator::sourceLocationComment(ASTNode const& _node)
{
return ::sourceLocationComment(_node, m_context);
}
+1 -1
View File
@@ -119,7 +119,7 @@ private:
void resetContext(ContractDefinition const& _contract, ExecutionContext _context);
std::string sourceLocationComment(ASTNode const& _node) const;
std::string sourceLocationComment(ASTNode const& _node);
langutil::EVMVersion const m_evmVersion;
OptimiserSettings const m_optimiserSettings;