<commit_before>#define _ERROR_
#define _IMG_

#include "SUPPORT/betaSet.h"
#include "SUPPORT/alphaSet.h"
#include "SUPPORT/delone10.h"
#include "SUPPORT/window2.h"
#include "SUPPORT/generate3.h"
#include "SUPPORT/geometricObject2.h"

#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <list>
#include <mpi.h>
#include <string>
#include <chrono>

#define MASTER 0        /* task ID of master task */

typedef alphaSet numberType;
typedef circle<numberType> windowType;

int main (int argc, char* argv[])
{

  // time measuring
  std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();

  int	taskid;
  int numtasks;
  int nodeid;
  int nodes;
  int rc;

  std::string buffer;
  std::string send_buffer;
  int length;

  std::list<std::string> res;
  std::list<std::string> data;
  std::list<std::string>::iterator iterator;

  MPI_Status status;

  // initialize
  numberType winSize(3, -1);
  Cpoint<numberType> origin( numberType::get(0,0), numberType::get(0,0) );

  std::string clipTileStr = "(0+1*beta)/2,(-1+2*beta)/2 (0+0*beta)/2,(0+1*beta)/1 (-1+2*beta)/2,(0+1*beta)/2 (0-1*beta)/2,(-1+2*beta)/2 (0+1*beta)/1,(0+0*beta)/4 (1-2*beta)/2,(0+1*beta)/2 (0+0*beta)/4,(0+0*beta)/4 (-1+2*beta)/2,(0-1*beta)/2 (0-1*beta)/1,(0+0*beta)/4 (0+1*beta)/2,(1-2*beta)/2 (1-2*beta)/2,(0-1*beta)/2 (0+0*beta)/2,(0-1*beta)/1 (0-1*beta)/2,(1-2*beta)/2 ";

  windowType win( winSize );
  win.center( origin );

  // hyperquasicrystal
  rhombus<numberType> *circ = dynamic_cast<rhombus<numberType>*> ( win.circumscribed() );

  // hypoquasicrystal
  rhombus<numberType> *insc = dynamic_cast<rhombus<numberType>*> ( win.inscribed() );

  numberType S = circ->Xwindow().Small();
  numberType L = insc->Xwindow().Large();

  numberType coveringR = numberType::coveringR()*L;

  // size of rhumbus circumscribed to covering radius disc
  numberType lengthToCover = numberType::get(8, 0)*coveringR;

  CvoronoiCell<numberType>::large = numberType::get(2, 0)*coveringR;

  // find out the word length by testing
  int wordLength = 1;
  do
  {
    ++wordLength;
  } while ( minWord(language(circ->Xwindow(), wordLength), circ->Xwindow()) < lengthToCover );

  //wordLength = 5;

  /* Obtain number of tasks and task ID */
  MPI_Init(&argc,&argv);
  MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
  MPI_Comm_rank(MPI_COMM_WORLD,&taskid);

  std::cout << std::string(4, ' ') << "MPI task " << taskid << " has started..." << std::endl;

  nodes = numtasks-1;
  nodeid = taskid-1;

  if (taskid != MASTER) // NODE ----------------------------------------
  {
    CvoronoiCell<numberType> clipTile;
    clipTile.load(clipTileStr);
    *clipTile.CarrierSet = *clipTile.CarrierSet*numberType(0,1);

    do
    {
      MPI_Probe(MASTER, MPI_ANY_TAG, MPI_COMM_WORLD, &status);

      MPI_Get_count(&status, MPI_CHAR, &length);
      char *cache = new char[length];

      MPI_Recv(cache, length, MPI_CHAR, MASTER, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
      buffer = std::string(cache, length);
      delete [] cache;

      //std::cout << std::string(4, ' ') << taskid << ": received " << buffer << " status: " << status.MPI_TAG << std::endl;

      //std::cout << "  node " << taskid << " data received" << std::endl;

      if (status.MPI_TAG == 0)
      {

        // process data ------------------------------------------------
        std::string word1 = buffer.substr(0, buffer.length()/2);
        std::string word2 = buffer.substr(buffer.length()/2);
        CdeloneSet10<numberType> delone = quasicrystal2D10(circ->Xwindow(), word1, word2);

        //delone << *clipTile.CarrierSet;

        delone.setPackingR();
        delone.setCoveringR(numberType::get(2, 0)*coveringR);
        delone.setDescription(word1+word2);
        delone.sortPotentialByDistance();

        delone.sortByDistance();

        std::list<CdeloneSet10<numberType> > delones;
        std::list<CvoronoiCell<numberType> > cells;
        delones.push_back(delone);

        for (std::list<CdeloneSet10<numberType> >::iterator it = delones.begin(); it != delones.end(); it = delones.begin())
        {
          //std::cout << "SIZE POTENTIAL: " << it->sizePotential() << std::endl;
          //it->filterPotentialByWindow(win);

          CvoronoiCell<numberType> voronoi;

          *(voronoi.CarrierSet) = *it;

          voronoi.CarrierSet->sort();
          voronoi.CarrierSet->unique();

          voronoi.CarrierSet->sortByDistance();
          voronoi.CarrierSet->setPackingR();
          voronoi.CarrierSet->setCoveringR(CvoronoiCell<numberType>::large);
          voronoi.setCenter(origin);
          voronoi.construct();
          voronoi.filterSet();

          std::list<Cpoint<numberType> > potential;
          potential = it->getPotential();
          voronoi.filterSetPotential( &potential );
          it->clearPotential();
          it->addPotential(potential);

          //std::cout << "SIZE POTENTIAL: " << it->sizePotential() << '\t' << "SIZE DELONES: " << delones.size() << std::endl;

          // deal with potential
          while (it->isPotential())
          {
            Cpoint<numberType> cache = it->popPotential();

            delone = *it;
            delone << cache;
            delones.push_back(delone);
          }

          cells.push_back( voronoi );

          delones.erase(it);

          delones.sort();
          delones.unique();

          //std::cout << "  node " << taskid << " delones: " << delones.size() << std::endl;
        }

        cells.sort();
        cells.unique();

        std::list<std::string> list;

        for (std::list<CvoronoiCell<numberType> >::iterator it = cells.begin(); it != cells.end(); ++it)
        {
          list.push_back(it->save());
        }

        list.sort();
        list.unique();
        // end ---------------------------------------------------------

        //std::cout << "  node " << taskid << " sending back: " << list.size() << std::endl;

        for (std::list<std::string>::iterator it = list.begin(); it != --list.end(); ++it)
        {
          send_buffer = *it;
          // return result
          MPI_Send(send_buffer.c_str(), send_buffer.length(), MPI_CHAR, MASTER, 0, MPI_COMM_WORLD);
        }

        send_buffer = *list.rbegin();
        // return result
        MPI_Send(send_buffer.c_str(), send_buffer.length(), MPI_CHAR, MASTER, 1, MPI_COMM_WORLD);
      }
    } while (status.MPI_TAG == 0);
  }
  else // MASTER -------------------------------------------------------
  {
    // create data -----------------------------------------------------
    std::cout << "Load data" << std::endl;

    std::list<std::string> lang = language( insc->Xwindow(), circ->Xwindow(), wordLength );
    for ( std::list<std::string>::iterator it = lang.begin(); it != lang.end(); ++it )
    {
      for ( std::list<std::string>::iterator ot = lang.begin(); ot != lang.end(); ++ot )
      {
        data.push_back(*it+*ot);
      }
    }

    std::cout << "tasks: " << data.size() << std::endl;
    std::cout << "word length: " << wordLength << std::endl;

    iterator = data.begin();

    int count = 0;
    // send initial load of data
    std::cout << "Send initial load of data" << std::endl;
    for (int it = 0; it < nodes; ++it)
    {
      send_buffer = *(iterator++);

      //std::cout << std::string(4, ' ') << "MASTER sending: " << iterator << "/168" << std::endl;

      MPI_Send(send_buffer.c_str(), send_buffer.length(), MPI_CHAR, it+1, 0, MPI_COMM_WORLD);
      count++;
    }

    // gather data while processing
    std::cout << "distribute the rest on demand" << std::endl;
    while (iterator != data.end())
    {
      //std::cout << "waiting" << std::endl;
      MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);

      MPI_Get_count(&status, MPI_CHAR, &length);
      char *cache = new char[length];
      MPI_Recv(cache, length, MPI_CHAR, status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
      buffer = std::string(cache, length);
      delete [] cache;

      // save result
      res.push_back(buffer);
      //std::cout << "finished: " << res.size() << std::endl;

      while (status.MPI_TAG == 0)
      {
        MPI_Probe(status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);

        MPI_Get_count(&status, MPI_CHAR, &length);
        char *cache = new char[length];
        MPI_Recv(cache, length, MPI_CHAR, status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
        buffer = std::string(cache, length);
        delete [] cache;

        // save result
        res.push_back(buffer);
        //std::cout << "finished: " << res.size() << std::endl;
      }

      //std::cout << std::string(4, ' ') << "MASTER received from: " << status.MPI_SOURCE << " sending: " << iterator << std::endl;

      send_buffer = *(iterator++);

      MPI_Send(send_buffer.c_str(), send_buffer.length(), MPI_CHAR, status.MPI_SOURCE, 0, MPI_COMM_WORLD);

      count++;
      if ((20*count)%data.size() == 0)
      {
        std::cout << "processed " << count << "/" << data.size() << " <=> " << 10*count/data.size() << "0%" << std::endl;
      }
    }

    // terminate processes
    std::cout << "termination" << std::endl;
    for (int it = 0; it < nodes; ++it)
    {
      MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);

      MPI_Get_count(&status, MPI_CHAR, &length);
      char *cache = new char[length];
      MPI_Recv(cache, length, MPI_CHAR, status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
      buffer = std::string(cache, length);
      delete [] cache;

      // save result
      res.push_back(buffer);
      std::cout << "finished: " << res.size() << std::endl;

      //std::cout << std::string(4, ' ') << "MASTER received from: " << status.MPI_SOURCE << " - " << buffer << std::endl;

      send_buffer = std::to_string(0);

      rc = MPI_Send(send_buffer.c_str(), send_buffer.length(), MPI_CHAR, it+1, 1, MPI_COMM_WORLD);
    }

    // write to file
    std::ostringstream convert;
    convert << argv[1] << "_" << wordLength << "_";
    printFile(convert, winSize);

    std::ofstream output(convert.str().c_str());
    res.sort();
    res.unique();

    print(output, winSize);
    output << std::endl;
    for (std::list<std::string>::iterator it = res.begin(); it != res.end(); ++it)
    {
      output << *it << std::endl;
    }
    output.close();
  }

  std::cout << std::string(4, ' ') << "... MPI task " << taskid << " is closing" << std::endl;
  MPI_Finalize();

  // time measuring
  std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
  auto duration = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();
  std::cout << "microseconds: " << duration << " (" << std::round(duration/100000.0)/10.0 << "s)" << std::endl;

  return 0;
}
<commit_msg>increased verbosity<commit_after>#define _ERROR_
#define _IMG_

#include "SUPPORT/betaSet.h"
#include "SUPPORT/alphaSet.h"
#include "SUPPORT/delone10.h"
#include "SUPPORT/window2.h"
#include "SUPPORT/generate3.h"
#include "SUPPORT/geometricObject2.h"

#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <list>
#include <mpi.h>
#include <string>
#include <chrono>

#define MASTER 0        /* task ID of master task */

typedef alphaSet numberType;
typedef circle<numberType> windowType;

int main (int argc, char* argv[])
{

  // time measuring
  std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();

  int	taskid;
  int numtasks;
  int nodeid;
  int nodes;
  int rc;

  std::string buffer;
  std::string send_buffer;
  int length;

  std::list<std::string> res;
  std::list<std::string> data;
  std::list<std::string>::iterator iterator;

  MPI_Status status;

  // initialize
  numberType winSize(3, -1);
  Cpoint<numberType> origin( numberType::get(0,0), numberType::get(0,0) );

  std::string clipTileStr = "(0+1*beta)/2,(-1+2*beta)/2 (0+0*beta)/2,(0+1*beta)/1 (-1+2*beta)/2,(0+1*beta)/2 (0-1*beta)/2,(-1+2*beta)/2 (0+1*beta)/1,(0+0*beta)/4 (1-2*beta)/2,(0+1*beta)/2 (0+0*beta)/4,(0+0*beta)/4 (-1+2*beta)/2,(0-1*beta)/2 (0-1*beta)/1,(0+0*beta)/4 (0+1*beta)/2,(1-2*beta)/2 (1-2*beta)/2,(0-1*beta)/2 (0+0*beta)/2,(0-1*beta)/1 (0-1*beta)/2,(1-2*beta)/2 ";

  windowType win( winSize );
  win.center( origin );

  // hyperquasicrystal
  rhombus<numberType> *circ = dynamic_cast<rhombus<numberType>*> ( win.circumscribed() );

  // hypoquasicrystal
  rhombus<numberType> *insc = dynamic_cast<rhombus<numberType>*> ( win.inscribed() );

  numberType S = circ->Xwindow().Small();
  numberType L = insc->Xwindow().Large();

  numberType coveringR = numberType::coveringR()*L;

  // size of rhumbus circumscribed to covering radius disc
  numberType lengthToCover = numberType::get(8, 0)*coveringR;

  CvoronoiCell<numberType>::large = numberType::get(2, 0)*coveringR;

  // find out the word length by testing
  int wordLength = 1;
  do
  {
    ++wordLength;
  } while ( minWord(language(circ->Xwindow(), wordLength), circ->Xwindow()) < lengthToCover );

  //wordLength = 7;

  /* Obtain number of tasks and task ID */
  MPI_Init(&argc,&argv);
  MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
  MPI_Comm_rank(MPI_COMM_WORLD,&taskid);

  std::cout << std::string(4, ' ') << "MPI task " << taskid << " has started..." << std::endl;

  nodes = numtasks-1;
  nodeid = taskid-1;

  if (taskid != MASTER) // NODE ----------------------------------------
  {
    CvoronoiCell<numberType> clipTile;
    clipTile.load(clipTileStr);
    *clipTile.CarrierSet = *clipTile.CarrierSet*numberType(0,1);

    do
    {
      MPI_Probe(MASTER, MPI_ANY_TAG, MPI_COMM_WORLD, &status);

      MPI_Get_count(&status, MPI_CHAR, &length);
      char *cache = new char[length];

      MPI_Recv(cache, length, MPI_CHAR, MASTER, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
      buffer = std::string(cache, length);
      delete [] cache;

      //std::cout << std::string(4, ' ') << taskid << ": received " << buffer << " status: " << status.MPI_TAG << std::endl;

      std::cout << "  node " << taskid << " data received" << std::endl;

      if (status.MPI_TAG == 0)
      {

        // process data ------------------------------------------------
        std::string word1 = buffer.substr(0, buffer.length()/2);
        std::string word2 = buffer.substr(buffer.length()/2);
        CdeloneSet10<numberType> delone = quasicrystal2D10(circ->Xwindow(), word1, word2);

        //delone << *clipTile.CarrierSet;

        delone.setPackingR();
        delone.setCoveringR(numberType::get(2, 0)*coveringR);
        delone.setDescription(word1+word2);
        delone.sortPotentialByDistance();

        delone.sortByDistance();

        std::list<CdeloneSet10<numberType> > delones;
        std::list<CvoronoiCell<numberType> > cells;
        delones.push_back(delone);

        for (std::list<CdeloneSet10<numberType> >::iterator it = delones.begin(); it != delones.end(); it = delones.begin())
        {
          //std::cout << "SIZE POTENTIAL: " << it->sizePotential() << std::endl;
          it->filterPotentialByWindow(win);

          CvoronoiCell<numberType> voronoi;

          *(voronoi.CarrierSet) = *it;

          voronoi.CarrierSet->sort();
          voronoi.CarrierSet->unique();

          voronoi.CarrierSet->sortByDistance();
          voronoi.CarrierSet->setPackingR();
          voronoi.CarrierSet->setCoveringR(CvoronoiCell<numberType>::large);
          voronoi.setCenter(origin);
          voronoi.construct();
          voronoi.filterSet();

          std::list<Cpoint<numberType> > potential;
          potential = it->getPotential();
          voronoi.filterSetPotential( &potential );
          it->clearPotential();
          it->addPotential(potential);

          //std::cout << "SIZE POTENTIAL: " << it->sizePotential() << '\t' << "SIZE DELONES: " << delones.size() << std::endl;

          // deal with potential
          while (it->isPotential())
          {
            Cpoint<numberType> cache = it->popPotential();

            delone = *it;
            delone << cache;
            delones.push_back(delone);
          }

          cells.push_back( voronoi );

          delones.erase(it);

          delones.sort();
          delones.unique();

          //std::cout << "  node " << taskid << " delones: " << delones.size() << std::endl;
        }

        cells.sort();
        cells.unique();

        std::list<std::string> list;

        for (std::list<CvoronoiCell<numberType> >::iterator it = cells.begin(); it != cells.end(); ++it)
        {
          list.push_back(it->save());
        }

        list.sort();
        list.unique();
        // end ---------------------------------------------------------

        std::cout << "  node " << taskid << " sending back: " << list.size() << std::endl;

        for (std::list<std::string>::iterator it = list.begin(); it != --list.end(); ++it)
        {
          send_buffer = *it;
          // return result
          MPI_Send(send_buffer.c_str(), send_buffer.length(), MPI_CHAR, MASTER, 0, MPI_COMM_WORLD);
        }

        send_buffer = *list.rbegin();
        // return result
        MPI_Send(send_buffer.c_str(), send_buffer.length(), MPI_CHAR, MASTER, 1, MPI_COMM_WORLD);
      }
    } while (status.MPI_TAG == 0);
  }
  else // MASTER -------------------------------------------------------
  {
    // create data -----------------------------------------------------
    std::cout << "Load data" << std::endl;

    std::list<std::string> lang = language( insc->Xwindow(), circ->Xwindow(), wordLength );
    for ( std::list<std::string>::iterator it = lang.begin(); it != lang.end(); ++it )
    {
      for ( std::list<std::string>::iterator ot = lang.begin(); ot != lang.end(); ++ot )
      {
        data.push_back(*it+*ot);
      }
    }

    std::cout << "tasks: " << data.size() << std::endl;
    std::cout << "word length: " << wordLength << std::endl;

    iterator = data.begin();

    int count = 0;
    // send initial load of data
    std::cout << "Send initial load of data" << std::endl;
    for (int it = 0; it < nodes; ++it)
    {
      send_buffer = *(iterator++);

      //std::cout << std::string(4, ' ') << "MASTER sending: " << iterator << "/168" << std::endl;

      MPI_Send(send_buffer.c_str(), send_buffer.length(), MPI_CHAR, it+1, 0, MPI_COMM_WORLD);
      count++;
    }

    // gather data while processing
    std::cout << "distribute the rest on demand" << std::endl;
    while (iterator != data.end())
    {
      //std::cout << "waiting" << std::endl;
      MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);

      MPI_Get_count(&status, MPI_CHAR, &length);
      char *cache = new char[length];
      MPI_Recv(cache, length, MPI_CHAR, status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
      buffer = std::string(cache, length);
      delete [] cache;

      // save result
      res.push_back(buffer);
      std::cout << "finished: " << res.size() << std::endl;

      while (status.MPI_TAG == 0)
      {
        MPI_Probe(status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);

        MPI_Get_count(&status, MPI_CHAR, &length);
        char *cache = new char[length];
        MPI_Recv(cache, length, MPI_CHAR, status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
        buffer = std::string(cache, length);
        delete [] cache;

        // save result
        res.push_back(buffer);
        std::cout << "finished: " << res.size() << std::endl;
      }

      //std::cout << std::string(4, ' ') << "MASTER received from: " << status.MPI_SOURCE << " sending: " << iterator << std::endl;

      send_buffer = *(iterator++);

      MPI_Send(send_buffer.c_str(), send_buffer.length(), MPI_CHAR, status.MPI_SOURCE, 0, MPI_COMM_WORLD);

      count++;
      if ((20*count)%data.size() == 0)
      {
        std::cout << "processed " << count << "/" << data.size() << " <=> " << 10*count/data.size() << "0%" << std::endl;
      }
    }

    // terminate processes
    std::cout << "termination" << std::endl;
    for (int it = 0; it < nodes; ++it)
    {
      MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);

      MPI_Get_count(&status, MPI_CHAR, &length);
      char *cache = new char[length];
      MPI_Recv(cache, length, MPI_CHAR, status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
      buffer = std::string(cache, length);
      delete [] cache;

      // save result
      res.push_back(buffer);
      std::cout << "finished: " << res.size() << std::endl;

      //std::cout << std::string(4, ' ') << "MASTER received from: " << status.MPI_SOURCE << " - " << buffer << std::endl;

      send_buffer = std::to_string(0);

      rc = MPI_Send(send_buffer.c_str(), send_buffer.length(), MPI_CHAR, it+1, 1, MPI_COMM_WORLD);
    }

    // write to file
    std::ostringstream convert;
    convert << argv[1] << "_" << wordLength << "_";
    printFile(convert, winSize);

    std::ofstream output(convert.str().c_str());
    res.sort();
    res.unique();

    print(output, winSize);
    output << std::endl;
    for (std::list<std::string>::iterator it = res.begin(); it != res.end(); ++it)
    {
      output << *it << std::endl;
    }
    output.close();
  }

  std::cout << std::string(4, ' ') << "... MPI task " << taskid << " is closing" << std::endl;
  MPI_Finalize();

  // time measuring
  std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
  auto duration = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();
  std::cout << "microseconds: " << duration << " (" << std::round(duration/100000.0)/10.0 << "s)" << std::endl;

  return 0;
}
<|endoftext|>


<commit_before>/*
 * Copyright (c) 2003-2005 The Regents of The University of Michigan
 * Copyright (c) 2007 MIPS Technologies, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met: redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer;
 * redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution;
 * neither the name of the copyright holders nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Authors: Gabe Black
 *          Ali Saidi
 *          Korey Sewell
 */

#ifndef __ARCH_MIPS_REGFILE_REGFILE_HH__
#define __ARCH_MIPS_REGFILE_REGFILE_HH__

#include "arch/mips/types.hh"
#include "arch/mips/isa_traits.hh"
#include "arch/mips/mt.hh"
#include "arch/mips/regfile/misc_regfile.hh"
#include "sim/faults.hh"

class Checkpoint;
class ThreadContext;

using namespace MipsISA;

void RegFile::clear()
{
    miscRegFile.clear();
}

void
RegFile::reset(std::string core_name, ThreadID num_threads,
               unsigned num_vpes)
{
    miscRegFile.reset(core_name, num_threads, num_vpes);
}

MiscReg
RegFile::readMiscRegNoEffect(int miscReg, ThreadID tid = 0)
{
    return miscRegFile.readRegNoEffect(miscReg, tid);
}

MiscReg
RegFile::readMiscReg(int miscReg, ThreadContext *tc, ThreadID tid = 0)
{
    return miscRegFile.readReg(miscReg, tc, tid);
}

void
RegFile::setMiscRegNoEffect(int miscReg, const MiscReg &val, ThreadID tid = 0)
{
    miscRegFile.setRegNoEffect(miscReg, val, tid);
}

void
RegFile::setMiscReg(int miscReg, const MiscReg &val,
                    ThreadContext *tc, ThreadID tid = 0)
{
    miscRegFile.setReg(miscReg, val, tc, tid);
}

Addr RegFile::readPC()
{
    return pc;
}

void RegFile::setPC(Addr val)
{
    pc = val;
}

Addr RegFile::readNextPC()
{
    return npc;
}

void RegFile::setNextPC(Addr val)
{
    npc = val;
}

Addr RegFile::readNextNPC()
{
    return nnpc;
}

void RegFile::setNextNPC(Addr val)
{
    nnpc = val;
}

void
RegFile::serialize(std::ostream &os)
{
    miscRegFile.serialize(os);

    SERIALIZE_SCALAR(pc);
    SERIALIZE_SCALAR(npc);
    SERIALIZE_SCALAR(nnpc);
}

void
RegFile::unserialize(Checkpoint *cp, const std::string &section)
{
    miscRegFile.unserialize(cp, section);
    UNSERIALIZE_SCALAR(pc);
    UNSERIALIZE_SCALAR(npc);
    UNSERIALIZE_SCALAR(nnpc);

}

void
MipsISA::copyRegs(ThreadContext *src, ThreadContext *dest)
{
    panic("Copy Regs Not Implemented Yet\n");
}

void
MipsISA::copyMiscRegs(ThreadContext *src, ThreadContext *dest)
{
    panic("Copy Misc. Regs Not Implemented Yet\n");
}
<commit_msg>MIPS: Get rid of an orphaned MIPS .cc file.<commit_after><|endoftext|>


<commit_before><commit_msg>Control: add infor in preprocessor_submodule for paladin<commit_after><|endoftext|>


<commit_before>#include "Athena/FileReader.hpp"
#include "Athena/FileNotFoundException.hpp"
#include "Athena/InvalidDataException.hpp"
#include "Athena/InvalidOperationException.hpp"
#include "Athena/IOException.hpp"

#if _WIN32
#include "win32_largefilewrapper.h"
#elif __APPLE__
#include "osx_largefilewrapper.h"
#endif

namespace Athena
{
namespace io
{
FileReader::FileReader(const std::string& filename, atInt32 cacheSize)
    : m_filename(filename),
      m_fileHandle(nullptr),
      m_cacheData(nullptr),
      m_offset(0)
{
    setCacheSize(cacheSize);
    open();
}

FileReader::~FileReader()
{
    if (isOpen())
        close();
}

void FileReader::open()
{
    m_fileHandle = fopen(m_filename.c_str(), "rb");

    if (!m_fileHandle)
        THROW_FILE_NOT_FOUND_EXCEPTION(m_filename);

    // ensure we're at the beginning of the file
    rewind(m_fileHandle);
}

void FileReader::close()
{
    if (!m_fileHandle)
        THROW_INVALID_OPERATION_EXCEPTION("Cannot close an unopened stream");

    fclose(m_fileHandle);
    m_fileHandle = NULL;
    return;
}

void FileReader::seek(atInt64 pos, SeekOrigin origin)
{
    // check block position
    if (m_blockSize > 0)
    {
        atUint64 oldOff = m_offset;
        switch(origin)
        {
            case SeekOrigin::Begin:
                m_offset = pos;
                break;
            case SeekOrigin::Current:
                m_offset += pos;
                break;
            case SeekOrigin::End:
                m_offset = length() - pos;
                break;
        }
        if (m_offset > length())
        {
            oldOff = m_offset;
            THROW_INVALID_OPERATION_EXCEPTION("Unable to seek in file");
        }

        size_t block = m_offset / m_blockSize;
        if (block != m_curBlock)
        {
            fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
            fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
            m_curBlock = block;
        }
    }
    else if (fseeko64(m_fileHandle, pos, (int)origin) != 0)
        THROW_INVALID_OPERATION_EXCEPTION("Unable to seek in file");
}

atUint64 FileReader::position() const
{
    if (!isOpen())
        THROW_INVALID_OPERATION_EXCEPTION_RETURN(0, "File not open");

    if (m_blockSize > 0)
        return m_offset;
    else
        return ftello64(m_fileHandle);
}

atUint64 FileReader::length() const
{
    if (!isOpen())
        THROW_INVALID_OPERATION_EXCEPTION_RETURN(0, "File not open");

    return utility::fileSize(m_filename);
}

atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len)
{
    if (!isOpen())
        THROW_INVALID_OPERATION_EXCEPTION_RETURN(0, "File not open for reading");

    if (m_blockSize <= 0)
        return fread(buf, 1, len, m_fileHandle);
    else
    {
        size_t block = m_offset / m_blockSize;
        atUint64 cacheOffset = m_offset % m_blockSize;
        atUint64 cacheSize;
        atUint64 rem = len;
        atUint8* dst = (atUint8*)buf;

        while (rem)
        {
            if (block != m_curBlock)
            {
                fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
                fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
                m_curBlock = block;
            }

            cacheSize = rem;
            if (cacheSize + cacheOffset > m_blockSize)
                cacheSize = m_blockSize - cacheOffset;

            memcpy(dst, m_cacheData.get() + cacheOffset, cacheSize);
            dst += cacheSize;
            rem -= cacheSize;
            cacheOffset = 0;
            ++block;
        }
        m_offset += len;
        return dst - (atUint8*)buf;
    }
}

void FileReader::setCacheSize(const atInt32 blockSize)
{
    m_blockSize = blockSize;

    if (m_blockSize > length())
        m_blockSize = length();

    m_curBlock = -1;
    if (m_blockSize > 0)
        m_cacheData.reset(new atUint8[m_blockSize]);
}

} // io
} // Athena
<commit_msg>Un-derpified major derp<commit_after>#include "Athena/FileReader.hpp"
#include "Athena/FileNotFoundException.hpp"
#include "Athena/InvalidDataException.hpp"
#include "Athena/InvalidOperationException.hpp"
#include "Athena/IOException.hpp"

#if _WIN32
#include "win32_largefilewrapper.h"
#elif __APPLE__
#include "osx_largefilewrapper.h"
#endif

namespace Athena
{
namespace io
{
FileReader::FileReader(const std::string& filename, atInt32 cacheSize)
    : m_filename(filename),
      m_fileHandle(nullptr),
      m_cacheData(nullptr),
      m_offset(0)
{
    open();
    setCacheSize(cacheSize);
}

FileReader::~FileReader()
{
    if (isOpen())
        close();
}

void FileReader::open()
{
    m_fileHandle = fopen(m_filename.c_str(), "rb");

    if (!m_fileHandle)
        THROW_FILE_NOT_FOUND_EXCEPTION(m_filename);

    // ensure we're at the beginning of the file
    rewind(m_fileHandle);
}

void FileReader::close()
{
    if (!m_fileHandle)
        THROW_INVALID_OPERATION_EXCEPTION("Cannot close an unopened stream");

    fclose(m_fileHandle);
    m_fileHandle = NULL;
    return;
}

void FileReader::seek(atInt64 pos, SeekOrigin origin)
{
    // check block position
    if (m_blockSize > 0)
    {
        atUint64 oldOff = m_offset;
        switch(origin)
        {
            case SeekOrigin::Begin:
                m_offset = pos;
                break;
            case SeekOrigin::Current:
                m_offset += pos;
                break;
            case SeekOrigin::End:
                m_offset = length() - pos;
                break;
        }
        if (m_offset > length())
        {
            oldOff = m_offset;
            THROW_INVALID_OPERATION_EXCEPTION("Unable to seek in file");
        }

        size_t block = m_offset / m_blockSize;
        if (block != m_curBlock)
        {
            fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
            fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
            m_curBlock = block;
        }
    }
    else if (fseeko64(m_fileHandle, pos, (int)origin) != 0)
        THROW_INVALID_OPERATION_EXCEPTION("Unable to seek in file");
}

atUint64 FileReader::position() const
{
    if (!isOpen())
        THROW_INVALID_OPERATION_EXCEPTION_RETURN(0, "File not open");

    if (m_blockSize > 0)
        return m_offset;
    else
        return ftello64(m_fileHandle);
}

atUint64 FileReader::length() const
{
    if (!isOpen())
        THROW_INVALID_OPERATION_EXCEPTION_RETURN(0, "File not open");

    return utility::fileSize(m_filename);
}

atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len)
{
    if (!isOpen())
        THROW_INVALID_OPERATION_EXCEPTION_RETURN(0, "File not open for reading");

    if (m_blockSize <= 0)
        return fread(buf, 1, len, m_fileHandle);
    else
    {
        size_t block = m_offset / m_blockSize;
        atUint64 cacheOffset = m_offset % m_blockSize;
        atUint64 cacheSize;
        atUint64 rem = len;
        atUint8* dst = (atUint8*)buf;

        while (rem)
        {
            if (block != m_curBlock)
            {
                fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
                fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
                m_curBlock = block;
            }

            cacheSize = rem;
            if (cacheSize + cacheOffset > m_blockSize)
                cacheSize = m_blockSize - cacheOffset;

            memcpy(dst, m_cacheData.get() + cacheOffset, cacheSize);
            dst += cacheSize;
            rem -= cacheSize;
            cacheOffset = 0;
            ++block;
        }
        m_offset += len;
        return dst - (atUint8*)buf;
    }
}

void FileReader::setCacheSize(const atInt32 blockSize)
{
    m_blockSize = blockSize;

    if (m_blockSize > length())
        m_blockSize = length();

    m_curBlock = -1;
    if (m_blockSize > 0)
        m_cacheData.reset(new atUint8[m_blockSize]);
}

} // io
} // Athena
<|endoftext|>


<commit_before>// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s

// rdar://8818236
namespace rdar8818236 {
struct S {
  char c2;
  union {
    char c;
    int i;
  };
};

// CHECK: @_ZN11rdar88182363fooE = global i64 4
char S::*foo  = &S::c;
}

struct A {
  union {
    int a;
    void* b;
  };

  A() : a(0) { }
};

A a;

namespace PR7021 {
  struct X
  {
    union { long l; };
  };

  // CHECK: define void @_ZN6PR70211fENS_1XES0_
  void f(X x, X z) {
    X x1;

    // CHECK: store i64 1, i64
    x1.l = 1;

    // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
    X x2(x1);

    X x3;
    // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
    x3 = x1;

    // CHECK: ret void
  }
}

namespace test2 {
  struct A {
    struct {
      union {
        int b;
      };
    };

    A();
  };

  A::A() : b(10) { }
  // CHECK: define void @_ZN5test21AC2Ev(
  // CHECK-NOT: }
  // CHECK: store i32 10
  // CHECK: }
}

namespace test3 {
  struct A {
    union {
      mutable char fibers[100];
      struct {
        void (*callback)(void*);
        void *callback_value;
      };
    };

    A();
  };

  A::A() : callback(0), callback_value(0) {}
  // CHECK: define void @_ZN5test31AC2Ev(
  // CHECK: [[THIS:%.*]] = load
  // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0
  // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to
  // CHECK-NEXT: [[CALLBACK:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 0
  // CHECK: store {{.*}}* null, {{.*}}** [[CALLBACK]]
  // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0
  // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to
  // CHECK-NEXT: [[CVALUE:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 1
  // CHECK-NEXT: store i8* null, i8** [[CVALUE]]
}

struct S {
  // CHECK: store i32 42
  // CHECK: store i32 55
  S() : x(42), y(55) {}
  union {
    struct {
      int x;
      union { int y; };
    };
  };
} s;

//PR8760
template <typename T> struct Foo {
  Foo() : ptr(__nullptr) {}
  union {
    T *ptr;
  };
};
Foo<int> f;
<commit_msg>relax this test a bit to hopefully work with VC++<commit_after>// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s

// rdar://8818236
namespace rdar8818236 {
struct S {
  char c2;
  union {
    char c;
    int i;
  };
};

// CHECK: @_ZN11rdar88182363fooE = global i64 4
char S::*foo  = &S::c;
}

struct A {
  union {
    int a;
    void* b;
  };

  A() : a(0) { }
};

A a;

namespace PR7021 {
  struct X
  {
    union { long l; };
  };

  // CHECK: define void @_ZN6PR70211fENS_1XES0_
  void f(X x, X z) {
    X x1;

    // CHECK: store i64 1, i64
    x1.l = 1;

    // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
    X x2(x1);

    X x3;
    // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
    x3 = x1;

    // CHECK: ret void
  }
}

namespace test2 {
  struct A {
    struct {
      union {
        int b;
      };
    };

    A();
  };

  A::A() : b(10) { }
  // CHECK: define void @_ZN5test21AC2Ev(
  // CHECK-NOT: }
  // CHECK: store i32 10
  // CHECK: }
}

namespace test3 {
  struct A {
    union {
      mutable char fibers[100];
      struct {
        void (*callback)(void*);
        void *callback_value;
      };
    };

    A();
  };

  A::A() : callback(0), callback_value(0) {}
  // CHECK: define void @_ZN5test31AC2Ev(
  // CHECK: [[THIS:%.*]] = load
  // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0
  // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to
  // CHECK-NEXT: [[CALLBACK:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 0
  // CHECK: store
  // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0
  // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to
  // CHECK-NEXT: [[CVALUE:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 1
  // CHECK-NEXT: store i8* null, i8** [[CVALUE]]
}

struct S {
  // CHECK: store i32 42
  // CHECK: store i32 55
  S() : x(42), y(55) {}
  union {
    struct {
      int x;
      union { int y; };
    };
  };
} s;

//PR8760
template <typename T> struct Foo {
  Foo() : ptr(__nullptr) {}
  union {
    T *ptr;
  };
};
Foo<int> f;
<|endoftext|>


<commit_before>/*
 * Copyright (c) 2007 The Hewlett-Packard Development Company
 * All rights reserved.
 *
 * Redistribution and use of this software in source and binary forms,
 * with or without modification, are permitted provided that the
 * following conditions are met:
 *
 * The software must be used only for Non-Commercial Use which means any
 * use which is NOT directed to receiving any direct monetary
 * compensation for, or commercial advantage from such use.  Illustrative
 * examples of non-commercial use are academic research, personal study,
 * teaching, education and corporate research & development.
 * Illustrative examples of commercial use are distributing products for
 * commercial advantage and providing services using the software for
 * commercial advantage.
 *
 * If you wish to use this software or functionality therein that may be
 * covered by patents for commercial use, please contact:
 *     Director of Intellectual Property Licensing
 *     Office of Strategy and Technology
 *     Hewlett-Packard Company
 *     1501 Page Mill Road
 *     Palo Alto, California  94304
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.  Redistributions
 * in binary form must reproduce the above copyright notice, this list of
 * conditions and the following disclaimer in the documentation and/or
 * other materials provided with the distribution.  Neither the name of
 * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.  No right of
 * sublicense is granted herewith.  Derivatives of the software and
 * output created using the software may be prepared, but only for
 * Non-Commercial Uses.  Derivatives of the software may be shared with
 * others provided: (i) the others agree to abide by the list of
 * conditions herein which includes the Non-Commercial Use restrictions;
 * and (ii) such Derivatives of the software include the above copyright
 * notice to acknowledge the contribution from this software where
 * applicable, this list of conditions and the disclaimer below.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Authors: Gabe Black
 */

#ifndef __ARCH_X86_MISCREGS_HH__
#define __ARCH_X86_MISCREGS_HH__

#include "base/bitunion.hh"

namespace X86ISA
{
    enum CondFlagBit {
        CFBit = 1 << 0,
        PFBit = 1 << 2,
        ECFBit = 1 << 3,
        AFBit = 1 << 4,
        EZFBit = 1 << 5,
        ZFBit = 1 << 6,
        SFBit = 1 << 7,
        OFBit = 1 << 11
    };

    enum MiscRegIndex
    {
        // Control registers
        // Most of these are invalid.
        MISCREG_CR0,
        MISCREG_CR1,
        MISCREG_CR2,
        MISCREG_CR3,
        MISCREG_CR4,
        MISCREG_CR5,
        MISCREG_CR6,
        MISCREG_CR7,
        MISCREG_CR8,
        MISCREG_CR9,
        MISCREG_CR10,
        MISCREG_CR11,
        MISCREG_CR12,
        MISCREG_CR13,
        MISCREG_CR14,
        MISCREG_CR15,

        // Debug registers
        MISCREG_DR0,
        MISCREG_DR1,
        MISCREG_DR2,
        MISCREG_DR3,
        MISCREG_DR4,
        MISCREG_DR5,
        MISCREG_DR6,
        MISCREG_DR7,

        // Flags register
        MISCREG_RFLAGS,

        // Segment selectors
        MISCREG_ES,
        MISCREG_CS,
        MISCREG_SS,
        MISCREG_DS,
        MISCREG_FS,
        MISCREG_GS,

        // Hidden segment base field
        MISCREG_ES_BASE,
        MISCREG_CS_BASE,
        MISCREG_SS_BASE,
        MISCREG_DS_BASE,
        MISCREG_FS_BASE,
        MISCREG_GS_BASE,

        // Hidden segment limit field
        MISCREG_ES_LIMIT,
        MISCREG_CS_LIMIT,
        MISCREG_SS_LIMIT,
        MISCREG_DS_LIMIT,
        MISCREG_FS_LIMIT,
        MISCREG_GS_LIMIT,

        // Hidden segment limit attributes
        MISCREG_ES_ATTR,
        MISCREG_CS_ATTR,
        MISCREG_SS_ATTR,
        MISCREG_DS_ATTR,
        MISCREG_FS_ATTR,
        MISCREG_GS_ATTR,

        // System segment selectors
        MISCREG_LDTR,
        MISCREG_TR,

        // Hidden system segment base field
        MISCREG_LDTR_BASE,
        MISCREG_TR_BASE,
        MISCREG_GDTR_BASE,
        MISCREG_IDTR_BASE,

        // Hidden system segment limit field
        MISCREG_LDTR_LIMIT,
        MISCREG_TR_LIMIT,
        MISCREG_GDTR_LIMIT,
        MISCREG_IDTR_LIMIT,

        // Hidden system segment attribute field
        MISCREG_LDTR_ATTR,
        MISCREG_TR_ATTR,

        //XXX Add "Model-Specific Registers"

        NUM_MISCREGS
    };

    /**
     * A type to describe the condition code bits of the RFLAGS register,
     * plus two flags, EZF and ECF, which are only visible to microcode.
     */
    BitUnion64(CCFlagBits)
        Bitfield<11> OF;
        Bitfield<7> SF;
        Bitfield<6> ZF;
        Bitfield<5> EZF;
        Bitfield<4> AF;
        Bitfield<3> ECF;
        Bitfield<2> PF;
        Bitfield<0> CF;
    EndBitUnion(CCFlagBits)

    /**
     * RFLAGS
     */
    BitUnion64(RFLAGS)
        Bitfield<21> ID; // ID Flag
        Bitfield<20> VIP; // Virtual Interrupt Pending
        Bitfield<19> VIF; // Virtual Interrupt Flag
        Bitfield<18> AC; // Alignment Check
        Bitfield<17> VM; // Virtual-8086 Mode
        Bitfield<16> RF; // Resume Flag
        Bitfield<14> NT; // Nested Task
        Bitfield<13, 12> IOPL; // I/O Privilege Level
        Bitfield<11> OF; // Overflow Flag
        Bitfield<10> DF; // Direction Flag
        Bitfield<9> IF; // Interrupt Flag
        Bitfield<8> TF; // Trap Flag
        Bitfield<7> SF; // Sign Flag
        Bitfield<6> ZF; // Zero Flag
        Bitfield<4> AF; // Auxiliary Flag
        Bitfield<2> PF; // Parity Flag
        Bitfield<0> CF; // Carry Flag
    EndBitUnion(RFLAGS)

    /**
     * Control registers
     */
    BitUnion64(CR0)
        Bitfield<31> PG; // Paging
        Bitfield<30> CD; // Cache Disable
        Bitfield<29> NW; // Not Writethrough
        Bitfield<18> AM; // Alignment Mask
        Bitfield<16> WP; // Write Protect
        Bitfield<5> NE; // Numeric Error
        Bitfield<4> ET; // Extension Type
        Bitfield<3> TS; // Task Switched
        Bitfield<2> EM; // Emulation
        Bitfield<1> MP; // Monitor Coprocessor
        Bitfield<0> PE; // Protection Enabled
    EndBitUnion(CR0)

    // Page Fault Virtual Address
    BitUnion64(CR2)
        Bitfield<31, 0> legacy;
    EndBitUnion(CR2)

    BitUnion64(CR3)
        Bitfield<51, 12> longPDTB; // Long Mode Page-Directory-Table
                                   // Base Address
        Bitfield<31, 12> PDTB; // Non-PAE Addressing Page-Directory-Table
                               // Base Address
        Bitfield<31, 5> PAEPDTB; // PAE Addressing Page-Directory-Table
                                 // Base Address
        Bitfield<4> PCD; // Page-Level Cache Disable
        Bitfield<3> PWT; // Page-Level Writethrough
    EndBitUnion(CR3)

    BitUnion64(CR4)
        Bitfield<10> OSXMMEXCPT; // Operating System Unmasked
                                 // Exception Support
        Bitfield<9> OSFXSR; // Operating System FXSave/FSRSTOR Support
        Bitfield<8> PCE; // Performance-Monitoring Counter Enable
        Bitfield<7> PGE; // Page-Global Enable
        Bitfield<6> MCE; // Machine Check Enable
        Bitfield<5> PAE; // Physical-Address Extension
        Bitfield<4> PSE; // Page Size Extensions
        Bitfield<3> DE; // Debugging Extensions
        Bitfield<2> TSD; // Time Stamp Disable
        Bitfield<1> PVI; // Protected-Mode Virtual Interrupts
        Bitfield<0> VME; // Virtual-8086 Mode Extensions
    EndBitUnion(CR4)

    BitUnion64(CR8)
        Bitfield<3, 0> TPR; // Task Priority Register
    EndBitUnion(CR4)

    /**
     * Segment Selector
     */
    BitUnion64(SegSelector)
        Bitfield<15, 3> SI; // Selector Index
        Bitfield<2> TI; // Table Indicator
        Bitfield<1, 0> RPL; // Requestor Privilege Level
    EndBitUnion(SegSelector)

    /**
     * Segment Descriptors
     */

    BitUnion64(SegDescriptor)
        Bitfield<63, 56> baseHigh;
        Bitfield<39, 16> baseLow;
        Bitfield<55> G; // Granularity
        Bitfield<54> D; // Default Operand Size
        Bitfield<54> B; // Default Operand Size
        Bitfield<53> L; // Long Attribute Bit
        Bitfield<52> AVL; // Available To Software
        Bitfield<51, 48> limitHigh;
        Bitfield<15, 0> limitLow;
        Bitfield<47> P; // Present
        Bitfield<46, 45> DPL; // Descriptor Privilege-Level
        Bitfield<44> S; // System
        SubBitUnion(type, 43, 40)
            // Specifies whether this descriptor is for code or data.
            Bitfield<43> codeOrData;

            // These bit fields are for code segments
            Bitfield<42> C; // Conforming
            Bitfield<41> R; // Readable

            // These bit fields are for data segments
            Bitfield<42> E; // Expand-Down
            Bitfield<41> W; // Writable

            // This is used for both code and data segments.
            Bitfield<40> A; // Accessed
        EndSubBitUnion(type)
    EndBitUnion(SegDescriptor)

    BitUnion64(GateDescriptor)
        Bitfield<63, 48> offsetHigh; // Target Code-Segment Offset
        Bitfield<15, 0> offsetLow; // Target Code-Segment Offset
        Bitfield<31, 16> selector; // Target Code-Segment Selector
        Bitfield<47> P; // Present
        Bitfield<46, 45> DPL; // Descriptor Privilege-Level
        Bitfield<43, 40> type;
        Bitfield<36, 32> count; // Parameter Count
    EndBitUnion(GateDescriptor)

    /**
     * Descriptor-Table Registers
     */
    BitUnion64(GDTR)
    EndBitUnion(GDTR)

    BitUnion64(IDTR)
    EndBitUnion(IDTR)

    BitUnion64(LDTR)
    EndBitUnion(LDTR)

    /**
     * Task Register
     */
    BitUnion64(TR)
    EndBitUnion(TR)
};

#endif // __ARCH_X86_INTREGS_HH__
<commit_msg>X86: Create a base enum value for indexing into a region of the miscregs. This lets you index into a group of registers without having to know explicitly which one is the lowest in that group.<commit_after>/*
 * Copyright (c) 2007 The Hewlett-Packard Development Company
 * All rights reserved.
 *
 * Redistribution and use of this software in source and binary forms,
 * with or without modification, are permitted provided that the
 * following conditions are met:
 *
 * The software must be used only for Non-Commercial Use which means any
 * use which is NOT directed to receiving any direct monetary
 * compensation for, or commercial advantage from such use.  Illustrative
 * examples of non-commercial use are academic research, personal study,
 * teaching, education and corporate research & development.
 * Illustrative examples of commercial use are distributing products for
 * commercial advantage and providing services using the software for
 * commercial advantage.
 *
 * If you wish to use this software or functionality therein that may be
 * covered by patents for commercial use, please contact:
 *     Director of Intellectual Property Licensing
 *     Office of Strategy and Technology
 *     Hewlett-Packard Company
 *     1501 Page Mill Road
 *     Palo Alto, California  94304
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.  Redistributions
 * in binary form must reproduce the above copyright notice, this list of
 * conditions and the following disclaimer in the documentation and/or
 * other materials provided with the distribution.  Neither the name of
 * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.  No right of
 * sublicense is granted herewith.  Derivatives of the software and
 * output created using the software may be prepared, but only for
 * Non-Commercial Uses.  Derivatives of the software may be shared with
 * others provided: (i) the others agree to abide by the list of
 * conditions herein which includes the Non-Commercial Use restrictions;
 * and (ii) such Derivatives of the software include the above copyright
 * notice to acknowledge the contribution from this software where
 * applicable, this list of conditions and the disclaimer below.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Authors: Gabe Black
 */

#ifndef __ARCH_X86_MISCREGS_HH__
#define __ARCH_X86_MISCREGS_HH__

#include "base/bitunion.hh"

namespace X86ISA
{
    enum CondFlagBit {
        CFBit = 1 << 0,
        PFBit = 1 << 2,
        ECFBit = 1 << 3,
        AFBit = 1 << 4,
        EZFBit = 1 << 5,
        ZFBit = 1 << 6,
        SFBit = 1 << 7,
        OFBit = 1 << 11
    };

    enum MiscRegIndex
    {
        // Control registers
        // Most of these are invalid.
        MISCREG_CR_BASE,
        MISCREG_CR0 = MISCREG_CR_BASE,
        MISCREG_CR1,
        MISCREG_CR2,
        MISCREG_CR3,
        MISCREG_CR4,
        MISCREG_CR5,
        MISCREG_CR6,
        MISCREG_CR7,
        MISCREG_CR8,
        MISCREG_CR9,
        MISCREG_CR10,
        MISCREG_CR11,
        MISCREG_CR12,
        MISCREG_CR13,
        MISCREG_CR14,
        MISCREG_CR15,

        // Debug registers
        MISCREG_DR_BASE,
        MISCREG_DR0 = MISCREG_DR_BASE,
        MISCREG_DR1,
        MISCREG_DR2,
        MISCREG_DR3,
        MISCREG_DR4,
        MISCREG_DR5,
        MISCREG_DR6,
        MISCREG_DR7,

        // Flags register
        MISCREG_RFLAGS,

        // Segment selectors
        MISCREG_SEG_SEL_BASE,
        MISCREG_ES = MISCREG_SEG_SEL_BASE,
        MISCREG_CS,
        MISCREG_SS,
        MISCREG_DS,
        MISCREG_FS,
        MISCREG_GS,

        // Hidden segment base field
        MISCREG_SEG_BASE_BASE,
        MISCREG_ES_BASE = MISCREG_SEG_BASE_BASE,
        MISCREG_CS_BASE,
        MISCREG_SS_BASE,
        MISCREG_DS_BASE,
        MISCREG_FS_BASE,
        MISCREG_GS_BASE,

        // Hidden segment limit field
        MISCREG_SEG_LIMIT_BASE,
        MISCREG_ES_LIMIT = MISCREG_SEG_LIMIT_BASE,
        MISCREG_CS_LIMIT,
        MISCREG_SS_LIMIT,
        MISCREG_DS_LIMIT,
        MISCREG_FS_LIMIT,
        MISCREG_GS_LIMIT,

        // Hidden segment limit attributes
        MISCREG_SEG_ATTR_BASE,
        MISCREG_ES_ATTR = MISCREG_SEG_ATTR_BASE,
        MISCREG_CS_ATTR,
        MISCREG_SS_ATTR,
        MISCREG_DS_ATTR,
        MISCREG_FS_ATTR,
        MISCREG_GS_ATTR,

        // System segment selectors
        MISCREG_SYSSEG_SEL_BASE,
        MISCREG_LDTR = MISCREG_SYSSEG_SEL_BASE,
        MISCREG_TR,

        // Hidden system segment base field
        MISCREG_SYSSEG_BASE_BASE,
        MISCREG_LDTR_BASE = MISCREG_SYSSEG_BASE_BASE,
        MISCREG_TR_BASE,
        MISCREG_GDTR_BASE,
        MISCREG_IDTR_BASE,

        // Hidden system segment limit field
        MISCREG_SYSSEG_LIMIT_BASE,
        MISCREG_LDTR_LIMIT = MISCREG_SYSSEG_LIMIT_BASE,
        MISCREG_TR_LIMIT,
        MISCREG_GDTR_LIMIT,
        MISCREG_IDTR_LIMIT,

        // Hidden system segment attribute field
        MISCREG_SYSSEG_ATTR_BASE,
        MISCREG_LDTR_ATTR = MISCREG_SYSSEG_ATTR_BASE,
        MISCREG_TR_ATTR,

        //XXX Add "Model-Specific Registers"

        NUM_MISCREGS
    };

    /**
     * A type to describe the condition code bits of the RFLAGS register,
     * plus two flags, EZF and ECF, which are only visible to microcode.
     */
    BitUnion64(CCFlagBits)
        Bitfield<11> OF;
        Bitfield<7> SF;
        Bitfield<6> ZF;
        Bitfield<5> EZF;
        Bitfield<4> AF;
        Bitfield<3> ECF;
        Bitfield<2> PF;
        Bitfield<0> CF;
    EndBitUnion(CCFlagBits)

    /**
     * RFLAGS
     */
    BitUnion64(RFLAGS)
        Bitfield<21> ID; // ID Flag
        Bitfield<20> VIP; // Virtual Interrupt Pending
        Bitfield<19> VIF; // Virtual Interrupt Flag
        Bitfield<18> AC; // Alignment Check
        Bitfield<17> VM; // Virtual-8086 Mode
        Bitfield<16> RF; // Resume Flag
        Bitfield<14> NT; // Nested Task
        Bitfield<13, 12> IOPL; // I/O Privilege Level
        Bitfield<11> OF; // Overflow Flag
        Bitfield<10> DF; // Direction Flag
        Bitfield<9> IF; // Interrupt Flag
        Bitfield<8> TF; // Trap Flag
        Bitfield<7> SF; // Sign Flag
        Bitfield<6> ZF; // Zero Flag
        Bitfield<4> AF; // Auxiliary Flag
        Bitfield<2> PF; // Parity Flag
        Bitfield<0> CF; // Carry Flag
    EndBitUnion(RFLAGS)

    /**
     * Control registers
     */
    BitUnion64(CR0)
        Bitfield<31> PG; // Paging
        Bitfield<30> CD; // Cache Disable
        Bitfield<29> NW; // Not Writethrough
        Bitfield<18> AM; // Alignment Mask
        Bitfield<16> WP; // Write Protect
        Bitfield<5> NE; // Numeric Error
        Bitfield<4> ET; // Extension Type
        Bitfield<3> TS; // Task Switched
        Bitfield<2> EM; // Emulation
        Bitfield<1> MP; // Monitor Coprocessor
        Bitfield<0> PE; // Protection Enabled
    EndBitUnion(CR0)

    // Page Fault Virtual Address
    BitUnion64(CR2)
        Bitfield<31, 0> legacy;
    EndBitUnion(CR2)

    BitUnion64(CR3)
        Bitfield<51, 12> longPDTB; // Long Mode Page-Directory-Table
                                   // Base Address
        Bitfield<31, 12> PDTB; // Non-PAE Addressing Page-Directory-Table
                               // Base Address
        Bitfield<31, 5> PAEPDTB; // PAE Addressing Page-Directory-Table
                                 // Base Address
        Bitfield<4> PCD; // Page-Level Cache Disable
        Bitfield<3> PWT; // Page-Level Writethrough
    EndBitUnion(CR3)

    BitUnion64(CR4)
        Bitfield<10> OSXMMEXCPT; // Operating System Unmasked
                                 // Exception Support
        Bitfield<9> OSFXSR; // Operating System FXSave/FSRSTOR Support
        Bitfield<8> PCE; // Performance-Monitoring Counter Enable
        Bitfield<7> PGE; // Page-Global Enable
        Bitfield<6> MCE; // Machine Check Enable
        Bitfield<5> PAE; // Physical-Address Extension
        Bitfield<4> PSE; // Page Size Extensions
        Bitfield<3> DE; // Debugging Extensions
        Bitfield<2> TSD; // Time Stamp Disable
        Bitfield<1> PVI; // Protected-Mode Virtual Interrupts
        Bitfield<0> VME; // Virtual-8086 Mode Extensions
    EndBitUnion(CR4)

    BitUnion64(CR8)
        Bitfield<3, 0> TPR; // Task Priority Register
    EndBitUnion(CR4)

    /**
     * Segment Selector
     */
    BitUnion64(SegSelector)
        Bitfield<15, 3> SI; // Selector Index
        Bitfield<2> TI; // Table Indicator
        Bitfield<1, 0> RPL; // Requestor Privilege Level
    EndBitUnion(SegSelector)

    /**
     * Segment Descriptors
     */

    BitUnion64(SegDescriptor)
        Bitfield<63, 56> baseHigh;
        Bitfield<39, 16> baseLow;
        Bitfield<55> G; // Granularity
        Bitfield<54> D; // Default Operand Size
        Bitfield<54> B; // Default Operand Size
        Bitfield<53> L; // Long Attribute Bit
        Bitfield<52> AVL; // Available To Software
        Bitfield<51, 48> limitHigh;
        Bitfield<15, 0> limitLow;
        Bitfield<47> P; // Present
        Bitfield<46, 45> DPL; // Descriptor Privilege-Level
        Bitfield<44> S; // System
        SubBitUnion(type, 43, 40)
            // Specifies whether this descriptor is for code or data.
            Bitfield<43> codeOrData;

            // These bit fields are for code segments
            Bitfield<42> C; // Conforming
            Bitfield<41> R; // Readable

            // These bit fields are for data segments
            Bitfield<42> E; // Expand-Down
            Bitfield<41> W; // Writable

            // This is used for both code and data segments.
            Bitfield<40> A; // Accessed
        EndSubBitUnion(type)
    EndBitUnion(SegDescriptor)

    BitUnion64(GateDescriptor)
        Bitfield<63, 48> offsetHigh; // Target Code-Segment Offset
        Bitfield<15, 0> offsetLow; // Target Code-Segment Offset
        Bitfield<31, 16> selector; // Target Code-Segment Selector
        Bitfield<47> P; // Present
        Bitfield<46, 45> DPL; // Descriptor Privilege-Level
        Bitfield<43, 40> type;
        Bitfield<36, 32> count; // Parameter Count
    EndBitUnion(GateDescriptor)

    /**
     * Descriptor-Table Registers
     */
    BitUnion64(GDTR)
    EndBitUnion(GDTR)

    BitUnion64(IDTR)
    EndBitUnion(IDTR)

    BitUnion64(LDTR)
    EndBitUnion(LDTR)

    /**
     * Task Register
     */
    BitUnion64(TR)
    EndBitUnion(TR)
};

#endif // __ARCH_X86_INTREGS_HH__
<|endoftext|>


<commit_before>// RUN: %check_clang_tidy %s misc-forwarding-reference-overload %t -- -- -std=c++14

namespace std {
template <bool B, class T = void>
struct enable_if { typedef T type; };

template <class T>
struct enable_if<true, T> { typedef T type; };

template <bool B, class T = void>
using enable_if_t = typename enable_if<B, T>::type;

template <class T>
struct enable_if_nice { typedef T type; };
}

namespace foo {
template <class T>
struct enable_if { typedef T type; };
}

template <typename T>
constexpr bool just_true = true;

class Test1 {
public:
  template <typename T>
  Test1(T &&n);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]

  template <typename T>
  Test1(T &&n, int i = 5, ...);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]

  template <typename T, typename U = typename std::enable_if_nice<T>::type>
  Test1(T &&n);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]

  template <typename T>
  Test1(T &&n, typename foo::enable_if<long>::type i = 5, ...);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]

  Test1(const Test1 &other) {}
  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here

  Test1(Test1 &other) {}
  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here

  Test1(Test1 &&other) {}
  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
};

template <typename U>
class Test2 {
public:
  // Two parameters without default value, can't act as copy / move constructor.
  template <typename T, class V>
  Test2(T &&n, V &&m, int i = 5, ...);

  // Guarded with enable_if.
  template <typename T>
  Test2(T &&n, int i = 5, std::enable_if_t<sizeof(int) < sizeof(long), int> a = 5, ...);

  // Guarded with enable_if.
  template <typename T, typename X = typename std::enable_if<sizeof(int) < sizeof(long), double>::type &>
  Test2(T &&n);

  // Guarded with enable_if.
  template <typename T>
  Test2(T &&n, typename std::enable_if<just_true<T>>::type **a = nullptr);

  // Guarded with enable_if.
  template <typename T, typename X = std::enable_if_t<just_true<T>> *&&>
  Test2(T &&n, double d = 0.0);

  // Not a forwarding reference parameter.
  template <typename T>
  Test2(const T &&n);

  // Not a forwarding reference parameter.
  Test2(int &&x);

  // Two parameters without default value, can't act as copy / move constructor.
  template <typename T>
  Test2(T &&n, int x);

  // Not a forwarding reference parameter.
  template <typename T>
  Test2(U &&n);
};

// The copy and move constructors are both disabled.
class Test3 {
public:
  template <typename T>
  Test3(T &&n);

  template <typename T>
  Test3(T &&n, int I = 5, ...);

  Test3(const Test3 &rhs) = delete;

private:
  Test3(Test3 &&rhs);
};

// Both the copy and the (compiler generated) move constructors can be hidden.
class Test4 {
public:
  template <typename T>
  Test4(T &&n);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]

  Test4(const Test4 &rhs);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
};

// Only the (compiler generated) copy constructor can be hidden.
class Test5 {
public:
  template <typename T>
  Test5(T &&n);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy constructor [misc-forwarding-reference-overload]

  Test5(Test5 &&rhs) = delete;
};

// Only the move constructor can be hidden.
class Test6 {
public:
  template <typename T>
  Test6(T &&n);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the move constructor [misc-forwarding-reference-overload]

  Test6(Test6 &&rhs);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
private:
  Test6(const Test6 &rhs);
};
<commit_msg>[clang-tidy] Temporarily disable a test-case that does not work on windows.<commit_after>// RUN: %check_clang_tidy %s misc-forwarding-reference-overload %t -- -- -std=c++14

namespace std {
template <bool B, class T = void>
struct enable_if { typedef T type; };

template <class T>
struct enable_if<true, T> { typedef T type; };

template <bool B, class T = void>
using enable_if_t = typename enable_if<B, T>::type;

template <class T>
struct enable_if_nice { typedef T type; };
}

namespace foo {
template <class T>
struct enable_if { typedef T type; };
}

template <typename T>
constexpr bool just_true = true;

class Test1 {
public:
  template <typename T>
  Test1(T &&n);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]

  template <typename T>
  Test1(T &&n, int i = 5, ...);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]

  template <typename T, typename U = typename std::enable_if_nice<T>::type>
  Test1(T &&n);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]

  template <typename T>
  Test1(T &&n, typename foo::enable_if<long>::type i = 5, ...);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]

  Test1(const Test1 &other) {}
  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here

  Test1(Test1 &other) {}
  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here

  Test1(Test1 &&other) {}
  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
};

template <typename U>
class Test2 {
public:
  // Two parameters without default value, can't act as copy / move constructor.
  template <typename T, class V>
  Test2(T &&n, V &&m, int i = 5, ...);

  // Guarded with enable_if.
  template <typename T>
  Test2(T &&n, int i = 5, std::enable_if_t<sizeof(int) < sizeof(long), int> a = 5, ...);

  // Guarded with enable_if.
  template <typename T, typename X = typename std::enable_if<sizeof(int) < sizeof(long), double>::type &>
  Test2(T &&n);

  // Guarded with enable_if.
  template <typename T>
  Test2(T &&n, typename std::enable_if<just_true<T>>::type **a = nullptr);

  // Guarded with enable_if.
  template <typename T, typename X = std::enable_if_t<just_true<T>> *&&>
  Test2(T &&n, double d = 0.0);

  // Not a forwarding reference parameter.
  template <typename T>
  Test2(const T &&n);

  // Not a forwarding reference parameter.
  Test2(int &&x);

  // Two parameters without default value, can't act as copy / move constructor.
  template <typename T>
  Test2(T &&n, int x);

  // Not a forwarding reference parameter.
  template <typename T>
  Test2(U &&n);
};

// The copy and move constructors are both disabled.
class Test3 {
public:
  template <typename T>
  Test3(T &&n);

  template <typename T>
  Test3(T &&n, int I = 5, ...);

  Test3(const Test3 &rhs) = delete;

private:
  Test3(Test3 &&rhs);
};

// Both the copy and the (compiler generated) move constructors can be hidden.
class Test4 {
public:
  template <typename T>
  Test4(T &&n);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]

  Test4(const Test4 &rhs);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
};

// Only the (compiler generated) copy constructor can be hidden.
// FIXME: Temporarily disabled due to failer on windows build bots.
//class Test5 {
//public:
//  template <typename T>
//  Test5(T &&n);
//  // CM: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy constructor [misc-forwarding-reference-overload]
//
//  Test5(Test5 &&rhs) = delete;
//};

// Only the move constructor can be hidden.
class Test6 {
public:
  template <typename T>
  Test6(T &&n);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the move constructor [misc-forwarding-reference-overload]

  Test6(Test6 &&rhs);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
private:
  Test6(const Test6 &rhs);
};
<|endoftext|>


<commit_before>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2006 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/
//$Id: ogrindex.cc 27 2005-03-30 21:45:40Z pavlenko $

#include <iostream>
#include <vector>
#include <string>

#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/program_options.hpp>

#include <mapnik/datasource.hpp>
#include <mapnik/envelope.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/feature_layer_desc.hpp>

#include "../shapeindex/quadtree.hpp"

#include "ogr_converter.cpp"
#include "ogr_datasource.cpp"
#include "ogr_featureset.cpp"
#include "ogr_index_featureset.cpp"

const int MAXDEPTH = 64;
const int DEFAULT_DEPTH = 8;
const double MINRATIO=0.5;
const double MAXRATIO=0.8;
const double DEFAULT_RATIO=0.55;

int main (int argc,char** argv)
{
    using namespace mapnik;
    namespace po = boost::program_options;
    using std::string;
    using std::vector;

    bool verbose=false;
    unsigned int depth=DEFAULT_DEPTH;
    double ratio=DEFAULT_RATIO;
    vector<string> ogr_files;

    try
    {
        po::options_description desc("ogrindex utility");
        desc.add_options()
            ("help,h",     "produce usage message")
            ("version,V",  "print version string")
            ("verbose,v",  "verbose output")
            ("depth,d",    po::value<unsigned int>(), "max tree depth\n(default 8)")
            ("ratio,r",    po::value<double>(), "split ratio (default 0.55)")
            ("ogr_files",  po::value<vector<string> >(), "ogr supported files to index: file1 file2 ...fileN")
            ;

        po::positional_options_description p;
        p.add("ogr_files",-1);
        po::variables_map vm;
        po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
        po::notify(vm);

        if (vm.count("version"))
        {
            std::clog<<"version 0.3.0" <<std::endl;
            return 1;
        }
        if (vm.count("help"))
        {
            std::clog << desc << std::endl;
            return 1;
        }
        if (vm.count("depth"))
        {
            depth = vm["depth"].as<unsigned int>();
        }
        if (vm.count("ratio"))
        {
            ratio = vm["ratio"].as<double>();
        }
        if (vm.count("ogr_files"))
        {
            ogr_files=vm["ogr_files"].as< vector<string> >();
        }
    }
    catch (...)
    {
        std::clog << "Exception of unknown type!" << std::endl;
        return -1;
    }

    std::clog << "max tree depth:" << depth << std::endl;
    std::clog << "split ratio:" << ratio << std::endl;

    vector<string>::const_iterator itr = ogr_files.begin();
    if (itr == ogr_files.end())
    {
        std::clog << "no ogr files to index" << std::endl;
        return 0;
    }
    while (itr != ogr_files.end())
    {
        std::clog << "processing " << *itr << std::endl;

        std::string ogrname (*itr++);

        if (! boost::filesystem::exists (ogrname))
        {
            std::clog << "error : file " << ogrname << " doesn't exists" << std::endl;
            continue;
        }

        int breakpoint = ogrname.find_last_of (".");
        if (breakpoint == string::npos) breakpoint = ogrname.length();
        std::string ogrlayername (ogrname.substr(0, breakpoint));

        if (boost::filesystem::exists (ogrlayername + ".index"))
        {
            std::clog << "error : " << ogrlayername << ".index file already exists for " << ogrname << std::endl;
            continue;
        }

        mapnik::parameters params;
        params["type"] = "ogr";
        params["file"] = ogrname;
        params["layer"] = ogrlayername;

        ogr_datasource ogr (params);

        Envelope<double> extent = ogr.envelope();
        quadtree<int> tree (extent, depth, ratio);
        int count=0;

        std::clog << "file:" << ogrname << std::endl;
        std::clog << "layer:" << ogrlayername << std::endl;
        std::clog << "extent:" << extent << std::endl;

        mapnik::query q (extent, 1.0);
        mapnik::featureset_ptr itr = ogr.features (q);

        while (true)
        {
            mapnik::feature_ptr fp = itr->next();
            if (!fp)
            {
                break;
            }

            Envelope<double> item_ext = fp->envelope();

            tree.insert (count, item_ext);
            if (verbose) {
                std::clog << "record number " << (count + 1) << " box=" << item_ext << std::endl;
            }

            ++count;
        }

        std::clog << " number shapes=" << count << std::endl;

        std::fstream file((ogrlayername+".index").c_str(),
                          std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary);
        if (!file) {
            std::clog << "cannot open index file for writing file \""
                      << (ogrlayername+".index") << "\"" << std::endl;
        } else {
            tree.trim();
            std::clog<<" number nodes="<<tree.count()<<std::endl;
            file.exceptions(std::ios::failbit | std::ios::badbit);
            tree.write(file);
            file.flush();
            file.close();
        }
    }

    std::clog << "done!" << std::endl;
    return 0;
}

<commit_msg>+ fixed version for ogrindex<commit_after>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2006 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/
//$Id: ogrindex.cc 27 2005-03-30 21:45:40Z pavlenko $

#include <iostream>
#include <vector>
#include <string>

#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/program_options.hpp>

#include <mapnik/datasource.hpp>
#include <mapnik/envelope.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/feature_layer_desc.hpp>

#include "../shapeindex/quadtree.hpp"

#include "ogr_converter.cpp"
#include "ogr_datasource.cpp"
#include "ogr_featureset.cpp"
#include "ogr_index_featureset.cpp"

const int MAXDEPTH = 64;
const int DEFAULT_DEPTH = 8;
const double MINRATIO=0.5;
const double MAXRATIO=0.8;
const double DEFAULT_RATIO=0.55;

int main (int argc,char** argv)
{
    using namespace mapnik;
    namespace po = boost::program_options;
    using std::string;
    using std::vector;

    bool verbose=false;
    unsigned int depth=DEFAULT_DEPTH;
    double ratio=DEFAULT_RATIO;
    vector<string> ogr_files;

    try
    {
        po::options_description desc("ogrindex utility");
        desc.add_options()
            ("help,h",     "produce usage message")
            ("version,V",  "print version string")
            ("verbose,v",  "verbose output")
            ("depth,d",    po::value<unsigned int>(), "max tree depth\n(default 8)")
            ("ratio,r",    po::value<double>(), "split ratio (default 0.55)")
            ("ogr_files",  po::value<vector<string> >(), "ogr supported files to index: file1 file2 ...fileN")
            ;

        po::positional_options_description p;
        p.add("ogr_files",-1);
        po::variables_map vm;
        po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
        po::notify(vm);

        if (vm.count("version"))
        {
            std::clog<<"version 0.1.0" <<std::endl;
            return 1;
        }
        if (vm.count("help"))
        {
            std::clog << desc << std::endl;
            return 1;
        }
        if (vm.count("depth"))
        {
            depth = vm["depth"].as<unsigned int>();
        }
        if (vm.count("ratio"))
        {
            ratio = vm["ratio"].as<double>();
        }
        if (vm.count("ogr_files"))
        {
            ogr_files=vm["ogr_files"].as< vector<string> >();
        }
    }
    catch (...)
    {
        std::clog << "Exception of unknown type!" << std::endl;
        return -1;
    }

    std::clog << "max tree depth:" << depth << std::endl;
    std::clog << "split ratio:" << ratio << std::endl;

    vector<string>::const_iterator itr = ogr_files.begin();
    if (itr == ogr_files.end())
    {
        std::clog << "no ogr files to index" << std::endl;
        return 0;
    }
    while (itr != ogr_files.end())
    {
        std::clog << "processing " << *itr << std::endl;

        std::string ogrname (*itr++);

        if (! boost::filesystem::exists (ogrname))
        {
            std::clog << "error : file " << ogrname << " doesn't exists" << std::endl;
            continue;
        }

        int breakpoint = ogrname.find_last_of (".");
        if (breakpoint == string::npos) breakpoint = ogrname.length();
        std::string ogrlayername (ogrname.substr(0, breakpoint));

        if (boost::filesystem::exists (ogrlayername + ".index"))
        {
            std::clog << "error : " << ogrlayername << ".index file already exists for " << ogrname << std::endl;
            continue;
        }

        mapnik::parameters params;
        params["type"] = "ogr";
        params["file"] = ogrname;
        params["layer"] = ogrlayername;

        ogr_datasource ogr (params);

        Envelope<double> extent = ogr.envelope();
        quadtree<int> tree (extent, depth, ratio);
        int count=0;

        std::clog << "file:" << ogrname << std::endl;
        std::clog << "layer:" << ogrlayername << std::endl;
        std::clog << "extent:" << extent << std::endl;

        mapnik::query q (extent, 1.0);
        mapnik::featureset_ptr itr = ogr.features (q);

        while (true)
        {
            mapnik::feature_ptr fp = itr->next();
            if (!fp)
            {
                break;
            }

            Envelope<double> item_ext = fp->envelope();

            tree.insert (count, item_ext);
            if (verbose) {
                std::clog << "record number " << (count + 1) << " box=" << item_ext << std::endl;
            }

            ++count;
        }

        std::clog << " number shapes=" << count << std::endl;

        std::fstream file((ogrlayername+".index").c_str(),
                          std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary);
        if (!file) {
            std::clog << "cannot open index file for writing file \""
                      << (ogrlayername+".index") << "\"" << std::endl;
        } else {
            tree.trim();
            std::clog<<" number nodes="<<tree.count()<<std::endl;
            file.exceptions(std::ios::failbit | std::ios::badbit);
            tree.write(file);
            file.flush();
            file.close();
        }
    }

    std::clog << "done!" << std::endl;
    return 0;
}

<|endoftext|>