2014-05-26 09:22:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of cpp-ethereum.
|
|
|
|
|
|
|
|
cpp-ethereum is free software: you can redistribute it and/or modify
|
|
|
|
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.
|
|
|
|
|
|
|
|
cpp-ethereum is distributed in the hope that it will be useful,
|
|
|
|
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
|
|
|
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
/** @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:
|
2014-05-26 17:41:46 +00:00
|
|
|
CodeFragment() {}
|
2014-05-26 09:22:19 +00:00
|
|
|
CodeFragment(sp::utree const& _t, CompilerState& _s, bool _allowASM = false);
|
|
|
|
|
|
|
|
static CodeFragment compile(std::string const& _src, CompilerState& _s);
|
|
|
|
|
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);
|
|
|
|
|
2014-10-02 12:20:33 +00:00
|
|
|
template <class T> void error() const { BOOST_THROW_EXCEPTION(T() ); }
|
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;
|
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
|
|
|
|