Skip to content

Commit

Permalink
[Rule] Add alloc() for DynArrUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
totoroXD authored and dm4 committed Nov 20, 2018
1 parent 508cbb7 commit 466fe76
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions libsolidity/codegen/ContractCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ void ContractCompiler::appendRules(ContractDefinition const& _contract)
// rule init
for(auto rule: _contract.rules())
{
m_context << 32*3;
CompilerUtils(m_context).allocateMemory();
DynArrUtils(m_context, 1).alloc();
// lock_on_active listMaddr
m_context << keccak256(rule->name()+"-lockOnActive-list") << Instruction::SSTORE;
}

Expand Down
8 changes: 8 additions & 0 deletions libsolidity/codegen/DynArrUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ void DynArrUtils::popItem()
m_context << Instruction::POP;
}

// Stack pre :
// Stack post:
void DynArrUtils::alloc()
{
m_context << 32*3;
utils().allocateMemory();
}

// Stack pre : reference cap'(#elmts)
// Stack post:
void DynArrUtils::reAlloc()
Expand Down
4 changes: 3 additions & 1 deletion libsolidity/codegen/DynArrUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class DynArrUtils
/// Stack post: len
void getLen() { m_context << 32 << Instruction::ADD << Instruction::MLOAD; }

/// reallocate memory space and copy data to the new space
/// allocate memory space for array slice, which cost 32*3 bytes
void alloc();
/// reallocate data memory space and copy data to the new space
/// Stack pre : refer cap'
/// Stack post:
void reAlloc();
Expand Down
10 changes: 4 additions & 6 deletions libsolidity/codegen/RuleEngineCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ void RuleEngineCompiler::compile(TypeNode const& _node)
auto inListAddr = keccak256(_node.type()->richIdentifier()+"-factlist");
// listPtr(to memList) in storage
auto outListPtrAddr = _node.outAddr();
m_context << 32*3;
utils().allocateMemory();

DynArrUtils(m_context, 1).alloc();
m_context << outListPtrAddr << Instruction::SSTORE;

eth::AssemblyItem loopStart = m_context.newTag();
Expand Down Expand Up @@ -157,8 +157,7 @@ void RuleEngineCompiler::compile(AlphaNode const& _node)
auto inListPtrAddr = _node.parent()->outAddr();
auto outListPtrAddr = _node.outAddr();

m_context << 32*3;
utils().allocateMemory();
DynArrUtils(m_context, 1).alloc();
m_context << outListPtrAddr << Instruction::SSTORE;

m_context << inListPtrAddr << Instruction::SLOAD;
Expand Down Expand Up @@ -213,8 +212,7 @@ void RuleEngineCompiler::compile(JoinNode const& _node)
JoinNode const& left = *_node.leftParent();
AlphaNode const& right = *_node.rightParent();

m_context << 32*3;
utils().allocateMemory();
DynArrUtils(m_context, 1).alloc();
m_context << _node.outAddr() << Instruction::SSTORE;

m_context << right.outAddr() << Instruction::SLOAD;
Expand Down

0 comments on commit 466fe76

Please sign in to comment.