Skip to content

Commit

Permalink
Introduce Julia mode in AsmAnalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed May 26, 2017
1 parent 3b75c5b commit 8fe79fe
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion libsolidity/analysis/ReferencesResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly)

// Will be re-generated later with correct information
assembly::AsmAnalysisInfo analysisInfo;
assembly::AsmAnalyzer(analysisInfo, errorsIgnored, resolver).analyze(_inlineAssembly.operations());
assembly::AsmAnalyzer(analysisInfo, errorsIgnored, false, resolver).analyze(_inlineAssembly.operations());
return false;
}

Expand Down
1 change: 1 addition & 0 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
assembly::AsmAnalyzer analyzer(
*_inlineAssembly.annotation().analysisInfo,
m_errors,
false,
identifierAccess
);
if (!analyzer.analyze(_inlineAssembly.operations()))
Expand Down
9 changes: 6 additions & 3 deletions libsolidity/inlineasm/AsmAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ bool AsmAnalyzer::analyze(Block const& _block)

bool AsmAnalyzer::operator()(Label const& _label)
{
solAssert(!m_julia, "");
m_info.stackHeightInfo[&_label] = m_stackHeight;
return true;
}

bool AsmAnalyzer::operator()(assembly::Instruction const& _instruction)
{
solAssert(!m_julia, "");
auto const& info = instructionInfo(_instruction.instruction);
m_stackHeight += info.ret - info.args;
m_info.stackHeightInfo[&_instruction] = m_stackHeight;
Expand Down Expand Up @@ -135,6 +137,7 @@ bool AsmAnalyzer::operator()(assembly::Identifier const& _identifier)

bool AsmAnalyzer::operator()(FunctionalInstruction const& _instr)
{
solAssert(!m_julia, "");
bool success = true;
for (auto const& arg: _instr.arguments | boost::adaptors::reversed)
{
Expand All @@ -154,12 +157,12 @@ bool AsmAnalyzer::operator()(FunctionalInstruction const& _instr)

bool AsmAnalyzer::operator()(assembly::StackAssignment const& _assignment)
{
solAssert(!m_julia, "");
bool success = checkAssignment(_assignment.variableName, size_t(-1));
m_info.stackHeightInfo[&_assignment] = m_stackHeight;
return success;
}


bool AsmAnalyzer::operator()(assembly::Assignment const& _assignment)
{
int const stackHeight = m_stackHeight;
Expand Down Expand Up @@ -454,8 +457,8 @@ Scope& AsmAnalyzer::scope(Block const* _block)

void AsmAnalyzer::expectValidType(string const& type, SourceLocation const& _location)
{
// if (!m_julia)
// return;
if (!m_julia)
return;

if (!(set<string>{"bool", "u8", "s8", "u32", "s32", "u64", "s64", "u128", "s128", "u256", "s256"}).count(type))
m_errors.push_back(make_shared<Error>(
Expand Down
4 changes: 3 additions & 1 deletion libsolidity/inlineasm/AsmAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ class AsmAnalyzer: public boost::static_visitor<bool>
explicit AsmAnalyzer(
AsmAnalysisInfo& _analysisInfo,
ErrorList& _errors,
bool _julia = false,
julia::ExternalIdentifierAccess::Resolver const& _resolver = julia::ExternalIdentifierAccess::Resolver()
): m_resolver(_resolver), m_info(_analysisInfo), m_errors(_errors) {}
): m_resolver(_resolver), m_info(_analysisInfo), m_errors(_errors), m_julia(_julia) {}

bool analyze(assembly::Block const& _block);

Expand Down Expand Up @@ -99,6 +100,7 @@ class AsmAnalyzer: public boost::static_visitor<bool>
Scope* m_currentScope = nullptr;
AsmAnalysisInfo& m_info;
ErrorList& m_errors;
bool m_julia = false;
};

}
Expand Down
4 changes: 2 additions & 2 deletions libsolidity/inlineasm/AsmStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool InlineAssemblyStack::parse(

*m_parserResult = std::move(*result);
AsmAnalysisInfo analysisInfo;
return (AsmAnalyzer(analysisInfo, m_errors, _resolver)).analyze(*m_parserResult);
return (AsmAnalyzer(analysisInfo, m_errors, false, _resolver)).analyze(*m_parserResult);
}

string InlineAssemblyStack::toString()
Expand Down Expand Up @@ -84,7 +84,7 @@ bool InlineAssemblyStack::parseAndAssemble(
solAssert(parserResult, "");

AsmAnalysisInfo analysisInfo;
AsmAnalyzer analyzer(analysisInfo, errors, _identifierAccess.resolve);
AsmAnalyzer analyzer(analysisInfo, errors, false, _identifierAccess.resolve);
solAssert(analyzer.analyze(*parserResult), "");
CodeGenerator(errors).assemble(*parserResult, analysisInfo, _assembly, _identifierAccess);

Expand Down
2 changes: 1 addition & 1 deletion test/libjulia/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool parse(string const& _source, ErrorList& errors)
if (parserResult)
{
assembly::AsmAnalysisInfo analysisInfo;
return (assembly::AsmAnalyzer(analysisInfo, errors)).analyze(*parserResult);
return (assembly::AsmAnalyzer(analysisInfo, errors, true)).analyze(*parserResult);
}
}
catch (FatalError const&)
Expand Down

0 comments on commit 8fe79fe

Please sign in to comment.