2014-05-26 09:22:19 +00:00
|
|
|
/*
|
2017-02-02 10:06:28 +00:00
|
|
|
This file is part of solidity.
|
2014-05-26 09:22:19 +00:00
|
|
|
|
2017-02-02 10:06:28 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2014-05-26 09:22:19 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2017-02-02 10:06:28 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2014-05-26 09:22:19 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2017-02-02 10:06:28 +00:00
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2014-05-26 09:22:19 +00:00
|
|
|
*/
|
|
|
|
/** @file CodeFragment.h
|
|
|
|
* @author Gav Wood <i@gavwood.com>
|
|
|
|
* @date 2014
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-09-05 16:24:29 +00:00
|
|
|
#include <libdevcore/Common.h>
|
2016-04-01 20:11:01 +00:00
|
|
|
#include <libevmasm/Instruction.h>
|
2015-04-24 15:35:16 +00:00
|
|
|
#include <libevmasm/Assembly.h>
|
2014-05-26 09:22:19 +00:00
|
|
|
#include "Exceptions.h"
|
|
|
|
|
|
|
|
namespace boost { namespace spirit { class utree; } }
|
|
|
|
namespace sp = boost::spirit;
|
|
|
|
|
2014-09-05 15:09:58 +00:00
|
|
|
namespace dev
|
|
|
|
{
|
2014-05-26 09:22:19 +00:00
|
|
|
namespace eth
|
|
|
|
{
|
|
|
|
|
2014-06-04 10:34:14 +00:00
|
|
|
struct CompilerState;
|
2014-05-26 09:22:19 +00:00
|
|
|
|
|
|
|
class CodeFragment
|
|
|
|
{
|
|
|
|
public:
|
2017-10-02 12:17:52 +00:00
|
|
|
using ReadCallback = std::function<std::string(std::string const&)>;
|
|
|
|
|
2014-05-26 17:41:46 +00:00
|
|
|
CodeFragment() {}
|
2017-10-02 12:17:52 +00:00
|
|
|
CodeFragment(sp::utree const& _t, CompilerState& _s, ReadCallback const& _readFile, bool _allowASM = false);
|
2014-05-26 09:22:19 +00:00
|
|
|
|
2017-10-02 12:17:52 +00:00
|
|
|
static CodeFragment compile(std::string const& _src, CompilerState& _s, ReadCallback const& _readFile);
|
2014-05-26 09:22:19 +00:00
|
|
|
|
2014-05-26 17:41:46 +00:00
|
|
|
/// Consolidates data and compiles code.
|
2014-07-27 11:09:36 +00:00
|
|
|
Assembly& assembly(CompilerState const& _cs) { finalise(_cs); return m_asm; }
|
2014-05-26 09:22:19 +00:00
|
|
|
|
|
|
|
private:
|
2014-06-30 22:16:01 +00:00
|
|
|
void finalise(CompilerState const& _cs);
|
|
|
|
|
2017-08-21 21:05:24 +00:00
|
|
|
template <class T> static void error() { BOOST_THROW_EXCEPTION(T() ); }
|
|
|
|
template <class T> static void error(std::string const& reason) {
|
2016-10-26 12:47:32 +00:00
|
|
|
auto err = T();
|
|
|
|
err << errinfo_comment(reason);
|
|
|
|
BOOST_THROW_EXCEPTION(err);
|
|
|
|
}
|
2014-05-26 09:22:19 +00:00
|
|
|
void constructOperation(sp::utree const& _t, CompilerState& _s);
|
|
|
|
|
2014-06-30 22:16:01 +00:00
|
|
|
bool m_finalised = false;
|
2014-05-26 17:41:46 +00:00
|
|
|
Assembly m_asm;
|
2017-10-02 12:17:52 +00:00
|
|
|
ReadCallback m_readFile;
|
2014-05-26 09:22:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const CodeFragment NullCodeFragment;
|
|
|
|
|
|
|
|
}
|
2014-09-05 15:09:58 +00:00
|
|
|
}
|
2015-01-21 19:31:14 +00:00
|
|
|
|