OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [gold/] [int_encoding.h] - Diff between revs 27 and 166

Only display areas with differences | Details | Blame | View Log

Rev 27 Rev 166
// int_encoding.h -- variable length and unaligned integers -*- C++ -*-
// int_encoding.h -- variable length and unaligned integers -*- C++ -*-
 
 
// Copyright 2009 Free Software Foundation, Inc.
// Copyright 2009 Free Software Foundation, Inc.
// Written by Doug Kwan <dougkwan@google.com> by refactoring scattered
// Written by Doug Kwan <dougkwan@google.com> by refactoring scattered
// contents from other files in gold.  Original code written by Ian
// contents from other files in gold.  Original code written by Ian
// Lance Taylor <iant@google.com> and Caleb Howe  <cshowe@google.com>.
// Lance Taylor <iant@google.com> and Caleb Howe  <cshowe@google.com>.
 
 
// This file is part of gold.
// This file is part of gold.
 
 
// This program is free software; you can redistribute it and/or modify
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// (at your option) any later version.
 
 
// This program is distributed in the hope that it will be useful,
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// GNU General Public License for more details.
 
 
// You should have received a copy of the GNU General Public License
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
// MA 02110-1301, USA.
// MA 02110-1301, USA.
 
 
#ifndef GOLD_INT_ENCODING_H
#ifndef GOLD_INT_ENCODING_H
#define GOLD_INT_ENCODING_H
#define GOLD_INT_ENCODING_H
 
 
#include <vector>
#include <vector>
#include "elfcpp.h"
#include "elfcpp.h"
#include "target.h"
#include "target.h"
#include "parameters.h"
#include "parameters.h"
 
 
namespace gold
namespace gold
{
{
 
 
//
//
// LEB 128 encoding support.
// LEB 128 encoding support.
//
//
 
 
// Read a ULEB 128 encoded integer from BUFFER.  Return the length of the
// Read a ULEB 128 encoded integer from BUFFER.  Return the length of the
// encoded integer at the location PLEN. 
// encoded integer at the location PLEN.  The common case of a single-byte
 
// value is handled inline, and multi-byte values are processed by the _x
 
// routine, where BYTE is the first byte of the value.
 
 
uint64_t
uint64_t
read_unsigned_LEB_128(const unsigned char* buffer, size_t* plen);
read_unsigned_LEB_128_x(const unsigned char* buffer, size_t* plen,
 
                        unsigned char byte);
 
 
 
inline uint64_t
 
read_unsigned_LEB_128(const unsigned char* buffer, size_t* plen)
 
{
 
  unsigned char byte = *buffer++;
 
 
 
  if ((byte & 0x80) != 0)
 
    return read_unsigned_LEB_128_x(buffer, plen, byte);
 
 
 
  *plen = 1;
 
  return static_cast<uint64_t>(byte);
 
}
 
 
// Read an SLEB 128 encoded integer from BUFFER.  Return the length of the
// Read an SLEB 128 encoded integer from BUFFER.  Return the length of the
// encoded integer at the location PLEN. 
// encoded integer at the location PLEN.  The common case of a single-byte
 
// value is handled inline, and multi-byte values are processed by the _x
 
// routine, where BYTE is the first byte of the value.
 
 
int64_t
int64_t
read_signed_LEB_128(const unsigned char* buffer, size_t* plen);
read_signed_LEB_128_x(const unsigned char* buffer, size_t* plen,
 
                      unsigned char byte);
 
 
 
inline int64_t
 
read_signed_LEB_128(const unsigned char* buffer, size_t* plen)
 
{
 
  unsigned char byte = *buffer++;
 
 
 
  if ((byte & 0x80) != 0)
 
    return read_signed_LEB_128_x(buffer, plen, byte);
 
 
 
  *plen = 1;
 
  if (byte & 0x40)
 
    return -(static_cast<int64_t>(1) << 7) | static_cast<int64_t>(byte);
 
  return static_cast<int64_t>(byte);
 
}
 
 
// Write a ULEB 128 encoded VALUE to BUFFER.
// Write a ULEB 128 encoded VALUE to BUFFER.
 
 
void
void
write_unsigned_LEB_128(std::vector<unsigned char>* buffer, uint64_t value);
write_unsigned_LEB_128(std::vector<unsigned char>* buffer, uint64_t value);
 
 
// Return the ULEB 128 encoded size of VALUE.
// Return the ULEB 128 encoded size of VALUE.
 
 
size_t
size_t
get_length_as_unsigned_LEB_128(uint64_t value);
get_length_as_unsigned_LEB_128(uint64_t value);
 
 
//
//
// Unaligned integer encoding support.
// Unaligned integer encoding support.
//
//
 
 
// Insert VALSIZE-bit integer VALUE into DESTINATION.
// Insert VALSIZE-bit integer VALUE into DESTINATION.
 
 
template <int valsize>
template <int valsize>
void insert_into_vector(std::vector<unsigned char>* destination,
void insert_into_vector(std::vector<unsigned char>* destination,
                        typename elfcpp::Valtype_base<valsize>::Valtype value)
                        typename elfcpp::Valtype_base<valsize>::Valtype value)
{
{
  unsigned char buffer[valsize / 8];
  unsigned char buffer[valsize / 8];
  if (parameters->target().is_big_endian())
  if (parameters->target().is_big_endian())
    elfcpp::Swap_unaligned<valsize, true>::writeval(buffer, value);
    elfcpp::Swap_unaligned<valsize, true>::writeval(buffer, value);
  else
  else
    elfcpp::Swap_unaligned<valsize, false>::writeval(buffer, value);
    elfcpp::Swap_unaligned<valsize, false>::writeval(buffer, value);
  destination->insert(destination->end(), buffer, buffer + valsize / 8);
  destination->insert(destination->end(), buffer, buffer + valsize / 8);
}
}
 
 
// Read a possibly unaligned integer of SIZE from SOURCE.
// Read a possibly unaligned integer of SIZE from SOURCE.
 
 
template <int valsize>
template <int valsize>
typename elfcpp::Valtype_base<valsize>::Valtype
typename elfcpp::Valtype_base<valsize>::Valtype
read_from_pointer(const unsigned char* source)
read_from_pointer(const unsigned char* source)
{
{
  typename elfcpp::Valtype_base<valsize>::Valtype return_value;
  typename elfcpp::Valtype_base<valsize>::Valtype return_value;
  if (parameters->target().is_big_endian())
  if (parameters->target().is_big_endian())
    return_value = elfcpp::Swap_unaligned<valsize, true>::readval(source);
    return_value = elfcpp::Swap_unaligned<valsize, true>::readval(source);
  else
  else
    return_value = elfcpp::Swap_unaligned<valsize, false>::readval(source);
    return_value = elfcpp::Swap_unaligned<valsize, false>::readval(source);
  return return_value;
  return return_value;
}
}
 
 
// Read a possibly unaligned integer of SIZE.  Update SOURCE after read.
// Read a possibly unaligned integer of SIZE.  Update SOURCE after read.
 
 
template <int valsize>
template <int valsize>
typename elfcpp::Valtype_base<valsize>::Valtype
typename elfcpp::Valtype_base<valsize>::Valtype
read_from_pointer(unsigned char** source)
read_from_pointer(unsigned char** source)
{
{
  typename elfcpp::Valtype_base<valsize>::Valtype return_value;
  typename elfcpp::Valtype_base<valsize>::Valtype return_value;
  if (parameters->target().is_big_endian())
  if (parameters->target().is_big_endian())
    return_value = elfcpp::Swap_unaligned<valsize, true>::readval(*source);
    return_value = elfcpp::Swap_unaligned<valsize, true>::readval(*source);
  else
  else
    return_value = elfcpp::Swap_unaligned<valsize, false>::readval(*source);
    return_value = elfcpp::Swap_unaligned<valsize, false>::readval(*source);
  *source += valsize / 8;
  *source += valsize / 8;
  return return_value;
  return return_value;
}
}
 
 
// Same as the above except for use with const unsigned char data.
// Same as the above except for use with const unsigned char data.
 
 
template <int valsize>
template <int valsize>
typename elfcpp::Valtype_base<valsize>::Valtype
typename elfcpp::Valtype_base<valsize>::Valtype
read_from_pointer(const unsigned char** source)
read_from_pointer(const unsigned char** source)
{
{
  typename elfcpp::Valtype_base<valsize>::Valtype return_value;
  typename elfcpp::Valtype_base<valsize>::Valtype return_value;
  if (parameters->target().is_big_endian())
  if (parameters->target().is_big_endian())
    return_value = elfcpp::Swap_unaligned<valsize, true>::readval(*source);
    return_value = elfcpp::Swap_unaligned<valsize, true>::readval(*source);
  else
  else
    return_value = elfcpp::Swap_unaligned<valsize, false>::readval(*source);
    return_value = elfcpp::Swap_unaligned<valsize, false>::readval(*source);
  *source += valsize / 8;
  *source += valsize / 8;
  return return_value;
  return return_value;
}
}
 
 
} // End namespace gold.
} // End namespace gold.
 
 
#endif // !defined(GOLD_INT_ENCODING_H)
#endif // !defined(GOLD_INT_ENCODING_H)
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.