Commit a721dca3 authored by Jonathon Duerig's avatar Jonathon Duerig
Browse files

Update assign portability to work with clang

...bringing assign kicking and screaming into the century of the fruitbat.
parent cde74b05
......@@ -30,6 +30,16 @@ NEWER_BOOST = @NEWER_BOOST@
include $(OBJDIR)/Makeconf
#
# XXX tmp hack for FreeBSD 10 with clang:
# Doesn't compile right now with clang so use gcc46 instead.
#
#ifneq ($(wildcard /usr/bin/clang),)
#CC=gcc46
#CPP=cpp46
#CXX=g++46
#endif
#
# Uncomment these to build with gcc3.3
#
......@@ -48,7 +58,7 @@ OBJS=parse_top.o parse_ptop.o assign.o pclass.o vclass.o score.o \
config.o
LIBS+= -lm
LDFLAGS+= -pipe -O3
CXXFLAGS = -pipe -I/usr/local/include -ftemplate-depth-40
CXXFLAGS = -pipe -I/usr/local/include -ftemplate-depth-80 -Wno-c++11-extensions
# For OSX w/ macports
CXXFLAGS += -I/opt/local/include
LIBS += -L/opt/local/lib
......
......@@ -158,7 +158,7 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
double deltatemp, deltaavg;
// List of unassigned virtual nodes
slist<vvertex> unassigned_nodes;
list<vvertex> unassigned_nodes;
#ifdef VERBOSE
cout << "Initialized to cycles="<<cycles<<" mintrans="
......@@ -511,7 +511,7 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
if (! unassigned_nodes.empty()) {
// Pick a random node from the list of unassigned nodes
int choice = RANDOM() % unassigned_nodes.size();
slist<vvertex>::iterator uit = unassigned_nodes.begin();
list<vvertex>::iterator uit = unassigned_nodes.begin();
for (int i = 0; i < choice; i++) { uit++; }
assert(uit != unassigned_nodes.end());
......
......@@ -36,19 +36,6 @@ using namespace boost;
#include <iostream>
using namespace std;
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#ifdef NEW_GCC
#include <ext/hash_map>
#include <ext/slist>
using namespace __gnu_cxx;
#else
#include <hash_map>
#include <slist>
#endif
#include <math.h>
#include "delay.h"
......
......@@ -26,27 +26,7 @@
#include "port.h"
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#ifdef NEW_GCC
#include <ext/hash_map>
#ifdef NEWER_GCC
#include <backward/hash_fun.h>
#else
#include <ext/hash_fun.h>
#endif
using namespace __gnu_cxx;
#define RANDOM() random()
#else
#include <hash_map>
#define RANDOM() std::random()
#endif
#include <utility>
#include "port.h"
#include "fstring.h"
#include <boost/graph/adjacency_list.hpp>
......@@ -74,6 +54,15 @@ using namespace __gnu_cxx;
namespace __gnu_cxx
{
#endif
#ifdef __clang__
template<> struct std::hash< std::string >
{
size_t operator()( const std::string& x ) const
{
return hash< const char* >()( x.c_str() );
}
};
#else
template<> struct hash< std::string >
{
size_t operator()( const std::string& x ) const
......@@ -81,6 +70,7 @@ namespace __gnu_cxx
return hash< const char* >()( x.c_str() );
}
};
#endif
#ifdef NEW_GCC
}
#endif
......
......@@ -38,13 +38,6 @@
#include <boost/graph/dijkstra_shortest_paths.hpp>
using namespace boost;
#ifdef NEW_GCC
#include <ext/hash_set>
using namespace __gnu_cxx;
#else
#include <hash_set>
#endif
#include <list>
#include <vector>
using namespace std;
......
......@@ -52,7 +52,7 @@ using namespace std;
#include <ext/hash_fun.h>
#endif
using namespace __gnu_cxx;
#else
#elif ! defined __clang__
#include <stl_hash_fun.h>
#endif
......@@ -211,16 +211,25 @@ class fstring {
};
// A hash function for fstrings
#ifdef NEW_GCC
#if defined NEW_GCC
namespace __gnu_cxx {
#endif
#if defined __clang__
template<> struct std::hash<fstring> {
size_t operator()(const fstring& __str) const
{
return (size_t)__str.hash();
}
};
#else
template<> struct hash<fstring> {
size_t operator()(const fstring& __str) const
{
return (size_t)__str.hash();
}
};
#ifdef NEW_GCC
#endif
#if defined NEW_GCC
}
#endif
......
......@@ -31,17 +31,6 @@ static const char rcsid[] = "$Id: pclass.cc,v 1.31 2009-06-15 19:42:26 ricci Exp
#include <list>
#include <algorithm>
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#ifdef NEW_GCC
#include <ext/hash_map>
using namespace __gnu_cxx;
#else
#include <hash_map>
#endif
#include <boost/config.hpp>
#include <boost/utility.hpp>
#include BOOST_PMAP_HEADER
......
......@@ -42,19 +42,6 @@ using namespace boost;
#include <string>
using namespace std;
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#ifdef NEW_GCC
#include <ext/hash_set>
#include <ext/hash_map>
using namespace __gnu_cxx;
#else
#include <hash_set>
#include <hash_map>
#endif
// Icky, but I can't include virtual.h here
class tb_vnode;
typedef hash_set<tb_vnode*,hashptr<tb_vnode*> > tb_vnode_set;
......@@ -363,8 +350,10 @@ template <class T> struct pairhash {
size_t operator()(pair<T,T> const &A) const {
#ifdef NEW_GCC
__gnu_cxx::hash<T> H;
#else
#elif ! defined __clang__
::hash<T> H;
#else
std::hash<T> H;
#endif
return (H(A.first) | H(A.second));
}
......
......@@ -46,17 +46,29 @@
* hash_map with tr1::unordered_map in <tr1/unordered_map>
*/
#if (__GNUC__ == 3 && __GNUC_MINOR__ > 0) || (__GNUC__ > 3)
#ifndef __clang__
#define NEW_GCC
#endif
#endif
#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || (__GNUC__ > 4)
#ifndef __clang__
#define NEWER_GCC
#endif
#endif
#ifdef __clang__
#undef NEW_GCC
#undef NEWER_GCC
#include <forward_list>
template<typename T>
using slist = std::forward_list<T>;
#endif
#ifdef NEW_GCC
#include <ext/slist>
using namespace __gnu_cxx;
#else
#elif ! defined __clang__
#include <slist>
#endif
......@@ -66,5 +78,41 @@ using namespace __gnu_cxx;
#define BOOST_PMAP_HEADER <boost/property_map.hpp>
#endif
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#ifdef NEW_GCC
#include <ext/hash_map>
#include <ext/hash_set>
#ifdef NEWER_GCC
#include <backward/hash_fun.h>
#else
#include <ext/hash_fun.h>
#endif
using namespace __gnu_cxx;
#define RANDOM() random()
#elif ! defined __clang__
#include <hash_map>
#include <hash_set>
#define RANDOM() std::random()
#endif
#ifdef __clang__
#include <functional>
#include <unordered_map>
#include <unordered_set>
template < typename T, typename U, typename F=std::hash<T> >
using hash_map = std::unordered_map<T, U, F>;
template < typename T, typename F=std::hash<T> >
using hash_set = std::unordered_set<T, F>;
#define RANDOM() std::rand()
#endif
#else
#endif
......@@ -28,19 +28,6 @@ static const char rcsid[] = "$Id: score.cc,v 1.69 2009-12-09 22:53:44 ricci Exp
#include <iostream>
#include <float.h>
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#ifdef NEW_GCC
#include <ext/hash_map>
#include <ext/hash_set>
using namespace __gnu_cxx;
#else
#include <hash_map>
#include <hash_set>
#endif
#include <boost/config.hpp>
#include <boost/utility.hpp>
#include BOOST_PMAP_HEADER
......
......@@ -27,17 +27,6 @@
#include "port.h"
#include "fstring.h"
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#ifdef NEW_GCC
#include <ext/hash_map>
using namespace __gnu_cxx;
#else
#include <hash_map>
#endif
#include <iostream>
using namespace std;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment