Skip to content

Commit

Permalink
Parse with indices expload#245
Browse files Browse the repository at this point in the history
  • Loading branch information
nevgeny committed Oct 22, 2018
1 parent f2ddf49 commit 6b25a53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion evm/src/main/scala/pravda/evm/parse/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ object Parser {

private val ops: P[Either[String, List[Op]]] = P(Start ~ op.rep ~ End).map(ops => sequence(ops.toList))

//private val opsWithIndices = P(Start ~ (Index ~ op).rep ~ End)
val opsWithIndices = P(Start ~ (Index ~ op).rep ~ End)

}
9 changes: 9 additions & 0 deletions evm/src/main/scala/pravda/evm/translate/Translator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import pravda.vm.asm
import cats.instances.list._
import cats.instances.either._
import cats.syntax.traverse._
import pravda.evm.EVM.{CodeCopy, Push}
import pravda.evm.translate.opcode.SimpleTranslation

object Translator {
Expand All @@ -30,4 +31,12 @@ object Translator {
ops.map(SimpleTranslation.evmOpToOps).sequence.map(_.flatten)
}

def translateActualContract(ops: List[(Int,EVM.Op)]): Either[String, List[asm.Operation]] = {
val offset = ops.takeWhile({case (_,CodeCopy) => false case _ => true}).reverse.tail.headOption match {
case Some((_,Push(address))) => BigInt(1,address.toArray).intValue()
case _ => throw new Exception("Parse error")
}
ops.flatMap({case(ind,op) => if (ind - offset < 0) None else Some((ind - offset,op)) })
}

}
2 changes: 2 additions & 0 deletions evm/src/test/scala/pravda/evm/parse/EvmTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ object EvmTests extends TestSuite {
'SimpleStorage - {
val bytes = evm.readSolidityBinFile("SimpleStorage.bin")

Parser.opsWithIndices.parse(bytes).get.value.foreach(println)

Parser(bytes) ==>
Right(
List(
Expand Down

0 comments on commit 6b25a53

Please sign in to comment.