aboutsummaryrefslogtreecommitdiffstats
path: root/shell/e-shell-importer.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2008-04-23 10:11:32 +0800
committerMatthew Barnes <mbarnes@src.gnome.org>2008-04-23 10:11:32 +0800
commitd45f9bbd609b0068337fd345c927f9008f0f15f9 (patch)
tree50f2f2aed76875a72415d06a2af40fb27f3e313e /shell/e-shell-importer.c
parent69ca3b1c8141d61ec4c26028147005aa15c93ea5 (diff)
downloadgsoc2013-evolution-EVOLUTION_2_23_1.tar.gz
gsoc2013-evolution-EVOLUTION_2_23_1.tar.zst
gsoc2013-evolution-EVOLUTION_2_23_1.zip
** Fixes bug #458505EVOLUTION_2_23_1
2008-04-22 Matthew Barnes <mbarnes@redhat.com> ** Fixes bug #458505 * mail/mail-config.glade: One space between "Sender" and "Photograph". svn path=/trunk/; revision=35405
Diffstat (limited to 'shell/e-shell-importer.c')
0 files changed, 0 insertions, 0 deletions
'n109' href='#n109'>109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
/*
    This file is part of solidity.

    solidity 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.

    solidity 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 solidity.  If not, see <http://www.gnu.org/licenses/>.
*/
/**
 * Assembly interface for EVM and EVM1.5.
 */

#include <libjulia/backends/evm/EVMAssembly.h>

#include <libevmasm/Instruction.h>

#include <libsolidity/interface/Exceptions.h>

using namespace std;
using namespace dev;
using namespace julia;

namespace
{
/// Size of labels in bytes. Four-byte labels are required by some EVM1.5 instructions.
size_t constexpr labelReferenceSize = 4;
}


void EVMAssembly::setSourceLocation(SourceLocation const&)
{
    // Ignored for now;
}

void EVMAssembly::appendInstruction(solidity::Instruction _instr)
{
    m_bytecode.push_back(byte(_instr));
    m_stackHeight += solidity::instructionInfo(_instr).ret - solidity::instructionInfo(_instr).args;
}

void EVMAssembly::appendConstant(u256 const& _constant)
{
    bytes data = toCompactBigEndian(_constant, 1);
    appendInstruction(solidity::pushInstruction(data.size()));
    m_bytecode += data;
}

void EVMAssembly::appendLabel(LabelID _labelId)
{
    setLabelToCurrentPosition(_labelId);
    appendInstruction(solidity::Instruction::JUMPDEST);
}

void EVMAssembly::appendLabelReference(LabelID _labelId)
{
    solAssert(!m_evm15, "Cannot use plain label references in EMV1.5 mode.");
    // @TODO we now always use labelReferenceSize for all labels, it could be shortened
    // for some of them.
    appendInstruction(solidity::pushInstruction(labelReferenceSize));
    m_labelReferences[m_bytecode.size()] = _labelId;
    m_bytecode += bytes(labelReferenceSize);
}

EVMAssembly::LabelID EVMAssembly::newLabelId()
{
    m_labelPositions[m_nextLabelId] = size_t(-1);
    return m_nextLabelId++;
}

void EVMAssembly::appendLinkerSymbol(string const&)
{
    solAssert(false, "Linker symbols not yet implemented.");
}

void EVMAssembly::appendJump(int _stackDiffAfter)
{
    solAssert(!m_evm15, "Plain JUMP used for EVM 1.5");
    appendInstruction(solidity::Instruction::JUMP);
    m_stackHeight += _stackDiffAfter;
}

void EVMAssembly::appendJumpTo(LabelID _labelId, int _stackDiffAfter)
{
    if (m_evm15)
    {
        m_bytecode.push_back(byte(solidity::Instruction::JUMPTO));
        appendLabelReferenceInternal(_labelId);
        m_stackHeight += _stackDiffAfter;
    }
    else
    {
        appendLabelReference(_labelId);
        appendJump(_stackDiffAfter);
    }
}

void EVMAssembly::appendJumpToIf(LabelID _labelId)
{
    if (m_evm15)
    {
        m_bytecode.push_back(byte(solidity::Instruction::JUMPIF));
        appendLabelReferenceInternal(_labelId);
        m_stackHeight--;
    }
    else
    {
        appendLabelReference(_labelId);
        appendInstruction(solidity::Instruction::JUMPI);
    }
}

void EVMAssembly::appendBeginsub(LabelID _labelId, int _arguments)
{
    solAssert(m_evm15, "BEGINSUB used for EVM 1.0");
    solAssert(_arguments >= 0, "");
    setLabelToCurrentPosition(_labelId);
    m_bytecode.push_back(byte(solidity::Instruction::BEGINSUB));
    m_stackHeight += _arguments;
}

void EVMAssembly::appendJumpsub(LabelID _labelId, int _arguments, int _returns)
{
    solAssert(m_evm15, "JUMPSUB used for EVM 1.0");
    solAssert(_arguments >= 0 && _returns >= 0, "");
    m_bytecode.push_back(byte(solidity::Instruction::JUMPSUB));
    appendLabelReferenceInternal(_labelId);
    m_stackHeight += _returns - _arguments;
}

void EVMAssembly::appendReturnsub(int _returns, int _stackDiffAfter)
{
    solAssert(m_evm15, "RETURNSUB used for EVM 1.0");
    solAssert(_returns >= 0, "");
    m_bytecode.push_back(byte(solidity::Instruction::RETURNSUB));
    m_stackHeight += _stackDiffAfter - _returns;
}

eth::LinkerObject EVMAssembly::finalize()
{
    for (auto const& ref: m_labelReferences)
    {
        size_t referencePos = ref.first;
        solAssert(m_labelPositions.count(ref.second), "");
        size_t labelPos = m_labelPositions.at(ref.second);
        solAssert(labelPos != size_t(-1), "Undefined but allocated label used.");
        solAssert(m_bytecode.size() >= 4 && referencePos <= m_bytecode.size() - 4, "");
        solAssert(uint64_t(labelPos) < (uint64_t(1) << (8 * labelReferenceSize)), "");
        for (size_t i = 0; i < labelReferenceSize; i++)
            m_bytecode[referencePos + i] = byte((labelPos >> (8 * (labelReferenceSize - i - 1))) & 0xff);
    }
    eth::LinkerObject obj;
    obj.bytecode = m_bytecode;
    return obj;
}

void EVMAssembly::setLabelToCurrentPosition(LabelID _labelId)
{
    solAssert(m_labelPositions.count(_labelId), "Label not found.");
    solAssert(m_labelPositions[_labelId] == size_t(-1), "Label already set.");
    m_labelPositions[_labelId] = m_bytecode.size();
}

void EVMAssembly::appendLabelReferenceInternal(LabelID _labelId)
{
    m_labelReferences[m_bytecode.size()] = _labelId;
    m_bytecode += bytes(labelReferenceSize);
}