diff options
author | CJentzsch <jentzsch.software@gmail.com> | 2014-12-14 04:40:42 +0800 |
---|---|---|
committer | CJentzsch <jentzsch.software@gmail.com> | 2014-12-14 04:40:42 +0800 |
commit | e00df9b681410ac8cfdeb9d3e6eb6287487c8f82 (patch) | |
tree | 03d95fa9bdcae7022050674c12b073bc84d8307a /solidityCompiler.cpp | |
parent | 66154817f9d7abde414ea8aec8cadec6313a763d (diff) | |
parent | 25faab7009d851eb3afca57c9891cd7c151be36e (diff) | |
download | dexon-solidity-e00df9b681410ac8cfdeb9d3e6eb6287487c8f82.tar.gz dexon-solidity-e00df9b681410ac8cfdeb9d3e6eb6287487c8f82.tar.zst dexon-solidity-e00df9b681410ac8cfdeb9d3e6eb6287487c8f82.zip |
Merge remote-tracking branch 'upstream/develop' into NewStateTests
Conflicts:
test/state.cpp
Diffstat (limited to 'solidityCompiler.cpp')
-rw-r--r-- | solidityCompiler.cpp | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/solidityCompiler.cpp b/solidityCompiler.cpp index ba2db67e..eae8f314 100644 --- a/solidityCompiler.cpp +++ b/solidityCompiler.cpp @@ -46,16 +46,23 @@ namespace bytes compileContract(const string& _sourceCode) { Parser parser; - ASTPointer<ContractDefinition> contract; - BOOST_REQUIRE_NO_THROW(contract = parser.parse(make_shared<Scanner>(CharStream(_sourceCode)))); - NameAndTypeResolver resolver; - BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract)); - - Compiler compiler; - compiler.compileContract(*contract); - // debug - //compiler.streamAssembly(cout); - return compiler.getAssembledBytecode(); + ASTPointer<SourceUnit> sourceUnit; + BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode)))); + NameAndTypeResolver resolver({}); + resolver.registerDeclarations(*sourceUnit); + for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) + if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) + { + BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract)); + + Compiler compiler; + compiler.compileContract(*contract, {}); + // debug + //compiler.streamAssembly(cout); + return compiler.getAssembledBytecode(); + } + BOOST_FAIL("No contract found in source."); + return bytes(); } /// Checks that @a _compiledCode is present starting from offset @a _offset in @a _expectation. @@ -80,7 +87,7 @@ BOOST_AUTO_TEST_CASE(smoke_test) "}\n"; bytes code = compileContract(sourceCode); - unsigned boilerplateSize = 51; + unsigned boilerplateSize = 40; bytes expectation({byte(Instruction::JUMPDEST), byte(Instruction::PUSH1), 0x0, // initialize local variable x byte(Instruction::PUSH1), 0x2, @@ -100,8 +107,8 @@ BOOST_AUTO_TEST_CASE(different_argument_numbers) "}\n"; bytes code = compileContract(sourceCode); - unsigned shift = 75; - unsigned boilerplateSize = 88; + unsigned shift = 68; + unsigned boilerplateSize = 81; bytes expectation({byte(Instruction::JUMPDEST), byte(Instruction::PUSH1), 0x0, // initialize return variable d byte(Instruction::DUP3), @@ -118,8 +125,8 @@ BOOST_AUTO_TEST_CASE(different_argument_numbers) byte(Instruction::JUMP), // end of f byte(Instruction::JUMPDEST), // beginning of g byte(Instruction::PUSH1), 0x0, - byte(Instruction::DUP1), // initialized e and h - byte(Instruction::PUSH1), byte(0x29 + shift), // ret address + byte(Instruction::PUSH1), 0x0, // initialized e and h + byte(Instruction::PUSH1), byte(0x2a + shift), // ret address byte(Instruction::PUSH1), 0x1, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND), byte(Instruction::PUSH1), 0x2, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND), byte(Instruction::PUSH1), 0x3, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND), @@ -128,8 +135,6 @@ BOOST_AUTO_TEST_CASE(different_argument_numbers) byte(Instruction::JUMP), byte(Instruction::JUMPDEST), // stack here: ret e h f(1,2,3) - byte(Instruction::DUP2), - byte(Instruction::POP), byte(Instruction::SWAP1), // stack here: ret e f(1,2,3) h byte(Instruction::POP), @@ -153,8 +158,8 @@ BOOST_AUTO_TEST_CASE(ifStatement) "}\n"; bytes code = compileContract(sourceCode); - unsigned shift = 38; - unsigned boilerplateSize = 51; + unsigned shift = 27; + unsigned boilerplateSize = 40; bytes expectation({byte(Instruction::JUMPDEST), byte(Instruction::PUSH1), 0x0, byte(Instruction::DUP1), @@ -195,8 +200,8 @@ BOOST_AUTO_TEST_CASE(loops) "}\n"; bytes code = compileContract(sourceCode); - unsigned shift = 38; - unsigned boilerplateSize = 51; + unsigned shift = 27; + unsigned boilerplateSize = 40; bytes expectation({byte(Instruction::JUMPDEST), byte(Instruction::JUMPDEST), byte(Instruction::PUSH1), 0x1, |