Basic infrastructure.

This commit is contained in:
Daniel Kirchner
2023-09-13 22:37:00 +02:00
committed by Nikola Matic
parent 9bce5f91dc
commit fa815764dd
7 changed files with 361 additions and 19 deletions
+48 -19
View File
@@ -57,6 +57,7 @@
#include <libsolidity/parsing/Parser.h>
#include <libsolidity/experimental/analysis/Analysis.h>
#include <libsolidity/experimental/codegen/IRGenerator.h>
#include <libsolidity/codegen/ir/Common.h>
#include <libsolidity/codegen/ir/IRGenerator.h>
@@ -310,6 +311,7 @@ void CompilerStack::reset(bool _keepSettings)
{
m_stackState = Empty;
m_sources.clear();
m_maxAstId.reset();
m_smtlib2Responses.clear();
m_unhandledSMTLib2Queries.clear();
if (!_keepSettings)
@@ -410,6 +412,10 @@ bool CompilerStack::parse()
m_stackState = (m_stopAfter <= Parsed ? Parsed : ParsedAndImported);
storeContractDefinitions();
solAssert(!m_maxAstId.has_value());
m_maxAstId = parser.maxID();
return true;
}
@@ -461,7 +467,7 @@ bool CompilerStack::analyze()
m_globalContext = std::make_shared<GlobalContext>();
// We need to keep the same resolver during the whole process.
NameAndTypeResolver resolver(*m_globalContext, m_evmVersion, m_errorReporter);
NameAndTypeResolver resolver(*m_globalContext, m_evmVersion, m_errorReporter, experimentalSolidity);
for (Source const* source: m_sourceOrder)
if (source->ast && !resolver.registerDeclarations(*source->ast))
return false;
@@ -475,10 +481,12 @@ bool CompilerStack::analyze()
resolver.warnHomonymDeclarations();
DocStringTagParser docStringTagParser(m_errorReporter);
for (Source const* source: m_sourceOrder)
if (source->ast && !docStringTagParser.parseDocStrings(*source->ast))
noErrors = false;
{
DocStringTagParser docStringTagParser(m_errorReporter);
for (Source const* source: m_sourceOrder)
if (source->ast && !docStringTagParser.parseDocStrings(*source->ast))
noErrors = false;
}
// Requires DocStringTagParser
for (Source const* source: m_sourceOrder)
@@ -655,7 +663,8 @@ bool CompilerStack::analyzeLegacy(bool _noErrorsSoFar)
bool CompilerStack::analyzeExperimental()
{
solAssert(!m_experimentalAnalysis);
m_experimentalAnalysis = std::make_unique<experimental::Analysis>(m_errorReporter);
solAssert(m_maxAstId && *m_maxAstId >= 0);
m_experimentalAnalysis = std::make_unique<experimental::Analysis>(m_errorReporter, static_cast<std::uint64_t>(*m_maxAstId));
std::vector<std::shared_ptr<SourceUnit const>> sourceAsts;
for (Source const* source: m_sourceOrder)
if (source->ast)
@@ -1492,19 +1501,39 @@ void CompilerStack::generateIR(ContractDefinition const& _contract)
for (auto const& pair: m_contracts)
otherYulSources.emplace(pair.second.contract, pair.second.yulIR);
IRGenerator generator(
m_evmVersion,
m_eofVersion,
m_revertStrings,
sourceIndices(),
m_debugInfoSelection,
this
);
compiledContract.yulIR = generator.run(
_contract,
createCBORMetadata(compiledContract, /* _forIR */ true),
otherYulSources
);
if (m_experimentalAnalysis)
{
experimental::IRGenerator generator(
m_evmVersion,
m_eofVersion,
m_revertStrings,
sourceIndices(),
m_debugInfoSelection,
this,
*m_experimentalAnalysis
);
compiledContract.yulIR = generator.run(
_contract,
{}, // TODO: createCBORMetadata(compiledContract, /* _forIR */ true),
otherYulSources
);
}
else
{
IRGenerator generator(
m_evmVersion,
m_eofVersion,
m_revertStrings,
sourceIndices(),
m_debugInfoSelection,
this
);
compiledContract.yulIR = generator.run(
_contract,
createCBORMetadata(compiledContract, /* _forIR */ true),
otherYulSources
);
}
yul::YulStack stack(
m_evmVersion,
+7
View File
@@ -225,6 +225,13 @@ public:
/// @returns false on error.
bool analyze();
/// Perform the analysis steps of legacy language mode.
/// @returns false on error.
bool analyzeLegacy(bool _noErrorsSoFar);
/// Perform the analysis steps of experimental language mode.
/// @returns false on error.
bool analyzeExperimental();
/// Parses and analyzes all source units that were added
/// @returns false on error.
bool parseAndAnalyze(State _stopAfter = State::CompilationSuccessful);