Update mclinker for LLVM rebase to r222494. This corresponds to the following upstream mclinker change: commit b2f1691276052c4215abf36715d43248d6337cf8 Author: Diana Chen <[email protected]> Date: Tue Nov 25 14:03:29 2014 +0800 option: Allow `-hash-style' can be specified zero or more times Change-Id: I332546680bb45cf9692adfa2c2d3dcdc84361afc
diff --git a/include/mcld/ADT/BinTree.h b/include/mcld/ADT/BinTree.h index a23bc7d..a9b50f4 100644 --- a/include/mcld/ADT/BinTree.h +++ b/include/mcld/ADT/BinTree.h
@@ -6,12 +6,12 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_BITREE_H -#define MCLD_ADT_BITREE_H +#ifndef MCLD_ADT_BINTREE_H_ +#define MCLD_ADT_BINTREE_H_ -#include <mcld/ADT/Uncopyable.h> -#include <mcld/ADT/TreeBase.h> -#include <mcld/ADT/TreeAllocator.h> +#include "mcld/ADT/TreeAllocator.h" +#include "mcld/ADT/TreeBase.h" +#include "mcld/Support/Compiler.h" #include <cstddef> #include <iterator> @@ -21,30 +21,25 @@ namespace mcld { -template<class DataType> +template <class DataType> class BinaryTree; -class DFSIterator : public TreeIteratorBase -{ -public: - DFSIterator() - : TreeIteratorBase() - { } +class DFSIterator : public TreeIteratorBase { + public: + DFSIterator() : TreeIteratorBase() {} - DFSIterator(NodeBase *X) - : TreeIteratorBase(X) { + explicit DFSIterator(NodeBase* X) : TreeIteratorBase(X) { if (hasRightChild()) m_Stack.push(m_pNode->right); if (hasLeftChild()) m_Stack.push(m_pNode->left); } - virtual ~DFSIterator() - { } + virtual ~DFSIterator() {} void advance() { - if (m_Stack.empty()) { // reach the end - m_pNode = m_pNode->right; // should be root + if (m_Stack.empty()) { // reach the end + m_pNode = m_pNode->right; // should be root return; } m_pNode = m_Stack.top(); @@ -55,31 +50,26 @@ m_Stack.push(m_pNode->left); } -private: - std::stack<NodeBase *> m_Stack; + private: + std::stack<NodeBase*> m_Stack; }; -class BFSIterator : public TreeIteratorBase -{ -public: - BFSIterator() - : TreeIteratorBase() - { } +class BFSIterator : public TreeIteratorBase { + public: + BFSIterator() : TreeIteratorBase() {} - BFSIterator(NodeBase *X) - : TreeIteratorBase(X) { + explicit BFSIterator(NodeBase* X) : TreeIteratorBase(X) { if (hasRightChild()) m_Queue.push(m_pNode->right); if (hasLeftChild()) m_Queue.push(m_pNode->left); } - virtual ~BFSIterator() - { } + virtual ~BFSIterator() {} void advance() { - if (m_Queue.empty()) { // reach the end - m_pNode = m_pNode->right; // should be root + if (m_Queue.empty()) { // reach the end + m_pNode = m_pNode->right; // should be root return; } m_pNode = m_Queue.front(); @@ -90,71 +80,75 @@ m_Queue.push(m_pNode->left); } -private: - std::queue<NodeBase *> m_Queue; + private: + std::queue<NodeBase*> m_Queue; }; -template<class DataType, class Traits, class IteratorType> -class PolicyIteratorBase : public IteratorType -{ -public: - typedef DataType value_type; - typedef Traits traits; - typedef typename traits::pointer pointer; - typedef typename traits::reference reference; +template <class DataType, class Traits, class IteratorType> +class PolicyIteratorBase : public IteratorType { + public: + typedef DataType value_type; + typedef Traits traits; + typedef typename traits::pointer pointer; + typedef typename traits::reference reference; - typedef PolicyIteratorBase<value_type, Traits, IteratorType> Self; - typedef Node<value_type> node_type; - typedef typename traits::nonconst_traits nonconst_traits; - typedef PolicyIteratorBase<value_type, nonconst_traits, IteratorType> iterator; - typedef typename traits::const_traits const_traits; - typedef PolicyIteratorBase<value_type, const_traits, IteratorType> const_iterator; - typedef std::forward_iterator_tag iterator_category; - typedef size_t size_type; - typedef ptrdiff_t difference_type; + typedef PolicyIteratorBase<value_type, Traits, IteratorType> Self; + typedef Node<value_type> node_type; -public: - PolicyIteratorBase() - : IteratorType() {} + typedef typename traits::nonconst_traits nonconst_traits; + typedef typename traits::const_traits const_traits; - PolicyIteratorBase(const iterator &X) - : IteratorType(X.m_pNode) {} + typedef PolicyIteratorBase<value_type, nonconst_traits, IteratorType> + iterator; + typedef PolicyIteratorBase<value_type, const_traits, IteratorType> + const_iterator; - explicit PolicyIteratorBase(NodeBase* X) - : IteratorType(X) {} + typedef std::forward_iterator_tag iterator_category; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + public: + PolicyIteratorBase() : IteratorType() {} + + PolicyIteratorBase(const iterator& X) : IteratorType(X.m_pNode) {} + + explicit PolicyIteratorBase(NodeBase* X) : IteratorType(X) {} virtual ~PolicyIteratorBase() {} // ----- operators ----- // - pointer operator*() const - { return static_cast<node_type*>(IteratorType::m_pNode)->data; } + pointer operator*() const { + return static_cast<node_type*>(IteratorType::m_pNode)->data; + } - reference operator->() const - { return *static_cast<node_type*>(IteratorType::m_pNode)->data; } + reference operator->() const { + return *static_cast<node_type*>(IteratorType::m_pNode)->data; + } - bool hasData() const - { return (!IteratorType::isRoot() && (0 != static_cast<node_type*>(IteratorType::m_pNode)->data)); } - + bool hasData() const { + return (!IteratorType::isRoot() && + (0 != static_cast<node_type*>(IteratorType::m_pNode)->data)); + } }; -template<class DataType, class Traits, class IteratorType> -class PolicyIterator : public PolicyIteratorBase<DataType, Traits, IteratorType> -{ -public: +template <class DataType, class Traits, class IteratorType> +class PolicyIterator + : public PolicyIteratorBase<DataType, Traits, IteratorType> { + public: typedef PolicyIterator<DataType, Traits, IteratorType> Self; typedef PolicyIteratorBase<DataType, Traits, IteratorType> Base; - typedef PolicyIterator<DataType, typename Traits::nonconst_traits, IteratorType> iterator; - typedef PolicyIterator<DataType, typename Traits::const_traits, IteratorType> const_iterator; + typedef PolicyIterator<DataType, + typename Traits::nonconst_traits, + IteratorType> iterator; + typedef PolicyIterator<DataType, typename Traits::const_traits, IteratorType> + const_iterator; -public: - PolicyIterator() - : Base() {} + public: + PolicyIterator() : Base() {} - PolicyIterator(const iterator &X) - : Base(X.m_pNode) {} + PolicyIterator(const iterator& X) : Base(X.m_pNode) {} - explicit PolicyIterator(NodeBase* X) - : Base(X) {} + explicit PolicyIterator(NodeBase* X) : Base(X) {} virtual ~PolicyIterator() {} @@ -170,7 +164,7 @@ } }; -template<class DataType> +template <class DataType> class BinaryTree; /** \class TreeIterator @@ -182,47 +176,44 @@ * * @see TreeIteratorBase */ -template<class DataType, class Traits> -struct TreeIterator : public TreeIteratorBase -{ -public: - typedef DataType value_type; - typedef Traits traits; - typedef typename traits::pointer pointer; - typedef typename traits::reference reference; +template <class DataType, class Traits> +struct TreeIterator : public TreeIteratorBase { + public: + typedef DataType value_type; + typedef Traits traits; + typedef typename traits::pointer pointer; + typedef typename traits::reference reference; - typedef TreeIterator<value_type, Traits> Self; - typedef Node<value_type> node_type; + typedef TreeIterator<value_type, Traits> Self; + typedef Node<value_type> node_type; - typedef typename traits::nonconst_traits nonconst_traits; + typedef typename traits::nonconst_traits nonconst_traits; typedef TreeIterator<value_type, nonconst_traits> iterator; - typedef typename traits::const_traits const_traits; - typedef TreeIterator<value_type, const_traits> const_iterator; - typedef std::bidirectional_iterator_tag iterator_category; - typedef size_t size_type; - typedef ptrdiff_t difference_type; + typedef typename traits::const_traits const_traits; + typedef TreeIterator<value_type, const_traits> const_iterator; + typedef std::bidirectional_iterator_tag iterator_category; + typedef size_t size_type; + typedef ptrdiff_t difference_type; -public: - TreeIterator() - : TreeIteratorBase() {} + public: + TreeIterator() : TreeIteratorBase() {} - TreeIterator(const iterator &X) - : TreeIteratorBase(X.m_pNode) {} + TreeIterator(const iterator& X) : TreeIteratorBase(X.m_pNode) {} ~TreeIterator() {} // ----- operators ----- // - pointer operator*() const - { return static_cast<node_type*>(m_pNode)->data; } + pointer operator*() const { return static_cast<node_type*>(m_pNode)->data; } - reference operator->() const - { return *static_cast<node_type*>(m_pNode)->data; } + reference operator->() const { + return *static_cast<node_type*>(m_pNode)->data; + } - bool isRoot() const - { return (m_pNode->right == m_pNode); } + bool isRoot() const { return (m_pNode->right == m_pNode); } - bool hasData() const - { return (!isRoot() && (0 != static_cast<node_type*>(m_pNode)->data)); } + bool hasData() const { + return (!isRoot() && (0 != static_cast<node_type*>(m_pNode)->data)); + } Self& operator++() { this->move<TreeIteratorBase::Rightward>(); @@ -246,8 +237,7 @@ return tmp; } - explicit TreeIterator(NodeBase* X) - : TreeIteratorBase(X) {} + explicit TreeIterator(NodeBase* X) : TreeIteratorBase(X) {} }; /** \class BinaryTreeBase @@ -259,12 +249,12 @@ * * @see BinaryTree */ -template<class DataType> -class BinaryTreeBase : private Uncopyable -{ -public: +template <class DataType> +class BinaryTreeBase { + public: typedef Node<DataType> NodeType; -protected: + + protected: /// TreeImpl - TreeImpl records the root node and the number of nodes // // +---> Root(end) <---+ @@ -274,22 +264,17 @@ // | Left Right | // +---/ \-----+ // - class TreeImpl : public NodeFactory<DataType> - { - typedef typename NodeFactory<DataType>::iterator iterator; + class TreeImpl : public NodeFactory<DataType> { + typedef typename NodeFactory<DataType>::iterator iterator; typedef typename NodeFactory<DataType>::const_iterator const_iterator; - public: + public: NodeBase node; - public: - TreeImpl() - : NodeFactory<DataType>() { - node.left = node.right = &node; - } + public: + TreeImpl() : NodeFactory<DataType>() { node.left = node.right = &node; } - ~TreeImpl() - { } + ~TreeImpl() {} /// summon - change the final edges of pClient to our root void summon(TreeImpl& pClient) { @@ -298,54 +283,48 @@ iterator data; iterator dEnd = pClient.end(); - for (data = pClient.begin(); data!=dEnd; ++data ) { + for (data = pClient.begin(); data != dEnd; ++data) { if ((*data).left == &pClient.node) (*data).left = &node; if ((*data).right == &pClient.node) (*data).right = &node; } } - }; // TreeImpl + }; // TreeImpl -protected: + protected: /// m_Root is a special object who responses: // - the pointer of root // - the simple factory of nodes. TreeImpl m_Root; -protected: - NodeType *createNode() { - NodeType *result = m_Root.produce(); + protected: + NodeType* createNode() { + NodeType* result = m_Root.produce(); result->left = result->right = &m_Root.node; return result; } - void destroyNode(NodeType *pNode) { + void destroyNode(NodeType* pNode) { pNode->left = pNode->right = 0; pNode->data = 0; m_Root.deallocate(pNode); } -public: - BinaryTreeBase() - : m_Root() - { } + public: + BinaryTreeBase() : m_Root() {} - virtual ~BinaryTreeBase() - { } + virtual ~BinaryTreeBase() {} - size_t size() const { - return m_Root.size(); - } + size_t size() const { return m_Root.size(); } - bool empty() const { - return m_Root.empty(); - } + bool empty() const { return m_Root.empty(); } -protected: - void clear() { - m_Root.clear(); - } + protected: + void clear() { m_Root.clear(); } + + private: + DISALLOW_COPY_AND_ASSIGN(BinaryTreeBase); }; /** \class BinaryTree @@ -353,81 +332,94 @@ * * @see mcld::InputTree */ -template<class DataType> -class BinaryTree : public BinaryTreeBase<DataType> -{ -public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef DataType value_type; - typedef value_type* pointer; - typedef value_type& reference; - typedef const value_type* const_pointer; - typedef const value_type& const_reference; +template <class DataType> +class BinaryTree : public BinaryTreeBase<DataType> { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef DataType value_type; + typedef value_type* pointer; + typedef value_type& reference; + typedef const value_type* const_pointer; + typedef const value_type& const_reference; - typedef BinaryTree<DataType> Self; + typedef BinaryTree<DataType> Self; typedef TreeIterator<value_type, NonConstTraits<value_type> > iterator; - typedef TreeIterator<value_type, ConstTraits<value_type> > const_iterator; + typedef TreeIterator<value_type, ConstTraits<value_type> > const_iterator; - typedef PolicyIterator<value_type, NonConstTraits<value_type>, DFSIterator> dfs_iterator; - typedef PolicyIterator<value_type, ConstTraits<value_type>, DFSIterator> const_dfs_iterator; - typedef PolicyIterator<value_type, NonConstTraits<value_type>, BFSIterator> bfs_iterator; - typedef PolicyIterator<value_type, ConstTraits<value_type>, BFSIterator> const_bfs_iterator; + typedef PolicyIterator<value_type, NonConstTraits<value_type>, DFSIterator> + dfs_iterator; + typedef PolicyIterator<value_type, ConstTraits<value_type>, DFSIterator> + const_dfs_iterator; -protected: + typedef PolicyIterator<value_type, NonConstTraits<value_type>, BFSIterator> + bfs_iterator; + typedef PolicyIterator<value_type, ConstTraits<value_type>, BFSIterator> + const_bfs_iterator; + + protected: typedef Node<value_type> node_type; -public: + public: // ----- constructors and destructor ----- // - BinaryTree() - : BinaryTreeBase<DataType>() - { } + BinaryTree() : BinaryTreeBase<DataType>() {} - ~BinaryTree() { - } + ~BinaryTree() {} // ----- iterators ----- // - bfs_iterator bfs_begin() - { return bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left); } + bfs_iterator bfs_begin() { + return bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left); + } - bfs_iterator bfs_end() - { return bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right); } + bfs_iterator bfs_end() { + return bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right); + } - const_bfs_iterator bfs_begin() const - { return const_bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left); } + const_bfs_iterator bfs_begin() const { + return const_bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left); + } - const_bfs_iterator bfs_end() const - { return const_bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right); } + const_bfs_iterator bfs_end() const { + return const_bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right); + } - dfs_iterator dfs_begin() - { return dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left); } + dfs_iterator dfs_begin() { + return dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left); + } - dfs_iterator dfs_end() - { return dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right); } + dfs_iterator dfs_end() { + return dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right); + } - const_dfs_iterator dfs_begin() const - { return const_dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left); } + const_dfs_iterator dfs_begin() const { + return const_dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left); + } - const_dfs_iterator dfs_end() const - { return const_dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right); } + const_dfs_iterator dfs_end() const { + return const_dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right); + } - iterator root() - { return iterator(&(BinaryTreeBase<DataType>::m_Root.node)); } + iterator root() { return iterator(&(BinaryTreeBase<DataType>::m_Root.node)); } - const_iterator root() const - { return const_iterator(&(BinaryTreeBase<DataType>::m_Root.node)); } + const_iterator root() const { + return const_iterator(&(BinaryTreeBase<DataType>::m_Root.node)); + } - iterator begin() - { return iterator(BinaryTreeBase<DataType>::m_Root.node.left); } + iterator begin() { + return iterator(BinaryTreeBase<DataType>::m_Root.node.left); + } - iterator end() - { return iterator(BinaryTreeBase<DataType>::m_Root.node.right); } + iterator end() { + return iterator(BinaryTreeBase<DataType>::m_Root.node.right); + } - const_iterator begin() const - { return const_iterator(BinaryTreeBase<DataType>::m_Root.node.left); } + const_iterator begin() const { + return const_iterator(BinaryTreeBase<DataType>::m_Root.node.left); + } - const_iterator end() const - { return const_iterator(BinaryTreeBase<DataType>::m_Root.node.right); } + const_iterator end() const { + return const_iterator(BinaryTreeBase<DataType>::m_Root.node.right); + } // ----- modifiers ----- // /// join - create a leaf node and merge it in the tree. @@ -435,9 +427,9 @@ // @param DIRECT the direction of the connecting edge of the parent node. // @param position the parent node // @param value the value being pushed. - template<size_t DIRECT> + template <size_t DIRECT> BinaryTree& join(TreeIteratorBase& pPosition, const DataType& pValue) { - node_type *node = BinaryTreeBase<DataType>::createNode(); + node_type* node = BinaryTreeBase<DataType>::createNode(); node->data = const_cast<DataType*>(&pValue); if (pPosition.isRoot()) @@ -453,7 +445,7 @@ // @param position the parent node // @param the tree being joined. // @return the joined tree - template<size_t DIRECT> + template <size_t DIRECT> BinaryTree& merge(TreeIteratorBase& pPosition, BinaryTree& pTree) { if (this == &pTree) return *this; @@ -461,7 +453,7 @@ if (!pTree.empty()) { pPosition.hook<DIRECT>(pTree.m_Root.node.left); BinaryTreeBase<DataType>::m_Root.summon( - pTree.BinaryTreeBase<DataType>::m_Root); + pTree.BinaryTreeBase<DataType>::m_Root); BinaryTreeBase<DataType>::m_Root.delegate(pTree.m_Root); pTree.m_Root.node.left = pTree.m_Root.node.right = &pTree.m_Root.node; } @@ -469,7 +461,6 @@ } }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_ADT_BINTREE_H_
diff --git a/include/mcld/ADT/Flags.h b/include/mcld/ADT/Flags.h index 0336770..e53ee09 100644 --- a/include/mcld/ADT/Flags.h +++ b/include/mcld/ADT/Flags.h
@@ -6,44 +6,34 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_FLAGS_H -#define MCLD_ADT_FLAGS_H +#ifndef MCLD_ADT_FLAGS_H_ +#define MCLD_ADT_FLAGS_H_ -namespace mcld -{ +namespace mcld { -template<typename Enum> -class Flags -{ -public: +template <typename Enum> +class Flags { + public: typedef Enum enum_type; -public: - Flags(const Flags& pOther) - : m_Data(pOther.m_Data) {} + public: + Flags(const Flags& pOther) : m_Data(pOther.m_Data) {} - Flags(Enum pFlag) - : m_Data(pFlag) {} + explicit Flags(Enum pFlag) : m_Data(pFlag) {} - Flags(unsigned int pFlag = 0x0) - : m_Data(pFlag) {} + explicit Flags(unsigned int pFlag = 0x0) : m_Data(pFlag) {} - operator unsigned int () const - { return m_Data; } + operator unsigned int() const { return m_Data; } - bool operator! () const - { return (m_Data == 0x0); } + bool operator!() const { return (m_Data == 0x0); } - Flags operator& (int pMask ) const - { return Flags(m_Data & pMask); } + Flags operator&(int pMask) const { return Flags(m_Data & pMask); } - Flags operator& (unsigned int pMask ) const - { return Flags(m_Data & pMask); } + Flags operator&(unsigned int pMask) const { return Flags(m_Data & pMask); } - Flags operator& (Enum pMask ) const - { return Flags(m_Data & pMask); } + Flags operator&(Enum pMask) const { return Flags(m_Data & pMask); } - Flags& operator&= (unsigned int pMask ) { + Flags& operator&=(unsigned int pMask) { m_Data &= pMask; return *this; } @@ -53,46 +43,40 @@ return *this; } - Flags operator^ (Flags pOther) const - { return Flags(m_Data^pOther.m_Data); } + Flags operator^(Flags pOther) const { return Flags(m_Data ^ pOther.m_Data); } - Flags operator^ (Enum pOther) const - { return Flags(m_Data^pOther); } + Flags operator^(Enum pOther) const { return Flags(m_Data ^ pOther); } - Flags& operator^= (Flags pOther) { + Flags& operator^=(Flags pOther) { m_Data ^= pOther.m_Data; return *this; } - Flags& operator^= (Enum pOther) { + Flags& operator^=(Enum pOther) { m_Data ^= pOther; return *this; } - Flags operator| (Flags pOther) const - { return Flags(m_Data | pOther.m_Data); } + Flags operator|(Flags pOther) const { return Flags(m_Data | pOther.m_Data); } - Flags operator| (Enum pOther ) const - { return Flags(m_Data | pOther); } + Flags operator|(Enum pOther) const { return Flags(m_Data | pOther); } - Flags& operator|= (Flags pOther) { + Flags& operator|=(Flags pOther) { m_Data |= pOther.m_Data; return *this; } - Flags& operator|= (Enum pOther) { + Flags& operator|=(Enum pOther) { m_Data |= pOther; return *this; } - Flags operator~ () const - { return Flags(~m_Data); } + Flags operator~() const { return Flags(~m_Data); } -private: + private: unsigned int m_Data; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_ADT_FLAGS_H_
diff --git a/include/mcld/ADT/GraphLite/Digraph.h b/include/mcld/ADT/GraphLite/Digraph.h deleted file mode 100644 index 2e20c6c..0000000 --- a/include/mcld/ADT/GraphLite/Digraph.h +++ /dev/null
@@ -1,82 +0,0 @@ -//===- Digraph.h ----------------------------------------------------------===// -// -// The MCLinker Project -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_GRAPHLITE_DIGRAPH_H -#define MCLD_ADT_GRAPHLITE_DIGRAPH_H -#include <mcld/ADT/Uncopyable.h> -#include <mcld/ADT/GraphLite/GraphBasicTypes.h> -#include <stdint.h> - -namespace mcld { -namespace graph { - -/** \class Digraph - * \brief Digraph provides the common interface of all directed graphs. - */ -class Digraph : private Uncopyable -{ -public: - typedef DirectedTag direction_tag; - - class Node - { - friend class Digraph; - public: - Node() {} - - bool operator==(const Node& pOther) const { return m_ID == pOther.m_ID; } - bool operator!=(const Node& pOther) const { return m_ID != pOther.m_ID; } - - protected: - intptr_t m_ID; - }; - - class Arc - { - friend class Digraph; - public: - Arc(); - - bool operator==(const Node& pOther) const; - bool operator!=(const Node& pOther) const; - - Node source() const; - Node target() const; - - protected: - Arc(Digraph& pParent); - - protected: - intptr_t m_ID; - Digraph* m_Parent; - }; - -public: - Digraph(); - - Node addNode(); - - Arc addArc(const Node& pSource, const Node& pTarget); - - void erase(const Node& pNode); - - void erase(const Arc& pArc); - - void clear(); - - unsigned int numOfNodes() const; - - unsigned int numOfArcs() const; - -}; - -} // namespace of graph -} // namespace of mcld - -#endif -
diff --git a/include/mcld/ADT/GraphLite/GraphBasicTypes.h b/include/mcld/ADT/GraphLite/GraphBasicTypes.h deleted file mode 100644 index 5862bcb..0000000 --- a/include/mcld/ADT/GraphLite/GraphBasicTypes.h +++ /dev/null
@@ -1,29 +0,0 @@ -//===- GraphBasicTypes.h --------------------------------------------------===// -// -// The MCLinker Project -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_GRAPHLITE_GRAPHBASICTYPES_H -#define MCLD_ADT_GRAPHLITE_GRAPHBASICTYPES_H - -namespace mcld { -namespace graph { - -/** \class UndirectedTag - * \brief Undirected graph category. - */ -struct UndirectedTag {}; - -/** \class DirectedTag - * \brief Directed graph category. - */ -struct DirectedTag {}; - -} // namespace of graph -} // namespace of mcld - -#endif -
diff --git a/include/mcld/ADT/GraphLite/ListDigraph.h b/include/mcld/ADT/GraphLite/ListDigraph.h deleted file mode 100644 index b36dd67..0000000 --- a/include/mcld/ADT/GraphLite/ListDigraph.h +++ /dev/null
@@ -1,89 +0,0 @@ -//===- ListDigraph.h ------------------------------------------------------===// -// -// The MCLinker Project -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_GRAPHLITE_LISTDIGRAPH_H -#define MCLD_ADT_GRAPHLITE_LISTDIGRAPH_H -#include <mcld/Support/GCFactory.h> - -namespace mcld { -namespace graph { - -/** \class ListDigraph - * \brief ListDigraph provides an linked-list inplementation of a graph. - * - * ListDigraph is designed to get well performance for most algorithms of - * graph theory. - * - * Function | Complexity | Best Complexity - * ----------------|------------|-------------------------- - * Storage | V + E | - * Add node | O(1) | - * Add arc | O(1) | - * Remove node | O(E) | O(#(fan-in) + #(fan-out)) - * Remove edge | O(1) | - * Query adjacency | O(E) | O(#(fan-in) + #(fan-out)) - * - */ -class ListDigraph -{ -public: - struct Node; - struct Arc; - - struct Node { - public: - Node(); - - public: - Node *prev, *next; - Arc *first_in, *first_out; - }; - - struct Arc { - public: - Arc(); - - public: - Node *target, *source; - Arc *prev_in, *next_in; - Arc *prev_out, *next_out; - }; - -public: - ListDigraph(); - - Node* addNode(); - - Arc* addArc(Node& pU, Node& pV); - - void erase(Node& pNode); - - void erase(Arc& pArc); - - void clear(); - - void getHead(Node*& pNode) const { pNode = m_pNodeHead; } - -private: - typedef GCFactory<Node, 0> NodeList; - typedef GCFactory<Arc, 0> ArcList; - -private: - Node* m_pNodeHead; - Node* m_pFreeNodeHead; - Arc* m_pFreeArcHead; - - NodeList m_NodeList; - ArcList m_ArcList; -}; - -} // namespace of graph -} // namespace of mcld - -#endif -
diff --git a/include/mcld/ADT/HashBase.h b/include/mcld/ADT/HashBase.h index d80333b..f3019bd 100644 --- a/include/mcld/ADT/HashBase.h +++ b/include/mcld/ADT/HashBase.h
@@ -6,37 +6,37 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_HASHBASE_H -#define MCLD_ADT_HASHBASE_H +#ifndef MCLD_ADT_HASHBASE_H_ +#define MCLD_ADT_HASHBASE_H_ + #include <llvm/ADT/StringRef.h> + #include <cstdlib> namespace mcld { /** forward declaration **/ -template<typename HashTableImplTy> +template <typename HashTableImplTy> class ChainIteratorBase; -template<typename HashTableImplTy> +template <typename HashTableImplTy> class EntryIteratorBase; /** \class HashBucket * \brief HashBucket is an entry in the hash table. */ -template<typename HashEntryTy> -class HashBucket -{ -public: +template <typename HashEntryTy> +class HashBucket { + public: typedef HashEntryTy entry_type; -public: + public: unsigned int FullHashValue; - entry_type *Entry; + entry_type* Entry; -public: + public: static entry_type* getEmptyBucket(); static entry_type* getTombstone(); - }; /** \class HashTableImpl @@ -60,14 +60,12 @@ * than static linkers. HashTableImpl also provides a template argument to * change the hash functions. */ -template<typename HashEntryTy, - typename HashFunctionTy> -class HashTableImpl -{ -private: +template <typename HashEntryTy, typename HashFunctionTy> +class HashTableImpl { + private: static const unsigned int NumOfInitBuckets = 16; -public: + public: typedef size_t size_type; typedef HashFunctionTy hasher; typedef HashEntryTy entry_type; @@ -75,8 +73,7 @@ typedef HashBucket<HashEntryTy> bucket_type; typedef HashTableImpl<HashEntryTy, HashFunctionTy> Self; - -public: + public: HashTableImpl(); explicit HashTableImpl(unsigned int pInitSize); virtual ~HashTableImpl(); @@ -84,19 +81,15 @@ // ----- observers ----- // bool empty() const; - size_t numOfBuckets() const - { return m_NumOfBuckets; } + size_t numOfBuckets() const { return m_NumOfBuckets; } - size_t numOfEntries() const - { return m_NumOfEntries; } + size_t numOfEntries() const { return m_NumOfEntries; } - hasher& hash() - { return m_Hasher; } + hasher& hash() { return m_Hasher; } - const hasher& hash() const - { return m_Hasher; } + const hasher& hash() const { return m_Hasher; } -protected: + protected: /// initialize the hash table. void init(unsigned int pInitSize); @@ -113,26 +106,26 @@ /// mayRehash - check the load_factor, compute the new size, and then doRehash void mayRehash(); - /// doRehash - re-new the hash table, and rehash all elements into the new buckets + /// doRehash - re-new the hash table, and rehash all elements into the new + /// buckets void doRehash(unsigned int pNewSize); -friend class ChainIteratorBase<Self>; -friend class ChainIteratorBase<const Self>; -friend class EntryIteratorBase<Self>; -friend class EntryIteratorBase<const Self>; -protected: + friend class ChainIteratorBase<Self>; + friend class ChainIteratorBase<const Self>; + friend class EntryIteratorBase<Self>; + friend class EntryIteratorBase<const Self>; + + protected: // Array of Buckets bucket_type* m_Buckets; unsigned int m_NumOfBuckets; unsigned int m_NumOfEntries; unsigned int m_NumOfTombstones; hasher m_Hasher; - }; #include "HashBase.tcc" -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_ADT_HASHBASE_H_
diff --git a/include/mcld/ADT/HashBase.tcc b/include/mcld/ADT/HashBase.tcc index 50f6ac4..8b0a9be 100644 --- a/include/mcld/ADT/HashBase.tcc +++ b/include/mcld/ADT/HashBase.tcc
@@ -10,13 +10,11 @@ //===----------------------------------------------------------------------===// // internal non-member functions //===----------------------------------------------------------------------===// -inline static unsigned int compute_bucket_count(unsigned int pNumOfBuckets) -{ - static const unsigned int bucket_size[] = - { - 1, 3, 17, 37, 67, 97, 197, 419, 977, 2593, 4099, 8209, 12289, - 16411, 20483, 32771, 49157, 65537, 98317, 131101, 196613 - }; +inline static unsigned int compute_bucket_count(unsigned int pNumOfBuckets) { + static const unsigned int bucket_size[] = { + 1, 3, 17, 37, 67, 97, 197, + 419, 977, 2593, 4099, 8209, 12289, 16411, + 20483, 32771, 49157, 65537, 98317, 131101, 196613}; const unsigned int buckets_count = sizeof(bucket_size) / sizeof(bucket_size[0]); @@ -26,26 +24,24 @@ return bucket_size[idx]; } ++idx; - } while(idx < buckets_count); + } while (idx < buckets_count); - return (pNumOfBuckets+131101); // rare case. increase constantly + return (pNumOfBuckets + 131101); // rare case. increase constantly } //===----------------------------------------------------------------------===// // template implementation of HashBucket //===----------------------------------------------------------------------===// -template<typename DataType> +template <typename DataType> typename HashBucket<DataType>::entry_type* -HashBucket<DataType>::getEmptyBucket() -{ +HashBucket<DataType>::getEmptyBucket() { static entry_type* empty_bucket = reinterpret_cast<entry_type*>(0x0); return empty_bucket; } -template<typename DataType> +template <typename DataType> typename HashBucket<DataType>::entry_type* -HashBucket<DataType>::getTombstone() -{ +HashBucket<DataType>::getTombstone() { static entry_type* tombstone = reinterpret_cast<entry_type*>(0x1); return tombstone; } @@ -53,21 +49,19 @@ //===----------------------------------------------------------------------===// // template implementation of HashTableImpl //===----------------------------------------------------------------------===// -template<typename HashEntryTy, - typename HashFunctionTy> +template <typename HashEntryTy, typename HashFunctionTy> HashTableImpl<HashEntryTy, HashFunctionTy>::HashTableImpl() - : m_Buckets(0), - m_NumOfBuckets(0), - m_NumOfEntries(0), - m_NumOfTombstones(0), - m_Hasher() { + : m_Buckets(0), + m_NumOfBuckets(0), + m_NumOfEntries(0), + m_NumOfTombstones(0), + m_Hasher() { } -template<typename HashEntryTy, - typename HashFunctionTy> +template <typename HashEntryTy, typename HashFunctionTy> HashTableImpl<HashEntryTy, HashFunctionTy>::HashTableImpl( - unsigned int pInitSize) - : m_Hasher() { + unsigned int pInitSize) + : m_Hasher() { if (pInitSize) { init(pInitSize); return; @@ -79,27 +73,22 @@ m_NumOfTombstones = 0; } -template<typename HashEntryTy, - typename HashFunctionTy> -HashTableImpl<HashEntryTy, HashFunctionTy>::~HashTableImpl() -{ +template <typename HashEntryTy, typename HashFunctionTy> +HashTableImpl<HashEntryTy, HashFunctionTy>::~HashTableImpl() { clear(); } /// empty - check if the hash table is empty -template<typename HashEntryTy, - typename HashFunctionTy> -bool HashTableImpl<HashEntryTy, HashFunctionTy>::empty() const -{ - return (0 == m_NumOfEntries); +template <typename HashEntryTy, typename HashFunctionTy> +bool HashTableImpl<HashEntryTy, HashFunctionTy>::empty() const { + return (m_NumOfEntries == 0); } /// init - initialize the hash table. -template<typename HashEntryTy, - typename HashFunctionTy> -void HashTableImpl<HashEntryTy, HashFunctionTy>::init(unsigned int pInitSize) -{ - m_NumOfBuckets = pInitSize? compute_bucket_count(pInitSize): NumOfInitBuckets; +template <typename HashEntryTy, typename HashFunctionTy> +void HashTableImpl<HashEntryTy, HashFunctionTy>::init(unsigned int pInitSize) { + m_NumOfBuckets = + pInitSize ? compute_bucket_count(pInitSize) : NumOfInitBuckets; m_NumOfEntries = 0; m_NumOfTombstones = 0; @@ -109,10 +98,8 @@ } /// clear - clear the hash table. -template<typename HashEntryTy, - typename HashFunctionTy> -void HashTableImpl<HashEntryTy, HashFunctionTy>::clear() -{ +template <typename HashEntryTy, typename HashFunctionTy> +void HashTableImpl<HashEntryTy, HashFunctionTy>::clear() { free(m_Buckets); m_Buckets = 0; @@ -122,13 +109,10 @@ } /// lookUpBucketFor - look up the bucket whose key is pKey -template<typename HashEntryTy, - typename HashFunctionTy> -unsigned int -HashTableImpl<HashEntryTy, HashFunctionTy>::lookUpBucketFor( - const typename HashTableImpl<HashEntryTy, HashFunctionTy>::key_type& pKey) -{ - if (0 == m_NumOfBuckets) { +template <typename HashEntryTy, typename HashFunctionTy> +unsigned int HashTableImpl<HashEntryTy, HashFunctionTy>::lookUpBucketFor( + const typename HashTableImpl<HashEntryTy, HashFunctionTy>::key_type& pKey) { + if (m_NumOfBuckets == 0) { // NumOfBuckets is changed after init(pInitSize) init(NumOfInitBuckets); } @@ -140,11 +124,11 @@ int firstTombstone = -1; // linear probing - while(true) { + while (true) { bucket_type& bucket = m_Buckets[index]; // If we found an empty bucket, this key isn't in the table yet, return it. if (bucket_type::getEmptyBucket() == bucket.Entry) { - if (-1 != firstTombstone) { + if (firstTombstone != -1) { m_Buckets[firstTombstone].FullHashValue = full_hash; return firstTombstone; } @@ -154,11 +138,10 @@ } if (bucket_type::getTombstone() == bucket.Entry) { - if (-1 == firstTombstone) { + if (firstTombstone == -1) { firstTombstone = index; } - } - else if (bucket.FullHashValue == full_hash) { + } else if (bucket.FullHashValue == full_hash) { if (bucket.Entry->compare(pKey)) { return index; } @@ -170,13 +153,11 @@ } } -template<typename HashEntryTy, - typename HashFunctionTy> -int -HashTableImpl<HashEntryTy, HashFunctionTy>::findKey( - const typename HashTableImpl<HashEntryTy, HashFunctionTy>::key_type& pKey) const -{ - if (0 == m_NumOfBuckets) +template <typename HashEntryTy, typename HashFunctionTy> +int HashTableImpl<HashEntryTy, HashFunctionTy>::findKey( + const typename HashTableImpl<HashEntryTy, HashFunctionTy>::key_type& pKey) + const { + if (m_NumOfBuckets == 0) return -1; unsigned int full_hash = m_Hasher(pKey); @@ -185,15 +166,14 @@ const unsigned int probe = 1; // linear probing while (true) { - bucket_type &bucket = m_Buckets[index]; + bucket_type& bucket = m_Buckets[index]; if (bucket_type::getEmptyBucket() == bucket.Entry) return -1; if (bucket_type::getTombstone() == bucket.Entry) { // Ignore tombstones. - } - else if (full_hash == bucket.FullHashValue) { + } else if (full_hash == bucket.FullHashValue) { // get string, compare, if match, return index if (bucket.Entry->compare(pKey)) return index; @@ -204,18 +184,16 @@ } } -template<typename HashEntryTy, - typename HashFunctionTy> -void HashTableImpl<HashEntryTy, HashFunctionTy>::mayRehash() -{ - +template <typename HashEntryTy, typename HashFunctionTy> +void HashTableImpl<HashEntryTy, HashFunctionTy>::mayRehash() { unsigned int new_size; // If the hash table is now more than 3/4 full, or if fewer than 1/8 of // the buckets are empty (meaning that many are filled with tombstones), // grow/rehash the table. - if ((m_NumOfEntries<<2) > m_NumOfBuckets*3) + if ((m_NumOfEntries << 2) > m_NumOfBuckets * 3) new_size = compute_bucket_count(m_NumOfBuckets); - else if (((m_NumOfBuckets-(m_NumOfEntries+m_NumOfTombstones))<<3) < m_NumOfBuckets) + else if (((m_NumOfBuckets - (m_NumOfEntries + m_NumOfTombstones)) << 3) < + m_NumOfBuckets) new_size = m_NumOfBuckets; else return; @@ -223,15 +201,15 @@ doRehash(new_size); } -template<typename HashEntryTy, - typename HashFunctionTy> -void HashTableImpl<HashEntryTy, HashFunctionTy>::doRehash(unsigned int pNewSize) -{ +template <typename HashEntryTy, typename HashFunctionTy> +void HashTableImpl<HashEntryTy, HashFunctionTy>::doRehash( + unsigned int pNewSize) { bucket_type* new_table = (bucket_type*)calloc(pNewSize, sizeof(bucket_type)); // Rehash all the items into their new buckets. Luckily :) we already have // the hash values available, so we don't have to recall hash function again. - for (bucket_type *IB = m_Buckets, *E = m_Buckets+m_NumOfBuckets; IB != E; ++IB) { + for (bucket_type* IB = m_Buckets, * E = m_Buckets + m_NumOfBuckets; IB != E; + ++IB) { if (IB->Entry != bucket_type::getEmptyBucket() && IB->Entry != bucket_type::getTombstone()) { // Fast case, bucket available. @@ -263,4 +241,3 @@ m_NumOfBuckets = pNewSize; m_NumOfTombstones = 0; } -
diff --git a/include/mcld/ADT/HashEntry.h b/include/mcld/ADT/HashEntry.h index 3dc3ab7..fd450dd 100644 --- a/include/mcld/ADT/HashEntry.h +++ b/include/mcld/ADT/HashEntry.h
@@ -1,4 +1,4 @@ -//===- HashEntry.h ---------------------------------------------------------===// +//===- HashEntry.h --------------------------------------------------------===// // // The MCLinker Project // @@ -7,13 +7,13 @@ // //===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_HASHENTRY_H -#define MCLD_ADT_HASHENTRY_H +#ifndef MCLD_ADT_HASHENTRY_H_ +#define MCLD_ADT_HASHENTRY_H_ namespace mcld { /** forward declaration **/ -template<typename HashEntryTy> +template <typename HashEntryTy> class EntryFactory; /** \class HashEntry @@ -30,53 +30,46 @@ * are doing when you let a new class inherit from mcld::HashEntry. */ template <typename KeyType, typename ValueType, typename KeyCompare> -class HashEntry -{ -public: +class HashEntry { + public: typedef KeyType key_type; typedef ValueType value_type; typedef KeyCompare key_compare; -private: + private: typedef HashEntry<KeyType, ValueType, KeyCompare> Self; friend class EntryFactory<Self>; -private: - HashEntry(const KeyType& pKey); + private: + explicit HashEntry(const KeyType& pKey); ~HashEntry(); -public: - KeyType& key() - { return m_Key; } + public: + KeyType& key() { return m_Key; } - const KeyType& key() const - { return m_Key; } + const KeyType& key() const { return m_Key; } - ValueType& value() - { return m_Value; } + ValueType& value() { return m_Value; } - const ValueType& value() const - { return m_Value; } + const ValueType& value() const { return m_Value; } - void setValue(const ValueType& pValue) - { m_Value = pValue; } + void setValue(const ValueType& pValue) { m_Value = pValue; } bool compare(const key_type& pKey); -public: + public: KeyType m_Key; ValueType m_Value; }; template <typename HashEntryTy> -class EntryFactory -{ -public: - typedef HashEntryTy entry_type; - typedef typename HashEntryTy::key_type key_type; +class EntryFactory { + public: + typedef HashEntryTy entry_type; + typedef typename HashEntryTy::key_type key_type; typedef typename HashEntryTy::value_type value_type; -public: + public: EntryFactory(); ~EntryFactory(); @@ -86,7 +79,6 @@ #include "HashEntry.tcc" -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_ADT_HASHENTRY_H_
diff --git a/include/mcld/ADT/HashEntry.tcc b/include/mcld/ADT/HashEntry.tcc index fdd886b..3aa514e 100644 --- a/include/mcld/ADT/HashEntry.tcc +++ b/include/mcld/ADT/HashEntry.tcc
@@ -11,17 +11,15 @@ // template implementation of HashEntry template <typename KeyType, typename ValueType, typename KeyCompare> HashEntry<KeyType, ValueType, KeyCompare>::HashEntry(const KeyType& pKey) - : m_Key(pKey) { + : m_Key(pKey) { } template <typename KeyType, typename ValueType, typename KeyCompare> -HashEntry<KeyType, ValueType, KeyCompare>::~HashEntry() -{ +HashEntry<KeyType, ValueType, KeyCompare>::~HashEntry() { } template <typename KeyType, typename ValueType, typename KeyCompare> -bool HashEntry<KeyType, ValueType, KeyCompare>::compare(const KeyType& pKey) -{ +bool HashEntry<KeyType, ValueType, KeyCompare>::compare(const KeyType& pKey) { static KeyCompare comparator; return comparator(m_Key, pKey); } @@ -29,25 +27,20 @@ //===--------------------------------------------------------------------===// // template implementation of EntryFactory template <typename HashEntryTy> -EntryFactory<HashEntryTy>::EntryFactory() -{ +EntryFactory<HashEntryTy>::EntryFactory() { } template <typename HashEntryTy> -EntryFactory<HashEntryTy>::~EntryFactory() -{ +EntryFactory<HashEntryTy>::~EntryFactory() { } template <typename HashEntryTy> -void EntryFactory<HashEntryTy>::destroy(HashEntryTy* pEntry) -{ +void EntryFactory<HashEntryTy>::destroy(HashEntryTy* pEntry) { delete pEntry; } template <typename HashEntryTy> -HashEntryTy* -EntryFactory<HashEntryTy>::produce(const typename EntryFactory<HashEntryTy>::key_type& pKey) -{ +HashEntryTy* EntryFactory<HashEntryTy>::produce( + const typename EntryFactory<HashEntryTy>::key_type& pKey) { return new HashEntryTy(pKey); } -
diff --git a/include/mcld/ADT/HashEntryFactory.h b/include/mcld/ADT/HashEntryFactory.h index 91deab4..6c6114f 100644 --- a/include/mcld/ADT/HashEntryFactory.h +++ b/include/mcld/ADT/HashEntryFactory.h
@@ -1,4 +1,4 @@ -//===- HashEntryFactory.h --------------------------------------------------===// +//===- HashEntryFactory.h -------------------------------------------------===// // // The MCLinker Project // @@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_HASHENTRYFACTORY_H -#define MCLD_ADT_HASHENTRYFACTORY_H +#ifndef MCLD_ADT_HASHENTRYFACTORY_H_ +#define MCLD_ADT_HASHENTRYFACTORY_H_ namespace mcld { @@ -15,22 +15,20 @@ * \brief HashEntryFactoy is a factory wrapper for those entries who have * factory methods. */ -template<typename HashEntryTy> -class HashEntryFactory -{ -public: - typedef HashEntryTy entry_type; +template <typename HashEntryTy> +class HashEntryFactory { + public: + typedef HashEntryTy entry_type; typedef typename HashEntryTy::key_type key_type; -public: - entry_type* produce(const key_type& pKey) - { return HashEntryTy::Create(pKey); } + public: + entry_type* produce(const key_type& pKey) { + return HashEntryTy::Create(pKey); + } - void destroy(entry_type*& pEntry) - { HashEntryTy::Destroy(pEntry); } + void destroy(entry_type*& pEntry) { HashEntryTy::Destroy(pEntry); } }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_ADT_HASHENTRYFACTORY_H_
diff --git a/include/mcld/ADT/HashIterator.h b/include/mcld/ADT/HashIterator.h index adf593f..c7764a3 100644 --- a/include/mcld/ADT/HashIterator.h +++ b/include/mcld/ADT/HashIterator.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_HASHITERATOR_H -#define MCLD_ADT_HASHITERATOR_H +#ifndef MCLD_ADT_HASHITERATOR_H_ +#define MCLD_ADT_HASHITERATOR_H_ #include <cstddef> @@ -16,32 +16,28 @@ /** \class ChainIteratorBase * \brief ChaintIteratorBase follows the HashEntryTy with the same hash value. */ -template<typename HashTableImplTy> -class ChainIteratorBase -{ -public: +template <typename HashTableImplTy> +class ChainIteratorBase { + public: typedef HashTableImplTy hash_table; typedef typename HashTableImplTy::key_type key_type; typedef typename HashTableImplTy::entry_type entry_type; typedef typename HashTableImplTy::bucket_type bucket_type; -public: + public: ChainIteratorBase() - : m_pHashTable(0), m_Index(0), m_HashValue(0), m_EndIndex(0) - { } + : m_pHashTable(NULL), m_Index(0), m_HashValue(0), m_EndIndex(0) {} ChainIteratorBase(HashTableImplTy* pTable, const key_type& pKey) - : m_pHashTable(pTable) - { + : m_pHashTable(pTable) { m_HashValue = pTable->hash()(pKey); m_EndIndex = m_Index = m_HashValue % m_pHashTable->m_NumOfBuckets; const unsigned int probe = 1; - while(true) { - bucket_type &bucket = m_pHashTable->m_Buckets[m_Index]; + while (true) { + bucket_type& bucket = m_pHashTable->m_Buckets[m_Index]; if (bucket_type::getTombstone() == bucket.Entry) { // Ignore tombstones. - } - else if (m_HashValue == bucket.FullHashValue) { + } else if (m_HashValue == bucket.FullHashValue) { if (bucket.Entry->compare(pKey)) { m_EndIndex = m_Index; break; @@ -59,11 +55,10 @@ } ChainIteratorBase(const ChainIteratorBase& pCopy) - : m_pHashTable(pCopy.m_pHashTable), - m_Index(pCopy.m_Index), - m_HashValue(pCopy.m_HashValue), - m_EndIndex(pCopy.m_EndIndex) - { } + : m_pHashTable(pCopy.m_pHashTable), + m_Index(pCopy.m_Index), + m_HashValue(pCopy.m_HashValue), + m_EndIndex(pCopy.m_EndIndex) {} ChainIteratorBase& assign(const ChainIteratorBase& pCopy) { m_pHashTable = pCopy.m_pHashTable; @@ -74,41 +69,41 @@ } inline bucket_type* getBucket() { - if (0 == m_pHashTable) - return 0; + if (m_pHashTable == NULL) + return NULL; return &(m_pHashTable->m_Buckets[m_Index]); } inline const bucket_type* getBucket() const { - if (0 == m_pHashTable) - return 0; + if (m_pHashTable == NULL) + return NULL; return &(m_pHashTable->m_Buckets[m_Index]); } inline entry_type* getEntry() { - if (0 == m_pHashTable) - return 0; + if (m_pHashTable == NULL) + return NULL; return m_pHashTable->m_Buckets[m_Index].Entry; } inline const entry_type* getEntry() const { - if (0 == m_pHashTable) - return 0; + if (m_pHashTable == NULL) + return NULL; return m_pHashTable->m_Buckets[m_Index].Entry; } inline void reset() { - m_pHashTable = 0; + m_pHashTable = NULL; m_Index = 0; m_EndIndex = 0; m_HashValue = 0; } inline void advance() { - if (0 == m_pHashTable) + if (m_pHashTable == NULL) return; const unsigned int probe = 1; - while(true) { + while (true) { m_Index += probe; if (m_Index == m_pHashTable->m_NumOfBuckets) m_Index = 0; @@ -118,13 +113,12 @@ return; } - bucket_type &bucket = m_pHashTable->m_Buckets[m_Index]; + bucket_type& bucket = m_pHashTable->m_Buckets[m_Index]; if (bucket_type::getTombstone() == bucket.Entry || bucket_type::getEmptyBucket() == bucket.Entry) { // Ignore tombstones. - } - else if (m_HashValue == bucket.FullHashValue) { + } else if (m_HashValue == bucket.FullHashValue) { return; } } @@ -132,19 +126,19 @@ bool operator==(const ChainIteratorBase& pCopy) const { if (m_pHashTable == pCopy.m_pHashTable) { - if (0 == m_pHashTable) + if (m_pHashTable == NULL) return true; return ((m_HashValue == pCopy.m_HashValue) && - (m_EndIndex == pCopy.m_EndIndex) && - (m_Index == pCopy.m_Index)); + (m_EndIndex == pCopy.m_EndIndex) && (m_Index == pCopy.m_Index)); } return false; } - bool operator!=(const ChainIteratorBase& pCopy) const - { return !(*this == pCopy); } + bool operator!=(const ChainIteratorBase& pCopy) const { + return !(*this == pCopy); + } -private: + private: HashTableImplTy* m_pHashTable; unsigned int m_Index; unsigned int m_HashValue; @@ -155,28 +149,22 @@ * \brief EntryIteratorBase walks over hash table by the natural layout of the * buckets */ -template<typename HashTableImplTy> -class EntryIteratorBase -{ -public: +template <typename HashTableImplTy> +class EntryIteratorBase { + public: typedef HashTableImplTy hash_table; typedef typename HashTableImplTy::key_type key_type; typedef typename HashTableImplTy::entry_type entry_type; typedef typename HashTableImplTy::bucket_type bucket_type; -public: - EntryIteratorBase() - : m_pHashTable(0), m_Index(0) - { } + public: + EntryIteratorBase() : m_pHashTable(NULL), m_Index(0) {} - EntryIteratorBase(HashTableImplTy* pTable, - unsigned int pIndex) - : m_pHashTable(pTable), m_Index(pIndex) - { } + EntryIteratorBase(HashTableImplTy* pTable, unsigned int pIndex) + : m_pHashTable(pTable), m_Index(pIndex) {} EntryIteratorBase(const EntryIteratorBase& pCopy) - : m_pHashTable(pCopy.m_pHashTable), m_Index(pCopy.m_Index) - { } + : m_pHashTable(pCopy.m_pHashTable), m_Index(pCopy.m_Index) {} EntryIteratorBase& assign(const EntryIteratorBase& pCopy) { m_pHashTable = pCopy.m_pHashTable; @@ -185,58 +173,60 @@ } inline bucket_type* getBucket() { - if (0 == m_pHashTable) - return 0; + if (m_pHashTable == NULL) + return NULL; return &(m_pHashTable->m_Buckets[m_Index]); } inline const bucket_type* getBucket() const { - if (0 == m_pHashTable) - return 0; + if (m_pHashTable == NULL) + return NULL; return &(m_pHashTable->m_Buckets[m_Index]); } inline entry_type* getEntry() { - if (0 == m_pHashTable) - return 0; + if (m_pHashTable == NULL) + return NULL; return m_pHashTable->m_Buckets[m_Index].Entry; } inline const entry_type* getEntry() const { - if (0 == m_pHashTable) - return 0; + if (m_pHashTable == NULL) + return NULL; return m_pHashTable->m_Buckets[m_Index].Entry; } inline void reset() { - m_pHashTable = 0; + m_pHashTable = NULL; m_Index = 0; } inline void advance() { - if (0 == m_pHashTable) + if (m_pHashTable == NULL) return; do { ++m_Index; - if (m_pHashTable->m_NumOfBuckets == m_Index) { // to the end + if (m_pHashTable->m_NumOfBuckets == m_Index) { // to the end reset(); return; } - } while(bucket_type::getEmptyBucket() == m_pHashTable->m_Buckets[m_Index].Entry || - bucket_type::getTombstone() == m_pHashTable->m_Buckets[m_Index].Entry); + } while (bucket_type::getEmptyBucket() == + m_pHashTable->m_Buckets[m_Index].Entry || + bucket_type::getTombstone() == + m_pHashTable->m_Buckets[m_Index].Entry); } - bool operator==(const EntryIteratorBase& pCopy) const - { return ((m_pHashTable == pCopy.m_pHashTable) && - (m_Index == pCopy.m_Index)); } + bool operator==(const EntryIteratorBase& pCopy) const { + return ((m_pHashTable == pCopy.m_pHashTable) && (m_Index == pCopy.m_Index)); + } - bool operator!=(const EntryIteratorBase& pCopy) const - { return !(*this == pCopy); } + bool operator!=(const EntryIteratorBase& pCopy) const { + return !(*this == pCopy); + } -private: + private: HashTableImplTy* m_pHashTable; unsigned int m_Index; - }; /** \class HashIterator @@ -250,53 +240,41 @@ * behavior by change the template argument IteratorBase. HashTable defines * above two iterators by defining HashIterators with different IteratorBase. */ -template<typename IteratorBase, - typename Traits> -class HashIterator : public IteratorBase -{ -public: - typedef Traits traits; - typedef typename traits::pointer pointer; +template <typename IteratorBase, typename Traits> +class HashIterator : public IteratorBase { + public: + typedef Traits traits; + typedef typename traits::pointer pointer; typedef typename traits::reference reference; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef IteratorBase Base; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef IteratorBase Base; - typedef HashIterator<IteratorBase, - Traits> Self; + typedef HashIterator<IteratorBase, Traits> Self; typedef typename traits::nonconst_traits nonconst_traits; - typedef HashIterator<IteratorBase, - nonconst_traits> iterator; + typedef HashIterator<IteratorBase, nonconst_traits> iterator; - typedef typename traits::const_traits const_traits; - typedef HashIterator<IteratorBase, - const_traits> const_iterator; - typedef std::forward_iterator_tag iterator_category; + typedef typename traits::const_traits const_traits; + typedef HashIterator<IteratorBase, const_traits> const_iterator; + typedef std::forward_iterator_tag iterator_category; -public: - HashIterator() - : IteratorBase() - { } + public: + HashIterator() : IteratorBase() {} /// HashIterator - constructor for EntryIterator HashIterator(typename IteratorBase::hash_table* pTable, unsigned int pIndex) - : IteratorBase(pTable, pIndex) - { } + : IteratorBase(pTable, pIndex) {} /// HashIterator - constructor for ChainIterator explicit HashIterator(typename IteratorBase::hash_table* pTable, const typename IteratorBase::key_type& pKey, int) - : IteratorBase(pTable, pKey) - { } + : IteratorBase(pTable, pKey) {} - HashIterator(const HashIterator& pCopy) - : IteratorBase(pCopy) - { } + HashIterator(const HashIterator& pCopy) : IteratorBase(pCopy) {} - ~HashIterator() - { } + ~HashIterator() {} HashIterator& operator=(const HashIterator& pCopy) { IteratorBase::assign(pCopy); @@ -316,7 +294,6 @@ } }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_ADT_HASHITERATOR_H_
diff --git a/include/mcld/ADT/HashTable.h b/include/mcld/ADT/HashTable.h index 83ff868..62b1bd3 100644 --- a/include/mcld/ADT/HashTable.h +++ b/include/mcld/ADT/HashTable.h
@@ -1,4 +1,4 @@ -//===- HashTable.h ---------------------------------------------------------===// +//===- HashTable.h --------------------------------------------------------===// // // The MCLinker Project // @@ -6,15 +6,16 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_HASHTABLE_H -#define MCLD_ADT_HASHTABLE_H +#ifndef MCLD_ADT_HASHTABLE_H_ +#define MCLD_ADT_HASHTABLE_H_ -#include <mcld/ADT/HashBase.h> -#include <mcld/ADT/HashIterator.h> -#include <mcld/ADT/HashEntryFactory.h> -#include <mcld/ADT/Uncopyable.h> -#include <mcld/ADT/TypeTraits.h> -#include <mcld/Support/Allocators.h> +#include "mcld/ADT/HashBase.h" +#include "mcld/ADT/HashEntryFactory.h" +#include "mcld/ADT/HashIterator.h" +#include "mcld/ADT/TypeTraits.h" +#include "mcld/Support/Allocators.h" +#include "mcld/Support/Compiler.h" + #include <utility> namespace mcld { @@ -27,42 +28,39 @@ * the memory space of the entries by itself. Instead, entries are allocated * outside and then emplaced into the hash table. */ -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy = HashEntryFactory<HashEntryTy> > -class HashTable : public HashTableImpl<HashEntryTy, HashFunctionTy>, - private Uncopyable -{ -private: +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy = HashEntryFactory<HashEntryTy> > +class HashTable : public HashTableImpl<HashEntryTy, HashFunctionTy> { + private: typedef HashTableImpl<HashEntryTy, HashFunctionTy> BaseTy; -public: + public: typedef size_t size_type; typedef HashFunctionTy hasher; typedef HashEntryTy entry_type; typedef typename BaseTy::bucket_type bucket_type; typedef typename HashEntryTy::key_type key_type; - typedef HashIterator<ChainIteratorBase<BaseTy>, - NonConstTraits<HashEntryTy> > chain_iterator; + typedef HashIterator<ChainIteratorBase<BaseTy>, NonConstTraits<HashEntryTy> > + chain_iterator; typedef HashIterator<ChainIteratorBase<const BaseTy>, - ConstTraits<HashEntryTy> > const_chain_iterator; + ConstTraits<HashEntryTy> > const_chain_iterator; - typedef HashIterator<EntryIteratorBase<BaseTy>, - NonConstTraits<HashEntryTy> > entry_iterator; + typedef HashIterator<EntryIteratorBase<BaseTy>, NonConstTraits<HashEntryTy> > + entry_iterator; typedef HashIterator<EntryIteratorBase<const BaseTy>, - ConstTraits<HashEntryTy> > const_entry_iterator; + ConstTraits<HashEntryTy> > const_entry_iterator; - typedef entry_iterator iterator; - typedef const_entry_iterator const_iterator; + typedef entry_iterator iterator; + typedef const_entry_iterator const_iterator; -public: + public: // ----- constructor ----- // - explicit HashTable(size_type pSize=3); + explicit HashTable(size_type pSize = 3); ~HashTable(); - EntryFactoryTy& getEntryFactory() - { return m_EntryFactory; } + EntryFactoryTy& getEntryFactory() { return m_EntryFactory; } // ----- modifiers ----- // void clear(); @@ -109,14 +107,15 @@ const_chain_iterator begin(const key_type& pKey) const; const_chain_iterator end(const key_type& pKey) const; -private: + private: EntryFactoryTy m_EntryFactory; + private: + DISALLOW_COPY_AND_ASSIGN(HashTable); }; #include "HashTable.tcc" -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_ADT_HASHTABLE_H_
diff --git a/include/mcld/ADT/HashTable.tcc b/include/mcld/ADT/HashTable.tcc index d0040ae..4d5e8dc 100644 --- a/include/mcld/ADT/HashTable.tcc +++ b/include/mcld/ADT/HashTable.tcc
@@ -1,4 +1,4 @@ -//===- HashTable.tcc ---------------------------------------------------------===// +//===- HashTable.tcc ------------------------------------------------------===// // // The MCLinker Project // @@ -7,45 +7,43 @@ // //===----------------------------------------------------------------------===// -//===--------------------------------------------------------------------===// +//===----------------------------------------------------------------------===// // template implementation of HashTable -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> -HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::HashTable(size_type pSize) - : HashTableImpl<HashEntryTy, HashFunctionTy>(pSize), m_EntryFactory() -{ +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> +HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::HashTable( + size_type pSize) + : HashTableImpl<HashEntryTy, HashFunctionTy>(pSize), m_EntryFactory() { } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> -HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::~HashTable() -{ +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> +HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::~HashTable() { if (BaseTy::empty()) return; /** clean up **/ - for (unsigned int i=0; i < BaseTy::m_NumOfBuckets; ++i) { + for (unsigned int i = 0; i < BaseTy::m_NumOfBuckets; ++i) { if (bucket_type::getEmptyBucket() != BaseTy::m_Buckets[i].Entry && - bucket_type::getTombstone() != BaseTy::m_Buckets[i].Entry ) { + bucket_type::getTombstone() != BaseTy::m_Buckets[i].Entry) { m_EntryFactory.destroy(BaseTy::m_Buckets[i].Entry); } } } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> -void HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::clear() -{ +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> +void HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::clear() { if (BaseTy::empty()) return; /** clean up **/ - for (unsigned int i=0; i < BaseTy::m_NumOfBuckets; ++i) { - if (bucket_type::getEmptyBucket() != BaseTy::m_Buckets[i].Entry ) { - if (bucket_type::getTombstone() != BaseTy::m_Buckets[i].Entry ) { + for (unsigned int i = 0; i < BaseTy::m_NumOfBuckets; ++i) { + if (bucket_type::getEmptyBucket() != BaseTy::m_Buckets[i].Entry) { + if (bucket_type::getTombstone() != BaseTy::m_Buckets[i].Entry) { m_EntryFactory.destroy(BaseTy::m_Buckets[i].Entry); } BaseTy::m_Buckets[i].Entry = bucket_type::getEmptyBucket(); @@ -57,14 +55,15 @@ /// insert - insert a new element to the container. If the element already // exist, return the element. -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::entry_type* HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::insert( - const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey, - bool& pExist) -{ + const typename HashTable<HashEntryTy, + HashFunctionTy, + EntryFactoryTy>::key_type& pKey, + bool& pExist) { unsigned int index = BaseTy::lookUpBucketFor(pKey); bucket_type& bucket = BaseTy::m_Buckets[index]; entry_type* entry = bucket.Entry; @@ -88,15 +87,16 @@ /// erase - remove the elements with the pKey // @return the number of removed elements. -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::size_type HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::erase( - const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey) -{ + const typename HashTable<HashEntryTy, + HashFunctionTy, + EntryFactoryTy>::key_type& pKey) { int index; - if (-1 == (index = BaseTy::findKey(pKey))) + if ((index = BaseTy::findKey(pKey)) == -1) return 0; bucket_type& bucket = BaseTy::m_Buckets[index]; @@ -109,39 +109,42 @@ return 1; } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::iterator HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::find( - const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey) -{ + const typename HashTable<HashEntryTy, + HashFunctionTy, + EntryFactoryTy>::key_type& pKey) { int index; - if (-1 == (index = BaseTy::findKey(pKey))) + if ((index = BaseTy::findKey(pKey)) == -1) return end(); return iterator(this, index); } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::const_iterator HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::find( - const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey) const -{ + const typename HashTable<HashEntryTy, + HashFunctionTy, + EntryFactoryTy>::key_type& pKey) const { int index; - if (-1 == (index = BaseTy::findKey(pKey))) + if ((index = BaseTy::findKey(pKey)) == -1) return end(); return const_iterator(this, index); } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::size_type HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::count( - const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey) const -{ + const typename HashTable<HashEntryTy, + HashFunctionTy, + EntryFactoryTy>::key_type& pKey) const { const_chain_iterator bucket, bEnd = end(pKey); size_type count = 0; for (bucket = begin(pKey); bucket != bEnd; ++bucket) @@ -149,39 +152,35 @@ return count; } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> -float HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::load_factor() const -{ - return ((float)BaseTy::m_NumOfEntries/(float)BaseTy::m_NumOfBuckets); +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> +float HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::load_factor() + const { + return ((float)BaseTy::m_NumOfEntries / (float)BaseTy::m_NumOfBuckets); } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> -void -HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::rehash() -{ +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> +void HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::rehash() { BaseTy::mayRehash(); } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> -void -HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::rehash( - typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::size_type pCount) -{ +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> +void HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::rehash( + typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::size_type + pCount) { BaseTy::doRehash(pCount); } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::iterator -HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin() -{ +HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin() { if (BaseTy::empty()) return end(); unsigned int index = 0; @@ -192,21 +191,19 @@ return iterator(this, index); } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::iterator -HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::end() -{ +HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::end() { return iterator(NULL, 0); } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::const_iterator -HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin() const -{ +HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin() const { if (BaseTy::empty()) return end(); unsigned int index = 0; @@ -217,52 +214,58 @@ return const_iterator(this, index); } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::const_iterator -HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::end() const -{ +HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::end() const { return const_iterator(NULL, 0); } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::chain_iterator HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin( - const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey) -{ + const typename HashTable<HashEntryTy, + HashFunctionTy, + EntryFactoryTy>::key_type& pKey) { return chain_iterator(this, pKey, 0x0); } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::chain_iterator HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::end( - const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey) -{ + const typename HashTable<HashEntryTy, + HashFunctionTy, + EntryFactoryTy>::key_type& pKey) { return chain_iterator(); } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> -typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::const_chain_iterator +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> +typename HashTable<HashEntryTy, + HashFunctionTy, + EntryFactoryTy>::const_chain_iterator HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin( - const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey) const -{ + const typename HashTable<HashEntryTy, + HashFunctionTy, + EntryFactoryTy>::key_type& pKey) const { return const_chain_iterator(this, pKey, 0x0); } -template<typename HashEntryTy, - typename HashFunctionTy, - typename EntryFactoryTy> -typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::const_chain_iterator +template <typename HashEntryTy, + typename HashFunctionTy, + typename EntryFactoryTy> +typename HashTable<HashEntryTy, + HashFunctionTy, + EntryFactoryTy>::const_chain_iterator HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::end( - const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey) const -{ + const typename HashTable<HashEntryTy, + HashFunctionTy, + EntryFactoryTy>::key_type& pKey) const { return const_chain_iterator(); } -
diff --git a/include/mcld/ADT/SizeTraits.h b/include/mcld/ADT/SizeTraits.h index 53a6742..577fd69 100644 --- a/include/mcld/ADT/SizeTraits.h +++ b/include/mcld/ADT/SizeTraits.h
@@ -6,80 +6,75 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_SIZETRAITS_H -#define MCLD_ADT_SIZETRAITS_H +#ifndef MCLD_ADT_SIZETRAITS_H_ +#define MCLD_ADT_SIZETRAITS_H_ #include <llvm/Support/DataTypes.h> #include <llvm/Support/ELF.h> -namespace mcld -{ +namespace mcld { -template<size_t SIZE> +template <size_t SIZE> class SizeTraits; -template<> -class SizeTraits<32> -{ -public: +template <> +class SizeTraits<32> { + public: typedef uint32_t Address; typedef uint32_t Offset; typedef uint32_t Word; - typedef int32_t SWord; + typedef int32_t SWord; }; -template<> -class SizeTraits<64> -{ -public: +template <> +class SizeTraits<64> { + public: typedef uint64_t Address; typedef uint64_t Offset; typedef uint64_t Word; - typedef int64_t SWord; + typedef int64_t SWord; }; // FIXME: move this to mcld internal ELF header file? -template<size_t SIZE> +template <size_t SIZE> class ELFSizeTraits; -template<> -class ELFSizeTraits<32> -{ -public: - typedef llvm::ELF::Elf32_Addr Addr; // Program address - typedef llvm::ELF::Elf32_Off Off; // File offset - typedef llvm::ELF::Elf32_Half Half; - typedef llvm::ELF::Elf32_Word Word; +template <> +class ELFSizeTraits<32> { + public: + typedef llvm::ELF::Elf32_Addr Addr; // Program address + typedef llvm::ELF::Elf32_Off Off; // File offset + typedef llvm::ELF::Elf32_Half Half; + typedef llvm::ELF::Elf32_Word Word; typedef llvm::ELF::Elf32_Sword Sword; - typedef llvm::ELF::Elf32_Ehdr Ehdr; - typedef llvm::ELF::Elf32_Shdr Shdr; - typedef llvm::ELF::Elf32_Sym Sym; - typedef llvm::ELF::Elf32_Rel Rel; - typedef llvm::ELF::Elf32_Rela Rela; - typedef llvm::ELF::Elf32_Phdr Phdr; - typedef llvm::ELF::Elf32_Dyn Dyn; + typedef llvm::ELF::Elf32_Ehdr Ehdr; + typedef llvm::ELF::Elf32_Shdr Shdr; + typedef llvm::ELF::Elf32_Sym Sym; + typedef llvm::ELF::Elf32_Rel Rel; + typedef llvm::ELF::Elf32_Rela Rela; + typedef llvm::ELF::Elf32_Phdr Phdr; + typedef llvm::ELF::Elf32_Dyn Dyn; }; -template<> -class ELFSizeTraits<64> -{ -public: - typedef llvm::ELF::Elf64_Addr Addr; - typedef llvm::ELF::Elf64_Off Off; - typedef llvm::ELF::Elf64_Half Half; - typedef llvm::ELF::Elf64_Word Word; - typedef llvm::ELF::Elf64_Sword Sword; - typedef llvm::ELF::Elf64_Xword Xword; +template <> +class ELFSizeTraits<64> { + public: + typedef llvm::ELF::Elf64_Addr Addr; + typedef llvm::ELF::Elf64_Off Off; + typedef llvm::ELF::Elf64_Half Half; + typedef llvm::ELF::Elf64_Word Word; + typedef llvm::ELF::Elf64_Sword Sword; + typedef llvm::ELF::Elf64_Xword Xword; typedef llvm::ELF::Elf64_Sxword Sxword; - typedef llvm::ELF::Elf64_Ehdr Ehdr; - typedef llvm::ELF::Elf64_Shdr Shdr; - typedef llvm::ELF::Elf64_Sym Sym; - typedef llvm::ELF::Elf64_Rel Rel; - typedef llvm::ELF::Elf64_Rela Rela; - typedef llvm::ELF::Elf64_Phdr Phdr; - typedef llvm::ELF::Elf64_Dyn Dyn; + typedef llvm::ELF::Elf64_Ehdr Ehdr; + typedef llvm::ELF::Elf64_Shdr Shdr; + typedef llvm::ELF::Elf64_Sym Sym; + typedef llvm::ELF::Elf64_Rel Rel; + typedef llvm::ELF::Elf64_Rela Rela; + typedef llvm::ELF::Elf64_Phdr Phdr; + typedef llvm::ELF::Elf64_Dyn Dyn; }; /// alignAddress - helper function to align an address with given alignment @@ -87,24 +82,21 @@ /// /// @param pAddr - the address to be aligned /// @param pAlignConstraint - the alignment used to align the given address -inline void alignAddress(uint64_t& pAddr, uint64_t pAlignConstraint) -{ +inline void alignAddress(uint64_t& pAddr, uint64_t pAlignConstraint) { if (pAlignConstraint != 0) - pAddr = (pAddr + pAlignConstraint - 1) &~ (pAlignConstraint - 1); + pAddr = (pAddr + pAlignConstraint - 1) & ~(pAlignConstraint - 1); } -template<size_t Constraint> +template <size_t Constraint> uint64_t Align(uint64_t pAddress); -template<> -inline uint64_t Align<32>(uint64_t pAddress) -{ +template <> +inline uint64_t Align<32>(uint64_t pAddress) { return (pAddress + 0x1F) & (~0x1F); } -template<> -inline uint64_t Align<64>(uint64_t pAddress) -{ +template <> +inline uint64_t Align<64>(uint64_t pAddress) { return (pAddress + 0x3F) & (~0x3F); } @@ -120,54 +112,45 @@ /// bswap16 - byte swap 16-bit version /// @ref binary utilities - elfcpp_swap -inline uint16_t bswap16(uint16_t pData) -{ - return ((pData >> 8) & 0xFF) | ((pData & 0xFF) << 8); +inline uint16_t bswap16(uint16_t pData) { + return ((pData >> 8) & 0xFF) | ((pData & 0xFF) << 8); } /// bswap32 - byte swap 32-bit version /// @ref elfcpp_swap -inline uint32_t bswap32(uint32_t pData) -{ - return (((pData & 0xFF000000) >> 24) | - ((pData & 0x00FF0000) >> 8) | - ((pData & 0x0000FF00) << 8) | - ((pData & 0x000000FF) << 24)); - +inline uint32_t bswap32(uint32_t pData) { + return (((pData & 0xFF000000) >> 24) | ((pData & 0x00FF0000) >> 8) | + ((pData & 0x0000FF00) << 8) | ((pData & 0x000000FF) << 24)); } /// bswap64 - byte swap 64-bit version /// @ref binary utilities - elfcpp_swap -inline uint64_t bswap64(uint64_t pData) -{ - return (((pData & 0xFF00000000000000ULL) >> 56) | - ((pData & 0x00FF000000000000ULL) >> 40) | - ((pData & 0x0000FF0000000000ULL) >> 24) | - ((pData & 0x000000FF00000000ULL) >> 8) | - ((pData & 0x00000000FF000000ULL) << 8) | - ((pData & 0x0000000000FF0000ULL) << 24) | - ((pData & 0x000000000000FF00ULL) << 40) | - ((pData & 0x00000000000000FFULL) << 56)); +inline uint64_t bswap64(uint64_t pData) { + return (((pData & 0xFF00000000000000ULL) >> 56) | + ((pData & 0x00FF000000000000ULL) >> 40) | + ((pData & 0x0000FF0000000000ULL) >> 24) | + ((pData & 0x000000FF00000000ULL) >> 8) | + ((pData & 0x00000000FF000000ULL) << 8) | + ((pData & 0x0000000000FF0000ULL) << 24) | + ((pData & 0x000000000000FF00ULL) << 40) | + ((pData & 0x00000000000000FFULL) << 56)); } -template<size_t SIZE> +template <size_t SIZE> typename SizeTraits<SIZE>::Word bswap(typename SizeTraits<SIZE>::Word pData); -template<> -inline SizeTraits<32>::Word bswap<32>(SizeTraits<32>::Word pData) -{ +template <> +inline SizeTraits<32>::Word bswap<32>(SizeTraits<32>::Word pData) { return bswap32(pData); } -template<> -inline SizeTraits<64>::Word bswap<64>(SizeTraits<64>::Word pData) -{ +template <> +inline SizeTraits<64>::Word bswap<64>(SizeTraits<64>::Word pData) { return bswap64(pData); } template <size_t WIDTH> -inline uint64_t signExtend(uint64_t pVal) -{ +inline uint64_t signExtend(uint64_t pVal) { uint64_t mask = (~((uint64_t)0)) >> (64 - WIDTH); uint64_t sign_bit = 1 << (WIDTH - 1); @@ -175,23 +158,21 @@ } template <> -inline uint64_t signExtend<64>(uint64_t pVal) -{ +inline uint64_t signExtend<64>(uint64_t pVal) { return pVal; } template <size_t SizeOfStr, typename FieldType> -class StringSizerHelper -{ -private: +class StringSizerHelper { + private: char FIELD_TOO_SMALL[SizeOfStr <= FieldType(~0U) ? 1 : -1]; -public: + + public: enum { Size = SizeOfStr }; }; -#define STR_SIZE(str, fieldTy) StringSizerHelper<sizeof(str)-1, fieldTy>::Size +#define STR_SIZE(str, fieldTy) StringSizerHelper<sizeof(str) - 1, fieldTy>::Size -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_ADT_SIZETRAITS_H_
diff --git a/include/mcld/ADT/StringEntry.h b/include/mcld/ADT/StringEntry.h index 4f57f10..99610cc 100644 --- a/include/mcld/ADT/StringEntry.h +++ b/include/mcld/ADT/StringEntry.h
@@ -1,4 +1,4 @@ -//===- StringEntry.h -------------------------------------------------------===// +//===- StringEntry.h ------------------------------------------------------===// // // The MCLinker Project // @@ -6,64 +6,55 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_STRINGENTRY_H -#define MCLD_ADT_STRINGENTRY_H +#ifndef MCLD_ADT_STRINGENTRY_H_ +#define MCLD_ADT_STRINGENTRY_H_ + #include <llvm/ADT/StringRef.h> #include <llvm/Support/DataTypes.h> + +#include <cassert> #include <cstdlib> #include <cstring> -#include <cassert> -namespace mcld -{ -template<typename DataType> +namespace mcld { +template <typename DataType> class StringEntryFactory; /** \class StringEntry * \brief StringEntry is a pair of strings which is designed for high locality. */ -template<typename DataType> -class StringEntry -{ -public: - typedef llvm::StringRef key_type; +template <typename DataType> +class StringEntry { + public: + typedef llvm::StringRef key_type; typedef DataType value_type; -public: - key_type key() - { return key_type(m_Key, m_KeyLen); } + public: + key_type key() { return key_type(m_Key, m_KeyLen); } - const key_type key() const - { return key_type(m_Key, m_KeyLen); } + const key_type key() const { return key_type(m_Key, m_KeyLen); } - value_type& value() - { return m_Value; } + value_type& value() { return m_Value; } - const value_type& value() const - { return m_Value; } + const value_type& value() const { return m_Value; } - size_t getKeyLength() const - { return m_KeyLen; } + size_t getKeyLength() const { return m_KeyLen; } - size_t getValueLength() const - { return m_Value.size(); } + size_t getValueLength() const { return m_Value.size(); } - void setValue(const DataType& pVal) - { m_Value = pVal; } + void setValue(const DataType& pVal) { m_Value = pVal; } - bool compare(const llvm::StringRef& pX) - { return (0 == key().compare(pX)); } + bool compare(const llvm::StringRef& pX) { return key().equals(pX); } - bool compare(const llvm::StringRef& pX) const - { return (0 == key().compare(pX)); } + bool compare(const llvm::StringRef& pX) const { return key().equals(pX); } -private: + private: StringEntry(); - StringEntry(const key_type& pKey); + explicit StringEntry(const key_type& pKey); StringEntry(const StringEntry& pCopy); ~StringEntry(); -private: + private: DataType m_Value; uint16_t m_KeyLen; char m_Key[]; @@ -71,53 +62,42 @@ friend class StringEntryFactory<DataType>; }; - -template<> -class StringEntry<llvm::StringRef> -{ -public: +template <> +class StringEntry<llvm::StringRef> { + public: typedef llvm::StringRef key_type; typedef llvm::StringRef value_type; -public: - key_type key() - { return key_type(m_Key, m_KeyLen); } + public: + key_type key() { return key_type(m_Key, m_KeyLen); } - const key_type key() const - { return key_type(m_Key, m_KeyLen); } + const key_type key() const { return key_type(m_Key, m_KeyLen); } - value_type& value() - { return m_Value; } + value_type& value() { return m_Value; } - const value_type& value() const - { return m_Value; } + const value_type& value() const { return m_Value; } - size_t getKeyLength() const - { return m_KeyLen; } + size_t getKeyLength() const { return m_KeyLen; } - size_t getValueLength() const - { return m_Value.size(); } + size_t getValueLength() const { return m_Value.size(); } - void setValue(const std::string& pVal) - { setValue(pVal.c_str()); } + void setValue(const std::string& pVal) { setValue(pVal.c_str()); } void setValue(const char* pVal); - void setValue(llvm::StringRef& pVal); + void setValue(llvm::StringRef pVal); - bool compare(const llvm::StringRef& pX) - { return (0 == key().compare(pX)); } + bool compare(const llvm::StringRef pX) { return key().equals(pX); } - bool compare(const llvm::StringRef& pX) const - { return (0 == key().compare(pX)); } + bool compare(const llvm::StringRef pX) const { return key().equals(pX); } -private: + private: StringEntry(); - StringEntry(const key_type& pKey); + explicit StringEntry(const key_type& pKey); StringEntry(const StringEntry& pCopy); ~StringEntry(); -private: + private: llvm::StringRef m_Value; uint16_t m_KeyLen; char m_Key[]; @@ -125,15 +105,14 @@ friend class StringEntryFactory<llvm::StringRef>; }; -template<typename DataType> -class StringEntryFactory -{ -public: - typedef StringEntry<DataType> entry_type; - typedef typename StringEntry<DataType>::key_type key_type; +template <typename DataType> +class StringEntryFactory { + public: + typedef StringEntry<DataType> entry_type; + typedef typename StringEntry<DataType>::key_type key_type; typedef typename StringEntry<DataType>::value_type value_type; -public: + public: StringEntryFactory(); ~StringEntryFactory(); @@ -143,7 +122,6 @@ #include "StringEntry.tcc" -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_ADT_STRINGENTRY_H_
diff --git a/include/mcld/ADT/StringEntry.tcc b/include/mcld/ADT/StringEntry.tcc index fa86f24..a9ed6b7 100644 --- a/include/mcld/ADT/StringEntry.tcc +++ b/include/mcld/ADT/StringEntry.tcc
@@ -1,4 +1,4 @@ -//===- StringEntry.tcc -----------------------------------------------------===// +//===- StringEntry.tcc ----------------------------------------------------===// // // The MCLinker Project // @@ -9,47 +9,43 @@ //===----------------------------------------------------------------------===// // StringEntry -template<typename DataType> +template <typename DataType> StringEntry<DataType>::StringEntry() - : m_KeyLen(0) { + : m_KeyLen(0) { } -template<typename DataType> +template <typename DataType> StringEntry<DataType>::StringEntry(const StringEntry::key_type& pKey) - : m_KeyLen(pKey.size()) { + : m_KeyLen(pKey.size()) { } -template<typename DataType> +template <typename DataType> StringEntry<DataType>::StringEntry(const StringEntry<DataType>& pCopy) - : m_KeyLen(pCopy.m_KeyLen), m_Value(pCopy.m_Value) { + : m_KeyLen(pCopy.m_KeyLen), m_Value(pCopy.m_Value) { assert("Copy constructor of StringEntry should not be called!"); } -template<typename DataType> -StringEntry<DataType>::~StringEntry() -{ +template <typename DataType> +StringEntry<DataType>::~StringEntry() { } //===----------------------------------------------------------------------===// // StringEntryFactory -template<typename DataType> -StringEntryFactory<DataType>::StringEntryFactory() -{ +template <typename DataType> +StringEntryFactory<DataType>::StringEntryFactory() { } -template<typename DataType> -StringEntryFactory<DataType>::~StringEntryFactory() -{ +template <typename DataType> +StringEntryFactory<DataType>::~StringEntryFactory() { } -template<typename DataType> -StringEntry<DataType>* -StringEntryFactory<DataType>::produce(const typename StringEntryFactory<DataType>::key_type& pKey) -{ +template <typename DataType> +StringEntry<DataType>* StringEntryFactory<DataType>::produce( + const typename StringEntryFactory<DataType>::key_type& pKey) { StringEntry<DataType>* result = static_cast<StringEntry<DataType>*>( - malloc(sizeof(StringEntry<DataType>) + pKey.size() + 1)); + malloc(sizeof(StringEntry<DataType>) + pKey.size() + 1)); - if (NULL == result) + if (result == NULL) return NULL; size_t len = pKey.size(); @@ -60,12 +56,10 @@ return result; } -template<typename DataType> -void StringEntryFactory<DataType>::destroy(StringEntry<DataType>* pEntry) -{ - if (NULL != pEntry) { +template <typename DataType> +void StringEntryFactory<DataType>::destroy(StringEntry<DataType>* pEntry) { + if (pEntry != NULL) { pEntry->~StringEntry<DataType>(); free(pEntry); } } -
diff --git a/include/mcld/ADT/StringHash.h b/include/mcld/ADT/StringHash.h index ae9479b..f24bb6b 100644 --- a/include/mcld/ADT/StringHash.h +++ b/include/mcld/ADT/StringHash.h
@@ -6,40 +6,28 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_STRINGHASH_H -#define MCLD_ADT_STRINGHASH_H +#ifndef MCLD_ADT_STRINGHASH_H_ +#define MCLD_ADT_STRINGHASH_H_ + #include <llvm/ADT/StringRef.h> #include <llvm/Support/DataTypes.h> -#include <cctype> + #include <cassert> +#include <cctype> #include <functional> namespace mcld { namespace hash { -enum Type { - RS, - JS, - PJW, - ELF, - BKDR, - SDBM, - DJB, - DEK, - BP, - FNV, - AP, - ES -}; +enum Type { RS, JS, PJW, ELF, BKDR, SDBM, DJB, DEK, BP, FNV, AP, ES }; /** \class template<uint32_t TYPE> StringHash * \brief the template StringHash class, for specification */ -template<uint32_t TYPE> -struct StringHash : public std::unary_function<const llvm::StringRef&, uint32_t> -{ - uint32_t operator()(const llvm::StringRef& pKey) const - { +template <uint32_t TYPE> +struct StringHash + : public std::unary_function<const llvm::StringRef, uint32_t> { + uint32_t operator()(const llvm::StringRef pKey) const { assert(false && "Undefined StringHash function.\n"); return 0; } @@ -48,16 +36,15 @@ /** \class StringHash<RSHash> * \brief RS StringHash funciton */ -template<> -struct StringHash<RS> : public std::unary_function<const llvm::StringRef&, uint32_t> -{ - uint32_t operator()(const llvm::StringRef& pKey) const - { +template <> +struct StringHash<RS> + : public std::unary_function<const llvm::StringRef, uint32_t> { + uint32_t operator()(const llvm::StringRef pKey) const { const unsigned int b = 378551; uint32_t a = 63689; uint32_t hash_val = 0; - for(unsigned int i = 0; i < pKey.size(); ++i) { + for (unsigned int i = 0; i < pKey.size(); ++i) { hash_val = hash_val * a + pKey[i]; a = a * b; } @@ -68,15 +55,14 @@ /** \class StringHash<JSHash> * \brief JS hash funciton */ -template<> -struct StringHash<JS> : public std::unary_function<const llvm::StringRef&, uint32_t> -{ - uint32_t operator()(const llvm::StringRef& pKey) const - { +template <> +struct StringHash<JS> + : public std::unary_function<const llvm::StringRef, uint32_t> { + uint32_t operator()(const llvm::StringRef pKey) const { uint32_t hash_val = 1315423911; - for(unsigned int i = 0; i < pKey.size(); ++i) { - hash_val ^= ((hash_val << 5) + pKey[i] + (hash_val >> 2)); + for (unsigned int i = 0; i < pKey.size(); ++i) { + hash_val ^= ((hash_val << 5) + pKey[i] + (hash_val >> 2)); } return hash_val; } @@ -85,23 +71,25 @@ /** \class StringHash<PJW> * \brief P.J. Weinberger hash function */ -template<> -struct StringHash<PJW> : public std::unary_function<const llvm::StringRef&, uint32_t> -{ - uint32_t operator()(const llvm::StringRef& pKey) const - { - const unsigned int BitsInUnsignedInt = (unsigned int)(sizeof(unsigned int) * 8); - const unsigned int ThreeQuarters = (unsigned int)((BitsInUnsignedInt * 3) / 4); - const unsigned int OneEighth = (unsigned int)(BitsInUnsignedInt / 8); - const unsigned int HighBits = (unsigned int)(0xFFFFFFFF) << (BitsInUnsignedInt - OneEighth); +template <> +struct StringHash<PJW> + : public std::unary_function<const llvm::StringRef, uint32_t> { + uint32_t operator()(const llvm::StringRef pKey) const { + const unsigned int BitsInUnsignedInt = + (unsigned int)(sizeof(unsigned int) * 8); + const unsigned int ThreeQuarters = + (unsigned int)((BitsInUnsignedInt * 3) / 4); + const unsigned int OneEighth = (unsigned int)(BitsInUnsignedInt / 8); + const unsigned int HighBits = (unsigned int)(0xFFFFFFFF) + << (BitsInUnsignedInt - OneEighth); uint32_t hash_val = 0; uint32_t test = 0; - for(unsigned int i = 0; i < pKey.size(); ++i) { + for (unsigned int i = 0; i < pKey.size(); ++i) { hash_val = (hash_val << OneEighth) + pKey[i]; - if((test = hash_val & HighBits) != 0) { - hash_val = (( hash_val ^ (test >> ThreeQuarters)) & (~HighBits)); + if ((test = hash_val & HighBits) != 0) { + hash_val = ((hash_val ^ (test >> ThreeQuarters)) & (~HighBits)); } } return hash_val; @@ -111,17 +99,16 @@ /** \class StringHash<ELF> * \brief ELF hash function. */ -template<> -struct StringHash<ELF> : public std::unary_function<const llvm::StringRef&, uint32_t> -{ - uint32_t operator()(const llvm::StringRef& pKey) const - { +template <> +struct StringHash<ELF> + : public std::unary_function<const llvm::StringRef, uint32_t> { + uint32_t operator()(const llvm::StringRef pKey) const { uint32_t hash_val = 0; uint32_t x = 0; for (unsigned int i = 0; i < pKey.size(); ++i) { hash_val = (hash_val << 4) + pKey[i]; - if((x = hash_val & 0xF0000000L) != 0) + if ((x = hash_val & 0xF0000000L) != 0) hash_val ^= (x >> 24); hash_val &= ~x; } @@ -132,33 +119,30 @@ /** \class StringHash<BKDR> * \brief BKDR hash function */ -template<> -struct StringHash<BKDR> : public std::unary_function<const llvm::StringRef&, uint32_t> -{ - uint32_t operator()(const llvm::StringRef& pKey) const - { +template <> +struct StringHash<BKDR> + : public std::unary_function<const llvm::StringRef, uint32_t> { + uint32_t operator()(const llvm::StringRef pKey) const { const uint32_t seed = 131; uint32_t hash_val = 0; - for(uint32_t i = 0; i < pKey.size(); ++i) + for (uint32_t i = 0; i < pKey.size(); ++i) hash_val = (hash_val * seed) + pKey[i]; return hash_val; } }; - /** \class StringHash<SDBM> * \brief SDBM hash function * 0.049s in 100000 test */ -template<> -struct StringHash<SDBM> : public std::unary_function<const llvm::StringRef&, uint32_t> -{ - uint32_t operator()(const llvm::StringRef& pKey) const - { +template <> +struct StringHash<SDBM> + : public std::unary_function<const llvm::StringRef, uint32_t> { + uint32_t operator()(const llvm::StringRef pKey) const { uint32_t hash_val = 0; - for(uint32_t i = 0; i < pKey.size(); ++i) + for (uint32_t i = 0; i < pKey.size(); ++i) hash_val = pKey[i] + (hash_val << 6) + (hash_val << 16) - hash_val; return hash_val; } @@ -168,14 +152,13 @@ * \brief DJB hash function * 0.057s in 100000 test */ -template<> -struct StringHash<DJB> : public std::unary_function<const llvm::StringRef&, uint32_t> -{ - uint32_t operator()(const llvm::StringRef& pKey) const - { +template <> +struct StringHash<DJB> + : public std::unary_function<const llvm::StringRef, uint32_t> { + uint32_t operator()(const llvm::StringRef pKey) const { uint32_t hash_val = 5381; - for(uint32_t i = 0; i < pKey.size(); ++i) + for (uint32_t i = 0; i < pKey.size(); ++i) hash_val = ((hash_val << 5) + hash_val) + pKey[i]; return hash_val; @@ -186,14 +169,13 @@ * \brief DEK hash function * 0.60s */ -template<> -struct StringHash<DEK> : public std::unary_function<const llvm::StringRef&, uint32_t> -{ - uint32_t operator()(const llvm::StringRef& pKey) const - { +template <> +struct StringHash<DEK> + : public std::unary_function<const llvm::StringRef, uint32_t> { + uint32_t operator()(const llvm::StringRef pKey) const { uint32_t hash_val = pKey.size(); - for(uint32_t i = 0; i < pKey.size(); ++i) + for (uint32_t i = 0; i < pKey.size(); ++i) hash_val = ((hash_val << 5) ^ (hash_val >> 27)) ^ pKey[i]; return hash_val; @@ -204,13 +186,12 @@ * \brief BP hash function * 0.057s */ -template<> -struct StringHash<BP> : public std::unary_function<const llvm::StringRef&, uint32_t> -{ - uint32_t operator()(const llvm::StringRef& pKey) const - { +template <> +struct StringHash<BP> + : public std::unary_function<const llvm::StringRef, uint32_t> { + uint32_t operator()(const llvm::StringRef pKey) const { uint32_t hash_val = 0; - for(uint32_t i = 0; i < pKey.size(); ++i) + for (uint32_t i = 0; i < pKey.size(); ++i) hash_val = hash_val << 7 ^ pKey[i]; return hash_val; @@ -221,14 +202,13 @@ * \brief FNV hash function * 0.058s */ -template<> -struct StringHash<FNV> : public std::unary_function<const llvm::StringRef&, uint32_t> -{ - uint32_t operator()(const llvm::StringRef& pKey) const - { +template <> +struct StringHash<FNV> + : public std::unary_function<const llvm::StringRef, uint32_t> { + uint32_t operator()(const llvm::StringRef pKey) const { const uint32_t fnv_prime = 0x811C9DC5; uint32_t hash_val = 0; - for(uint32_t i = 0; i < pKey.size(); ++i) { + for (uint32_t i = 0; i < pKey.size(); ++i) { hash_val *= fnv_prime; hash_val ^= pKey[i]; } @@ -241,17 +221,16 @@ * \brief AP hash function * 0.060s */ -template<> -struct StringHash<AP> : public std::unary_function<const llvm::StringRef&, uint32_t> -{ - uint32_t operator()(const llvm::StringRef& pKey) const - { +template <> +struct StringHash<AP> + : public std::unary_function<const llvm::StringRef, uint32_t> { + uint32_t operator()(const llvm::StringRef pKey) const { unsigned int hash_val = 0xAAAAAAAA; - for(uint32_t i = 0; i < pKey.size(); ++i) { - hash_val ^= ((i & 1) == 0)? - ((hash_val << 7) ^ pKey[i] * (hash_val >> 3)): - (~((hash_val << 11) + (pKey[i] ^ (hash_val >> 5)))); + for (uint32_t i = 0; i < pKey.size(); ++i) { + hash_val ^= ((i & 1) == 0) + ? ((hash_val << 7) ^ pKey[i] * (hash_val >> 3)) + : (~((hash_val << 11) + (pKey[i] ^ (hash_val >> 5)))); } return hash_val; @@ -272,11 +251,10 @@ * bit 25~0 - Bit 25 is set only if the string contains a 'a' or 'A', and * Bit 24 is set only if ... 'b' or 'B', ... */ -template<> -struct StringHash<ES> : public std::unary_function<const llvm::StringRef&, uint32_t> -{ - uint32_t operator()(const llvm::StringRef& pString) const - { +template <> +struct StringHash<ES> + : public std::unary_function<const llvm::StringRef, uint32_t> { + uint32_t operator()(const llvm::StringRef pString) const { uint32_t result = 0x0; unsigned int dot = 0; std::string::size_type idx; @@ -312,21 +290,19 @@ return result; } - /** \func may_include * \brief is it possible that pRule is a sub-string of pInString */ - static bool may_include(uint32_t pRule, uint32_t pInString) - { + static bool may_include(uint32_t pRule, uint32_t pInString) { uint32_t in_c = pInString << 4; - uint32_t r_c = pRule << 4; + uint32_t r_c = pRule << 4; uint32_t res = (in_c ^ r_c) & r_c; if (0 != res) return false; uint32_t in_dot = pInString >> 28; - uint32_t r_dot = pRule >> 28; + uint32_t r_dot = pRule >> 28; if (r_dot > in_dot) return false; @@ -337,29 +313,32 @@ /** \class template<uint32_t TYPE> StringCompare * \brief the template StringCompare class, for specification */ -template<typename STRING_TYPE> -struct StringCompare : public std::binary_function<const STRING_TYPE&, const STRING_TYPE&, bool> -{ - bool operator()(const STRING_TYPE& X, const STRING_TYPE& Y) const - { return X == Y; } +template <typename STRING_TYPE> +struct StringCompare : public std::binary_function<const STRING_TYPE&, + const STRING_TYPE&, + bool> { + bool operator()(const STRING_TYPE& X, const STRING_TYPE& Y) const { + return X == Y; + } }; -template<> -struct StringCompare<const char*> : public std::binary_function<const char*, const char*, bool> -{ - bool operator()(const char* X, const char* Y) const - { return (0 == std::strcmp(X, Y)); } +template <> +struct StringCompare<const char*> + : public std::binary_function<const char*, const char*, bool> { + bool operator()(const char* X, const char* Y) const { + return (std::strcmp(X, Y) == 0); + } }; -template<> -struct StringCompare<char*> : public std::binary_function<const char*, const char*, bool> -{ - bool operator()(const char* X, const char* Y) const - { return (0 == std::strcmp(X, Y)); } +template <> +struct StringCompare<char*> + : public std::binary_function<const char*, const char*, bool> { + bool operator()(const char* X, const char* Y) const { + return (std::strcmp(X, Y) == 0); + } }; -} // namespace of hash -} // namespace of mcld +} // namespace hash +} // namespace mcld -#endif - +#endif // MCLD_ADT_STRINGHASH_H_
diff --git a/include/mcld/ADT/TreeAllocator.h b/include/mcld/ADT/TreeAllocator.h index d7f47cc..b55a926 100644 --- a/include/mcld/ADT/TreeAllocator.h +++ b/include/mcld/ADT/TreeAllocator.h
@@ -6,10 +6,13 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_TREEALLOCATOR_H -#define MCLD_ADT_TREEALLOCATOR_H +#ifndef MCLD_ADT_TREEALLOCATOR_H_ +#define MCLD_ADT_TREEALLOCATOR_H_ + +#include "mcld/ADT/TreeBase.h" +#include "mcld/Support/GCFactory.h" + #include <set> -#include <mcld/Support/GCFactory.h> namespace mcld { @@ -25,18 +28,17 @@ * * @see LinearAllocator */ -template<typename DataType> -class NodeFactory : public GCFactory<Node<DataType>, 64> -{ -private: +template <typename DataType> +class NodeFactory : public GCFactory<Node<DataType>, 64> { + private: typedef GCFactory<Node<DataType>, 64> Alloc; -public: - typedef Node<DataType> NodeType; - typedef typename Alloc::iterator iterator; + public: + typedef Node<DataType> NodeType; + typedef typename Alloc::iterator iterator; typedef typename Alloc::const_iterator const_iterator; -public: + public: /// produce - produce a node, add it under control NodeType* produce() { NodeType* result = Alloc::allocate(); @@ -65,10 +67,9 @@ pClient.renounce(); } -private: + private: /// renounce - give up the control of all chunks - void renounce() - { Alloc::reset(); } + void renounce() { Alloc::reset(); } /// replace - be the agent of client. void replace(NodeFactory& pClient) { @@ -87,7 +88,6 @@ } }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_ADT_TREEALLOCATOR_H_
diff --git a/include/mcld/ADT/TreeBase.h b/include/mcld/ADT/TreeBase.h index bca375f..5d0cd16 100644 --- a/include/mcld/ADT/TreeBase.h +++ b/include/mcld/ADT/TreeBase.h
@@ -6,121 +6,109 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_TREEBASE_H -#define MCLD_ADT_TREEBASE_H -#include <mcld/ADT/TypeTraits.h> +#ifndef MCLD_ADT_TREEBASE_H_ +#define MCLD_ADT_TREEBASE_H_ -#include <cstddef> +#include "mcld/ADT/TypeTraits.h" + #include <cassert> +#include <cstddef> #include <iterator> namespace mcld { -class NodeBase -{ -public: - NodeBase *left; - NodeBase *right; +class NodeBase { + public: + NodeBase* left; + NodeBase* right; -public: - NodeBase() - : left(0), right(0) - { } + public: + NodeBase() : left(NULL), right(NULL) {} }; -class TreeIteratorBase -{ -public: - enum Direct { - Leftward, - Rightward - }; +class TreeIteratorBase { + public: + enum Direct { Leftward, Rightward }; - typedef size_t size_type; - typedef ptrdiff_t difference_type; + typedef size_t size_type; + typedef ptrdiff_t difference_type; typedef std::bidirectional_iterator_tag iterator_category; -public: + public: NodeBase* m_pNode; -public: - TreeIteratorBase() - : m_pNode(0) - { } + public: + TreeIteratorBase() : m_pNode(NULL) {} - TreeIteratorBase(NodeBase *X) - : m_pNode(X) - { } + explicit TreeIteratorBase(NodeBase* X) : m_pNode(X) {} virtual ~TreeIteratorBase(){}; - template<size_t DIRECT> - void move() { assert(0 && "not allowed"); } + template <size_t DIRECT> + void move() { + assert(0 && "not allowed"); + } - template<size_t DIRECT> - void hook(NodeBase* pNode) { assert(0 && "not allowed"); } + template <size_t DIRECT> + void hook(NodeBase* pNode) { + assert(0 && "not allowed"); + } - bool isRoot() const - { return (m_pNode->right == m_pNode); } + bool isRoot() const { return (m_pNode->right == m_pNode); } - bool hasRightChild() const - { return ((m_pNode->right) != (m_pNode->right->right)); } + bool hasRightChild() const { + return ((m_pNode->right) != (m_pNode->right->right)); + } - bool hasLeftChild() const - { return ((m_pNode->left) != (m_pNode->left->right)); } + bool hasLeftChild() const { + return ((m_pNode->left) != (m_pNode->left->right)); + } - bool operator==(const TreeIteratorBase& y) const - { return this->m_pNode == y.m_pNode; } + bool operator==(const TreeIteratorBase& y) const { + return this->m_pNode == y.m_pNode; + } - bool operator!=(const TreeIteratorBase& y) const - { return this->m_pNode != y.m_pNode; } + bool operator!=(const TreeIteratorBase& y) const { + return this->m_pNode != y.m_pNode; + } }; -template<> inline -void TreeIteratorBase::move<TreeIteratorBase::Leftward>() -{ +template <> +inline void TreeIteratorBase::move<TreeIteratorBase::Leftward>() { this->m_pNode = this->m_pNode->left; } -template<> inline -void TreeIteratorBase::move<TreeIteratorBase::Rightward>() -{ +template <> +inline void TreeIteratorBase::move<TreeIteratorBase::Rightward>() { this->m_pNode = this->m_pNode->right; } -template<> inline -void TreeIteratorBase::hook<TreeIteratorBase::Leftward>(NodeBase* pOther) -{ +template <> +inline void TreeIteratorBase::hook<TreeIteratorBase::Leftward>( + NodeBase* pOther) { this->m_pNode->left = pOther; } -template<> inline -void TreeIteratorBase::hook<TreeIteratorBase::Rightward>(NodeBase* pOther) -{ +template <> +inline void TreeIteratorBase::hook<TreeIteratorBase::Rightward>( + NodeBase* pOther) { this->m_pNode->right = pOther; } -template<typename DataType> -class Node : public NodeBase -{ -public: - typedef DataType value_type; +template <typename DataType> +class Node : public NodeBase { + public: + typedef DataType value_type; -public: + public: value_type* data; -public: - Node() - : NodeBase(), data(0) - { } + public: + Node() : NodeBase(), data(NULL) {} - Node(const value_type& pValue) - : NodeBase(), data(&pValue) - { } - + explicit Node(const value_type& pValue) : NodeBase(), data(&pValue) {} }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_ADT_TREEBASE_H_
diff --git a/include/mcld/ADT/TypeTraits.h b/include/mcld/ADT/TypeTraits.h index 11e9b69..1c13d76 100644 --- a/include/mcld/ADT/TypeTraits.h +++ b/include/mcld/ADT/TypeTraits.h
@@ -6,63 +6,58 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_TYPETRAITS_H -#define MCLD_ADT_TYPETRAITS_H +#ifndef MCLD_ADT_TYPETRAITS_H_ +#define MCLD_ADT_TYPETRAITS_H_ #include <cstdlib> namespace mcld { -template<typename DataType> +template <typename DataType> struct NonConstTraits; -template<typename DataType> -struct ConstTraits -{ - typedef DataType value_type; - typedef const DataType* pointer; - typedef const DataType& reference; - typedef size_t size_type; - typedef ConstTraits<DataType> const_traits; +template <typename DataType> +struct ConstTraits { + typedef DataType value_type; + typedef const DataType* pointer; + typedef const DataType& reference; + typedef size_t size_type; + typedef ConstTraits<DataType> const_traits; typedef NonConstTraits<DataType> nonconst_traits; }; -template<typename DataType> -struct NonConstTraits -{ - typedef DataType value_type; - typedef DataType* pointer; - typedef DataType& reference; - typedef size_t size_type; - typedef ConstTraits<DataType> const_traits; +template <typename DataType> +struct NonConstTraits { + typedef DataType value_type; + typedef DataType* pointer; + typedef DataType& reference; + typedef size_t size_type; + typedef ConstTraits<DataType> const_traits; typedef NonConstTraits<DataType> nonconst_traits; }; -template<typename DataType> -struct ConstIteratorTraits -{ - typedef DataType value_type; - typedef const DataType* pointer; - typedef const DataType& reference; - typedef size_t size_type; - typedef ConstTraits<DataType> const_traits; - typedef NonConstTraits<DataType> nonconst_traits; +template <typename DataType> +struct ConstIteratorTraits { + typedef DataType value_type; + typedef const DataType* pointer; + typedef const DataType& reference; + typedef size_t size_type; + typedef ConstTraits<DataType> const_traits; + typedef NonConstTraits<DataType> nonconst_traits; typedef typename DataType::const_iterator iterator; }; -template<typename DataType> -struct NonConstIteratorTraits -{ - typedef DataType value_type; - typedef DataType* pointer; - typedef DataType& reference; - typedef size_t size_type; - typedef ConstTraits<DataType> const_traits; - typedef NonConstTraits<DataType> nonconst_traits; +template <typename DataType> +struct NonConstIteratorTraits { + typedef DataType value_type; + typedef DataType* pointer; + typedef DataType& reference; + typedef size_t size_type; + typedef ConstTraits<DataType> const_traits; + typedef NonConstTraits<DataType> nonconst_traits; typedef typename DataType::iterator iterator; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_ADT_TYPETRAITS_H_
diff --git a/include/mcld/ADT/Uncopyable.h b/include/mcld/ADT/Uncopyable.h deleted file mode 100644 index 1ac89a9..0000000 --- a/include/mcld/ADT/Uncopyable.h +++ /dev/null
@@ -1,33 +0,0 @@ -//===- Uncopyable.h -------------------------------------------------------===// -// -// The MCLinker Project -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef MCLD_ADT_UNCOPYABLE_H -#define MCLD_ADT_UNCOPYABLE_H - -namespace mcld -{ - -/** \class Uncopyable - * \brief Uncopyable provides the base class to forbit copy operations. - * - */ -class Uncopyable -{ -protected: - Uncopyable() { } - ~Uncopyable() { } - -private: - Uncopyable(const Uncopyable&); /// NOT TO IMPLEMENT - Uncopyable& operator=(const Uncopyable&); /// NOT TO IMPLEMENT -}; - -} // namespace of mcld - -#endif -
diff --git a/include/mcld/AttributeOption.h b/include/mcld/AttributeOption.h index a42f70b..40b2724 100644 --- a/include/mcld/AttributeOption.h +++ b/include/mcld/AttributeOption.h
@@ -6,30 +6,28 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ATTRIBUTEOPTION_H -#define MCLD_ATTRIBUTEOPTION_H -#include <mcld/MC/Attribute.h> +#ifndef MCLD_ATTRIBUTEOPTION_H_ +#define MCLD_ATTRIBUTEOPTION_H_ +#include "mcld/MC/Attribute.h" namespace mcld { -class AttributeOption -{ -public: +class AttributeOption { + public: AttributeOption(); ~AttributeOption(); const Attribute& predefined() const { return m_Predefined; } - Attribute& predefined() { return m_Predefined; } + Attribute& predefined() { return m_Predefined; } const AttrConstraint& constraint() const { return m_Constraint; } - AttrConstraint& constraint() { return m_Constraint; } + AttrConstraint& constraint() { return m_Constraint; } -private: + private: Attribute m_Predefined; AttrConstraint m_Constraint; }; -} // namespace mcld +} // namespace mcld -#endif - +#endif // MCLD_ATTRIBUTEOPTION_H_
diff --git a/include/mcld/BitcodeOption.h b/include/mcld/BitcodeOption.h deleted file mode 100644 index 7236d6a..0000000 --- a/include/mcld/BitcodeOption.h +++ /dev/null
@@ -1,46 +0,0 @@ -//===- BitcodeOption.h ----------------------------------------------------===// -// -// The MCLinker Project -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef MCLD_BITCODEOPTION_H -#define MCLD_BITCODEOPTION_H - -#include <mcld/Support/Path.h> - -namespace mcld { - -/** \class BitcodeOption - * \brief BitcodeOption represents the options of bitcode on the command line. - */ -class BitcodeOption -{ -public: - BitcodeOption(); - - ~BitcodeOption(); - - void setPosition(unsigned int pPosition) { m_Position = pPosition; } - - unsigned int getPosition() const { return m_Position; } - - void setPath(const sys::fs::Path& pPath) { m_Path = pPath; } - - const sys::fs::Path& getPath() const { return m_Path; } - - bool hasDefined() const; - -private: - int m_Position; - - sys::fs::Path m_Path; - -}; - -} // namespace of mcld - -#endif -
diff --git a/include/mcld/CodeGen/MCLinker.h b/include/mcld/CodeGen/MCLinker.h deleted file mode 100644 index 048ebb2..0000000 --- a/include/mcld/CodeGen/MCLinker.h +++ /dev/null
@@ -1,82 +0,0 @@ -//===- MCLinker.h ---------------------------------------------------------===// -// -// The MCLinker Project -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// MCLinker is a base class inherited by target specific linker. -// This class primarily handles common functionality used by all linkers. -// -//===----------------------------------------------------------------------===// -#ifndef MCLD_CODEGEN_MCLINKER_H -#define MCLD_CODEGEN_MCLINKER_H -#include <llvm/CodeGen/MachineFunctionPass.h> - -namespace llvm { - -class Module; -class MachineFunction; - -} // namespace of llvm - -namespace mcld { - -class Module; -class IRBuilder; -class LinkerConfig; -class Linker; -class FileHandle; - -/** \class MCLinker -* \brief MCLinker provides a linking pass for standard compilation flow -* -* MCLinker is responded for -* - provide an interface for target-specific linker -* - set up environment for ObjectLinker -* - perform linking -* -* @see MachineFunctionPass ObjectLinker -*/ -class MCLinker : public llvm::MachineFunctionPass -{ -protected: - // Constructor. Although MCLinker has only two arguments, - // TargetMCLinker should handle - // - enabled attributes - // - the default attribute - // - the default link script - // - the standard symbols - MCLinker(LinkerConfig& pConfig, - mcld::Module& pModule, - FileHandle& pFileHandle); - -public: - virtual ~MCLinker(); - - virtual bool doInitialization(llvm::Module &pM); - - virtual bool doFinalization(llvm::Module &pM); - - virtual bool runOnMachineFunction(llvm::MachineFunction& pMFn); - -protected: - void initializeInputTree(IRBuilder& pBuilder); - -protected: - LinkerConfig& m_Config; - mcld::Module& m_Module; - FileHandle& m_FileHandle; - IRBuilder* m_pBuilder; - Linker* m_pLinker; - -private: - static char m_ID; -}; - -} // namespace of MC Linker - -#endif -
diff --git a/include/mcld/CodeGen/TargetMachine.h b/include/mcld/CodeGen/TargetMachine.h deleted file mode 100644 index 6454d87..0000000 --- a/include/mcld/CodeGen/TargetMachine.h +++ /dev/null
@@ -1,111 +0,0 @@ -//===- TargetMachine.h ----------------------------------------------------===// -// -// The MCLinker Project -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef MCLD_CODEGEN_TARGETMACHINE_H -#define MCLD_CODEGEN_TARGETMACHINE_H -#include <llvm/Support/CodeGen.h> -#include <string> - -namespace llvm { - -class Target; -class TargetData; -class TargetMachine; -class MCContext; -class raw_ostream; -class formatted_raw_ostream; -namespace legacy { -class PassManagerBase; -} // namepsace legacy -} // namespace llvm - -namespace mcld { - -class Module; -class Target; -class FileHandle; -class LinkerConfig; -class ToolOutputFile; - -enum CodeGenFileType { - CGFT_ASMFile, - CGFT_OBJFile, - CGFT_DSOFile, - CGFT_EXEFile, - CGFT_PARTIAL, - CGFT_BINARY, - CGFT_NULLFile -}; - - -/** \class mcld::MCLDTargetMachine - * \brief mcld::MCLDTargetMachine is a object adapter of LLVMTargetMachine. - */ -class MCLDTargetMachine -{ -public: - /// Adapter of llvm::TargetMachine - /// - MCLDTargetMachine(llvm::TargetMachine& pTM, - const llvm::Target& pLLMVTarget, - const mcld::Target& pMCLDTarget, - const std::string& pTriple); - - virtual ~MCLDTargetMachine(); - - /// getTarget - adapt llvm::TargetMachine::getTarget - const mcld::Target& getTarget() const; - - /// getTM - return adapted the llvm::TargetMachine. - const llvm::TargetMachine& getTM() const { return m_TM; } - llvm::TargetMachine& getTM() { return m_TM; } - - /// appPassesToEmitFile - The target function which we has to modify as - /// upstreaming. - bool addPassesToEmitFile(llvm::legacy::PassManagerBase &, - mcld::ToolOutputFile& pOutput, - mcld::CodeGenFileType, - llvm::CodeGenOpt::Level, - mcld::Module& pModule, - mcld::LinkerConfig& pConfig, - bool DisableVerify = true); - -private: - /// addCommonCodeGenPasses - Add standard LLVM codegen passes used for - /// both emitting to assembly files or machine code output. - bool addCommonCodeGenPasses(llvm::legacy::PassManagerBase &, - mcld::CodeGenFileType, - llvm::CodeGenOpt::Level, - bool DisableVerify, - llvm::MCContext *&OutCtx); - - bool addCompilerPasses(llvm::legacy::PassManagerBase &pPM, - llvm::formatted_raw_ostream &pOutput, - llvm::MCContext *&OutCtx); - - bool addAssemblerPasses(llvm::legacy::PassManagerBase &pPM, - llvm::raw_ostream &pOutput, - llvm::MCContext *&OutCtx); - - bool addLinkerPasses(llvm::legacy::PassManagerBase &pPM, - mcld::LinkerConfig& pConfig, - mcld::Module& pModule, - mcld::FileHandle& pFileHandle, - llvm::MCContext *&OutCtx); - -private: - llvm::TargetMachine &m_TM; - const llvm::Target *m_pLLVMTarget; - const mcld::Target *m_pMCLDTarget; - const std::string& m_Triple; -}; - -} // namespace of mcld - -#endif -
diff --git a/include/mcld/Config/Config.h.cmake b/include/mcld/Config/Config.h.cmake new file mode 100644 index 0000000..482debd --- /dev/null +++ b/include/mcld/Config/Config.h.cmake
@@ -0,0 +1,621 @@ +/* include/llvm/Config/config.h.cmake corresponding to config.h.in. */ +//===- Config.h.in --------------------------------------------------------===// +// +// The MCLinker Project +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#ifndef MCLD_CONFIG_CONFIG_H +#define MCLD_CONFIG_CONFIG_H + +#define MCLD_REGION_CHUNK_SIZE 32 +#define MCLD_NUM_OF_INPUTS 32 +#define MCLD_SECTIONS_PER_INPUT 16 +#define MCLD_SYMBOLS_PER_INPUT 128 +#define MCLD_RELOCATIONS_PER_INPUT 1024 + +#define MCLD_SEGMENTS_PER_OUTPUT 8 + +#cmakedefine MCLD_VERSION "${MCLD_VERSION}" + +/* Target triple LLVM will generate code for by default */ +#cmakedefine MCLD_DEFAULT_TARGET_TRIPLE "${MCLD_DEFAULT_TARGET_TRIPLE}" + +#cmakedefine MCLD_ON_UNIX "${MCLD_ON_UNIX}" + +#cmakedefine MCLD_ON_WIN32 "${MCLD_ON_WIN32}" + + +/* Define to 1 if you have the `arc4random' function. */ +#cmakedefine HAVE_ARC4RANDOM + +/* Define to 1 if you have the `argz_append' function. */ +#cmakedefine HAVE_ARGZ_APPEND ${HAVE_ARGZ_APPEND} + +/* Define to 1 if you have the `argz_create_sep' function. */ +#cmakedefine HAVE_ARGZ_CREATE_SEP ${HAVE_ARGZ_CREATE_SEP} + +/* Define to 1 if you have the <argz.h> header file. */ +#cmakedefine HAVE_ARGZ_H ${HAVE_ARGZ_H} + +/* Define to 1 if you have the `argz_insert' function. */ +#cmakedefine HAVE_ARGZ_INSERT ${HAVE_ARGZ_INSERT} + +/* Define to 1 if you have the `argz_next' function. */ +#cmakedefine HAVE_ARGZ_NEXT ${HAVE_ARGZ_NEXT} + +/* Define to 1 if you have the `argz_stringify' function. */ +#cmakedefine HAVE_ARGZ_STRINGIFY ${HAVE_ARGZ_STRINGIFY} + +/* Define to 1 if you have the <assert.h> header file. */ +#cmakedefine HAVE_ASSERT_H ${HAVE_ASSERT_H} + +/* Define to 1 if you have the `backtrace' function. */ +#cmakedefine HAVE_BACKTRACE ${HAVE_BACKTRACE} + +/* Define to 1 if you have the `bcopy' function. */ +#undef HAVE_BCOPY + +/* Define to 1 if you have the `ceilf' function. */ +#cmakedefine HAVE_CEILF ${HAVE_CEILF} + +/* Define if the neat program is available */ +#cmakedefine HAVE_CIRCO ${HAVE_CIRCO} + +/* Define to 1 if you have the `closedir' function. */ +#cmakedefine HAVE_CLOSEDIR ${HAVE_CLOSEDIR} + +/* Define to 1 if you have the <CrashReporterClient.h> header file. */ +#undef HAVE_CRASHREPORTERCLIENT_H + +/* can use __crashreporter_info__ */ +#undef HAVE_CRASHREPORTER_INFO + +/* Define to 1 if you have the <ctype.h> header file. */ +#cmakedefine HAVE_CTYPE_H ${HAVE_CTYPE_H} + +/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you + don't. */ +#cmakedefine01 HAVE_DECL_STRERROR_S + +/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'. + */ +#cmakedefine HAVE_DIRENT_H ${HAVE_DIRENT_H} + +/* Define if you have the GNU dld library. */ +#undef HAVE_DLD + +/* Define to 1 if you have the <dld.h> header file. */ +#cmakedefine HAVE_DLD_H ${HAVE_DLD_H} + +/* Define to 1 if you have the `dlerror' function. */ +#cmakedefine HAVE_DLERROR ${HAVE_DLERROR} + +/* Define to 1 if you have the <dlfcn.h> header file. */ +#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H} + +/* Define if dlopen() is available on this platform. */ +#cmakedefine HAVE_DLOPEN ${HAVE_DLOPEN} + +/* Define to 1 if you have the <dl.h> header file. */ +#cmakedefine HAVE_DL_H ${HAVE_DL_H} + +/* Define if the dot program is available */ +#cmakedefine HAVE_DOT ${HAVE_DOT} + +/* Define if the dotty program is available */ +#cmakedefine HAVE_DOTTY ${HAVE_DOTTY} + +/* Define if you have the _dyld_func_lookup function. */ +#undef HAVE_DYLD + +/* Define to 1 if you have the <errno.h> header file. */ +#cmakedefine HAVE_ERRNO_H ${HAVE_ERRNO_H} + +/* Define to 1 if the system has the type `error_t'. */ +#cmakedefine HAVE_ERROR_T ${HAVE_ERROR_T} + +/* Define to 1 if you have the <execinfo.h> header file. */ +#cmakedefine HAVE_EXECINFO_H ${HAVE_EXECINFO_H} + +/* Define to 1 if you have the <fcntl.h> header file. */ +#cmakedefine HAVE_FCNTL_H ${HAVE_FCNTL_H} + +/* Define if the neat program is available */ +#cmakedefine HAVE_FDP ${HAVE_FDP} + +/* Define to 1 if you have the <fenv.h> header file. */ +#cmakedefine HAVE_FENV_H ${HAVE_FENV_H} + +/* Define if libffi is available on this platform. */ +#cmakedefine HAVE_FFI_CALL ${HAVE_FFI_CALL} + +/* Define to 1 if you have the <ffi/ffi.h> header file. */ +#cmakedefine HAVE_FFI_FFI_H ${HAVE_FFI_FFI_H} + +/* Define to 1 if you have the <ffi.h> header file. */ +#cmakedefine HAVE_FFI_H ${HAVE_FFI_H} + +/* Set to 1 if the finite function is found in <ieeefp.h> */ +#cmakedefine HAVE_FINITE_IN_IEEEFP_H ${HAVE_FINITE_IN_IEEEFP_H} + +/* Define to 1 if you have the `floorf' function. */ +#cmakedefine HAVE_FLOORF ${HAVE_FLOORF} + +/* Define to 1 if you have the `log' function. */ +#cmakedefine HAVE_LOG ${HAVE_LOG} + +/* Define to 1 if you have the `log2' function. */ +#cmakedefine HAVE_LOG2 ${HAVE_LOG2} + +/* Define to 1 if you have the `log10' function. */ +#cmakedefine HAVE_LOG10 ${HAVE_LOG10} + +/* Define to 1 if you have the `exp' function. */ +#cmakedefine HAVE_EXP ${HAVE_LOG} + +/* Define to 1 if you have the `exp2' function. */ +#cmakedefine HAVE_EXP2 ${HAVE_LOG2} + +/* Define to 1 if you have the `exp10' function. */ +#cmakedefine HAVE_EXP10 ${HAVE_LOG10} + +/* Define to 1 if you have the `fmodf' function. */ +#cmakedefine HAVE_FMODF ${HAVE_FMODF} + +/* Define to 1 if you have the `getcwd' function. */ +#cmakedefine HAVE_GETCWD ${HAVE_GETCWD} + +/* Define to 1 if you have the `getpagesize' function. */ +#cmakedefine HAVE_GETPAGESIZE ${HAVE_GETPAGESIZE} + +/* Define to 1 if you have the `getrlimit' function. */ +#cmakedefine HAVE_GETRLIMIT ${HAVE_GETRLIMIT} + +/* Define to 1 if you have the `getrusage' function. */ +#cmakedefine HAVE_GETRUSAGE ${HAVE_GETRUSAGE} + +/* Define to 1 if you have the `gettimeofday' function. */ +#cmakedefine HAVE_GETTIMEOFDAY ${HAVE_GETTIMEOFDAY} + +/* Define if the Graphviz program is available */ +#cmakedefine HAVE_GRAPHVIZ ${HAVE_GRAPHVIZ} + +/* Define if the gv program is available */ +#cmakedefine HAVE_GV ${HAVE_GV} + +/* Define to 1 if you have the `index' function. */ +#cmakedefine HAVE_INDEX ${HAVE_INDEX} + +/* Define to 1 if the system has the type `int64_t'. */ +#cmakedefine HAVE_INT64_T ${HAVE_INT64_T} + +/* Define to 1 if you have the <inttypes.h> header file. */ +#cmakedefine HAVE_INTTYPES_H ${HAVE_INTTYPES_H} + +/* Define to 1 if you have the `isatty' function. */ +#cmakedefine HAVE_ISATTY 1 + +/* Set to 1 if the isinf function is found in <cmath> */ +#cmakedefine HAVE_ISINF_IN_CMATH ${HAVE_ISINF_IN_CMATH} + +/* Set to 1 if the isinf function is found in <math.h> */ +#cmakedefine HAVE_ISINF_IN_MATH_H ${HAVE_ISINF_IN_MATH_H} + +/* Set to 1 if the isnan function is found in <cmath> */ +#cmakedefine HAVE_ISNAN_IN_CMATH ${HAVE_ISNAN_IN_CMATH} + +/* Set to 1 if the isnan function is found in <math.h> */ +#cmakedefine HAVE_ISNAN_IN_MATH_H ${HAVE_ISNAN_IN_MATH_H} + +/* Define if you have the libdl library or equivalent. */ +#cmakedefine HAVE_LIBDL ${HAVE_LIBDL} + +/* Define to 1 if you have the `imagehlp' library (-limagehlp). */ +#cmakedefine HAVE_LIBIMAGEHLP ${HAVE_LIBIMAGEHLP} + +/* Define to 1 if you have the `m' library (-lm). */ +#undef HAVE_LIBM + +/* Define to 1 if you have the `psapi' library (-lpsapi). */ +#cmakedefine HAVE_LIBPSAPI ${HAVE_LIBPSAPI} + +/* Define to 1 if you have the `pthread' library (-lpthread). */ +#cmakedefine HAVE_LIBPTHREAD ${HAVE_LIBPTHREAD} + +/* Define to 1 if you have the `udis86' library (-ludis86). */ +#undef HAVE_LIBUDIS86 + +/* Define to 1 if you have the <limits.h> header file. */ +#cmakedefine HAVE_LIMITS_H ${HAVE_LIMITS_H} + +/* Define if you can use -Wl,-export-dynamic. */ +#define HAVE_LINK_EXPORT_DYNAMIC 1 + +/* Define to 1 if you have the <link.h> header file. */ +#cmakedefine HAVE_LINK_H ${HAVE_LINK_H} + +/* Define if you can use -Wl,-R. to pass -R. to the linker, in order to add + the current directory to the dynamic linker search path. */ +#undef HAVE_LINK_R + +/* Define to 1 if you have the `longjmp' function. */ +#cmakedefine HAVE_LONGJMP ${HAVE_LONGJMP} + +/* Define to 1 if you have the <mach/mach.h> header file. */ +#cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H} + +/* Define to 1 if you have the <mach-o/dyld.h> header file. */ +#cmakedefine HAVE_MACH_O_DYLD_H ${HAVE_MACH_O_DYLD_H} + +/* Define if mallinfo() is available on this platform. */ +#cmakedefine HAVE_MALLINFO ${HAVE_MALLINFO} + +/* Define to 1 if you have the <malloc.h> header file. */ +#cmakedefine HAVE_MALLOC_H ${HAVE_MALLOC_H} + +/* Define to 1 if you have the <malloc/malloc.h> header file. */ +#cmakedefine HAVE_MALLOC_MALLOC_H ${HAVE_MALLOC_MALLOC_H} + +/* Define to 1 if you have the `malloc_zone_statistics' function. */ +#cmakedefine HAVE_MALLOC_ZONE_STATISTICS ${HAVE_MALLOC_ZONE_STATISTICS} + +/* Define to 1 if you have the `memcpy' function. */ +#cmakedefine HAVE_MEMCPY ${HAVE_MEMCPY} + +/* Define to 1 if you have the `memmove' function. */ +#cmakedefine HAVE_MEMMOVE ${HAVE_MEMMOVE} + +/* Define to 1 if you have the <memory.h> header file. */ +#cmakedefine HAVE_MEMORY_H ${HAVE_MEMORY_H} + +/* Define to 1 if you have the `mkdtemp' function. */ +#cmakedefine HAVE_MKDTEMP ${HAVE_MKDTEMP} + +/* Define to 1 if you have the `mkstemp' function. */ +#cmakedefine HAVE_MKSTEMP ${HAVE_MKSTEMP} + +/* Define to 1 if you have the `mktemp' function. */ +#cmakedefine HAVE_MKTEMP ${HAVE_MKTEMP} + +/* Define to 1 if you have a working `mmap' system call. */ +#undef HAVE_MMAP + +/* Define if mmap() uses MAP_ANONYMOUS to map anonymous pages, or undefine if + it uses MAP_ANON */ +#undef HAVE_MMAP_ANONYMOUS + +/* Define if mmap() can map files into memory */ +#undef HAVE_MMAP_FILE + +/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */ +#cmakedefine HAVE_NDIR_H ${HAVE_NDIR_H} + +/* Define to 1 if you have the `nearbyintf' function. */ +#cmakedefine HAVE_NEARBYINTF ${HAVE_NEARBYINTF} + +/* Define if the neat program is available */ +#cmakedefine HAVE_NEATO ${HAVE_NEATO} + +/* Define to 1 if you have the `opendir' function. */ +#cmakedefine HAVE_OPENDIR ${HAVE_OPENDIR} + +/* Define to 1 if you have the `posix_spawn' function. */ +#cmakedefine HAVE_POSIX_SPAWN ${HAVE_POSIX_SPAWN} + +/* Define to 1 if you have the `powf' function. */ +#cmakedefine HAVE_POWF ${HAVE_POWF} + +/* Define to 1 if you have the `pread' function. */ +#cmakedefine HAVE_PREAD ${HAVE_PREAD} + +/* Define if libtool can extract symbol lists from object files. */ +#undef HAVE_PRELOADED_SYMBOLS + +/* Define to have the %a format string */ +#undef HAVE_PRINTF_A + +/* Have pthread_getspecific */ +#cmakedefine HAVE_PTHREAD_GETSPECIFIC ${HAVE_PTHREAD_GETSPECIFIC} + +/* Define to 1 if you have the <pthread.h> header file. */ +#cmakedefine HAVE_PTHREAD_H ${HAVE_PTHREAD_H} + +/* Have pthread_mutex_lock */ +#cmakedefine HAVE_PTHREAD_MUTEX_LOCK ${HAVE_PTHREAD_MUTEX_LOCK} + +/* Have pthread_rwlock_init */ +#cmakedefine HAVE_PTHREAD_RWLOCK_INIT ${HAVE_PTHREAD_RWLOCK_INIT} + +/* Define to 1 if srand48/lrand48/drand48 exist in <stdlib.h> */ +#cmakedefine HAVE_RAND48 ${HAVE_RAND48} + +/* Define to 1 if you have the `readdir' function. */ +#cmakedefine HAVE_READDIR ${HAVE_READDIR} + +/* Define to 1 if you have the `realpath' function. */ +#undef HAVE_REALPATH + +/* Define to 1 if you have the `rindex' function. */ +#cmakedefine HAVE_RINDEX ${HAVE_RINDEX} + +/* Define to 1 if you have the `rintf' function. */ +#undef HAVE_RINTF + +/* Define to 1 if you have the `round' function. */ +#cmakedefine HAVE_ROUND ${HAVE_ROUND} + +/* Define to 1 if you have the `roundf' function. */ +#undef HAVE_ROUNDF + +/* Define to 1 if you have the `sbrk' function. */ +#cmakedefine HAVE_SBRK ${HAVE_SBRK} + +/* Define to 1 if you have the `setenv' function. */ +#cmakedefine HAVE_SETENV ${HAVE_SETENV} + +/* Define to 1 if you have the `setjmp' function. */ +#cmakedefine HAVE_SETJMP ${HAVE_SETJMP} + +/* Define to 1 if you have the <setjmp.h> header file. */ +#cmakedefine HAVE_SETJMP_H ${HAVE_SETJMP_H} + +/* Define to 1 if you have the `setrlimit' function. */ +#cmakedefine HAVE_SETRLIMIT ${HAVE_SETRLIMIT} + +/* Define if you have the shl_load function. */ +#undef HAVE_SHL_LOAD + +/* Define to 1 if you have the `siglongjmp' function. */ +#cmakedefine HAVE_SIGLONGJMP ${HAVE_SIGLONGJMP} + +/* Define to 1 if you have the <signal.h> header file. */ +#cmakedefine HAVE_SIGNAL_H ${HAVE_SIGNAL_H} + +/* Define to 1 if you have the `sigsetjmp' function. */ +#cmakedefine HAVE_SIGSETJMP ${HAVE_SIGSETJMP} + +/* Define to 1 if you have the <stdint.h> header file. */ +#cmakedefine HAVE_STDINT_H ${HAVE_STDINT_H} + +/* Define to 1 if you have the <stdio.h> header file. */ +#cmakedefine HAVE_STDIO_H ${HAVE_STDIO_H} + +/* Define to 1 if you have the <stdlib.h> header file. */ +#cmakedefine HAVE_STDLIB_H ${HAVE_STDLIB_H} + +/* Set to 1 if the std::isinf function is found in <cmath> */ +#undef HAVE_STD_ISINF_IN_CMATH + +/* Set to 1 if the std::isnan function is found in <cmath> */ +#undef HAVE_STD_ISNAN_IN_CMATH + +/* Define to 1 if you have the `strchr' function. */ +#cmakedefine HAVE_STRCHR ${HAVE_STRCHR} + +/* Define to 1 if you have the `strcmp' function. */ +#cmakedefine HAVE_STRCMP ${HAVE_STRCMP} + +/* Define to 1 if you have the `strdup' function. */ +#cmakedefine HAVE_STRDUP ${HAVE_STRDUP} + +/* Define to 1 if you have the `strerror' function. */ +#cmakedefine HAVE_STRERROR ${HAVE_STRERROR} + +/* Define to 1 if you have the `strerror_r' function. */ +#cmakedefine HAVE_STRERROR_R ${HAVE_STRERROR_R} + +/* Define to 1 if you have the <strings.h> header file. */ +#cmakedefine HAVE_STRINGS_H ${HAVE_STRINGS_H} + +/* Define to 1 if you have the <string.h> header file. */ +#cmakedefine HAVE_STRING_H ${HAVE_STRING_H} + +/* Define to 1 if you have the `strrchr' function. */ +#cmakedefine HAVE_STRRCHR ${HAVE_STRRCHR} + +/* Define to 1 if you have the `strtof' function. */ +#cmakedefine HAVE_STRTOF ${HAVE_STRTOF} + +/* Define to 1 if you have the `strtoll' function. */ +#cmakedefine HAVE_STRTOLL ${HAVE_STRTOLL} + +/* Define to 1 if you have the `strtoq' function. */ +#cmakedefine HAVE_STRTOQ ${HAVE_STRTOQ} + +/* Define to 1 if you have the `sysconf' function. */ +#undef HAVE_SYSCONF + +/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'. + */ +#cmakedefine HAVE_SYS_DIR_H ${HAVE_SYS_DIR_H} + +/* Define to 1 if you have the <sys/dl.h> header file. */ +#cmakedefine HAVE_SYS_DL_H ${HAVE_SYS_DL_H} + +/* Define to 1 if you have the <sys/ioctl.h> header file. */ +#cmakedefine HAVE_SYS_IOCTL_H ${HAVE_SYS_IOCTL_H} + +/* Define to 1 if you have the <sys/mman.h> header file. */ +#cmakedefine HAVE_SYS_MMAN_H ${} + +/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'. + */ +#cmakedefine HAVE_SYS_NDIR_H ${HAVE_SYS_NDIR_H} + +/* Define to 1 if you have the <sys/param.h> header file. */ +#cmakedefine HAVE_SYS_PARAM_H ${HAVE_SYS_PARAM_H} + +/* Define to 1 if you have the <sys/resource.h> header file. */ +#cmakedefine HAVE_SYS_RESOURCE_H ${HAVE_SYS_RESOURCE_H} + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#cmakedefine HAVE_SYS_STAT_H ${HAVE_SYS_STAT_H} + +/* Define to 1 if you have the <sys/time.h> header file. */ +#cmakedefine HAVE_SYS_TIME_H ${HAVE_SYS_TIME_H} + +/* Define to 1 if you have the <sys/types.h> header file. */ +#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H} + +/* Define to 1 if you have the <sys/uio.h> header file. */ +#cmakedefine HAVE_SYS_UIO_H ${HAVE_SYS_UIO_H} + +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */ +#cmakedefine HAVE_SYS_WAIT_H ${HAVE_SYS_WAIT_H} + +/* Define to 1 if you have the <termios.h> header file. */ +#cmakedefine HAVE_TERMIOS_H ${HAVE_TERMIOS_H} + +/* Define if the neat program is available */ +#cmakedefine HAVE_TWOPI ${HAVE_TWOPI} + +/* Define to 1 if the system has the type `uint64_t'. */ +#cmakedefine HAVE_UINT64_T ${HAVE_UINT64_T} + +/* Define to 1 if you have the <unistd.h> header file. */ +#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H} + +/* Define to 1 if you have the <utime.h> header file. */ +#cmakedefine HAVE_UTIME_H ${HAVE_UTIME_H} + +/* Define to 1 if the system has the type `u_int64_t'. */ +#cmakedefine HAVE_U_INT64_T ${HAVE_U_INT64_T} + +/* Define to 1 if you have the <valgrind/valgrind.h> header file. */ +#cmakedefine HAVE_VALGRIND_VALGRIND_H ${HAVE_VALGRIND_VALGRIND_H} + +/* Define to 1 if you have the <windows.h> header file. */ +#cmakedefine HAVE_WINDOWS_H ${HAVE_WINDOWS_H} + +/* Define to 1 if you have the `writev' function. */ +#cmakedefine HAVE_WRITEV ${HAVE_WRITEV} + +/* Define if the xdot.py program is available */ +#cmakedefine HAVE_XDOT_PY ${HAVE_XDOT_PY} + +/* Have host's _alloca */ +#cmakedefine HAVE__ALLOCA ${HAVE__ALLOCA} + +/* Have host's __alloca */ +#cmakedefine HAVE___ALLOCA ${HAVE___ALLOCA} + +/* Have host's __ashldi3 */ +#cmakedefine HAVE___ASHLDI3 ${HAVE___ASHLDI3} + +/* Have host's __ashrdi3 */ +#cmakedefine HAVE___ASHRDI3 ${HAVE___ASHRDI3} + +/* Have host's __chkstk */ +#cmakedefine HAVE___CHKSTK ${HAVE___CHKSTK} + +/* Have host's __cmpdi2 */ +#cmakedefine HAVE___CMPDI2 ${HAVE___CMPDI2} + +/* Have host's __divdi3 */ +#cmakedefine HAVE___DIVDI3 ${HAVE___DIVDI3} + +/* Define to 1 if you have the `__dso_handle' function. */ +#undef HAVE___DSO_HANDLE + +/* Have host's __fixdfdi */ +#cmakedefine HAVE___FIXDFDI ${HAVE___FIXDFDI} + +/* Have host's __fixsfdi */ +#cmakedefine HAVE___FIXSFDI ${HAVE___FIXSFDI} + +/* Have host's __floatdidf */ +#cmakedefine HAVE___FLOATDIDF ${HAVE___FLOATDIDF} + +/* Have host's __lshrdi3 */ +#cmakedefine HAVE___LSHRDI3 ${HAVE___LSHRDI3} + +/* Have host's __main */ +#cmakedefine HAVE___MAIN ${HAVE___MAIN} + +/* Have host's __moddi3 */ +#cmakedefine HAVE___MODDI3 ${HAVE___MODDI3} + +/* Have host's __udivdi3 */ +#cmakedefine HAVE___UDIVDI3 ${HAVE___UDIVDI3} + +/* Have host's __umoddi3 */ +#cmakedefine HAVE___UMODDI3 ${HAVE___UMODDI3} + +/* Have host's ___chkstk */ +#cmakedefine HAVE____CHKSTK ${HAVE____CHKSTK} + +/* Define if /dev/zero should be used when mapping RWX memory, or undefine if + its not necessary */ +#undef NEED_DEV_ZERO_FOR_MMAP + +/* Define if dlsym() requires a leading underscore in symbol names. */ +#undef NEED_USCORE + +/* Define to the address where bug reports for this package should be sent. */ +#cmakedefine PACKAGE_BUGREPORT "${PACKAGE_BUGREPORT}" + +/* Define to the full name of this package. */ +#cmakedefine PACKAGE_NAME "${PACKAGE_NAME}" + +/* Define to the full name and version of this package. */ +#cmakedefine PACKAGE_STRING "${PACKAGE_STRING}" + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#cmakedefine PACKAGE_VERSION "${PACKAGE_VERSION}" + +/* Define as the return type of signal handlers (`int' or `void'). */ +#cmakedefine RETSIGTYPE ${RETSIGTYPE} + +/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */ +#undef STAT_MACROS_BROKEN + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ +#undef TIME_WITH_SYS_TIME + +/* Define to 1 if your <sys/time.h> declares `struct tm'. */ +#undef TM_IN_SYS_TIME + +/* Define if use udis86 library */ +#undef USE_UDIS86 + +/* Type of 1st arg on ELM Callback */ +#cmakedefine WIN32_ELMCB_PCSTR ${WIN32_ELMCB_PCSTR} + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define to a type to use for `error_t' if it is not otherwise available. */ +#cmakedefine error_t ${error_t} + +/* Define to `int' if <sys/types.h> does not define. */ +#undef pid_t + +/* Define to `unsigned int' if <sys/types.h> does not define. */ +#undef size_t + +/* Define to a function replacing strtoll */ +#cmakedefine strtoll ${strtoll} + +/* Define to a function implementing strtoull */ +#cmakedefine strtoull ${strtoull} + +/* Define to a function implementing stricmp */ +#cmakedefine stricmp ${stricmp} + +/* Define to a function implementing strdup */ +#cmakedefine strdup ${strdup} + +/* Define to 1 if you have the `_chsize_s' function. */ +#cmakedefine HAVE__CHSIZE_S ${HAVE__CHSIZE_S} + +#endif +
diff --git a/include/mcld/Config/Config.h.in b/include/mcld/Config/Config.h.in index 4a38cbf..8afadca 100644 --- a/include/mcld/Config/Config.h.in +++ b/include/mcld/Config/Config.h.in
@@ -13,6 +13,9 @@ #define MCLD_CONFIG_H +/* Define to 1 if you have the <cxxabi.h> header file. */ +#undef HAVE_CXXABI_H + /* Define to 1 if you have the <dlfcn.h> header file. */ #undef HAVE_DLFCN_H @@ -52,6 +55,9 @@ /* Define to 1 if you have the <unistd.h> header file. */ #undef HAVE_UNISTD_H +/* Define to 1 if you have the <zlib.h> header file. */ +#undef HAVE_ZLIB_H + /* Define to the sub-directory in which libtool stores uninstalled libraries. */ #undef LT_OBJDIR @@ -102,12 +108,17 @@ /* Version number of package */ #undef VERSION +/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a + `char[]'. */ +#undef YYTEXT_POINTER + #define MCLD_REGION_CHUNK_SIZE 32 #define MCLD_NUM_OF_INPUTS 32 #define MCLD_SECTIONS_PER_INPUT 16 #define MCLD_SYMBOLS_PER_INPUT 128 #define MCLD_RELOCATIONS_PER_INPUT 1024 + #define MCLD_SEGMENTS_PER_OUTPUT 8 #endif
diff --git a/include/mcld/Config/Linkers.def.cmake b/include/mcld/Config/Linkers.def.cmake new file mode 100644 index 0000000..d03ead0 --- /dev/null +++ b/include/mcld/Config/Linkers.def.cmake
@@ -0,0 +1,28 @@ +//===- llvm/Config/Linkers.def - MCLinkers ----------------------*- C++ -*-===// +// +// The MCLinker Project +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file enumerates all of the linkers supported by this build of MCLinker. +// Clients of this file should define the MCLD_LINKER macro to be a function-like +// macro with a single parameter (the name of the target whose exe/dso can be +// generated); including this file will then enumerate all of the targets with +// linkers. +// +// The set of targets supported by MCLD is generated at configuration +// time, at which point this header is generated. Do not modify this +// header directly. +// +//===----------------------------------------------------------------------===// + +#ifndef MCLD_LINKER +# error Please define the macro MCLD_LINKER(TargetName) +#endif + +${MCLD_ENUM_LINKERS} + +#undef MCLD_LINKER
diff --git a/include/mcld/Config/Targets.def.cmake b/include/mcld/Config/Targets.def.cmake new file mode 100644 index 0000000..062a231 --- /dev/null +++ b/include/mcld/Config/Targets.def.cmake
@@ -0,0 +1,28 @@ +/*===- llvm/Config/Targets.def - MCLD Target Architectures ------*- C++ -*-===*\ +|* *| +|* The MCLinker Project *| +|* *| +|* This file is distributed under the University of Illinois Open Source *| +|* License. See LICENSE.TXT for details. *| +|* *| +|*===----------------------------------------------------------------------===*| +|* *| +|* This file enumerates all of the target architectures supported by *| +|* this build of MCLD. Clients of this file should define the *| +|* MCLD_TARGET macro to be a function-like macro with a single *| +|* parameter (the name of the target); including this file will then *| +|* enumerate all of the targets. *| +|* *| +|* The set of targets supported by MCLD is generated at configuration *| +|* time, at which point this header is generated. Do not modify this *| +|* header directly. *| +|* *| +\*===----------------------------------------------------------------------===*/ + +#ifndef MCLD_TARGET +# error Please define the macro MCLD_TARGET(TargetName) +#endif + +${MCLD_ENUM_TARGETS} + +#undef MCLD_TARGET
diff --git a/include/mcld/Environment.h b/include/mcld/Environment.h index 20bcd8e..4f577da 100644 --- a/include/mcld/Environment.h +++ b/include/mcld/Environment.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ENVIRONMENT_H -#define MCLD_ENVIRONMENT_H +#ifndef MCLD_ENVIRONMENT_H_ +#define MCLD_ENVIRONMENT_H_ namespace mcld { @@ -15,6 +15,6 @@ void Finalize(); -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_ENVIRONMENT_H_
diff --git a/include/mcld/Fragment/AlignFragment.h b/include/mcld/Fragment/AlignFragment.h index 5ca9b84..1680f9c 100644 --- a/include/mcld/Fragment/AlignFragment.h +++ b/include/mcld/Fragment/AlignFragment.h
@@ -6,20 +6,22 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_FRAGMENT_ALIGNFRAGMENT_H -#define MCLD_FRAGMENT_ALIGNFRAGMENT_H +#ifndef MCLD_FRAGMENT_ALIGNFRAGMENT_H_ +#define MCLD_FRAGMENT_ALIGNFRAGMENT_H_ -#include <mcld/Fragment/Fragment.h> +#include "mcld/Fragment/Fragment.h" namespace mcld { class SectionData; -class AlignFragment : public Fragment -{ -public: - AlignFragment(unsigned int pAlignment, int64_t pValue, unsigned int pValueSize, - unsigned int pMaxBytesToEmit, SectionData *pSD = NULL); +class AlignFragment : public Fragment { + public: + AlignFragment(unsigned int pAlignment, + int64_t pValue, + unsigned int pValueSize, + unsigned int pMaxBytesToEmit, + SectionData* pSD = NULL); unsigned int getAlignment() const { return m_Alignment; } @@ -33,13 +35,15 @@ void setEmitNops(bool pValue) { m_bEmitNops = pValue; } - static bool classof(const Fragment *F) - { return F->getKind() == Fragment::Alignment; } - static bool classof(const AlignFragment *) { return true; } + static bool classof(const Fragment* F) { + return F->getKind() == Fragment::Alignment; + } + + static bool classof(const AlignFragment*) { return true; } size_t size() const; -private: + private: /// Alignment - The alignment to ensure, in bytes. unsigned int m_Alignment; @@ -57,10 +61,8 @@ /// of using the provided value. The exact interpretation of this flag is /// target dependent. bool m_bEmitNops : 1; - }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_FRAGMENT_ALIGNFRAGMENT_H_
diff --git a/include/mcld/Fragment/FillFragment.h b/include/mcld/Fragment/FillFragment.h index 96a17f6..3bb15db 100644 --- a/include/mcld/Fragment/FillFragment.h +++ b/include/mcld/Fragment/FillFragment.h
@@ -6,35 +6,37 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_FRAGMENT_FILLFRAGMENT_H -#define MCLD_FRAGMENT_FILLFRAGMENT_H +#ifndef MCLD_FRAGMENT_FILLFRAGMENT_H_ +#define MCLD_FRAGMENT_FILLFRAGMENT_H_ + +#include "mcld/Fragment/Fragment.h" #include <llvm/Support/DataTypes.h> -#include <mcld/Fragment/Fragment.h> - namespace mcld { class SectionData; -class FillFragment : public Fragment -{ -public: - FillFragment(int64_t pValue, unsigned int pValueSize, uint64_t pSize, +class FillFragment : public Fragment { + public: + FillFragment(int64_t pValue, + unsigned int pValueSize, + uint64_t pSize, SectionData* pSD = NULL); int64_t getValue() const { return m_Value; } unsigned getValueSize() const { return m_ValueSize; } - static bool classof(const Fragment *F) - { return F->getKind() == Fragment::Fillment; } + static bool classof(const Fragment* F) { + return F->getKind() == Fragment::Fillment; + } - static bool classof(const FillFragment *) { return true; } + static bool classof(const FillFragment*) { return true; } size_t size() const { return m_Size; } -private: + private: /// m_Value - Value used for filling bytes int64_t m_Value; @@ -46,7 +48,6 @@ uint64_t m_Size; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_FRAGMENT_FILLFRAGMENT_H_
diff --git a/include/mcld/Fragment/Fragment.h b/include/mcld/Fragment/Fragment.h index 572ebde..76a5028 100644 --- a/include/mcld/Fragment/Fragment.h +++ b/include/mcld/Fragment/Fragment.h
@@ -6,15 +6,16 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_FRAGMENT_FRAGMENT_H -#define MCLD_FRAGMENT_FRAGMENT_H +#ifndef MCLD_FRAGMENT_FRAGMENT_H_ +#define MCLD_FRAGMENT_FRAGMENT_H_ + +#include "mcld/Support/Compiler.h" #include <llvm/ADT/ilist_node.h> - #include <llvm/Support/DataTypes.h> -#include <cstddef> #include <cassert> +#include <cstddef> namespace mcld { @@ -23,31 +24,23 @@ /** \class Fragment * \brief Fragment is the minimun linking unit of MCLinker. */ -class Fragment : public llvm::ilist_node<Fragment> -{ -public: - enum Type { - Alignment, - Fillment, - Region, - Target, - Stub, - Null - }; +class Fragment : public llvm::ilist_node<Fragment> { + public: + enum Type { Alignment, Fillment, Region, Target, Stub, Null }; -public: + public: Fragment(); - Fragment(Type pKind, SectionData *pParent = NULL); + explicit Fragment(Type pKind, SectionData* pParent = NULL); virtual ~Fragment(); Type getKind() const { return m_Kind; } const SectionData* getParent() const { return m_pParent; } - SectionData* getParent() { return m_pParent; } + SectionData* getParent() { return m_pParent; } - void setParent(SectionData *pValue) { m_pParent = pValue; } + void setParent(SectionData* pValue) { m_pParent = pValue; } uint64_t getOffset() const; @@ -55,26 +48,24 @@ bool hasOffset() const; - static bool classof(const Fragment *O) { return true; } + static bool classof(const Fragment* O) { return true; } virtual size_t size() const { assert(false && "Can not call abstract Fragment::size()!"); return 0; } -private: - Fragment(const Fragment& ); // DO NOT IMPLEMENT - Fragment& operator=(const Fragment& ); // DO NOT IMPLEMENT - -private: + private: Type m_Kind; + SectionData* m_pParent; uint64_t m_Offset; + private: + DISALLOW_COPY_AND_ASSIGN(Fragment); }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_FRAGMENT_FRAGMENT_H_
diff --git a/include/mcld/Fragment/FragmentRef.h b/include/mcld/Fragment/FragmentRef.h index 768dab3..1db45a2 100644 --- a/include/mcld/Fragment/FragmentRef.h +++ b/include/mcld/Fragment/FragmentRef.h
@@ -6,13 +6,13 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_FRAGMENT_FRAGMENTREF_H -#define MCLD_FRAGMENT_FRAGMENTREF_H +#ifndef MCLD_FRAGMENT_FRAGMENTREF_H_ +#define MCLD_FRAGMENT_FRAGMENTREF_H_ -#include <mcld/Config/Config.h> -#include <mcld/ADT/SizeTraits.h> -#include <mcld/ADT/TypeTraits.h> -#include <mcld/Support/Allocators.h> +#include "mcld/ADT/SizeTraits.h" +#include "mcld/ADT/TypeTraits.h" +#include "mcld/Config/Config.h" +#include "mcld/Support/Allocators.h" namespace mcld { @@ -24,14 +24,13 @@ * \brief FragmentRef is a reference of a Fragment's contetnt. * */ -class FragmentRef -{ -public: - typedef uint64_t Offset; // FIXME: use SizeTraits<T>::Offset +class FragmentRef { + public: + typedef uint64_t Offset; // FIXME: use SizeTraits<T>::Offset typedef NonConstTraits<unsigned char>::pointer Address; typedef ConstTraits<unsigned char>::pointer ConstAddress; -public: + public: /// Create - create a fragment reference for a given fragment. /// /// @param pFrag - the given fragment @@ -64,35 +63,31 @@ // ----- observers ----- // bool isNull() const { return (this == Null()); } - Fragment* frag() - { return m_pFragment; } + Fragment* frag() { return m_pFragment; } - const Fragment* frag() const - { return m_pFragment; } + const Fragment* frag() const { return m_pFragment; } - Offset offset() const - { return m_Offset; } + Offset offset() const { return m_Offset; } Offset getOutputOffset() const; -private: + private: friend FragmentRef& NullFragmentRef(); friend class Chunk<FragmentRef, MCLD_SECTIONS_PER_INPUT>; friend class Relocation; FragmentRef(); - FragmentRef(Fragment& pFrag, Offset pOffset = 0); + explicit FragmentRef(Fragment& pFrag, Offset pOffset = 0); -private: + private: Fragment* m_pFragment; + Offset m_Offset; static FragmentRef g_NullFragmentRef; - }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_FRAGMENT_FRAGMENTREF_H_
diff --git a/include/mcld/Fragment/NullFragment.h b/include/mcld/Fragment/NullFragment.h index cd3ba9f..1764b26 100644 --- a/include/mcld/Fragment/NullFragment.h +++ b/include/mcld/Fragment/NullFragment.h
@@ -6,10 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_FRAGMENT_NULLFRAGMENT_H -#define MCLD_FRAGMENT_NULLFRAGMENT_H +#ifndef MCLD_FRAGMENT_NULLFRAGMENT_H_ +#define MCLD_FRAGMENT_NULLFRAGMENT_H_ -#include <mcld/Fragment/Fragment.h> +#include "mcld/Fragment/Fragment.h" namespace mcld { @@ -19,22 +19,20 @@ * \brief NullFragment is a kind of MCFragment that presents the "end fragment" * referenced by some special symbols */ -class NullFragment : public Fragment -{ -public: - NullFragment(SectionData* pSD = NULL); +class NullFragment : public Fragment { + public: + explicit NullFragment(SectionData* pSD = NULL); /// size - size_t size() const { return 0x0; } - static bool classof(const Fragment *F) - { return F->getKind() == Fragment::Null; } + static bool classof(const Fragment* F) { + return F->getKind() == Fragment::Null; + } - static bool classof(const NullFragment *) - { return true; } + static bool classof(const NullFragment*) { return true; } }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_FRAGMENT_NULLFRAGMENT_H_
diff --git a/include/mcld/Fragment/RegionFragment.h b/include/mcld/Fragment/RegionFragment.h index 09d2db8..16ccea8 100644 --- a/include/mcld/Fragment/RegionFragment.h +++ b/include/mcld/Fragment/RegionFragment.h
@@ -6,10 +6,11 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_FRAGMENT_REGIONFRAGMENT_H -#define MCLD_FRAGMENT_REGIONFRAGMENT_H +#ifndef MCLD_FRAGMENT_REGIONFRAGMENT_H_ +#define MCLD_FRAGMENT_REGIONFRAGMENT_H_ -#include <mcld/Fragment/Fragment.h> +#include "mcld/Fragment/Fragment.h" + #include <llvm/ADT/StringRef.h> namespace mcld { @@ -17,29 +18,27 @@ /** \class RegionFragment * \brief RegionFragment is a kind of Fragment containing input memory region */ -class RegionFragment : public Fragment -{ -public: - RegionFragment(llvm::StringRef pRegion, SectionData* pSD = NULL); +class RegionFragment : public Fragment { + public: + explicit RegionFragment(llvm::StringRef pRegion, SectionData* pSD = NULL); ~RegionFragment(); const llvm::StringRef getRegion() const { return m_Region; } - llvm::StringRef getRegion() { return m_Region; } + llvm::StringRef getRegion() { return m_Region; } - static bool classof(const Fragment *F) - { return F->getKind() == Fragment::Region; } + static bool classof(const Fragment* F) { + return F->getKind() == Fragment::Region; + } - static bool classof(const RegionFragment *) - { return true; } + static bool classof(const RegionFragment*) { return true; } size_t size() const; -private: + private: llvm::StringRef m_Region; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_FRAGMENT_REGIONFRAGMENT_H_
diff --git a/include/mcld/Fragment/Relocation.h b/include/mcld/Fragment/Relocation.h index a8479b5..e6a4c76 100644 --- a/include/mcld/Fragment/Relocation.h +++ b/include/mcld/Fragment/Relocation.h
@@ -6,11 +6,12 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_FRAGMENT_RELOCATION_H -#define MCLD_FRAGMENT_RELOCATION_H -#include <mcld/Config/Config.h> -#include <mcld/Fragment/FragmentRef.h> -#include <mcld/Support/GCFactoryListTraits.h> +#ifndef MCLD_FRAGMENT_RELOCATION_H_ +#define MCLD_FRAGMENT_RELOCATION_H_ + +#include "mcld/Config/Config.h" +#include "mcld/Fragment/FragmentRef.h" +#include "mcld/Support/GCFactoryListTraits.h" #include <llvm/ADT/ilist_node.h> #include <llvm/Support/DataTypes.h> @@ -21,20 +22,19 @@ class Relocator; class LinkerConfig; -class Relocation : public llvm::ilist_node<Relocation> -{ -friend class RelocationFactory; -friend class GCFactoryListTraits<Relocation>; -friend class Chunk<Relocation, MCLD_RELOCATIONS_PER_INPUT>; +class Relocation : public llvm::ilist_node<Relocation> { + friend class RelocationFactory; + friend class GCFactoryListTraits<Relocation>; + friend class Chunk<Relocation, MCLD_RELOCATIONS_PER_INPUT>; -public: - typedef uint64_t Address; // FIXME: use SizeTrait<T>::Address instead - typedef uint64_t DWord; // FIXME: use SizeTrait<T>::Word instead - typedef int64_t SWord; // FIXME: use SizeTrait<T>::SWord instead + public: + typedef uint64_t Address; // FIXME: use SizeTrait<T>::Address instead + typedef uint64_t DWord; // FIXME: use SizeTrait<T>::Word instead + typedef int64_t SWord; // FIXME: use SizeTrait<T>::SWord instead typedef uint32_t Type; typedef uint32_t Size; -private: + private: Relocation(); Relocation(Type pType, @@ -44,7 +44,7 @@ ~Relocation(); -public: + public: /// Initialize - set up the relocation factory static void SetUp(const LinkerConfig& pConfig); @@ -58,22 +58,21 @@ /// @param pType [in] the type of the relocation entry /// @param pFragRef [in] the place to apply the relocation /// @param pAddend [in] the addend of the relocation entry - static Relocation* Create(Type pType, FragmentRef& pFragRef, + static Relocation* Create(Type pType, + FragmentRef& pFragRef, Address pAddend = 0); /// Destroy - destroy a relocation entry static void Destroy(Relocation*& pRelocation); /// type - relocation type - Type type() const - { return m_Type; } + Type type() const { return m_Type; } /// symValue - S value - the symbol address Address symValue() const; /// addend - A value - Address addend() const - { return m_Addend; } + Address addend() const { return m_Addend; } /// place - P value - address of the place being relocated Address place() const; @@ -83,15 +82,15 @@ /// symbol info - binding, type const ResolveInfo* symInfo() const { return m_pSymInfo; } - ResolveInfo* symInfo() { return m_pSymInfo; } + ResolveInfo* symInfo() { return m_pSymInfo; } /// target - the target data to relocate const DWord& target() const { return m_TargetData; } - DWord& target() { return m_TargetData; } + DWord& target() { return m_TargetData; } /// targetRef - the reference of the target data const FragmentRef& targetRef() const { return m_TargetAddress; } - FragmentRef& targetRef() { return m_TargetAddress; } + FragmentRef& targetRef() { return m_TargetAddress; } void apply(Relocator& pRelocator); @@ -106,7 +105,7 @@ void setSymInfo(ResolveInfo* pSym); -private: + private: /// m_Type - the type of the relocation entries Type m_Type; @@ -123,7 +122,6 @@ Address m_Addend; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_FRAGMENT_RELOCATION_H_
diff --git a/include/mcld/Fragment/Stub.h b/include/mcld/Fragment/Stub.h index f05aefe..94f58e9 100644 --- a/include/mcld/Fragment/Stub.h +++ b/include/mcld/Fragment/Stub.h
@@ -7,56 +7,53 @@ // //===----------------------------------------------------------------------===// -#ifndef MCLD_FRAGMENT_STUB_H -#define MCLD_FRAGMENT_STUB_H +#ifndef MCLD_FRAGMENT_STUB_H_ +#define MCLD_FRAGMENT_STUB_H_ + +#include "mcld/Fragment/Fragment.h" +#include "mcld/Fragment/Relocation.h" #include <llvm/Support/DataTypes.h> -#include <mcld/Fragment/Fragment.h> -#include <mcld/Fragment/Relocation.h> -#include <vector> -#include <string> -namespace mcld -{ +#include <string> +#include <vector> + +namespace mcld { class Relocation; class ResolveInfo; -class Stub: public Fragment -{ -public: +class Stub : public Fragment { + public: typedef Relocation::DWord DWord; typedef Relocation::SWord SWord; - typedef Relocation::Type Type; + typedef Relocation::Type Type; - class Fixup - { - public: + class Fixup { + public: Fixup(DWord pOffset, SWord pAddend, Type pType) - : m_Offset(pOffset), m_Addend(pAddend), m_Type(pType) - { } + : m_Offset(pOffset), m_Addend(pAddend), m_Type(pType) {} - ~Fixup() - { } + ~Fixup() {} DWord offset() const { return m_Offset; } SWord addend() const { return m_Addend; } - Type type() const { return m_Type; } + Type type() const { return m_Type; } - private: + private: DWord m_Offset; SWord m_Addend; - Type m_Type; + Type m_Type; }; -public: + public: typedef std::vector<Fixup*> FixupListType; typedef FixupListType::iterator fixup_iterator; typedef FixupListType::const_iterator const_fixup_iterator; -public: + public: Stub(); virtual ~Stub(); @@ -83,49 +80,48 @@ virtual size_t alignment() const = 0; /// symInfo - ResolveInfo of this Stub - ResolveInfo* symInfo() { return m_pSymInfo; } + ResolveInfo* symInfo() { return m_pSymInfo; } const ResolveInfo* symInfo() const { return m_pSymInfo; } /// symValue - initial value for stub's symbol - virtual uint64_t initSymValue() const { return 0x0; } + virtual uint64_t initSymValue() const { return 0x0; } /// ----- Fixup ----- /// - fixup_iterator fixup_begin() { return m_FixupList.begin(); } + fixup_iterator fixup_begin() { return m_FixupList.begin(); } const_fixup_iterator fixup_begin() const { return m_FixupList.begin(); } - fixup_iterator fixup_end() { return m_FixupList.end(); } + fixup_iterator fixup_end() { return m_FixupList.end(); } - const_fixup_iterator fixup_end() const { return m_FixupList.end(); } + const_fixup_iterator fixup_end() const { return m_FixupList.end(); } /// ----- modifiers ----- /// void setSymInfo(ResolveInfo* pSymInfo); // Stub is a kind of Fragment with type of Stub - static bool classof(const Fragment *F) - { return F->getKind() == Fragment::Stub; } + static bool classof(const Fragment* F) { + return F->getKind() == Fragment::Stub; + } - static bool classof(const Stub *) - { return true; } + static bool classof(const Stub*) { return true; } -protected: + protected: /// addFixup - add a fixup for this stub to build a relocation void addFixup(DWord pOffset, SWord pAddend, Type pType); /// addFixup - add a fixup from a existing fixup of the prototype void addFixup(const Fixup& pFixup); -private: + private: /// doClone - when adding a backend stub, we should implement this function virtual Stub* doClone() = 0; -private: + private: ResolveInfo* m_pSymInfo; FixupListType m_FixupList; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_FRAGMENT_STUB_H_
diff --git a/include/mcld/Fragment/TargetFragment.h b/include/mcld/Fragment/TargetFragment.h index aa404a0..e0c3051 100644 --- a/include/mcld/Fragment/TargetFragment.h +++ b/include/mcld/Fragment/TargetFragment.h
@@ -6,10 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_FRAGMENT_TARGETFRAGMENT_H -#define MCLD_FRAGMENT_TARGETFRAGMENT_H +#ifndef MCLD_FRAGMENT_TARGETFRAGMENT_H_ +#define MCLD_FRAGMENT_TARGETFRAGMENT_H_ -#include <mcld/Fragment/Fragment.h> +#include "mcld/Fragment/Fragment.h" namespace mcld { @@ -19,23 +19,21 @@ * \brief TargetFragment is a kind of MCFragment inherited by * target-depedent Fragment. */ -class TargetFragment : public Fragment -{ -protected: - TargetFragment(Fragment::Type pKind, SectionData* pSD = NULL) - : Fragment(pKind, pSD) {} +class TargetFragment : public Fragment { + protected: + explicit TargetFragment(Fragment::Type pKind, SectionData* pSD = NULL) + : Fragment(pKind, pSD) {} -public: + public: virtual ~TargetFragment() {} - static bool classof(const Fragment *F) - { return F->getKind() == Fragment::Target; } + static bool classof(const Fragment* F) { + return F->getKind() == Fragment::Target; + } - static bool classof(const TargetFragment *) - { return true; } + static bool classof(const TargetFragment*) { return true; } }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_FRAGMENT_TARGETFRAGMENT_H_
diff --git a/include/mcld/GeneralOptions.h b/include/mcld/GeneralOptions.h index 1d6c9a3..58e4eb3 100644 --- a/include/mcld/GeneralOptions.h +++ b/include/mcld/GeneralOptions.h
@@ -6,10 +6,11 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_GENERALOPTIONS_H -#define MCLD_GENERALOPTIONS_H -#include <mcld/Support/RealPath.h> -#include <mcld/Support/FileSystem.h> +#ifndef MCLD_GENERALOPTIONS_H_ +#define MCLD_GENERALOPTIONS_H_ +#include "mcld/Config/Config.h" +#include "mcld/Support/RealPath.h" +#include "mcld/Support/FileSystem.h" #include <string> #include <vector> #include <set> @@ -24,9 +25,8 @@ * - input files * - attribute of input files */ -class GeneralOptions -{ -public: +class GeneralOptions { + public: enum StripSymbolMode { KeepAllSymbols, StripTemporaries, @@ -34,17 +34,9 @@ StripAllSymbols }; - enum HashStyle { - SystemV = 0x1, - GNU = 0x2, - Both = 0x3 - }; + enum HashStyle { SystemV = 0x1, GNU = 0x2, Both = 0x3 }; - enum ICF { - ICF_None, - ICF_All, - ICF_Safe - }; + enum ICF { ICF_None, ICF_All, ICF_Safe }; typedef std::vector<std::string> RpathList; typedef RpathList::iterator rpath_iterator; @@ -64,404 +56,324 @@ typedef std::set<std::string> ExcludeLIBS; -public: + public: GeneralOptions(); ~GeneralOptions(); /// trace - void setTrace(bool pEnableTrace = true) - { m_bTrace = pEnableTrace; } + void setTrace(bool pEnableTrace = true) { m_bTrace = pEnableTrace; } - bool trace() const - { return m_bTrace; } + bool trace() const { return m_bTrace; } - void setBsymbolic(bool pBsymbolic = true) - { m_Bsymbolic = pBsymbolic; } + void setBsymbolic(bool pBsymbolic = true) { m_Bsymbolic = pBsymbolic; } - bool Bsymbolic() const - { return m_Bsymbolic; } + bool Bsymbolic() const { return m_Bsymbolic; } - void setPIE(bool pPIE = true) - { m_bPIE = pPIE; } + void setPIE(bool pPIE = true) { m_bPIE = pPIE; } - bool isPIE() const - { return m_bPIE; } + bool isPIE() const { return m_bPIE; } - void setBgroup(bool pBgroup = true) - { m_Bgroup = pBgroup; } + void setBgroup(bool pBgroup = true) { m_Bgroup = pBgroup; } - bool Bgroup() const - { return m_Bgroup; } + bool Bgroup() const { return m_Bgroup; } - void setDyld(const std::string& pDyld) - { m_Dyld = pDyld; } + void setDyld(const std::string& pDyld) { m_Dyld = pDyld; } - const std::string& dyld() const - { return m_Dyld; } + const std::string& dyld() const { return m_Dyld; } - bool hasDyld() const - { return !m_Dyld.empty(); } + bool hasDyld() const { return !m_Dyld.empty(); } void setSOName(const std::string& pName); - const std::string& soname() const - { return m_SOName; } + const std::string& soname() const { return m_SOName; } - void setVerbose(int8_t pVerbose = -1) - { m_Verbose = pVerbose; } + void setVerbose(int8_t pVerbose = -1) { m_Verbose = pVerbose; } - int8_t verbose() const - { return m_Verbose; } + int8_t verbose() const { return m_Verbose; } - void setMaxErrorNum(int16_t pNum) - { m_MaxErrorNum = pNum; } + void setMaxErrorNum(int16_t pNum) { m_MaxErrorNum = pNum; } - int16_t maxErrorNum() const - { return m_MaxErrorNum; } + int16_t maxErrorNum() const { return m_MaxErrorNum; } - void setMaxWarnNum(int16_t pNum) - { m_MaxWarnNum = pNum; } + void setMaxWarnNum(int16_t pNum) { m_MaxWarnNum = pNum; } - int16_t maxWarnNum() const - { return m_MaxWarnNum; } + int16_t maxWarnNum() const { return m_MaxWarnNum; } - void setColor(bool pEnabled = true) - { m_bColor = pEnabled; } + void setColor(bool pEnabled = true) { m_bColor = pEnabled; } - bool color() const - { return m_bColor; } + bool color() const { return m_bColor; } - void setNoUndefined(bool pEnable = true) - { m_NoUndefined = (pEnable?YES:NO); } + void setNoUndefined(bool pEnable = true) { + m_NoUndefined = (pEnable ? YES : NO); + } - void setMulDefs(bool pEnable = true) - { m_MulDefs = (pEnable?YES:NO); } + void setMulDefs(bool pEnable = true) { m_MulDefs = (pEnable ? YES : NO); } - void setEhFrameHdr(bool pEnable = true) - { m_bCreateEhFrameHdr = pEnable; } + void setEhFrameHdr(bool pEnable = true) { m_bCreateEhFrameHdr = pEnable; } /// ----- the -z options ----- /// void addZOption(const mcld::ZOption& pOption); - bool hasCombReloc() const - { return m_bCombReloc; } + bool hasCombReloc() const { return m_bCombReloc; } - bool hasNoUndefined() const - { return (Unknown != m_NoUndefined); } + bool hasNoUndefined() const { return (Unknown != m_NoUndefined); } - bool isNoUndefined() const - { return (YES == m_NoUndefined); } + bool isNoUndefined() const { return (YES == m_NoUndefined); } - bool hasStackSet() const - { return (Unknown != m_ExecStack); } + bool hasStackSet() const { return (Unknown != m_ExecStack); } - bool hasExecStack() const - { return (YES == m_ExecStack); } + bool hasExecStack() const { return (YES == m_ExecStack); } - bool hasInitFirst() const - { return m_bInitFirst; } + bool hasInitFirst() const { return m_bInitFirst; } - bool hasInterPose() const - { return m_bInterPose; } + bool hasInterPose() const { return m_bInterPose; } - bool hasLoadFltr() const - { return m_bLoadFltr; } + bool hasLoadFltr() const { return m_bLoadFltr; } - bool hasMulDefs() const - { return (Unknown != m_MulDefs); } + bool hasMulDefs() const { return (Unknown != m_MulDefs); } - bool isMulDefs() const - { return (YES == m_MulDefs); } + bool isMulDefs() const { return (YES == m_MulDefs); } - bool hasNoCopyReloc() const - { return m_bNoCopyReloc; } + bool hasNoCopyReloc() const { return m_bNoCopyReloc; } - bool hasNoDefaultLib() const - { return m_bNoDefaultLib; } + bool hasNoDefaultLib() const { return m_bNoDefaultLib; } - bool hasNoDelete() const - { return m_bNoDelete; } + bool hasNoDelete() const { return m_bNoDelete; } - bool hasNoDLOpen() const - { return m_bNoDLOpen; } + bool hasNoDLOpen() const { return m_bNoDLOpen; } - bool hasNoDump() const - { return m_bNoDump; } + bool hasNoDump() const { return m_bNoDump; } - bool hasRelro() const - { return m_bRelro; } + bool hasRelro() const { return m_bRelro; } - bool hasNow() const - { return m_bNow; } + bool hasNow() const { return m_bNow; } - bool hasOrigin() const - { return m_bOrigin; } + bool hasOrigin() const { return m_bOrigin; } - uint64_t commPageSize() const - { return m_CommPageSize; } + uint64_t commPageSize() const { return m_CommPageSize; } - uint64_t maxPageSize() const - { return m_MaxPageSize; } + uint64_t maxPageSize() const { return m_MaxPageSize; } - bool hasEhFrameHdr() const - { return m_bCreateEhFrameHdr; } + bool hasEhFrameHdr() const { return m_bCreateEhFrameHdr; } // -n, --nmagic - void setNMagic(bool pMagic = true) - { m_bNMagic = pMagic; } + void setNMagic(bool pMagic = true) { m_bNMagic = pMagic; } - bool nmagic() const - { return m_bNMagic; } + bool nmagic() const { return m_bNMagic; } // -N, --omagic - void setOMagic(bool pMagic = true) - { m_bOMagic = pMagic; } + void setOMagic(bool pMagic = true) { m_bOMagic = pMagic; } - bool omagic() const - { return m_bOMagic; } + bool omagic() const { return m_bOMagic; } // -S, --strip-debug - void setStripDebug(bool pStripDebug = true) - { m_bStripDebug = pStripDebug; } + void setStripDebug(bool pStripDebug = true) { m_bStripDebug = pStripDebug; } - bool stripDebug() const - { return m_bStripDebug; } + bool stripDebug() const { return m_bStripDebug; } // -E, --export-dynamic - void setExportDynamic(bool pExportDynamic = true) - { m_bExportDynamic = pExportDynamic; } + void setExportDynamic(bool pExportDynamic = true) { + m_bExportDynamic = pExportDynamic; + } - bool exportDynamic() const - { return m_bExportDynamic; } + bool exportDynamic() const { return m_bExportDynamic; } // --warn-shared-textrel - void setWarnSharedTextrel(bool pWarnSharedTextrel = true) - { m_bWarnSharedTextrel = pWarnSharedTextrel; } + void setWarnSharedTextrel(bool pWarnSharedTextrel = true) { + m_bWarnSharedTextrel = pWarnSharedTextrel; + } - bool warnSharedTextrel() const - { return m_bWarnSharedTextrel; } + bool warnSharedTextrel() const { return m_bWarnSharedTextrel; } - void setBinaryInput(bool pBinaryInput = true) - { m_bBinaryInput = pBinaryInput; } + void setBinaryInput(bool pBinaryInput = true) { + m_bBinaryInput = pBinaryInput; + } - bool isBinaryInput() const - { return m_bBinaryInput; } + bool isBinaryInput() const { return m_bBinaryInput; } - void setDefineCommon(bool pEnable = true) - { m_bDefineCommon = pEnable; } + void setDefineCommon(bool pEnable = true) { m_bDefineCommon = pEnable; } - bool isDefineCommon() const - { return m_bDefineCommon; } + bool isDefineCommon() const { return m_bDefineCommon; } - void setFatalWarnings(bool pEnable = true) - { m_bFatalWarnings = pEnable; } + void setFatalWarnings(bool pEnable = true) { m_bFatalWarnings = pEnable; } - bool isFatalWarnings() const - { return m_bFatalWarnings; } + bool isFatalWarnings() const { return m_bFatalWarnings; } - StripSymbolMode getStripSymbolMode() const - { return m_StripSymbols; } + StripSymbolMode getStripSymbolMode() const { return m_StripSymbols; } - void setStripSymbols(StripSymbolMode pMode) - { m_StripSymbols = pMode; } + void setStripSymbols(StripSymbolMode pMode) { m_StripSymbols = pMode; } - void setNewDTags(bool pEnable = true) - { m_bNewDTags = pEnable; } + void setNewDTags(bool pEnable = true) { m_bNewDTags = pEnable; } - bool hasNewDTags() const - { return m_bNewDTags; } + bool hasNewDTags() const { return m_bNewDTags; } - void setNoStdlib(bool pEnable = true) - { m_bNoStdlib = pEnable; } + void setNoStdlib(bool pEnable = true) { m_bNoStdlib = pEnable; } - bool nostdlib() const - { return m_bNoStdlib; } + bool nostdlib() const { return m_bNoStdlib; } // -M, --print-map - void setPrintMap(bool pEnable = true) - { m_bPrintMap = pEnable; } + void setPrintMap(bool pEnable = true) { m_bPrintMap = pEnable; } - bool printMap() const - { return m_bPrintMap; } + bool printMap() const { return m_bPrintMap; } - void setWarnMismatch(bool pEnable = true) - { m_bWarnMismatch = pEnable; } + void setWarnMismatch(bool pEnable = true) { m_bWarnMismatch = pEnable; } - bool warnMismatch() const - { return m_bWarnMismatch; } + bool warnMismatch() const { return m_bWarnMismatch; } // --gc-sections - void setGCSections(bool pEnable = true) - { m_bGCSections = pEnable; } + void setGCSections(bool pEnable = true) { m_bGCSections = pEnable; } - bool GCSections() const - { return m_bGCSections; } + bool GCSections() const { return m_bGCSections; } // --print-gc-sections - void setPrintGCSections(bool pEnable = true) - { m_bPrintGCSections = pEnable; } + void setPrintGCSections(bool pEnable = true) { m_bPrintGCSections = pEnable; } - bool getPrintGCSections() const - { return m_bPrintGCSections; } + bool getPrintGCSections() const { return m_bPrintGCSections; } // --ld-generated-unwind-info - void setGenUnwindInfo(bool pEnable = true) - { m_bGenUnwindInfo = pEnable; } + void setGenUnwindInfo(bool pEnable = true) { m_bGenUnwindInfo = pEnable; } - bool genUnwindInfo() const - { return m_bGenUnwindInfo; } + bool genUnwindInfo() const { return m_bGenUnwindInfo; } // -G, max GP size option - void setGPSize(int gpsize) - { m_GPSize = gpsize; } + void setGPSize(int gpsize) { m_GPSize = gpsize; } - int getGPSize() const - { return m_GPSize; } + int getGPSize() const { return m_GPSize; } unsigned int getHashStyle() const { return m_HashStyle; } - void setHashStyle(unsigned int pStyle) - { m_HashStyle = pStyle; } + void setHashStyle(unsigned int pStyle) { m_HashStyle = pStyle; } ICF getICFMode() const { return m_ICF; } - void setICFMode(ICF pMode) - { m_ICF = pMode; } + void setICFMode(ICF pMode) { m_ICF = pMode; } size_t getICFIterations() const { return m_ICFIterations; } - void setICFIterations(size_t pNum) - { m_ICFIterations = pNum; } + void setICFIterations(size_t pNum) { m_ICFIterations = pNum; } bool printICFSections() const { return m_bPrintICFSections; } - void setPrintICFSections(bool pPrintICFSections) - { m_bPrintICFSections = pPrintICFSections; } + void setPrintICFSections(bool pPrintICFSections) { + m_bPrintICFSections = pPrintICFSections; + } // ----- link-in rpath ----- // const RpathList& getRpathList() const { return m_RpathList; } - RpathList& getRpathList() { return m_RpathList; } + RpathList& getRpathList() { return m_RpathList; } const_rpath_iterator rpath_begin() const { return m_RpathList.begin(); } - rpath_iterator rpath_begin() { return m_RpathList.begin(); } - const_rpath_iterator rpath_end () const { return m_RpathList.end(); } - rpath_iterator rpath_end () { return m_RpathList.end(); } + rpath_iterator rpath_begin() { return m_RpathList.begin(); } + const_rpath_iterator rpath_end() const { return m_RpathList.end(); } + rpath_iterator rpath_end() { return m_RpathList.end(); } // ----- link-in script ----- // const ScriptList& getScriptList() const { return m_ScriptList; } - ScriptList& getScriptList() { return m_ScriptList; } + ScriptList& getScriptList() { return m_ScriptList; } const_script_iterator script_begin() const { return m_ScriptList.begin(); } - script_iterator script_begin() { return m_ScriptList.begin(); } - const_script_iterator script_end () const { return m_ScriptList.end(); } - script_iterator script_end () { return m_ScriptList.end(); } + script_iterator script_begin() { return m_ScriptList.begin(); } + const_script_iterator script_end() const { return m_ScriptList.end(); } + script_iterator script_end() { return m_ScriptList.end(); } // ----- -u/--undefined, undefined symbols ----- // const UndefSymList& getUndefSymList() const { return m_UndefSymList; } - UndefSymList& getUndefSymList() { return m_UndefSymList; } + UndefSymList& getUndefSymList() { return m_UndefSymList; } - const_undef_sym_iterator undef_sym_begin() const - { return m_UndefSymList.begin(); } - undef_sym_iterator undef_sym_begin() - { return m_UndefSymList.begin(); } + const_undef_sym_iterator undef_sym_begin() const { + return m_UndefSymList.begin(); + } + undef_sym_iterator undef_sym_begin() { return m_UndefSymList.begin(); } - const_undef_sym_iterator undef_sym_end() const - { return m_UndefSymList.end(); } - undef_sym_iterator undef_sym_end() - { return m_UndefSymList.end(); } + const_undef_sym_iterator undef_sym_end() const { + return m_UndefSymList.end(); + } + undef_sym_iterator undef_sym_end() { return m_UndefSymList.end(); } // ----- filter and auxiliary filter ----- // - void setFilter(const std::string& pFilter) - { m_Filter = pFilter; } + void setFilter(const std::string& pFilter) { m_Filter = pFilter; } - const std::string& filter() const - { return m_Filter; } + const std::string& filter() const { return m_Filter; } - bool hasFilter() const - { return !m_Filter.empty(); } + bool hasFilter() const { return !m_Filter.empty(); } const AuxiliaryList& getAuxiliaryList() const { return m_AuxiliaryList; } - AuxiliaryList& getAuxiliaryList() { return m_AuxiliaryList; } + AuxiliaryList& getAuxiliaryList() { return m_AuxiliaryList; } const_aux_iterator aux_begin() const { return m_AuxiliaryList.begin(); } - aux_iterator aux_begin() { return m_AuxiliaryList.begin(); } - const_aux_iterator aux_end () const { return m_AuxiliaryList.end(); } - aux_iterator aux_end () { return m_AuxiliaryList.end(); } + aux_iterator aux_begin() { return m_AuxiliaryList.begin(); } + const_aux_iterator aux_end() const { return m_AuxiliaryList.end(); } + aux_iterator aux_end() { return m_AuxiliaryList.end(); } // ----- exclude libs ----- // - ExcludeLIBS& excludeLIBS() - { return m_ExcludeLIBS; } + ExcludeLIBS& excludeLIBS() { return m_ExcludeLIBS; } bool isInExcludeLIBS(const Input& pInput) const; + const char* getVersionString() const { return PACKAGE_NAME " " MCLD_VERSION; } -private: - enum status { - YES, - NO, - Unknown - }; + private: + enum status { YES, NO, Unknown }; -private: + private: std::string m_DefaultLDScript; std::string m_Dyld; std::string m_SOName; - int8_t m_Verbose; // --verbose[=0,1,2] - uint16_t m_MaxErrorNum; // --error-limit=N - uint16_t m_MaxWarnNum; // --warning-limit=N - status m_ExecStack; // execstack, noexecstack - status m_NoUndefined; // defs, --no-undefined - status m_MulDefs; // muldefs, --allow-multiple-definition - uint64_t m_CommPageSize; // common-page-size=value - uint64_t m_MaxPageSize; // max-page-size=value - bool m_bCombReloc : 1; // combreloc, nocombreloc - bool m_bInitFirst : 1; // initfirst - bool m_bInterPose : 1; // interpose - bool m_bLoadFltr : 1; // loadfltr - bool m_bNoCopyReloc : 1; // nocopyreloc - bool m_bNoDefaultLib : 1; // nodefaultlib - bool m_bNoDelete : 1; // nodelete - bool m_bNoDLOpen : 1; // nodlopen - bool m_bNoDump : 1; // nodump - bool m_bRelro : 1; // relro, norelro - bool m_bNow : 1; // lazy, now - bool m_bOrigin : 1; // origin - bool m_bTrace : 1; // --trace - bool m_Bsymbolic : 1; // --Bsymbolic - bool m_Bgroup : 1; - bool m_bPIE : 1; - bool m_bColor : 1; // --color[=true,false,auto] - bool m_bCreateEhFrameHdr : 1; // --eh-frame-hdr - bool m_bNMagic : 1; // -n, --nmagic - bool m_bOMagic : 1; // -N, --omagic - bool m_bStripDebug : 1; // -S, --strip-debug - bool m_bExportDynamic :1; //-E, --export-dynamic - bool m_bWarnSharedTextrel : 1; // --warn-shared-textrel - bool m_bBinaryInput : 1; // -b [input-format], --format=[input-format] - bool m_bDefineCommon : 1; // -d, -dc, -dp - bool m_bFatalWarnings : 1; // --fatal-warnings - bool m_bNewDTags: 1; // --enable-new-dtags - bool m_bNoStdlib: 1; // -nostdlib - bool m_bPrintMap: 1; // --print-map - bool m_bWarnMismatch: 1; // --no-warn-mismatch - bool m_bGCSections: 1; // --gc-sections - bool m_bPrintGCSections:1; // --print-gc-sections - bool m_bGenUnwindInfo: 1; // --ld-generated-unwind-info - bool m_bPrintICFSections: 1; // --print-icf-sections + int8_t m_Verbose; // --verbose[=0,1,2] + uint16_t m_MaxErrorNum; // --error-limit=N + uint16_t m_MaxWarnNum; // --warning-limit=N + status m_ExecStack; // execstack, noexecstack + status m_NoUndefined; // defs, --no-undefined + status m_MulDefs; // muldefs, --allow-multiple-definition + uint64_t m_CommPageSize; // common-page-size=value + uint64_t m_MaxPageSize; // max-page-size=value + bool m_bCombReloc : 1; // combreloc, nocombreloc + bool m_bInitFirst : 1; // initfirst + bool m_bInterPose : 1; // interpose + bool m_bLoadFltr : 1; // loadfltr + bool m_bNoCopyReloc : 1; // nocopyreloc + bool m_bNoDefaultLib : 1; // nodefaultlib + bool m_bNoDelete : 1; // nodelete + bool m_bNoDLOpen : 1; // nodlopen + bool m_bNoDump : 1; // nodump + bool m_bRelro : 1; // relro, norelro + bool m_bNow : 1; // lazy, now + bool m_bOrigin : 1; // origin + bool m_bTrace : 1; // --trace + bool m_Bsymbolic : 1; // --Bsymbolic + bool m_Bgroup : 1; + bool m_bPIE : 1; + bool m_bColor : 1; // --color[=true,false,auto] + bool m_bCreateEhFrameHdr : 1; // --eh-frame-hdr + bool m_bNMagic : 1; // -n, --nmagic + bool m_bOMagic : 1; // -N, --omagic + bool m_bStripDebug : 1; // -S, --strip-debug + bool m_bExportDynamic : 1; // -E, --export-dynamic + bool m_bWarnSharedTextrel : 1; // --warn-shared-textrel + bool m_bBinaryInput : 1; // -b [input-format], --format=[input-format] + bool m_bDefineCommon : 1; // -d, -dc, -dp + bool m_bFatalWarnings : 1; // --fatal-warnings + bool m_bNewDTags : 1; // --enable-new-dtags + bool m_bNoStdlib : 1; // -nostdlib + bool m_bPrintMap : 1; // --print-map + bool m_bWarnMismatch : 1; // --no-warn-mismatch + bool m_bGCSections : 1; // --gc-sections + bool m_bPrintGCSections : 1; // --print-gc-sections + bool m_bGenUnwindInfo : 1; // --ld-generated-unwind-info + bool m_bPrintICFSections : 1; // --print-icf-sections ICF m_ICF; size_t m_ICFIterations; - uint32_t m_GPSize; // -G, --gpsize + uint32_t m_GPSize; // -G, --gpsize StripSymbolMode m_StripSymbols; RpathList m_RpathList; ScriptList m_ScriptList; - UndefSymList m_UndefSymList; // -u [symbol], --undefined [symbol] + UndefSymList m_UndefSymList; // -u [symbol], --undefined [symbol] unsigned int m_HashStyle; std::string m_Filter; AuxiliaryList m_AuxiliaryList; ExcludeLIBS m_ExcludeLIBS; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_GENERALOPTIONS_H_
diff --git a/include/mcld/IRBuilder.h b/include/mcld/IRBuilder.h index 7cacb36..b68b8fa 100644 --- a/include/mcld/IRBuilder.h +++ b/include/mcld/IRBuilder.h
@@ -11,30 +11,27 @@ // with a consistent and simplified interface. // //===----------------------------------------------------------------------===// -#ifndef MCLD_IRBUILDER_H -#define MCLD_IRBUILDER_H +#ifndef MCLD_IRBUILDER_H_ +#define MCLD_IRBUILDER_H_ -#include <mcld/MC/Input.h> -#include <mcld/MC/InputBuilder.h> - -#include <mcld/LD/LDSection.h> -#include <mcld/LD/EhFrame.h> -#include <mcld/LD/LDSymbol.h> - -#include <mcld/Fragment/Fragment.h> -#include <mcld/Fragment/Relocation.h> -#include <mcld/Fragment/RegionFragment.h> -#include <mcld/Fragment/FillFragment.h> -#include <mcld/Fragment/FragmentRef.h> - -#include <mcld/Support/Path.h> -#include <mcld/Support/FileHandle.h> +#include "mcld/Fragment/FillFragment.h" +#include "mcld/Fragment/Fragment.h" +#include "mcld/Fragment/FragmentRef.h" +#include "mcld/Fragment/RegionFragment.h" +#include "mcld/Fragment/Relocation.h" +#include "mcld/LD/EhFrame.h" +#include "mcld/LD/LDSection.h" +#include "mcld/LD/LDSymbol.h" +#include "mcld/MC/Input.h" +#include "mcld/MC/InputBuilder.h" +#include "mcld/Support/FileHandle.h" +#include "mcld/Support/Path.h" namespace mcld { -class Module; -class LinkerConfig; class InputTree; +class LinkerConfig; +class Module; /** \class IRBuilder * \brief IRBuilder provides an uniform API for creating sections and @@ -44,38 +41,27 @@ * language into a system-dependent binary. IRBuilder helps such kind of VMs * to emit binaries in native object format, such as ELF or MachO. */ -class IRBuilder -{ -public: - enum ObjectFormat { - ELF, - MachO, - COFF - }; +class IRBuilder { + public: + enum ObjectFormat { ELF, MachO, COFF }; - enum SymbolDefinePolicy { - Force, - AsReferred - }; + enum SymbolDefinePolicy { Force, AsReferred }; - enum SymbolResolvePolicy { - Unresolve, - Resolve - }; + enum SymbolResolvePolicy { Unresolve, Resolve }; -public: + public: IRBuilder(Module& pModule, const LinkerConfig& pConfig); ~IRBuilder(); const InputBuilder& getInputBuilder() const { return m_InputBuilder; } - InputBuilder& getInputBuilder() { return m_InputBuilder; } + InputBuilder& getInputBuilder() { return m_InputBuilder; } const Module& getModule() const { return m_Module; } - Module& getModule() { return m_Module; } + Module& getModule() { return m_Module; } -/// @} -/// @name Input Files On The Command Line -/// @{ + /// @} + /// @name Input Files On The Command Line + /// @{ /// CreateInput - To create an input file and append it to the input tree. /// This function is like to add an input file in the command line. @@ -159,9 +145,9 @@ /// MCLinker to stop adding following archives in the created group. bool EndGroup(); -/// @} -/// @name Positional Options On The Command Line -/// @{ + /// @} + /// @name Positional Options On The Command Line + /// @{ /// WholeArchive - Append a --whole-archive option on the command line /// @@ -217,9 +203,9 @@ /// search archives before shared objects for the following namespec. void AgainstStatic(); -/// @} -/// @name Input Methods -/// @{ + /// @} + /// @name Input Methods + /// @{ /// CreateELFHeader - To create and append a section header in the input file /// @@ -255,7 +241,7 @@ /// @return The created relocation data. If the pSection already has /// relocation data, or if the pSection's type is not /// LDFileFormat::Relocation, then an assertion occurs. - static RelocData* CreateRelocData(LDSection &pSection); + static RelocData* CreateRelocData(LDSection& pSection); /// CreateEhFrame - To create a eh_frame for given pSection /// @param [in, out] pSection The given LDSection. It can be in either an @@ -266,6 +252,13 @@ /// assertion occurs. static EhFrame* CreateEhFrame(LDSection& pSection); + /// CreateDebugString - To create a debug_str for given pSection + /// @param pSection The given LDSection. It should be the output + /// .debug_str section + /// pSection.getDebugString() is set to a valid eh_frame. + /// @return The created DebugString + static DebugString* CreateDebugString(LDSection& pSection); + /// CreateBSS - To create a bss section for given pSection /// @param [in, out] pSection The given LDSection. It can be in either an /// input or the output. @@ -432,19 +425,21 @@ /// { Global, Weak, Local, Absolute } /// /// @return The symbol kept in mcld::Module. - template<SymbolDefinePolicy POLICY, SymbolResolvePolicy RESOLVE> - LDSymbol* AddSymbol(const llvm::StringRef& pName, - ResolveInfo::Type pType, - ResolveInfo::Desc pDesc, - ResolveInfo::Binding pBinding, - ResolveInfo::SizeType pSize = 0, - LDSymbol::ValueType pValue = 0x0, - FragmentRef* pFragmentRef = FragmentRef::Null(), - ResolveInfo::Visibility pVisibility = ResolveInfo::Default); + template <SymbolDefinePolicy POLICY, SymbolResolvePolicy RESOLVE> + LDSymbol* AddSymbol( + const llvm::StringRef& pName, + ResolveInfo::Type pType, + ResolveInfo::Desc pDesc, + ResolveInfo::Binding pBinding, + ResolveInfo::SizeType pSize = 0, + LDSymbol::ValueType pValue = 0x0, + FragmentRef * pFragmentRef = FragmentRef::Null(), + ResolveInfo::Visibility pVisibility = ResolveInfo::Default); /// AddRelocation - To add a relocation entry /// - /// @param [in] pSection The relocation section. pSection's link should point to + /// @param [in] pSection The relocation section. pSection's link should point + /// to /// the target section. /// @param [in] pType The type of the relocation (target dependent) /// @param [in] pSym The symbol should be the symbol in the input file. @@ -460,7 +455,7 @@ /// symbols should be force to local symbols bool shouldForceLocal(const ResolveInfo& pInfo, const LinkerConfig& pConfig); -private: + private: LDSymbol* addSymbolFromObject(const std::string& pName, ResolveInfo::Type pType, ResolveInfo::Desc pDesc, @@ -479,57 +474,57 @@ LDSymbol::ValueType pValue, ResolveInfo::Visibility pVisibility); -private: + private: Module& m_Module; const LinkerConfig& m_Config; InputBuilder m_InputBuilder; }; -template<> LDSymbol* -IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>( - const llvm::StringRef& pName, - ResolveInfo::Type pType, - ResolveInfo::Desc pDesc, - ResolveInfo::Binding pBinding, - ResolveInfo::SizeType pSize, - LDSymbol::ValueType pValue, - FragmentRef* pFragmentRef, - ResolveInfo::Visibility pVisibility); +template <> +LDSymbol* IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>( + const llvm::StringRef& pName, + ResolveInfo::Type pType, + ResolveInfo::Desc pDesc, + ResolveInfo::Binding pBinding, + ResolveInfo::SizeType pSize, + LDSymbol::ValueType pValue, + FragmentRef* pFragmentRef, + ResolveInfo::Visibility pVisibility); -template<> LDSymbol* -IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>( - const llvm::StringRef& pName, - ResolveInfo::Type pType, - ResolveInfo::Desc pDesc, - ResolveInfo::Binding pBinding, - ResolveInfo::SizeType pSize, - LDSymbol::ValueType pValue, - FragmentRef* pFragmentRef, - ResolveInfo::Visibility pVisibility); +template <> +LDSymbol* IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>( + const llvm::StringRef& pName, + ResolveInfo::Type pType, + ResolveInfo::Desc pDesc, + ResolveInfo::Binding pBinding, + ResolveInfo::SizeType pSize, + LDSymbol::ValueType pValue, + FragmentRef* pFragmentRef, + ResolveInfo::Visibility pVisibility); -template<> LDSymbol* -IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Resolve>( - const llvm::StringRef& pName, - ResolveInfo::Type pType, - ResolveInfo::Desc pDesc, - ResolveInfo::Binding pBinding, - ResolveInfo::SizeType pSize, - LDSymbol::ValueType pValue, - FragmentRef* pFragmentRef, - ResolveInfo::Visibility pVisibility); +template <> +LDSymbol* IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Resolve>( + const llvm::StringRef& pName, + ResolveInfo::Type pType, + ResolveInfo::Desc pDesc, + ResolveInfo::Binding pBinding, + ResolveInfo::SizeType pSize, + LDSymbol::ValueType pValue, + FragmentRef* pFragmentRef, + ResolveInfo::Visibility pVisibility); -template<> LDSymbol* -IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>( - const llvm::StringRef& pName, - ResolveInfo::Type pType, - ResolveInfo::Desc pDesc, - ResolveInfo::Binding pBinding, - ResolveInfo::SizeType pSize, - LDSymbol::ValueType pValue, - FragmentRef* pFragmentRef, - ResolveInfo::Visibility pVisibility); +template <> +LDSymbol* IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>( + const llvm::StringRef& pName, + ResolveInfo::Type pType, + ResolveInfo::Desc pDesc, + ResolveInfo::Binding pBinding, + ResolveInfo::SizeType pSize, + LDSymbol::ValueType pValue, + FragmentRef* pFragmentRef, + ResolveInfo::Visibility pVisibility); -} // end of namespace mcld +} // end of namespace mcld -#endif +#endif // MCLD_IRBUILDER_H_
diff --git a/include/mcld/InputTree.h b/include/mcld/InputTree.h index 687c805..88ad34a 100644 --- a/include/mcld/InputTree.h +++ b/include/mcld/InputTree.h
@@ -6,45 +6,43 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_INPUTTREE_H -#define MCLD_INPUTTREE_H +#ifndef MCLD_INPUTTREE_H_ +#define MCLD_INPUTTREE_H_ -#include <mcld/ADT/BinTree.h> -#include <mcld/ADT/TypeTraits.h> -#include <mcld/MC/Input.h> -#include <mcld/Support/Path.h> +#include "mcld/ADT/BinTree.h" +#include "mcld/ADT/TypeTraits.h" +#include "mcld/MC/Input.h" +#include "mcld/Support/Path.h" #include <string> - namespace mcld { -/** \class template<typename Traits, typename Iterator> PolicyIterator<mcld::Input> +/** \class template<typename Traits, typename Iterator> + * PolicyIterator<mcld::Input> * \brief PolicyIterator<mcld::Input> is a partially specific PolicyIterator */ -template<typename Traits, typename IteratorType> -class PolicyIterator<mcld::Input, Traits, IteratorType> : public PolicyIteratorBase<Input, Traits, IteratorType> -{ -public: +template <typename Traits, typename IteratorType> +class PolicyIterator<mcld::Input, Traits, IteratorType> + : public PolicyIteratorBase<Input, Traits, IteratorType> { + public: typedef PolicyIterator<Input, Traits, IteratorType> Self; typedef PolicyIteratorBase<Input, Traits, IteratorType> Base; - typedef PolicyIterator<Input, typename Traits::nonconst_traits, IteratorType> iterator; - typedef PolicyIterator<Input, typename Traits::const_traits, IteratorType> const_iterator; + typedef PolicyIterator<Input, typename Traits::nonconst_traits, IteratorType> + iterator; + typedef PolicyIterator<Input, typename Traits::const_traits, IteratorType> + const_iterator; -public: - PolicyIterator() - : Base() {} + public: + PolicyIterator() : Base() {} - PolicyIterator(const iterator &X) - : Base(X.m_pNode) {} + PolicyIterator(const iterator& X) : Base(X.m_pNode) {} - explicit PolicyIterator(NodeBase* X) - : Base(X) {} + explicit PolicyIterator(NodeBase* X) : Base(X) {} virtual ~PolicyIterator() {} - bool isGroup() const - { return !Base::hasData() && !Base::isRoot(); } + bool isGroup() const { return !Base::hasData() && !Base::isRoot(); } Self& operator++() { IteratorType::advance(); @@ -64,114 +62,109 @@ } }; -template<> -class BinaryTree<Input> : public BinaryTreeBase<Input> -{ -public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef Input value_type; - typedef value_type* pointer; - typedef value_type& reference; - typedef const value_type* const_pointer; - typedef const value_type& const_reference; +template <> +class BinaryTree<Input> : public BinaryTreeBase<Input> { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef Input value_type; + typedef value_type* pointer; + typedef value_type& reference; + typedef const value_type* const_pointer; + typedef const value_type& const_reference; - typedef BinaryTree<Input> Self; + typedef BinaryTree<Input> Self; typedef TreeIterator<value_type, NonConstTraits<value_type> > iterator; - typedef TreeIterator<value_type, ConstTraits<value_type> > const_iterator; + typedef TreeIterator<value_type, ConstTraits<value_type> > const_iterator; - typedef PolicyIterator<value_type, NonConstTraits<value_type>, DFSIterator> dfs_iterator; - typedef PolicyIterator<value_type, ConstTraits<value_type>, DFSIterator> const_dfs_iterator; - typedef PolicyIterator<value_type, NonConstTraits<value_type>, BFSIterator> bfs_iterator; - typedef PolicyIterator<value_type, ConstTraits<value_type>, BFSIterator> const_bfs_iterator; + typedef PolicyIterator<value_type, NonConstTraits<value_type>, DFSIterator> + dfs_iterator; + typedef PolicyIterator<value_type, ConstTraits<value_type>, DFSIterator> + const_dfs_iterator; + typedef PolicyIterator<value_type, NonConstTraits<value_type>, BFSIterator> + bfs_iterator; + typedef PolicyIterator<value_type, ConstTraits<value_type>, BFSIterator> + const_bfs_iterator; -protected: + protected: typedef Node<value_type> node_type; -public: + public: // ----- constructors and destructor ----- // - BinaryTree() - : BinaryTreeBase<Input>() - { } + BinaryTree() : BinaryTreeBase<Input>() {} - ~BinaryTree() { - } + ~BinaryTree() {} // ----- iterators ----- // - bfs_iterator bfs_begin() - { - bfs_iterator it = bfs_iterator(BinaryTreeBase<Input>::m_Root.node.left); - if (it.isGroup()) - ++it; - return it; + bfs_iterator bfs_begin() { + bfs_iterator it = bfs_iterator(BinaryTreeBase<Input>::m_Root.node.left); + if (it.isGroup()) + ++it; + return it; } - bfs_iterator bfs_end() - { return bfs_iterator(BinaryTreeBase<Input>::m_Root.node.right); } - - const_bfs_iterator bfs_begin() const - { - const_bfs_iterator it = - const_bfs_iterator(BinaryTreeBase<Input>::m_Root.node.left); - if (it.isGroup()) - ++it; - return it; + bfs_iterator bfs_end() { + return bfs_iterator(BinaryTreeBase<Input>::m_Root.node.right); } - const_bfs_iterator bfs_end() const - { return const_bfs_iterator(BinaryTreeBase<Input>::m_Root.node.right); } + const_bfs_iterator bfs_begin() const { + const_bfs_iterator it = + const_bfs_iterator(BinaryTreeBase<Input>::m_Root.node.left); + if (it.isGroup()) + ++it; + return it; + } - dfs_iterator dfs_begin() - { + const_bfs_iterator bfs_end() const { + return const_bfs_iterator(BinaryTreeBase<Input>::m_Root.node.right); + } + + dfs_iterator dfs_begin() { dfs_iterator it = dfs_iterator(BinaryTreeBase<Input>::m_Root.node.left); if (it.isGroup()) ++it; return it; } - dfs_iterator dfs_end() - { return dfs_iterator(BinaryTreeBase<Input>::m_Root.node.right); } + dfs_iterator dfs_end() { + return dfs_iterator(BinaryTreeBase<Input>::m_Root.node.right); + } - const_dfs_iterator dfs_begin() const - { + const_dfs_iterator dfs_begin() const { const_dfs_iterator it = - const_dfs_iterator(BinaryTreeBase<Input>::m_Root.node.left); + const_dfs_iterator(BinaryTreeBase<Input>::m_Root.node.left); if (it.isGroup()) ++it; return it; } - const_dfs_iterator dfs_end() const - { return const_dfs_iterator(BinaryTreeBase<Input>::m_Root.node.right); } + const_dfs_iterator dfs_end() const { + return const_dfs_iterator(BinaryTreeBase<Input>::m_Root.node.right); + } - iterator root() - { return iterator(&(BinaryTreeBase<Input>::m_Root.node)); } + iterator root() { return iterator(&(BinaryTreeBase<Input>::m_Root.node)); } - const_iterator root() const - { + const_iterator root() const { // FIXME: provide the iterater constructors for constant NodeBase instead of // using const_cast return const_iterator( - const_cast<NodeBase*>(&BinaryTreeBase<Input>::m_Root.node)); + const_cast<NodeBase*>(&BinaryTreeBase<Input>::m_Root.node)); } - iterator begin() - { + iterator begin() { iterator it = iterator(BinaryTreeBase<Input>::m_Root.node.left); return it; } - iterator end() - { return iterator(BinaryTreeBase<Input>::m_Root.node.right); } + iterator end() { return iterator(BinaryTreeBase<Input>::m_Root.node.right); } - const_iterator begin() const - { - const_iterator it = const_iterator(BinaryTreeBase<Input>::m_Root.node.left); - return it; + const_iterator begin() const { + return const_iterator(BinaryTreeBase<Input>::m_Root.node.left); } - const_iterator end() const - { return const_iterator(BinaryTreeBase<Input>::m_Root.node.right); } + const_iterator end() const { + return const_iterator(BinaryTreeBase<Input>::m_Root.node.right); + } // ----- modifiers ----- // /// join - create a leaf node and merge it in the tree. @@ -179,9 +172,9 @@ // @param DIRECT the direction of the connecting edge of the parent node. // @param position the parent node // @param value the value being pushed. - template<size_t DIRECT> + template <size_t DIRECT> BinaryTree& join(TreeIteratorBase& pPosition, const Input& value) { - node_type *node = BinaryTreeBase<Input>::createNode(); + node_type* node = BinaryTreeBase<Input>::createNode(); node->data = const_cast<Input*>(&value); if (pPosition.isRoot()) @@ -197,15 +190,14 @@ // @param position the parent node // @param the tree being joined. // @return the joined tree - template<size_t DIRECT> + template <size_t DIRECT> BinaryTree& merge(TreeIteratorBase& pPosition, BinaryTree& pTree) { if (this == &pTree) return *this; if (!pTree.empty()) { pPosition.hook<DIRECT>(pTree.m_Root.node.left); - BinaryTreeBase<Input>::m_Root.summon( - pTree.BinaryTreeBase<Input>::m_Root); + BinaryTreeBase<Input>::m_Root.summon(pTree.BinaryTreeBase<Input>::m_Root); BinaryTreeBase<Input>::m_Root.delegate(pTree.m_Root); pTree.m_Root.node.left = pTree.m_Root.node.right = &pTree.m_Root.node; } @@ -221,21 +213,20 @@ * * @see Input */ -class InputTree : public BinaryTree<Input> -{ -private: +class InputTree : public BinaryTree<Input> { + private: typedef BinaryTree<Input> BinTreeTy; -public: + public: enum Direction { - Inclusive = TreeIteratorBase::Leftward, + Inclusive = TreeIteratorBase::Leftward, Positional = TreeIteratorBase::Rightward }; - typedef BinaryTree<Input>::iterator iterator; + typedef BinaryTree<Input>::iterator iterator; typedef BinaryTree<Input>::const_iterator const_iterator; -public: + public: /** \class Mover * \brief Mover provides the interface for moving iterator forward. * @@ -246,7 +237,7 @@ struct Mover { virtual void connect(TreeIteratorBase& pFrom, NodeBase* pTo) const = 0; virtual void move(TreeIteratorBase& pNode) const = 0; - virtual ~Mover() { } + virtual ~Mover() {} }; /** \class Succeeder @@ -257,9 +248,7 @@ pFrom.hook<Positional>(pTo); } - void move(TreeIteratorBase& pNode) const { - pNode.move<Positional>(); - } + void move(TreeIteratorBase& pNode) const { pNode.move<Positional>(); } }; /** \class Includer @@ -270,38 +259,30 @@ pFrom.hook<Inclusive>(pTo); } - void move(TreeIteratorBase& pNode) const { - pNode.move<Inclusive>(); - } + void move(TreeIteratorBase& pNode) const { pNode.move<Inclusive>(); } }; -public: + public: static Succeeder Afterward; - static Includer Downward; + static Includer Downward; -public: - + public: using BinTreeTy::merge; // ----- modify ----- // - template<size_t DIRECT> + template <size_t DIRECT> InputTree& enterGroup(TreeIteratorBase pRoot); - template<size_t DIRECT> - InputTree& insert(TreeIteratorBase pRoot, - Input& pInput); + template <size_t DIRECT> + InputTree& insert(TreeIteratorBase pRoot, Input& pInput); InputTree& merge(TreeIteratorBase pRoot, const Mover& pMover, InputTree& pTree); - InputTree& insert(TreeIteratorBase pRoot, - const Mover& pMover, - Input& pInput); + InputTree& insert(TreeIteratorBase pRoot, const Mover& pMover, Input& pInput); - InputTree& enterGroup(TreeIteratorBase pRoot, - const Mover& pMover); - + InputTree& enterGroup(TreeIteratorBase pRoot, const Mover& pMover); }; bool isGroup(const InputTree::iterator& pos); @@ -311,15 +292,13 @@ bool isGroup(const InputTree::bfs_iterator& pos); bool isGroup(const InputTree::const_bfs_iterator& pos); -} // namespace of mcld +} // namespace mcld //===----------------------------------------------------------------------===// // template member functions //===----------------------------------------------------------------------===// -template<size_t DIRECT> -mcld::InputTree& -mcld::InputTree::enterGroup(mcld::TreeIteratorBase pRoot) -{ +template <size_t DIRECT> +mcld::InputTree& mcld::InputTree::enterGroup(mcld::TreeIteratorBase pRoot) { BinTreeTy::node_type* node = createNode(); if (pRoot.isRoot()) @@ -330,10 +309,9 @@ return *this; } -template<size_t DIRECT> +template <size_t DIRECT> mcld::InputTree& mcld::InputTree::insert(mcld::TreeIteratorBase pRoot, - mcld::Input& pInput) -{ + mcld::Input& pInput) { BinTreeTy::node_type* node = createNode(); node->data = &pInput; @@ -345,5 +323,4 @@ return *this; } -#endif - +#endif // MCLD_INPUTTREE_H_
diff --git a/include/mcld/LD/Archive.h b/include/mcld/LD/Archive.h index 34fc9cf..db333cb 100644 --- a/include/mcld/LD/Archive.h +++ b/include/mcld/LD/Archive.h
@@ -6,41 +6,39 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_ARCHIVE_H -#define MCLD_LD_ARCHIVE_H +#ifndef MCLD_LD_ARCHIVE_H_ +#define MCLD_LD_ARCHIVE_H_ -#include <mcld/InputTree.h> -#include <mcld/ADT/HashEntry.h> -#include <mcld/ADT/HashTable.h> -#include <mcld/ADT/StringHash.h> -#include <mcld/Support/GCFactory.h> +#include "mcld/InputTree.h" +#include "mcld/ADT/HashEntry.h" +#include "mcld/ADT/HashTable.h" +#include "mcld/ADT/StringHash.h" +#include "mcld/Support/GCFactory.h" -#include <vector> #include <string> +#include <vector> namespace mcld { class Input; -class InputFactory; class InputBuilder; +class InputFactory; /** \class Archive * \brief This class define the interfacee to Archive files */ -class Archive -{ -public: - static const char MAGIC[]; ///< magic string - static const char THIN_MAGIC[]; ///< magic of thin archive - static const size_t MAGIC_LEN; ///< length of magic string - static const char SVR4_SYMTAB_NAME[]; ///< SVR4 symtab entry name - static const char IRIX6_SYMTAB_NAME[]; ///< Irix6 symtab entry name - static const char STRTAB_NAME[]; ///< Name of string table - static const char PAD[]; ///< inter-file align padding - static const char MEMBER_MAGIC[]; ///< fmag field magic # +class Archive { + public: + static const char MAGIC[]; ///< magic string + static const char THIN_MAGIC[]; ///< magic of thin archive + static const size_t MAGIC_LEN; ///< length of magic string + static const char SVR4_SYMTAB_NAME[]; ///< SVR4 symtab entry name + static const char IRIX6_SYMTAB_NAME[]; ///< Irix6 symtab entry name + static const char STRTAB_NAME[]; ///< Name of string table + static const char PAD[]; ///< inter-file align padding + static const char MEMBER_MAGIC[]; ///< fmag field magic # - struct MemberHeader - { + struct MemberHeader { char name[16]; ///< Name of the file member. char date[12]; ///< File date, decimal seconds since Epoch char uid[6]; ///< user id in ASCII decimal @@ -50,18 +48,14 @@ char fmag[2]; ///< Always contains ARFILE_MAGIC_TERMINATOR }; -private: - template<typename OFFSET_TYPE> - struct OffsetCompare - { - bool operator()(OFFSET_TYPE X, OFFSET_TYPE Y) const - { return (X == Y); } + private: + template <typename OFFSET_TYPE> + struct OffsetCompare { + bool operator()(OFFSET_TYPE X, OFFSET_TYPE Y) const { return (X == Y); } }; - struct MurmurHash3 - { - size_t operator()(uint32_t pKey) const - { + struct MurmurHash3 { + size_t operator()(uint32_t pKey) const { pKey ^= pKey >> 16; pKey *= 0x85ebca6b; pKey ^= pKey >> 13; @@ -71,51 +65,41 @@ } }; - typedef HashEntry<uint32_t, - InputTree::iterator, - OffsetCompare<uint32_t> > ObjectMemberEntryType; -public: + typedef HashEntry<uint32_t, InputTree::iterator, OffsetCompare<uint32_t> > + ObjectMemberEntryType; + + public: typedef HashTable<ObjectMemberEntryType, MurmurHash3, EntryFactory<ObjectMemberEntryType> > ObjectMemberMapType; - struct ArchiveMember - { + struct ArchiveMember { Input* file; InputTree::iterator lastPos; InputTree::Mover* move; }; -private: + private: typedef HashEntry<const llvm::StringRef, ArchiveMember, - hash::StringCompare<llvm::StringRef> > ArchiveMemberEntryType; + hash::StringCompare<llvm::StringRef> > + ArchiveMemberEntryType; -public: + public: typedef HashTable<ArchiveMemberEntryType, hash::StringHash<hash::DJB>, EntryFactory<ArchiveMemberEntryType> > ArchiveMemberMapType; - struct Symbol - { - public: - enum Status - { - Include, - Exclude, - Unknown - }; + struct Symbol { + public: + enum Status { Include, Exclude, Unknown }; - Symbol(const char* pName, - uint32_t pOffset, - enum Status pStatus) - : name(pName), fileOffset(pOffset), status(pStatus) - {} + Symbol(const char* pName, uint32_t pOffset, enum Status pStatus) + : name(pName), fileOffset(pOffset), status(pStatus) {} - ~Symbol() - {} + ~Symbol() {} - public: + public: std::string name; uint32_t fileOffset; enum Status status; @@ -123,7 +107,7 @@ typedef std::vector<Symbol*> SymTabType; -public: + public: Archive(Input& pInputFile, InputBuilder& pBuilder); ~Archive(); @@ -198,10 +182,9 @@ /// addSymbol - add a symtab entry to symtab /// @param pName - symbol name /// @param pFileOffset - file offset in symtab represents a object file - void - addSymbol(const char* pName, - uint32_t pFileOffset, - enum Symbol::Status pStatus = Archive::Symbol::Unknown); + void addSymbol(const char* pName, + uint32_t pFileOffset, + enum Symbol::Status pStatus = Archive::Symbol::Unknown); /// getSymbolName - get the symbol name with the given index const std::string& getSymbolName(size_t pSymIdx) const; @@ -236,12 +219,12 @@ const sys::fs::Path& pPath, off_t pFileOffset = 0); -private: + private: typedef GCFactory<Symbol, 0> SymbolFactory; -private: + private: Input& m_ArchiveFile; - InputTree *m_pInputTree; + InputTree* m_pInputTree; ObjectMemberMapType m_ObjectMemberMap; ArchiveMemberMapType m_ArchiveMemberMap; SymbolFactory m_SymbolFactory; @@ -251,7 +234,6 @@ InputBuilder& m_Builder; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ARCHIVE_H_
diff --git a/include/mcld/LD/ArchiveReader.h b/include/mcld/LD/ArchiveReader.h index 6f2ce12..6e15872 100644 --- a/include/mcld/LD/ArchiveReader.h +++ b/include/mcld/LD/ArchiveReader.h
@@ -6,15 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_ARCHIVEREADER_H -#define MCLD_LD_ARCHIVEREADER_H -#include <mcld/LD/LDReader.h> +#ifndef MCLD_LD_ARCHIVEREADER_H_ +#define MCLD_LD_ARCHIVEREADER_H_ +#include "mcld/LD/LDReader.h" -namespace mcld -{ +namespace mcld { -class LinkerConfig; class Archive; +class LinkerConfig; /** \class ArchiveReader * \brief ArchiveReader provides an common interface for all archive readers. @@ -26,16 +25,14 @@ * 3. All archive headers are the same size. */ -class ArchiveReader : public LDReader -{ -public: +class ArchiveReader : public LDReader { + public: ArchiveReader(); virtual ~ArchiveReader(); virtual bool readArchive(const LinkerConfig& pConfig, Archive& pArchive) = 0; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ARCHIVEREADER_H_
diff --git a/include/mcld/LD/BSDArchiveReader.h b/include/mcld/LD/BSDArchiveReader.h index 8ba12cf..3b28bde 100644 --- a/include/mcld/LD/BSDArchiveReader.h +++ b/include/mcld/LD/BSDArchiveReader.h
@@ -6,32 +6,29 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_BSDARCHIVEREADER_H -#define MCLD_LD_BSDARCHIVEREADER_H -#include <mcld/LD/ArchiveReader.h> +#ifndef MCLD_LD_BSDARCHIVEREADER_H_ +#define MCLD_LD_BSDARCHIVEREADER_H_ +#include "mcld/LD/ArchiveReader.h" -namespace mcld -{ +namespace mcld { -class Input; class Archive; +class Input; class LinkerConfig; /** \class BSDArchiveReader * \brief BSDArchiveReader reads BSD-variant archive files. * */ -class BSDArchiveReader : public ArchiveReader -{ -public: +class BSDArchiveReader : public ArchiveReader { + public: BSDArchiveReader(); ~BSDArchiveReader(); bool readArchive(const LinkerConfig& pConfig, Archive& pArchive); - bool isMyFormat(Input& pInput, bool &pContinue) const; + bool isMyFormat(Input& pInput, bool& pContinue) const; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_BSDARCHIVEREADER_H_
diff --git a/include/mcld/LD/BinaryReader.h b/include/mcld/LD/BinaryReader.h index 26dab6f..09e5b27 100644 --- a/include/mcld/LD/BinaryReader.h +++ b/include/mcld/LD/BinaryReader.h
@@ -6,31 +6,30 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_BINARYREADER_H -#define MCLD_LD_BINARYREADER_H +#ifndef MCLD_LD_BINARYREADER_H_ +#define MCLD_LD_BINARYREADER_H_ #include "mcld/LD/LDReader.h" namespace mcld { -class Module; class Input; /** \class BinaryReader * \brief BinaryReader provides an common interface for different Binary * formats. */ -class BinaryReader : public LDReader -{ -public: +class BinaryReader : public LDReader { + public: virtual ~BinaryReader() = 0; - virtual bool isMyFormat(Input& pInput, bool &pContinue) const - { pContinue = true; return false; } + virtual bool isMyFormat(Input& pInput, bool& pContinue) const { + pContinue = true; + return false; + } virtual bool readBinary(Input& pFile) = 0; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_BINARYREADER_H_
diff --git a/include/mcld/LD/BranchIsland.h b/include/mcld/LD/BranchIsland.h index 8733ddb..c57e5fb 100644 --- a/include/mcld/LD/BranchIsland.h +++ b/include/mcld/LD/BranchIsland.h
@@ -6,32 +6,33 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_BRANCHISLAND_H -#define MCLD_LD_BRANCHISLAND_H +#ifndef MCLD_LD_BRANCHISLAND_H_ +#define MCLD_LD_BRANCHISLAND_H_ -#include <mcld/ADT/HashEntry.h> -#include <mcld/ADT/HashTable.h> -#include <mcld/ADT/StringHash.h> -#include <mcld/LD/SectionData.h> -#include <mcld/LD/LDSymbol.h> -#include <mcld/Fragment/FragmentRef.h> -#include <mcld/Fragment/Stub.h> +#include "mcld/ADT/HashEntry.h" +#include "mcld/ADT/HashTable.h" +#include "mcld/ADT/StringHash.h" +#include "mcld/LD/SectionData.h" +#include "mcld/Fragment/FragmentRef.h" +#include "mcld/Fragment/Stub.h" +#include "mcld/LD/LDSymbol.h" + #include <llvm/Support/DataTypes.h> #include <llvm/ADT/StringRef.h> + #include <string> namespace mcld { -class Stub; class Relocation; +class Stub; /** \class BranchIsland * \brief BranchIsland is a collection of stubs * */ -class BranchIsland -{ -public: +class BranchIsland { + public: typedef SectionData::iterator iterator; typedef SectionData::const_iterator const_iterator; @@ -39,7 +40,7 @@ typedef RelocationListType::iterator reloc_iterator; typedef RelocationListType::const_iterator const_reloc_iterator; -public: + public: /* * ---------- * --- Entry -> | Island | -> Exit --- @@ -64,17 +65,13 @@ const_iterator end() const; /// relocation iterators of the island - reloc_iterator reloc_begin() - { return m_Relocations.begin(); } + reloc_iterator reloc_begin() { return m_Relocations.begin(); } - const_reloc_iterator reloc_begin() const - { return m_Relocations.begin(); } + const_reloc_iterator reloc_begin() const { return m_Relocations.begin(); } - reloc_iterator reloc_end() - { return m_Relocations.end(); } + reloc_iterator reloc_end() { return m_Relocations.end(); } - const_reloc_iterator reloc_end() const - { return m_Relocations.end(); } + const_reloc_iterator reloc_end() const { return m_Relocations.end(); } /// observers uint64_t offset() const; @@ -97,47 +94,38 @@ /// addRelocation - add a relocation into island bool addRelocation(Relocation& pReloc); -private: + private: /** \class Key * \brief Key to recognize a stub in the island. * */ - class Key - { - public: + class Key { + public: Key(const Stub* pPrototype, const LDSymbol* pSymbol, Stub::SWord pAddend) - : m_pPrototype(pPrototype), m_pSymbol(pSymbol), m_Addend(pAddend) - { } + : m_pPrototype(pPrototype), m_pSymbol(pSymbol), m_Addend(pAddend) {} - ~Key() - { } + ~Key() {} - const Stub* prototype() const { return m_pPrototype; } + const Stub* prototype() const { return m_pPrototype; } const LDSymbol* symbol() const { return m_pSymbol; } - Stub::SWord addend() const { return m_Addend; } + Stub::SWord addend() const { return m_Addend; } - struct Hash - { - size_t operator() (const Key& KEY) const - { + struct Hash { + size_t operator()(const Key& KEY) const { llvm::StringRef sym_name(KEY.symbol()->name()); hash::StringHash<hash::DJB> str_hasher; - return (size_t((uintptr_t)KEY.prototype())) ^ - str_hasher(sym_name) ^ + return (size_t((uintptr_t)KEY.prototype())) ^ str_hasher(sym_name) ^ KEY.addend(); } }; - struct Compare - { - bool operator() (const Key& KEY1, const Key& KEY2) const - { + struct Compare { + bool operator()(const Key& KEY1, const Key& KEY2) const { bool res = false; if ((KEY1.prototype() == KEY2.prototype()) && (KEY1.addend() == KEY2.addend())) { - if (KEY1.symbol() == KEY2.symbol()) { res = true; } else { @@ -156,7 +144,7 @@ } }; - private: + private: const Stub* m_pPrototype; const LDSymbol* m_pSymbol; Stub::SWord m_Addend; @@ -164,13 +152,13 @@ typedef HashEntry<Key, Stub*, Key::Compare> StubEntryType; - typedef HashTable<StubEntryType, - Key::Hash, - EntryFactory<StubEntryType> > StubMapType; -private: - Fragment& m_Entry; // entry fragment of the island - Fragment* m_pExit; // exit fragment of the island - Fragment* m_pRear; // rear fragment of the island + typedef HashTable<StubEntryType, Key::Hash, EntryFactory<StubEntryType> > + StubMapType; + + private: + Fragment& m_Entry; // entry fragment of the island + Fragment* m_pExit; // exit fragment of the island + Fragment* m_pRear; // rear fragment of the island size_t m_MaxSize; std::string m_Name; StubMapType m_StubMap; @@ -178,7 +166,6 @@ RelocationListType m_Relocations; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_BRANCHISLAND_H_
diff --git a/include/mcld/LD/BranchIslandFactory.h b/include/mcld/LD/BranchIslandFactory.h index 61a13ad..575d40f 100644 --- a/include/mcld/LD/BranchIslandFactory.h +++ b/include/mcld/LD/BranchIslandFactory.h
@@ -6,15 +6,15 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_BRANCHISLANDFACTORY_H -#define MCLD_LD_BRANCHISLANDFACTORY_H +#ifndef MCLD_LD_BRANCHISLANDFACTORY_H_ +#define MCLD_LD_BRANCHISLANDFACTORY_H_ + +#include "mcld/LD/BranchIsland.h" +#include "mcld/Support/GCFactory.h" #include <llvm/Support/DataTypes.h> -#include <mcld/Support/GCFactory.h> -#include <mcld/LD/BranchIsland.h> -namespace mcld -{ +namespace mcld { class Fragment; class Module; @@ -23,9 +23,8 @@ * \brief * */ -class BranchIslandFactory : public GCFactory<BranchIsland, 0> -{ -public: +class BranchIslandFactory : public GCFactory<BranchIsland, 0> { + public: /// ctor /// @param pMaxFwdBranchRange - the max forward branch range of the target /// @param pMaxBwdBranchRange - the max backward branch range of the target @@ -50,13 +49,12 @@ /// @return - return the pair of <fwd island, bwd island> std::pair<BranchIsland*, BranchIsland*> getIslands(const Fragment& pFragment); -private: + private: int64_t m_MaxFwdBranchRange; int64_t m_MaxBwdBranchRange; size_t m_MaxIslandSize; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_BRANCHISLANDFACTORY_H_
diff --git a/include/mcld/LD/DWARFLineInfo.h b/include/mcld/LD/DWARFLineInfo.h index 6152437..21f3345 100644 --- a/include/mcld/LD/DWARFLineInfo.h +++ b/include/mcld/LD/DWARFLineInfo.h
@@ -6,23 +6,18 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_DWARFLINEINFO_H -#define MCLD_LD_DWARFLINEINFO_H -#include <mcld/LD/DiagnosticLineInfo.h> +#ifndef MCLD_LD_DWARFLINEINFO_H_ +#define MCLD_LD_DWARFLINEINFO_H_ +#include "mcld/LD/DiagnosticLineInfo.h" -namespace mcld -{ +namespace mcld { /** \class DWARFLineInfo * \brief DWARFLineInfo provides the conversion from address to line of code * by DWARF format. */ -class DWARFLineInfo : public DiagnosticLineInfo -{ +class DWARFLineInfo : public DiagnosticLineInfo {}; -}; +} // namespace mcld -} // namespace of mcld - -#endif - +#endif // MCLD_LD_DWARFLINEINFO_H_
diff --git a/include/mcld/LD/DebugString.h b/include/mcld/LD/DebugString.h new file mode 100644 index 0000000..ada8975 --- /dev/null +++ b/include/mcld/LD/DebugString.h
@@ -0,0 +1,65 @@ +//===- DebugString.h ------------------------------------------------------===// +// +// The MCLinker Project +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#ifndef MCLD_LD_DEBUGSTRING_H_ +#define MCLD_LD_DEBUGSTRING_H_ + +#include "mcld/LD/MergedStringTable.h" + +#include <vector> + +namespace mcld { + +class LDSection; +class Relocation; +class TargetLDBackend; + +/** \class DebugString + * \brief DebugString represents the output debug section .debug_str + */ +class DebugString { + public: + DebugString() + : m_pSection(NULL) {} + + static DebugString* Create(LDSection& pSection); + + /// merge - process the strings in the given input .debug_str section and add + /// those strings into merged string map + void merge(LDSection& pSection); + + /// computeOffsetSize - set up the output offset of each strings and the + /// section size + /// @return string table size + size_t computeOffsetSize(); + + /// applyOffset - apply the relocation which refer to debug string. This + /// should be called after finalizeStringsOffset() + void applyOffset(Relocation& pReloc, TargetLDBackend& pBackend); + + /// emit - emit the section .debug_str + void emit(MemoryRegion& pRegion); + + void setOutputSection(LDSection& pSection) + { m_pSection = &pSection; } + + /// ---- observers ----- /// + const LDSection* getSection() const { return m_pSection; } + LDSection* getSection() { return m_pSection; } + + private: + /// m_Section - the output LDSection of this .debug_str + LDSection* m_pSection; + + MergedStringTable m_StringTable; +}; + +} // namespace mcld + +#endif // MCLD_LD_DEBUGSTRING_H_ +
diff --git a/include/mcld/LD/DiagAttribute.inc b/include/mcld/LD/DiagAttribute.inc index 453ae65..b6ce546 100644 --- a/include/mcld/LD/DiagAttribute.inc +++ b/include/mcld/LD/DiagAttribute.inc
@@ -1,19 +1,75 @@ // General -DIAG(warn_unsupported_attribute_section_format, DiagnosticEngine::Warning, "unsupported format of attribute section in input %0 (version=%1).", "unsupported format of attribute section in input %0 (version=%1).") -DIAG(warn_unrecognized_vendor_subsection, DiagnosticEngine::Warning, "skip unrecognized private vendor subsection with name '%0' in %1.", "skip unrecognized private vendor subsection with name '%0' in %1.") +DIAG(warn_unsupported_attribute_section_format, + DiagnosticEngine::Warning, + "unsupported format of attribute section in input %0 (version=%1).", + "unsupported format of attribute section in input %0 (version=%1).") +DIAG(warn_unrecognized_vendor_subsection, + DiagnosticEngine::Warning, + "skip unrecognized private vendor subsection with name '%0' in %1.", + "skip unrecognized private vendor subsection with name '%0' in %1.") // ARM attributes -DIAG(error_unknown_cpu_arch, DiagnosticEngine::Error, "input %0 has unknown CPU architecture profile.", "input %0 has unknown CPU architecture profile.") -DIAG(warn_mismatch_cpu_arch_profile, DiagnosticEngine::Warning, "conflicting architecture profiles %0 in %1.", "conflicting architecture profiles %0 in %1.") -DIAG(error_mismatch_mpextension_use, DiagnosticEngine::Error, "conflicting values from Tag_MPextension_use and Tag_MPextension_use_legacy in %0", "conflicting values from Tag_MPextension_use and Tag_MPextension_use_legacy in %0") -DIAG(warn_mismatch_enum_size, DiagnosticEngine::Warning, "the size of enumerated data item in input %0 (value=%1) is not compatible with the output (value=%2).", "the size of enumerated data item in input %0 (value=%1) is not compatible with the output (value=%2).") -DIAG(warn_mismatch_fp16_format, DiagnosticEngine::Warning, "conflicting 16-bit FP number format in %0", "conflicting 16-bit FP number format in %0") -DIAG(warn_unrecognized_virtualization_use, DiagnosticEngine::Warning, "value of Tag_Virtualization_use cannot be recognized in %0 (value=%1).", "value of Tag_Virtualization_use cannot be recognized in %0 (value=%1).") -DIAG(warn_mismatch_abi_wmmx_args, DiagnosticEngine::Warning, "%0 uses different way to pass WMMX parameters and results.", "%0 uses different way to pass WMMX parameters and results.") -DIAG(warn_mismatch_pcs_config, DiagnosticEngine::Warning, "conflicting procedure call standard config in input %0.", "conflicting procedure call standard config in input %0.") -DIAG(warn_mismatch_r9_use, DiagnosticEngine::Warning, "conflicting way to use R9 in input %0.", "conflicting way to use R9 in input %0.") -DIAG(warn_conflict_rw_data_and_r9, DiagnosticEngine::Warning, "RW static data addressing (SB-relative) conflicts the use of R9 (Tag_ABI_PCS_R9_use) in input %0.", "RW static data addressing (SB-relative) conflicts the use of R9 (Tag_ABI_PCS_R9_use) in input %0.") -DIAG(warn_mismatch_wchar_size, DiagnosticEngine::Warning, "incompatible size of wchar_t in input %0 (value=%1) with the output (value=%2).", "incompatible size of wchar_t in input %0 (value=%1) with the output (value=%2).") -DIAG(warn_unknown_mandatory_attribute, DiagnosticEngine::Warning, "unknown mandatory attribute with tag %0 was ignored in %1.", "unknown mandatory attribute with tag %0 was ignored in %1.") -DIAG(warn_unknown_attribute, DiagnosticEngine::Warning, "unknown attribute with tag %0 was ignored in %1.", "unknown attribute with tag %0 was ignored in %1.") -DIAG(warn_mismatch_vfp_args, DiagnosticEngine::Warning, "%0 uses different way to pass the floating point parameter and results.", "%0 uses different way to pass the floating point parameter and results.") +DIAG(error_unknown_cpu_arch, + DiagnosticEngine::Error, + "input %0 has unknown CPU architecture profile.", + "input %0 has unknown CPU architecture profile.") +DIAG(warn_mismatch_cpu_arch_profile, + DiagnosticEngine::Warning, + "conflicting architecture profiles %0 in %1.", + "conflicting architecture profiles %0 in %1.") +DIAG(error_mismatch_mpextension_use, + DiagnosticEngine::Error, + "conflicting values from Tag_MPextension_use and " + "Tag_MPextension_use_legacy in %0", + "conflicting values from Tag_MPextension_use and " + "Tag_MPextension_use_legacy in %0") +DIAG(warn_mismatch_enum_size, + DiagnosticEngine::Warning, + "the size of enumerated data item in input %0 (value=%1) is not " + "compatible with the output (value=%2).", + "the size of enumerated data item in input %0 (value=%1) is not " + "compatible with the output (value=%2).") +DIAG(warn_mismatch_fp16_format, + DiagnosticEngine::Warning, + "conflicting 16-bit FP number format in %0", + "conflicting 16-bit FP number format in %0") +DIAG(warn_unrecognized_virtualization_use, + DiagnosticEngine::Warning, + "value of Tag_Virtualization_use cannot be recognized in %0 (value=%1).", + "value of Tag_Virtualization_use cannot be recognized in %0 (value=%1).") +DIAG(warn_mismatch_abi_wmmx_args, + DiagnosticEngine::Warning, + "%0 uses different way to pass WMMX parameters and results.", + "%0 uses different way to pass WMMX parameters and results.") +DIAG(warn_mismatch_pcs_config, + DiagnosticEngine::Warning, + "conflicting procedure call standard config in input %0.", + "conflicting procedure call standard config in input %0.") +DIAG(warn_mismatch_r9_use, + DiagnosticEngine::Warning, + "conflicting way to use R9 in input %0.", + "conflicting way to use R9 in input %0.") +DIAG(warn_conflict_rw_data_and_r9, + DiagnosticEngine::Warning, + "RW static data addressing (SB-relative) conflicts the use of R9 " + "(Tag_ABI_PCS_R9_use) in input %0.", + "RW static data addressing (SB-relative) conflicts the use of R9 " + "(Tag_ABI_PCS_R9_use) in input %0.") +DIAG(warn_mismatch_wchar_size, + DiagnosticEngine::Warning, + "incompatible size of wchar_t in input %0 (value=%1) with the output " + "(value=%2).", + "incompatible size of wchar_t in input %0 (value=%1) with the output " + "(value=%2).") +DIAG(warn_unknown_mandatory_attribute, + DiagnosticEngine::Warning, + "unknown mandatory attribute with tag %0 was ignored in %1.", + "unknown mandatory attribute with tag %0 was ignored in %1.") +DIAG(warn_unknown_attribute, + DiagnosticEngine::Warning, + "unknown attribute with tag %0 was ignored in %1.", + "unknown attribute with tag %0 was ignored in %1.") +DIAG(warn_mismatch_vfp_args, + DiagnosticEngine::Warning, + "%0 uses different way to pass the floating point parameter and results.", + "%0 uses different way to pass the floating point parameter and results.")
diff --git a/include/mcld/LD/DiagCommonKinds.inc b/include/mcld/LD/DiagCommonKinds.inc index 6bb1461..f673c78 100644 --- a/include/mcld/LD/DiagCommonKinds.inc +++ b/include/mcld/LD/DiagCommonKinds.inc
@@ -1,54 +1,221 @@ -DIAG(err_cannot_open_input, DiagnosticEngine::Error, "can not open input file `%0': %1", "can not open input file `%0' : %1") -DIAG(err_cannot_open_output_file, DiagnosticEngine::Fatal, "cannot open output file `%0': %1", "cannot open output file `%0': %1") -DIAG(warn_cannot_open_search_dir, DiagnosticEngine::Warning, "can not open search directory `-L%0'", "can not open search directory `-L%0'") +DIAG(err_cannot_open_input, + DiagnosticEngine::Error, + "can not open input file `%0': %1", + "can not open input file `%0' : %1") +DIAG(err_cannot_open_output_file, + DiagnosticEngine::Fatal, + "cannot open output file `%0': %1", + "cannot open output file `%0': %1") +DIAG(warn_cannot_open_search_dir, + DiagnosticEngine::Warning, + "can not open search directory `-L%0'", + "can not open search directory `-L%0'") DIAG(err_no_inputs, DiagnosticEngine::Error, "no inputs", "no inputs") -DIAG(err_empty_input, DiagnosticEngine::Error, "Empty input file `%0' : %1", "Empty input file `%0' : %1") -DIAG(warn_unrecognized_input_file, DiagnosticEngine::Warning, "cannot recognize the format of file `%0'.\n object format or given target machine (%1) is incompatible.","cannot recognize the format of file `%0'.\n object format or given target machine (%1) is incompatible.") -DIAG(err_cannot_find_namespec, DiagnosticEngine::Fatal, "cannot recognize namespec -l%0", "cannot recognize namespec -l%0") -DIAG(err_cannot_identify_option, DiagnosticEngine::Fatal, "unknown command line argument `%0' at %1", "unknown command line argument `%0' at %1") -DIAG(err_mixed_shared_static_objects, DiagnosticEngine::Error, "cannot link shared objects with -static option.\nShared object `%0': %1", "cannot link shared objects with -static option.\nShared object `%0': %1") -DIAG(unrecognized_output_file, DiagnosticEngine::Unreachable, "unsupported output file format: `%0'", "unsupported output file format: `%0'") -DIAG(unrecognized_output_sectoin, DiagnosticEngine::Unreachable, "Unable to emit section `%0'\nPlease report to `%1'", "Unable to emit section `%0'\nPlease report to `%1'") -DIAG(duplicated_wrap, DiagnosticEngine::Warning, "wrapped symbol `%0' had been claimed", "wrapped symbol `%0' had been claimed") -DIAG(rewrap, DiagnosticEngine::Warning, "There are duplicated --wrap `%0' on the command line\nsymbol `%1' had been claimed", "There are duplicated --wrap `%0' on the command line]\nsymbol `%1' had been claimed.") -DIAG(err_cannot_read_symbol, DiagnosticEngine::Fatal, "can not read symbol[%0] in file %1", "can not read symbol[%0] in file %1") -DIAG(err_cannot_read_section, DiagnosticEngine::Fatal, "can not read section `%0'.", "can not read section `%0'.") -DIAG(err_cannot_read_target_section, DiagnosticEngine::Fatal, "can not read target-dependent section `%0'.", "can not read target-dependent section `%0'.") -DIAG(err_cannot_read_relocated_section, DiagnosticEngine::Fatal, "can not read the section being relocated in file %0.\ninvalid sh_info: %1\nrelocation section: %2", "can not read the section being relocated in file %0.\ninvalid sh_info: %1\nrelocation section: %2") -DIAG(err_unsupported_section, DiagnosticEngine::Fatal, "unsupported section `%0' (type %1)", "unsupported section `%0' (type %1)") -DIAG(unreachable_invalid_section_idx, DiagnosticEngine::Unreachable, "section[%0] is invalid in file %1", "section[%0] is invalid in file %1") -DIAG(err_unsupported_whole_archive, DiagnosticEngine::Error, "Target does not support --whole-archive", "Target does not support --whole-archive") -DIAG(err_unsupported_as_needed, DiagnosticEngine::Error, "Target does not support --as-needed", "Target does not support --as-needed") -DIAG(err_unsupported_add_needed, DiagnosticEngine::Error, "Target doest not support --add-needed", "Target does not support --add-needed") -DIAG(err_unsupported_Bdynamic, DiagnosticEngine::Error, "Target does not support --Bdynamic", "Target does not support --Bdynamic") -DIAG(err_enable_as_needed_on_static_system, DiagnosticEngine::Warning, "can not enable --as-needed on the target which does not support shared objects", "can not enable --as-needed on the target which does not support shared objects") -DIAG(err_mix_static_as_needed, DiagnosticEngine::Warning, "cannot mix --static with --as-needed", "cannot mix --static with --as-needed") -DIAG(err_cannot_change_file_size, DiagnosticEngine::Error, "cannot truncate file `%0' to size %1", "cannot truncate ffile `%0' to size %1") -DIAG(err_cannot_open_file, DiagnosticEngine::Error, "cannot open file `%0': %1.", "cannot open file `%0': %1.") -DIAG(err_cannot_close_file, DiagnosticEngine::Error, "cannot close file `%0': %1.", "cannot close file `%0': %1.") -DIAG(err_cannot_read_file, DiagnosticEngine::Error, "cannot read file %0 from offset %1 to length %2.", "cannot read file %0 from offset %1 to length %2.") -DIAG(err_cannot_read_small_file, DiagnosticEngine::Fatal, "file %0 is too small to read.\n file size is %1.\n read from %2.", "file %0 is too small to read.\n file size is %1.\n read from %2.") -DIAG(err_cannot_mmap_file, DiagnosticEngine::Error, "cannot open memory mapped file %0 from offset %1 to length %2.", "cannot open memoory mpped file %0 from offset %1 to length %2.") -DIAG(err_cannot_munmap_file, DiagnosticEngine::Error, "cannot remove the mapped memory of file %0.", "cannot remove the mapped memory of file %0.") -DIAG(err_cannot_write_file, DiagnosticEngine::Error, "cannot write file %0 from offset %1 to length %2.", "cannot write file %0 from offset %1 to length %2.") -DIAG(warn_illegal_input_section, DiagnosticEngine::Warning, "section `%0' should not appear in input file `%1': %2", "section `%0' should not appear in input file `%1': %2") -DIAG(err_cannot_trace_file, DiagnosticEngine::Unreachable, "cannot identify the type (%0) of input file `%1'.\n %2", "cannot identify the type (%0) of input file `%1'.\n %2") -DIAG(err_out_of_range_region, DiagnosticEngine::Unreachable, "requested memory region [%0, %1] is out of range.", "requested memory region [%0, %1] is out of range.") -DIAG(debug_eh_unsupport, DiagnosticEngine::Debug, "unsupported .eh_frame section in input: %0", "unsupported .eh_frame section in input: %0") -DIAG(note_eh_cie, DiagnosticEngine::Note, "CIE length: %0, aug_string: %1, fde_encodeing: %2", "CIE length: %0, aug_string: %1, fde_encodeing: %2") -DIAG(note_eh_fde, DiagnosticEngine::Note, "FDE length: %0, offset of PC Begin: %1", "FDE length: %0, offset of PC Begin: %1") -DIAG(fatal_cannot_init_target, DiagnosticEngine::Fatal, "Cannot initialize mcld::Target for given triple '%0'.\n(Detail: %1)", "Cannot initialize mcld::Target for given triple '%0'.\n(Detail: %1)") -DIAG(fatal_cannot_init_lineinfo, DiagnosticEngine::Fatal, "Cannot initialize mcld::DiagnosticLineInfo for given triple '%0'", "Cannot initialize mcld::DiagnosticLineInfo for given triple '%0'") -DIAG(fatal_cannot_init_backend, DiagnosticEngine::Fatal, "Cannot initialize mcld::TargetLDBackend for given triple '%0'.", "Cannot initialize mcld::TargetLDBackend for given triple '%0'.") -DIAG(fatal_forbid_nest_group, DiagnosticEngine::Fatal, "not matched --start-group and --end-group", "not matched --start-group and --end-group") -DIAG(fatal_unwritable_output, DiagnosticEngine::Fatal, "unable to write output file %0", "unable to write output file %0") -DIAG(warn_unsupported_option, DiagnosticEngine::Warning, "Option `%0' is not implemented yet!", "Option `%0' is not implemented yet!") -DIAG(warn_shared_textrel, DiagnosticEngine::Warning, "Add DT_TEXTREL in a shared object!", "Add DT_TEXTREL in a shared object.") -DIAG(fatal_illegal_codegen_type, DiagnosticEngine::Fatal, "illegal output format of output %0", "illegal output format of output %0") -DIAG(err_nmagic_not_static, DiagnosticEngine::Error, "cannot mix -nmagic option with -shared", "cannot mix -nmagic option with -shared") -DIAG(err_omagic_not_static, DiagnosticEngine::Error, "cannot mix -omagic option with -shared", "cannot mix -omagic option with -shared") -DIAG(err_invalid_emulation, DiagnosticEngine::Error, "Invalid target emulation: `%0'.", "Invalid target emulation: `%0'.") -DIAG(err_cannot_find_scriptfile, DiagnosticEngine::Fatal, "cannot open %0 file %1", "cannot open %0 file %1") -DIAG(err_unsupported_archive, DiagnosticEngine::Error, "Unsupported archive type.", "Unsupported archive type.") -DIAG(unexpected_frag_type, DiagnosticEngine::Unreachable, "Unexpected fragment type `%0' when constructing FG", "Unexpected fragment type `%0' when constructing FG") -DIAG(debug_print_gc_sections, DiagnosticEngine::Debug, "removing unused section from '%0' in file '%1'", "removing unused section from '%0' in file '%1'") +DIAG(err_empty_input, + DiagnosticEngine::Error, + "Empty input file `%0' : %1", + "Empty input file `%0' : %1") +DIAG(warn_unrecognized_input_file, + DiagnosticEngine::Warning, + "cannot recognize the format of file `%0'.\n object format or given " + "target machine (%1) is incompatible.", + "cannot recognize the format of file `%0'.\n object format or given " + "target machine (%1) is incompatible.") +DIAG(err_cannot_find_namespec, + DiagnosticEngine::Fatal, + "cannot recognize namespec -l%0", + "cannot recognize namespec -l%0") +DIAG(err_cannot_identify_option, + DiagnosticEngine::Fatal, + "unknown command line argument `%0' at %1", + "unknown command line argument `%0' at %1") +DIAG(err_mixed_shared_static_objects, + DiagnosticEngine::Error, + "cannot link shared objects with -static option.\nShared object `%0': %1", + "cannot link shared objects with -static option.\nShared object `%0': %1") +DIAG(unrecognized_output_file, + DiagnosticEngine::Unreachable, + "unsupported output file format: `%0'", + "unsupported output file format: `%0'") +DIAG(unrecognized_output_sectoin, + DiagnosticEngine::Unreachable, + "Unable to emit section `%0'\nPlease report to `%1'", + "Unable to emit section `%0'\nPlease report to `%1'") +DIAG(duplicated_wrap, + DiagnosticEngine::Warning, + "wrapped symbol `%0' had been claimed", + "wrapped symbol `%0' had been claimed") +DIAG(rewrap, + DiagnosticEngine::Warning, + "There are duplicated --wrap `%0' on the command line\nsymbol `%1' had " + "been claimed", + "There are duplicated --wrap `%0' on the command line]\nsymbol `%1' had " + "been claimed.") +DIAG(err_cannot_read_symbol, + DiagnosticEngine::Fatal, + "can not read symbol[%0] in file %1", + "can not read symbol[%0] in file %1") +DIAG(err_cannot_read_section, + DiagnosticEngine::Fatal, + "can not read section `%0'.", + "can not read section `%0'.") +DIAG(err_cannot_read_target_section, + DiagnosticEngine::Fatal, + "can not read target-dependent section `%0'.", + "can not read target-dependent section `%0'.") +DIAG(err_cannot_read_relocated_section, + DiagnosticEngine::Fatal, + "can not read the section being relocated in file %0.\ninvalid sh_info: " + "%1\nrelocation section: %2", + "can not read the section being relocated in file %0.\ninvalid sh_info: " + "%1\nrelocation section: %2") +DIAG(err_unsupported_section, + DiagnosticEngine::Fatal, + "unsupported section `%0' (type %1)", + "unsupported section `%0' (type %1)") +DIAG(unreachable_invalid_section_idx, + DiagnosticEngine::Unreachable, + "section[%0] is invalid in file %1", + "section[%0] is invalid in file %1") +DIAG(err_unsupported_whole_archive, + DiagnosticEngine::Error, + "Target does not support --whole-archive", + "Target does not support --whole-archive") +DIAG(err_unsupported_as_needed, + DiagnosticEngine::Error, + "Target does not support --as-needed", + "Target does not support --as-needed") +DIAG(err_unsupported_add_needed, + DiagnosticEngine::Error, + "Target doest not support --add-needed", + "Target does not support --add-needed") +DIAG(err_unsupported_Bdynamic, + DiagnosticEngine::Error, + "Target does not support --Bdynamic", + "Target does not support --Bdynamic") +DIAG(err_enable_as_needed_on_static_system, + DiagnosticEngine::Warning, + "can not enable --as-needed on the target which does not support shared " + "objects", + "can not enable --as-needed on the target which does not support shared " + "objects") +DIAG(err_mix_static_as_needed, + DiagnosticEngine::Warning, + "cannot mix --static with --as-needed", + "cannot mix --static with --as-needed") +DIAG(err_cannot_change_file_size, + DiagnosticEngine::Error, + "cannot truncate file `%0' to size %1", + "cannot truncate ffile `%0' to size %1") +DIAG(err_cannot_open_file, + DiagnosticEngine::Error, + "cannot open file `%0': %1.", + "cannot open file `%0': %1.") +DIAG(err_cannot_close_file, + DiagnosticEngine::Error, + "cannot close file `%0': %1.", + "cannot close file `%0': %1.") +DIAG(err_cannot_read_file, + DiagnosticEngine::Error, + "cannot read file %0 from offset %1 to length %2.", + "cannot read file %0 from offset %1 to length %2.") +DIAG(err_cannot_read_small_file, + DiagnosticEngine::Fatal, + "file %0 is too small to read.\n file size is %1.\n read from %2.", + "file %0 is too small to read.\n file size is %1.\n read from %2.") +DIAG(err_cannot_mmap_file, + DiagnosticEngine::Error, + "cannot open memory mapped file %0 from offset %1 to length %2.", + "cannot open memoory mpped file %0 from offset %1 to length %2.") +DIAG(err_cannot_munmap_file, + DiagnosticEngine::Error, + "cannot remove the mapped memory of file %0.", + "cannot remove the mapped memory of file %0.") +DIAG(err_cannot_write_file, + DiagnosticEngine::Error, + "cannot write file %0 from offset %1 to length %2.", + "cannot write file %0 from offset %1 to length %2.") +DIAG(warn_illegal_input_section, + DiagnosticEngine::Warning, + "section `%0' should not appear in input file `%1': %2", + "section `%0' should not appear in input file `%1': %2") +DIAG(err_cannot_trace_file, + DiagnosticEngine::Unreachable, + "cannot identify the type (%0) of input file `%1'.\n %2", + "cannot identify the type (%0) of input file `%1'.\n %2") +DIAG(err_out_of_range_region, + DiagnosticEngine::Unreachable, + "requested memory region [%0, %1] is out of range.", + "requested memory region [%0, %1] is out of range.") +DIAG(debug_eh_unsupport, + DiagnosticEngine::Debug, + "unsupported .eh_frame section in input: %0", + "unsupported .eh_frame section in input: %0") +DIAG(note_eh_cie, + DiagnosticEngine::Note, + "CIE length: %0, aug_string: %1, fde_encodeing: %2", + "CIE length: %0, aug_string: %1, fde_encodeing: %2") +DIAG(note_eh_fde, + DiagnosticEngine::Note, + "FDE length: %0, offset of PC Begin: %1", + "FDE length: %0, offset of PC Begin: %1") +DIAG(fatal_cannot_init_target, + DiagnosticEngine::Fatal, + "Cannot initialize mcld::Target for given triple '%0'.\n(Detail: %1)", + "Cannot initialize mcld::Target for given triple '%0'.\n(Detail: %1)") +DIAG(fatal_cannot_init_lineinfo, + DiagnosticEngine::Fatal, + "Cannot initialize mcld::DiagnosticLineInfo for given triple '%0'", + "Cannot initialize mcld::DiagnosticLineInfo for given triple '%0'") +DIAG(fatal_cannot_init_backend, + DiagnosticEngine::Fatal, + "Cannot initialize mcld::TargetLDBackend for given triple '%0'.", + "Cannot initialize mcld::TargetLDBackend for given triple '%0'.") +DIAG(fatal_forbid_nest_group, + DiagnosticEngine::Fatal, + "not matched --start-group and --end-group", + "not matched --start-group and --end-group") +DIAG(fatal_unwritable_output, + DiagnosticEngine::Fatal, + "unable to write output file %0", + "unable to write output file %0") +DIAG(warn_unsupported_option, + DiagnosticEngine::Warning, + "Option `%0' is not implemented yet!", + "Option `%0' is not implemented yet!") +DIAG(warn_shared_textrel, + DiagnosticEngine::Warning, + "Add DT_TEXTREL in a shared object!", + "Add DT_TEXTREL in a shared object.") +DIAG(fatal_illegal_codegen_type, + DiagnosticEngine::Fatal, + "illegal output format of output %0", + "illegal output format of output %0") +DIAG(err_nmagic_not_static, + DiagnosticEngine::Error, + "cannot mix -nmagic option with -shared", + "cannot mix -nmagic option with -shared") +DIAG(err_omagic_not_static, + DiagnosticEngine::Error, + "cannot mix -omagic option with -shared", + "cannot mix -omagic option with -shared") +DIAG(err_invalid_emulation, + DiagnosticEngine::Error, + "Invalid target emulation: `%0'.", + "Invalid target emulation: `%0'.") +DIAG(err_cannot_find_scriptfile, + DiagnosticEngine::Fatal, + "cannot open %0 file %1", + "cannot open %0 file %1") +DIAG(err_unsupported_archive, + DiagnosticEngine::Error, + "Unsupported archive type.", + "Unsupported archive type.") +DIAG(unexpected_frag_type, + DiagnosticEngine::Unreachable, + "Unexpected fragment type `%0' when constructing FG", + "Unexpected fragment type `%0' when constructing FG") +DIAG(debug_print_gc_sections, + DiagnosticEngine::Debug, + "removing unused section from '%0' in file '%1'", + "removing unused section from '%0' in file '%1'")
diff --git a/include/mcld/LD/DiagGOTPLT.inc b/include/mcld/LD/DiagGOTPLT.inc index 172bceb..3de335a 100644 --- a/include/mcld/LD/DiagGOTPLT.inc +++ b/include/mcld/LD/DiagGOTPLT.inc
@@ -1,5 +1,20 @@ -DIAG(mips_got_symbol, DiagnosticEngine::Unreachable, "%0 is not a dynamic symbol, do not put it in global got", "%0 is not a dynamic symbol, do not put it in global got") -DIAG(fail_allocate_memory_got, DiagnosticEngine::Fatal, "fial to allocate memory for GOT", "fial to allocate memory for GOT") -DIAG(fail_allocate_memory_plt, DiagnosticEngine::Fatal, "fial to allocate memory for PLT", "fial to allocate memory for PLT") -DIAG(reserve_entry_number_mismatch_got, DiagnosticEngine::Unreachable, "The number of reserved entries for GOT is inconsist", "The number of reserved entries for GOT is inconsist") -DIAG(reserve_entry_number_mismatch_plt, DiagnosticEngine::Unreachable, "The number of reserved entries for PLT is inconsist", "The number of reserved entries for PLT is inconsist") +DIAG(mips_got_symbol, + DiagnosticEngine::Unreachable, + "%0 is not a dynamic symbol, do not put it in global got", + "%0 is not a dynamic symbol, do not put it in global got") +DIAG(fail_allocate_memory_got, + DiagnosticEngine::Fatal, + "fial to allocate memory for GOT", + "fial to allocate memory for GOT") +DIAG(fail_allocate_memory_plt, + DiagnosticEngine::Fatal, + "fial to allocate memory for PLT", + "fial to allocate memory for PLT") +DIAG(reserve_entry_number_mismatch_got, + DiagnosticEngine::Unreachable, + "The number of reserved entries for GOT is inconsist", + "The number of reserved entries for GOT is inconsist") +DIAG(reserve_entry_number_mismatch_plt, + DiagnosticEngine::Unreachable, + "The number of reserved entries for PLT is inconsist", + "The number of reserved entries for PLT is inconsist")
diff --git a/include/mcld/LD/DiagLDScript.inc b/include/mcld/LD/DiagLDScript.inc index c752773..1699bb9 100644 --- a/include/mcld/LD/DiagLDScript.inc +++ b/include/mcld/LD/DiagLDScript.inc
@@ -1,3 +1,12 @@ -DIAG(err_unterminated_comment, DiagnosticEngine::Error, "%0:%1:%2: error: unterminated comment\n", "%0:%1:%2: error: unterminated comment\n") -DIAG(err_syntax_error, DiagnosticEngine::Error, "%0:%1:%2: error: %3\n", "%0:%1:%2: error: %3\n") -DIAG(err_assert_failed, DiagnosticEngine::Error,"Assertion failed: %0\n", "Assertion failed: %0\n") +DIAG(err_unterminated_comment, + DiagnosticEngine::Error, + "%0:%1:%2: error: unterminated comment\n", + "%0:%1:%2: error: unterminated comment\n") +DIAG(err_syntax_error, + DiagnosticEngine::Error, + "%0:%1:%2: error: %3\n", + "%0:%1:%2: error: %3\n") +DIAG(err_assert_failed, + DiagnosticEngine::Error, + "Assertion failed: %0\n", + "Assertion failed: %0\n")
diff --git a/include/mcld/LD/DiagLayouts.inc b/include/mcld/LD/DiagLayouts.inc index 513ee33..c41b775 100644 --- a/include/mcld/LD/DiagLayouts.inc +++ b/include/mcld/LD/DiagLayouts.inc
@@ -1,8 +1,34 @@ -DIAG(warn_unsupported_exception, DiagnosticEngine::Warning, "Exception handling has not been fully supported yet.\nsection `%0'.", "Exception handling has not been fully supported yet.\nsection `%0'.") -DIAG(warn_unsupported_symbolic_versioning, DiagnosticEngine::Warning, "Symbolic versioning has not been fully supported yet.\nsection `%0'.", "Symbolic versioning has not been fully supported yet.\nsection `%0'") -DIAG(err_section_not_laid_out, DiagnosticEngine::Unreachable, "section %0 has not been laid out. Developers may use an output LDSection in Layout::getFragmentRef", "section %0 has not been laid out. Developers may use an output LDSection in Layout::getFragmentRef") -DIAG(warn_duplicate_std_sectmap, DiagnosticEngine::Warning, "Duplicated definition of section map \"from %0 to %0\".", "Duplicated definition of section map \"from %0 to %0\".") -DIAG(warn_rules_check_failed, DiagnosticEngine::Warning, "Illegal section mapping rule: %0 -> %1. (conflict with %2 -> %3)", "Illegal section mapping rule: %0 -> %1. (conflict with %2 -> %3)") -DIAG(err_cannot_merge_section, DiagnosticEngine::Error, "Cannot merge section %0 of %1", "Cannot merge section %0 of %1") -DIAG(debug_icf_iterations, DiagnosticEngine::Debug, "ICF converged after `%0' iteration(s).", "ICF converged after `%0' iteration(s).") -DIAG(debug_icf_folded_section, DiagnosticEngine::Debug, "ICF folding section `%0' of `%1' into `%2' of `%3'", "ICF folding section `%0' of `%1' into `%2' of `%3'") +DIAG(warn_unsupported_exception, + DiagnosticEngine::Warning, + "Exception handling has not been fully supported yet.\nsection `%0'.", + "Exception handling has not been fully supported yet.\nsection `%0'.") +DIAG(warn_unsupported_symbolic_versioning, + DiagnosticEngine::Warning, + "Symbolic versioning has not been fully supported yet.\nsection `%0'.", + "Symbolic versioning has not been fully supported yet.\nsection `%0'") +DIAG(err_section_not_laid_out, + DiagnosticEngine::Unreachable, + "section %0 has not been laid out. Developers may use an output LDSection " + "in Layout::getFragmentRef", + "section %0 has not been laid out. Developers may use an output LDSection " + "in Layout::getFragmentRef") +DIAG(warn_duplicate_std_sectmap, + DiagnosticEngine::Warning, + "Duplicated definition of section map \"from %0 to %0\".", + "Duplicated definition of section map \"from %0 to %0\".") +DIAG(warn_rules_check_failed, + DiagnosticEngine::Warning, + "Illegal section mapping rule: %0 -> %1. (conflict with %2 -> %3)", + "Illegal section mapping rule: %0 -> %1. (conflict with %2 -> %3)") +DIAG(err_cannot_merge_section, + DiagnosticEngine::Error, + "Cannot merge section %0 of %1", + "Cannot merge section %0 of %1") +DIAG(debug_icf_iterations, + DiagnosticEngine::Debug, + "ICF converged after `%0' iteration(s).", + "ICF converged after `%0' iteration(s).") +DIAG(debug_icf_folded_section, + DiagnosticEngine::Debug, + "ICF folding section `%0' of `%1' into `%2' of `%3'", + "ICF folding section `%0' of `%1' into `%2' of `%3'")
diff --git a/include/mcld/LD/DiagReaders.inc b/include/mcld/LD/DiagReaders.inc index 3f08a21..2409946 100644 --- a/include/mcld/LD/DiagReaders.inc +++ b/include/mcld/LD/DiagReaders.inc
@@ -1,4 +1,16 @@ -DIAG(archive_magic_mismatch, DiagnosticEngine::Error, "magic number is mismatched in `%0'", "magic number is mismatched in `%0'") -DIAG(debug_cannot_parse_eh, DiagnosticEngine::Debug, "cannot parse .eh_frame section in input %0", "cannot parse .eh_frame section in input %0.") -DIAG(debug_cannot_scan_eh, DiagnosticEngine::Debug, "cannot scan .eh_frame section in input %0", "cannot scan .eh_frame section in input %0.") -DIAG(fatal_cannot_read_input, DiagnosticEngine::Fatal, "cannot read input input %0", "cannot read input %0") +DIAG(archive_magic_mismatch, + DiagnosticEngine::Error, + "magic number is mismatched in `%0'", + "magic number is mismatched in `%0'") +DIAG(debug_cannot_parse_eh, + DiagnosticEngine::Debug, + "cannot parse .eh_frame section in input %0", + "cannot parse .eh_frame section in input %0.") +DIAG(debug_cannot_scan_eh, + DiagnosticEngine::Debug, + "cannot scan .eh_frame section in input %0", + "cannot scan .eh_frame section in input %0.") +DIAG(fatal_cannot_read_input, + DiagnosticEngine::Fatal, + "cannot read input input %0", + "cannot read input %0")
diff --git a/include/mcld/LD/DiagRelocations.inc b/include/mcld/LD/DiagRelocations.inc index bacae6e..8b2021b 100644 --- a/include/mcld/LD/DiagRelocations.inc +++ b/include/mcld/LD/DiagRelocations.inc
@@ -1,15 +1,72 @@ -DIAG(reloc_factory_has_not_config, DiagnosticEngine::Fatal, "Please call mcld::Linker::config before creating relocations", "Please call mcld::Linker::config before creating relocations") -DIAG(unsupported_bitclass, DiagnosticEngine::Fatal, "Only supports 32 and 64 bits targets. (Target: %0, bitclass:%1)", "Only supports 32 and 64 bits targets. (Target: %0, bitclass:%1)") -DIAG(undefined_reference, DiagnosticEngine::Fatal, "%1(%2+%3): undefined reference to `%0'", "%1(%2+%3): undefined reference to `%0'") -DIAG(undefined_reference_text, DiagnosticEngine::Fatal, "%1:%2:function %3: undefined reference to `%0'", "%1:%2: undefined reference to `%0'") -DIAG(non_pic_relocation, DiagnosticEngine::Error, "attempt to generate unsupported relocation type `%0' for symbol `%1', recompile with -fPIC", "attempt to generate unsupported relocation type `%0' for symbol `%1, recompile with -fPIC") -DIAG(base_relocation, DiagnosticEngine::Fatal, "relocation type `%0' is not supported for symbol `%1'\nPlease report to %2", "relocation type `%0' is not supported for symbol `%1'\nPlease report to %2") -DIAG(dynamic_relocation, DiagnosticEngine::Fatal, "unexpected relocation type `%0' in object file", "unexpected relocation type `%0' in object file") -DIAG(unsupported_relocation, DiagnosticEngine::Unreachable, "encounter unsupported relocation type `%0'\nPlease report to %1", "encounter unsupported relocation type `%0'\nPlease report to %1") -DIAG(unknown_relocation, DiagnosticEngine::Fatal, "encounter unknown relocation type `%0' for symbol `%1'", "encounter unknown relocation type `%0' for symbol `%1'") -DIAG(invalid_global_relocation, DiagnosticEngine::Unreachable, "relocation type `%0' is invalid for global symbol `%1'", "relocation type `%0' is invalid for global symbol `%1'") -DIAG(result_overflow, DiagnosticEngine::Error, "applying relocation `%0' causes overflow on symbol `%1'","applying relocation `%0' causes overflow on symbol `%1'") -DIAG(result_badreloc, DiagnosticEngine::Error, "applying relocation `%0' encounters unexpected opcode on symbol `%1'","applying relocation `%0' encounters unexpected opcode on symbol `%1'") -DIAG(invalid_tls, DiagnosticEngine::Error, "TLS relocation against invalid symbol `%0' in section `%1'", "TLS relocation against invalid symbol `%0' in section `%1'") -DIAG(unknown_reloc_section_type, DiagnosticEngine::Unreachable, "unknown relocation section type: `%0' in section `%1'", "unknown relocation section type: `%0' in section `%1'") -DIAG(unsupport_cond_branch_reloc, DiagnosticEngine::Error, "applying relocation `%0', conditional branch to PLT in THUMB-2 not supported yet", "applying relocation `%0', conditional branch to PLT in THUMB-2 not supported yet") +DIAG(reloc_factory_has_not_config, + DiagnosticEngine::Fatal, + "Please call mcld::Linker::config before creating relocations", + "Please call mcld::Linker::config before creating relocations") +DIAG(unsupported_bitclass, + DiagnosticEngine::Fatal, + "Only supports 32 and 64 bits targets. (Target: %0, bitclass:%1)", + "Only supports 32 and 64 bits targets. (Target: %0, bitclass:%1)") +DIAG(undefined_reference, + DiagnosticEngine::Fatal, + "%1(%2+%3): undefined reference to `%0'", + "%1(%2+%3): undefined reference to `%0'") +DIAG(undefined_reference_text, + DiagnosticEngine::Fatal, + "%1:%2:function %3: undefined reference to `%0'", + "%1:%2: undefined reference to `%0'") +DIAG(non_pic_relocation, + DiagnosticEngine::Error, + "attempt to generate unsupported relocation `%0' for symbol `%1', " + "recompile with -fPIC", + "attempt to generate unsupported relocation `%0' for symbol `%1, " + "recompile with -fPIC") +DIAG(base_relocation, + DiagnosticEngine::Fatal, + "relocation type `%0' is not supported for symbol `%1'\nPlease report to " + "%2", + "relocation type `%0' is not supported for symbol `%1'\nPlease report to " + "%2") +DIAG(dynamic_relocation, + DiagnosticEngine::Fatal, + "unexpected relocation type `%0' in object file", + "unexpected relocation type `%0' in object file") +DIAG(unsupported_relocation, + DiagnosticEngine::Unreachable, + "encounter unsupported relocation type `%0'\nPlease report to %1", + "encounter unsupported relocation type `%0'\nPlease report to %1") +DIAG(unknown_relocation, + DiagnosticEngine::Fatal, + "encounter unknown relocation type `%0' for symbol `%1'", + "encounter unknown relocation type `%0' for symbol `%1'") +DIAG(invalid_global_relocation, + DiagnosticEngine::Unreachable, + "relocation type `%0' is invalid for global symbol `%1'", + "relocation type `%0' is invalid for global symbol `%1'") +DIAG(result_overflow, + DiagnosticEngine::Error, + "applying relocation `%0' causes overflow on symbol `%1'", + "applying relocation `%0' causes overflow on symbol `%1'") +DIAG(result_badreloc, + DiagnosticEngine::Error, + "applying relocation `%0' encounters unexpected opcode on symbol `%1'", + "applying relocation `%0' encounters unexpected opcode on symbol `%1'") +DIAG(invalid_tls, + DiagnosticEngine::Error, + "TLS relocation against invalid symbol `%0' in section `%1'", + "TLS relocation against invalid symbol `%0' in section `%1'") +DIAG(unknown_reloc_section_type, + DiagnosticEngine::Unreachable, + "unknown relocation section type: `%0' in section `%1'", + "unknown relocation section type: `%0' in section `%1'") +DIAG(unsupported_cond_branch_reloc, + DiagnosticEngine::Error, + "applying relocation `%0', conditional branch to PLT in THUMB-2 not " + "supported yet", + "applying relocation `%0', conditional branch to PLT in THUMB-2 not " + "supported yet") +DIAG(unsupport_reloc_for_debug_string, + DiagnosticEngine::Error, + "applying relocation `%0' for .debug_str is not supported. " + "Please report to %1", + "applying relocation `%0' for .debug_str is not supported. " + "Please report to %1")
diff --git a/include/mcld/LD/DiagSymbolResolutions.inc b/include/mcld/LD/DiagSymbolResolutions.inc index 04113dc..b640334 100644 --- a/include/mcld/LD/DiagSymbolResolutions.inc +++ b/include/mcld/LD/DiagSymbolResolutions.inc
@@ -1,11 +1,44 @@ -DIAG(note_has_no_symtab, DiagnosticEngine::Note, "input file `%0' has no symbol table `%2'\n path of input file: %1", "input file `%0' has no symbol table `%2'\n path of input file: %1") -DIAG(fatal_cannot_read_strtab, DiagnosticEngine::Fatal, "cannot read strtab for %2 in file `%0': %1", "cannot read strtab for %2 in file `%0': %1") -DIAG(fail_sym_resolution, DiagnosticEngine::Unreachable, "Fails to resolve symbols [%0:%1]\nPlease reports to `%2'", "Fails to resolve symbols [%0:%1]\nPlease reports to `%2'") -DIAG(mark_dynamic_defined, DiagnosticEngine::Ignore, "refer to dynamic symbol %0", "call a external function %0") -DIAG(comm_refer_to_define, DiagnosticEngine::Ignore, "common symbol %0 is overridden by previous definition", "common symbol %0 is overridden by previous definition") -DIAG(redefine_common, DiagnosticEngine::Ignore, "common symbol %0 is overridden by definition", "common symbol %0 is overriden by definition") -DIAG(indirect_refer_to_common, DiagnosticEngine::Ignore, "indirect symbol %0 points to a common symbol", "indirect symbol %0 points to a common symbol") -DIAG(indirect_refer_to_inexist, DiagnosticEngine::Fatal, "indirect symbol %0 points to a undefined symbol", "variable %0 is undefined") -DIAG(multiple_definitions, DiagnosticEngine::Error, "multiple definition of symbol `%0'", "you define variable %0 twice") -DIAG(undefined_situation, DiagnosticEngine::Unreachable, "reach undefined situation, action: %0, old(%1) -> new(%2)", "reach undefined situation, action: %0, old(%1) -> new(%2)") -DIAG(multiple_absolute_definitions, DiagnosticEngine::Error, "inconsistent definitions of absolute symbol `%0': old(%1) -> new(%2)", "you defined an absolute symbol with different values") +DIAG(note_has_no_symtab, + DiagnosticEngine::Note, + "input file `%0' has no symbol table `%2'\n path of input file: %1", + "input file `%0' has no symbol table `%2'\n path of input file: %1") +DIAG(fatal_cannot_read_strtab, + DiagnosticEngine::Fatal, + "cannot read strtab for %2 in file `%0': %1", + "cannot read strtab for %2 in file `%0': %1") +DIAG(fail_sym_resolution, + DiagnosticEngine::Unreachable, + "Fails to resolve symbols [%0:%1]\nPlease reports to `%2'", + "Fails to resolve symbols [%0:%1]\nPlease reports to `%2'") +DIAG(mark_dynamic_defined, + DiagnosticEngine::Ignore, + "refer to dynamic symbol %0", + "call a external function %0") +DIAG(comm_refer_to_define, + DiagnosticEngine::Ignore, + "common symbol %0 is overridden by previous definition", + "common symbol %0 is overridden by previous definition") +DIAG(redefine_common, + DiagnosticEngine::Ignore, + "common symbol %0 is overridden by definition", + "common symbol %0 is overriden by definition") +DIAG(indirect_refer_to_common, + DiagnosticEngine::Ignore, + "indirect symbol %0 points to a common symbol", + "indirect symbol %0 points to a common symbol") +DIAG(indirect_refer_to_inexist, + DiagnosticEngine::Fatal, + "indirect symbol %0 points to a undefined symbol", + "variable %0 is undefined") +DIAG(multiple_definitions, + DiagnosticEngine::Error, + "multiple definition of symbol `%0'", + "you define variable %0 twice") +DIAG(undefined_situation, + DiagnosticEngine::Unreachable, + "reach undefined situation, action: %0, old(%1) -> new(%2)", + "reach undefined situation, action: %0, old(%1) -> new(%2)") +DIAG(multiple_absolute_definitions, + DiagnosticEngine::Error, + "inconsistent definitions of absolute symbol `%0': old(%1) -> new(%2)", + "you defined an absolute symbol with different values")
diff --git a/include/mcld/LD/Diagnostic.h b/include/mcld/LD/Diagnostic.h index 615c99d..6183947 100644 --- a/include/mcld/LD/Diagnostic.h +++ b/include/mcld/LD/Diagnostic.h
@@ -6,37 +6,35 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_DIAGNOSTIC_H -#define MCLD_LD_DIAGNOSTIC_H +#ifndef MCLD_LD_DIAGNOSTIC_H_ +#define MCLD_LD_DIAGNOSTIC_H_ -#include <string> +#include "mcld/LD/DiagnosticEngine.h" + #include <cassert> -#include <mcld/LD/DiagnosticEngine.h> +#include <string> namespace mcld { /** \class Diagnostic * \brief Diagnostic provides current status to DiagnosticPrinters. */ -class Diagnostic -{ -public: - Diagnostic(DiagnosticEngine& pEngine); +class Diagnostic { + public: + explicit Diagnostic(DiagnosticEngine& pEngine); ~Diagnostic(); - unsigned int getID() const - { return m_Engine.state().ID; } + unsigned int getID() const { return m_Engine.state().ID; } - unsigned int getNumArgs() const - { return m_Engine.state().numArgs; } + unsigned int getNumArgs() const { return m_Engine.state().numArgs; } DiagnosticEngine::ArgumentKind getArgKind(unsigned int pIdx) const { assert(pIdx < getNumArgs() && "Argument index is out of range!"); return (DiagnosticEngine::ArgumentKind)m_Engine.state().ArgumentKinds[pIdx]; } - const std::string &getArgStdStr(unsigned int pIdx) const { + const std::string& getArgStdStr(unsigned int pIdx) const { assert(getArgKind(pIdx) == DiagnosticEngine::ak_std_string && "Invalid argument accessor!"); return m_Engine.state().ArgumentStrs[pIdx]; @@ -51,7 +49,7 @@ int getArgSInt(unsigned int pIdx) const { assert(getArgKind(pIdx) == DiagnosticEngine::ak_sint && "Invalid argument accessor!"); - return (int)m_Engine.state().ArgumentVals[pIdx]; + return static_cast<int>(m_Engine.state().ArgumentVals[pIdx]); } unsigned int getArgUInt(unsigned int pIdx) const { @@ -69,7 +67,7 @@ bool getArgBool(unsigned int pIdx) const { assert(getArgKind(pIdx) == DiagnosticEngine::ak_bool && "Invalid argument accessor!"); - return (bool)m_Engine.state().ArgumentVals[pIdx]; + return static_cast<bool>(m_Engine.state().ArgumentVals[pIdx]); } intptr_t getRawVals(unsigned int pIdx) const { @@ -86,14 +84,13 @@ // arguments. The result is appended at on the pOutStr. void format(const char* pBegin, const char* pEnd, std::string& pOutStr) const; -private: - const char* findMatch(char pVal, const char* pBegin, const char* pEnd ) const; + private: + const char* findMatch(char pVal, const char* pBegin, const char* pEnd) const; -private: + private: DiagnosticEngine& m_Engine; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_DIAGNOSTIC_H_
diff --git a/include/mcld/LD/DiagnosticEngine.h b/include/mcld/LD/DiagnosticEngine.h index 460e4b7..ef73def 100644 --- a/include/mcld/LD/DiagnosticEngine.h +++ b/include/mcld/LD/DiagnosticEngine.h
@@ -6,19 +6,21 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_DIAGNOSTICENGINE_H -#define MCLD_LD_DIAGNOSTICENGINE_H -#include <string> +#ifndef MCLD_LD_DIAGNOSTICENGINE_H_ +#define MCLD_LD_DIAGNOSTICENGINE_H_ +#include "mcld/LD/DiagnosticInfos.h" + #include <llvm/Support/DataTypes.h> -#include <mcld/LD/DiagnosticInfos.h> + +#include <string> namespace mcld { +class DiagnosticLineInfo; +class DiagnosticPrinter; class Input; class LinkerConfig; class MsgHandler; -class DiagnosticPrinter; -class DiagnosticLineInfo; /** \class DiagnosticEngine * \brief DiagnosticEngine is used to report problems and issues. @@ -31,9 +33,8 @@ * - remember the argument string for MsgHandler * - choice the severity of a message by options */ -class DiagnosticEngine -{ -public: +class DiagnosticEngine { + public: enum Severity { Unreachable, Fatal, @@ -54,7 +55,7 @@ ak_bool // bool }; -public: + public: DiagnosticEngine(); ~DiagnosticEngine(); @@ -66,16 +67,14 @@ void setPrinter(DiagnosticPrinter& pPrinter, bool pShouldOwnPrinter = true); const DiagnosticPrinter* getPrinter() const { return m_pPrinter; } - DiagnosticPrinter* getPrinter() { return m_pPrinter; } - + DiagnosticPrinter* getPrinter() { return m_pPrinter; } DiagnosticPrinter* takePrinter() { m_OwnPrinter = false; return m_pPrinter; } - bool ownPrinter() const - { return m_OwnPrinter; } + bool ownPrinter() const { return m_OwnPrinter; } // ----- emission ----- // // emit - process the message to printer @@ -84,7 +83,7 @@ // report - issue the message to the printer MsgHandler report(uint16_t pID, Severity pSeverity); -private: + private: friend class MsgHandler; friend class Diagnostic; @@ -94,11 +93,10 @@ MaxArguments = 10 }; - struct State - { - public: - State() : numArgs(0), ID(-1), severity(None), file(NULL) { } - ~State() { } + struct State { + public: + State() : numArgs(0), ID(-1), severity(None), file(NULL) {} + ~State() {} void reset() { numArgs = 0; @@ -107,7 +105,7 @@ file = NULL; } - public: + public: std::string ArgumentStrs[MaxArguments]; intptr_t ArgumentVals[MaxArguments]; uint8_t ArgumentKinds[MaxArguments]; @@ -117,24 +115,22 @@ Input* file; }; -private: - State& state() - { return m_State; } + private: + State& state() { return m_State; } - const State& state() const - { return m_State; } + const State& state() const { return m_State; } DiagnosticInfos& infoMap() { - assert(NULL != m_pInfoMap && "DiagnosticEngine was not initialized!"); + assert(m_pInfoMap != NULL && "DiagnosticEngine was not initialized!"); return *m_pInfoMap; } const DiagnosticInfos& infoMap() const { - assert(NULL != m_pInfoMap && "DiagnosticEngine was not initialized!"); + assert(m_pInfoMap != NULL && "DiagnosticEngine was not initialized!"); return *m_pInfoMap; } -private: + private: const LinkerConfig* m_pConfig; DiagnosticLineInfo* m_pLineInfo; DiagnosticPrinter* m_pPrinter; @@ -144,7 +140,6 @@ State m_State; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_DIAGNOSTICENGINE_H_
diff --git a/include/mcld/LD/DiagnosticInfos.h b/include/mcld/LD/DiagnosticInfos.h index 543b754..804394e 100644 --- a/include/mcld/LD/DiagnosticInfos.h +++ b/include/mcld/LD/DiagnosticInfos.h
@@ -6,14 +6,15 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_DIAGNOSTICINFORMATION_H -#define MCLD_LD_DIAGNOSTICINFORMATION_H +#ifndef MCLD_LD_DIAGNOSTICINFOS_H_ +#define MCLD_LD_DIAGNOSTICINFOS_H_ + #include <llvm/ADT/StringRef.h> namespace mcld { namespace diag { - enum ID { +enum ID { #define DIAG(ENUM, CLASS, ADDRMSG, LINEMSG) ENUM, #include "mcld/LD/DiagAttribute.inc" #include "mcld/LD/DiagCommonKinds.inc" @@ -24,20 +25,19 @@ #include "mcld/LD/DiagGOTPLT.inc" #include "mcld/LD/DiagLDScript.inc" #undef DIAG - NUM_OF_BUILDIN_DIAGNOSTIC_INFO - }; -} // namespace of diag + NUM_OF_BUILDIN_DIAGNOSTIC_INFO +}; +} // namespace diag -class LinkerConfig; class DiagnosticEngine; +class LinkerConfig; /** \class DiagnosticInfos * \brief DiagnosticInfos caches run-time information of DiagnosticInfo. */ -class DiagnosticInfos -{ -public: - DiagnosticInfos(const LinkerConfig& pConfig); +class DiagnosticInfos { + public: + explicit DiagnosticInfos(const LinkerConfig& pConfig); ~DiagnosticInfos(); @@ -45,11 +45,10 @@ bool process(DiagnosticEngine& pEngine) const; -private: + private: const LinkerConfig& m_Config; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_DIAGNOSTICINFOS_H_
diff --git a/include/mcld/LD/DiagnosticLineInfo.h b/include/mcld/LD/DiagnosticLineInfo.h index a13aef6..852eaa5 100644 --- a/include/mcld/LD/DiagnosticLineInfo.h +++ b/include/mcld/LD/DiagnosticLineInfo.h
@@ -6,21 +6,16 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_DIAGNOSTICLINEINFO_H -#define MCLD_LD_DIAGNOSTICLINEINFO_H +#ifndef MCLD_LD_DIAGNOSTICLINEINFO_H_ +#define MCLD_LD_DIAGNOSTICLINEINFO_H_ -namespace mcld -{ +namespace mcld { /** \class DiagnosticLineInfo * \brief Map the address to the line of code. */ -class DiagnosticLineInfo -{ +class DiagnosticLineInfo {}; -}; +} // namespace mcld -} // namespace of mcld - -#endif - +#endif // MCLD_LD_DIAGNOSTICLINEINFO_H_
diff --git a/include/mcld/LD/DiagnosticPrinter.h b/include/mcld/LD/DiagnosticPrinter.h index d03b9a9..68cc484 100644 --- a/include/mcld/LD/DiagnosticPrinter.h +++ b/include/mcld/LD/DiagnosticPrinter.h
@@ -6,21 +6,20 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_DIAGNOSTICPRINTER_H -#define MCLD_LD_DIAGNOSTICPRINTER_H -#include <mcld/LD/DiagnosticEngine.h> -#include <mcld/LD/Diagnostic.h> +#ifndef MCLD_LD_DIAGNOSTICPRINTER_H_ +#define MCLD_LD_DIAGNOSTICPRINTER_H_ -namespace mcld -{ +#include "mcld/LD/Diagnostic.h" +#include "mcld/LD/DiagnosticEngine.h" + +namespace mcld { /** \class DiagnosticPrinter * \brief DiagnosticPrinter provides the interface to customize diagnostic * messages and output. */ -class DiagnosticPrinter -{ -public: +class DiagnosticPrinter { + public: DiagnosticPrinter(); virtual ~DiagnosticPrinter(); @@ -31,8 +30,7 @@ virtual void finish() {} - virtual void clear() - { m_NumErrors = m_NumWarnings = 0; } + virtual void clear() { m_NumErrors = m_NumWarnings = 0; } /// HandleDiagnostic - Handle this diagnostic, reporting it to the user or /// capturing it to a log as needed. @@ -42,12 +40,11 @@ unsigned int getNumErrors() const { return m_NumErrors; } unsigned int getNumWarnings() const { return m_NumWarnings; } -protected: + protected: unsigned int m_NumErrors; unsigned int m_NumWarnings; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_DIAGNOSTICPRINTER_H_
diff --git a/include/mcld/LD/DynObjFileFormat.h b/include/mcld/LD/DynObjFileFormat.h index dbacdd0..bb1c252 100644 --- a/include/mcld/LD/DynObjFileFormat.h +++ b/include/mcld/LD/DynObjFileFormat.h
@@ -6,21 +6,16 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_DYNOBJFILEFORMAT_H -#define MCLD_LD_DYNOBJFILEFORMAT_H +#ifndef MCLD_LD_DYNOBJFILEFORMAT_H_ +#define MCLD_LD_DYNOBJFILEFORMAT_H_ -namespace mcld -{ +namespace mcld { /** \class DynObjFormat * \brief DynObjFormat describes the file format for dynamic objects. */ -class DynObjFormat : public LDFileFormat -{ +class DynObjFormat : public LDFileFormat {}; -}; +} // namespace mcld -} // namespace of mcld - -#endif - +#endif // MCLD_LD_DYNOBJFILEFORMAT_H_
diff --git a/include/mcld/LD/DynObjReader.h b/include/mcld/LD/DynObjReader.h index 1817c4a..d313bf4 100644 --- a/include/mcld/LD/DynObjReader.h +++ b/include/mcld/LD/DynObjReader.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_DYNOBJREADER_H -#define MCLD_LD_DYNOBJREADER_H +#ifndef MCLD_LD_DYNOBJREADER_H_ +#define MCLD_LD_DYNOBJREADER_H_ #include "mcld/LD/LDReader.h" namespace mcld { @@ -19,22 +19,18 @@ * \brief DynObjReader provides an common interface for different object * formats. */ -class DynObjReader : public LDReader -{ -protected: - DynObjReader() - { } +class DynObjReader : public LDReader { + protected: + DynObjReader() {} -public: - virtual ~DynObjReader() { } + public: + virtual ~DynObjReader() {} virtual bool readHeader(Input& pFile) = 0; virtual bool readSymbols(Input& pFile) = 0; - }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_DYNOBJREADER_H_
diff --git a/include/mcld/LD/ELFBinaryReader.h b/include/mcld/LD/ELFBinaryReader.h index 117807e..f6fdfd4 100644 --- a/include/mcld/LD/ELFBinaryReader.h +++ b/include/mcld/LD/ELFBinaryReader.h
@@ -6,14 +6,13 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_ELFBINARYREADER_H -#define MCLD_LD_ELFBINARYREADER_H +#ifndef MCLD_LD_ELFBINARYREADER_H_ +#define MCLD_LD_ELFBINARYREADER_H_ -#include <mcld/LD/BinaryReader.h> +#include "mcld/LD/BinaryReader.h" namespace mcld { -class Module; class Input; class IRBuilder; class LinkerConfig; @@ -21,23 +20,21 @@ /** \lclass ELFBinaryReader * \brief ELFBinaryReader reads target-independent parts of Binary file */ -class ELFBinaryReader : public BinaryReader -{ -public: +class ELFBinaryReader : public BinaryReader { + public: ELFBinaryReader(IRBuilder& pBuilder, const LinkerConfig& pConfig); ~ELFBinaryReader(); - bool isMyFormat(Input& pInput, bool &pContinue) const; + bool isMyFormat(Input& pInput, bool& pContinue) const; bool readBinary(Input& pInput); -private: + private: IRBuilder& m_Builder; const LinkerConfig& m_Config; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ELFBINARYREADER_H_
diff --git a/include/mcld/LD/ELFDynObjFileFormat.h b/include/mcld/LD/ELFDynObjFileFormat.h index 8a18376..c239ca8 100644 --- a/include/mcld/LD/ELFDynObjFileFormat.h +++ b/include/mcld/LD/ELFDynObjFileFormat.h
@@ -6,9 +6,9 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_ELFDYNOBJFILEFROMAT_H -#define MCLD_LD_ELFDYNOBJFILEFROMAT_H -#include <mcld/LD/ELFFileFormat.h> +#ifndef MCLD_LD_ELFDYNOBJFILEFORMAT_H_ +#define MCLD_LD_ELFDYNOBJFILEFORMAT_H_ +#include "mcld/LD/ELFFileFormat.h" namespace mcld { @@ -17,14 +17,12 @@ /** \class ELFDynObjFileFormat * \brief ELFDynObjFileFormat describes the format for ELF dynamic objects. */ -class ELFDynObjFileFormat : public ELFFileFormat -{ +class ELFDynObjFileFormat : public ELFFileFormat { /// initObjectFormat - initialize sections that are dependent on shared /// objects. void initObjectFormat(ObjectBuilder& pBuilder, unsigned int pBitClass); }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ELFDYNOBJFILEFORMAT_H_
diff --git a/include/mcld/LD/ELFDynObjReader.h b/include/mcld/LD/ELFDynObjReader.h index 0beeecd..fdf9608 100644 --- a/include/mcld/LD/ELFDynObjReader.h +++ b/include/mcld/LD/ELFDynObjReader.h
@@ -6,44 +6,42 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_ELFDYNOBJREADER_H -#define MCLD_LD_ELFDYNOBJREADER_H -#include <mcld/LD/DynObjReader.h> +#ifndef MCLD_LD_ELFDYNOBJREADER_H_ +#define MCLD_LD_ELFDYNOBJREADER_H_ +#include "mcld/LD/DynObjReader.h" namespace mcld { -class Input; -class LinkerConfig; -class IRBuilder; -class GNULDBackend; class ELFReaderIF; +class GNULDBackend; +class Input; +class IRBuilder; +class LinkerConfig; /** \class ELFDynObjReader * \brief ELFDynObjReader reads ELF dynamic shared objects. * */ -class ELFDynObjReader : public DynObjReader -{ -public: +class ELFDynObjReader : public DynObjReader { + public: ELFDynObjReader(GNULDBackend& pBackend, IRBuilder& pBuilder, const LinkerConfig& pConfig); ~ELFDynObjReader(); // ----- observers ----- // - bool isMyFormat(Input &pFile, bool &pContinue) const; + bool isMyFormat(Input& pFile, bool& pContinue) const; // ----- readers ----- // bool readHeader(Input& pFile); bool readSymbols(Input& pInput); -private: - ELFReaderIF *m_pELFReader; + private: + ELFReaderIF* m_pELFReader; IRBuilder& m_Builder; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ELFDYNOBJREADER_H_
diff --git a/include/mcld/LD/ELFExecFileFormat.h b/include/mcld/LD/ELFExecFileFormat.h index 9279069..a37bac9 100644 --- a/include/mcld/LD/ELFExecFileFormat.h +++ b/include/mcld/LD/ELFExecFileFormat.h
@@ -6,9 +6,9 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ELF_EXEC_FILE_FORMAT_H -#define MCLD_ELF_EXEC_FILE_FORMAT_H -#include <mcld/LD/ELFFileFormat.h> +#ifndef MCLD_LD_ELFEXECFILEFORMAT_H_ +#define MCLD_LD_ELFEXECFILEFORMAT_H_ +#include "mcld/LD/ELFFileFormat.h" namespace mcld { @@ -17,14 +17,12 @@ /** \class ELFExecFileFormat * \brief ELFExecFileFormat describes the format for ELF dynamic objects. */ -class ELFExecFileFormat : public ELFFileFormat -{ +class ELFExecFileFormat : public ELFFileFormat { /// initObjectFormat - initialize sections that are dependent on executable /// objects. void initObjectFormat(ObjectBuilder& pBuilder, unsigned int pBitClass); }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ELFEXECFILEFORMAT_H_
diff --git a/include/mcld/LD/ELFFileFormat.h b/include/mcld/LD/ELFFileFormat.h index 360ff5a..5bb664c 100644 --- a/include/mcld/LD/ELFFileFormat.h +++ b/include/mcld/LD/ELFFileFormat.h
@@ -6,10 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ELF_FILE_FORMAT_H -#define MCLD_ELF_FILE_FORMAT_H -#include <mcld/LD/LDFileFormat.h> -#include <mcld/LD/LDSection.h> +#ifndef MCLD_LD_ELFFILEFORMAT_H_ +#define MCLD_LD_ELFFILEFORMAT_H_ +#include "mcld/LD/LDFileFormat.h" +#include "mcld/LD/LDSection.h" namespace mcld { @@ -25,683 +25,707 @@ * @ref "Object Format," Ch. 10, in ISO/IEC 23360 Part 1:2010(E), Linux * Standard Base Core Specification 4.1. */ -class ELFFileFormat : public LDFileFormat -{ -private: +class ELFFileFormat : public LDFileFormat { + private: /// initObjectFormat - initialize sections that are dependent on object /// formats. (executable, shared objects or relocatable objects). - virtual void - initObjectFormat(ObjectBuilder& pBuilder, unsigned int pBitClass) = 0; + virtual void initObjectFormat(ObjectBuilder& pBuilder, + unsigned int pBitClass) = 0; -public: + public: ELFFileFormat(); void initStdSections(ObjectBuilder& pBuilder, unsigned int pBitClass); // ----- capacity ----- // /// @ref Special Sections, Ch. 4.17, System V ABI, 4th edition. - bool hasNULLSection() const - { return (NULL != f_pNULLSection) && (0 != f_pNULLSection->size()); } + bool hasNULLSection() const { + return (f_pNULLSection != NULL) && (f_pNULLSection->size() != 0); + } - bool hasGOT() const - { return (NULL != f_pGOT) && (0 != f_pGOT->size()); } + bool hasGOT() const { return (f_pGOT != NULL) && (f_pGOT->size() != 0); } - bool hasPLT() const - { return (NULL != f_pPLT) && (0 != f_pPLT->size()); } + bool hasPLT() const { return (f_pPLT != NULL) && (f_pPLT->size() != 0); } - bool hasRelDyn() const - { return (NULL != f_pRelDyn) && (0 != f_pRelDyn->size()); } + bool hasRelDyn() const { + return (f_pRelDyn != NULL) && (f_pRelDyn->size() != 0); + } - bool hasRelPlt() const - { return (NULL != f_pRelPlt) && (0 != f_pRelPlt->size()); } + bool hasRelPlt() const { + return (f_pRelPlt != NULL) && (f_pRelPlt->size() != 0); + } - bool hasRelaDyn() const - { return (NULL != f_pRelaDyn) && (0 != f_pRelaDyn->size()); } + bool hasRelaDyn() const { + return (f_pRelaDyn != NULL) && (f_pRelaDyn->size() != 0); + } - bool hasRelaPlt() const - { return (NULL != f_pRelaPlt) && (0 != f_pRelaPlt->size()); } + bool hasRelaPlt() const { + return (f_pRelaPlt != NULL) && (f_pRelaPlt->size() != 0); + } /// @ref 10.3.1.1, ISO/IEC 23360, Part 1:2010(E), p. 21. - bool hasComment() const - { return (NULL != f_pComment) && (0 != f_pComment->size()); } + bool hasComment() const { + return (f_pComment != NULL) && (f_pComment->size() != 0); + } - bool hasData1() const - { return (NULL != f_pData1) && (0 != f_pData1->size()); } + bool hasData1() const { + return (f_pData1 != NULL) && (f_pData1->size() != 0); + } - bool hasDebug() const - { return (NULL != f_pDebug) && (0 != f_pDebug->size()); } + bool hasDebug() const { + return (f_pDebug != NULL) && (f_pDebug->size() != 0); + } - bool hasDynamic() const - { return (NULL != f_pDynamic) && (0 != f_pDynamic->size()); } + bool hasDynamic() const { + return (f_pDynamic != NULL) && (f_pDynamic->size() != 0); + } - bool hasDynStrTab() const - { return (NULL != f_pDynStrTab) && (0 != f_pDynStrTab->size()); } + bool hasDynStrTab() const { + return (f_pDynStrTab != NULL) && (f_pDynStrTab->size() != 0); + } - bool hasDynSymTab() const - { return (NULL != f_pDynSymTab) && (0 != f_pDynSymTab->size()); } + bool hasDynSymTab() const { + return (f_pDynSymTab != NULL) && (f_pDynSymTab->size() != 0); + } - bool hasFini() const - { return (NULL != f_pFini) && (0 != f_pFini->size()); } + bool hasFini() const { return (f_pFini != NULL) && (f_pFini->size() != 0); } - bool hasFiniArray() const - { return (NULL != f_pFiniArray) && (0 != f_pFiniArray->size()); } + bool hasFiniArray() const { + return (f_pFiniArray != NULL) && (f_pFiniArray->size() != 0); + } - bool hasHashTab() const - { return (NULL != f_pHashTab) && (0 != f_pHashTab->size()); } + bool hasHashTab() const { + return (f_pHashTab != NULL) && (f_pHashTab->size() != 0); + } - bool hasInit() const - { return (NULL != f_pInit) && (0 != f_pInit->size()); } + bool hasInit() const { return (f_pInit != NULL) && (f_pInit->size() != 0); } - bool hasInitArray() const - { return (NULL != f_pInitArray) && (0 != f_pInitArray->size()); } + bool hasInitArray() const { + return (f_pInitArray != NULL) && (f_pInitArray->size() != 0); + } - bool hasInterp() const - { return (NULL != f_pInterp) && (0 != f_pInterp->size()); } + bool hasInterp() const { + return (f_pInterp != NULL) && (f_pInterp->size() != 0); + } - bool hasLine() const - { return (NULL != f_pLine) && (0 != f_pLine->size()); } + bool hasLine() const { return (f_pLine != NULL) && (f_pLine->size() != 0); } - bool hasNote() const - { return (NULL != f_pNote) && (0 != f_pNote->size()); } + bool hasNote() const { return (f_pNote != NULL) && (f_pNote->size() != 0); } - bool hasPreInitArray() const - { return (NULL != f_pPreInitArray) && (0 != f_pPreInitArray->size()); } + bool hasPreInitArray() const { + return (f_pPreInitArray != NULL) && (f_pPreInitArray->size() != 0); + } - bool hasROData1() const - { return (NULL != f_pROData1) && (0 != f_pROData1->size()); } + bool hasROData1() const { + return (f_pROData1 != NULL) && (f_pROData1->size() != 0); + } - bool hasShStrTab() const - { return (NULL != f_pShStrTab) && (0 != f_pShStrTab->size()); } + bool hasShStrTab() const { + return (f_pShStrTab != NULL) && (f_pShStrTab->size() != 0); + } - bool hasStrTab() const - { return (NULL != f_pStrTab) && (0 != f_pStrTab->size()); } + bool hasStrTab() const { + return (f_pStrTab != NULL) && (f_pStrTab->size() != 0); + } - bool hasSymTab() const - { return (NULL != f_pSymTab) && (0 != f_pSymTab->size()); } + bool hasSymTab() const { + return (f_pSymTab != NULL) && (f_pSymTab->size() != 0); + } - bool hasTBSS() const - { return (NULL != f_pTBSS) && (0 != f_pTBSS->size()); } + bool hasTBSS() const { return (f_pTBSS != NULL) && (f_pTBSS->size() != 0); } - bool hasTData() const - { return (NULL != f_pTData) && (0 != f_pTData->size()); } + bool hasTData() const { + return (f_pTData != NULL) && (f_pTData->size() != 0); + } /// @ref 10.3.1.2, ISO/IEC 23360, Part 1:2010(E), p. 24. - bool hasCtors() const - { return (NULL != f_pCtors) && (0 != f_pCtors->size()); } + bool hasCtors() const { + return (f_pCtors != NULL) && (f_pCtors->size() != 0); + } - bool hasDataRelRo() const - { return (NULL != f_pDataRelRo) && (0 != f_pDataRelRo->size()); } + bool hasDataRelRo() const { + return (f_pDataRelRo != NULL) && (f_pDataRelRo->size() != 0); + } - bool hasDtors() const - { return (NULL != f_pDtors) && (0 != f_pDtors->size()); } + bool hasDtors() const { + return (f_pDtors != NULL) && (f_pDtors->size() != 0); + } - bool hasEhFrame() const - { return (NULL != f_pEhFrame) && (0 != f_pEhFrame->size()); } + bool hasEhFrame() const { + return (f_pEhFrame != NULL) && (f_pEhFrame->size() != 0); + } - bool hasEhFrameHdr() const - { return (NULL != f_pEhFrameHdr) && (0 != f_pEhFrameHdr->size()); } + bool hasEhFrameHdr() const { + return (f_pEhFrameHdr != NULL) && (f_pEhFrameHdr->size() != 0); + } - bool hasGCCExceptTable() const - { return (NULL != f_pGCCExceptTable) && (0 != f_pGCCExceptTable->size()); } + bool hasGCCExceptTable() const { + return (f_pGCCExceptTable != NULL) && (f_pGCCExceptTable->size() != 0); + } - bool hasGNUVersion() const - { return (NULL != f_pGNUVersion) && (0 != f_pGNUVersion->size()); } + bool hasGNUVersion() const { + return (f_pGNUVersion != NULL) && (f_pGNUVersion->size() != 0); + } - bool hasGNUVersionD() const - { return (NULL != f_pGNUVersionD) && (0 != f_pGNUVersionD->size()); } + bool hasGNUVersionD() const { + return (f_pGNUVersionD != NULL) && (f_pGNUVersionD->size() != 0); + } - bool hasGNUVersionR() const - { return (NULL != f_pGNUVersionR) && (0 != f_pGNUVersionR->size()); } + bool hasGNUVersionR() const { + return (f_pGNUVersionR != NULL) && (f_pGNUVersionR->size() != 0); + } - bool hasGOTPLT() const - { return (NULL != f_pGOTPLT) && (0 != f_pGOTPLT->size()); } + bool hasGOTPLT() const { + return (f_pGOTPLT != NULL) && (f_pGOTPLT->size() != 0); + } - bool hasJCR() const - { return (NULL != f_pJCR) && (0 != f_pJCR->size()); } + bool hasJCR() const { return (f_pJCR != NULL) && (f_pJCR->size() != 0); } - bool hasNoteABITag() const - { return (NULL != f_pNoteABITag) && (0 != f_pNoteABITag->size()); } + bool hasNoteABITag() const { + return (f_pNoteABITag != NULL) && (f_pNoteABITag->size() != 0); + } - bool hasStab() const - { return (NULL != f_pStab) && (0 != f_pStab->size()); } + bool hasStab() const { return (f_pStab != NULL) && (f_pStab->size() != 0); } - bool hasStabStr() const - { return (NULL != f_pStabStr) && (0 != f_pStabStr->size()); } + bool hasStabStr() const { + return (f_pStabStr != NULL) && (f_pStabStr->size() != 0); + } - bool hasStack() const - { return (NULL != f_pStack) && (0 != f_pStack->size()); } + bool hasStack() const { + return (f_pStack != NULL) && (f_pStack->size() != 0); + } - bool hasStackNote() const - { return (NULL != f_pStackNote); } + bool hasStackNote() const { return (f_pStackNote != NULL); } - bool hasDataRelRoLocal() const - { return (NULL != f_pDataRelRoLocal) && (0 != f_pDataRelRoLocal->size()); } + bool hasDataRelRoLocal() const { + return (f_pDataRelRoLocal != NULL) && (f_pDataRelRoLocal->size() != 0); + } - bool hasGNUHashTab() const - { return (NULL != f_pGNUHashTab) && (0 != f_pGNUHashTab->size()); } + bool hasGNUHashTab() const { + return (f_pGNUHashTab != NULL) && (f_pGNUHashTab->size() != 0); + } // ----- access functions ----- // /// @ref Special Sections, Ch. 4.17, System V ABI, 4th edition. LDSection& getNULLSection() { - assert(NULL != f_pNULLSection); + assert(f_pNULLSection != NULL); return *f_pNULLSection; } const LDSection& getNULLSection() const { - assert(NULL != f_pNULLSection); + assert(f_pNULLSection != NULL); return *f_pNULLSection; } LDSection& getGOT() { - assert(NULL != f_pGOT); + assert(f_pGOT != NULL); return *f_pGOT; } const LDSection& getGOT() const { - assert(NULL != f_pGOT); + assert(f_pGOT != NULL); return *f_pGOT; } LDSection& getPLT() { - assert(NULL != f_pPLT); + assert(f_pPLT != NULL); return *f_pPLT; } const LDSection& getPLT() const { - assert(NULL != f_pPLT); + assert(f_pPLT != NULL); return *f_pPLT; } LDSection& getRelDyn() { - assert(NULL != f_pRelDyn); + assert(f_pRelDyn != NULL); return *f_pRelDyn; } const LDSection& getRelDyn() const { - assert(NULL != f_pRelDyn); + assert(f_pRelDyn != NULL); return *f_pRelDyn; } LDSection& getRelPlt() { - assert(NULL != f_pRelPlt); + assert(f_pRelPlt != NULL); return *f_pRelPlt; } const LDSection& getRelPlt() const { - assert(NULL != f_pRelPlt); + assert(f_pRelPlt != NULL); return *f_pRelPlt; } LDSection& getRelaDyn() { - assert(NULL != f_pRelaDyn); + assert(f_pRelaDyn != NULL); return *f_pRelaDyn; } const LDSection& getRelaDyn() const { - assert(NULL != f_pRelaDyn); + assert(f_pRelaDyn != NULL); return *f_pRelaDyn; } LDSection& getRelaPlt() { - assert(NULL != f_pRelaPlt); + assert(f_pRelaPlt != NULL); return *f_pRelaPlt; } const LDSection& getRelaPlt() const { - assert(NULL != f_pRelaPlt); + assert(f_pRelaPlt != NULL); return *f_pRelaPlt; } LDSection& getComment() { - assert(NULL != f_pComment); + assert(f_pComment != NULL); return *f_pComment; } /// @ref 10.3.1.1, ISO/IEC 23360, Part 1:2010(E), p. 21. const LDSection& getComment() const { - assert(NULL != f_pComment); + assert(f_pComment != NULL); return *f_pComment; } LDSection& getData1() { - assert(NULL != f_pData1); + assert(f_pData1 != NULL); return *f_pData1; } const LDSection& getData1() const { - assert(NULL != f_pData1); + assert(f_pData1 != NULL); return *f_pData1; } LDSection& getDebug() { - assert(NULL != f_pDebug); + assert(f_pDebug != NULL); return *f_pDebug; } const LDSection& getDebug() const { - assert(NULL != f_pDebug); + assert(f_pDebug != NULL); return *f_pDebug; } LDSection& getDynamic() { - assert(NULL != f_pDynamic); + assert(f_pDynamic != NULL); return *f_pDynamic; } const LDSection& getDynamic() const { - assert(NULL != f_pDynamic); + assert(f_pDynamic != NULL); return *f_pDynamic; } LDSection& getDynStrTab() { - assert(NULL != f_pDynStrTab); + assert(f_pDynStrTab != NULL); return *f_pDynStrTab; } const LDSection& getDynStrTab() const { - assert(NULL != f_pDynStrTab); + assert(f_pDynStrTab != NULL); return *f_pDynStrTab; } LDSection& getDynSymTab() { - assert(NULL != f_pDynSymTab); + assert(f_pDynSymTab != NULL); return *f_pDynSymTab; } const LDSection& getDynSymTab() const { - assert(NULL != f_pDynSymTab); + assert(f_pDynSymTab != NULL); return *f_pDynSymTab; } LDSection& getFini() { - assert(NULL != f_pFini); + assert(f_pFini != NULL); return *f_pFini; } const LDSection& getFini() const { - assert(NULL != f_pFini); + assert(f_pFini != NULL); return *f_pFini; } LDSection& getFiniArray() { - assert(NULL != f_pFiniArray); + assert(f_pFiniArray != NULL); return *f_pFiniArray; } const LDSection& getFiniArray() const { - assert(NULL != f_pFiniArray); + assert(f_pFiniArray != NULL); return *f_pFiniArray; } LDSection& getHashTab() { - assert(NULL != f_pHashTab); + assert(f_pHashTab != NULL); return *f_pHashTab; } const LDSection& getHashTab() const { - assert(NULL != f_pHashTab); + assert(f_pHashTab != NULL); return *f_pHashTab; } LDSection& getInit() { - assert(NULL != f_pInit); + assert(f_pInit != NULL); return *f_pInit; } const LDSection& getInit() const { - assert(NULL != f_pInit); + assert(f_pInit != NULL); return *f_pInit; } LDSection& getInitArray() { - assert(NULL != f_pInitArray); + assert(f_pInitArray != NULL); return *f_pInitArray; } const LDSection& getInitArray() const { - assert(NULL != f_pInitArray); + assert(f_pInitArray != NULL); return *f_pInitArray; } LDSection& getInterp() { - assert(NULL != f_pInterp); + assert(f_pInterp != NULL); return *f_pInterp; } const LDSection& getInterp() const { - assert(NULL != f_pInterp); + assert(f_pInterp != NULL); return *f_pInterp; } LDSection& getLine() { - assert(NULL != f_pLine); + assert(f_pLine != NULL); return *f_pLine; } const LDSection& getLine() const { - assert(NULL != f_pLine); + assert(f_pLine != NULL); return *f_pLine; } LDSection& getNote() { - assert(NULL != f_pNote); + assert(f_pNote != NULL); return *f_pNote; } const LDSection& getNote() const { - assert(NULL != f_pNote); + assert(f_pNote != NULL); return *f_pNote; } LDSection& getPreInitArray() { - assert(NULL != f_pPreInitArray); + assert(f_pPreInitArray != NULL); return *f_pPreInitArray; } const LDSection& getPreInitArray() const { - assert(NULL != f_pPreInitArray); + assert(f_pPreInitArray != NULL); return *f_pPreInitArray; } LDSection& getROData1() { - assert(NULL != f_pROData1); + assert(f_pROData1 != NULL); return *f_pROData1; } const LDSection& getROData1() const { - assert(NULL != f_pROData1); + assert(f_pROData1 != NULL); return *f_pROData1; } LDSection& getShStrTab() { - assert(NULL != f_pShStrTab); + assert(f_pShStrTab != NULL); return *f_pShStrTab; } const LDSection& getShStrTab() const { - assert(NULL != f_pShStrTab); + assert(f_pShStrTab != NULL); return *f_pShStrTab; } LDSection& getStrTab() { - assert(NULL != f_pStrTab); + assert(f_pStrTab != NULL); return *f_pStrTab; } const LDSection& getStrTab() const { - assert(NULL != f_pStrTab); + assert(f_pStrTab != NULL); return *f_pStrTab; } LDSection& getSymTab() { - assert(NULL != f_pSymTab); + assert(f_pSymTab != NULL); return *f_pSymTab; } const LDSection& getSymTab() const { - assert(NULL != f_pSymTab); + assert(f_pSymTab != NULL); return *f_pSymTab; } LDSection& getTBSS() { - assert(NULL != f_pTBSS); + assert(f_pTBSS != NULL); return *f_pTBSS; } const LDSection& getTBSS() const { - assert(NULL != f_pTBSS); + assert(f_pTBSS != NULL); return *f_pTBSS; } LDSection& getTData() { - assert(NULL != f_pTData); + assert(f_pTData != NULL); return *f_pTData; } const LDSection& getTData() const { - assert(NULL != f_pTData); + assert(f_pTData != NULL); return *f_pTData; } /// @ref 10.3.1.2, ISO/IEC 23360, Part 1:2010(E), p. 24. LDSection& getCtors() { - assert(NULL != f_pCtors); + assert(f_pCtors != NULL); return *f_pCtors; } const LDSection& getCtors() const { - assert(NULL != f_pCtors); + assert(f_pCtors != NULL); return *f_pCtors; } LDSection& getDataRelRo() { - assert(NULL != f_pDataRelRo); + assert(f_pDataRelRo != NULL); return *f_pDataRelRo; } const LDSection& getDataRelRo() const { - assert(NULL != f_pDataRelRo); + assert(f_pDataRelRo != NULL); return *f_pDataRelRo; } LDSection& getDtors() { - assert(NULL != f_pDtors); + assert(f_pDtors != NULL); return *f_pDtors; } const LDSection& getDtors() const { - assert(NULL != f_pDtors); + assert(f_pDtors != NULL); return *f_pDtors; } LDSection& getEhFrame() { - assert(NULL != f_pEhFrame); + assert(f_pEhFrame != NULL); return *f_pEhFrame; } const LDSection& getEhFrame() const { - assert(NULL != f_pEhFrame); + assert(f_pEhFrame != NULL); return *f_pEhFrame; } LDSection& getEhFrameHdr() { - assert(NULL != f_pEhFrameHdr); + assert(f_pEhFrameHdr != NULL); return *f_pEhFrameHdr; } const LDSection& getEhFrameHdr() const { - assert(NULL != f_pEhFrameHdr); + assert(f_pEhFrameHdr != NULL); return *f_pEhFrameHdr; } LDSection& getGCCExceptTable() { - assert(NULL != f_pGCCExceptTable); + assert(f_pGCCExceptTable != NULL); return *f_pGCCExceptTable; } const LDSection& getGCCExceptTable() const { - assert(NULL != f_pGCCExceptTable); + assert(f_pGCCExceptTable != NULL); return *f_pGCCExceptTable; } LDSection& getGNUVersion() { - assert(NULL != f_pGNUVersion); + assert(f_pGNUVersion != NULL); return *f_pGNUVersion; } const LDSection& getGNUVersion() const { - assert(NULL != f_pGNUVersion); + assert(f_pGNUVersion != NULL); return *f_pGNUVersion; } LDSection& getGNUVersionD() { - assert(NULL != f_pGNUVersionD); + assert(f_pGNUVersionD != NULL); return *f_pGNUVersionD; } const LDSection& getGNUVersionD() const { - assert(NULL != f_pGNUVersionD); + assert(f_pGNUVersionD != NULL); return *f_pGNUVersionD; } LDSection& getGNUVersionR() { - assert(NULL != f_pGNUVersionR); + assert(f_pGNUVersionR != NULL); return *f_pGNUVersionR; } const LDSection& getGNUVersionR() const { - assert(NULL != f_pGNUVersionR); + assert(f_pGNUVersionR != NULL); return *f_pGNUVersionR; } LDSection& getGOTPLT() { - assert(NULL != f_pGOTPLT); + assert(f_pGOTPLT != NULL); return *f_pGOTPLT; } const LDSection& getGOTPLT() const { - assert(NULL != f_pGOTPLT); + assert(f_pGOTPLT != NULL); return *f_pGOTPLT; } LDSection& getJCR() { - assert(NULL != f_pJCR); + assert(f_pJCR != NULL); return *f_pJCR; } const LDSection& getJCR() const { - assert(NULL != f_pJCR); + assert(f_pJCR != NULL); return *f_pJCR; } LDSection& getNoteABITag() { - assert(NULL != f_pNoteABITag); + assert(f_pNoteABITag != NULL); return *f_pNoteABITag; } const LDSection& getNoteABITag() const { - assert(NULL != f_pNoteABITag); + assert(f_pNoteABITag != NULL); return *f_pNoteABITag; } LDSection& getStab() { - assert(NULL != f_pStab); + assert(f_pStab != NULL); return *f_pStab; } const LDSection& getStab() const { - assert(NULL != f_pStab); + assert(f_pStab != NULL); return *f_pStab; } LDSection& getStabStr() { - assert(NULL != f_pStabStr); + assert(f_pStabStr != NULL); return *f_pStabStr; } const LDSection& getStabStr() const { - assert(NULL != f_pStabStr); + assert(f_pStabStr != NULL); return *f_pStabStr; } LDSection& getStack() { - assert(NULL != f_pStack); + assert(f_pStack != NULL); return *f_pStack; } const LDSection& getStack() const { - assert(NULL != f_pStack); + assert(f_pStack != NULL); return *f_pStack; } LDSection& getStackNote() { - assert(NULL != f_pStackNote); + assert(f_pStackNote != NULL); return *f_pStackNote; } const LDSection& getStackNote() const { - assert(NULL != f_pStackNote); + assert(f_pStackNote != NULL); return *f_pStackNote; } LDSection& getDataRelRoLocal() { - assert(NULL != f_pDataRelRoLocal); + assert(f_pDataRelRoLocal != NULL); return *f_pDataRelRoLocal; } const LDSection& getDataRelRoLocal() const { - assert(NULL != f_pDataRelRoLocal); + assert(f_pDataRelRoLocal != NULL); return *f_pDataRelRoLocal; } LDSection& getGNUHashTab() { - assert(NULL != f_pGNUHashTab); + assert(f_pGNUHashTab != NULL); return *f_pGNUHashTab; } const LDSection& getGNUHashTab() const { - assert(NULL != f_pGNUHashTab); + assert(f_pGNUHashTab != NULL); return *f_pGNUHashTab; } -protected: + protected: // variable name : ELF /// @ref Special Sections, Ch. 4.17, System V ABI, 4th edition. LDSection* f_pNULLSection; - LDSection* f_pGOT; // .got - LDSection* f_pPLT; // .plt - LDSection* f_pRelDyn; // .rel.dyn - LDSection* f_pRelPlt; // .rel.plt - LDSection* f_pRelaDyn; // .rela.dyn - LDSection* f_pRelaPlt; // .rela.plt + LDSection* f_pGOT; // .got + LDSection* f_pPLT; // .plt + LDSection* f_pRelDyn; // .rel.dyn + LDSection* f_pRelPlt; // .rel.plt + LDSection* f_pRelaDyn; // .rela.dyn + LDSection* f_pRelaPlt; // .rela.plt /// @ref 10.3.1.1, ISO/IEC 23360, Part 1:2010(E), p. 21. - LDSection* f_pComment; // .comment - LDSection* f_pData1; // .data1 - LDSection* f_pDebug; // .debug - LDSection* f_pDynamic; // .dynamic - LDSection* f_pDynStrTab; // .dynstr - LDSection* f_pDynSymTab; // .dynsym - LDSection* f_pFini; // .fini - LDSection* f_pFiniArray; // .fini_array - LDSection* f_pHashTab; // .hash - LDSection* f_pInit; // .init - LDSection* f_pInitArray; // .init_array - LDSection* f_pInterp; // .interp - LDSection* f_pLine; // .line - LDSection* f_pNote; // .note - LDSection* f_pPreInitArray; // .preinit_array - LDSection* f_pROData1; // .rodata1 - LDSection* f_pShStrTab; // .shstrtab - LDSection* f_pStrTab; // .strtab - LDSection* f_pSymTab; // .symtab - LDSection* f_pTBSS; // .tbss - LDSection* f_pTData; // .tdata + LDSection* f_pComment; // .comment + LDSection* f_pData1; // .data1 + LDSection* f_pDebug; // .debug + LDSection* f_pDynamic; // .dynamic + LDSection* f_pDynStrTab; // .dynstr + LDSection* f_pDynSymTab; // .dynsym + LDSection* f_pFini; // .fini + LDSection* f_pFiniArray; // .fini_array + LDSection* f_pHashTab; // .hash + LDSection* f_pInit; // .init + LDSection* f_pInitArray; // .init_array + LDSection* f_pInterp; // .interp + LDSection* f_pLine; // .line + LDSection* f_pNote; // .note + LDSection* f_pPreInitArray; // .preinit_array + LDSection* f_pROData1; // .rodata1 + LDSection* f_pShStrTab; // .shstrtab + LDSection* f_pStrTab; // .strtab + LDSection* f_pSymTab; // .symtab + LDSection* f_pTBSS; // .tbss + LDSection* f_pTData; // .tdata /// @ref 10.3.1.2, ISO/IEC 23360, Part 1:2010(E), p. 24. - LDSection* f_pCtors; // .ctors - LDSection* f_pDataRelRo; // .data.rel.ro - LDSection* f_pDtors; // .dtors - LDSection* f_pEhFrame; // .eh_frame - LDSection* f_pEhFrameHdr; // .eh_frame_hdr - LDSection* f_pGCCExceptTable; // .gcc_except_table - LDSection* f_pGNUVersion; // .gnu.version - LDSection* f_pGNUVersionD; // .gnu.version_d - LDSection* f_pGNUVersionR; // .gnu.version_r - LDSection* f_pGOTPLT; // .got.plt - LDSection* f_pJCR; // .jcr - LDSection* f_pNoteABITag; // .note.ABI-tag - LDSection* f_pStab; // .stab - LDSection* f_pStabStr; // .stabstr + LDSection* f_pCtors; // .ctors + LDSection* f_pDataRelRo; // .data.rel.ro + LDSection* f_pDtors; // .dtors + LDSection* f_pEhFrame; // .eh_frame + LDSection* f_pEhFrameHdr; // .eh_frame_hdr + LDSection* f_pGCCExceptTable; // .gcc_except_table + LDSection* f_pGNUVersion; // .gnu.version + LDSection* f_pGNUVersionD; // .gnu.version_d + LDSection* f_pGNUVersionR; // .gnu.version_r + LDSection* f_pGOTPLT; // .got.plt + LDSection* f_pJCR; // .jcr + LDSection* f_pNoteABITag; // .note.ABI-tag + LDSection* f_pStab; // .stab + LDSection* f_pStabStr; // .stabstr /// practical - LDSection* f_pStack; // .stack - LDSection* f_pStackNote; // .note.GNU-stack - LDSection* f_pDataRelRoLocal; // .data.rel.ro.local - LDSection* f_pGNUHashTab; // .gnu.hash + LDSection* f_pStack; // .stack + LDSection* f_pStackNote; // .note.GNU-stack + LDSection* f_pDataRelRoLocal; // .data.rel.ro.local + LDSection* f_pGNUHashTab; // .gnu.hash }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ELFFILEFORMAT_H_
diff --git a/include/mcld/LD/ELFObjectFileFormat.h b/include/mcld/LD/ELFObjectFileFormat.h index 45e3ca2..9ca7713 100644 --- a/include/mcld/LD/ELFObjectFileFormat.h +++ b/include/mcld/LD/ELFObjectFileFormat.h
@@ -6,9 +6,9 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ELF_OBJECT_FILE_FROMAT_H -#define MCLD_ELF_OBJECT_FILE_FROMAT_H -#include <mcld/LD/ELFFileFormat.h> +#ifndef MCLD_LD_ELFOBJECTFILEFORMAT_H_ +#define MCLD_LD_ELFOBJECTFILEFORMAT_H_ +#include "mcld/LD/ELFFileFormat.h" namespace mcld { @@ -17,15 +17,13 @@ /** \class ELFObjectFileFormat * \brief ELFObjectFileFormat describes the format for ELF dynamic objects. */ -class ELFObjectFileFormat : public ELFFileFormat -{ +class ELFObjectFileFormat : public ELFFileFormat { void initObjectFormat(ObjectBuilder& pBuilder, unsigned int pBitClass) { // do nothing return; } }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ELFOBJECTFILEFORMAT_H_
diff --git a/include/mcld/LD/ELFObjectReader.h b/include/mcld/LD/ELFObjectReader.h index 4449234..a892e02 100644 --- a/include/mcld/LD/ELFObjectReader.h +++ b/include/mcld/LD/ELFObjectReader.h
@@ -6,36 +6,34 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_ELF_OBJECT_READER_H -#define MCLD_ELF_OBJECT_READER_H +#ifndef MCLD_LD_ELFOBJECTREADER_H_ +#define MCLD_LD_ELFOBJECTREADER_H_ -#include <mcld/LD/ObjectReader.h> -#include <mcld/ADT/Flags.h> +#include "mcld/ADT/Flags.h" +#include "mcld/LD/ObjectReader.h" namespace mcld { -class Module; +class EhFrameReader; +class ELFReaderIF; class Input; class IRBuilder; class GNULDBackend; -class ELFReaderIF; -class EhFrameReader; class LinkerConfig; /** \lclass ELFObjectReader * \brief ELFObjectReader reads target-independent parts of ELF object file */ -class ELFObjectReader : public ObjectReader -{ -public: +class ELFObjectReader : public ObjectReader { + public: enum ReadFlagType { - ParseEhFrame = 0x1, ///< parse .eh_frame section if the bit is set. - NumOfReadFlags = 1 + ParseEhFrame = 0x1, ///< parse .eh_frame section if the bit is set. + NumOfReadFlags = 1 }; typedef Flags<ReadFlagType> ReadFlag; -public: + public: ELFObjectReader(GNULDBackend& pBackend, IRBuilder& pBuilder, const LinkerConfig& pConfig); @@ -43,7 +41,7 @@ ~ELFObjectReader(); // ----- observers ----- // - bool isMyFormat(Input &pFile, bool &pContinue) const; + bool isMyFormat(Input& pFile, bool& pContinue) const; // ----- readers ----- // bool readHeader(Input& pFile); @@ -57,7 +55,7 @@ /// This function should be called after symbol resolution. virtual bool readRelocations(Input& pFile); -private: + private: ELFReaderIF* m_pELFReader; EhFrameReader* m_pEhFrameReader; IRBuilder& m_Builder; @@ -66,7 +64,6 @@ const LinkerConfig& m_Config; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ELFOBJECTREADER_H_
diff --git a/include/mcld/LD/ELFObjectWriter.h b/include/mcld/LD/ELFObjectWriter.h index b83fb01..8181b9f 100644 --- a/include/mcld/LD/ELFObjectWriter.h +++ b/include/mcld/LD/ELFObjectWriter.h
@@ -6,34 +6,30 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_ELFOBJWRITER_H -#define MCLD_LD_ELFOBJWRITER_H -#include <mcld/LD/ObjectWriter.h> -#include <cassert> +#ifndef MCLD_LD_ELFOBJECTWRITER_H_ +#define MCLD_LD_ELFOBJECTWRITER_H_ +#include "mcld/LD/ObjectWriter.h" +#include "mcld/Support/FileOutputBuffer.h" -#include <mcld/Support/FileOutputBuffer.h> +#include <cassert> namespace mcld { class EhFrame; -class Module; -class LinkerConfig; class GNULDBackend; -class FragmentLinker; -class Relocation; class LDSection; -class SectionData; +class LinkerConfig; +class Module; class RelocData; -class Output; +class SectionData; /** \class ELFObjectWriter * \brief ELFObjectWriter writes the target-independent parts of object files. * ELFObjectWriter reads a MCLDFile and writes into raw_ostream * */ -class ELFObjectWriter : public ObjectWriter -{ -public: +class ELFObjectWriter : public ObjectWriter { + public: ELFObjectWriter(GNULDBackend& pBackend, const LinkerConfig& pConfig); ~ELFObjectWriter(); @@ -42,16 +38,16 @@ size_t getOutputSize(const Module& pModule) const; -private: + private: void writeSection(Module& pModule, - FileOutputBuffer& pOutput, LDSection *section); + FileOutputBuffer& pOutput, + LDSection* section); - GNULDBackend& target() { return m_Backend; } - - const GNULDBackend& target() const { return m_Backend; } + const GNULDBackend& target() const { return m_Backend; } + GNULDBackend& target() { return m_Backend; } // writeELFHeader - emit ElfXX_Ehdr - template<size_t SIZE> + template <size_t SIZE> void writeELFHeader(const LinkerConfig& pConfig, const Module& pModule, FileOutputBuffer& pOutput) const; @@ -60,13 +56,13 @@ const Module& pModule) const; // emitSectionHeader - emit ElfXX_Shdr - template<size_t SIZE> + template <size_t SIZE> void emitSectionHeader(const Module& pModule, const LinkerConfig& pConfig, FileOutputBuffer& pOutput) const; // emitProgramHeader - emit ElfXX_Phdr - template<size_t SIZE> + template <size_t SIZE> void emitProgramHeader(FileOutputBuffer& pOutput) const; // emitShStrTab - emit .shstrtab @@ -77,26 +73,27 @@ void emitSectionData(const LDSection& pSection, MemoryRegion& pRegion) const; void emitEhFrame(Module& pModule, - EhFrame& pFrame, MemoryRegion& pRegion) const; + EhFrame& pFrame, + MemoryRegion& pRegion) const; void emitRelocation(const LinkerConfig& pConfig, const LDSection& pSection, MemoryRegion& pRegion) const; // emitRel - emit ElfXX_Rel - template<size_t SIZE> + template <size_t SIZE> void emitRel(const LinkerConfig& pConfig, const RelocData& pRelocData, MemoryRegion& pRegion) const; // emitRela - emit ElfXX_Rela - template<size_t SIZE> + template <size_t SIZE> void emitRela(const LinkerConfig& pConfig, const RelocData& pRelocData, MemoryRegion& pRegion) const; // getSectEntrySize - compute ElfXX_Shdr::sh_entsize - template<size_t SIZE> + template <size_t SIZE> uint64_t getSectEntrySize(const LDSection& pSection) const; // getSectLink - compute ElfXX_Shdr::sh_link @@ -106,28 +103,26 @@ // getSectInfo - compute ElfXX_Shdr::sh_info uint64_t getSectInfo(const LDSection& pSection) const; - template<size_t SIZE> - uint64_t getLastStartOffset(const Module& pModule) const - { + template <size_t SIZE> + uint64_t getLastStartOffset(const Module& pModule) const { assert(0 && "Call invalid ELFObjectWriter::getLastStartOffset"); return 0; } void emitSectionData(const SectionData& pSD, MemoryRegion& pRegion) const; -private: + private: GNULDBackend& m_Backend; const LinkerConfig& m_Config; }; -template<> +template <> uint64_t ELFObjectWriter::getLastStartOffset<32>(const Module& pModule) const; -template<> +template <> uint64_t ELFObjectWriter::getLastStartOffset<64>(const Module& pModule) const; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ELFOBJECTWRITER_H_
diff --git a/include/mcld/LD/ELFReader.h b/include/mcld/LD/ELFReader.h index afdb0b0..7cd91a5 100644 --- a/include/mcld/LD/ELFReader.h +++ b/include/mcld/LD/ELFReader.h
@@ -6,53 +6,49 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_ELFREADER_H -#define MCLD_LD_ELFREADER_H +#ifndef MCLD_LD_ELFREADER_H_ +#define MCLD_LD_ELFREADER_H_ + +#include "mcld/LD/ELFReaderIf.h" +#include "mcld/LD/LDSymbol.h" +#include "mcld/LD/ResolveInfo.h" +#include "mcld/Target/GNULDBackend.h" #include <llvm/ADT/StringRef.h> #include <llvm/Support/ELF.h> #include <llvm/Support/Host.h> -#include <mcld/LD/ELFReaderIf.h> -#include <mcld/LD/ResolveInfo.h> -#include <mcld/LD/LDSymbol.h> -#include <mcld/Target/GNULDBackend.h> - namespace mcld { -//class Module; class IRBuilder; -class SectionData; class LDSection; +class SectionData; /** \class ELFReader * \brief ELFReader is a template scaffolding for partial specification. */ -template<size_t BIT, bool LITTLEENDIAN> -class ELFReader -{ }; +template <size_t BIT, bool LITTLEENDIAN> +class ELFReader {}; /** \class ELFReader<32, true> * \brief ELFReader<32, true> is a 32-bit, little endian ELFReader. */ -template<> -class ELFReader<32, true> : public ELFReaderIF -{ -public: +template <> +class ELFReader<32, true> : public ELFReaderIF { + public: typedef llvm::ELF::Elf32_Ehdr ELFHeader; typedef llvm::ELF::Elf32_Shdr SectionHeader; - typedef llvm::ELF::Elf32_Sym Symbol; - typedef llvm::ELF::Elf32_Rel Rel; + typedef llvm::ELF::Elf32_Sym Symbol; + typedef llvm::ELF::Elf32_Rel Rel; typedef llvm::ELF::Elf32_Rela Rela; -public: - ELFReader(GNULDBackend& pBackend); + public: + explicit ELFReader(GNULDBackend& pBackend); ~ELFReader(); /// ELFHeaderSize - return the size of the ELFHeader - size_t getELFHeaderSize() const - { return sizeof(ELFHeader); } + size_t getELFHeaderSize() const { return sizeof(ELFHeader); } /// isELF - is this a ELF file bool isELF(const void* pELFHeader) const; @@ -97,52 +93,47 @@ /// readDynamic - read ELF .dynamic in input dynobj bool readDynamic(Input& pInput) const; -private: + private: struct AliasInfo { - LDSymbol* pt_alias; ///potential alias + LDSymbol* pt_alias; /// potential alias uint64_t ld_value; ResolveInfo::Binding ld_binding; }; /// comparison function to sort symbols for analyzing weak alias. /// sort symbols by symbol value and then weak before strong. - /// ref. to gold symtabl.cc 1595 static bool less(AliasInfo p1, AliasInfo p2) { if (p1.ld_value != p2.ld_value) return (p1.ld_value < p2.ld_value); if (p1.ld_binding != p2.ld_binding) { - if (ResolveInfo::Weak==p1.ld_binding) + if (ResolveInfo::Weak == p1.ld_binding) return true; - else if (ResolveInfo::Weak==p2.ld_binding) + else if (ResolveInfo::Weak == p2.ld_binding) return false; } return p1.pt_alias->str() < p2.pt_alias->str(); } - }; - /** \class ELFReader<64, true> * \brief ELFReader<64, true> is a 64-bit, little endian ELFReader. */ -template<> -class ELFReader<64, true> : public ELFReaderIF -{ -public: +template <> +class ELFReader<64, true> : public ELFReaderIF { + public: typedef llvm::ELF::Elf64_Ehdr ELFHeader; typedef llvm::ELF::Elf64_Shdr SectionHeader; - typedef llvm::ELF::Elf64_Sym Symbol; - typedef llvm::ELF::Elf64_Rel Rel; + typedef llvm::ELF::Elf64_Sym Symbol; + typedef llvm::ELF::Elf64_Rel Rel; typedef llvm::ELF::Elf64_Rela Rela; -public: - ELFReader(GNULDBackend& pBackend); + public: + explicit ELFReader(GNULDBackend& pBackend); ~ELFReader(); /// ELFHeaderSize - return the size of the ELFHeader - size_t getELFHeaderSize() const - { return sizeof(ELFHeader); } + size_t getELFHeaderSize() const { return sizeof(ELFHeader); } /// isELF - is this a ELF file bool isELF(const void* pELFHeader) const; @@ -187,31 +178,28 @@ /// readDynamic - read ELF .dynamic in input dynobj bool readDynamic(Input& pInput) const; -private: + private: struct AliasInfo { - LDSymbol* pt_alias; ///potential alias + LDSymbol* pt_alias; /// potential alias uint64_t ld_value; ResolveInfo::Binding ld_binding; }; /// comparison function to sort symbols for analyzing weak alias. /// sort symbols by symbol value and then weak before strong. - /// ref. to gold symtabl.cc 1595 static bool less(AliasInfo p1, AliasInfo p2) { if (p1.ld_value != p2.ld_value) return (p1.ld_value < p2.ld_value); if (p1.ld_binding != p2.ld_binding) { - if (ResolveInfo::Weak==p1.ld_binding) + if (ResolveInfo::Weak == p1.ld_binding) return true; - else if (ResolveInfo::Weak==p2.ld_binding) + else if (ResolveInfo::Weak == p2.ld_binding) return false; } return p1.pt_alias->str() < p2.pt_alias->str(); } - }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ELFREADER_H_
diff --git a/include/mcld/LD/ELFReaderIf.h b/include/mcld/LD/ELFReaderIf.h index 9fae24f..b359da1 100644 --- a/include/mcld/LD/ELFReaderIf.h +++ b/include/mcld/LD/ELFReaderIf.h
@@ -6,38 +6,32 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_ELFREADERIF_H -#define MCLD_LD_ELFREADERIF_H +#ifndef MCLD_LD_ELFREADERIF_H_ +#define MCLD_LD_ELFREADERIF_H_ + +#include "mcld/LinkerConfig.h" +#include "mcld/Support/MsgHandling.h" +#include "mcld/Target/GNULDBackend.h" #include <llvm/ADT/StringRef.h> #include <llvm/Support/ELF.h> #include <llvm/Support/Host.h> -#include <mcld/Module.h> -#include <mcld/LinkerConfig.h> -#include <mcld/LD/LDContext.h> -#include <mcld/Target/GNULDBackend.h> -#include <mcld/Support/MsgHandling.h> - namespace mcld { -class Module; class IRBuilder; class FragmentRef; -class SectionData; class LDSection; +class SectionData; /** \class ELFReaderIF * \brief ELFReaderIF provides common interface for all kind of ELF readers. */ -class ELFReaderIF -{ -public: - ELFReaderIF(GNULDBackend& pBackend) - : m_Backend(pBackend) - { } +class ELFReaderIF { + public: + explicit ELFReaderIF(GNULDBackend& pBackend) : m_Backend(pBackend) {} - virtual ~ELFReaderIF() { } + virtual ~ELFReaderIF() {} /// ELFHeaderSize - return the size of the ELFHeader virtual size_t getELFHeaderSize() const = 0; @@ -56,8 +50,7 @@ /// target - the target backend const GNULDBackend& target() const { return m_Backend; } - GNULDBackend& target() { return m_Backend; } - + GNULDBackend& target() { return m_Backend; } /// readSectionHeaders - read ELF section header table and create LDSections virtual bool readSectionHeaders(Input& pInput, @@ -91,7 +84,7 @@ /// readDynamic - read ELF .dynamic in input dynobj virtual bool readDynamic(Input& pInput) const = 0; -protected: + protected: /// LinkInfo - some section needs sh_link and sh_info, remember them. struct LinkInfo { LDSection* section; @@ -101,7 +94,7 @@ typedef std::vector<LinkInfo> LinkInfoList; -protected: + protected: ResolveInfo::Type getSymType(uint8_t pInfo, uint16_t pShndx) const; ResolveInfo::Desc getSymDesc(uint16_t pShndx, const Input& pInput) const; @@ -120,11 +113,10 @@ ResolveInfo::Visibility getSymVisibility(uint8_t pVis) const; -protected: + protected: GNULDBackend& m_Backend; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ELFREADERIF_H_
diff --git a/include/mcld/LD/ELFSegment.h b/include/mcld/LD/ELFSegment.h index cd86ecc..09fb612 100644 --- a/include/mcld/LD/ELFSegment.h +++ b/include/mcld/LD/ELFSegment.h
@@ -6,100 +6,92 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_ELFSEGMENT_H -#define MCLD_LD_ELFSEGMENT_H -#include <mcld/Support/Allocators.h> -#include <mcld/Config/Config.h> -#include <llvm/Support/ELF.h> +#ifndef MCLD_LD_ELFSEGMENT_H_ +#define MCLD_LD_ELFSEGMENT_H_ +#include "mcld/Config/Config.h" +#include "mcld/Support/Allocators.h" + #include <llvm/Support/DataTypes.h> +#include <llvm/Support/ELF.h> + #include <vector> -namespace mcld -{ +namespace mcld { class LDSection; /** \class ELFSegment * \brief decribe the program header for ELF executable or shared object */ -class ELFSegment -{ -public: +class ELFSegment { + public: typedef std::vector<LDSection*> SectionList; typedef SectionList::iterator iterator; typedef SectionList::const_iterator const_iterator; typedef SectionList::reverse_iterator reverse_iterator; typedef SectionList::const_reverse_iterator const_reverse_iterator; -private: + private: friend class Chunk<ELFSegment, MCLD_SEGMENTS_PER_OUTPUT>; ELFSegment(); - ELFSegment(uint32_t pType, uint32_t pFlag = llvm::ELF::PF_R); + explicit ELFSegment(uint32_t pType, uint32_t pFlag = llvm::ELF::PF_R); -public: + public: ~ELFSegment(); /// ----- iterators ----- /// - iterator begin() { return m_SectionList.begin(); } + iterator begin() { return m_SectionList.begin(); } const_iterator begin() const { return m_SectionList.begin(); } - iterator end() { return m_SectionList.end(); } - const_iterator end() const { return m_SectionList.end(); } + iterator end() { return m_SectionList.end(); } + const_iterator end() const { return m_SectionList.end(); } - reverse_iterator rbegin() { return m_SectionList.rbegin(); } + reverse_iterator rbegin() { return m_SectionList.rbegin(); } const_reverse_iterator rbegin() const { return m_SectionList.rbegin(); } - reverse_iterator rend() { return m_SectionList.rend(); } - const_reverse_iterator rend() const { return m_SectionList.rend(); } + reverse_iterator rend() { return m_SectionList.rend(); } + const_reverse_iterator rend() const { return m_SectionList.rend(); } - LDSection* front() { return m_SectionList.front(); } + LDSection* front() { return m_SectionList.front(); } const LDSection* front() const { return m_SectionList.front(); } - LDSection* back() { return m_SectionList.back(); } - const LDSection* back() const { return m_SectionList.back(); } + LDSection* back() { return m_SectionList.back(); } + const LDSection* back() const { return m_SectionList.back(); } /// ----- observers ----- /// - uint32_t type() const { return m_Type; } + uint32_t type() const { return m_Type; } uint64_t offset() const { return m_Offset; } - uint64_t vaddr() const { return m_Vaddr; } - uint64_t paddr() const { return m_Paddr; } + uint64_t vaddr() const { return m_Vaddr; } + uint64_t paddr() const { return m_Paddr; } uint64_t filesz() const { return m_Filesz; } - uint64_t memsz() const { return m_Memsz; } - uint32_t flag() const { return m_Flag; } - uint64_t align() const { return std::max(m_Align, m_MaxSectionAlign); } + uint64_t memsz() const { return m_Memsz; } + uint32_t flag() const { return m_Flag; } + uint64_t align() const { return std::max(m_Align, m_MaxSectionAlign); } size_t size() const { return m_SectionList.size(); } - bool empty() const { return m_SectionList.empty(); } + bool empty() const { return m_SectionList.empty(); } bool isLoadSegment() const; bool isDataSegment() const; bool isBssSegment() const; /// ----- modifiers ----- /// - void setOffset(uint64_t pOffset) - { m_Offset = pOffset; } + void setOffset(uint64_t pOffset) { m_Offset = pOffset; } - void setVaddr(uint64_t pVaddr) - { m_Vaddr = pVaddr; } + void setVaddr(uint64_t pVaddr) { m_Vaddr = pVaddr; } - void setPaddr(uint64_t pPaddr) - { m_Paddr = pPaddr; } + void setPaddr(uint64_t pPaddr) { m_Paddr = pPaddr; } - void setFilesz(uint64_t pFilesz) - { m_Filesz = pFilesz; } + void setFilesz(uint64_t pFilesz) { m_Filesz = pFilesz; } - void setMemsz(uint64_t pMemsz) - { m_Memsz = pMemsz; } + void setMemsz(uint64_t pMemsz) { m_Memsz = pMemsz; } - void setFlag(uint32_t pFlag) - { m_Flag = pFlag; } + void setFlag(uint32_t pFlag) { m_Flag = pFlag; } - void updateFlag(uint32_t pFlag) - { + void updateFlag(uint32_t pFlag) { // PT_TLS segment should be PF_R if (llvm::ELF::PT_TLS != m_Type) m_Flag |= pFlag; } - void setAlign(uint64_t pAlign) - { m_Align = pAlign; } + void setAlign(uint64_t pAlign) { m_Align = pAlign; } iterator insert(iterator pPos, LDSection* pSection); @@ -110,20 +102,19 @@ static void Destroy(ELFSegment*& pSegment); static void Clear(); -private: - uint32_t m_Type; // Type of segment - uint32_t m_Flag; // Segment flags - uint64_t m_Offset; // File offset where segment is located, in bytes - uint64_t m_Vaddr; // Virtual address of the segment - uint64_t m_Paddr; // Physical address of the segment (OS-specific) - uint64_t m_Filesz; // # of bytes in file image of segment (may be 0) - uint64_t m_Memsz; // # of bytes in mem image of segment (may be 0) - uint64_t m_Align; // alignment constraint - uint64_t m_MaxSectionAlign; // max alignment of the sections in this segment + private: + uint32_t m_Type; // Type of segment + uint32_t m_Flag; // Segment flags + uint64_t m_Offset; // File offset where segment is located, in bytes + uint64_t m_Vaddr; // Virtual address of the segment + uint64_t m_Paddr; // Physical address of the segment (OS-specific) + uint64_t m_Filesz; // # of bytes in file image of segment (may be 0) + uint64_t m_Memsz; // # of bytes in mem image of segment (may be 0) + uint64_t m_Align; // alignment constraint + uint64_t m_MaxSectionAlign; // max alignment of the sections in this segment SectionList m_SectionList; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ELFSEGMENT_H_
diff --git a/include/mcld/LD/ELFSegmentFactory.h b/include/mcld/LD/ELFSegmentFactory.h index 9bd6148..12a5831 100644 --- a/include/mcld/LD/ELFSegmentFactory.h +++ b/include/mcld/LD/ELFSegmentFactory.h
@@ -6,15 +6,15 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_ELFSEGMENTFACTORY_H -#define MCLD_LD_ELFSEGMENTFACTORY_H +#ifndef MCLD_LD_ELFSEGMENTFACTORY_H_ +#define MCLD_LD_ELFSEGMENTFACTORY_H_ #include <llvm/Support/DataTypes.h> #include <llvm/Support/ELF.h> + #include <vector> -namespace mcld -{ +namespace mcld { class ELFSegment; class LDSection; @@ -22,22 +22,21 @@ /** \class ELFSegmentFactory * \brief provide the interface to create and delete an ELFSegment */ -class ELFSegmentFactory -{ -public: +class ELFSegmentFactory { + public: typedef std::vector<ELFSegment*> Segments; typedef Segments::const_iterator const_iterator; typedef Segments::iterator iterator; const_iterator begin() const { return m_Segments.begin(); } - iterator begin() { return m_Segments.begin(); } - const_iterator end() const { return m_Segments.end(); } - iterator end() { return m_Segments.end(); } + iterator begin() { return m_Segments.begin(); } + const_iterator end() const { return m_Segments.end(); } + iterator end() { return m_Segments.end(); } const ELFSegment* front() const { return m_Segments.front(); } - ELFSegment* front() { return m_Segments.front(); } - const ELFSegment* back() const { return m_Segments.back(); } - ELFSegment* back() { return m_Segments.back(); } + ELFSegment* front() { return m_Segments.front(); } + const ELFSegment* back() const { return m_Segments.back(); } + ELFSegment* back() { return m_Segments.back(); } size_t size() const { return m_Segments.size(); } @@ -45,10 +44,11 @@ iterator find(uint32_t pType, uint32_t pFlagSet, uint32_t pFlagClear); - const_iterator - find(uint32_t pType, uint32_t pFlagSet, uint32_t pFlagClear) const; + const_iterator find(uint32_t pType, + uint32_t pFlagSet, + uint32_t pFlagClear) const; - iterator find(uint32_t pType, const LDSection* pSection); + iterator find(uint32_t pType, const LDSection* pSection); const_iterator find(uint32_t pType, const LDSection* pSection) const; @@ -59,11 +59,10 @@ void erase(iterator pSegment); -private: + private: Segments m_Segments; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_ELFSEGMENTFACTORY_H_
diff --git a/include/mcld/LD/EhFrame.h b/include/mcld/LD/EhFrame.h index eed80bc..ef6446d 100644 --- a/include/mcld/LD/EhFrame.h +++ b/include/mcld/LD/EhFrame.h
@@ -6,34 +6,32 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_EHFRAME_H -#define MCLD_LD_EHFRAME_H +#ifndef MCLD_LD_EHFRAME_H_ +#define MCLD_LD_EHFRAME_H_ -#include <mcld/Config/Config.h> -#include <mcld/Fragment/RegionFragment.h> -#include <mcld/LD/SectionData.h> -#include <mcld/Support/Allocators.h> +#include "mcld/Config/Config.h" +#include "mcld/Fragment/RegionFragment.h" +#include "mcld/LD/SectionData.h" +#include "mcld/Support/Allocators.h" +#include "mcld/Support/Compiler.h" #include <llvm/ADT/StringRef.h> + #include <list> #include <map> -#include <set> #include <vector> namespace mcld { class Input; -class Module; class LDSection; -class ObjectLinker; class Relocation; /** \class EhFrame * \brief EhFrame represents .eh_frame section */ -class EhFrame -{ -private: +class EhFrame { + private: friend class Chunk<EhFrame, MCLD_SECTIONS_PER_INPUT>; EhFrame(); @@ -41,15 +39,8 @@ ~EhFrame(); - EhFrame(const EhFrame&); // DO NOT IMPLEMENT - EhFrame& operator=(const EhFrame&); // DO NOT IMPLEMENT - -public: - enum RecordType { - RECORD_UNKNOWN, - RECORD_INPUT, - RECORD_GENERATED - }; + public: + enum RecordType { RECORD_UNKNOWN, RECORD_INPUT, RECORD_GENERATED }; class CIE; class FDE; @@ -62,32 +53,32 @@ typedef FDEList::iterator fde_iterator; typedef FDEList::const_iterator const_fde_iterator; - typedef std::map</*offset*/size_t, CIE*> CIEMap; + typedef std::map</*offset*/ size_t, CIE*> CIEMap; // A super class of CIE and FDE, containing the same part - class Record : public RegionFragment - { - public: - Record(llvm::StringRef pRegion); + class Record : public RegionFragment { + public: + explicit Record(llvm::StringRef pRegion); virtual ~Record(); - const llvm::StringRef getRegion() const { return RegionFragment::getRegion(); } - llvm::StringRef getRegion() { return RegionFragment::getRegion(); } + const llvm::StringRef getRegion() const { + return RegionFragment::getRegion(); + } + llvm::StringRef getRegion() { return RegionFragment::getRegion(); } virtual RecordType getRecordType() const { return RECORD_UNKNOWN; } - private: - Record(const Record&); // DO NOT IMPLEMENT - Record& operator=(const Record&); // DO NOT IMPLEMENT + private: + DISALLOW_COPY_AND_ASSIGN(Record); }; /** \class CIE * \brief Common Information Entry. - * The CIE structure refers to LSB Core Spec 4.1, chap.10.6. Exception Frames. + * The CIE structure refers to LSB Core Spec 4.1, chap.10.6. Exception + * Frames. */ - class CIE : public Record - { - public: - CIE(llvm::StringRef pRegion); + class CIE : public Record { + public: + explicit CIE(llvm::StringRef pRegion); ~CIE(); virtual RecordType getRecordType() const { return RECORD_INPUT; } @@ -101,14 +92,22 @@ void setRelocation(const Relocation& pReloc) { m_pReloc = &pReloc; } const Relocation* getRelocation() const { return m_pReloc; } - void setPersonalityOffset(uint64_t pOffset) { m_PersonalityOffset = pOffset; } + void setPersonalityOffset(uint64_t pOffset) { + m_PersonalityOffset = pOffset; + } uint64_t getPersonalityOffset() const { return m_PersonalityOffset; } - void setPersonalityName(const std::string& pStr) { m_PersonalityName = pStr; } + void setPersonalityName(const std::string& pStr) { + m_PersonalityName = pStr; + } const std::string& getPersonalityName() const { return m_PersonalityName; } - void setAugmentationData(const std::string& pStr) { m_AugmentationData = pStr; } - const std::string& getAugmentationData() const { return m_AugmentationData; } + void setAugmentationData(const std::string& pStr) { + m_AugmentationData = pStr; + } + const std::string& getAugmentationData() const { + return m_AugmentationData; + } void add(FDE& pFDE) { m_FDEs.push_back(&pFDE); } void remove(FDE& pFDE) { m_FDEs.remove(&pFDE); } @@ -116,11 +115,11 @@ size_t numOfFDEs() const { return m_FDEs.size(); } const_fde_iterator begin() const { return m_FDEs.begin(); } - fde_iterator begin() { return m_FDEs.begin(); } + fde_iterator begin() { return m_FDEs.begin(); } const_fde_iterator end() const { return m_FDEs.end(); } - fde_iterator end() { return m_FDEs.end(); } + fde_iterator end() { return m_FDEs.end(); } - private: + private: uint8_t m_FDEEncode; bool m_Mergeable; const Relocation* m_pReloc; @@ -132,43 +131,41 @@ /** \class FDE * \brief Frame Description Entry - * The FDE structure refers to LSB Core Spec 4.1, chap.10.6. Exception Frames. + * The FDE structure refers to LSB Core Spec 4.1, chap.10.6. Exception + * Frames. */ - class FDE : public Record - { - public: + class FDE : public Record { + public: FDE(llvm::StringRef pRegion, CIE& pCIE); ~FDE(); void setCIE(CIE& pCIE); const CIE& getCIE() const { return *m_pCIE; } - CIE& getCIE() { return *m_pCIE; } + CIE& getCIE() { return *m_pCIE; } - private: + private: CIE* m_pCIE; // Referenced CIE may change when merging. }; // These are created for PLT - class GeneratedCIE : public CIE - { - public: - GeneratedCIE(llvm::StringRef pRegion); + class GeneratedCIE : public CIE { + public: + explicit GeneratedCIE(llvm::StringRef pRegion); ~GeneratedCIE(); virtual RecordType getRecordType() const { return RECORD_GENERATED; } virtual bool getMergeable() const { return true; } }; - class GeneratedFDE : public FDE - { - public: + class GeneratedFDE : public FDE { + public: GeneratedFDE(llvm::StringRef pRegion, CIE& pCIE); ~GeneratedFDE(); virtual RecordType getRecordType() const { return RECORD_GENERATED; } }; -public: + public: static EhFrame* Create(LDSection& pSection); static void Destroy(EhFrame*& pSection); @@ -179,10 +176,10 @@ EhFrame& merge(const Input& pInput, EhFrame& pInFrame); const LDSection& getSection() const; - LDSection& getSection(); + LDSection& getSection(); const SectionData* getSectionData() const { return m_pSectionData; } - SectionData* getSectionData() { return m_pSectionData; } + SectionData* getSectionData() { return m_pSectionData; } // ----- fragment ----- // void addFragment(Fragment& pFrag); @@ -195,32 +192,34 @@ // ----- CIE ----- // const_cie_iterator cie_begin() const { return m_CIEs.begin(); } - cie_iterator cie_begin() { return m_CIEs.begin(); } - const_cie_iterator cie_end () const { return m_CIEs.end(); } - cie_iterator cie_end () { return m_CIEs.end(); } + cie_iterator cie_begin() { return m_CIEs.begin(); } + const_cie_iterator cie_end() const { return m_CIEs.end(); } + cie_iterator cie_end() { return m_CIEs.end(); } const CIE& cie_front() const { return *m_CIEs.front(); } - CIE& cie_front() { return *m_CIEs.front(); } - const CIE& cie_back () const { return *m_CIEs.back(); } - CIE& cie_back () { return *m_CIEs.back(); } + CIE& cie_front() { return *m_CIEs.front(); } + const CIE& cie_back() const { return *m_CIEs.back(); } + CIE& cie_back() { return *m_CIEs.back(); } bool emptyCIEs() const { return m_CIEs.empty(); } size_t numOfCIEs() const { return m_CIEs.size(); } size_t numOfFDEs() const; const CIEMap& getCIEMap() const { return m_FoundCIEs; } - CIEMap& getCIEMap() { return m_FoundCIEs; } + CIEMap& getCIEMap() { return m_FoundCIEs; } -public: + public: size_t computeOffsetSize(); /// getDataStartOffset - Get the offset after length and ID field. /// The offset is 8byte for 32b, and 16byte for 64b. /// We can just use "BITCLASS/4" to represent offset. template <size_t BITCLASS> - static size_t getDataStartOffset() { return BITCLASS / 4; } + static size_t getDataStartOffset() { + return BITCLASS / 4; + } -private: + private: // We needs to check if it is mergeable and check personality name // before merging them. The important note is we must do this after // ALL readSections done, that is the reason why we don't check this @@ -228,13 +227,15 @@ void setupAttributes(const LDSection* reloc_sect); void removeDiscardedFDE(CIE& pCIE, const LDSection* pRelocEhFrameSect); -private: - void removeAndUpdateCIEForFDE(EhFrame& pInFrame, CIE& pInCIE, CIE& pOutCIE, + private: + void removeAndUpdateCIEForFDE(EhFrame& pInFrame, + CIE& pInCIE, + CIE& pOutCIE, const LDSection* reloc_sect); void moveInputFragments(EhFrame& pInFrame); void moveInputFragments(EhFrame& pInFrame, CIE& pInCIE, CIE* pOutCIE = 0); -private: + private: LDSection* m_pSection; SectionData* m_pSectionData; @@ -248,11 +249,13 @@ // We need this map to find the corresponding CIE for FDE. Not all FDE point // to the nearest CIE. CIEMap m_FoundCIEs; + + private: + DISALLOW_COPY_AND_ASSIGN(EhFrame); }; bool operator==(const EhFrame::CIE&, const EhFrame::CIE&); -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_EHFRAME_H_
diff --git a/include/mcld/LD/EhFrameHdr.h b/include/mcld/LD/EhFrameHdr.h index 3ca4f72..2361afc 100644 --- a/include/mcld/LD/EhFrameHdr.h +++ b/include/mcld/LD/EhFrameHdr.h
@@ -6,13 +6,13 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_EHFRAMEHDR_H -#define MCLD_LD_EHFRAMEHDR_H -#include <mcld/ADT/SizeTraits.h> -#include <cassert> +#ifndef MCLD_LD_EHFRAMEHDR_H_ +#define MCLD_LD_EHFRAMEHDR_H_ +#include "mcld/ADT/SizeTraits.h" +#include "mcld/LD/EhFrame.h" +#include "mcld/Support/FileOutputBuffer.h" -#include <mcld/LD/EhFrame.h> -#include <mcld/Support/FileOutputBuffer.h> +#include <cassert> namespace mcld { class LDSection; @@ -32,9 +32,8 @@ * __________________________ when fde_count > 0 * <uint32_t, uint32_t>+ : binary search table */ -class EhFrameHdr -{ -public: +class EhFrameHdr { + public: EhFrameHdr(LDSection& pEhFrameHdr, const LDSection& pEhFrame); ~EhFrameHdr(); @@ -43,17 +42,17 @@ void sizeOutput(); /// emitOutput - write out eh_frame_hdr - template<size_t size> - void emitOutput(FileOutputBuffer& pOutput) - { assert(false && "Call invalid EhFrameHdr::emitOutput"); } + template <size_t size> + void emitOutput(FileOutputBuffer& pOutput) { + assert(false && "Call invalid EhFrameHdr::emitOutput"); + } -private: + private: /// computePCBegin - return the address of FDE's pc - /// @ref binutils gold: ehframe.cc:222 uint32_t computePCBegin(const EhFrame::FDE& pFDE, const MemoryRegion& pEhFrameRegion); -private: + private: /// .eh_frame_hdr section LDSection& m_EhFrameHdr; @@ -65,10 +64,9 @@ // Template Specification Functions //===----------------------------------------------------------------------===// /// emitOutput - write out eh_frame_hdr -template<> +template <> void EhFrameHdr::emitOutput<32>(FileOutputBuffer& pOutput); -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_EHFRAMEHDR_H_
diff --git a/include/mcld/LD/EhFrameReader.h b/include/mcld/LD/EhFrameReader.h index 0ae093c..a021ac4 100644 --- a/include/mcld/LD/EhFrameReader.h +++ b/include/mcld/LD/EhFrameReader.h
@@ -6,9 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_EHFRAMEREADER_H -#define MCLD_LD_EHFRAMEREADER_H -#include <mcld/LD/EhFrame.h> +#ifndef MCLD_LD_EHFRAMEREADER_H_ +#define MCLD_LD_EHFRAMEREADER_H_ +#include "mcld/LD/EhFrame.h" + #include <llvm/ADT/StringRef.h> #include <llvm/Support/DataTypes.h> @@ -23,38 +24,25 @@ * EhFrameReader is responsible to parse the input eh_frame sections and create * the corresponding CIE and FDE entries. */ -class EhFrameReader -{ -public: +class EhFrameReader { + public: typedef const char* ConstAddress; - typedef char* Address; + typedef char* Address; -public: + public: /// read - read an .eh_frame section and create the corresponding /// CIEs and FDEs /// @param pInput [in] the Input contains this eh_frame /// @param pEhFrame [inout] the input eh_frame /// @return if we read all CIEs and FDEs successfully, return true. Otherwise, /// return false; - template<size_t BITCLASS, bool SAME_ENDIAN> + template <size_t BITCLASS, bool SAME_ENDIAN> bool read(Input& pInput, EhFrame& pEhFrame); -private: - enum TokenKind { - CIE, - FDE, - Terminator, - Unknown, - NumOfTokenKinds - }; + private: + enum TokenKind { CIE, FDE, Terminator, Unknown, NumOfTokenKinds }; - enum State { - Q0, - Q1, - Accept, - NumOfStates = 2, - Reject = -1 - }; + enum State { Q0, Q1, Accept, NumOfStates = 2, Reject = -1 }; struct Token { TokenKind kind; @@ -70,11 +58,13 @@ typedef bool (*Action)(EhFrame& pEhFrame, llvm::StringRef pRegion, const Token& pToken); -private: + + private: /// scan - scan pData from pHandler for a token. - template<bool SAME_ENDIAN> Token scan(ConstAddress pHandler, - uint64_t pOffset, - llvm::StringRef pData) const; + template <bool SAME_ENDIAN> + Token scan(ConstAddress pHandler, + uint64_t pOffset, + llvm::StringRef pData) const; static bool addCIE(EhFrame& pEhFrame, llvm::StringRef pRegion, @@ -93,15 +83,14 @@ const Token& pToken); }; -template<> bool -EhFrameReader::read<32, true>(Input& pInput, EhFrame& pEhFrame); +template <> +bool EhFrameReader::read<32, true>(Input& pInput, EhFrame& pEhFrame); -template<> EhFrameReader::Token -EhFrameReader::scan<true>(ConstAddress pHandler, - uint64_t pOffset, - llvm::StringRef pData) const; +template <> +EhFrameReader::Token EhFrameReader::scan<true>(ConstAddress pHandler, + uint64_t pOffset, + llvm::StringRef pData) const; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_EHFRAMEREADER_H_
diff --git a/include/mcld/LD/GNUArchiveReader.h b/include/mcld/LD/GNUArchiveReader.h index 69d8cf6..5319c52 100644 --- a/include/mcld/LD/GNUArchiveReader.h +++ b/include/mcld/LD/GNUArchiveReader.h
@@ -6,26 +6,25 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_GNUARCHIVEREADER_H -#define MCLD_LD_GNUARCHIVEREADER_H +#ifndef MCLD_LD_GNUARCHIVEREADER_H_ +#define MCLD_LD_GNUARCHIVEREADER_H_ -#include <mcld/LD/ArchiveReader.h> -#include <mcld/LD/Archive.h> +#include "mcld/LD/Archive.h" +#include "mcld/LD/ArchiveReader.h" namespace mcld { -class Module; -class Input; -class ELFObjectReader; class Archive; +class ELFObjectReader; +class Input; class LinkerConfig; +class Module; /** \class GNUArchiveReader * \brief GNUArchiveReader reads GNU archive files. */ -class GNUArchiveReader : public ArchiveReader -{ -public: +class GNUArchiveReader : public ArchiveReader { + public: GNUArchiveReader(Module& pModule, ELFObjectReader& pELFObjectReader); ~GNUArchiveReader(); @@ -35,9 +34,9 @@ bool readArchive(const LinkerConfig& pConfig, Archive& pArchive); /// isMyFormat - bool isMyFormat(Input& input, bool &pContinue) const; + bool isMyFormat(Input& input, bool& pContinue) const; -private: + private: /// isArchive bool isArchive(const char* pStr) const; @@ -70,8 +69,8 @@ /// shouldIncludeSymbol - given a sym name from armap and check if we should /// include the corresponding archive member, and then return the decision - enum Archive::Symbol::Status - shouldIncludeSymbol(const llvm::StringRef& pSymName) const; + enum Archive::Symbol::Status shouldIncludeSymbol( + const llvm::StringRef& pSymName) const; /// includeMember - include the object member in the given file offset, and /// return the size of the object @@ -86,12 +85,11 @@ /// --whole-archive is the attribute for this archive file. bool includeAllMembers(const LinkerConfig& pConfig, Archive& pArchive); -private: + private: Module& m_Module; ELFObjectReader& m_ELFObjectReader; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_GNUARCHIVEREADER_H_
diff --git a/include/mcld/LD/GarbageCollection.h b/include/mcld/LD/GarbageCollection.h index ed43829..b467d3a 100644 --- a/include/mcld/LD/GarbageCollection.h +++ b/include/mcld/LD/GarbageCollection.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_GARBAGECOLLECTION_H -#define MCLD_LD_GARBAGECOLLECTION_H +#ifndef MCLD_LD_GARBAGECOLLECTION_H_ +#define MCLD_LD_GARBAGECOLLECTION_H_ #include <map> #include <set> @@ -22,20 +22,17 @@ /** \class GarbageCollection * \brief Implementation of garbage collection for --gc-section. - * @ref GNU gold, gc. */ -class GarbageCollection -{ -public: +class GarbageCollection { + public: typedef std::set<const LDSection*> SectionListTy; typedef std::vector<const LDSection*> SectionVecTy; /** \class SectionReachedListMap * \brief Map the section to the list of sections which it can reach directly */ - class SectionReachedListMap - { - public: + class SectionReachedListMap { + public: SectionReachedListMap() {} /// addReference - add a reference from pFrom to pTo @@ -49,15 +46,15 @@ /// pSection, return NULL if the list not exists SectionListTy* findReachedList(const LDSection& pSection); - private: + private: typedef std::map<const LDSection*, SectionListTy> ReachedSectionsTy; - private: + private: /// m_ReachedSections - map a section to the reachable sections list ReachedSectionsTy m_ReachedSections; }; -public: + public: GarbageCollection(const LinkerConfig& pConfig, const TargetLDBackend& pBackend, Module& pModule); @@ -66,13 +63,13 @@ /// run - do garbage collection bool run(); -private: + private: void setUpReachedSections(); void findReferencedSections(SectionVecTy& pEntry); void getEntrySections(SectionVecTy& pEntry); void stripSections(); -private: + private: /// m_SectionReachedListMap - map the section to the list of sections which it /// can reach directly SectionReachedListMap m_SectionReachedListMap; @@ -85,7 +82,6 @@ Module& m_Module; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_GARBAGECOLLECTION_H_
diff --git a/include/mcld/LD/Group.h b/include/mcld/LD/Group.h index 05d1780..f9530bc 100644 --- a/include/mcld/LD/Group.h +++ b/include/mcld/LD/Group.h
@@ -6,20 +6,16 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_GROUP_H -#define MCLD_LD_GROUP_H +#ifndef MCLD_LD_GROUP_H_ +#define MCLD_LD_GROUP_H_ -namespace mcld -{ +namespace mcld { /** \class Group * \brief Group records the grouping of all regions */ -class Group -{ -}; +class Group {}; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_GROUP_H_
diff --git a/include/mcld/LD/GroupReader.h b/include/mcld/LD/GroupReader.h index dd59150..3690ac5 100644 --- a/include/mcld/LD/GroupReader.h +++ b/include/mcld/LD/GroupReader.h
@@ -6,19 +6,19 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_GROUPREADER_H -#define MCLD_LD_GROUPREADER_H +#ifndef MCLD_LD_GROUPREADER_H_ +#define MCLD_LD_GROUPREADER_H_ -#include <mcld/Module.h> +#include "mcld/Module.h" -namespace mcld -{ +namespace mcld { class Archive; class ArchiveReader; +class BinaryReader; class DynObjReader; +class InputBuilder; class LinkerConfig; class ObjectReader; -class BinaryReader; /** \class GroupReader * \brief GroupReader handles the Group Node in InputTree @@ -26,9 +26,8 @@ * Group Node is the root of sub-tree in InputTree which includes the iputs in * the command line options --start-group and --end-group options */ -class GroupReader -{ -public: +class GroupReader { + public: GroupReader(Module& pModule, ObjectReader& pObjectReader, DynObjReader& pDynObjReader, @@ -44,18 +43,17 @@ InputBuilder& pBuilder, const LinkerConfig& pConfig); -private: + private: /// ArchiveListEntry - record the Archive and the corresponding input iterator /// of the archive node struct ArchiveListEntry { ArchiveListEntry(Archive& pArchive, Module::input_iterator pIterator) - : archive(pArchive), input(pIterator) { - } + : archive(pArchive), input(pIterator) {} Archive& archive; Module::input_iterator input; }; -private: + private: Module& m_Module; ObjectReader& m_ObjectReader; DynObjReader& m_DynObjReader; @@ -63,7 +61,6 @@ BinaryReader& m_BinaryReader; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_GROUPREADER_H_
diff --git a/include/mcld/LD/IdenticalCodeFolding.h b/include/mcld/LD/IdenticalCodeFolding.h index e26315e..a584fc6 100644 --- a/include/mcld/LD/IdenticalCodeFolding.h +++ b/include/mcld/LD/IdenticalCodeFolding.h
@@ -6,14 +6,16 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_IDENTICALCODEFOLDING_H -#define MCLD_LD_IDENTICALCODEFOLDING_H +#ifndef MCLD_LD_IDENTICALCODEFOLDING_H_ +#define MCLD_LD_IDENTICALCODEFOLDING_H_ #include <llvm/ADT/MapVector.h> + #include <string> #include <vector> namespace mcld { + class Input; class LDSection; class LinkerConfig; @@ -27,23 +29,22 @@ * Gold, http://research.google.com/pubs/pub36912.html */ class IdenticalCodeFolding { -public: + public: typedef std::pair<Input*, size_t> ObjectAndId; typedef llvm::MapVector<LDSection*, ObjectAndId> KeptSections; -private: + private: class FoldingCandidate { - public: - FoldingCandidate() - : sect(NULL), reloc_sect(NULL), obj(NULL) - { } + public: + FoldingCandidate() : sect(NULL), reloc_sect(NULL), obj(NULL) {} FoldingCandidate(LDSection* pCode, LDSection* pReloc, Input* pInput) - : sect(pCode), reloc_sect(pReloc), obj(pInput) - { } + : sect(pCode), reloc_sect(pReloc), obj(pInput) {} - void initConstantContent(const TargetLDBackend& pBackend, + void initConstantContent( + const TargetLDBackend& pBackend, const IdenticalCodeFolding::KeptSections& pKeptSections); - std::string getContentWithVariables(const TargetLDBackend& pBackend, + std::string getContentWithVariables( + const TargetLDBackend& pBackend, const IdenticalCodeFolding::KeptSections& pKeptSections); LDSection* sect; @@ -55,25 +56,25 @@ typedef std::vector<FoldingCandidate> FoldingCandidates; -public: + public: IdenticalCodeFolding(const LinkerConfig& pConfig, const TargetLDBackend& pBackend, Module& pModule); void foldIdenticalCode(); -private: + private: void findCandidates(FoldingCandidates& pCandidateList); bool matchCandidates(FoldingCandidates& pCandidateList); -private: + private: const LinkerConfig& m_Config; const TargetLDBackend& m_Backend; Module& m_Module; KeptSections m_KeptSections; }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_LD_IDENTICALCODEFOLDING_H_
diff --git a/include/mcld/LD/LDContext.h b/include/mcld/LD/LDContext.h index ae09154..8533fe3 100644 --- a/include/mcld/LD/LDContext.h +++ b/include/mcld/LD/LDContext.h
@@ -6,18 +6,20 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_LDCONTEXT_H -#define MCLD_LD_LDCONTEXT_H +#ifndef MCLD_LD_LDCONTEXT_H_ +#define MCLD_LD_LDCONTEXT_H_ -#include <vector> -#include <mcld/LD/LDFileFormat.h> +#include "mcld/LD/LDFileFormat.h" + #include <llvm/Support/DataTypes.h> -#include <string> + #include <cassert> +#include <string> +#include <vector> namespace llvm { class StringRef; -} +} // namespace llvm namespace mcld { @@ -27,9 +29,8 @@ /** \class LDContext * \brief LDContext stores the data which a object file should has */ -class LDContext -{ -public: +class LDContext { + public: typedef std::vector<LDSection*> SectionTable; typedef SectionTable::iterator sect_iterator; typedef SectionTable::const_iterator const_sect_iterator; @@ -38,51 +39,49 @@ typedef SymbolTable::iterator sym_iterator; typedef SymbolTable::const_iterator const_sym_iterator; -public: + public: // ----- sections ----- // LDContext& appendSection(LDSection& pSection); const_sect_iterator sectBegin() const { return m_SectionTable.begin(); } - sect_iterator sectBegin() { return m_SectionTable.begin(); } + sect_iterator sectBegin() { return m_SectionTable.begin(); } const_sect_iterator sectEnd() const { return m_SectionTable.end(); } - sect_iterator sectEnd() { return m_SectionTable.end(); } + sect_iterator sectEnd() { return m_SectionTable.end(); } const LDSection* getSection(unsigned int pIdx) const; - LDSection* getSection(unsigned int pIdx); + LDSection* getSection(unsigned int pIdx); const LDSection* getSection(const std::string& pName) const; - LDSection* getSection(const std::string& pName); + LDSection* getSection(const std::string& pName); size_t getSectionIdx(const std::string& pName) const; - size_t numOfSections() const - { return m_SectionTable.size(); } + size_t numOfSections() const { return m_SectionTable.size(); } // ----- symbols ----- // const LDSymbol* getSymbol(unsigned int pIdx) const; - LDSymbol* getSymbol(unsigned int pIdx); + LDSymbol* getSymbol(unsigned int pIdx); const LDSymbol* getSymbol(const llvm::StringRef& pName) const; - LDSymbol* getSymbol(const llvm::StringRef& pName); + LDSymbol* getSymbol(const llvm::StringRef& pName); - void addSymbol(LDSymbol* pSym) - { m_SymTab.push_back(pSym); } + void addSymbol(LDSymbol* pSym) { m_SymTab.push_back(pSym); } const_sym_iterator symTabBegin() const { return m_SymTab.begin(); } - sym_iterator symTabBegin() { return m_SymTab.begin(); } + sym_iterator symTabBegin() { return m_SymTab.begin(); } const_sym_iterator symTabEnd() const { return m_SymTab.end(); } - sym_iterator symTabEnd() { return m_SymTab.end(); } + sym_iterator symTabEnd() { return m_SymTab.end(); } // ----- relocations ----- // const_sect_iterator relocSectBegin() const { return m_RelocSections.begin(); } - sect_iterator relocSectBegin() { return m_RelocSections.begin(); } + sect_iterator relocSectBegin() { return m_RelocSections.begin(); } const_sect_iterator relocSectEnd() const { return m_RelocSections.end(); } - sect_iterator relocSectEnd() { return m_RelocSections.end(); } + sect_iterator relocSectEnd() { return m_RelocSections.end(); } -private: + private: SectionTable m_SectionTable; SymbolTable m_SymTab; SectionTable m_RelocSections; @@ -90,8 +89,6 @@ // FIXME : maintain a map<section name, section index> }; +} // namespace mcld -} // namespace of mcld - -#endif - +#endif // MCLD_LD_LDCONTEXT_H_
diff --git a/include/mcld/LD/LDFileFormat.h b/include/mcld/LD/LDFileFormat.h index 44d3bfc..df5d0f9 100644 --- a/include/mcld/LD/LDFileFormat.h +++ b/include/mcld/LD/LDFileFormat.h
@@ -6,11 +6,11 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_LDFILEFORMAT_H -#define MCLD_LD_LDFILEFORMAT_H +#ifndef MCLD_LD_LDFILEFORMAT_H_ +#define MCLD_LD_LDFILEFORMAT_H_ -#include <cstdio> #include <cassert> +#include <cstddef> namespace mcld { @@ -20,17 +20,17 @@ /** \class LDFileFormat * \brief LDFileFormat describes the common file formats. */ -class LDFileFormat -{ -public: +class LDFileFormat { + public: enum Kind { Null, - TEXT, // Executable regular sections - DATA, // Non-executable regular sections + TEXT, // Executable regular sections + DATA, // Non-executable regular sections BSS, NamePool, Relocation, Debug, + DebugString, Target, EhFrame, EhFrameHdr, @@ -46,10 +46,10 @@ Folded }; -protected: + protected: LDFileFormat(); -public: + public: virtual ~LDFileFormat(); /// initStdSections - initialize all standard section headers. @@ -60,53 +60,53 @@ // ----- access functions ----- // LDSection& getText() { - assert(NULL != f_pTextSection); + assert(f_pTextSection != NULL); return *f_pTextSection; } const LDSection& getText() const { - assert(NULL != f_pTextSection); + assert(f_pTextSection != NULL); return *f_pTextSection; } LDSection& getData() { - assert(NULL != f_pDataSection); + assert(f_pDataSection != NULL); return *f_pDataSection; } const LDSection& getData() const { - assert(NULL != f_pDataSection); + assert(f_pDataSection != NULL); return *f_pDataSection; } LDSection& getBSS() { - assert(NULL != f_pBSSSection); + assert(f_pBSSSection != NULL); return *f_pBSSSection; } const LDSection& getBSS() const { - assert(NULL != f_pBSSSection); + assert(f_pBSSSection != NULL); return *f_pBSSSection; } LDSection& getReadOnly() { - assert(NULL != f_pReadOnlySection); + assert(f_pReadOnlySection != NULL); return *f_pReadOnlySection; } const LDSection& getReadOnly() const { - assert(NULL != f_pReadOnlySection); + assert(f_pReadOnlySection != NULL); return *f_pReadOnlySection; } -protected: + + protected: // variable name : ELF MachO - LDSection* f_pTextSection; // .text __text - LDSection* f_pDataSection; // .data __data - LDSection* f_pBSSSection; // .bss __bss - LDSection* f_pReadOnlySection; // .rodata __const + LDSection* f_pTextSection; // .text __text + LDSection* f_pDataSection; // .data __data + LDSection* f_pBSSSection; // .bss __bss + LDSection* f_pReadOnlySection; // .rodata __const }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_LDFILEFORMAT_H_
diff --git a/include/mcld/LD/LDReader.h b/include/mcld/LD/LDReader.h index c10fc96..5bda159 100644 --- a/include/mcld/LD/LDReader.h +++ b/include/mcld/LD/LDReader.h
@@ -6,13 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_LDREADER_H -#define MCLD_LD_LDREADER_H +#ifndef MCLD_LD_LDREADER_H_ +#define MCLD_LD_LDREADER_H_ -#include <llvm/Support/DataTypes.h> - -namespace mcld -{ +namespace mcld { class Input; @@ -20,25 +17,19 @@ * \brief LDReader provides the basic interfaces for all readers. It also * provides basic functions to read data stream. */ -class LDReader -{ -public: - enum Endian { - LittleEndian, - BigEndian - }; +class LDReader { + public: + enum Endian { LittleEndian, BigEndian }; -protected: - LDReader() { } + protected: + LDReader() {} -public: - virtual ~LDReader() { } + public: + virtual ~LDReader() {} - virtual bool isMyFormat(Input& pInput, bool &pContinue) const = 0; - + virtual bool isMyFormat(Input& pInput, bool& pContinue) const = 0; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_LDREADER_H_
diff --git a/include/mcld/LD/LDSection.h b/include/mcld/LD/LDSection.h index 4f01df8..eb89f32 100644 --- a/include/mcld/LD/LDSection.h +++ b/include/mcld/LD/LDSection.h
@@ -6,29 +6,30 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +#ifndef MCLD_LD_LDSECTION_H_ +#define MCLD_LD_LDSECTION_H_ -#ifndef MCLD_LD_LDSECTION_H -#define MCLD_LD_LDSECTION_H +#include "mcld/Config/Config.h" +#include "mcld/LD/LDFileFormat.h" +#include "mcld/Support/Allocators.h" #include <llvm/Support/DataTypes.h> -#include <mcld/Support/Allocators.h> -#include <mcld/Config/Config.h> -#include <mcld/LD/LDFileFormat.h> + #include <string> namespace mcld { -class SectionData; -class RelocData; +class DebugString; class EhFrame; +class RelocData; +class SectionData; /** \class LDSection * \brief LDSection represents a section header entry. It is a unified * abstraction of a section header entry for various file formats. */ -class LDSection -{ -private: +class LDSection { + private: friend class Chunk<LDSection, MCLD_SECTIONS_PER_INPUT>; LDSection(); @@ -40,7 +41,7 @@ uint64_t pSize = 0, uint64_t pAddr = 0); -public: + public: ~LDSection(); static LDSection* Create(const std::string& pName, @@ -57,39 +58,33 @@ bool hasOffset() const; /// name - the name of this section. - const std::string& name() const - { return m_Name; } + const std::string& name() const { return m_Name; } /// kind - the kind of this section, such as Text, BSS, GOT, and so on. /// from LDFileFormat::Kind - LDFileFormat::Kind kind() const - { return m_Kind; } + LDFileFormat::Kind kind() const { return m_Kind; } /// type - The categorizes the section's contents and semantics. It's /// different from llvm::SectionKind. Type is format-dependent, but /// llvm::SectionKind is format independent and is used for bit-code. /// In ELF, it is sh_type /// In MachO, it's type field of struct section::flags - uint32_t type() const - { return m_Type; } + uint32_t type() const { return m_Type; } /// flag - An integer describes miscellaneous attributes. /// In ELF, it is sh_flags. /// In MachO, it's attribute field of struct section::flags - uint32_t flag() const - { return m_Flag; } + uint32_t flag() const { return m_Flag; } /// size - An integer specifying the size in bytes of the virtual memory /// occupied by this section. /// In ELF, if the type() is SHT_NOBITS, this function return zero. /// Before layouting, output's LDSection::size() should return zero. - uint64_t size() const - { return m_Size; } + uint64_t size() const { return m_Size; } /// offset - An integer specifying the offset of this section in the file. /// Before layouting, output's LDSection::offset() should return zero. - uint64_t offset() const - { return m_Offset; } + uint64_t offset() const { return m_Offset; } /// addr - An integer specifying the virtual address of this section in the /// virtual image. @@ -101,55 +96,42 @@ /// /// Because addr() in output is changing during linking, MCLinker does not /// store the address of the output here. The address is in Layout - uint64_t addr() const - { return m_Addr; } + uint64_t addr() const { return m_Addr; } /// align - An integer specifying the align of this section in the file. /// Before layouting, output's LDSection::align() should return zero. - uint32_t align() const - { return m_Align; } + uint32_t align() const { return m_Align; } - size_t index() const - { return m_Index; } + size_t index() const { return m_Index; } /// getLink - return the Link. When a section A needs the other section B /// during linking or loading, we say B is A's Link section. /// In ELF, InfoLink section control the ElfNN_Shdr::sh_link and sh_info. /// /// @return if the section needs no other sections, return NULL - LDSection* getLink() - { return m_pLink; } + LDSection* getLink() { return m_pLink; } - const LDSection* getLink() const - { return m_pLink; } + const LDSection* getLink() const { return m_pLink; } - size_t getInfo() const - { return m_Info; } + size_t getInfo() const { return m_Info; } - void setKind(LDFileFormat::Kind pKind) - { m_Kind = pKind; } + void setKind(LDFileFormat::Kind pKind) { m_Kind = pKind; } - void setSize(uint64_t size) - { m_Size = size; } + void setSize(uint64_t size) { m_Size = size; } - void setOffset(uint64_t Offset) - { m_Offset = Offset; } + void setOffset(uint64_t Offset) { m_Offset = Offset; } - void setAddr(uint64_t addr) - { m_Addr = addr; } + void setAddr(uint64_t addr) { m_Addr = addr; } - void setAlign(uint32_t align) - { m_Align = align; } + void setAlign(uint32_t align) { m_Align = align; } - void setFlag(uint32_t flag) - { m_Flag = flag; } + void setFlag(uint32_t flag) { m_Flag = flag; } - void setType(uint32_t type) - { m_Type = type; } + void setType(uint32_t type) { m_Type = type; } // ----- SectionData ----- // const SectionData* getSectionData() const { return m_Data.sect_data; } - SectionData* getSectionData() { return m_Data.sect_data; } + SectionData* getSectionData() { return m_Data.sect_data; } void setSectionData(SectionData* pSD) { m_Data.sect_data = pSD; } @@ -157,7 +139,7 @@ // ------ RelocData ------ // const RelocData* getRelocData() const { return m_Data.reloc_data; } - RelocData* getRelocData() { return m_Data.reloc_data; } + RelocData* getRelocData() { return m_Data.reloc_data; } void setRelocData(RelocData* pRD) { m_Data.reloc_data = pRD; } @@ -165,32 +147,38 @@ // ------ EhFrame ------ // const EhFrame* getEhFrame() const { return m_Data.eh_frame; } - EhFrame* getEhFrame() { return m_Data.eh_frame; } + EhFrame* getEhFrame() { return m_Data.eh_frame; } void setEhFrame(EhFrame* pEhFrame) { m_Data.eh_frame = pEhFrame; } bool hasEhFrame() const; + // ------ DebugString ------ // + const DebugString* getDebugString() const { return m_Data.debug_string; } + DebugString* getDebugString() { return m_Data.debug_string; } + + void setDebugString(DebugString* pDebugString) + { m_Data.debug_string = pDebugString; } + + bool hasDebugString() const; + /// setLink - set the sections should link with. /// if pLink is NULL, no Link section is set. - void setLink(LDSection* pLink) - { m_pLink = pLink; } + void setLink(LDSection* pLink) { m_pLink = pLink; } - void setInfo(size_t pInfo) - { m_Info = pInfo; } + void setInfo(size_t pInfo) { m_Info = pInfo; } - void setIndex(size_t pIndex) - { m_Index = pIndex; } + void setIndex(size_t pIndex) { m_Index = pIndex; } -private: - union SectOrRelocData - { + private: + union Data { SectionData* sect_data; RelocData* reloc_data; EhFrame* eh_frame; + DebugString* debug_string; }; -private: + private: std::string m_Name; LDFileFormat::Kind m_Kind; @@ -206,14 +194,12 @@ LDSection* m_pLink; /// m_Data - the SectionData or RelocData of this section - SectOrRelocData m_Data; + Data m_Data; /// m_Index - the index of the file size_t m_Index; +}; // end of LDSection -}; // end of LDSection +} // namespace mcld -} // end namespace mcld - -#endif - +#endif // MCLD_LD_LDSECTION_H_
diff --git a/include/mcld/LD/LDSymbol.h b/include/mcld/LD/LDSymbol.h index 45c10a8..32f8e0e 100644 --- a/include/mcld/LD/LDSymbol.h +++ b/include/mcld/LD/LDSymbol.h
@@ -6,22 +6,22 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_LDSYMBOL_H -#define MCLD_LD_LDSYMBOL_H +#ifndef MCLD_LD_LDSYMBOL_H_ +#define MCLD_LD_LDSYMBOL_H_ + +#include "mcld/Config/Config.h" +#include "mcld/LD/ResolveInfo.h" +#include "mcld/Support/Allocators.h" #include <cassert> -#include <mcld/Config/Config.h> -#include <mcld/ADT/Uncopyable.h> -#include <mcld/LD/ResolveInfo.h> -#include <mcld/Support/Allocators.h> - namespace llvm { // forware declaration -template<class T> void* object_creator(); +template <class T> +void* object_creator(); -} // namespace of llvm +} // namespace llvm namespace mcld { @@ -31,14 +31,13 @@ * \brief LDSymbol provides a consistent abstraction for different formats * in different targets. */ -class LDSymbol -{ -public: +class LDSymbol { + public: // FIXME: use SizeTrait<32> or SizeTrait<64> instead of big type typedef ResolveInfo::SizeType SizeType; typedef uint64_t ValueType; -public: + public: ~LDSymbol(); // ----- factory method ----- // @@ -57,98 +56,88 @@ bool isNull() const; const char* name() const { - assert(NULL != m_pResolveInfo); + assert(m_pResolveInfo != NULL); return m_pResolveInfo->name(); } unsigned int nameSize() const { - assert(NULL != m_pResolveInfo); + assert(m_pResolveInfo != NULL); return m_pResolveInfo->nameSize(); } llvm::StringRef str() const { - assert(NULL != m_pResolveInfo); + assert(m_pResolveInfo != NULL); return llvm::StringRef(m_pResolveInfo->name(), m_pResolveInfo->nameSize()); } bool isDyn() const { - assert(NULL != m_pResolveInfo); + assert(m_pResolveInfo != NULL); return m_pResolveInfo->isDyn(); } unsigned int type() const { - assert(NULL != m_pResolveInfo); + assert(m_pResolveInfo != NULL); return m_pResolveInfo->type(); } - unsigned int desc() const { - assert(NULL != m_pResolveInfo); + unsigned int desc() const { + assert(m_pResolveInfo != NULL); return m_pResolveInfo->desc(); } unsigned int binding() const { - assert(NULL != m_pResolveInfo); + assert(m_pResolveInfo != NULL); return m_pResolveInfo->binding(); } uint8_t other() const { - assert(NULL != m_pResolveInfo); + assert(m_pResolveInfo != NULL); return m_pResolveInfo->other(); } uint8_t visibility() const { - assert(NULL != m_pResolveInfo); + assert(m_pResolveInfo != NULL); return m_pResolveInfo->other(); } - ValueType value() const - { return m_Value; } + ValueType value() const { return m_Value; } - const FragmentRef* fragRef() const - { return m_pFragRef; } + const FragmentRef* fragRef() const { return m_pFragRef; } + FragmentRef* fragRef() { return m_pFragRef; } - FragmentRef* fragRef() - { return m_pFragRef; } + SizeType size() const { return m_pResolveInfo->size(); } - SizeType size() const - { return m_pResolveInfo->size(); } - - ResolveInfo* resolveInfo() - { return m_pResolveInfo; } - - const ResolveInfo* resolveInfo() const - { return m_pResolveInfo; } + const ResolveInfo* resolveInfo() const { return m_pResolveInfo; } + ResolveInfo* resolveInfo() { return m_pResolveInfo; } bool hasFragRef() const; // ----- modifiers ----- // void setSize(SizeType pSize) { - assert(NULL != m_pResolveInfo); + assert(m_pResolveInfo != NULL); m_pResolveInfo->setSize(pSize); } - void setValue(ValueType pValue) - { m_Value = pValue; } + void setValue(ValueType pValue) { m_Value = pValue; } void setFragmentRef(FragmentRef* pFragmentRef); void setResolveInfo(const ResolveInfo& pInfo); -private: + private: friend class Chunk<LDSymbol, MCLD_SYMBOLS_PER_INPUT>; - template<class T> friend void* llvm::object_creator(); + template <class T> + friend void* llvm::object_creator(); LDSymbol(); LDSymbol(const LDSymbol& pCopy); LDSymbol& operator=(const LDSymbol& pCopy); -private: + private: // ----- Symbol's fields ----- // ResolveInfo* m_pResolveInfo; FragmentRef* m_pFragRef; ValueType m_Value; - }; -} // namespace mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_LDSYMBOL_H_
diff --git a/include/mcld/LD/MergedStringTable.h b/include/mcld/LD/MergedStringTable.h new file mode 100644 index 0000000..ca18594 --- /dev/null +++ b/include/mcld/LD/MergedStringTable.h
@@ -0,0 +1,62 @@ +//===- MergedStringTable.h ------------------------------------------------===// +// +// The MCLinker Project +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#ifndef MCLD_LD_MERGEDSTRINGTABLE_H_ +#define MCLD_LD_MERGEDSTRINGTABLE_H_ + +#include "mcld/Support/MemoryRegion.h" + +#include <llvm/ADT/StringMap.h> +#include <llvm/ADT/StringRef.h> + +namespace mcld { + +/** \class MergedStringTable + * \brief MergedStringTable represents the mergeable string table. The sections + * with flag SHF_MERGED and SHF_STRING are mergeable. Every string in + * MergedStringTable is unique. + */ +class MergedStringTable { + public: + typedef llvm::StringMap<size_t> StringMapTy; + + public: + MergedStringTable() {} + + /// insertString - insert a string to the string table + /// @return false if the string already exists in the map. + bool insertString(llvm::StringRef pString); + + /// finalizeOffset - finalize the output offset of strings. After this + /// function been called, any string should not be added to this table + /// @return the section size + uint64_t finalizeOffset(); + + /// emit - emit the string table + void emit(MemoryRegion& pRegion); + + /// ----- observers -----/// + /// getOutputOffset - get the output offset of the string. This should be + /// called after finalizeOffset. + size_t getOutputOffset(llvm::StringRef pStr); + + private: + typedef StringMapTy::iterator string_map_iterator; + typedef StringMapTy::const_iterator const_string_map_iterator; + + private: + /// m_StringMap - the string pool of this section. It maps the string to the + /// output offset. The key of this map is the string, and the value is output + /// offset + StringMapTy m_StringMap; +}; + +} // namespace mcld + +#endif // MCLD_LD_MERGEDSTRINGTABLE_H_ +
diff --git a/include/mcld/LD/MsgHandler.h b/include/mcld/LD/MsgHandler.h index 36ba1cd..491edf7 100644 --- a/include/mcld/LD/MsgHandler.h +++ b/include/mcld/LD/MsgHandler.h
@@ -6,23 +6,24 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_MSGHANDLER_H -#define MCLD_LD_MSGHANDLER_H -#include <string> +#ifndef MCLD_LD_MSGHANDLER_H_ +#define MCLD_LD_MSGHANDLER_H_ +#include "mcld/LD/DiagnosticEngine.h" +#include "mcld/Support/Path.h" + #include <llvm/ADT/StringRef.h> #include <llvm/ADT/Twine.h> -#include <mcld/Support/Path.h> -#include <mcld/LD/DiagnosticEngine.h> + +#include <string> namespace mcld { /** \class MsgHandler * \brief MsgHandler controls the timing to output message. */ -class MsgHandler -{ -public: - MsgHandler(DiagnosticEngine& pEngine); +class MsgHandler { + public: + explicit MsgHandler(DiagnosticEngine& pEngine); ~MsgHandler(); bool emit(); @@ -31,89 +32,75 @@ void addString(const std::string& pStr) const; - void addTaggedVal(intptr_t pValue, DiagnosticEngine::ArgumentKind pKind) const; + void addTaggedVal(intptr_t pValue, + DiagnosticEngine::ArgumentKind pKind) const; -private: - void flushCounts() - { m_Engine.state().numArgs = m_NumArgs; } + private: + void flushCounts() { m_Engine.state().numArgs = m_NumArgs; } -private: + private: DiagnosticEngine& m_Engine; mutable unsigned int m_NumArgs; }; -inline const MsgHandler & -operator<<(const MsgHandler& pHandler, llvm::StringRef pStr) -{ +inline const MsgHandler& operator<<(const MsgHandler& pHandler, + llvm::StringRef pStr) { pHandler.addString(pStr); return pHandler; } -inline const MsgHandler & -operator<<(const MsgHandler& pHandler, const std::string& pStr) -{ +inline const MsgHandler& operator<<(const MsgHandler& pHandler, + const std::string& pStr) { pHandler.addString(pStr); return pHandler; } -inline const MsgHandler & -operator<<(const MsgHandler& pHandler, const sys::fs::Path& pPath) -{ +inline const MsgHandler& operator<<(const MsgHandler& pHandler, + const sys::fs::Path& pPath) { pHandler.addString(pPath.native()); return pHandler; } -inline const MsgHandler & -operator<<(const MsgHandler& pHandler, const char* pStr) -{ +inline const MsgHandler& operator<<(const MsgHandler& pHandler, + const char* pStr) { pHandler.addTaggedVal(reinterpret_cast<intptr_t>(pStr), DiagnosticEngine::ak_c_string); return pHandler; } -inline const MsgHandler & -operator<<(const MsgHandler& pHandler, int pValue) -{ +inline const MsgHandler& operator<<(const MsgHandler& pHandler, int pValue) { pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_sint); return pHandler; } -inline const MsgHandler & -operator<<(const MsgHandler& pHandler, unsigned int pValue) -{ +inline const MsgHandler& operator<<(const MsgHandler& pHandler, + unsigned int pValue) { pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_uint); return pHandler; } -inline const MsgHandler & -operator<<(const MsgHandler& pHandler, long pValue) -{ +inline const MsgHandler& operator<<(const MsgHandler& pHandler, long pValue) { pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_sint); return pHandler; } -inline const MsgHandler & -operator<<(const MsgHandler& pHandler, unsigned long pValue) -{ +inline const MsgHandler& operator<<(const MsgHandler& pHandler, + unsigned long pValue) { pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_uint); return pHandler; } -inline const MsgHandler & -operator<<(const MsgHandler& pHandler, unsigned long long pValue) -{ +inline const MsgHandler& operator<<(const MsgHandler& pHandler, + unsigned long long pValue) { pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_ulonglong); return pHandler; } -inline const MsgHandler & -operator<<(const MsgHandler& pHandler, bool pValue) -{ +inline const MsgHandler& operator<<(const MsgHandler& pHandler, bool pValue) { pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_bool); return pHandler; } -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_MSGHANDLER_H_
diff --git a/include/mcld/LD/NamePool.h b/include/mcld/LD/NamePool.h index a5df150..27f124a 100644 --- a/include/mcld/LD/NamePool.h +++ b/include/mcld/LD/NamePool.h
@@ -6,35 +6,30 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_NAMEPOOL_H -#define MCLD_LD_NAMEPOOL_H +#ifndef MCLD_LD_NAMEPOOL_H_ +#define MCLD_LD_NAMEPOOL_H_ -#include <mcld/Config/Config.h> -#include <mcld/ADT/HashTable.h> -#include <mcld/ADT/StringHash.h> -#include <mcld/ADT/Uncopyable.h> -#include <mcld/LD/Resolver.h> -#include <mcld/LD/ResolveInfo.h> -#include <mcld/Support/GCFactory.h> - -#include <utility> +#include "mcld/ADT/HashTable.h" +#include "mcld/ADT/StringHash.h" +#include "mcld/Config/Config.h" +#include "mcld/LD/ResolveInfo.h" +#include "mcld/LD/Resolver.h" +#include "mcld/Support/Compiler.h" +#include "mcld/Support/GCFactory.h" #include <llvm/ADT/StringRef.h> -namespace mcld { +#include <utility> -class StringTable; -class SymbolTableIF; -class SectionData; +namespace mcld { /** \class NamePool * \brief Store symbol and search symbol by name. Can help symbol resolution. * * - MCLinker is responsed for creating NamePool. */ -class NamePool : private Uncopyable -{ -public: +class NamePool { + public: typedef HashTable<ResolveInfo, hash::StringHash<hash::DJB> > Table; typedef Table::iterator syminfo_iterator; typedef Table::const_iterator const_syminfo_iterator; @@ -45,7 +40,7 @@ typedef size_t size_type; -public: + public: explicit NamePool(size_type pSize = 3); ~NamePool(); @@ -53,13 +48,14 @@ // ----- modifiers ----- // /// createSymbol - create a symbol but do not insert into the pool. /// The created symbol did not go through the path of symbol resolution. - ResolveInfo* createSymbol(const llvm::StringRef& pName, - bool pIsDyn, - ResolveInfo::Type pType, - ResolveInfo::Desc pDesc, - ResolveInfo::Binding pBinding, - ResolveInfo::SizeType pSize, - ResolveInfo::Visibility pVisibility = ResolveInfo::Default); + ResolveInfo* createSymbol( + const llvm::StringRef& pName, + bool pIsDyn, + ResolveInfo::Type pType, + ResolveInfo::Desc pDesc, + ResolveInfo::Binding pBinding, + ResolveInfo::SizeType pSize, + ResolveInfo::Visibility pVisibility = ResolveInfo::Default); /// insertSymbol - insert a symbol and resolve the symbol immediately /// @param pOldInfo - if pOldInfo is not NULL, the old ResolveInfo being @@ -80,11 +76,11 @@ /// findSymbol - find the resolved output LDSymbol const LDSymbol* findSymbol(const llvm::StringRef& pName) const; - LDSymbol* findSymbol(const llvm::StringRef& pName); + LDSymbol* findSymbol(const llvm::StringRef& pName); /// findInfo - find the resolved ResolveInfo const ResolveInfo* findInfo(const llvm::StringRef& pName) const; - ResolveInfo* findInfo(const llvm::StringRef& pName); + ResolveInfo* findInfo(const llvm::StringRef& pName); /// insertString - insert a string /// if the string has existed, modify pString to the existing string @@ -92,51 +88,45 @@ llvm::StringRef insertString(const llvm::StringRef& pString); // ----- observers ----- // - size_type size() const - { return m_Table.numOfEntries(); } + size_type size() const { return m_Table.numOfEntries(); } - bool empty() const - { return m_Table.empty(); } + bool empty() const { return m_Table.empty(); } // syminfo_iterator - traverse the ResolveInfo in the resolved HashTable - syminfo_iterator syminfo_begin() - { return m_Table.begin(); } + syminfo_iterator syminfo_begin() { return m_Table.begin(); } - syminfo_iterator syminfo_end() - { return m_Table.end(); } + syminfo_iterator syminfo_end() { return m_Table.end(); } - const_syminfo_iterator syminfo_begin() const - { return m_Table.begin(); } + const_syminfo_iterator syminfo_begin() const { return m_Table.begin(); } - const_syminfo_iterator syminfo_end() const - { return m_Table.end(); } + const_syminfo_iterator syminfo_end() const { return m_Table.end(); } // freeinfo_iterator - traverse the ResolveInfo those do not need to be // resolved, for example, local symbols - freeinfo_iterator freeinfo_begin() - { return m_FreeInfoSet.begin(); } + freeinfo_iterator freeinfo_begin() { return m_FreeInfoSet.begin(); } - freeinfo_iterator freeinfo_end() - { return m_FreeInfoSet.end(); } + freeinfo_iterator freeinfo_end() { return m_FreeInfoSet.end(); } - const_freeinfo_iterator freeinfo_begin() const - { return m_FreeInfoSet.begin(); } + const_freeinfo_iterator freeinfo_begin() const { + return m_FreeInfoSet.begin(); + } - const_freeinfo_iterator freeinfo_end() const - { return m_FreeInfoSet.end(); } + const_freeinfo_iterator freeinfo_end() const { return m_FreeInfoSet.end(); } // ----- capacity ----- // void reserve(size_type pN); size_type capacity() const; -private: + private: Resolver* m_pResolver; Table m_Table; FreeInfoSet m_FreeInfoSet; + + private: + DISALLOW_COPY_AND_ASSIGN(NamePool); }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_NAMEPOOL_H_
diff --git a/include/mcld/LD/ObjectReader.h b/include/mcld/LD/ObjectReader.h index 32a8c0a..c8a5546 100644 --- a/include/mcld/LD/ObjectReader.h +++ b/include/mcld/LD/ObjectReader.h
@@ -6,32 +6,31 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_OBJECTREADER_H -#define MCLD_LD_OBJECTREADER_H +#ifndef MCLD_LD_OBJECTREADER_H_ +#define MCLD_LD_OBJECTREADER_H_ +#include "mcld/ADT/HashTable.h" +#include "mcld/ADT/StringHash.h" #include "mcld/LD/LDReader.h" -#include <mcld/ADT/HashTable.h> -#include <mcld/ADT/StringHash.h> -#include <mcld/LD/ResolveInfo.h> +#include "mcld/LD/ResolveInfo.h" namespace mcld { -class Module; class Input; +class Module; /** \class ObjectReader * \brief ObjectReader provides an common interface for different object * formats. */ -class ObjectReader : public LDReader -{ -protected: - typedef HashTable<ResolveInfo, hash::StringHash<hash::DJB> > GroupSignatureMap; +class ObjectReader : public LDReader { + protected: + typedef HashTable<ResolveInfo, hash::StringHash<hash::DJB> > + GroupSignatureMap; -protected: - ObjectReader() - { } + protected: + ObjectReader() {} -public: + public: virtual ~ObjectReader() { f_GroupSignatureMap.clear(); } virtual bool readHeader(Input& pFile) = 0; @@ -45,18 +44,14 @@ /// This function should be called after symbol resolution. virtual bool readRelocations(Input& pFile) = 0; - GroupSignatureMap& signatures() - { return f_GroupSignatureMap; } + GroupSignatureMap& signatures() { return f_GroupSignatureMap; } - const GroupSignatureMap& signatures() const - { return f_GroupSignatureMap; } + const GroupSignatureMap& signatures() const { return f_GroupSignatureMap; } -protected: + protected: GroupSignatureMap f_GroupSignatureMap; - }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_OBJECTREADER_H_
diff --git a/include/mcld/LD/ObjectWriter.h b/include/mcld/LD/ObjectWriter.h index b58661a..69e50be 100644 --- a/include/mcld/LD/ObjectWriter.h +++ b/include/mcld/LD/ObjectWriter.h
@@ -6,24 +6,23 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_OBJECTWRITER_H -#define MCLD_LD_OBJECTWRITER_H +#ifndef MCLD_LD_OBJECTWRITER_H_ +#define MCLD_LD_OBJECTWRITER_H_ #include <system_error> namespace mcld { -class Module; class FileOutputBuffer; +class Module; /** \class ObjectWriter * \brief ObjectWriter provides a common interface for object file writers. */ -class ObjectWriter -{ -protected: +class ObjectWriter { + protected: ObjectWriter(); -public: + public: virtual ~ObjectWriter(); virtual std::error_code writeObject(Module& pModule, @@ -32,7 +31,6 @@ virtual size_t getOutputSize(const Module& pModule) const = 0; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_OBJECTWRITER_H_
diff --git a/include/mcld/LD/RelocData.h b/include/mcld/LD/RelocData.h index dff4ee0..ed649a2 100644 --- a/include/mcld/LD/RelocData.h +++ b/include/mcld/LD/RelocData.h
@@ -6,13 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_RELOCDATA_H -#define MCLD_LD_RELOCDATA_H +#ifndef MCLD_LD_RELOCDATA_H_ +#define MCLD_LD_RELOCDATA_H_ -#include <mcld/Config/Config.h> -#include <mcld/Fragment/Relocation.h> -#include <mcld/Support/Allocators.h> -#include <mcld/Support/GCFactoryListTraits.h> +#include "mcld/Config/Config.h" +#include "mcld/Fragment/Relocation.h" +#include "mcld/Support/Allocators.h" +#include "mcld/Support/Compiler.h" +#include "mcld/Support/GCFactoryListTraits.h" #include <llvm/ADT/ilist.h> #include <llvm/ADT/ilist_node.h> @@ -27,23 +28,20 @@ /** \class RelocData * \brief RelocData stores Relocation. * - * Since Relocations are created by GCFactory, we use GCFactoryListTraits for the + * Since Relocations are created by GCFactory, we use GCFactoryListTraits for + *the * RelocationList here to avoid iplist to delete Relocations. */ -class RelocData -{ -private: +class RelocData { + private: friend class Chunk<RelocData, MCLD_SECTIONS_PER_INPUT>; RelocData(); - explicit RelocData(LDSection &pSection); + explicit RelocData(LDSection& pSection); - RelocData(const RelocData &); // DO NOT IMPLEMENT - RelocData& operator=(const RelocData &); // DO NOT IMPLEMENT - -public: - typedef llvm::iplist<Relocation, - GCFactoryListTraits<Relocation> > RelocationListType; + public: + typedef llvm::iplist<Relocation, GCFactoryListTraits<Relocation> > + RelocationListType; typedef RelocationListType::reference reference; typedef RelocationListType::const_reference const_reference; @@ -54,7 +52,7 @@ typedef RelocationListType::reverse_iterator reverse_iterator; typedef RelocationListType::const_reverse_iterator const_reverse_iterator; -public: + public: static RelocData* Create(LDSection& pSection); static void Destroy(RelocData*& pSection); @@ -62,10 +60,10 @@ static void Clear(); const LDSection& getSection() const { return *m_pSection; } - LDSection& getSection() { return *m_pSection; } + LDSection& getSection() { return *m_pSection; } const RelocationListType& getRelocationList() const { return m_Relocations; } - RelocationListType& getRelocationList() { return m_Relocations; } + RelocationListType& getRelocationList() { return m_Relocations; } size_t size() const { return m_Relocations.size(); } @@ -74,21 +72,22 @@ RelocData& append(Relocation& pRelocation); Relocation& remove(Relocation& pRelocation); - reference front () { return m_Relocations.front(); } - const_reference front () const { return m_Relocations.front(); } - reference back () { return m_Relocations.back(); } - const_reference back () const { return m_Relocations.back(); } + const_reference front() const { return m_Relocations.front(); } + reference front() { return m_Relocations.front(); } + const_reference back() const { return m_Relocations.back(); } + reference back() { return m_Relocations.back(); } - const_iterator begin () const { return m_Relocations.begin(); } - iterator begin () { return m_Relocations.begin(); } - const_iterator end () const { return m_Relocations.end(); } - iterator end () { return m_Relocations.end(); } + const_iterator begin() const { return m_Relocations.begin(); } + iterator begin() { return m_Relocations.begin(); } + const_iterator end() const { return m_Relocations.end(); } + iterator end() { return m_Relocations.end(); } const_reverse_iterator rbegin() const { return m_Relocations.rbegin(); } - reverse_iterator rbegin() { return m_Relocations.rbegin(); } - const_reverse_iterator rend () const { return m_Relocations.rend(); } - reverse_iterator rend () { return m_Relocations.rend(); } + reverse_iterator rbegin() { return m_Relocations.rbegin(); } + const_reverse_iterator rend() const { return m_Relocations.rend(); } + reverse_iterator rend() { return m_Relocations.rend(); } - template<class Comparator> void sort(Comparator pComparator) { + template <class Comparator> + void sort(Comparator pComparator) { /* FIXME: use llvm::iplist::sort */ std::list<Relocation*> relocs; for (iterator it = begin(), ie = end(); it != ie; ++it) @@ -96,17 +95,21 @@ relocs.sort(pComparator); m_Relocations.clear(); for (std::list<Relocation*>::iterator it = relocs.begin(), - ie = relocs.end(); it != ie; ++it) + ie = relocs.end(); + it != ie; + ++it) { m_Relocations.push_back(*it); + } } -private: + private: RelocationListType m_Relocations; LDSection* m_pSection; + private: + DISALLOW_COPY_AND_ASSIGN(RelocData); }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_RELOCDATA_H_
diff --git a/include/mcld/LD/RelocationFactory.h b/include/mcld/LD/RelocationFactory.h index 205730a..6d5043b 100644 --- a/include/mcld/LD/RelocationFactory.h +++ b/include/mcld/LD/RelocationFactory.h
@@ -6,11 +6,11 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_RELOCATION_FACTORY_H -#define MCLD_LD_RELOCATION_FACTORY_H -#include <mcld/Config/Config.h> -#include <mcld/Support/GCFactory.h> -#include <mcld/Fragment/Relocation.h> +#ifndef MCLD_LD_RELOCATIONFACTORY_H_ +#define MCLD_LD_RELOCATIONFACTORY_H_ +#include "mcld/Config/Config.h" +#include "mcld/Fragment/Relocation.h" +#include "mcld/Support/GCFactory.h" namespace mcld { @@ -22,16 +22,16 @@ * relocation * */ -class RelocationFactory : public GCFactory<Relocation, MCLD_RELOCATIONS_PER_INPUT> -{ -public: +class RelocationFactory + : public GCFactory<Relocation, MCLD_RELOCATIONS_PER_INPUT> { + public: typedef Relocation::Type Type; typedef Relocation::Address Address; typedef Relocation::DWord DWord; typedef Relocation::SWord SWord; -public: - explicit RelocationFactory(); + public: + RelocationFactory(); void setConfig(const LinkerConfig& pConfig); @@ -40,9 +40,7 @@ /// @param pType - the type of the relocation entry /// @param pFragRef - the place to apply the relocation /// @param pAddend - the addend of the relocation entry - Relocation* produce(Type pType, - FragmentRef& pFragRef, - Address pAddend = 0); + Relocation* produce(Type pType, FragmentRef& pFragRef, Address pAddend = 0); /// produceEmptyEntry - produce an empty relocation which /// occupied memory space but all contents set to zero. @@ -50,11 +48,10 @@ void destroy(Relocation* pRelocation); -private: + private: const LinkerConfig* m_pConfig; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_RELOCATIONFACTORY_H_
diff --git a/include/mcld/LD/Relocator.h b/include/mcld/LD/Relocator.h index 82bdf8a..99a530b 100644 --- a/include/mcld/LD/Relocator.h +++ b/include/mcld/LD/Relocator.h
@@ -6,45 +6,34 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_RELOCATOR_H -#define MCLD_RELOCATOR_H +#ifndef MCLD_LD_RELOCATOR_H_ +#define MCLD_LD_RELOCATOR_H_ -#include <mcld/Fragment/Relocation.h> +#include "mcld/Fragment/Relocation.h" -namespace mcld -{ +namespace mcld { -class FragmentLinker; -class TargetLDBackend; +class Input; class IRBuilder; class Module; -class Input; +class TargetLDBackend; /** \class Relocator * \brief Relocator provides the interface of performing relocations */ -class Relocator -{ -public: - typedef Relocation::Type Type; +class Relocator { + public: + typedef Relocation::Type Type; typedef Relocation::Address Address; - typedef Relocation::DWord DWord; - typedef Relocation::SWord SWord; - typedef Relocation::Size Size; + typedef Relocation::DWord DWord; + typedef Relocation::SWord SWord; + typedef Relocation::Size Size; -public: - enum Result { - OK, - BadReloc, - Overflow, - Unsupport, - Unknown - }; + public: + enum Result { OK, BadReloc, Overflow, Unsupported, Unknown }; -public: - Relocator(const LinkerConfig& pConfig) - : m_Config(pConfig) - {} + public: + explicit Relocator(const LinkerConfig& pConfig) : m_Config(pConfig) {} virtual ~Relocator() = 0; @@ -65,7 +54,8 @@ LDSection& pSection, Input& pInput) = 0; - /// issueUndefRefError - Provides a basic version for undefined reference dump. + /// issueUndefRefError - Provides a basic version for undefined reference + /// dump. /// It will handle the filename and function name automatically. /// @param pReloc - a read in relocation entry /// @param pSection - the section of relocation applying target @@ -76,23 +66,19 @@ /// initializeScan - do initialization before scan relocations in pInput /// @return - return true for initialization success - virtual bool initializeScan(Input& pInput) - { return true; } + virtual bool initializeScan(Input& pInput) { return true; } /// finalizeScan - do finalization after scan relocations in pInput /// @return - return true for finalization success - virtual bool finalizeScan(Input& pInput) - { return true; } + virtual bool finalizeScan(Input& pInput) { return true; } /// initializeApply - do initialization before apply relocations in pInput /// @return - return true for initialization success - virtual bool initializeApply(Input& pInput) - { return true; } + virtual bool initializeApply(Input& pInput) { return true; } /// finalizeApply - do finalization after apply relocations in pInput /// @return - return true for finalization success - virtual bool finalizeApply(Input& pInput) - { return true; } + virtual bool finalizeApply(Input& pInput) { return true; } /// partialScanRelocation - When doing partial linking, backend can do any /// modification to relocation to fix the relocation offset after section @@ -101,8 +87,7 @@ /// @param pInputSym - the input LDSymbol of relocation target symbol /// @param pSection - the section of relocation applying target virtual void partialScanRelocation(Relocation& pReloc, - Module& pModule, - const LDSection& pSection); + Module& pModule); // ------ observers -----// virtual TargetLDBackend& getTarget() = 0; @@ -119,17 +104,25 @@ /// access a function pointer. /// Note: Each target relocator should override this function, or be /// conservative and return true to avoid getting folded. - virtual bool mayHaveFunctionPointerAccess(const Relocation& pReloc) const - { return true; } + virtual bool mayHaveFunctionPointerAccess(const Relocation& pReloc) const { + return true; + } -protected: + /// getDebugStringOffset - get the offset from the relocation target. This is + /// used to get the debug string offset. + virtual uint32_t getDebugStringOffset(Relocation& pReloc) const = 0; + + /// applyDebugStringOffset - apply the relocation target to specific offset. + /// This is used to set the debug string offset. + virtual void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset) = 0; + + protected: const LinkerConfig& config() const { return m_Config; } -private: + private: const LinkerConfig& m_Config; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_RELOCATOR_H_
diff --git a/include/mcld/LD/ResolveInfo.h b/include/mcld/LD/ResolveInfo.h index 9155a7c..329a436 100644 --- a/include/mcld/LD/ResolveInfo.h +++ b/include/mcld/LD/ResolveInfo.h
@@ -6,11 +6,11 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_RESOLVEINFO_H -#define MCLD_LD_RESOLVEINFO_H +#ifndef MCLD_LD_RESOLVEINFO_H_ +#define MCLD_LD_RESOLVEINFO_H_ -#include <llvm/Support/DataTypes.h> #include <llvm/ADT/StringRef.h> +#include <llvm/Support/DataTypes.h> namespace mcld { @@ -27,16 +27,17 @@ * - Type - what the symbol refers to * - Size - the size of the symbol point to * - Value - the pointer to another LDSymbol - * In order to save the memory and speed up the performance, FragmentLinker uses + * In order to save the memory and speed up the performance, FragmentLinker + *uses * a bit field to store all attributes. * * The maximum string length is (2^16 - 1) */ -class ResolveInfo -{ -friend class FragmentLinker; -friend class IRBuilder; -public: +class ResolveInfo { + friend class FragmentLinker; + friend class IRBuilder; + + public: typedef uint64_t SizeType; /** \enum Type @@ -46,16 +47,16 @@ * MachO does not need this, and can not jump between Thumb and ARM code. */ enum Type { - NoType = 0, - Object = 1, - Function = 2, - Section = 3, - File = 4, - CommonBlock = 5, - ThreadLocal = 6, - IndirectFunc = 10, - LoProc = 13, - HiProc = 15 + NoType = 0, + Object = 1, + Function = 2, + Section = 3, + File = 4, + CommonBlock = 5, + ThreadLocal = 6, + IndirectFunc = 10, + LoProc = 13, + HiProc = 15 }; /** \enum Desc @@ -64,33 +65,16 @@ * Follow the naming in MachO. Like MachO nlist::n_desc * In ELF, is a part of st_shndx */ - enum Desc { - Undefined = 0, - Define = 1, - Common = 2, - Indirect = 3, - NoneDesc - }; + enum Desc { Undefined = 0, Define = 1, Common = 2, Indirect = 3, NoneDesc }; - enum Binding { - Global = 0, - Weak = 1, - Local = 2, - Absolute = 3, - NoneBinding - }; + enum Binding { Global = 0, Weak = 1, Local = 2, Absolute = 3, NoneBinding }; - enum Visibility { - Default = 0, - Internal = 1, - Hidden = 2, - Protected = 3 - }; + enum Visibility { Default = 0, Internal = 1, Hidden = 2, Protected = 3 }; // ----- For HashTable ----- // typedef llvm::StringRef key_type; -public: + public: // ----- factory method ----- // static ResolveInfo* Create(const key_type& pKey); @@ -123,8 +107,7 @@ void setReserved(uint32_t pReserved); - void setSize(SizeType pSize) - { m_Size = pSize; } + void setSize(SizeType pSize) { m_Size = pSize; } void override(const ResolveInfo& pForm); @@ -132,8 +115,9 @@ void overrideVisibility(const ResolveInfo& pFrom); - void setSymPtr(const LDSymbol* pSymPtr) - { m_Ptr.sym_ptr = const_cast<LDSymbol*>(pSymPtr); } + void setSymPtr(const LDSymbol* pSymPtr) { + m_Ptr.sym_ptr = const_cast<LDSymbol*>(pSymPtr); + } void setLink(const ResolveInfo* pTarget) { m_Ptr.info_ptr = const_cast<ResolveInfo*>(pTarget); @@ -179,37 +163,27 @@ uint32_t reserved() const; - uint8_t other() const - { return (uint8_t)visibility(); } + uint8_t other() const { return (uint8_t)visibility(); } Visibility visibility() const; - LDSymbol* outSymbol() - { return m_Ptr.sym_ptr; } + LDSymbol* outSymbol() { return m_Ptr.sym_ptr; } - const LDSymbol* outSymbol() const - { return m_Ptr.sym_ptr; } + const LDSymbol* outSymbol() const { return m_Ptr.sym_ptr; } - ResolveInfo* link() - { return m_Ptr.info_ptr; } + ResolveInfo* link() { return m_Ptr.info_ptr; } - const ResolveInfo* link() const - { return m_Ptr.info_ptr; } + const ResolveInfo* link() const { return m_Ptr.info_ptr; } - SizeType size() const - { return m_Size; } + SizeType size() const { return m_Size; } - const char* name() const - { return m_Name; } + const char* name() const { return m_Name; } - unsigned int nameSize() const - { return (m_BitField >> NAME_LENGTH_OFFSET); } + unsigned int nameSize() const { return (m_BitField >> NAME_LENGTH_OFFSET); } - uint32_t info() const - { return (m_BitField & INFO_MASK); } + uint32_t info() const { return (m_BitField & INFO_MASK); } - uint32_t bitfield() const - { return m_BitField; } + uint32_t bitfield() const { return m_BitField; } // shouldForceLocal - check if this symbol should be forced to local bool shouldForceLocal(const LinkerConfig& pConfig); @@ -217,83 +191,84 @@ // ----- For HashTable ----- // bool compare(const key_type& pKey); -private: - static const uint32_t GLOBAL_OFFSET = 0; - static const uint32_t GLOBAL_MASK = 1; + private: + static const uint32_t GLOBAL_OFFSET = 0; + static const uint32_t GLOBAL_MASK = 1; - static const uint32_t DYN_OFFSET = 1; - static const uint32_t DYN_MASK = 1 << DYN_OFFSET; + static const uint32_t DYN_OFFSET = 1; + static const uint32_t DYN_MASK = 1 << DYN_OFFSET; - static const uint32_t DESC_OFFSET = 2; - static const uint32_t DESC_MASK = 0x3 << DESC_OFFSET; + static const uint32_t DESC_OFFSET = 2; + static const uint32_t DESC_MASK = 0x3 << DESC_OFFSET; - static const uint32_t LOCAL_OFFSET = 4; - static const uint32_t LOCAL_MASK = 1 << LOCAL_OFFSET; + static const uint32_t LOCAL_OFFSET = 4; + static const uint32_t LOCAL_MASK = 1 << LOCAL_OFFSET; - static const uint32_t BINDING_MASK = GLOBAL_MASK | LOCAL_MASK; + static const uint32_t BINDING_MASK = GLOBAL_MASK | LOCAL_MASK; - static const uint32_t VISIBILITY_OFFSET = 5; - static const uint32_t VISIBILITY_MASK = 0x3 << VISIBILITY_OFFSET; + static const uint32_t VISIBILITY_OFFSET = 5; + static const uint32_t VISIBILITY_MASK = 0x3 << VISIBILITY_OFFSET; - static const uint32_t TYPE_OFFSET = 7; - static const uint32_t TYPE_MASK = 0xF << TYPE_OFFSET; + static const uint32_t TYPE_OFFSET = 7; + static const uint32_t TYPE_MASK = 0xF << TYPE_OFFSET; - static const uint32_t SYMBOL_OFFSET = 11; - static const uint32_t SYMBOL_MASK = 1 << SYMBOL_OFFSET; + static const uint32_t SYMBOL_OFFSET = 11; + static const uint32_t SYMBOL_MASK = 1 << SYMBOL_OFFSET; - static const uint32_t RESERVED_OFFSET = 12; - static const uint32_t RESERVED_MASK = 0xF << RESERVED_OFFSET; + static const uint32_t RESERVED_OFFSET = 12; + static const uint32_t RESERVED_MASK = 0xF << RESERVED_OFFSET; - static const uint32_t IN_DYN_OFFSET = 16; - static const uint32_t IN_DYN_MASK = 1 << IN_DYN_OFFSET; + static const uint32_t IN_DYN_OFFSET = 16; + static const uint32_t IN_DYN_MASK = 1 << IN_DYN_OFFSET; static const uint32_t NAME_LENGTH_OFFSET = 17; - static const uint32_t INFO_MASK = 0xF; - static const uint32_t RESOLVE_MASK = 0xFFFF; + static const uint32_t INFO_MASK = 0xF; + static const uint32_t RESOLVE_MASK = 0xFFFF; union SymOrInfo { - LDSymbol* sym_ptr; + LDSymbol* sym_ptr; ResolveInfo* info_ptr; }; -public: - static const uint32_t global_flag = 0 << GLOBAL_OFFSET; - static const uint32_t weak_flag = 1 << GLOBAL_OFFSET; - static const uint32_t regular_flag = 0 << DYN_OFFSET; - static const uint32_t dynamic_flag = 1 << DYN_OFFSET; - static const uint32_t undefine_flag = 0 << DESC_OFFSET; - static const uint32_t define_flag = 1 << DESC_OFFSET; - static const uint32_t common_flag = 2 << DESC_OFFSET; - static const uint32_t indirect_flag = 3 << DESC_OFFSET; - static const uint32_t local_flag = 1 << LOCAL_OFFSET; - static const uint32_t absolute_flag = BINDING_MASK; - static const uint32_t object_flag = Object << TYPE_OFFSET; - static const uint32_t function_flag = Function << TYPE_OFFSET; - static const uint32_t section_flag = Section << TYPE_OFFSET; - static const uint32_t file_flag = File << TYPE_OFFSET; - static const uint32_t string_flag = 0 << SYMBOL_OFFSET; - static const uint32_t symbol_flag = 1 << SYMBOL_OFFSET; - static const uint32_t indyn_flag = 1 << IN_DYN_OFFSET; + public: + static const uint32_t global_flag = 0 << GLOBAL_OFFSET; + static const uint32_t weak_flag = 1 << GLOBAL_OFFSET; + static const uint32_t regular_flag = 0 << DYN_OFFSET; + static const uint32_t dynamic_flag = 1 << DYN_OFFSET; + static const uint32_t undefine_flag = 0 << DESC_OFFSET; + static const uint32_t define_flag = 1 << DESC_OFFSET; + static const uint32_t common_flag = 2 << DESC_OFFSET; + static const uint32_t indirect_flag = 3 << DESC_OFFSET; + static const uint32_t local_flag = 1 << LOCAL_OFFSET; + static const uint32_t absolute_flag = BINDING_MASK; + static const uint32_t object_flag = Object << TYPE_OFFSET; + static const uint32_t function_flag = Function << TYPE_OFFSET; + static const uint32_t section_flag = Section << TYPE_OFFSET; + static const uint32_t file_flag = File << TYPE_OFFSET; + static const uint32_t string_flag = 0 << SYMBOL_OFFSET; + static const uint32_t symbol_flag = 1 << SYMBOL_OFFSET; + static const uint32_t indyn_flag = 1 << IN_DYN_OFFSET; -private: + private: ResolveInfo(); ResolveInfo(const ResolveInfo& pCopy); ResolveInfo& operator=(const ResolveInfo& pCopy); ~ResolveInfo(); -private: + private: SizeType m_Size; SymOrInfo m_Ptr; /** m_BitField - * 31 ... 17 16 15 12 11 10..7 6 .. 5 4 3 2 1 0 - * |length of m_Name|InDyn|reserved|Symbol|Type |ELF visibility|Local|Com|Def|Dyn|Weak| + * 31 ... 17 16 15 12 11 10..7 6 .. 5 4 3 2 + * 1 0 + * |length of m_Name|InDyn|reserved|Symbol|Type |ELF + * visibility|Local|Com|Def|Dyn|Weak| */ uint32_t m_BitField; char m_Name[]; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_RESOLVEINFO_H_
diff --git a/include/mcld/LD/Resolver.h b/include/mcld/LD/Resolver.h index c66431d..9b19716 100644 --- a/include/mcld/LD/Resolver.h +++ b/include/mcld/LD/Resolver.h
@@ -6,17 +6,17 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_RESOLVER_H -#define MCLD_LD_RESOLVER_H +#ifndef MCLD_LD_RESOLVER_H_ +#define MCLD_LD_RESOLVER_H_ +#include "mcld/LD/LDSymbol.h" + #include <string> #include <utility> -#include <mcld/LD/LDSymbol.h> -namespace mcld -{ +namespace mcld { -class ResolveInfo; class NamePool; +class ResolveInfo; /** \class Resolver * \brief Resolver binds a symbol reference from one file to a symbol @@ -26,15 +26,9 @@ * two symbols depends on their type, binding and whether it is belonging to * a shared object. */ -class Resolver -{ -public: - enum Action { - Success, - Warning, - Abort, - LastAction - }; +class Resolver { + public: + enum Action { Success, Warning, Abort, LastAction }; /** \class Resolver::Result * \brief the result of symbol resolution @@ -48,33 +42,32 @@ bool overriden; }; -public: + public: virtual ~Resolver(); /// shouldOverride - Can resolver override the symbol pOld by the symbol pNew? /// @return the action should be taken. /// @param pOld the symbol which may be overridden. /// @param pNew the symbol which is used to replace pOld - virtual bool resolve(ResolveInfo & __restrict__ pOld, - const ResolveInfo & __restrict__ pNew, - bool &pOverride, LDSymbol::ValueType pValue) const = 0; + virtual bool resolve(ResolveInfo& __restrict__ pOld, + const ResolveInfo& __restrict__ pNew, + bool& pOverride, + LDSymbol::ValueType pValue) const = 0; /// resolveAgain - Can override by derived classes. /// @return the pointer to resolved ResolveInfo /// @return is the symbol existent? virtual void resolveAgain(NamePool& pNamePool, - unsigned int pAction, - ResolveInfo& __restrict__ pOld, - const ResolveInfo& __restrict__ pNew, - Result& pResult) const { + unsigned int pAction, + ResolveInfo& __restrict__ pOld, + const ResolveInfo& __restrict__ pNew, + Result& pResult) const { pResult.info = NULL; pResult.existent = false; pResult.overriden = false; } - }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_RESOLVER_H_
diff --git a/include/mcld/LD/SectionData.h b/include/mcld/LD/SectionData.h index ddafaf1..22cda34 100644 --- a/include/mcld/LD/SectionData.h +++ b/include/mcld/LD/SectionData.h
@@ -6,17 +6,18 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_SECTIONDATA_H -#define MCLD_LD_SECTIONDATA_H +#ifndef MCLD_LD_SECTIONDATA_H_ +#define MCLD_LD_SECTIONDATA_H_ + +#include "mcld/Config/Config.h" +#include "mcld/Fragment/Fragment.h" +#include "mcld/Support/Allocators.h" +#include "mcld/Support/Compiler.h" #include <llvm/ADT/ilist.h> #include <llvm/ADT/ilist_node.h> #include <llvm/Support/DataTypes.h> -#include <mcld/Config/Config.h> -#include <mcld/Support/Allocators.h> -#include <mcld/Fragment/Fragment.h> - namespace mcld { class LDSection; @@ -24,18 +25,14 @@ /** \class SectionData * \brief SectionData provides a container for all Fragments. */ -class SectionData -{ -private: +class SectionData { + private: friend class Chunk<SectionData, MCLD_SECTIONS_PER_INPUT>; SectionData(); - explicit SectionData(LDSection &pSection); + explicit SectionData(LDSection& pSection); - SectionData(const SectionData &); // DO NOT IMPLEMENT - SectionData& operator=(const SectionData &); // DO NOT IMPLEMENT - -public: + public: typedef llvm::iplist<Fragment> FragmentListType; typedef FragmentListType::reference reference; @@ -47,7 +44,7 @@ typedef FragmentListType::reverse_iterator reverse_iterator; typedef FragmentListType::const_reverse_iterator const_reverse_iterator; -public: + public: static SectionData* Create(LDSection& pSection); static void Destroy(SectionData*& pSection); @@ -55,36 +52,37 @@ static void Clear(); const LDSection& getSection() const { return *m_pSection; } - LDSection& getSection() { return *m_pSection; } + LDSection& getSection() { return *m_pSection; } - FragmentListType &getFragmentList() { return m_Fragments; } - const FragmentListType &getFragmentList() const { return m_Fragments; } + const FragmentListType& getFragmentList() const { return m_Fragments; } + FragmentListType& getFragmentList() { return m_Fragments; } size_t size() const { return m_Fragments.size(); } bool empty() const { return m_Fragments.empty(); } - reference front () { return m_Fragments.front(); } - const_reference front () const { return m_Fragments.front(); } - reference back () { return m_Fragments.back(); } - const_reference back () const { return m_Fragments.back(); } + reference front() { return m_Fragments.front(); } + const_reference front() const { return m_Fragments.front(); } + reference back() { return m_Fragments.back(); } + const_reference back() const { return m_Fragments.back(); } - const_iterator begin () const { return m_Fragments.begin(); } - iterator begin () { return m_Fragments.begin(); } - const_iterator end () const { return m_Fragments.end(); } - iterator end () { return m_Fragments.end(); } + const_iterator begin() const { return m_Fragments.begin(); } + iterator begin() { return m_Fragments.begin(); } + const_iterator end() const { return m_Fragments.end(); } + iterator end() { return m_Fragments.end(); } const_reverse_iterator rbegin() const { return m_Fragments.rbegin(); } - reverse_iterator rbegin() { return m_Fragments.rbegin(); } - const_reverse_iterator rend () const { return m_Fragments.rend(); } - reverse_iterator rend () { return m_Fragments.rend(); } + reverse_iterator rbegin() { return m_Fragments.rbegin(); } + const_reverse_iterator rend() const { return m_Fragments.rend(); } + reverse_iterator rend() { return m_Fragments.rend(); } -private: + private: FragmentListType m_Fragments; LDSection* m_pSection; + private: + DISALLOW_COPY_AND_ASSIGN(SectionData); }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_SECTIONDATA_H_
diff --git a/include/mcld/LD/SectionSymbolSet.h b/include/mcld/LD/SectionSymbolSet.h index 0f3b6e7..3de1cf3 100644 --- a/include/mcld/LD/SectionSymbolSet.h +++ b/include/mcld/LD/SectionSymbolSet.h
@@ -6,15 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_SECTIONSYMBOLSET_H -#define MCLD_LD_SECTIONSYMBOLSET_H +#ifndef MCLD_LD_SECTIONSYMBOLSET_H_ +#define MCLD_LD_SECTIONSYMBOLSET_H_ -#include <mcld/ADT/HashTable.h> -#include <mcld/ADT/HashEntry.h> -#include <mcld/MC/SymbolCategory.h> +#include "mcld/ADT/HashTable.h" +#include "mcld/ADT/HashEntry.h" +#include "mcld/MC/SymbolCategory.h" -namespace mcld -{ +namespace mcld { class LDSection; class NamePool; @@ -24,12 +23,11 @@ * \brief SectionSymbolSet contains the section symbols defined by linker for * the output sections */ -class SectionSymbolSet -{ -public: +class SectionSymbolSet { + public: typedef SymbolCategory SymbolTable; -public: + public: SectionSymbolSet(); ~SectionSymbolSet(); @@ -45,19 +43,17 @@ LDSymbol* get(const LDSection& pOutSect); const LDSymbol* get(const LDSection& pOutSect) const; -private: + private: /// sectCompare - hash compare function for LDSection* - struct SectCompare - { - bool operator()(const LDSection* X, const LDSection* Y) const - { return (X==Y); } + struct SectCompare { + bool operator()(const LDSection* X, const LDSection* Y) const { + return (X == Y); + } }; /// SectPtrHash - hash function for LDSection* - struct SectPtrHash - { - size_t operator()(const LDSection* pKey) const - { + struct SectPtrHash { + size_t operator()(const LDSection* pKey) const { return (unsigned((uintptr_t)pKey) >> 4) ^ (unsigned((uintptr_t)pKey) >> 9); } @@ -68,11 +64,10 @@ SectPtrHash, EntryFactory<SectHashEntryType> > SectHashTableType; -private: + private: SectHashTableType* m_pSectionSymbolMap; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_SECTIONSYMBOLSET_H_
diff --git a/include/mcld/LD/StaticResolver.h b/include/mcld/LD/StaticResolver.h index dfe0784..35ff7e7 100644 --- a/include/mcld/LD/StaticResolver.h +++ b/include/mcld/LD/StaticResolver.h
@@ -6,53 +6,51 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_STATICRESOLVER_H -#define MCLD_LD_STATICRESOLVER_H -#include <string> -#include <mcld/LD/Resolver.h> -#include <mcld/LD/ResolveInfo.h> +#ifndef MCLD_LD_STATICRESOLVER_H_ +#define MCLD_LD_STATICRESOLVER_H_ +#include "mcld/LD/ResolveInfo.h" +#include "mcld/LD/Resolver.h" -namespace mcld -{ +#include <string> + +namespace mcld { class NamePool; /** \class StaticResolver */ -class StaticResolver : public Resolver -{ -public: +class StaticResolver : public Resolver { + public: /** \enum LinkAction * LinkAction follows BFD:linker.c (binary file descriptor). * List all actions to take in the state table */ - enum LinkAction - { - FAIL, /* abort. */ - NOACT, /* no action. */ - UND, /* override by symbol undefined symbol. */ - WEAK, /* override by symbol weak undefined. */ - DEF, /* override by symbol defined. */ - DEFW, /* override by symbol weak defined. */ - DEFD, /* override by symbol dynamic defined. */ - DEFWD, /* override by symbol dynamic weak defined. */ - MDEFD, /* mark symbol dynamic defined. */ - MDEFWD, /* mark symbol dynamic weak defined. */ - DUND, /* override dynamic defined symbol by undefined one. */ - DUNDW, /* oevrride dynamic defined symbol by weak undefined one. */ - COM, /* override by symbol common. */ - CREF, /* Possibly warn about common reference to defined symbol. */ - CDEF, /* redefine existing common symbol. */ - BIG, /* override by symbol common using largest size. */ - MBIG, /* mark common symbol by larger size. */ - IND, /* override by indirect symbol. */ - CIND, /* mark indirect symbol from existing common symbol. */ - MDEF, /* multiple definition error. */ - MIND, /* multiple indirect symbols. */ - REFC /* Mark indirect symbol referenced and then CYCLE. */ + enum LinkAction { + FAIL, // abort. + NOACT, // no action. + UND, // override by symbol undefined symbol. + WEAK, // override by symbol weak undefined. + DEF, // override by symbol defined. + DEFW, // override by symbol weak defined. + DEFD, // override by symbol dynamic defined. + DEFWD, // override by symbol dynamic weak defined. + MDEFD, // mark symbol dynamic defined. + MDEFWD, // mark symbol dynamic weak defined. + DUND, // override dynamic defined symbol by undefined one. + DUNDW, // oevrride dynamic defined symbol by weak undefined one. + COM, // override by symbol common. + CREF, // Possibly warn about common reference to defined symbol. + CDEF, // redefine existing common symbol. + BIG, // override by symbol common using largest size. + MBIG, // mark common symbol by larger size. + IND, // override by indirect symbol. + CIND, // mark indirect symbol from existing common symbol. + MDEF, // multiple definition error. + MIND, // multiple indirect symbols. + REFC // Mark indirect symbol referenced and then CYCLE. }; -private: + private: // These are the values generated by the bit codes. /** Encoding: * D -> define @@ -62,28 +60,26 @@ * C -> common * I -> indirect */ - enum - { - U = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::undefine_flag, - w_U = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::undefine_flag, - d_U = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::undefine_flag, - wd_U = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::undefine_flag, - D = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::define_flag, - w_D = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::define_flag, - d_D = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::define_flag, - wd_D = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::define_flag, - C = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::common_flag, - w_C = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::common_flag, - d_C = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::common_flag, - wd_C = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::common_flag, - I = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::indirect_flag, - w_I = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::indirect_flag, - d_I = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::indirect_flag, - wd_I = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::indirect_flag + enum { + U = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::undefine_flag, // NOLINT + w_U = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::undefine_flag, // NOLINT + d_U = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::undefine_flag, // NOLINT + wd_U = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::undefine_flag, // NOLINT + D = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::define_flag, // NOLINT + w_D = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::define_flag, // NOLINT + d_D = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::define_flag, // NOLINT + wd_D = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::define_flag, // NOLINT + C = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::common_flag, // NOLINT + w_C = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::common_flag, // NOLINT + d_C = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::common_flag, // NOLINT + wd_C = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::common_flag, // NOLINT + I = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::indirect_flag, // NOLINT + w_I = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::indirect_flag, // NOLINT + d_I = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::indirect_flag, // NOLINT + wd_I = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::indirect_flag // NOLINT }; - enum ORDINATE - { + enum ORDINATE { U_ORD, w_U_ORD, d_U_ORD, @@ -99,18 +95,19 @@ LAST_ORD }; -public: + public: virtual ~StaticResolver(); /// shouldOverride - Can resolver override the symbol pOld by the symbol pNew? /// @return successfully resolved, return true; otherwise, return false. /// @param pOld the symbol which may be overridden. /// @param pNew the symbol which is used to replace pOld - virtual bool resolve(ResolveInfo & __restrict__ pOld, - const ResolveInfo & __restrict__ pNew, - bool &pOverride, LDSymbol::ValueType pValue) const; + virtual bool resolve(ResolveInfo& __restrict__ pOld, + const ResolveInfo& __restrict__ pNew, + bool& pOverride, + LDSymbol::ValueType pValue) const; -private: + private: inline unsigned int getOrdinate(const ResolveInfo& pInfo) const { if (pInfo.isAbsolute() && pInfo.isDyn()) return d_D_ORD; @@ -128,7 +125,6 @@ } }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_STATICRESOLVER_H_
diff --git a/include/mcld/LD/StubFactory.h b/include/mcld/LD/StubFactory.h index 23dc5ec..2a093d0 100644 --- a/include/mcld/LD/StubFactory.h +++ b/include/mcld/LD/StubFactory.h
@@ -6,26 +6,26 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_STUBFACTORY_H -#define MCLD_LD_STUBFACTORY_H +#ifndef MCLD_LD_STUBFACTORY_H_ +#define MCLD_LD_STUBFACTORY_H_ #include <llvm/Support/DataTypes.h> + #include <vector> namespace mcld { -class Stub; -class Relocation; class BranchIslandFactory; class IRBuilder; +class Relocation; +class Stub; /** \class StubFactory * \brief the clone factory of Stub * */ -class StubFactory -{ -public: +class StubFactory { + public: ~StubFactory(); /// addPrototype - register a stub prototype @@ -37,20 +37,20 @@ IRBuilder& pBuilder, BranchIslandFactory& pBRIslandFactory); -private: + private: /// findPrototype - find if there is a registered stub prototype for the given /// relocation Stub* findPrototype(const Relocation& pReloc, const uint64_t pSource, uint64_t pTargetSymValue); -private: - typedef std::vector<Stub*> StubPoolType; + private: + typedef std::vector<Stub*> StubPoolType; -private: - StubPoolType m_StubPool; // stub pool + private: + StubPoolType m_StubPool; // stub pool }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_LD_STUBFACTORY_H_
diff --git a/include/mcld/LD/TextDiagnosticPrinter.h b/include/mcld/LD/TextDiagnosticPrinter.h index 262901b..60939aa 100644 --- a/include/mcld/LD/TextDiagnosticPrinter.h +++ b/include/mcld/LD/TextDiagnosticPrinter.h
@@ -6,23 +6,23 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_TEXTDIAGNOSTICPRINTER_H -#define MCLD_LD_TEXTDIAGNOSTICPRINTER_H -#include <mcld/LD/DiagnosticPrinter.h> +#ifndef MCLD_LD_TEXTDIAGNOSTICPRINTER_H_ +#define MCLD_LD_TEXTDIAGNOSTICPRINTER_H_ +#include "mcld/LD/DiagnosticPrinter.h" + #include <llvm/Support/raw_ostream.h> -namespace mcld -{ +namespace mcld { class LinkerConfig; /** \class TextDiagnosticPrinter * \brief The plain, text-based DiagnosticPrinter. */ -class TextDiagnosticPrinter : public DiagnosticPrinter -{ -public: - TextDiagnosticPrinter(llvm::raw_ostream& pOStream, const LinkerConfig& pConfig); +class TextDiagnosticPrinter : public DiagnosticPrinter { + public: + TextDiagnosticPrinter(llvm::raw_ostream& pOStream, + const LinkerConfig& pConfig); virtual ~TextDiagnosticPrinter(); @@ -35,13 +35,12 @@ virtual void endInput(); -private: + private: llvm::raw_ostream& m_OStream; const LinkerConfig& m_Config; const Input* m_pInput; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LD_TEXTDIAGNOSTICPRINTER_H_
diff --git a/include/mcld/Linker.h b/include/mcld/Linker.h index 1982c13..9fe8f8f 100644 --- a/include/mcld/Linker.h +++ b/include/mcld/Linker.h
@@ -6,32 +6,28 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LINKER_H -#define MCLD_LINKER_H +#ifndef MCLD_LINKER_H_ +#define MCLD_LINKER_H_ #include <string> namespace mcld { -class Module; -class LinkerConfig; -class LinkerScript; - -class Target; -class TargetLDBackend; - -class IRBuilder; -class ObjectLinker; - class FileHandle; class FileOutputBuffer; +class IRBuilder; +class LinkerConfig; +class LinkerScript; +class Module; +class ObjectLinker; +class Target; +class TargetLDBackend; /** \class Linker * \brief Linker is a modular linker. */ -class Linker -{ -public: +class Linker { + public: Linker(); ~Linker(); @@ -63,7 +59,7 @@ bool reset(); -private: + private: bool initTarget(); bool initBackend(); @@ -72,7 +68,7 @@ bool initEmulator(LinkerScript& pScript); -private: + private: LinkerConfig* m_pConfig; IRBuilder* m_pIRBuilder; @@ -81,7 +77,6 @@ ObjectLinker* m_pObjLinker; }; -} // namespace of MC Linker +} // namespace mcld -#endif - +#endif // MCLD_LINKER_H_
diff --git a/include/mcld/LinkerConfig.h b/include/mcld/LinkerConfig.h index 4507206..36033e7 100644 --- a/include/mcld/LinkerConfig.h +++ b/include/mcld/LinkerConfig.h
@@ -6,17 +6,16 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LINKERCONFIG_H -#define MCLD_LINKERCONFIG_H +#ifndef MCLD_LINKERCONFIG_H_ +#define MCLD_LINKERCONFIG_H_ + +#include "mcld/GeneralOptions.h" +#include "mcld/TargetOptions.h" +#include "mcld/AttributeOption.h" +#include "mcld/Support/Path.h" #include <llvm/ADT/Triple.h> -#include <mcld/GeneralOptions.h> -#include <mcld/TargetOptions.h> -#include <mcld/BitcodeOption.h> -#include <mcld/AttributeOption.h> -#include <mcld/Support/Path.h> - #include <string> namespace mcld { @@ -27,17 +26,9 @@ * bitcode() - the bitcode being linked * attribute() - the attribute options */ -class LinkerConfig -{ -public: - enum CodeGenType { - Unknown, - Object, - DynObj, - Exec, - External, - Binary - }; +class LinkerConfig { + public: + enum CodeGenType { Unknown, Object, DynObj, Exec, External, Binary }; /** \enum CodePosition * CodePosition indicates the ability of the generated output to be @@ -56,30 +47,27 @@ * output. */ enum CodePosition { - Independent, ///< Position Independent - DynamicDependent, ///< Can call outside libraries - StaticDependent, ///< Can not call outside libraries - Unset ///< Undetermine code position mode + Independent, ///< Position Independent + DynamicDependent, ///< Can call outside libraries + StaticDependent, ///< Can not call outside libraries + Unset ///< Undetermine code position mode }; -public: + public: LinkerConfig(); - explicit LinkerConfig(const std::string &pTripleString); + explicit LinkerConfig(const std::string& pTripleString); ~LinkerConfig(); const GeneralOptions& options() const { return m_Options; } - GeneralOptions& options() { return m_Options; } + GeneralOptions& options() { return m_Options; } - const TargetOptions& targets() const { return m_Targets; } - TargetOptions& targets() { return m_Targets; } - - const BitcodeOption& bitcode() const { return m_Bitcode; } - BitcodeOption& bitcode() { return m_Bitcode; } + const TargetOptions& targets() const { return m_Targets; } + TargetOptions& targets() { return m_Targets; } const AttributeOption& attribute() const { return m_Attribute; } - AttributeOption& attribute() { return m_Attribute; } + AttributeOption& attribute() { return m_Attribute; } CodeGenType codeGenType() const { return m_CodeGenType; } @@ -88,24 +76,22 @@ CodePosition codePosition() const { return m_CodePosition; } void setCodePosition(CodePosition pPosition) { m_CodePosition = pPosition; } - bool isCodeIndep() const { return (Independent == m_CodePosition); } + bool isCodeIndep() const { return (Independent == m_CodePosition); } bool isCodeDynamic() const { return (DynamicDependent == m_CodePosition); } - bool isCodeStatic() const { return (StaticDependent == m_CodePosition); } + bool isCodeStatic() const { return (StaticDependent == m_CodePosition); } static const char* version(); -private: + private: // ----- General Options ----- // GeneralOptions m_Options; TargetOptions m_Targets; - BitcodeOption m_Bitcode; AttributeOption m_Attribute; CodeGenType m_CodeGenType; CodePosition m_CodePosition; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LINKERCONFIG_H_
diff --git a/include/mcld/LinkerScript.h b/include/mcld/LinkerScript.h index 581c517..3e2737e 100644 --- a/include/mcld/LinkerScript.h +++ b/include/mcld/LinkerScript.h
@@ -6,18 +6,21 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LINKERSCRIPT_H -#define MCLD_LINKERSCRIPT_H +#ifndef MCLD_LINKERSCRIPT_H_ +#define MCLD_LINKERSCRIPT_H_ + +#include "mcld/ADT/HashTable.h" +#include "mcld/ADT/StringEntry.h" +#include "mcld/ADT/StringHash.h" +#include "mcld/MC/SearchDirs.h" +#include "mcld/Object/SectionMap.h" +#include "mcld/Script/AssertCmd.h" +#include "mcld/Script/Assignment.h" + +#include <llvm/ADT/StringRef.h> + #include <string> #include <vector> -#include <llvm/ADT/StringRef.h> -#include <mcld/ADT/StringEntry.h> -#include <mcld/ADT/StringHash.h> -#include <mcld/ADT/HashTable.h> -#include <mcld/Object/SectionMap.h> -#include <mcld/MC/SearchDirs.h> -#include <mcld/Script/Assignment.h> -#include <mcld/Script/AssertCmd.h> namespace mcld { @@ -26,9 +29,8 @@ /** \class LinkerScript * */ -class LinkerScript -{ -public: +class LinkerScript { + public: typedef HashTable<StringEntry<llvm::StringRef>, hash::StringHash<hash::DJB>, StringEntryFactory<llvm::StringRef> > SymbolRenameMap; @@ -41,34 +43,34 @@ typedef std::vector<AssertCmd> Assertions; -public: + public: LinkerScript(); ~LinkerScript(); const SymbolRenameMap& renameMap() const { return m_SymbolRenames; } - SymbolRenameMap& renameMap() { return m_SymbolRenames; } + SymbolRenameMap& renameMap() { return m_SymbolRenames; } const AddressMap& addressMap() const { return m_AddressMap; } - AddressMap& addressMap() { return m_AddressMap; } + AddressMap& addressMap() { return m_AddressMap; } const SectionMap& sectionMap() const { return m_SectionMap; } - SectionMap& sectionMap() { return m_SectionMap; } + SectionMap& sectionMap() { return m_SectionMap; } const Assignments& assignments() const { return m_Assignments; } - Assignments& assignments() { return m_Assignments; } + Assignments& assignments() { return m_Assignments; } const Assertions& assertions() const { return m_Assertions; } - Assertions& assertions() { return m_Assertions; } + Assertions& assertions() { return m_Assertions; } /// search directory const SearchDirs& directories() const { return m_SearchDirs; } - SearchDirs& directories() { return m_SearchDirs; } + SearchDirs& directories() { return m_SearchDirs; } /// sysroot const sys::fs::Path& sysroot() const; - void setSysroot(const sys::fs::Path &pPath); + void setSysroot(const sys::fs::Path& pPath); bool hasSysroot() const; @@ -86,7 +88,7 @@ bool hasOutputFile() const; -private: + private: SymbolRenameMap m_SymbolRenames; AddressMap m_AddressMap; SectionMap m_SectionMap; @@ -97,7 +99,6 @@ std::string m_OutputFile; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_LINKERSCRIPT_H_
diff --git a/include/mcld/MC/Attribute.h b/include/mcld/MC/Attribute.h index 227ae29..37db1e8 100644 --- a/include/mcld/MC/Attribute.h +++ b/include/mcld/MC/Attribute.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_MC_ATTRIBUTE_H -#define MCLD_MC_ATTRIBUTE_H +#ifndef MCLD_MC_ATTRIBUTE_H_ +#define MCLD_MC_ATTRIBUTE_H_ namespace mcld { @@ -28,48 +28,39 @@ * which have identical attributes share common attribute. AttributeBase is * the shared storage for attribute. */ -class AttributeBase -{ -public: +class AttributeBase { + public: AttributeBase() - : m_WholeArchive(false), - m_AsNeeded(false), - m_AddNeeded(true), - m_Static(false) - { } + : m_WholeArchive(false), + m_AsNeeded(false), + m_AddNeeded(true), + m_Static(false) {} AttributeBase(const AttributeBase& pBase) - : m_WholeArchive(pBase.m_WholeArchive), - m_AsNeeded(pBase.m_AsNeeded), - m_AddNeeded(pBase.m_AddNeeded), - m_Static(pBase.m_Static) - { } + : m_WholeArchive(pBase.m_WholeArchive), + m_AsNeeded(pBase.m_AsNeeded), + m_AddNeeded(pBase.m_AddNeeded), + m_Static(pBase.m_Static) {} - virtual ~AttributeBase() - { } + virtual ~AttributeBase() {} // ----- observers ----- // // represent GNU ld --whole-archive/--no-whole-archive options - bool isWholeArchive() const - { return m_WholeArchive; } + bool isWholeArchive() const { return m_WholeArchive; } // represent GNU ld --as-needed/--no-as-needed options - bool isAsNeeded() const - { return m_AsNeeded; } + bool isAsNeeded() const { return m_AsNeeded; } // represent GNU ld --add-needed/--no-add-needed options - bool isAddNeeded() const - { return m_AddNeeded; } + bool isAddNeeded() const { return m_AddNeeded; } // represent GNU ld -static option - bool isStatic() const - { return m_Static; } + bool isStatic() const { return m_Static; } // represent GNU ld -call_shared option - bool isDynamic() const - { return !m_Static; } + bool isDynamic() const { return !m_Static; } -public: + public: bool m_WholeArchive : 1; bool m_AsNeeded : 1; bool m_AddNeeded : 1; @@ -83,33 +74,24 @@ * For conventience and producing less bugs, we move the stoarges of attributes * onto AttributeBase, and modifiers remains with the class Attribute. */ -class Attribute : public AttributeBase -{ -public: +class Attribute : public AttributeBase { + public: // ----- modifiers ----- // - void setWholeArchive() - { m_WholeArchive = true; } + void setWholeArchive() { m_WholeArchive = true; } - void unsetWholeArchive() - { m_WholeArchive = false; } + void unsetWholeArchive() { m_WholeArchive = false; } - void setAsNeeded() - { m_AsNeeded = true; } + void setAsNeeded() { m_AsNeeded = true; } - void unsetAsNeeded() - { m_AsNeeded = false; } + void unsetAsNeeded() { m_AsNeeded = false; } - void setAddNeeded() - { m_AddNeeded = true; } + void setAddNeeded() { m_AddNeeded = true; } - void unsetAddNeeded() - { m_AddNeeded = false; } + void unsetAddNeeded() { m_AddNeeded = false; } - void setStatic() - { m_Static = true; } + void setStatic() { m_Static = true; } - void setDynamic() - { m_Static = false; } + void setDynamic() { m_Static = false; } }; /** \class AttrConstraint @@ -124,38 +106,27 @@ * * @see SectLinker */ -class AttrConstraint : public AttributeBase -{ -public: - void enableWholeArchive() - { m_WholeArchive = true; } +class AttrConstraint : public AttributeBase { + public: + void enableWholeArchive() { m_WholeArchive = true; } - void disableWholeArchive() - { m_WholeArchive = false; } + void disableWholeArchive() { m_WholeArchive = false; } - void enableAsNeeded() - { m_AsNeeded = true; } + void enableAsNeeded() { m_AsNeeded = true; } - void disableAsNeeded() - { m_AsNeeded = false; } + void disableAsNeeded() { m_AsNeeded = false; } - void enableAddNeeded() - { m_AddNeeded = true; } + void enableAddNeeded() { m_AddNeeded = true; } - void disableAddNeeded() - { m_AddNeeded = false; } + void disableAddNeeded() { m_AddNeeded = false; } - void setSharedSystem() - { m_Static = false; } + void setSharedSystem() { m_Static = false; } - void setStaticSystem() - { m_Static = true; } + void setStaticSystem() { m_Static = true; } - bool isSharedSystem() const - { return !m_Static; } + bool isSharedSystem() const { return !m_Static; } - bool isStaticSystem() const - { return m_Static; } + bool isStaticSystem() const { return m_Static; } bool isLegal(const Attribute& pAttr) const; }; @@ -175,9 +146,8 @@ * the attribute of the input file. If the searching fails, AttributeProxy * requests a new attribute from the AttributeSet. */ -class AttributeProxy -{ -public: +class AttributeProxy { + public: AttributeProxy(AttributeSet& pParent, const Attribute& pBase, const AttrConstraint& pConstraint); @@ -195,8 +165,7 @@ bool isDynamic() const; - const Attribute* attr() const - { return m_pBase; } + const Attribute* attr() const { return m_pBase; } // ----- modifiers ----- // void setWholeArchive(); @@ -210,28 +179,24 @@ AttributeProxy& assign(Attribute* pBase); -private: - AttributeSet &m_AttrPool; - const Attribute *m_pBase; + private: + AttributeSet& m_AttrPool; + const Attribute* m_pBase; const AttrConstraint& m_Constraint; }; - // ----- comparisons ----- // -inline bool operator== (const Attribute& pLHS, const Attribute& pRHS) -{ +inline bool operator==(const Attribute& pLHS, const Attribute& pRHS) { return ((pLHS.isWholeArchive() == pRHS.isWholeArchive()) && - (pLHS.isAsNeeded() == pRHS.isAsNeeded()) && - (pLHS.isAddNeeded() == pRHS.isAddNeeded()) && - (pLHS.isStatic() == pRHS.isStatic())); + (pLHS.isAsNeeded() == pRHS.isAsNeeded()) && + (pLHS.isAddNeeded() == pRHS.isAddNeeded()) && + (pLHS.isStatic() == pRHS.isStatic())); } -inline bool operator!= (const Attribute& pLHS, const Attribute& pRHS) -{ +inline bool operator!=(const Attribute& pLHS, const Attribute& pRHS) { return !(pLHS == pRHS); } -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_MC_ATTRIBUTE_H_
diff --git a/include/mcld/MC/AttributeSet.h b/include/mcld/MC/AttributeSet.h index 6dc8801..e415c30 100644 --- a/include/mcld/MC/AttributeSet.h +++ b/include/mcld/MC/AttributeSet.h
@@ -6,9 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_MC_ATTRIBUTESET_H -#define MCLD_MC_ATTRIBUTESET_H -#include <mcld/ADT/Uncopyable.h> +#ifndef MCLD_MC_ATTRIBUTESET_H_ +#define MCLD_MC_ATTRIBUTESET_H_ +#include "mcld/Support/Compiler.h" + #include <vector> namespace mcld { @@ -21,39 +22,40 @@ * Clients delegates Attributes to AttributeSet. AttributeSet deletes delegated * Attributes during destruction. */ -class AttributeSet : private Uncopyable -{ -private: +class AttributeSet { + private: typedef std::vector<Attribute*> AttrSet; -public: + public: typedef AttrSet::iterator iterator; typedef AttrSet::const_iterator const_iterator; -public: + public: AttributeSet(unsigned int pNum, const Attribute& pPredefined); ~AttributeSet(); // ----- iterators ----- // const_iterator begin() const { return m_AttrSet.begin(); } - iterator begin() { return m_AttrSet.begin(); } - const_iterator end () const { return m_AttrSet.end(); } - iterator end () { return m_AttrSet.end(); } + iterator begin() { return m_AttrSet.begin(); } + const_iterator end() const { return m_AttrSet.end(); } + iterator end() { return m_AttrSet.end(); } // exists- return the recorded attribute whose content is identical to the // input attribute. - Attribute *exists(const Attribute& pAttr) const; + Attribute* exists(const Attribute& pAttr) const; // record - record the attribute no mater if it has been recorded. void record(Attribute& pAttr); -private: + private: AttrSet m_AttrSet; const Attribute& m_Predefined; + + private: + DISALLOW_COPY_AND_ASSIGN(AttributeSet); }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_MC_ATTRIBUTESET_H_
diff --git a/include/mcld/MC/CommandAction.h b/include/mcld/MC/CommandAction.h index ab4e35a..85f3e2b 100644 --- a/include/mcld/MC/CommandAction.h +++ b/include/mcld/MC/CommandAction.h
@@ -6,13 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_MC_COMMANDACTION_H -#define MCLD_MC_COMMANDACTION_H +#ifndef MCLD_MC_COMMANDACTION_H_ +#define MCLD_MC_COMMANDACTION_H_ + +#include "mcld/MC/InputAction.h" +#include "mcld/Script/ScriptFile.h" +#include "mcld/Support/Path.h" #include <string> -#include <mcld/Support/Path.h> -#include <mcld/MC/InputAction.h> -#include <mcld/Script/ScriptFile.h> namespace mcld { @@ -24,158 +25,145 @@ // Derived InputAction //===----------------------------------------------------------------------===// /// InputFileAction -class InputFileAction : public InputAction -{ -public: - explicit InputFileAction(unsigned int pPosition, const sys::fs::Path &pPath); +class InputFileAction : public InputAction { + public: + InputFileAction(unsigned int pPosition, const sys::fs::Path& pPath); + + InputFileAction(unsigned int pPosition, const char* pPath); const sys::fs::Path& path() const { return m_Path; } bool activate(InputBuilder&) const; -private: + private: sys::fs::Path m_Path; }; /// NamespecAction -class NamespecAction : public InputAction -{ -public: +class NamespecAction : public InputAction { + public: NamespecAction(unsigned int pPosition, - const std::string &pNamespec, + const std::string& pNamespec, const SearchDirs& pSearchDirs); - const std::string &namespec() const { return m_Namespec; } + const std::string& namespec() const { return m_Namespec; } bool activate(InputBuilder&) const; -private: + private: std::string m_Namespec; const SearchDirs& m_SearchDirs; }; /// BitcodeAction -class BitcodeAction : public InputAction -{ -public: - BitcodeAction(unsigned int pPosition, const sys::fs::Path &pPath); +class BitcodeAction : public InputAction { + public: + BitcodeAction(unsigned int pPosition, const sys::fs::Path& pPath); const sys::fs::Path& path() const { return m_Path; } bool activate(InputBuilder&) const; -private: + private: sys::fs::Path m_Path; }; /// StartGroupAction -class StartGroupAction : public InputAction -{ -public: +class StartGroupAction : public InputAction { + public: explicit StartGroupAction(unsigned int pPosition); bool activate(InputBuilder&) const; }; /// EndGroupAction -class EndGroupAction : public InputAction -{ -public: +class EndGroupAction : public InputAction { + public: explicit EndGroupAction(unsigned int pPosition); bool activate(InputBuilder&) const; }; /// WholeArchiveAction -class WholeArchiveAction : public InputAction -{ -public: +class WholeArchiveAction : public InputAction { + public: explicit WholeArchiveAction(unsigned int pPosition); bool activate(InputBuilder&) const; }; /// NoWholeArchiveAction -class NoWholeArchiveAction : public InputAction -{ -public: +class NoWholeArchiveAction : public InputAction { + public: explicit NoWholeArchiveAction(unsigned int pPosition); bool activate(InputBuilder&) const; }; /// AsNeededAction -class AsNeededAction : public InputAction -{ -public: +class AsNeededAction : public InputAction { + public: explicit AsNeededAction(unsigned int pPosition); bool activate(InputBuilder&) const; }; /// NoAsNeededAction -class NoAsNeededAction : public InputAction -{ -public: +class NoAsNeededAction : public InputAction { + public: explicit NoAsNeededAction(unsigned int pPosition); bool activate(InputBuilder&) const; }; /// AddNeededAction -class AddNeededAction : public InputAction -{ -public: +class AddNeededAction : public InputAction { + public: explicit AddNeededAction(unsigned int pPosition); bool activate(InputBuilder&) const; }; /// NoAddNeededAction -class NoAddNeededAction : public InputAction -{ -public: +class NoAddNeededAction : public InputAction { + public: explicit NoAddNeededAction(unsigned int pPosition); bool activate(InputBuilder&) const; }; /// BDynamicAction -class BDynamicAction : public InputAction -{ -public: +class BDynamicAction : public InputAction { + public: explicit BDynamicAction(unsigned int pPosition); bool activate(InputBuilder&) const; }; /// BStaticAction -class BStaticAction : public InputAction -{ -public: +class BStaticAction : public InputAction { + public: explicit BStaticAction(unsigned int pPosition); bool activate(InputBuilder&) const; }; /// DefSymAction -class DefSymAction : public InputAction -{ -public: +class DefSymAction : public InputAction { + public: explicit DefSymAction(unsigned int pPosition, std::string& pAssignment); bool activate(InputBuilder&) const; const std::string& assignment() const { return m_Assignment; } -private: + private: std::string& m_Assignment; }; /// ScriptAction -class ScriptAction : public InputAction -{ -public: +class ScriptAction : public InputAction { + public: ScriptAction(unsigned int pPosition, const std::string& pFileName, ScriptFile::Kind pKind, @@ -187,13 +175,12 @@ ScriptFile::Kind kind() const { return m_Kind; } -private: + private: std::string m_FileName; ScriptFile::Kind m_Kind; const SearchDirs& m_SearchDirs; }; -} // end of namespace mcld +} // namespace mcld -#endif - +#endif // MCLD_MC_COMMANDACTION_H_
diff --git a/include/mcld/MC/ContextFactory.h b/include/mcld/MC/ContextFactory.h index 34512f6..6067476 100644 --- a/include/mcld/MC/ContextFactory.h +++ b/include/mcld/MC/ContextFactory.h
@@ -6,15 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_MC_CONTEXTFACTORY_H -#define MCLD_MC_CONTEXTFACTORY_H +#ifndef MCLD_MC_CONTEXTFACTORY_H_ +#define MCLD_MC_CONTEXTFACTORY_H_ -#include <mcld/LD/LDContext.h> -#include <mcld/Support/UniqueGCFactory.h> -#include <mcld/Support/Path.h> +#include "mcld/LD/LDContext.h" +#include "mcld/Support/UniqueGCFactory.h" +#include "mcld/Support/Path.h" -namespace mcld -{ +namespace mcld { /** \class ContextFactory * \brief ContextFactory avoids the duplicated LDContext of the same file. * @@ -29,17 +28,16 @@ * @see LDContext * @see UniqueGCFactoryBase */ -class ContextFactory : public UniqueGCFactoryBase<sys::fs::Path, LDContext, 0> -{ -public: +class ContextFactory : public UniqueGCFactoryBase<sys::fs::Path, LDContext, 0> { + public: explicit ContextFactory(size_t pNum); ~ContextFactory(); LDContext* produce(); LDContext* produce(const sys::fs::Path& pPath); + LDContext* produce(const char* pPath); }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_MC_CONTEXTFACTORY_H_
diff --git a/include/mcld/MC/FileAction.h b/include/mcld/MC/FileAction.h index 7671c0a..ab135d7 100644 --- a/include/mcld/MC/FileAction.h +++ b/include/mcld/MC/FileAction.h
@@ -6,10 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_MC_FILEACTION_H -#define MCLD_MC_FILEACTION_H -#include <mcld/MC/InputAction.h> -#include <mcld/Support/FileHandle.h> +#ifndef MCLD_MC_FILEACTION_H_ +#define MCLD_MC_FILEACTION_H_ +#include "mcld/MC/InputAction.h" +#include "mcld/Support/FileHandle.h" namespace mcld { @@ -18,9 +18,8 @@ /** \class ContextAction * \brief ContextAction is a command object to create input's LDContext. */ -class ContextAction : public InputAction -{ -public: +class ContextAction : public InputAction { + public: explicit ContextAction(unsigned int pPosition); bool activate(InputBuilder& pBuilder) const; @@ -29,21 +28,19 @@ /** \class MemoryAreaAction * \brief MemoryAreaAction is a command object to create input's MemoryArea. */ -class MemoryAreaAction : public InputAction -{ -public: +class MemoryAreaAction : public InputAction { + public: MemoryAreaAction(unsigned int pPosition, - FileHandle::OpenMode pMode, - FileHandle::Permission pPerm = FileHandle::System); + FileHandle::OpenModeEnum pMode, + FileHandle::PermissionEnum pPerm = FileHandle::System); bool activate(InputBuilder& pBuilder) const; -private: + private: FileHandle::OpenMode m_Mode; FileHandle::Permission m_Permission; }; -} // end of namespace mcld +} // namespace mcld -#endif - +#endif // MCLD_MC_FILEACTION_H_
diff --git a/include/mcld/MC/Input.h b/include/mcld/MC/Input.h index da3a647..dfd7df3 100644 --- a/include/mcld/MC/Input.h +++ b/include/mcld/MC/Input.h
@@ -10,26 +10,26 @@ // Input class inherits MCLDFile, which is used to represent a input file // //===----------------------------------------------------------------------===// -#ifndef MCLD_MC_INPUT_H -#define MCLD_MC_INPUT_H +#ifndef MCLD_MC_INPUT_H_ +#define MCLD_MC_INPUT_H_ -#include <mcld/Support/Path.h> +#include "mcld/Support/Path.h" namespace mcld { -class MemoryArea; class AttributeProxy; class Attribute; class InputFactory; class LDContext; +class MemoryArea; /** \class Input * \brief Input provides the information of a input file. */ -class Input -{ -friend class InputFactory; -public: +class Input { + friend class InputFactory; + + public: enum Type { Unknown, Binary, @@ -42,11 +42,10 @@ External }; -public: + public: explicit Input(llvm::StringRef pName); - Input(llvm::StringRef pName, - const AttributeProxy& pAttr); + Input(llvm::StringRef pName, const AttributeProxy& pAttr); Input(llvm::StringRef pName, const sys::fs::Path& pPath, @@ -61,76 +60,57 @@ ~Input(); - const std::string& name() const - { return m_Name; } + const std::string& name() const { return m_Name; } - void setName(const std::string& pName) - { m_Name = pName; } + void setName(const std::string& pName) { m_Name = pName; } - const sys::fs::Path& path() const - { return m_Path; } + const sys::fs::Path& path() const { return m_Path; } - void setPath(const sys::fs::Path& pPath) - { m_Path = pPath; } + void setPath(const sys::fs::Path& pPath) { m_Path = pPath; } - void setType(unsigned int pType) - { m_Type = pType; } + void setType(unsigned int pType) { m_Type = pType; } - unsigned int type() const - { return m_Type; } + unsigned int type() const { return m_Type; } - bool isRecognized() const - { return (m_Type != Unknown); } + bool isRecognized() const { return (m_Type != Unknown); } - bool hasAttribute() const - { return (NULL != m_pAttr); } + bool hasAttribute() const { return (m_pAttr != NULL); } - const Attribute* attribute() const - { return m_pAttr; } + const Attribute* attribute() const { return m_pAttr; } - bool isNeeded() const - { return m_bNeeded; } + bool isNeeded() const { return m_bNeeded; } - void setNeeded() - { m_bNeeded = true; } + void setNeeded() { m_bNeeded = true; } - bool noExport() const - { return m_bNoExport; } + bool noExport() const { return m_bNoExport; } - void setNoExport() - { m_bNoExport = true; } + void setNoExport() { m_bNoExport = true; } - off_t fileOffset() const - { return m_fileOffset; } + off_t fileOffset() const { return m_fileOffset; } - void setFileOffset(off_t pFileOffset) - { m_fileOffset = pFileOffset; } + void setFileOffset(off_t pFileOffset) { m_fileOffset = pFileOffset; } // ----- memory area ----- // - void setMemArea(MemoryArea* pMemArea) - { m_pMemArea = pMemArea; } + void setMemArea(MemoryArea* pMemArea) { m_pMemArea = pMemArea; } - bool hasMemArea() const - { return (NULL != m_pMemArea); } + bool hasMemArea() const { return (m_pMemArea != NULL); } const MemoryArea* memArea() const { return m_pMemArea; } - MemoryArea* memArea() { return m_pMemArea; } + MemoryArea* memArea() { return m_pMemArea; } // ----- context ----- // - void setContext(LDContext* pContext) - { m_pContext = pContext; } + void setContext(LDContext* pContext) { m_pContext = pContext; } - bool hasContext() const - { return (NULL != m_pContext); } + bool hasContext() const { return (m_pContext != NULL); } const LDContext* context() const { return m_pContext; } - LDContext* context() { return m_pContext; } + LDContext* context() { return m_pContext; } -private: + private: unsigned int m_Type; std::string m_Name; sys::fs::Path m_Path; - Attribute *m_pAttr; + Attribute* m_pAttr; bool m_bNeeded; bool m_bNoExport; off_t m_fileOffset; @@ -138,7 +118,6 @@ LDContext* m_pContext; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_MC_INPUT_H_
diff --git a/include/mcld/MC/InputAction.h b/include/mcld/MC/InputAction.h index 46b43f0..d03829c 100644 --- a/include/mcld/MC/InputAction.h +++ b/include/mcld/MC/InputAction.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_MC_INPUTACTION_H -#define MCLD_MC_INPUTACTION_H +#ifndef MCLD_MC_INPUTACTION_H_ +#define MCLD_MC_INPUTACTION_H_ namespace mcld { @@ -20,31 +20,30 @@ /** \class InputAction * \brief InputAction is a command object to construct mcld::InputTree. */ -class InputAction -{ -protected: +class InputAction { + protected: explicit InputAction(unsigned int pPosition); -public: + public: virtual ~InputAction(); virtual bool activate(InputBuilder&) const = 0; unsigned int position() const { return m_Position; } - bool operator<(const InputAction& pOther) const - { return (position() < pOther.position()); } + bool operator<(const InputAction& pOther) const { + return (position() < pOther.position()); + } -private: + private: InputAction(); // DO_NOT_IMPLEMENT - InputAction(const InputAction& ); // DO_NOT_IMPLEMENT - InputAction& operator=(const InputAction& ); // DO_NOT_IMPLEMENT + InputAction(const InputAction&); // DO_NOT_IMPLEMENT + InputAction& operator=(const InputAction&); // DO_NOT_IMPLEMENT -private: + private: unsigned int m_Position; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_MC_INPUTACTION_H_
diff --git a/include/mcld/MC/InputBuilder.h b/include/mcld/MC/InputBuilder.h index 9918c0d..ba43baa 100644 --- a/include/mcld/MC/InputBuilder.h +++ b/include/mcld/MC/InputBuilder.h
@@ -6,32 +6,31 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_MC_INPUTBUILDER_H -#define MCLD_MC_INPUTBUILDER_H +#ifndef MCLD_MC_INPUTBUILDER_H_ +#define MCLD_MC_INPUTBUILDER_H_ -#include <string> +#include "mcld/InputTree.h" +#include "mcld/MC/Input.h" +#include "mcld/Support/FileHandle.h" + #include <stack> - -#include <mcld/InputTree.h> -#include <mcld/MC/Input.h> -#include <mcld/Support/FileHandle.h> +#include <string> namespace mcld { -class LinkerConfig; -class InputFactory; -class ContextFactory; -class MemoryAreaFactory; class AttrConstraint; +class ContextFactory; +class InputFactory; +class LinkerConfig; +class MemoryAreaFactory; /** \class InputBuilder * \brief InputBuilder recieves InputActions and build the InputTree. * * InputBuilder build input tree and inputs. */ -class InputBuilder -{ -public: +class InputBuilder { + public: explicit InputBuilder(const LinkerConfig& pConfig); InputBuilder(const LinkerConfig& pConfig, @@ -44,15 +43,15 @@ // ----- input tree operations ----- // const InputTree& getCurrentTree() const; - InputTree& getCurrentTree(); + InputTree& getCurrentTree(); void setCurrentTree(InputTree& pInputTree); // ----- root of input tree ----- // const InputTree::iterator& getCurrentNode() const { return m_Root; } - InputTree::iterator& getCurrentNode() { return m_Root; } + InputTree::iterator& getCurrentNode() { return m_Root; } - template<InputTree::Direction DIRECTION> + template <InputTree::Direction DIRECTION> InputTree& createNode(const std::string& pName, const sys::fs::Path& pPath, unsigned int pType = Input::Unknown); @@ -67,7 +66,7 @@ bool setMemory(Input& pInput, FileHandle::OpenMode pMode, - FileHandle::Permission pPerm = FileHandle::System); + FileHandle::Permission pPerm); bool setMemory(Input& pInput, void* pMemBuffer, size_t pSize); @@ -80,9 +79,9 @@ const AttrConstraint& getConstraint() const; const AttributeProxy& getAttributes() const; - AttributeProxy& getAttributes(); + AttributeProxy& getAttributes(); -private: + private: const LinkerConfig& m_Config; InputFactory* m_pInputFactory; @@ -95,18 +94,17 @@ std::stack<InputTree::iterator> m_ReturnStack; bool m_bOwnFactory; - }; //===----------------------------------------------------------------------===// // Template implement //===----------------------------------------------------------------------===// -template<> inline InputTree& -InputBuilder::createNode<InputTree::Inclusive>(const std::string& pName, - const sys::fs::Path& pPath, - unsigned int pType) -{ - assert(NULL != m_pCurrentTree && NULL != m_pMove); +template <> +inline InputTree& InputBuilder::createNode<InputTree::Inclusive>( + const std::string& pName, + const sys::fs::Path& pPath, + unsigned int pType) { + assert(m_pCurrentTree != NULL && m_pMove != NULL); Input* input = createInput(pName, pPath, pType); m_pCurrentTree->insert(m_Root, *m_pMove, *input); @@ -116,12 +114,12 @@ return *m_pCurrentTree; } -template<> inline InputTree& -InputBuilder::createNode<InputTree::Positional>(const std::string& pName, - const sys::fs::Path& pPath, - unsigned int pType) -{ - assert(NULL != m_pCurrentTree && NULL != m_pMove); +template <> +inline InputTree& InputBuilder::createNode<InputTree::Positional>( + const std::string& pName, + const sys::fs::Path& pPath, + unsigned int pType) { + assert(m_pCurrentTree != NULL && m_pMove != NULL); Input* input = createInput(pName, pPath, pType); m_pCurrentTree->insert(m_Root, *m_pMove, *input); @@ -131,7 +129,6 @@ return *m_pCurrentTree; } -} // end of namespace mcld +} // namespace mcld -#endif - +#endif // MCLD_MC_INPUTBUILDER_H_
diff --git a/include/mcld/MC/InputFactory.h b/include/mcld/MC/InputFactory.h index 6dbeee5..de42b9e 100644 --- a/include/mcld/MC/InputFactory.h +++ b/include/mcld/MC/InputFactory.h
@@ -6,16 +6,16 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_MC_INPUTFACTORY_H -#define MCLD_MC_INPUTFACTORY_H -#include <mcld/Support/GCFactory.h> -#include <mcld/MC/Input.h> +#ifndef MCLD_MC_INPUTFACTORY_H_ +#define MCLD_MC_INPUTFACTORY_H_ +#include "mcld/MC/Input.h" +#include "mcld/Support/GCFactory.h" namespace mcld { -class LinkerConfig; class AttributeProxy; class AttributeSet; +class LinkerConfig; /** \class InputFactory * \brief InputFactory controls the production and destruction of @@ -26,12 +26,11 @@ * * \see llvm::sys::Path */ -class InputFactory : public GCFactory<Input,0> -{ -public: +class InputFactory : public GCFactory<Input, 0> { + public: typedef GCFactory<Input, 0> Alloc; -public: + public: InputFactory(size_t pNum, const LinkerConfig& pConfig); ~InputFactory(); @@ -42,17 +41,21 @@ unsigned int pType = Input::Unknown, off_t pFileOffset = 0); + Input* produce(llvm::StringRef pName, + const char* pPath, + unsigned int pType = Input::Unknown, + off_t pFileOffset = 0); + // ----- attributes ----- // /// attr - the last touched attribute. const AttributeProxy& attr() const { return *m_pLast; } - AttributeProxy& attr() { return *m_pLast; } + AttributeProxy& attr() { return *m_pLast; } -private: + private: AttributeProxy* m_pLast; AttributeSet* m_pAttrSet; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_MC_INPUTFACTORY_H_
diff --git a/include/mcld/MC/MCLDDirectory.h b/include/mcld/MC/MCLDDirectory.h index de2abb5..674ffae 100644 --- a/include/mcld/MC/MCLDDirectory.h +++ b/include/mcld/MC/MCLDDirectory.h
@@ -6,45 +6,43 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_MC_MCLDDIRECTORY_H -#define MCLD_MC_MCLDDIRECTORY_H +#ifndef MCLD_MC_MCLDDIRECTORY_H_ +#define MCLD_MC_MCLDDIRECTORY_H_ #include "mcld/Support/Directory.h" #include "mcld/Support/FileSystem.h" + #include <llvm/ADT/StringRef.h> + #include <string> -namespace mcld -{ +namespace mcld { /** \class MCLDDirectory * \brief MCLDDirectory is an directory entry for library search. * */ -class MCLDDirectory : public sys::fs::Directory -{ -public: +class MCLDDirectory : public sys::fs::Directory { + public: MCLDDirectory(); - MCLDDirectory(const char* pName); - MCLDDirectory(const std::string& pName); - MCLDDirectory(llvm::StringRef pName); + explicit MCLDDirectory(const char* pName); + explicit MCLDDirectory(const std::string& pName); + explicit MCLDDirectory(llvm::StringRef pName); virtual ~MCLDDirectory(); -public: - MCLDDirectory &assign(llvm::StringRef pName); + public: + MCLDDirectory& assign(llvm::StringRef pName); bool isInSysroot() const; /// setSysroot - if MCLDDirectory is in sysroot, modify the path. void setSysroot(const sys::fs::Path& pPath); - const std::string& name() const - { return m_Name; } + const std::string& name() const { return m_Name; } -private: + private: std::string m_Name; bool m_bInSysroot; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_MC_MCLDDIRECTORY_H_
diff --git a/include/mcld/MC/SearchDirs.h b/include/mcld/MC/SearchDirs.h index d09450d..e219d32 100644 --- a/include/mcld/MC/SearchDirs.h +++ b/include/mcld/MC/SearchDirs.h
@@ -6,21 +6,22 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_MC_SEARCHDIRS_H -#define MCLD_MC_SEARCHDIRS_H -#include <mcld/ADT/Uncopyable.h> -#include <mcld/MC/Input.h> -#include <mcld/Support/Path.h> +#ifndef MCLD_MC_SEARCHDIRS_H_ +#define MCLD_MC_SEARCHDIRS_H_ + +#include "mcld/MC/Input.h" +#include "mcld/Support/Path.h" +#include "mcld/Support/Compiler.h" #include <llvm/ADT/StringRef.h> -#include <vector> #include <string> +#include <vector> namespace mcld { -class MCLDFile; class MCLDDirectory; +class MCLDFile; /** \class SearchDirs * \brief SearchDirs contains the list of paths that MCLinker will search for @@ -31,35 +32,34 @@ * * @see MCLDDirectory. */ -class SearchDirs : private Uncopyable -{ -public: +class SearchDirs { + public: typedef std::vector<MCLDDirectory*> DirList; typedef DirList::iterator iterator; typedef DirList::const_iterator const_iterator; -public: + public: SearchDirs(); - SearchDirs(const sys::fs::Path& pSysRoot); + explicit SearchDirs(const sys::fs::Path& pSysRoot); ~SearchDirs(); // find - give a namespec, return a real path of the shared object. - sys::fs::Path* - find(const std::string& pNamespec, mcld::Input::Type pPreferType); + sys::fs::Path* find(const std::string& pNamespec, + mcld::Input::Type pPreferType); - const sys::fs::Path* - find(const std::string& pNamespec, mcld::Input::Type pPreferType) const; + const sys::fs::Path* find(const std::string& pNamespec, + mcld::Input::Type pPreferType) const; void setSysRoot(const sys::fs::Path& pSysRoot) { m_SysRoot = pSysRoot; } const sys::fs::Path& sysroot() const { return m_SysRoot; } // ----- iterators ----- // const_iterator begin() const { return m_DirList.begin(); } - iterator begin() { return m_DirList.begin(); } - const_iterator end () const { return m_DirList.end(); } - iterator end () { return m_DirList.end(); } + iterator begin() { return m_DirList.begin(); } + const_iterator end() const { return m_DirList.end(); } + iterator end() { return m_DirList.end(); } // ----- modifiers ----- // bool insert(const char* pDirectory); @@ -68,12 +68,14 @@ bool insert(const sys::fs::Path& pDirectory); -private: + private: DirList m_DirList; sys::fs::Path m_SysRoot; + + private: + DISALLOW_COPY_AND_ASSIGN(SearchDirs); }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_MC_SEARCHDIRS_H_
diff --git a/include/mcld/MC/SymbolCategory.h b/include/mcld/MC/SymbolCategory.h index 1ceb471..4a04ec5 100644 --- a/include/mcld/MC/SymbolCategory.h +++ b/include/mcld/MC/SymbolCategory.h
@@ -6,29 +6,27 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_MC_SYMBOLCATEGORY_H -#define MCLD_MC_SYMBOLCATEGORY_H +#ifndef MCLD_MC_SYMBOLCATEGORY_H_ +#define MCLD_MC_SYMBOLCATEGORY_H_ #include <cstddef> #include <vector> -namespace mcld -{ +namespace mcld { class LDSymbol; class ResolveInfo; /** \class SymbolCategory * \brief SymbolCategory groups output LDSymbol into different categories. */ -class SymbolCategory -{ -private: +class SymbolCategory { + private: typedef std::vector<LDSymbol*> OutputSymbols; -public: + public: typedef OutputSymbols::iterator iterator; typedef OutputSymbols::const_iterator const_iterator; -public: + public: SymbolCategory(); ~SymbolCategory(); @@ -45,17 +43,17 @@ SymbolCategory& changeToDynamic(LDSymbol& pSymbol); // ----- access ----- // - LDSymbol& at(size_t pPosition) - { return *m_OutputSymbols.at(pPosition); } + LDSymbol& at(size_t pPosition) { return *m_OutputSymbols.at(pPosition); } - const LDSymbol& at(size_t pPosition) const - { return *m_OutputSymbols.at(pPosition); } + const LDSymbol& at(size_t pPosition) const { + return *m_OutputSymbols.at(pPosition); + } - LDSymbol& operator[](size_t pPosition) - { return *m_OutputSymbols[pPosition]; } + LDSymbol& operator[](size_t pPosition) { return *m_OutputSymbols[pPosition]; } - const LDSymbol& operator[](size_t pPosition) const - { return *m_OutputSymbols[pPosition]; } + const LDSymbol& operator[](size_t pPosition) const { + return *m_OutputSymbols[pPosition]; + } // ----- observers ----- // size_t numOfSymbols() const; @@ -122,20 +120,12 @@ const_iterator regularBegin() const; const_iterator regularEnd() const; -private: - class Category - { - public: - enum Type { - File, - Local, - LocalDyn, - Common, - Dynamic, - Regular - }; + private: + class Category { + public: + enum Type { File, Local, LocalDyn, Common, Dynamic, Regular }; - public: + public: Type type; size_t begin; @@ -144,38 +134,29 @@ Category* prev; Category* next; - public: - Category(Type pType) - : type(pType), - begin(0), - end(0), - prev(NULL), - next(NULL) { - } + public: + explicit Category(Type pType) + : type(pType), begin(0), end(0), prev(NULL), next(NULL) {} - size_t size() const - { return (end - begin); } + size_t size() const { return (end - begin); } - bool empty() const - { return (begin == end); } + bool empty() const { return (begin == end); } - bool isFirst() const - { return (NULL == prev); } + bool isFirst() const { return (prev == NULL); } - bool isLast() const - { return (NULL == next); } + bool isLast() const { return (next == NULL); } static Type categorize(const ResolveInfo& pInfo); }; -private: + private: SymbolCategory& add(LDSymbol& pSymbol, Category::Type pTarget); SymbolCategory& arrange(LDSymbol& pSymbol, Category::Type pSource, Category::Type pTarget); -private: + private: OutputSymbols m_OutputSymbols; Category* m_pFile; @@ -186,7 +167,6 @@ Category* m_pRegular; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_MC_SYMBOLCATEGORY_H_
diff --git a/include/mcld/MC/ZOption.h b/include/mcld/MC/ZOption.h index b2e4c68..6468614 100644 --- a/include/mcld/MC/ZOption.h +++ b/include/mcld/MC/ZOption.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_MC_ZOPTION_H -#define MCLD_MC_ZOPTION_H +#ifndef MCLD_MC_ZOPTION_H_ +#define MCLD_MC_ZOPTION_H_ #include <llvm/Support/DataTypes.h> @@ -16,9 +16,8 @@ /** \class ZOption * \brief The -z options for GNU ld compatibility. */ -class ZOption -{ -public: +class ZOption { + public: enum Kind { CombReloc, NoCombReloc, @@ -44,9 +43,13 @@ Unknown }; -public: + public: ZOption(); + explicit ZOption(Kind pKind); + + ZOption(Kind pKind, uint64_t pPageSize); + Kind kind() const { return m_Kind; } void setKind(Kind pKind) { m_Kind = pKind; } @@ -55,12 +58,11 @@ void setPageSize(uint64_t pPageSize) { m_PageSize = pPageSize; } -private: + private: Kind m_Kind; uint64_t m_PageSize; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_MC_ZOPTION_H_
diff --git a/include/mcld/Module.h b/include/mcld/Module.h index b18ff9b..fdeb442 100644 --- a/include/mcld/Module.h +++ b/include/mcld/Module.h
@@ -10,13 +10,13 @@ // Module contains the intermediate representation (LDIR) of MCLinker. // //===----------------------------------------------------------------------===// -#ifndef MCLD_MODULE_H -#define MCLD_MODULE_H +#ifndef MCLD_MODULE_H_ +#define MCLD_MODULE_H_ -#include <mcld/InputTree.h> -#include <mcld/LD/NamePool.h> -#include <mcld/LD/SectionSymbolSet.h> -#include <mcld/MC/SymbolCategory.h> +#include "mcld/InputTree.h" +#include "mcld/LD/NamePool.h" +#include "mcld/LD/SectionSymbolSet.h" +#include "mcld/MC/SymbolCategory.h" #include <vector> #include <string> @@ -31,9 +31,8 @@ /** \class Module * \brief Module provides the intermediate representation for linking. */ -class Module -{ -public: +class Module { + public: typedef std::vector<Input*> ObjectList; typedef ObjectList::iterator obj_iterator; typedef ObjectList::const_iterator const_obj_iterator; @@ -57,7 +56,7 @@ typedef AliasList::iterator alias_iterator; typedef AliasList::const_iterator const_alias_iterator; -public: + public: explicit Module(LinkerScript& pScript); Module(const std::string& pName, LinkerScript& pScript); @@ -70,86 +69,88 @@ const LinkerScript& getScript() const { return m_Script; } - LinkerScript& getScript() { return m_Script; } + LinkerScript& getScript() { return m_Script; } // ----- link-in objects ----- // const ObjectList& getObjectList() const { return m_ObjectList; } - ObjectList& getObjectList() { return m_ObjectList; } + ObjectList& getObjectList() { return m_ObjectList; } const_obj_iterator obj_begin() const { return m_ObjectList.begin(); } - obj_iterator obj_begin() { return m_ObjectList.begin(); } - const_obj_iterator obj_end () const { return m_ObjectList.end(); } - obj_iterator obj_end () { return m_ObjectList.end(); } + obj_iterator obj_begin() { return m_ObjectList.begin(); } + const_obj_iterator obj_end() const { return m_ObjectList.end(); } + obj_iterator obj_end() { return m_ObjectList.end(); } // ----- link-in libraries ----- // const LibraryList& getLibraryList() const { return m_LibraryList; } - LibraryList& getLibraryList() { return m_LibraryList; } + LibraryList& getLibraryList() { return m_LibraryList; } const_lib_iterator lib_begin() const { return m_LibraryList.begin(); } - lib_iterator lib_begin() { return m_LibraryList.begin(); } - const_lib_iterator lib_end () const { return m_LibraryList.end(); } - lib_iterator lib_end () { return m_LibraryList.end(); } + lib_iterator lib_begin() { return m_LibraryList.begin(); } + const_lib_iterator lib_end() const { return m_LibraryList.end(); } + lib_iterator lib_end() { return m_LibraryList.end(); } // ----- link-in inputs ----- // const InputTree& getInputTree() const { return m_MainTree; } - InputTree& getInputTree() { return m_MainTree; } + InputTree& getInputTree() { return m_MainTree; } const_input_iterator input_begin() const { return m_MainTree.begin(); } - input_iterator input_begin() { return m_MainTree.begin(); } - const_input_iterator input_end () const { return m_MainTree.end(); } - input_iterator input_end () { return m_MainTree.end(); } + input_iterator input_begin() { return m_MainTree.begin(); } + const_input_iterator input_end() const { return m_MainTree.end(); } + input_iterator input_end() { return m_MainTree.end(); } -/// @} -/// @name Section Accessors -/// @{ + /// @} + /// @name Section Accessors + /// @{ // ----- sections ----- // const SectionTable& getSectionTable() const { return m_SectionTable; } - SectionTable& getSectionTable() { return m_SectionTable; } + SectionTable& getSectionTable() { return m_SectionTable; } - iterator begin() { return m_SectionTable.begin(); } - const_iterator begin() const { return m_SectionTable.begin(); } - iterator end () { return m_SectionTable.end(); } - const_iterator end () const { return m_SectionTable.end(); } - LDSection* front() { return m_SectionTable.front(); } + iterator begin() { return m_SectionTable.begin(); } + const_iterator begin() const { return m_SectionTable.begin(); } + iterator end() { return m_SectionTable.end(); } + const_iterator end() const { return m_SectionTable.end(); } + LDSection* front() { return m_SectionTable.front(); } const LDSection* front() const { return m_SectionTable.front(); } - LDSection* back () { return m_SectionTable.back(); } - const LDSection* back () const { return m_SectionTable.back(); } - size_t size () const { return m_SectionTable.size(); } - bool empty() const { return m_SectionTable.empty(); } + LDSection* back() { return m_SectionTable.back(); } + const LDSection* back() const { return m_SectionTable.back(); } + size_t size() const { return m_SectionTable.size(); } + bool empty() const { return m_SectionTable.empty(); } - LDSection* getSection(const std::string& pName); + LDSection* getSection(const std::string& pName); const LDSection* getSection(const std::string& pName) const; -/// @} -/// @name Symbol Accessors -/// @{ + /// @} + /// @name Symbol Accessors + /// @{ // ----- symbols ----- // const SymbolTable& getSymbolTable() const { return m_SymbolTable; } - SymbolTable& getSymbolTable() { return m_SymbolTable; } + SymbolTable& getSymbolTable() { return m_SymbolTable; } - sym_iterator sym_begin() { return m_SymbolTable.begin(); } - const_sym_iterator sym_begin() const { return m_SymbolTable.begin(); } - sym_iterator sym_end () { return m_SymbolTable.end(); } - const_sym_iterator sym_end () const { return m_SymbolTable.end(); } - size_t sym_size () const { return m_SymbolTable.numOfSymbols(); } + sym_iterator sym_begin() { return m_SymbolTable.begin(); } + const_sym_iterator sym_begin() const { return m_SymbolTable.begin(); } + sym_iterator sym_end() { return m_SymbolTable.end(); } + const_sym_iterator sym_end() const { return m_SymbolTable.end(); } + size_t sym_size() const { return m_SymbolTable.numOfSymbols(); } // ----- section symbols ----- // - const LDSymbol* getSectionSymbol(const LDSection& pSection) const - { return m_SectSymbolSet.get(pSection); } + const LDSymbol* getSectionSymbol(const LDSection& pSection) const { + return m_SectSymbolSet.get(pSection); + } - LDSymbol* getSectionSymbol(const LDSection& pSection) - { return m_SectSymbolSet.get(pSection); } + LDSymbol* getSectionSymbol(const LDSection& pSection) { + return m_SectSymbolSet.get(pSection); + } - const SectionSymbolSet& getSectionSymbolSet() const - { return m_SectSymbolSet; } - SectionSymbolSet& getSectionSymbolSet() - { return m_SectSymbolSet; } + const SectionSymbolSet& getSectionSymbolSet() const { + return m_SectSymbolSet; + } + SectionSymbolSet& getSectionSymbolSet() { return m_SectSymbolSet; } // ----- names ----- // const NamePool& getNamePool() const { return m_NamePool; } - NamePool& getNamePool() { return m_NamePool; } + NamePool& getNamePool() { return m_NamePool; } // ----- Aliases ----- // // create an alias list for pSym, the aliases of pSym @@ -160,7 +161,7 @@ void addAlias(const ResolveInfo& pAlias); AliasList* getAliasList(const ResolveInfo& pSym); -private: + private: std::string m_Name; LinkerScript& m_Script; ObjectList m_ObjectList; @@ -173,7 +174,6 @@ std::vector<AliasList*> m_AliasLists; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_MODULE_H_
diff --git a/include/mcld/Object/ObjectBuilder.h b/include/mcld/Object/ObjectBuilder.h index 57b672e..a1d3319 100644 --- a/include/mcld/Object/ObjectBuilder.h +++ b/include/mcld/Object/ObjectBuilder.h
@@ -6,10 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_OBJECT_OBJECTBUILDER_H -#define MCLD_OBJECT_OBJECTBUILDER_H -#include <mcld/LD/LDFileFormat.h> -#include <mcld/LD/EhFrame.h> +#ifndef MCLD_OBJECT_OBJECTBUILDER_H_ +#define MCLD_OBJECT_OBJECTBUILDER_H_ +#include "mcld/LD/EhFrame.h" +#include "mcld/LD/LDFileFormat.h" #include <llvm/Support/DataTypes.h> @@ -17,31 +17,32 @@ namespace mcld { -class Module; -class LDSection; -class SectionData; class Fragment; class Input; +class LDSection; +class Module; +class SectionData; /** \class ObjectBuilder * \brief ObjectBuilder recieve ObjectAction and build the mcld::Module. */ -class ObjectBuilder -{ -public: - ObjectBuilder(Module& pTheModule); +class ObjectBuilder { + public: + explicit ObjectBuilder(Module& pTheModule); -/// @} -/// @name Section Methods -/// @{ + /// @} + /// @name Section Methods + /// @{ /// CreateSection - To create an output LDSection in mcld::Module. /// Link scripts and command line options define some SECTIONS commands that - /// specify where input sections are placed into output sections. This function + /// specify where input sections are placed into output sections. This + /// function /// checks SECTIONS commands to change given name to the output section name. /// This function creates a new LDSection and push the created LDSection into /// @ref mcld::Module. /// - /// To create an input LDSection in mcld::LDContext, use @ref LDSection::Create(). + /// To create an input LDSection in mcld::LDContext, use @ref + /// LDSection::Create(). /// /// @see SectionMap /// @@ -73,9 +74,9 @@ static void UpdateSectionAlign(LDSection& pSection, uint32_t pAlignConstraint); -/// @} -/// @name Fragment Methods -/// @{ + /// @} + /// @name Fragment Methods + /// @{ /// AppendFragment - To append pFrag to the given SectionData pSD. /// In order to keep the alignment of pFrag, This function inserts an /// AlignFragment before pFrag if pAlignConstraint is larger than 1. @@ -87,14 +88,14 @@ /// @param [in, out] pSD The section data being appended. /// @param [in] pAlignConstraint The alignment constraint. /// @return Total size of the inserted fragments. - static uint64_t AppendFragment(Fragment& pFrag, SectionData& pSD, + static uint64_t AppendFragment(Fragment& pFrag, + SectionData& pSD, uint32_t pAlignConstraint = 1); -private: + private: Module& m_Module; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_OBJECT_OBJECTBUILDER_H_
diff --git a/include/mcld/Object/ObjectLinker.h b/include/mcld/Object/ObjectLinker.h index 9d54d2e..e3bd0f8 100644 --- a/include/mcld/Object/ObjectLinker.h +++ b/include/mcld/Object/ObjectLinker.h
@@ -6,37 +6,35 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_OBJECT_OBJECTLINKER_H -#define MCLD_OBJECT_OBJECTLINKER_H +#ifndef MCLD_OBJECT_OBJECTLINKER_H_ +#define MCLD_OBJECT_OBJECTLINKER_H_ #include <llvm/Support/DataTypes.h> namespace mcld { -class Module; -class LinkerConfig; -class IRBuilder; -class TargetLDBackend; -class FileOutputBuffer; -class ObjectReader; -class DynObjReader; class ArchiveReader; -class GroupReader; class BinaryReader; -class ScriptReader; -class ObjectWriter; +class BinaryWriter; +class DynObjReader; class DynObjWriter; class ExecWriter; -class BinaryWriter; +class FileOutputBuffer; +class GroupReader; +class IRBuilder; +class LinkerConfig; +class Module; +class ObjectReader; +class ObjectWriter; class Relocation; class ResolveInfo; +class ScriptReader; +class TargetLDBackend; /** \class ObjectLinker */ -class ObjectLinker -{ -public: - ObjectLinker(const LinkerConfig& pConfig, - TargetLDBackend& pLDBackend); +class ObjectLinker { + public: + ObjectLinker(const LinkerConfig& pConfig, TargetLDBackend& pLDBackend); ~ObjectLinker(); @@ -126,28 +124,28 @@ bool postProcessing(FileOutputBuffer& pOutput); // ----- readers and writers ----- // - const ObjectReader* getObjectReader () const { return m_pObjectReader; } - ObjectReader* getObjectReader () { return m_pObjectReader; } + const ObjectReader* getObjectReader() const { return m_pObjectReader; } + ObjectReader* getObjectReader() { return m_pObjectReader; } - const DynObjReader* getDynObjReader () const { return m_pDynObjReader; } - DynObjReader* getDynObjReader () { return m_pDynObjReader; } + const DynObjReader* getDynObjReader() const { return m_pDynObjReader; } + DynObjReader* getDynObjReader() { return m_pDynObjReader; } const ArchiveReader* getArchiveReader() const { return m_pArchiveReader; } - ArchiveReader* getArchiveReader() { return m_pArchiveReader; } + ArchiveReader* getArchiveReader() { return m_pArchiveReader; } - const GroupReader* getGroupReader () const { return m_pGroupReader; } - GroupReader* getGroupReader () { return m_pGroupReader; } + const GroupReader* getGroupReader() const { return m_pGroupReader; } + GroupReader* getGroupReader() { return m_pGroupReader; } - const BinaryReader* getBinaryReader () const { return m_pBinaryReader; } - BinaryReader* getBinaryReader () { return m_pBinaryReader; } + const BinaryReader* getBinaryReader() const { return m_pBinaryReader; } + BinaryReader* getBinaryReader() { return m_pBinaryReader; } - const ScriptReader* getScriptReader () const { return m_pScriptReader; } - ScriptReader* getScriptReader () { return m_pScriptReader; } + const ScriptReader* getScriptReader() const { return m_pScriptReader; } + ScriptReader* getScriptReader() { return m_pScriptReader; } - const ObjectWriter* getWriter () const { return m_pWriter; } - ObjectWriter* getWriter () { return m_pWriter; } + const ObjectWriter* getWriter() const { return m_pWriter; } + ObjectWriter* getWriter() { return m_pWriter; } -private: + private: /// normalSyncRelocationResult - sync relocation result when producing shared /// objects or executables void normalSyncRelocationResult(FileOutputBuffer& pOutput); @@ -164,22 +162,23 @@ /// section symbol and not defined in the discarded section void addSymbolToOutput(ResolveInfo& pInfo, Module& pModule); -private: + private: const LinkerConfig& m_Config; Module* m_pModule; IRBuilder* m_pBuilder; - TargetLDBackend &m_LDBackend; + TargetLDBackend& m_LDBackend; // ----- readers and writers ----- // - ObjectReader* m_pObjectReader; - DynObjReader* m_pDynObjReader; + ObjectReader* m_pObjectReader; + DynObjReader* m_pDynObjReader; ArchiveReader* m_pArchiveReader; - GroupReader* m_pGroupReader; - BinaryReader* m_pBinaryReader; - ScriptReader* m_pScriptReader; - ObjectWriter* m_pWriter; + GroupReader* m_pGroupReader; + BinaryReader* m_pBinaryReader; + ScriptReader* m_pScriptReader; + ObjectWriter* m_pWriter; }; -} // end namespace mcld -#endif +} // namespace mcld + +#endif // MCLD_OBJECT_OBJECTLINKER_H_
diff --git a/include/mcld/Object/SectionMap.h b/include/mcld/Object/SectionMap.h index bbb4823..46ba7b9 100644 --- a/include/mcld/Object/SectionMap.h +++ b/include/mcld/Object/SectionMap.h
@@ -6,15 +6,17 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_OBJECT_SECTIONMAP_H -#define MCLD_OBJECT_SECTIONMAP_H +#ifndef MCLD_OBJECT_SECTIONMAP_H_ +#define MCLD_OBJECT_SECTIONMAP_H_ -#include <mcld/Script/OutputSectDesc.h> -#include <mcld/Script/InputSectDesc.h> -#include <mcld/Script/Assignment.h> +#include "mcld/Script/Assignment.h" +#include "mcld/Script/InputSectDesc.h" +#include "mcld/Script/OutputSectDesc.h" + #include <llvm/Support/DataTypes.h> -#include <vector> + #include <string> +#include <vector> namespace mcld { @@ -24,34 +26,33 @@ /** \class SectionMap * \brief descirbe how to map input sections into output sections */ -class SectionMap -{ -public: +class SectionMap { + public: class Input { - public: + public: typedef std::vector<std::pair<Fragment*, Assignment> > DotAssignments; typedef DotAssignments::const_iterator const_dot_iterator; typedef DotAssignments::iterator dot_iterator; Input(const std::string& pName, InputSectDesc::KeepPolicy pPolicy); - Input(const InputSectDesc& pInputDesc); + explicit Input(const InputSectDesc& pInputDesc); InputSectDesc::KeepPolicy policy() const { return m_Policy; } const InputSectDesc::Spec& spec() const { return m_Spec; } const LDSection* getSection() const { return m_pSection; } - LDSection* getSection() { return m_pSection; } + LDSection* getSection() { return m_pSection; } const_dot_iterator dot_begin() const { return m_DotAssignments.begin(); } - dot_iterator dot_begin() { return m_DotAssignments.begin(); } - const_dot_iterator dot_end () const { return m_DotAssignments.end(); } - dot_iterator dot_end () { return m_DotAssignments.end(); } + dot_iterator dot_begin() { return m_DotAssignments.begin(); } + const_dot_iterator dot_end() const { return m_DotAssignments.end(); } + dot_iterator dot_end() { return m_DotAssignments.end(); } const DotAssignments& dotAssignments() const { return m_DotAssignments; } - DotAssignments& dotAssignments() { return m_DotAssignments; } + DotAssignments& dotAssignments() { return m_DotAssignments; } - private: + private: InputSectDesc::KeepPolicy m_Policy; InputSectDesc::Spec m_Spec; LDSection* m_pSection; @@ -59,7 +60,7 @@ }; class Output { - public: + public: typedef std::vector<Input*> InputList; typedef InputList::const_iterator const_iterator; typedef InputList::iterator iterator; @@ -70,16 +71,16 @@ typedef DotAssignments::const_iterator const_dot_iterator; typedef DotAssignments::iterator dot_iterator; - Output(const std::string& pName); - Output(const OutputSectDesc& pOutputDesc); + explicit Output(const std::string& pName); + explicit Output(const OutputSectDesc& pOutputDesc); const std::string& name() const { return m_Name; } const OutputSectDesc::Prolog& prolog() const { return m_Prolog; } - OutputSectDesc::Prolog& prolog() { return m_Prolog; } + OutputSectDesc::Prolog& prolog() { return m_Prolog; } const OutputSectDesc::Epilog& epilog() const { return m_Epilog; } - OutputSectDesc::Epilog& epilog() { return m_Epilog; } + OutputSectDesc::Epilog& epilog() { return m_Epilog; } size_t order() const { return m_Order; } @@ -88,19 +89,19 @@ bool hasContent() const; const LDSection* getSection() const { return m_pSection; } - LDSection* getSection() { return m_pSection; } + LDSection* getSection() { return m_pSection; } void setSection(LDSection* pSection) { m_pSection = pSection; } const_iterator begin() const { return m_InputList.begin(); } - iterator begin() { return m_InputList.begin(); } - const_iterator end () const { return m_InputList.end(); } - iterator end () { return m_InputList.end(); } + iterator begin() { return m_InputList.begin(); } + const_iterator end() const { return m_InputList.end(); } + iterator end() { return m_InputList.end(); } const_reference front() const { return m_InputList.front(); } - reference front() { return m_InputList.front(); } - const_reference back () const { return m_InputList.back(); } - reference back () { return m_InputList.back(); } + reference front() { return m_InputList.front(); } + const_reference back() const { return m_InputList.back(); } + reference back() { return m_InputList.back(); } size_t size() const { return m_InputList.size(); } @@ -111,20 +112,20 @@ void append(Input* pInput) { m_InputList.push_back(pInput); } const_dot_iterator dot_begin() const { return m_DotAssignments.begin(); } - dot_iterator dot_begin() { return m_DotAssignments.begin(); } - const_dot_iterator dot_end () const { return m_DotAssignments.end(); } - dot_iterator dot_end () { return m_DotAssignments.end(); } + dot_iterator dot_begin() { return m_DotAssignments.begin(); } + const_dot_iterator dot_end() const { return m_DotAssignments.end(); } + dot_iterator dot_end() { return m_DotAssignments.end(); } const_dot_iterator find_first_explicit_dot() const; - dot_iterator find_first_explicit_dot(); + dot_iterator find_first_explicit_dot(); const_dot_iterator find_last_explicit_dot() const; - dot_iterator find_last_explicit_dot(); + dot_iterator find_last_explicit_dot(); const DotAssignments& dotAssignments() const { return m_DotAssignments; } - DotAssignments& dotAssignments() { return m_DotAssignments; } + DotAssignments& dotAssignments() { return m_DotAssignments; } - private: + private: std::string m_Name; OutputSectDesc::Prolog m_Prolog; OutputSectDesc::Epilog m_Epilog; @@ -135,10 +136,10 @@ DotAssignments m_DotAssignments; }; - struct SHOCompare - { - bool operator()(const Output* LHS, const Output* RHS) const - { return LHS->order() < RHS->order(); } + struct SHOCompare { + bool operator()(const Output* LHS, const Output* RHS) const { + return LHS->order() < RHS->order(); + } }; typedef std::pair<const Output*, const Input*> const_mapping; @@ -153,59 +154,57 @@ typedef OutputDescList::const_reverse_iterator const_reverse_iterator; typedef OutputDescList::reverse_iterator reverse_iterator; -public: + public: ~SectionMap(); const_mapping find(const std::string& pInputFile, const std::string& pInputSection) const; - mapping find(const std::string& pInputFile, - const std::string& pInputSection); + mapping find(const std::string& pInputFile, const std::string& pInputSection); const_iterator find(const std::string& pOutputSection) const; - iterator find(const std::string& pOutputSection); + iterator find(const std::string& pOutputSection); - std::pair<mapping, bool> - insert(const std::string& pInputSection, - const std::string& pOutputSection, - InputSectDesc::KeepPolicy pPolicy = InputSectDesc::NoKeep); - std::pair<mapping, bool> - insert(const InputSectDesc& pInputDesc, const OutputSectDesc& pOutputDesc); + std::pair<mapping, bool> insert( + const std::string& pInputSection, + const std::string& pOutputSection, + InputSectDesc::KeepPolicy pPolicy = InputSectDesc::NoKeep); + std::pair<mapping, bool> insert(const InputSectDesc& pInputDesc, + const OutputSectDesc& pOutputDesc); - bool empty() const { return m_OutputDescList.empty(); } - size_t size () const { return m_OutputDescList.size(); } + bool empty() const { return m_OutputDescList.empty(); } + size_t size() const { return m_OutputDescList.size(); } const_iterator begin() const { return m_OutputDescList.begin(); } - iterator begin() { return m_OutputDescList.begin(); } - const_iterator end () const { return m_OutputDescList.end(); } - iterator end () { return m_OutputDescList.end(); } + iterator begin() { return m_OutputDescList.begin(); } + const_iterator end() const { return m_OutputDescList.end(); } + iterator end() { return m_OutputDescList.end(); } const_reference front() const { return m_OutputDescList.front(); } - reference front() { return m_OutputDescList.front(); } - const_reference back () const { return m_OutputDescList.back(); } - reference back () { return m_OutputDescList.back(); } + reference front() { return m_OutputDescList.front(); } + const_reference back() const { return m_OutputDescList.back(); } + reference back() { return m_OutputDescList.back(); } const_reverse_iterator rbegin() const { return m_OutputDescList.rbegin(); } - reverse_iterator rbegin() { return m_OutputDescList.rbegin(); } - const_reverse_iterator rend () const { return m_OutputDescList.rend(); } - reverse_iterator rend () { return m_OutputDescList.rend(); } + reverse_iterator rbegin() { return m_OutputDescList.rbegin(); } + const_reverse_iterator rend() const { return m_OutputDescList.rend(); } + reverse_iterator rend() { return m_OutputDescList.rend(); } iterator insert(iterator pPosition, LDSection* pSection); // fixupDotSymbols - ensure the dot assignments are valid void fixupDotSymbols(); -private: + private: bool matched(const Input& pInput, const std::string& pInputFile, const std::string& pInputSection) const; bool matched(const WildcardPattern& pPattern, const std::string& pName) const; -private: + private: OutputDescList m_OutputDescList; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_OBJECT_SECTIONMAP_H_
diff --git a/include/mcld/Script/AssertCmd.h b/include/mcld/Script/AssertCmd.h index 14ead49..9201891 100644 --- a/include/mcld/Script/AssertCmd.h +++ b/include/mcld/Script/AssertCmd.h
@@ -6,14 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_ASSERTCMD_H -#define MCLD_SCRIPT_ASSERTCMD_H +#ifndef MCLD_SCRIPT_ASSERTCMD_H_ +#define MCLD_SCRIPT_ASSERTCMD_H_ -#include <mcld/Script/ScriptCommand.h> +#include "mcld/Script/ScriptCommand.h" + #include <string> -namespace mcld -{ +namespace mcld { class RpnExpr; class Module; @@ -22,9 +22,8 @@ * \brief This class defines the interfaces to assert command. */ -class AssertCmd : public ScriptCommand -{ -public: +class AssertCmd : public ScriptCommand { + public: AssertCmd(RpnExpr& pRpnExpr, const std::string& pMessage); ~AssertCmd(); @@ -32,24 +31,23 @@ AssertCmd& operator=(const AssertCmd& pAssertCmd); const RpnExpr& getRpnExpr() const { return m_RpnExpr; } - RpnExpr& getRpnExpr() { return m_RpnExpr; } + RpnExpr& getRpnExpr() { return m_RpnExpr; } const std::string& message() const { return m_Message; } void dump() const; - static bool classof(const ScriptCommand* pCmd) - { + static bool classof(const ScriptCommand* pCmd) { return pCmd->getKind() == ScriptCommand::ASSERT; } void activate(Module& pModule); -private: + private: RpnExpr& m_RpnExpr; std::string m_Message; }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_SCRIPT_ASSERTCMD_H_
diff --git a/include/mcld/Script/Assignment.h b/include/mcld/Script/Assignment.h index c81e871..ced4d19 100644 --- a/include/mcld/Script/Assignment.h +++ b/include/mcld/Script/Assignment.h
@@ -6,44 +6,34 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_ASSIGNMENT_H -#define MCLD_SCRIPT_ASSIGNMENT_H +#ifndef MCLD_SCRIPT_ASSIGNMENT_H_ +#define MCLD_SCRIPT_ASSIGNMENT_H_ -#include <mcld/Script/ScriptCommand.h> +#include "mcld/Script/ScriptCommand.h" -namespace mcld -{ +namespace mcld { class Module; +class RpnEvaluator; class RpnExpr; class SymOperand; -class RpnEvaluator; /** \class Assignment * \brief This class defines the interfaces to assignment command. */ -class Assignment : public ScriptCommand -{ -public: +class Assignment : public ScriptCommand { + public: enum Level { - OUTSIDE_SECTIONS, // outside SECTIONS command - OUTPUT_SECTION, // related to an output section - INPUT_SECTION // related to an input section + OUTSIDE_SECTIONS, // outside SECTIONS command + OUTPUT_SECTION, // related to an output section + INPUT_SECTION // related to an input section }; - enum Type { - DEFAULT, - HIDDEN, - PROVIDE, - PROVIDE_HIDDEN - }; + enum Type { DEFAULT, HIDDEN, PROVIDE, PROVIDE_HIDDEN }; -public: - Assignment(Level pLevel, - Type pType, - SymOperand& pSymbol, - RpnExpr& pRpnExpr); + public: + Assignment(Level pLevel, Type pType, SymOperand& pSymbol, RpnExpr& pRpnExpr); ~Assignment(); @@ -54,15 +44,14 @@ Type type() const { return m_Type; } const SymOperand& symbol() const { return m_Symbol; } - SymOperand& symbol() { return m_Symbol; } + SymOperand& symbol() { return m_Symbol; } const RpnExpr& getRpnExpr() const { return m_RpnExpr; } - RpnExpr& getRpnExpr() { return m_RpnExpr; } + RpnExpr& getRpnExpr() { return m_RpnExpr; } void dump() const; - static bool classof(const ScriptCommand* pCmd) - { + static bool classof(const ScriptCommand* pCmd) { return pCmd->getKind() == ScriptCommand::ASSIGNMENT; } @@ -71,14 +60,13 @@ /// assign - evaluate the rhs and assign the result to lhs. bool assign(RpnEvaluator& pEvaluator); -private: + private: Level m_Level; Type m_Type; SymOperand& m_Symbol; RpnExpr& m_RpnExpr; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_ASSIGNMENT_H_
diff --git a/include/mcld/Script/BinaryOp.h b/include/mcld/Script/BinaryOp.h index c96521e..f684ffa 100644 --- a/include/mcld/Script/BinaryOp.h +++ b/include/mcld/Script/BinaryOp.h
@@ -6,14 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_BINARYOP_H -#define MCLD_SCRIPT_BINARYOP_H +#ifndef MCLD_SCRIPT_BINARYOP_H_ +#define MCLD_SCRIPT_BINARYOP_H_ -#include <mcld/Script/Operator.h> +#include "mcld/Script/Operator.h" + #include <cstddef> -namespace mcld -{ +namespace mcld { class Operand; class IntOperand; @@ -24,109 +24,97 @@ * \brief This class defines the interfaces to an binary operator token. */ -template<Operator::Type TYPE> -class BinaryOp : public Operator -{ -private: +template <Operator::Type TYPE> +class BinaryOp : public Operator { + private: friend class Operator; - BinaryOp() - : Operator(Operator::BINARY, TYPE), m_Size(0) - { + BinaryOp() : Operator(Operator::BINARY, TYPE), m_Size(0) { m_pOperand[0] = m_pOperand[1] = NULL; } -public: - ~BinaryOp() - {} + public: + ~BinaryOp() {} IntOperand* eval(const Module& pModule, const TargetLDBackend& pBackend); - void appendOperand(Operand* pOperand) - { + void appendOperand(Operand* pOperand) { m_pOperand[m_Size++] = pOperand; if (m_Size == 2) m_Size = 0; } -private: + private: size_t m_Size; Operand* m_pOperand[2]; }; -template<> +template <> IntOperand* BinaryOp<Operator::MUL>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* BinaryOp<Operator::DIV>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* BinaryOp<Operator::MOD>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* BinaryOp<Operator::ADD>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* BinaryOp<Operator::SUB>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* BinaryOp<Operator::LSHIFT>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* BinaryOp<Operator::RSHIFT>::eval(const Module&, const TargetLDBackend&); -template<> -IntOperand* BinaryOp<Operator::LT>::eval(const Module&, - const TargetLDBackend&); -template<> -IntOperand* BinaryOp<Operator::LE>::eval(const Module&, - const TargetLDBackend&); -template<> -IntOperand* BinaryOp<Operator::GT>::eval(const Module&, - const TargetLDBackend&); -template<> -IntOperand* BinaryOp<Operator::GE>::eval(const Module&, - const TargetLDBackend&); -template<> -IntOperand* BinaryOp<Operator::EQ>::eval(const Module&, - const TargetLDBackend&); -template<> -IntOperand* BinaryOp<Operator::NE>::eval(const Module&, - const TargetLDBackend&); -template<> +template <> +IntOperand* BinaryOp<Operator::LT>::eval(const Module&, const TargetLDBackend&); +template <> +IntOperand* BinaryOp<Operator::LE>::eval(const Module&, const TargetLDBackend&); +template <> +IntOperand* BinaryOp<Operator::GT>::eval(const Module&, const TargetLDBackend&); +template <> +IntOperand* BinaryOp<Operator::GE>::eval(const Module&, const TargetLDBackend&); +template <> +IntOperand* BinaryOp<Operator::EQ>::eval(const Module&, const TargetLDBackend&); +template <> +IntOperand* BinaryOp<Operator::NE>::eval(const Module&, const TargetLDBackend&); +template <> IntOperand* BinaryOp<Operator::BITWISE_AND>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* BinaryOp<Operator::BITWISE_XOR>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* BinaryOp<Operator::BITWISE_OR>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* BinaryOp<Operator::LOGICAL_AND>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* BinaryOp<Operator::LOGICAL_OR>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* BinaryOp<Operator::ALIGN>::eval(const Module&, const TargetLDBackend&); -template<> -IntOperand* -BinaryOp<Operator::DATA_SEGMENT_RELRO_END>::eval(const Module&, - const TargetLDBackend&); -template<> +template <> +IntOperand* BinaryOp<Operator::DATA_SEGMENT_RELRO_END>::eval( + const Module&, + const TargetLDBackend&); +template <> IntOperand* BinaryOp<Operator::MAX>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* BinaryOp<Operator::MIN>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* BinaryOp<Operator::SEGMENT_START>::eval(const Module&, const TargetLDBackend&); -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_BINARYOP_H_
diff --git a/include/mcld/Script/EntryCmd.h b/include/mcld/Script/EntryCmd.h index 509cc9a..90a4d8a 100644 --- a/include/mcld/Script/EntryCmd.h +++ b/include/mcld/Script/EntryCmd.h
@@ -6,14 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_ENTRYCMD_H -#define MCLD_SCRIPT_ENTRYCMD_H +#ifndef MCLD_SCRIPT_ENTRYCMD_H_ +#define MCLD_SCRIPT_ENTRYCMD_H_ -#include <mcld/Script/ScriptCommand.h> +#include "mcld/Script/ScriptCommand.h" + #include <string> -namespace mcld -{ +namespace mcld { class Module; @@ -21,26 +21,23 @@ * \brief This class defines the interfaces to Entry command. */ -class EntryCmd : public ScriptCommand -{ -public: - EntryCmd(const std::string& pEntry); +class EntryCmd : public ScriptCommand { + public: + explicit EntryCmd(const std::string& pEntry); ~EntryCmd(); void dump() const; - static bool classof(const ScriptCommand* pCmd) - { + static bool classof(const ScriptCommand* pCmd) { return pCmd->getKind() == ScriptCommand::ENTRY; } void activate(Module& pModule); -private: + private: std::string m_Entry; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_ENTRYCMD_H_
diff --git a/include/mcld/Script/ExprToken.h b/include/mcld/Script/ExprToken.h index a182b3c..2e680b2 100644 --- a/include/mcld/Script/ExprToken.h +++ b/include/mcld/Script/ExprToken.h
@@ -6,42 +6,33 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_EXPRTOKEN_H -#define MCLD_SCRIPT_EXPRTOKEN_H +#ifndef MCLD_SCRIPT_EXPRTOKEN_H_ +#define MCLD_SCRIPT_EXPRTOKEN_H_ -namespace mcld -{ +namespace mcld { /** \class ExprToken * \brief This class defines the interfaces to an expression token. */ -class ExprToken -{ -public: - enum Kind { - OPERATOR, - OPERAND - }; +class ExprToken { + public: + enum Kind { OPERATOR, OPERAND }; -protected: - ExprToken(Kind pKind) - : m_Kind(pKind) - {} + protected: + explicit ExprToken(Kind pKind) : m_Kind(pKind) {} -public: - virtual ~ExprToken() - {} + public: + virtual ~ExprToken() {} virtual void dump() const = 0; Kind kind() const { return m_Kind; } -private: + private: Kind m_Kind; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_EXPRTOKEN_H_
diff --git a/include/mcld/Script/FileToken.h b/include/mcld/Script/FileToken.h index 4beaacb..e10e00e 100644 --- a/include/mcld/Script/FileToken.h +++ b/include/mcld/Script/FileToken.h
@@ -6,33 +6,30 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_FILETOKEN_H -#define MCLD_SCRIPT_FILETOKEN_H +#ifndef MCLD_SCRIPT_FILETOKEN_H_ +#define MCLD_SCRIPT_FILETOKEN_H_ -#include <mcld/Script/InputToken.h> -#include <mcld/Support/Allocators.h> -#include <mcld/Config/Config.h> +#include "mcld/Config/Config.h" +#include "mcld/Script/InputToken.h" +#include "mcld/Support/Allocators.h" -namespace mcld -{ +namespace mcld { /** \class FileToken * \brief This class defines the interfaces to a filename in INPUT/GROUP * command. */ -class FileToken : public InputToken -{ -private: +class FileToken : public InputToken { + private: friend class Chunk<FileToken, MCLD_SYMBOLS_PER_INPUT>; FileToken(); FileToken(const std::string& pName, bool pAsNeeded); -public: + public: ~FileToken(); - static bool classof(const InputToken* pToken) - { + static bool classof(const InputToken* pToken) { return pToken->type() == InputToken::File; } @@ -42,6 +39,6 @@ static void clear(); }; -} // namepsace of mcld +} // namespace mcld -#endif +#endif // MCLD_SCRIPT_FILETOKEN_H_
diff --git a/include/mcld/Script/FlexLexer.h b/include/mcld/Script/FlexLexer.h index f09ab20..3514ee1 100644 --- a/include/mcld/Script/FlexLexer.h +++ b/include/mcld/Script/FlexLexer.h
@@ -58,158 +58,151 @@ #define __FLEX_LEXER_H #include <iostream> -# ifndef FLEX_STD -# define FLEX_STD std:: -# endif +#ifndef FLEX_STD +#define FLEX_STD std:: +#endif extern "C++" { - struct yy_buffer_state; typedef int yy_state_type; class FlexLexer { -public: - virtual ~FlexLexer() { } + public: + virtual ~FlexLexer() {} - const char* YYText() const { return yytext; } - int YYLeng() const { return yyleng; } + const char* YYText() const { return yytext; } + int YYLeng() const { return yyleng; } - virtual void - yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0; - virtual struct yy_buffer_state* - yy_create_buffer( FLEX_STD istream* s, int size ) = 0; - virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0; - virtual void yyrestart( FLEX_STD istream* s ) = 0; + virtual void yy_switch_to_buffer(struct yy_buffer_state* new_buffer) = 0; + virtual struct yy_buffer_state* yy_create_buffer(FLEX_STD istream* s, + int size) = 0; + virtual void yy_delete_buffer(struct yy_buffer_state* b) = 0; + virtual void yyrestart(FLEX_STD istream* s) = 0; - virtual int yylex() = 0; + virtual int yylex() = 0; - // Call yylex with new input/output sources. - int yylex( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 ) - { - switch_streams( new_in, new_out ); - return yylex(); - } + // Call yylex with new input/output sources. + int yylex(FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0) { + switch_streams(new_in, new_out); + return yylex(); + } - // Switch to new input/output streams. A nil stream pointer - // indicates "keep the current one". - virtual void switch_streams( FLEX_STD istream* new_in = 0, - FLEX_STD ostream* new_out = 0 ) = 0; + // Switch to new input/output streams. A nil stream pointer + // indicates "keep the current one". + virtual void switch_streams(FLEX_STD istream* new_in = 0, + FLEX_STD ostream* new_out = 0) = 0; - int lineno() const { return yylineno; } + int lineno() const { return yylineno; } - int debug() const { return yy_flex_debug; } - void set_debug( int flag ) { yy_flex_debug = flag; } + int debug() const { return yy_flex_debug; } + void set_debug(int flag) { yy_flex_debug = flag; } -protected: - char* yytext; - int yyleng; - int yylineno; // only maintained if you use %option yylineno - int yy_flex_debug; // only has effect with -d or "%option debug" + protected: + char* yytext; + int yyleng; + int yylineno; // only maintained if you use %option yylineno + int yy_flex_debug; // only has effect with -d or "%option debug" }; - } -#endif // FLEXLEXER_H +#endif // FLEXLEXER_H -#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce) +#if defined(yyFlexLexer) || !defined(yyFlexLexerOnce) // Either this is the first time through (yyFlexLexerOnce not defined), // or this is a repeated include to define a different flavor of // yyFlexLexer, as discussed in the flex manual. #define yyFlexLexerOnce extern "C++" { - class yyFlexLexer : public FlexLexer { -public: - // arg_yyin and arg_yyout default to the cin and cout, but we - // only make that assignment when initializing in yylex(). - yyFlexLexer( FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0 ); + public: + // arg_yyin and arg_yyout default to the cin and cout, but we + // only make that assignment when initializing in yylex(). + yyFlexLexer(FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0); - virtual ~yyFlexLexer(); + virtual ~yyFlexLexer(); - void yy_switch_to_buffer( struct yy_buffer_state* new_buffer ); - struct yy_buffer_state* yy_create_buffer( FLEX_STD istream* s, int size ); - void yy_delete_buffer( struct yy_buffer_state* b ); - void yyrestart( FLEX_STD istream* s ); + void yy_switch_to_buffer(struct yy_buffer_state* new_buffer); + struct yy_buffer_state* yy_create_buffer(FLEX_STD istream* s, int size); + void yy_delete_buffer(struct yy_buffer_state* b); + void yyrestart(FLEX_STD istream* s); - void yypush_buffer_state( struct yy_buffer_state* new_buffer ); - void yypop_buffer_state(); + void yypush_buffer_state(struct yy_buffer_state* new_buffer); + void yypop_buffer_state(); - virtual int yylex(); - virtual void switch_streams( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 ); - virtual int yywrap(); + virtual int yylex(); + virtual void switch_streams(FLEX_STD istream* new_in, + FLEX_STD ostream* new_out = 0); + virtual int yywrap(); -protected: - virtual int LexerInput( char* buf, int max_size ); - virtual void LexerOutput( const char* buf, int size ); - virtual void LexerError( const char* msg ); + protected: + virtual int LexerInput(char* buf, int max_size); + virtual void LexerOutput(const char* buf, int size); + virtual void LexerError(const char* msg); - void yyunput( int c, char* buf_ptr ); - int yyinput(); + void yyunput(int c, char* buf_ptr); + int yyinput(); - void yy_load_buffer_state(); - void yy_init_buffer( struct yy_buffer_state* b, FLEX_STD istream* s ); - void yy_flush_buffer( struct yy_buffer_state* b ); + void yy_load_buffer_state(); + void yy_init_buffer(struct yy_buffer_state* b, FLEX_STD istream* s); + void yy_flush_buffer(struct yy_buffer_state* b); - int yy_start_stack_ptr; - int yy_start_stack_depth; - int* yy_start_stack; + int yy_start_stack_ptr; + int yy_start_stack_depth; + int* yy_start_stack; - void yy_push_state( int new_state ); - void yy_pop_state(); - int yy_top_state(); + void yy_push_state(int new_state); + void yy_pop_state(); + int yy_top_state(); - yy_state_type yy_get_previous_state(); - yy_state_type yy_try_NUL_trans( yy_state_type current_state ); - int yy_get_next_buffer(); + yy_state_type yy_get_previous_state(); + yy_state_type yy_try_NUL_trans(yy_state_type current_state); + int yy_get_next_buffer(); - FLEX_STD istream* yyin; // input source for default LexerInput - FLEX_STD ostream* yyout; // output sink for default LexerOutput + FLEX_STD istream* yyin; // input source for default LexerInput + FLEX_STD ostream* yyout; // output sink for default LexerOutput - // yy_hold_char holds the character lost when yytext is formed. - char yy_hold_char; + // yy_hold_char holds the character lost when yytext is formed. + char yy_hold_char; - // Number of characters read into yy_ch_buf. - int yy_n_chars; + // Number of characters read into yy_ch_buf. + int yy_n_chars; - // Points to current character in buffer. - char* yy_c_buf_p; + // Points to current character in buffer. + char* yy_c_buf_p; - int yy_init; // whether we need to initialize - int yy_start; // start state number + int yy_init; // whether we need to initialize + int yy_start; // start state number - // Flag which is used to allow yywrap()'s to do buffer switches - // instead of setting up a fresh yyin. A bit of a hack ... - int yy_did_buffer_switch_on_eof; + // Flag which is used to allow yywrap()'s to do buffer switches + // instead of setting up a fresh yyin. A bit of a hack ... + int yy_did_buffer_switch_on_eof; + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + struct yy_buffer_state** yy_buffer_stack; /**< Stack as an array. */ + void yyensure_buffer_stack(void); - size_t yy_buffer_stack_top; /**< index of top of stack. */ - size_t yy_buffer_stack_max; /**< capacity of stack. */ - struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */ - void yyensure_buffer_stack(void); + // The following are not always needed, but may be depending + // on use of certain flex features (like REJECT or yymore()). - // The following are not always needed, but may be depending - // on use of certain flex features (like REJECT or yymore()). + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; - yy_state_type yy_last_accepting_state; - char* yy_last_accepting_cpos; + yy_state_type* yy_state_buf; + yy_state_type* yy_state_ptr; - yy_state_type* yy_state_buf; - yy_state_type* yy_state_ptr; + char* yy_full_match; + int* yy_full_state; + int yy_full_lp; - char* yy_full_match; - int* yy_full_state; - int yy_full_lp; + int yy_lp; + int yy_looking_for_trail_begin; - int yy_lp; - int yy_looking_for_trail_begin; - - int yy_more_flag; - int yy_more_len; - int yy_more_offset; - int yy_prev_more_offset; + int yy_more_flag; + int yy_more_len; + int yy_more_offset; + int yy_prev_more_offset; }; - } -#endif // yyFlexLexer || ! yyFlexLexerOnce - +#endif // yyFlexLexer || ! yyFlexLexerOnce
diff --git a/include/mcld/Script/GroupCmd.h b/include/mcld/Script/GroupCmd.h index 5a016db..8f3f171 100644 --- a/include/mcld/Script/GroupCmd.h +++ b/include/mcld/Script/GroupCmd.h
@@ -6,27 +6,25 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_GROUPCMD_H -#define MCLD_SCRIPT_GROUPCMD_H +#ifndef MCLD_SCRIPT_GROUPCMD_H_ +#define MCLD_SCRIPT_GROUPCMD_H_ -#include <mcld/Script/ScriptCommand.h> +#include "mcld/Script/ScriptCommand.h" -namespace mcld -{ +namespace mcld { -class StringList; class InputTree; class InputBuilder; class GroupReader; class LinkerConfig; +class StringList; /** \class GroupCmd * \brief This class defines the interfaces to Group command. */ -class GroupCmd : public ScriptCommand -{ -public: +class GroupCmd : public ScriptCommand { + public: GroupCmd(StringList& pStringList, InputTree& pInputTree, InputBuilder& pBuilder, @@ -36,14 +34,13 @@ void dump() const; - static bool classof(const ScriptCommand* pCmd) - { + static bool classof(const ScriptCommand* pCmd) { return pCmd->getKind() == ScriptCommand::GROUP; } void activate(Module& pModule); -private: + private: StringList& m_StringList; InputTree& m_InputTree; InputBuilder& m_Builder; @@ -51,7 +48,6 @@ const LinkerConfig& m_Config; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_GROUPCMD_H_
diff --git a/include/mcld/Script/InputCmd.h b/include/mcld/Script/InputCmd.h new file mode 100644 index 0000000..694fcda --- /dev/null +++ b/include/mcld/Script/InputCmd.h
@@ -0,0 +1,59 @@ +//===- InputCmd.h ---------------------------------------------------------===// +// +// The MCLinker Project +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#ifndef MCLD_SCRIPT_INPUTCMD_H_ +#define MCLD_SCRIPT_INPUTCMD_H_ + +#include "mcld/Script/ScriptCommand.h" + +namespace mcld { + +class ArchiveReader; +class DynObjReader; +class InputBuilder; +class InputTree; +class LinkerConfig; +class ObjectReader; +class StringList; + +/** \class InputCmd + * \brief This class defines the interfaces to Input command. + */ + +class InputCmd : public ScriptCommand { + public: + InputCmd(StringList& pStringList, + InputTree& pInputTree, + InputBuilder& pBuilder, + ObjectReader& pObjectReader, + ArchiveReader& pArchiveReader, + DynObjReader& pDynObjReader, + const LinkerConfig& pConfig); + ~InputCmd(); + + void dump() const; + + static bool classof(const ScriptCommand* pCmd) { + return pCmd->getKind() == ScriptCommand::INPUT; + } + + void activate(Module& pModule); + + private: + StringList& m_StringList; + InputTree& m_InputTree; + InputBuilder& m_Builder; + ObjectReader& m_ObjectReader; + ArchiveReader& m_ArchiveReader; + DynObjReader& m_DynObjReader; + const LinkerConfig& m_Config; +}; + +} // namespace mcld + +#endif // MCLD_SCRIPT_INPUTCMD_H_
diff --git a/include/mcld/Script/InputSectDesc.h b/include/mcld/Script/InputSectDesc.h index ede2a3d..a883769 100644 --- a/include/mcld/Script/InputSectDesc.h +++ b/include/mcld/Script/InputSectDesc.h
@@ -6,30 +6,26 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_INPUTSECTDESC_H -#define MCLD_SCRIPT_INPUTSECTDESC_H +#ifndef MCLD_SCRIPT_INPUTSECTDESC_H_ +#define MCLD_SCRIPT_INPUTSECTDESC_H_ -#include <mcld/Script/ScriptCommand.h> -#include <mcld/Script/StringList.h> +#include "mcld/Script/ScriptCommand.h" +#include "mcld/Script/StringList.h" + #include <cassert> -namespace mcld -{ +namespace mcld { -class WildcardPattern; class OutputSectDesc; +class WildcardPattern; /** \class InputSectDesc * \brief This class defines the interfaces to input section description. */ -class InputSectDesc : public ScriptCommand -{ -public: - enum KeepPolicy { - Keep, - NoKeep - }; +class InputSectDesc : public ScriptCommand { + public: + enum KeepPolicy { Keep, NoKeep }; struct Spec { bool hasFile() const { return m_pWildcardFile != NULL; } @@ -72,7 +68,7 @@ StringList* m_pWildcardSections; }; -public: + public: InputSectDesc(KeepPolicy pPolicy, const Spec& pSpec, const OutputSectDesc& pOutputDesc); @@ -84,19 +80,18 @@ void dump() const; - static bool classof(const ScriptCommand* pCmd) - { + static bool classof(const ScriptCommand* pCmd) { return pCmd->getKind() == ScriptCommand::INPUT_SECT_DESC; } void activate(Module& pModule); -private: + private: KeepPolicy m_KeepPolicy; Spec m_Spec; const OutputSectDesc& m_OutputSectDesc; }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_SCRIPT_INPUTSECTDESC_H_
diff --git a/include/mcld/Script/InputToken.h b/include/mcld/Script/InputToken.h index 057c06d..9f761c3 100644 --- a/include/mcld/Script/InputToken.h +++ b/include/mcld/Script/InputToken.h
@@ -6,48 +6,41 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_INPUTTOKEN_H -#define MCLD_SCRIPT_INPUTTOKEN_H +#ifndef MCLD_SCRIPT_INPUTTOKEN_H_ +#define MCLD_SCRIPT_INPUTTOKEN_H_ -#include <mcld/Script/StrToken.h> +#include "mcld/Script/StrToken.h" -namespace mcld -{ +namespace mcld { /** \class InputToken * \brief This class defines the interfaces to a file/namespec token. */ -class InputToken : public StrToken -{ -public: - enum Type { - Unknown, - File, - NameSpec - }; +class InputToken : public StrToken { + public: + enum Type { Unknown, File, NameSpec }; -protected: + protected: InputToken(); InputToken(Type pType, const std::string& pName, bool pAsNeeded); -public: + public: virtual ~InputToken(); Type type() const { return m_Type; } bool asNeeded() const { return m_bAsNeeded; } - static bool classof(const StrToken* pToken) - { + static bool classof(const StrToken* pToken) { return pToken->kind() == StrToken::Input; } -private: + private: Type m_Type; bool m_bAsNeeded; }; -} // namepsace of mcld +} // namespace mcld -#endif +#endif // MCLD_SCRIPT_INPUTTOKEN_H_
diff --git a/include/mcld/Script/NameSpec.h b/include/mcld/Script/NameSpec.h index 50040fa..a8db136 100644 --- a/include/mcld/Script/NameSpec.h +++ b/include/mcld/Script/NameSpec.h
@@ -6,33 +6,30 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_NAMESPEC_H -#define MCLD_SCRIPT_NAMESPEC_H +#ifndef MCLD_SCRIPT_NAMESPEC_H_ +#define MCLD_SCRIPT_NAMESPEC_H_ -#include <mcld/Script/InputToken.h> -#include <mcld/Support/Allocators.h> -#include <mcld/Config/Config.h> +#include "mcld/Config/Config.h" +#include "mcld/Script/InputToken.h" +#include "mcld/Support/Allocators.h" -namespace mcld -{ +namespace mcld { /** \class NameSpec * \brief This class defines the interfaces to a namespec in INPUT/GROUP * command. */ -class NameSpec : public InputToken -{ -private: +class NameSpec : public InputToken { + private: friend class Chunk<NameSpec, MCLD_SYMBOLS_PER_INPUT>; NameSpec(); NameSpec(const std::string& pName, bool pAsNeeded); -public: + public: ~NameSpec(); - static bool classof(const InputToken* pToken) - { + static bool classof(const InputToken* pToken) { return pToken->type() == InputToken::NameSpec; } @@ -42,6 +39,6 @@ static void clear(); }; -} // namepsace of mcld +} // namespace mcld -#endif +#endif // MCLD_SCRIPT_NAMESPEC_H_
diff --git a/include/mcld/Script/NullaryOp.h b/include/mcld/Script/NullaryOp.h index 00a7db2..129d756 100644 --- a/include/mcld/Script/NullaryOp.h +++ b/include/mcld/Script/NullaryOp.h
@@ -6,14 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_NULLOP_H -#define MCLD_SCRIPT_NULLOP_H +#ifndef MCLD_SCRIPT_NULLARYOP_H_ +#define MCLD_SCRIPT_NULLARYOP_H_ -#include <mcld/Script/Operator.h> +#include "mcld/Script/Operator.h" + #include <cassert> -namespace mcld -{ +namespace mcld { class Operand; class IntOperand; @@ -24,39 +24,32 @@ * \brief This class defines the interfaces to an nullary operator token. */ -template<Operator::Type TYPE> -class NullaryOp : public Operator -{ -private: +template <Operator::Type TYPE> +class NullaryOp : public Operator { + private: friend class Operator; - NullaryOp() - : Operator(Operator::NULLARY, TYPE) - {} + NullaryOp() : Operator(Operator::NULLARY, TYPE) {} -public: - ~NullaryOp() - {} + public: + ~NullaryOp() {} IntOperand* eval(const Module& pModule, const TargetLDBackend& pBackend); - void appendOperand(Operand* pOperand) - { - assert(0); - } + void appendOperand(Operand* pOperand) { assert(0); } }; -template<> +template <> IntOperand* NullaryOp<Operator::SIZEOF_HEADERS>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* NullaryOp<Operator::MAXPAGESIZE>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* NullaryOp<Operator::COMMONPAGESIZE>::eval(const Module&, const TargetLDBackend&); -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_SCRIPT_NULLARYOP_H_
diff --git a/include/mcld/Script/Operand.h b/include/mcld/Script/Operand.h index 86c1228..9258a32 100644 --- a/include/mcld/Script/Operand.h +++ b/include/mcld/Script/Operand.h
@@ -6,52 +6,46 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_OPERAND_H -#define MCLD_SCRIPT_OPERAND_H +#ifndef MCLD_SCRIPT_OPERAND_H_ +#define MCLD_SCRIPT_OPERAND_H_ -#include <mcld/Script/ExprToken.h> -#include <mcld/Object/SectionMap.h> -#include <mcld/Support/Allocators.h> -#include <mcld/Config/Config.h> +#include "mcld/Config/Config.h" +#include "mcld/Object/SectionMap.h" +#include "mcld/Script/ExprToken.h" +#include "mcld/Support/Allocators.h" + #include <llvm/Support/DataTypes.h> + #include <string> + #include <cassert> -namespace mcld -{ +namespace mcld { /** \class Operand * \brief This class defines the interfaces to an operand token. */ -class Operand : public ExprToken -{ -public: - enum Type { - SYMBOL, - INTEGER, - SECTION, - SECTION_DESC, - FRAGMENT - }; +class Operand : public ExprToken { + public: + enum Type { SYMBOL, INTEGER, SECTION, SECTION_DESC, FRAGMENT }; -protected: - Operand(Type pType); + protected: + explicit Operand(Type pType); virtual ~Operand(); -public: + public: Type type() const { return m_Type; } virtual bool isDot() const { return false; } virtual uint64_t value() const = 0; - static bool classof(const ExprToken* pToken) - { + static bool classof(const ExprToken* pToken) { return pToken->kind() == ExprToken::OPERAND; } -private: + private: Type m_Type; }; @@ -59,14 +53,13 @@ * \brief This class defines the interfaces to a symbol operand. */ -class SymOperand : public Operand -{ -private: +class SymOperand : public Operand { + private: friend class Chunk<SymOperand, MCLD_SYMBOLS_PER_INPUT>; SymOperand(); - SymOperand(const std::string& pName); + explicit SymOperand(const std::string& pName); -public: + public: void dump() const; const std::string& name() const { return m_Name; } @@ -77,8 +70,7 @@ void setValue(uint64_t pValue) { m_Value = pValue; } - static bool classof(const Operand* pOperand) - { + static bool classof(const Operand* pOperand) { return pOperand->type() == Operand::SYMBOL; } @@ -87,7 +79,7 @@ static void destroy(SymOperand*& pOperand); static void clear(); -private: + private: std::string m_Name; uint64_t m_Value; }; @@ -96,22 +88,20 @@ * \brief This class defines the interfaces to an integer operand. */ -class IntOperand : public Operand -{ -private: +class IntOperand : public Operand { + private: friend class Chunk<IntOperand, MCLD_SYMBOLS_PER_INPUT>; IntOperand(); - IntOperand(uint64_t pValue); + explicit IntOperand(uint64_t pValue); -public: + public: void dump() const; uint64_t value() const { return m_Value; } void setValue(uint64_t pValue) { m_Value = pValue; } - static bool classof(const Operand* pOperand) - { + static bool classof(const Operand* pOperand) { return pOperand->type() == Operand::INTEGER; } @@ -120,7 +110,7 @@ static void destroy(IntOperand*& pOperand); static void clear(); -private: + private: uint64_t m_Value; }; @@ -129,26 +119,23 @@ */ class LDSection; -class SectOperand : public Operand -{ -private: +class SectOperand : public Operand { + private: friend class Chunk<SectOperand, MCLD_SECTIONS_PER_INPUT>; SectOperand(); - SectOperand(const std::string& pName); + explicit SectOperand(const std::string& pName); -public: + public: void dump() const; const std::string& name() const { return m_Name; } - uint64_t value() const - { + uint64_t value() const { assert(0); return 0; } - static bool classof(const Operand* pOperand) - { + static bool classof(const Operand* pOperand) { return pOperand->type() == Operand::SECTION; } @@ -157,7 +144,7 @@ static void destroy(SectOperand*& pOperand); static void clear(); -private: + private: std::string m_Name; }; @@ -165,26 +152,23 @@ * \brief This class defines the interfaces to an section name operand. */ -class SectDescOperand : public Operand -{ -private: +class SectDescOperand : public Operand { + private: friend class Chunk<SectDescOperand, MCLD_SECTIONS_PER_INPUT>; SectDescOperand(); - SectDescOperand(const SectionMap::Output* pOutputDesc); + explicit SectDescOperand(const SectionMap::Output* pOutputDesc); -public: + public: void dump() const; const SectionMap::Output* outputDesc() const { return m_pOutputDesc; } - uint64_t value() const - { + uint64_t value() const { assert(0); return 0; } - static bool classof(const Operand* pOperand) - { + static bool classof(const Operand* pOperand) { return pOperand->type() == Operand::SECTION_DESC; } @@ -193,7 +177,7 @@ static void destroy(SectDescOperand*& pOperand); static void clear(); -private: + private: const SectionMap::Output* m_pOutputDesc; }; @@ -203,23 +187,21 @@ class Fragment; -class FragOperand : public Operand -{ -private: +class FragOperand : public Operand { + private: friend class Chunk<FragOperand, MCLD_SYMBOLS_PER_INPUT>; FragOperand(); - FragOperand(Fragment& pFragment); + explicit FragOperand(Fragment& pFragment); -public: + public: void dump() const; const Fragment* frag() const { return m_pFragment; } - Fragment* frag() { return m_pFragment; } + Fragment* frag() { return m_pFragment; } uint64_t value() const; - static bool classof(const Operand* pOperand) - { + static bool classof(const Operand* pOperand) { return pOperand->type() == Operand::FRAGMENT; } @@ -228,11 +210,10 @@ static void destroy(FragOperand*& pOperand); static void clear(); -private: + private: Fragment* m_pFragment; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_OPERAND_H_
diff --git a/include/mcld/Script/Operator.h b/include/mcld/Script/Operator.h index b438b4d..017e735 100644 --- a/include/mcld/Script/Operator.h +++ b/include/mcld/Script/Operator.h
@@ -6,100 +6,93 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_OPERATOR_INTERFACE_H -#define MCLD_SCRIPT_OPERATOR_INTERFACE_H +#ifndef MCLD_SCRIPT_OPERATOR_H_ +#define MCLD_SCRIPT_OPERATOR_H_ -#include <mcld/Script/ExprToken.h> +#include "mcld/Script/ExprToken.h" #include <llvm/Support/DataTypes.h> -namespace mcld -{ +namespace mcld { -class Operand; class IntOperand; class Module; +class Operand; class TargetLDBackend; /** \class Operator * \brief This class defines the interfaces to an operator token. */ -class Operator : public ExprToken -{ -public: - enum Arity { - NULLARY, - UNARY, - BINARY, - TERNARY - }; +class Operator : public ExprToken { + public: + enum Arity { NULLARY, UNARY, BINARY, TERNARY }; enum Type { /* arithmetic operator */ - UNARY_PLUS = 0, + UNARY_PLUS = 0, UNARY_MINUS = 1, LOGICAL_NOT = 2, BITWISE_NOT = 3, - MUL = 4, - DIV = 5, - MOD = 6, - ADD = 7, - SUB = 8, - LSHIFT = 9, - RSHIFT = 10, - LT = 11, - LE = 12, - GT = 13, - GE = 14, - EQ = 15, - NE = 16, + MUL = 4, + DIV = 5, + MOD = 6, + ADD = 7, + SUB = 8, + LSHIFT = 9, + RSHIFT = 10, + LT = 11, + LE = 12, + GT = 13, + GE = 14, + EQ = 15, + NE = 16, BITWISE_AND = 17, BITWISE_XOR = 18, - BITWISE_OR = 19, + BITWISE_OR = 19, LOGICAL_AND = 20, - LOGICAL_OR = 21, - TERNARY_IF = 22, - ASSIGN = 23, - ADD_ASSIGN = 24, - SUB_ASSIGN = 25, - MUL_ASSIGN = 26, - DIV_ASSIGN = 27, - AND_ASSIGN = 28, - OR_ASSIGN = 29, - LS_ASSIGN = 30, - RS_ASSIGN = 31, + LOGICAL_OR = 21, + TERNARY_IF = 22, + ASSIGN = 23, + ADD_ASSIGN = 24, + SUB_ASSIGN = 25, + MUL_ASSIGN = 26, + DIV_ASSIGN = 27, + AND_ASSIGN = 28, + OR_ASSIGN = 29, + LS_ASSIGN = 30, + RS_ASSIGN = 31, /* function */ - ABSOLUTE = 32, - ADDR = 33, - ALIGN = 34, - ALIGNOF = 35, - BLOCK = 36, - DATA_SEGMENT_ALIGN = 37, - DATA_SEGMENT_END = 38, + ABSOLUTE = 32, + ADDR = 33, + ALIGN = 34, + ALIGNOF = 35, + BLOCK = 36, + DATA_SEGMENT_ALIGN = 37, + DATA_SEGMENT_END = 38, DATA_SEGMENT_RELRO_END = 39, - DEFINED = 40, - LENGTH = 41, - LOADADDR = 42, - MAX = 43, - MIN = 44, - NEXT = 45, - ORIGIN = 46, - SEGMENT_START = 47, - SIZEOF = 48, - SIZEOF_HEADERS = 49, - MAXPAGESIZE = 50, - COMMONPAGESIZE = 51 + DEFINED = 40, + LENGTH = 41, + LOADADDR = 42, + MAX = 43, + MIN = 44, + NEXT = 45, + ORIGIN = 46, + SEGMENT_START = 47, + SIZEOF = 48, + SIZEOF_HEADERS = 49, + MAXPAGESIZE = 50, + COMMONPAGESIZE = 51 }; static const char* OpNames[]; -protected: + protected: Operator(Arity pArity, Type pType); const IntOperand* result() const { return m_pIntOperand; } - IntOperand* result() { return m_pIntOperand; } + IntOperand* result() { return m_pIntOperand; } -public: + public: virtual ~Operator(); Arity arity() const { return m_Arity; } @@ -113,116 +106,113 @@ virtual void appendOperand(Operand* pOperand) = 0; - static bool classof(const ExprToken* pToken) - { + static bool classof(const ExprToken* pToken) { return pToken->kind() == ExprToken::OPERATOR; } - template<Operator::Type TYPE> + template <Operator::Type TYPE> static Operator& create(); -private: + private: Arity m_Arity; Type m_Type; IntOperand* m_pIntOperand; }; /* Nullary operator */ -template<> +template <> Operator& Operator::create<Operator::SIZEOF_HEADERS>(); -template<> +template <> Operator& Operator::create<Operator::MAXPAGESIZE>(); -template<> +template <> Operator& Operator::create<Operator::COMMONPAGESIZE>(); /* Unary operator */ -template<> +template <> Operator& Operator::create<Operator::UNARY_PLUS>(); -template<> +template <> Operator& Operator::create<Operator::UNARY_MINUS>(); -template<> +template <> Operator& Operator::create<Operator::LOGICAL_NOT>(); -template<> +template <> Operator& Operator::create<Operator::BITWISE_NOT>(); -template<> +template <> Operator& Operator::create<Operator::ABSOLUTE>(); -template<> +template <> Operator& Operator::create<Operator::ADDR>(); -template<> +template <> Operator& Operator::create<Operator::ALIGNOF>(); -template<> +template <> Operator& Operator::create<Operator::DATA_SEGMENT_END>(); -template<> +template <> Operator& Operator::create<Operator::DEFINED>(); -template<> +template <> Operator& Operator::create<Operator::LENGTH>(); -template<> +template <> Operator& Operator::create<Operator::LOADADDR>(); -template<> +template <> Operator& Operator::create<Operator::NEXT>(); -template<> +template <> Operator& Operator::create<Operator::ORIGIN>(); -template<> +template <> Operator& Operator::create<Operator::SIZEOF>(); /* Binary operator */ -template<> +template <> Operator& Operator::create<Operator::MUL>(); -template<> +template <> Operator& Operator::create<Operator::DIV>(); -template<> +template <> Operator& Operator::create<Operator::MOD>(); -template<> +template <> Operator& Operator::create<Operator::ADD>(); -template<> +template <> Operator& Operator::create<Operator::SUB>(); -template<> +template <> Operator& Operator::create<Operator::LSHIFT>(); -template<> +template <> Operator& Operator::create<Operator::RSHIFT>(); -template<> +template <> Operator& Operator::create<Operator::LT>(); -template<> +template <> Operator& Operator::create<Operator::LE>(); -template<> +template <> Operator& Operator::create<Operator::GT>(); -template<> +template <> Operator& Operator::create<Operator::GE>(); -template<> +template <> Operator& Operator::create<Operator::EQ>(); -template<> +template <> Operator& Operator::create<Operator::NE>(); -template<> +template <> Operator& Operator::create<Operator::BITWISE_AND>(); -template<> +template <> Operator& Operator::create<Operator::BITWISE_XOR>(); -template<> +template <> Operator& Operator::create<Operator::BITWISE_OR>(); -template<> +template <> Operator& Operator::create<Operator::LOGICAL_AND>(); -template<> +template <> Operator& Operator::create<Operator::LOGICAL_OR>(); -template<> +template <> Operator& Operator::create<Operator::ALIGN>(); -template<> +template <> Operator& Operator::create<Operator::DATA_SEGMENT_RELRO_END>(); -template<> +template <> Operator& Operator::create<Operator::MAX>(); -template<> +template <> Operator& Operator::create<Operator::MIN>(); -template<> +template <> Operator& Operator::create<Operator::SEGMENT_START>(); /* Ternary operator */ -template<> +template <> Operator& Operator::create<Operator::TERNARY_IF>(); -template<> -Operator& -Operator::create<Operator::DATA_SEGMENT_ALIGN>(); -} // namespace of mcld +template <> +Operator& Operator::create<Operator::DATA_SEGMENT_ALIGN>(); +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_OPERATOR_H_
diff --git a/include/mcld/Script/OutputArchCmd.h b/include/mcld/Script/OutputArchCmd.h index aad97fc..1c22697 100644 --- a/include/mcld/Script/OutputArchCmd.h +++ b/include/mcld/Script/OutputArchCmd.h
@@ -6,14 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_OUTPUTARCHCMD_H -#define MCLD_SCRIPT_OUTPUTARCHCMD_H +#ifndef MCLD_SCRIPT_OUTPUTARCHCMD_H_ +#define MCLD_SCRIPT_OUTPUTARCHCMD_H_ -#include <mcld/Script/ScriptCommand.h> +#include "mcld/Script/ScriptCommand.h" + #include <string> -namespace mcld -{ +namespace mcld { class Module; @@ -21,26 +21,23 @@ * \brief This class defines the interfaces to OutputArch command. */ -class OutputArchCmd : public ScriptCommand -{ -public: - OutputArchCmd(const std::string& pArch); +class OutputArchCmd : public ScriptCommand { + public: + explicit OutputArchCmd(const std::string& pArch); ~OutputArchCmd(); void dump() const; - static bool classof(const ScriptCommand* pCmd) - { + static bool classof(const ScriptCommand* pCmd) { return pCmd->getKind() == ScriptCommand::OUTPUT_ARCH; } void activate(Module& pModule); -private: + private: std::string m_Arch; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_OUTPUTARCHCMD_H_
diff --git a/include/mcld/Script/OutputCmd.h b/include/mcld/Script/OutputCmd.h index 0ee895f..d7afa25 100644 --- a/include/mcld/Script/OutputCmd.h +++ b/include/mcld/Script/OutputCmd.h
@@ -6,14 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_OUTPUTCMD_H -#define MCLD_SCRIPT_OUTPUTCMD_H +#ifndef MCLD_SCRIPT_OUTPUTCMD_H_ +#define MCLD_SCRIPT_OUTPUTCMD_H_ -#include <mcld/Script/ScriptCommand.h> +#include "mcld/Script/ScriptCommand.h" + #include <string> -namespace mcld -{ +namespace mcld { class Module; @@ -21,27 +21,24 @@ * \brief This class defines the interfaces to Output command. */ -class OutputCmd : public ScriptCommand -{ -public: - OutputCmd(const std::string& pOutputFile); +class OutputCmd : public ScriptCommand { + public: + explicit OutputCmd(const std::string& pOutputFile); ~OutputCmd(); void dump() const; - static bool classof(const ScriptCommand* pCmd) - { + static bool classof(const ScriptCommand* pCmd) { return pCmd->getKind() == ScriptCommand::OUTPUT; } void activate(Module& pModule); -private: + private: std::string m_OutputFile; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_OUTPUTCMD_H_
diff --git a/include/mcld/Script/OutputFormatCmd.h b/include/mcld/Script/OutputFormatCmd.h index 0c34872..307f738 100644 --- a/include/mcld/Script/OutputFormatCmd.h +++ b/include/mcld/Script/OutputFormatCmd.h
@@ -6,15 +6,15 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_OUTPUTFORMATCMD_H -#define MCLD_SCRIPT_OUTPUTFORMATCMD_H +#ifndef MCLD_SCRIPT_OUTPUTFORMATCMD_H_ +#define MCLD_SCRIPT_OUTPUTFORMATCMD_H_ -#include <mcld/Script/ScriptCommand.h> +#include "mcld/Script/ScriptCommand.h" + #include <string> #include <vector> -namespace mcld -{ +namespace mcld { class Module; @@ -22,39 +22,36 @@ * \brief This class defines the interfaces to OutputFormat command. */ -class OutputFormatCmd : public ScriptCommand -{ -public: +class OutputFormatCmd : public ScriptCommand { + public: typedef std::vector<std::string> FormatList; typedef FormatList::const_iterator const_iterator; typedef FormatList::iterator iterator; -public: - OutputFormatCmd(const std::string& pFormat); + public: + explicit OutputFormatCmd(const std::string& pFormat); OutputFormatCmd(const std::string& pDefault, const std::string& pBig, const std::string& pLittle); ~OutputFormatCmd(); const_iterator begin() const { return m_FormatList.begin(); } - iterator begin() { return m_FormatList.begin(); } - const_iterator end() const { return m_FormatList.end(); } - iterator end() { return m_FormatList.end(); } + iterator begin() { return m_FormatList.begin(); } + const_iterator end() const { return m_FormatList.end(); } + iterator end() { return m_FormatList.end(); } void dump() const; - static bool classof(const ScriptCommand* pCmd) - { + static bool classof(const ScriptCommand* pCmd) { return pCmd->getKind() == ScriptCommand::OUTPUT_FORMAT; } void activate(Module& pModule); -private: + private: FormatList m_FormatList; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_OUTPUTFORMATCMD_H_
diff --git a/include/mcld/Script/OutputSectDesc.h b/include/mcld/Script/OutputSectDesc.h index abf4613..c8df493 100644 --- a/include/mcld/Script/OutputSectDesc.h +++ b/include/mcld/Script/OutputSectDesc.h
@@ -6,16 +6,17 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_OUTPUTSECTDESC_H -#define MCLD_SCRIPT_OUTPUTSECTDESC_H +#ifndef MCLD_SCRIPT_OUTPUTSECTDESC_H_ +#define MCLD_SCRIPT_OUTPUTSECTDESC_H_ -#include <mcld/Script/ScriptCommand.h> -#include <vector> +#include "mcld/Script/ScriptCommand.h" + #include <string> +#include <vector> + #include <cassert> -namespace mcld -{ +namespace mcld { class RpnExpr; class StringList; @@ -24,11 +25,10 @@ * \brief This class defines the interfaces to output section description. */ -class OutputSectDesc : public ScriptCommand -{ -public: +class OutputSectDesc : public ScriptCommand { + public: enum Type { - LOAD, // ALLOC + LOAD, // ALLOC NOLOAD, DSECT, COPY, @@ -36,11 +36,7 @@ OVERLAY }; - enum Constraint { - NO_CONSTRAINT, - ONLY_IF_RO, - ONLY_IF_RW - }; + enum Constraint { NO_CONSTRAINT, ONLY_IF_RO, ONLY_IF_RW }; struct Prolog { bool hasVMA() const { return m_pVMA != NULL; } @@ -53,9 +49,7 @@ return *m_pVMA; } - void setType(Type pType) { - m_Type = pType; - } + void setType(Type pType) { m_Type = pType; } Type type() const { return m_Type; } @@ -91,7 +85,7 @@ return false; if (m_Type != pRHS.m_Type) return false; - if (m_pLMA!= pRHS.m_pLMA) + if (m_pLMA != pRHS.m_pLMA) return false; if (m_pAlign != pRHS.m_pAlign) return false; @@ -162,19 +156,19 @@ typedef OutputSectCmds::const_reference const_reference; typedef OutputSectCmds::reference reference; -public: + public: OutputSectDesc(const std::string& pName, const Prolog& pProlog); ~OutputSectDesc(); - const_iterator begin() const { return m_OutputSectCmds.begin(); } - iterator begin() { return m_OutputSectCmds.begin(); } - const_iterator end() const { return m_OutputSectCmds.end(); } - iterator end() { return m_OutputSectCmds.end(); } + const_iterator begin() const { return m_OutputSectCmds.begin(); } + iterator begin() { return m_OutputSectCmds.begin(); } + const_iterator end() const { return m_OutputSectCmds.end(); } + iterator end() { return m_OutputSectCmds.end(); } const_reference front() const { return m_OutputSectCmds.front(); } - reference front() { return m_OutputSectCmds.front(); } - const_reference back() const { return m_OutputSectCmds.back(); } - reference back() { return m_OutputSectCmds.back(); } + reference front() { return m_OutputSectCmds.front(); } + const_reference back() const { return m_OutputSectCmds.back(); } + reference back() { return m_OutputSectCmds.back(); } const std::string& name() const { return m_Name; } @@ -184,8 +178,7 @@ void dump() const; - static bool classof(const ScriptCommand* pCmd) - { + static bool classof(const ScriptCommand* pCmd) { return pCmd->getKind() == ScriptCommand::OUTPUT_SECT_DESC; } @@ -199,13 +192,13 @@ const Epilog& epilog() const { return m_Epilog; } -private: + private: OutputSectCmds m_OutputSectCmds; std::string m_Name; Prolog m_Prolog; Epilog m_Epilog; }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_SCRIPT_OUTPUTSECTDESC_H_
diff --git a/include/mcld/Script/RpnEvaluator.h b/include/mcld/Script/RpnEvaluator.h index 7e35e86..d71366b 100644 --- a/include/mcld/Script/RpnEvaluator.h +++ b/include/mcld/Script/RpnEvaluator.h
@@ -6,31 +6,32 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_RPNEVALUATOR_H -#define MCLD_SCRIPT_RPNEVALUATOR_H +#ifndef MCLD_SCRIPT_RPNEVALUATOR_H_ +#define MCLD_SCRIPT_RPNEVALUATOR_H_ + +#include <cstdint> namespace mcld { -class RpnExpr; class Module; +class RpnExpr; class TargetLDBackend; /** \class RpnEvaluator * \brief RpnEvaluator evaluate a rpn expression */ -class RpnEvaluator -{ -public: +class RpnEvaluator { + public: RpnEvaluator(const Module& pModule, const TargetLDBackend& pBackend); // evaluate a valid expression and set the value in the second parameter bool eval(const RpnExpr& pExpr, uint64_t& pResult); -private: + private: const Module& m_Module; const TargetLDBackend& m_Backend; }; -} // mcld +} // namespace mcld -#endif +#endif // MCLD_SCRIPT_RPNEVALUATOR_H_
diff --git a/include/mcld/Script/RpnExpr.h b/include/mcld/Script/RpnExpr.h index eaf4f72..c80314d 100644 --- a/include/mcld/Script/RpnExpr.h +++ b/include/mcld/Script/RpnExpr.h
@@ -6,16 +6,16 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_RPNEXPR_H -#define MCLD_SCRIPT_RPNEXPR_H +#ifndef MCLD_SCRIPT_RPNEXPR_H_ +#define MCLD_SCRIPT_RPNEXPR_H_ -#include <mcld/Support/Allocators.h> -#include <mcld/Config/Config.h> -#include <mcld/Object/SectionMap.h> +#include "mcld/Config/Config.h" +#include "mcld/Object/SectionMap.h" +#include "mcld/Support/Allocators.h" + #include <vector> -namespace mcld -{ +namespace mcld { class ExprToken; class Fragment; @@ -24,24 +24,23 @@ * \brief This class defines the interfaces to a rpn expression. */ -class RpnExpr -{ -public: +class RpnExpr { + public: typedef std::vector<ExprToken*> TokenQueue; typedef TokenQueue::const_iterator const_iterator; typedef TokenQueue::iterator iterator; -private: + private: friend class Chunk<RpnExpr, MCLD_SYMBOLS_PER_INPUT>; RpnExpr(); -public: + public: ~RpnExpr(); const_iterator begin() const { return m_TokenQueue.begin(); } - iterator begin() { return m_TokenQueue.begin(); } - const_iterator end() const { return m_TokenQueue.end(); } - iterator end() { return m_TokenQueue.end(); } + iterator begin() { return m_TokenQueue.begin(); } + const_iterator end() const { return m_TokenQueue.end(); } + iterator end() { return m_TokenQueue.end(); } size_t size() const { return m_TokenQueue.size(); } @@ -68,11 +67,10 @@ // buildHelperExpr - build the helper expr: `fragment' static RpnExpr* buildHelperExpr(Fragment& pFrag); -private: + private: TokenQueue m_TokenQueue; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_RPNEXPR_H_
diff --git a/include/mcld/Script/ScriptCommand.h b/include/mcld/Script/ScriptCommand.h index d670b01..f8d3a6e 100644 --- a/include/mcld/Script/ScriptCommand.h +++ b/include/mcld/Script/ScriptCommand.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_COMMAND_H -#define MCLD_SCRIPT_COMMAND_H +#ifndef MCLD_SCRIPT_SCRIPTCOMMAND_H_ +#define MCLD_SCRIPT_SCRIPTCOMMAND_H_ namespace mcld { @@ -16,29 +16,27 @@ /** \class ScriptCommand * \brief This class defines the interfaces to a script command. */ -class ScriptCommand -{ -public: +class ScriptCommand { + public: enum Kind { - ENTRY, - OUTPUT_FORMAT, - GROUP, - OUTPUT, - SEARCH_DIR, - OUTPUT_ARCH, ASSERT, ASSIGNMENT, - SECTIONS, + ENTRY, + GROUP, + INPUT, + INPUT_SECT_DESC, + OUTPUT, + OUTPUT_ARCH, + OUTPUT_FORMAT, + SEARCH_DIR, OUTPUT_SECT_DESC, - INPUT_SECT_DESC + SECTIONS }; -protected: - ScriptCommand(Kind pKind) - : m_Kind(pKind) - {} + protected: + explicit ScriptCommand(Kind pKind) : m_Kind(pKind) {} -public: + public: virtual ~ScriptCommand() = 0; virtual void dump() const = 0; @@ -47,11 +45,10 @@ Kind getKind() const { return m_Kind; } -private: + private: Kind m_Kind; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_SCRIPTCOMMAND_H_
diff --git a/include/mcld/Script/ScriptFile.h b/include/mcld/Script/ScriptFile.h index b54ba1f..dad2776 100644 --- a/include/mcld/Script/ScriptFile.h +++ b/include/mcld/Script/ScriptFile.h
@@ -6,40 +6,42 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_SCRIPTFILE_H -#define MCLD_SCRIPT_SCRIPTFILE_H +#ifndef MCLD_SCRIPT_SCRIPTFILE_H_ +#define MCLD_SCRIPT_SCRIPTFILE_H_ -#include <mcld/Script/Assignment.h> -#include <mcld/Script/OutputSectDesc.h> -#include <mcld/Script/InputSectDesc.h> -#include <vector> +#include "mcld/Script/Assignment.h" +#include "mcld/Script/InputSectDesc.h" +#include "mcld/Script/OutputSectDesc.h" + #include <string> +#include <vector> -namespace mcld -{ +namespace mcld { -class ScriptCommand; -class Input; -class InputTree; -class InputBuilder; +class ArchiveReader; +class DynObjReader; class GroupReader; +class Input; +class InputBuilder; +class InputTree; class LinkerConfig; -class RpnExpr; -class StringList; class Module; +class ObjectReader; +class ScriptCommand; +class StringList; +class RpnExpr; /** \class ScriptFile * \brief This class defines the interfaces to a linker script file. */ -class ScriptFile -{ -public: +class ScriptFile { + public: enum Kind { - LDScript, // -T - Expression, // --defsym - VersionScript, // --version-script - DynamicList, // --dynamic-list + LDScript, // -T + Expression, // --defsym + VersionScript, // --version-script + DynamicList, // --dynamic-list Unknown }; @@ -49,32 +51,32 @@ typedef CommandQueue::const_reference const_reference; typedef CommandQueue::reference reference; -public: + public: ScriptFile(Kind pKind, Input& pInput, InputBuilder& pBuilder); ~ScriptFile(); - const_iterator begin() const { return m_CommandQueue.begin(); } - iterator begin() { return m_CommandQueue.begin(); } - const_iterator end() const { return m_CommandQueue.end(); } - iterator end() { return m_CommandQueue.end(); } + const_iterator begin() const { return m_CommandQueue.begin(); } + iterator begin() { return m_CommandQueue.begin(); } + const_iterator end() const { return m_CommandQueue.end(); } + iterator end() { return m_CommandQueue.end(); } const_reference front() const { return m_CommandQueue.front(); } - reference front() { return m_CommandQueue.front(); } - const_reference back() const { return m_CommandQueue.back(); } - reference back() { return m_CommandQueue.back(); } + reference front() { return m_CommandQueue.front(); } + const_reference back() const { return m_CommandQueue.back(); } + reference back() { return m_CommandQueue.back(); } const Input& input() const { return m_Input; } - Input& input() { return m_Input; } + Input& input() { return m_Input; } size_t size() const { return m_CommandQueue.size(); } Kind getKind() const { return m_Kind; } const InputTree& inputs() const { return *m_pInputTree; } - InputTree& inputs() { return *m_pInputTree; } + InputTree& inputs() { return *m_pInputTree; } const std::string& name() const { return m_Name; } - std::string& name() { return m_Name; } + std::string& name() { return m_Name; } void dump() const; void activate(Module& pModule); @@ -89,6 +91,14 @@ const std::string& pBig, const std::string& pLittle); + /// INPUT(file, file, ...) + /// INPUT(file file ...) + void addInputCmd(StringList& pStringList, + ObjectReader& pObjectReader, + ArchiveReader& pArchiveReader, + DynObjReader& pDynObjReader, + const LinkerConfig& pConfig); + /// GROUP(file, file, ...) /// GROUP(file file ...) void addGroupCmd(StringList& pStringList, @@ -128,11 +138,11 @@ RpnExpr* createRpnExpr(); const RpnExpr* getCurrentRpnExpr() const { return m_pRpnExpr; } - RpnExpr* getCurrentRpnExpr() { return m_pRpnExpr; } + RpnExpr* getCurrentRpnExpr() { return m_pRpnExpr; } StringList* createStringList(); const StringList* getCurrentStringList() const { return m_pStringList; } - StringList* getCurrentStringList() { return m_pStringList; } + StringList* getCurrentStringList() { return m_pStringList; } void setAsNeeded(bool pEnable = true); bool asNeeded() const { return m_bAsNeeded; } @@ -141,7 +151,7 @@ static void clearParserStrPool(); -private: + private: Kind m_Kind; Input& m_Input; std::string m_Name; @@ -156,7 +166,6 @@ bool m_bAsNeeded; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_SCRIPTFILE_H_
diff --git a/include/mcld/Script/ScriptReader.h b/include/mcld/Script/ScriptReader.h index a3f91c4..a04b89f 100644 --- a/include/mcld/Script/ScriptReader.h +++ b/include/mcld/Script/ScriptReader.h
@@ -6,25 +6,30 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_SCRIPTREADER_H -#define MCLD_SCRIPT_SCRIPTREADER_H +#ifndef MCLD_SCRIPT_SCRIPTREADER_H_ +#define MCLD_SCRIPT_SCRIPTREADER_H_ -#include <mcld/LD/LDReader.h> +#include "mcld/LD/LDReader.h" namespace mcld { -class Module; -class ScriptFile; -class Input; +class ArchiveReader; +class DynObjReader; class GroupReader; +class Input; class LinkerConfig; class LinkerScript; +class Module; +class ObjectReader; +class ScriptFile; class TargetLDBackend; -class ScriptReader : public LDReader -{ -public: - ScriptReader(GroupReader& pGroupReader); +class ScriptReader : public LDReader { + public: + ScriptReader(ObjectReader& pObjectReader, + ArchiveReader& pArchiveReader, + DynObjReader& pDynObjReader, + GroupReader& pGroupReader); ~ScriptReader(); @@ -32,15 +37,15 @@ bool readScript(const LinkerConfig& pConfig, ScriptFile& pScriptFile); /// isMyFormat - bool isMyFormat(Input& pInput, bool &pContinue) const; + bool isMyFormat(Input& pInput, bool& pContinue) const; - GroupReader& getGroupReader() { return m_GroupReader; } - -private: + private: + ObjectReader& m_ObjectReader; + ArchiveReader& m_ArchiveReader; + DynObjReader& m_DynObjReader; GroupReader& m_GroupReader; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_SCRIPTREADER_H_
diff --git a/include/mcld/Script/ScriptScanner.h b/include/mcld/Script/ScriptScanner.h index 4cab6ec..4a572a1 100644 --- a/include/mcld/Script/ScriptScanner.h +++ b/include/mcld/Script/ScriptScanner.h
@@ -6,22 +6,22 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_SCRIPTSCANNER_H -#define MCLD_SCRIPT_SCRIPTSCANNER_H +#ifndef MCLD_SCRIPT_SCRIPTSCANNER_H_ +#define MCLD_SCRIPT_SCRIPTSCANNER_H_ #ifndef __FLEX_LEXER_H #include "FlexLexer.h" #endif #ifndef YY_DECL -#define YY_DECL \ - mcld::ScriptParser::token_type \ - mcld::ScriptScanner::lex(mcld::ScriptParser::semantic_type* yylval, \ - mcld::ScriptParser::location_type* yylloc, \ - const mcld::ScriptFile& pScriptFile) +#define YY_DECL \ + mcld::ScriptParser::token_type mcld::ScriptScanner::lex( \ + mcld::ScriptParser::semantic_type* yylval, \ + mcld::ScriptParser::location_type* yylloc, \ + const mcld::ScriptFile& pScriptFile) #endif -#include <mcld/Script/ScriptFile.h> +#include "mcld/Script/ScriptFile.h" #include "ScriptParser.h" #include <stack> @@ -30,10 +30,9 @@ /** \class ScriptScanner * */ -class ScriptScanner : public yyFlexLexer -{ -public: - ScriptScanner(std::istream* yyin = NULL, std::ostream* yyout = NULL); +class ScriptScanner : public yyFlexLexer { + public: + explicit ScriptScanner(std::istream* yyin = NULL, std::ostream* yyout = NULL); virtual ~ScriptScanner(); @@ -45,15 +44,14 @@ void popLexState(); -private: + private: void enterComments(ScriptParser::location_type& pLocation); -private: + private: ScriptFile::Kind m_Kind; std::stack<ScriptFile::Kind> m_StateStack; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_SCRIPTSCANNER_H_
diff --git a/include/mcld/Script/SearchDirCmd.h b/include/mcld/Script/SearchDirCmd.h index 3358b6e..ceb584b 100644 --- a/include/mcld/Script/SearchDirCmd.h +++ b/include/mcld/Script/SearchDirCmd.h
@@ -6,14 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_SEARCHDIRCMD_H -#define MCLD_SCRIPT_SEARCHDIRCMD_H +#ifndef MCLD_SCRIPT_SEARCHDIRCMD_H_ +#define MCLD_SCRIPT_SEARCHDIRCMD_H_ -#include <mcld/Script/ScriptCommand.h> +#include "mcld/Script/ScriptCommand.h" + #include <string> -namespace mcld -{ +namespace mcld { class Module; @@ -21,26 +21,23 @@ * \brief This class defines the interfaces to SEARCH_DIR command. */ -class SearchDirCmd : public ScriptCommand -{ -public: - SearchDirCmd(const std::string& pPath); +class SearchDirCmd : public ScriptCommand { + public: + explicit SearchDirCmd(const std::string& pPath); ~SearchDirCmd(); void dump() const; void activate(Module& pModule); - static bool classof(const ScriptCommand* pCmd) - { + static bool classof(const ScriptCommand* pCmd) { return pCmd->getKind() == ScriptCommand::SEARCH_DIR; } -private: + private: std::string m_Path; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_SEARCHDIRCMD_H_
diff --git a/include/mcld/Script/SectionsCmd.h b/include/mcld/Script/SectionsCmd.h index f64a841..93a55c2 100644 --- a/include/mcld/Script/SectionsCmd.h +++ b/include/mcld/Script/SectionsCmd.h
@@ -6,15 +6,16 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_SECTIONSCMD_H -#define MCLD_SCRIPT_SECTIONSCMD_H +#ifndef MCLD_SCRIPT_SECTIONSCMD_H_ +#define MCLD_SCRIPT_SECTIONSCMD_H_ -#include <mcld/Script/ScriptCommand.h> +#include "mcld/Script/ScriptCommand.h" + #include <llvm/Support/DataTypes.h> + #include <vector> -namespace mcld -{ +namespace mcld { class Module; @@ -22,28 +23,27 @@ * \brief This class defines the interfaces to SECTIONS command. */ -class SectionsCmd : public ScriptCommand -{ -public: +class SectionsCmd : public ScriptCommand { + public: typedef std::vector<ScriptCommand*> SectionCommands; typedef SectionCommands::const_iterator const_iterator; typedef SectionCommands::iterator iterator; typedef SectionCommands::const_reference const_reference; typedef SectionCommands::reference reference; -public: + public: SectionsCmd(); ~SectionsCmd(); - const_iterator begin() const { return m_SectionCommands.begin(); } - iterator begin() { return m_SectionCommands.begin(); } - const_iterator end() const { return m_SectionCommands.end(); } - iterator end() { return m_SectionCommands.end(); } + const_iterator begin() const { return m_SectionCommands.begin(); } + iterator begin() { return m_SectionCommands.begin(); } + const_iterator end() const { return m_SectionCommands.end(); } + iterator end() { return m_SectionCommands.end(); } const_reference front() const { return m_SectionCommands.front(); } - reference front() { return m_SectionCommands.front(); } - const_reference back() const { return m_SectionCommands.back(); } - reference back() { return m_SectionCommands.back(); } + reference front() { return m_SectionCommands.front(); } + const_reference back() const { return m_SectionCommands.back(); } + reference back() { return m_SectionCommands.back(); } size_t size() const { return m_SectionCommands.size(); } @@ -51,8 +51,7 @@ void dump() const; - static bool classof(const ScriptCommand* pCmd) - { + static bool classof(const ScriptCommand* pCmd) { return pCmd->getKind() == ScriptCommand::SECTIONS; } @@ -60,10 +59,10 @@ void push_back(ScriptCommand* pCommand); -private: + private: SectionCommands m_SectionCommands; }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_SCRIPT_SECTIONSCMD_H_
diff --git a/include/mcld/Script/StrToken.h b/include/mcld/Script/StrToken.h index 08aef06..2800367 100644 --- a/include/mcld/Script/StrToken.h +++ b/include/mcld/Script/StrToken.h
@@ -6,46 +6,40 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_STRTOKEN_H -#define MCLD_SCRIPT_STRTOKEN_H +#ifndef MCLD_SCRIPT_STRTOKEN_H_ +#define MCLD_SCRIPT_STRTOKEN_H_ -#include <mcld/Support/Allocators.h> -#include <mcld/Config/Config.h> +#include "mcld/Config/Config.h" +#include "mcld/Support/Allocators.h" + #include <string> -namespace mcld -{ +namespace mcld { /** \class StrToken * \brief This class defines the interfaces to a element in EXCLUDE_FILE list * or in Output Section Phdr, or be a base class of other str token. */ -class StrToken -{ -public: - enum Kind { - Unknown, - String, - Input, - Wildcard - }; +class StrToken { + public: + enum Kind { Unknown, String, Input, Wildcard }; -private: + private: friend class Chunk<StrToken, MCLD_SYMBOLS_PER_INPUT>; -protected: + + protected: StrToken(); StrToken(Kind pKind, const std::string& pString); -public: + public: virtual ~StrToken(); Kind kind() const { return m_Kind; } const std::string& name() const { return m_Name; } - static bool classof(const StrToken* pToken) - { + static bool classof(const StrToken* pToken) { return pToken->kind() == StrToken::String; } @@ -54,11 +48,11 @@ static void destroy(StrToken*& pToken); static void clear(); -private: + private: Kind m_Kind; std::string m_Name; }; -} // namepsace of mcld +} // namespace mcld -#endif +#endif // MCLD_SCRIPT_STRTOKEN_H_
diff --git a/include/mcld/Script/StringList.h b/include/mcld/Script/StringList.h index 76255d0..7c938b1 100644 --- a/include/mcld/Script/StringList.h +++ b/include/mcld/Script/StringList.h
@@ -6,15 +6,15 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_STRINGLIST_H -#define MCLD_SCRIPT_STRINGLIST_H +#ifndef MCLD_SCRIPT_STRINGLIST_H_ +#define MCLD_SCRIPT_STRINGLIST_H_ -#include <mcld/Config/Config.h> -#include <mcld/Support/Allocators.h> +#include "mcld/Config/Config.h" +#include "mcld/Support/Allocators.h" + #include <vector> -namespace mcld -{ +namespace mcld { class StrToken; @@ -22,31 +22,30 @@ * \brief This class defines the interfaces to StringList. */ -class StringList -{ -public: +class StringList { + public: typedef std::vector<StrToken*> Tokens; typedef Tokens::const_iterator const_iterator; typedef Tokens::iterator iterator; typedef Tokens::const_reference const_reference; typedef Tokens::reference reference; -private: + private: friend class Chunk<StringList, MCLD_SYMBOLS_PER_INPUT>; StringList(); -public: + public: ~StringList(); - const_iterator begin() const { return m_Tokens.begin(); } - iterator begin() { return m_Tokens.begin(); } - const_iterator end() const { return m_Tokens.end(); } - iterator end() { return m_Tokens.end(); } + const_iterator begin() const { return m_Tokens.begin(); } + iterator begin() { return m_Tokens.begin(); } + const_iterator end() const { return m_Tokens.end(); } + iterator end() { return m_Tokens.end(); } const_reference front() const { return m_Tokens.front(); } - reference front() { return m_Tokens.front(); } - const_reference back() const { return m_Tokens.back(); } - reference back() { return m_Tokens.back(); } + reference front() { return m_Tokens.front(); } + const_reference back() const { return m_Tokens.back(); } + reference back() { return m_Tokens.back(); } bool empty() const { return m_Tokens.empty(); } @@ -59,11 +58,10 @@ static void destroy(StringList*& pStringList); static void clear(); -private: + private: Tokens m_Tokens; }; -} // namepsace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_STRINGLIST_H_
diff --git a/include/mcld/Script/TernaryOp.h b/include/mcld/Script/TernaryOp.h index bf47bca..a837c14 100644 --- a/include/mcld/Script/TernaryOp.h +++ b/include/mcld/Script/TernaryOp.h
@@ -6,63 +6,58 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_TERNARYOP_H -#define MCLD_SCRIPT_TERNARYOP_H +#ifndef MCLD_SCRIPT_TERNARYOP_H_ +#define MCLD_SCRIPT_TERNARYOP_H_ -#include <mcld/Script/Operator.h> +#include "mcld/Script/Operator.h" + #include <cstddef> -namespace mcld -{ +namespace mcld { -class Operand; class IntOperand; class Module; +class Operand; class TargetLDBackend; /** \class TernaryOP * \brief This class defines the interfaces to an binary operator token. */ -template<Operator::Type TYPE> -class TernaryOp : public Operator -{ -private: +template <Operator::Type TYPE> +class TernaryOp : public Operator { + private: friend class Operator; - TernaryOp() - : Operator(Operator::TERNARY, TYPE) - { + TernaryOp() : Operator(Operator::TERNARY, TYPE) { m_pOperand[0] = m_pOperand[1] = m_pOperand[2] = NULL; } -public: - ~TernaryOp() - {} + public: + ~TernaryOp() {} IntOperand* eval(const Module& pModule, const TargetLDBackend& pBackend); - void appendOperand(Operand* pOperand) - { + void appendOperand(Operand* pOperand) { m_pOperand[m_Size++] = pOperand; if (m_Size == 3) m_Size = 0; } -private: + private: size_t m_Size; Operand* m_pOperand[3]; }; -template<> +template <> IntOperand* TernaryOp<Operator::TERNARY_IF>::eval(const Module&, const TargetLDBackend&); -template<> -IntOperand* -TernaryOp<Operator::DATA_SEGMENT_ALIGN>::eval(const Module&, - const TargetLDBackend&); +template <> +IntOperand* TernaryOp<Operator::DATA_SEGMENT_ALIGN>::eval( + const Module&, + const TargetLDBackend&); -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_SCRIPT_TERNARYOP_H_
diff --git a/include/mcld/Script/UnaryOp.h b/include/mcld/Script/UnaryOp.h index b7f69c6..922e192 100644 --- a/include/mcld/Script/UnaryOp.h +++ b/include/mcld/Script/UnaryOp.h
@@ -6,94 +6,86 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_UNARYOP_H -#define MCLD_SCRIPT_UNARYOP_H +#ifndef MCLD_SCRIPT_UNARYOP_H_ +#define MCLD_SCRIPT_UNARYOP_H_ -#include <mcld/Script/Operator.h> +#include "mcld/Script/Operator.h" + #include <cstddef> -namespace mcld -{ +namespace mcld { -class Operand; class IntOperand; class Module; +class Operand; class TargetLDBackend; /** \class UnaryOp * \brief This class defines the interfaces to an unary operator token. */ -template<Operator::Type TYPE> -class UnaryOp : public Operator -{ -private: +template <Operator::Type TYPE> +class UnaryOp : public Operator { + private: friend class Operator; - UnaryOp() - : Operator(Operator::UNARY, TYPE), m_pOperand(NULL) - {} + UnaryOp() : Operator(Operator::UNARY, TYPE), m_pOperand(NULL) {} -public: - ~UnaryOp() - {} + public: + ~UnaryOp() {} IntOperand* eval(const Module& pModule, const TargetLDBackend& pBackend); - void appendOperand(Operand* pOperand) - { - m_pOperand = pOperand; - } + void appendOperand(Operand* pOperand) { m_pOperand = pOperand; } -private: + private: Operand* m_pOperand; }; -template<> +template <> IntOperand* UnaryOp<Operator::UNARY_PLUS>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* UnaryOp<Operator::UNARY_MINUS>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* UnaryOp<Operator::LOGICAL_NOT>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* UnaryOp<Operator::BITWISE_NOT>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* UnaryOp<Operator::ABSOLUTE>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* UnaryOp<Operator::ADDR>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* UnaryOp<Operator::ALIGNOF>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* UnaryOp<Operator::DATA_SEGMENT_END>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* UnaryOp<Operator::DEFINED>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* UnaryOp<Operator::LENGTH>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* UnaryOp<Operator::LOADADDR>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* UnaryOp<Operator::NEXT>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* UnaryOp<Operator::ORIGIN>::eval(const Module&, const TargetLDBackend&); -template<> +template <> IntOperand* UnaryOp<Operator::SIZEOF>::eval(const Module&, const TargetLDBackend&); -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SCRIPT_UNARYOP_H_
diff --git a/include/mcld/Script/WildcardPattern.h b/include/mcld/Script/WildcardPattern.h index fe81ee3..75b1405 100644 --- a/include/mcld/Script/WildcardPattern.h +++ b/include/mcld/Script/WildcardPattern.h
@@ -6,24 +6,23 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SCRIPT_WILDCARDPATTERN_H -#define MCLD_SCRIPT_WILDCARDPATTERN_H +#ifndef MCLD_SCRIPT_WILDCARDPATTERN_H_ +#define MCLD_SCRIPT_WILDCARDPATTERN_H_ -#include <mcld/Script/StrToken.h> -#include <mcld/Support/Allocators.h> -#include <mcld/Config/Config.h> +#include "mcld/Config/Config.h" +#include "mcld/Script/StrToken.h" +#include "mcld/Support/Allocators.h" + #include <llvm/ADT/StringRef.h> -namespace mcld -{ +namespace mcld { /** \class WildcardPattern * \brief This class defines the interfaces to Input Section Wildcard Patterns */ -class WildcardPattern : public StrToken -{ -public: +class WildcardPattern : public StrToken { + public: enum SortPolicy { SORT_NONE, SORT_BY_NAME, @@ -33,12 +32,12 @@ SORT_BY_INIT_PRIORITY }; -private: + private: friend class Chunk<WildcardPattern, MCLD_SYMBOLS_PER_INPUT>; WildcardPattern(); WildcardPattern(const std::string& pPattern, SortPolicy pPolicy); -public: + public: ~WildcardPattern(); SortPolicy sortPolicy() const { return m_SortPolicy; } @@ -47,8 +46,7 @@ llvm::StringRef prefix() const; - static bool classof(const StrToken* pToken) - { + static bool classof(const StrToken* pToken) { return pToken->kind() == StrToken::Wildcard; } @@ -58,11 +56,11 @@ static void destroy(WildcardPattern*& pToken); static void clear(); -private: + private: SortPolicy m_SortPolicy; bool m_bIsPrefix; }; -} // namepsace of mcld +} // namespace mcld -#endif +#endif // MCLD_SCRIPT_WILDCARDPATTERN_H_
diff --git a/include/mcld/Support/Allocators.h b/include/mcld/Support/Allocators.h index bb95bd6..c66b77e 100644 --- a/include/mcld/Support/Allocators.h +++ b/include/mcld/Support/Allocators.h
@@ -1,4 +1,4 @@ -//===- Allocators.h ---------------------------------------------------------===// +//===- Allocators.h -------------------------------------------------------===// // // The MCLinker Project // @@ -6,10 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_ALLOCATORS_H -#define MCLD_SUPPORT_ALLOCATORS_H -#include <mcld/ADT/Uncopyable.h> -#include <mcld/ADT/TypeTraits.h> +#ifndef MCLD_SUPPORT_ALLOCATORS_H_ +#define MCLD_SUPPORT_ALLOCATORS_H_ +#include "mcld/ADT/TypeTraits.h" +#include "mcld/Support/Compiler.h" #include <cstddef> #include <cstdlib> @@ -21,44 +21,39 @@ * * @see LinearAllocator */ -template<typename DataType, size_t ChunkSize> -class Chunk -{ -public: +template <typename DataType, size_t ChunkSize> +class Chunk { + public: typedef DataType value_type; -public: - Chunk() - : next(0), bound(0) - { } + + public: + Chunk() : next(NULL), bound(0) {} static size_t size() { return ChunkSize; } - static void construct(value_type* pPtr) - { new (pPtr) value_type(); } + static void construct(value_type* pPtr) { new (pPtr) value_type(); } - static void construct(value_type* pPtr, const value_type& pValue) - { new (pPtr) value_type(pValue); } + static void construct(value_type* pPtr, const value_type& pValue) { + new (pPtr) value_type(pValue); + } - static void destroy(value_type* pPtr) - { } + static void destroy(value_type* pPtr) {} -public: + public: Chunk* next; size_t bound; DataType data[ChunkSize]; }; -template<typename DataType> -class Chunk<DataType, 0> -{ -public: +template <typename DataType> +class Chunk<DataType, 0> { + public: typedef DataType value_type; -public: - Chunk() - : next(0), bound(0) { - if (0 != m_Size) - data = (DataType*)malloc(sizeof(DataType)*m_Size); + public: + Chunk() : next(NULL), bound(0) { + if (m_Size != 0) + data = reinterpret_cast<DataType*>(malloc(sizeof(DataType) * m_Size)); else data = 0; } @@ -72,79 +67,69 @@ static void setSize(size_t pSize) { m_Size = pSize; } - static void construct(value_type* pPtr) - { new (pPtr) value_type(); } + static void construct(value_type* pPtr) { new (pPtr) value_type(); } - static void construct(value_type* pPtr, const value_type& pValue) - { new (pPtr) value_type(pValue); } + static void construct(value_type* pPtr, const value_type& pValue) { + new (pPtr) value_type(pValue); + } - static void destroy(value_type* pPtr) - { pPtr->~value_type(); } + static void destroy(value_type* pPtr) { pPtr->~value_type(); } -public: + public: Chunk* next; size_t bound; - DataType *data; + DataType* data; static size_t m_Size; }; -template<typename DataType> +template <typename DataType> size_t Chunk<DataType, 0>::m_Size = 0; -template<typename ChunkType> -class LinearAllocatorBase : private Uncopyable -{ -public: - typedef ChunkType chunk_type; - typedef typename ChunkType::value_type value_type; - typedef typename ChunkType::value_type* pointer; - typedef typename ChunkType::value_type& reference; +template <typename ChunkType> +class LinearAllocatorBase { + public: + typedef ChunkType chunk_type; + typedef typename ChunkType::value_type value_type; + typedef typename ChunkType::value_type* pointer; + typedef typename ChunkType::value_type& reference; typedef const typename ChunkType::value_type* const_pointer; typedef const typename ChunkType::value_type& const_reference; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef unsigned char byte_type; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef unsigned char byte_type; -protected: - LinearAllocatorBase() - : m_pRoot(0), - m_pCurrent(0), - m_AllocatedNum(0) { - } + protected: + LinearAllocatorBase() : m_pRoot(NULL), m_pCurrent(NULL), m_AllocatedNum(0) {} // LinearAllocatorBase does NOT mean to destroy the allocated memory. // If you want a memory allocator to release memory at destruction, please // use GCFactory series. - virtual ~LinearAllocatorBase() - { } + virtual ~LinearAllocatorBase() {} -public: - pointer address(reference X) const - { return &X; } + public: + pointer address(reference X) const { return &X; } - const_pointer address(const_reference X) const - { return &X; } + const_pointer address(const_reference X) const { return &X; } /// standard construct - constructing an object on the location pointed by // pPtr, and using its copy constructor to initialized its value to pValue. // // @param pPtr the address where the object to be constructed // @param pValue the value to be constructed - void construct(pointer pPtr, const_reference pValue) - { chunk_type::construct(pPtr, pValue); } + void construct(pointer pPtr, const_reference pValue) { + chunk_type::construct(pPtr, pValue); + } /// default construct - constructing an object on the location pointed by // pPtr, and using its default constructor to initialized its value to // pValue. // // @param pPtr the address where the object to be constructed - void construct(pointer pPtr) - { chunk_type::construct(pPtr); } + void construct(pointer pPtr) { chunk_type::construct(pPtr); } /// standard destroy - destroy data on arbitrary address // @para pPtr the address where the data to be destruected. - void destroy(pointer pPtr) - { chunk_type::destroy(pPtr); } + void destroy(pointer pPtr) { chunk_type::destroy(pPtr); } /// allocate - allocate N data in order. // - Disallow to allocate a chunk whose size is bigger than a chunk. @@ -152,7 +137,7 @@ // @param N the number of allocated data. // @return the start address of the allocated memory pointer allocate(size_type N) { - if (0 == N || N > chunk_type::size()) + if (N == 0 || N > chunk_type::size()) return 0; if (empty()) @@ -183,10 +168,8 @@ /// deallocate - deallocate N data from the pPtr // - if we can simply release some memory, then do it. Otherwise, do // nothing. - void deallocate(pointer &pPtr, size_type N) { - if (0 == N || - N > chunk_type::size() || - 0 == m_pCurrent->bound || + void deallocate(pointer& pPtr, size_type N) { + if (N == 0 || N > chunk_type::size() || m_pCurrent->bound == 0 || N >= m_pCurrent->bound) return; if (!isAvailable(pPtr)) @@ -196,8 +179,8 @@ } /// deallocate - clone function of deallocating one datum - void deallocate(pointer &pPtr) { - if (0 == m_pCurrent->bound) + void deallocate(pointer& pPtr) { + if (m_pCurrent->bound == 0) return; if (!isAvailable(pPtr)) return; @@ -208,7 +191,7 @@ /// isIn - whether the pPtr is in the current chunk? bool isIn(pointer pPtr) const { if (pPtr >= &(m_pCurrent->data[0]) && - pPtr <= &(m_pCurrent->data[chunk_type::size()-1])) + pPtr <= &(m_pCurrent->data[chunk_type::size() - 1])) return true; return false; } @@ -216,7 +199,7 @@ /// isIn - whether the pPtr is allocated, and can be constructed. bool isAvailable(pointer pPtr) const { if (pPtr >= &(m_pCurrent->data[m_pCurrent->bound]) && - pPtr <= &(m_pCurrent->data[chunk_type::size()-1])) + pPtr <= &(m_pCurrent->data[chunk_type::size() - 1])) return true; return false; } @@ -229,8 +212,8 @@ /// clear - clear all chunks void clear() { - chunk_type *cur = m_pRoot, *prev; - while (0 != cur) { + chunk_type* cur = m_pRoot, *prev; + while (cur != 0) { prev = cur; cur = cur->next; for (unsigned int idx = 0; idx != prev->bound; ++idx) @@ -241,32 +224,32 @@ } // ----- observers ----- // - bool empty() const { - return (0 == m_pRoot); - } + bool empty() const { return (m_pRoot == 0); } - size_type max_size() const - { return m_AllocatedNum; } + size_type max_size() const { return m_AllocatedNum; } -protected: + protected: inline void initialize() { m_pRoot = new chunk_type(); m_pCurrent = m_pRoot; m_AllocatedNum += chunk_type::size(); } - inline chunk_type *getNewChunk() { - chunk_type *result = new chunk_type(); + inline chunk_type* getNewChunk() { + chunk_type* result = new chunk_type(); m_pCurrent->next = result; m_pCurrent = result; m_AllocatedNum += chunk_type::size(); return result; } -protected: - chunk_type *m_pRoot; - chunk_type *m_pCurrent; - size_type m_AllocatedNum; + protected: + chunk_type* m_pRoot; + chunk_type* m_pCurrent; + size_type m_AllocatedNum; + + private: + DISALLOW_COPY_AND_ASSIGN(LinearAllocatorBase); }; /** \class LinearAllocator @@ -285,167 +268,145 @@ * template argument DataType is the DataType to be allocated * template argument ChunkSize is the number of bytes of a chunk */ -template<typename DataType, size_t ChunkSize> -class LinearAllocator : public LinearAllocatorBase<Chunk<DataType, ChunkSize> > -{ -public: - template<typename NewDataType> +template <typename DataType, size_t ChunkSize> +class LinearAllocator + : public LinearAllocatorBase<Chunk<DataType, ChunkSize> > { + public: + template <typename NewDataType> struct rebind { typedef LinearAllocator<NewDataType, ChunkSize> other; }; -public: - LinearAllocator() - : LinearAllocatorBase<Chunk<DataType, ChunkSize> >() { - } + public: + LinearAllocator() : LinearAllocatorBase<Chunk<DataType, ChunkSize> >() {} - virtual ~LinearAllocator() - { } + virtual ~LinearAllocator() {} }; -template<typename DataType> -class LinearAllocator<DataType, 0> : public LinearAllocatorBase<Chunk<DataType, 0> > -{ -public: - template<typename NewDataType> +template <typename DataType> +class LinearAllocator<DataType, 0> + : public LinearAllocatorBase<Chunk<DataType, 0> > { + public: + template <typename NewDataType> struct rebind { typedef LinearAllocator<NewDataType, 0> other; }; -public: + public: explicit LinearAllocator(size_t pNum) - : LinearAllocatorBase<Chunk<DataType, 0> >() { + : LinearAllocatorBase<Chunk<DataType, 0> >() { Chunk<DataType, 0>::setSize(pNum); } - virtual ~LinearAllocator() - { } + virtual ~LinearAllocator() {} }; -template<typename DataType> -class MallocAllocator -{ -public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef DataType* pointer; +template <typename DataType> +class MallocAllocator { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef DataType* pointer; typedef const DataType* const_pointer; - typedef DataType& reference; + typedef DataType& reference; typedef const DataType& const_reference; - typedef DataType value_type; + typedef DataType value_type; - template<typename OtherDataType> - struct rebind - { + template <typename OtherDataType> + struct rebind { typedef MallocAllocator<OtherDataType> other; }; -public: - MallocAllocator() throw() - { } + public: + MallocAllocator() throw() {} - MallocAllocator(const MallocAllocator&) throw() - { } + MallocAllocator(const MallocAllocator&) throw() {} - ~MallocAllocator() throw() - { } + ~MallocAllocator() throw() {} - pointer address(reference X) const - { return &X; } + pointer address(reference X) const { return &X; } - const_pointer address(const_reference X) const - { return &X; } + const_pointer address(const_reference X) const { return &X; } - pointer allocate(size_type pNumOfElements, const void* = 0) - { + pointer allocate(size_type pNumOfElements, const void* = 0) { return static_cast<DataType*>( - std::malloc(pNumOfElements*sizeof(DataType))); + std::malloc(pNumOfElements * sizeof(DataType))); } - void deallocate(pointer pObject, size_type) - { std::free(static_cast<void*>(pObject)); } + void deallocate(pointer pObject, size_type) { + std::free(static_cast<void*>(pObject)); + } - size_type max_size() const throw() - { return size_t(-1) / sizeof(DataType); } + size_type max_size() const throw() { return size_t(-1) / sizeof(DataType); } - void construct(pointer pObject, const DataType& pValue) - { ::new((void *)pObject) value_type(pValue); } + void construct(pointer pObject, const DataType& pValue) { + ::new (reinterpret_cast<void*>(pObject)) value_type(pValue); + } - void destroy(pointer pObject) - { pObject->~DataType(); } - + void destroy(pointer pObject) { pObject->~DataType(); } }; -template<> -class MallocAllocator<void> -{ -public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef void* pointer; +template <> +class MallocAllocator<void> { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef void* pointer; typedef const void* const_pointer; - typedef void* reference; + typedef void* reference; typedef const void* const_reference; - typedef void* value_type; + typedef void* value_type; - template<typename OtherDataType> - struct rebind - { + template <typename OtherDataType> + struct rebind { typedef MallocAllocator<OtherDataType> other; }; -public: - MallocAllocator() throw() - { } + public: + MallocAllocator() throw() {} - MallocAllocator(const MallocAllocator&) throw() - { } + MallocAllocator(const MallocAllocator&) throw() {} - ~MallocAllocator() throw() - { } + ~MallocAllocator() throw() {} - size_type max_size() const throw() - { return size_t(-1) / sizeof(void*); } + size_type max_size() const throw() { return size_t(-1) / sizeof(void*); } - pointer address(reference X) const - { return X; } + pointer address(reference X) const { return X; } - const_pointer address(const_reference X) const - { return X; } + const_pointer address(const_reference X) const { return X; } - template<typename DataType> + template <typename DataType> DataType* allocate(size_type pNumOfElements, const void* = 0) { return static_cast<DataType*>( - std::malloc(pNumOfElements*sizeof(DataType))); + std::malloc(pNumOfElements * sizeof(DataType))); } pointer allocate(size_type pNumOfElements, const void* = 0) { return std::malloc(pNumOfElements); } - template<typename DataType> - void deallocate(DataType* pObject, size_type) - { std::free(static_cast<void*>(pObject)); } + template <typename DataType> + void deallocate(DataType* pObject, size_type) { + std::free(static_cast<void*>(pObject)); + } - void deallocate(pointer pObject, size_type) - { std::free(pObject); } + void deallocate(pointer pObject, size_type) { std::free(pObject); } - template<typename DataType> - void construct(DataType* pObject, const DataType& pValue) - { /* do nothing */ } + template <typename DataType> + void construct(DataType* pObject, const DataType& pValue) { /* do nothing */ + } - void construct(pointer pObject, const_reference pValue) - { /* do nothing */ } + void construct(pointer pObject, const_reference pValue) { /* do nothing */ + } - template<typename DataType> - void destroy(DataType* pObject) - { /* do nothing */ } + template <typename DataType> + void destroy(DataType* pObject) { /* do nothing */ + } - void destroy(pointer pObject) - { /* do nothing */ } + void destroy(pointer pObject) { /* do nothing */ + } }; -} // namespace mcld +} // namespace mcld -#endif - +#endif // MCLD_SUPPORT_ALLOCATORS_H_
diff --git a/include/mcld/Support/CommandLine.h b/include/mcld/Support/CommandLine.h index 1801354..8c10b91 100644 --- a/include/mcld/Support/CommandLine.h +++ b/include/mcld/Support/CommandLine.h
@@ -6,10 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_COMMANDLINE_H -#define MCLD_SUPPORT_COMMANDLINE_H -#include <mcld/Support/FileSystem.h> -#include <mcld/MC/ZOption.h> +#ifndef MCLD_SUPPORT_COMMANDLINE_H_ +#define MCLD_SUPPORT_COMMANDLINE_H_ +#include "mcld/MC/ZOption.h" +#include "mcld/Support/FileSystem.h" #include <llvm/ADT/StringRef.h> #include <llvm/ADT/Triple.h> @@ -23,18 +23,17 @@ //===----------------------------------------------------------------------===// // SearchDirParser //===----------------------------------------------------------------------===// -class SearchDirParser : public llvm::cl::basic_parser<std::string> -{ -public: +class SearchDirParser : public llvm::cl::basic_parser<std::string> { + public: // parse - Return true on error. - bool parse(Option &pOption, + bool parse(Option& pOption, StringRef pArgName, StringRef pArg, - std::string &pValue); + std::string& pValue); - const char *getValueName() const { return "searchdir"; } + const char* getValueName() const { return "searchdir"; } - void printOptionDiff(const Option &pOption, + void printOptionDiff(const Option& pOption, StringRef pValue, OptVal pDefault, size_t pGlobalWidth) const; @@ -45,11 +44,10 @@ //===----------------------------------------------------------------------===// // FalseParser //===----------------------------------------------------------------------===// -class FalseParser : public cl::parser<bool> -{ -public: +class FalseParser : public cl::parser<bool> { + public: // parse - Return true on error. - bool parse(cl::Option &O, StringRef ArgName, StringRef Arg, bool &Val) { + bool parse(cl::Option& O, StringRef ArgName, StringRef Arg, bool& Val) { if (cl::parser<bool>::parse(O, ArgName, Arg, Val)) return false; Val = false; @@ -60,18 +58,17 @@ //===----------------------------------------------------------------------===// // parser<mcld::sys::fs::Path> //===----------------------------------------------------------------------===// -template<> -class parser<mcld::sys::fs::Path> : public basic_parser<mcld::sys::fs::Path> -{ -public: - bool parse(Option &O, +template <> +class parser<mcld::sys::fs::Path> : public basic_parser<mcld::sys::fs::Path> { + public: + bool parse(Option& O, StringRef ArgName, StringRef Arg, - mcld::sys::fs::Path &Val); + mcld::sys::fs::Path& Val); - virtual const char *getValueName() const { return "path"; } - void printOptionDiff(const Option &O, - const mcld::sys::fs::Path &V, + virtual const char* getValueName() const { return "path"; } + void printOptionDiff(const Option& O, + const mcld::sys::fs::Path& V, OptVal Default, size_t GlobalWidth) const; virtual void anchor(); @@ -80,22 +77,20 @@ //===----------------------------------------------------------------------===// // parser<mcld::ZOption> //===----------------------------------------------------------------------===// -template<> -class parser<mcld::ZOption> : public llvm::cl::basic_parser<mcld::ZOption> -{ -public: - bool parse(Option &O, StringRef ArgName, StringRef Arg, mcld::ZOption &Val); +template <> +class parser<mcld::ZOption> : public llvm::cl::basic_parser<mcld::ZOption> { + public: + bool parse(Option& O, StringRef ArgName, StringRef Arg, mcld::ZOption& Val); - virtual const char *getValueName() const { return "z-option"; } - void printOptionDiff(const Option &O, - const mcld::ZOption &V, + virtual const char* getValueName() const { return "z-option"; } + void printOptionDiff(const Option& O, + const mcld::ZOption& V, OptVal Default, size_t GlobalWidth) const; virtual void anchor(); }; -} // namespace of cl -} // namespace of llvm +} // namespace cl +} // namespace llvm -#endif - +#endif // MCLD_SUPPORT_COMMANDLINE_H_
diff --git a/include/mcld/Support/Compiler.h b/include/mcld/Support/Compiler.h new file mode 100644 index 0000000..9a0d738 --- /dev/null +++ b/include/mcld/Support/Compiler.h
@@ -0,0 +1,30 @@ +//===- Compiler.h ---------------------------------------------------------===// +// +// The MCLinker Project +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#ifndef MCLD_SUPPORT_COMPILER_H_ +#define MCLD_SUPPORT_COMPILER_H_ + +#include <llvm/Support/Compiler.h> + +// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions. It goes +// in the private: declarations in a class. +#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&) = delete; \ + void operator=(const TypeName&) = delete + +// A macro to disallow all the implicit constructors, namely the default +// constructor, copy constructor and operator= functions. +// +// This should be used in the private: declarations for a class that wants to +// prevent anyone from instantiating it. This is especially useful for classes +// containing only static methods. +#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ + TypeName() = delete; \ + DISALLOW_COPY_AND_ASSIGN(TypeName) + +#endif // MCLD_SUPPORT_COMPILER_H_
diff --git a/include/mcld/Support/Demangle.h b/include/mcld/Support/Demangle.h index b6f7412..6f671b9 100644 --- a/include/mcld/Support/Demangle.h +++ b/include/mcld/Support/Demangle.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_DEMANGLE_H -#define MCLD_SUPPORT_DEMANGLE_H +#ifndef MCLD_SUPPORT_DEMANGLE_H_ +#define MCLD_SUPPORT_DEMANGLE_H_ #include <string> @@ -17,6 +17,6 @@ bool isCtorOrDtor(const char* pName, size_t pLength); -} // namespace mcld +} // namespace mcld -#endif +#endif // MCLD_SUPPORT_DEMANGLE_H_
diff --git a/include/mcld/Support/Directory.h b/include/mcld/Support/Directory.h index 09b7221..00ba531 100644 --- a/include/mcld/Support/Directory.h +++ b/include/mcld/Support/Directory.h
@@ -6,17 +6,17 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_DIRECTORY_H -#define MCLD_SUPPORT_DIRECTORY_H +#ifndef MCLD_SUPPORT_DIRECTORY_H_ +#define MCLD_SUPPORT_DIRECTORY_H_ -#include <mcld/ADT/TypeTraits.h> -#include <mcld/Support/FileSystem.h> -#include <mcld/Support/Path.h> +#include "mcld/ADT/TypeTraits.h" +#include "mcld/Support/FileSystem.h" +#include "mcld/Support/Path.h" +#include "mcld/Support/PathCache.h" + #include <llvm/Support/Allocator.h> #include <cstddef> -#include "PathCache.h" - namespace mcld { namespace sys { namespace fs { @@ -28,18 +28,19 @@ * non-symbolic link status, and a FileStatus object for symbolic link * status. The FileStatus objects act as value caches. */ -class Directory -{ -friend mcld::sys::fs::PathCache::entry_type* detail::bring_one_into_cache(DirIterator& pIter); -friend void detail::open_dir(Directory& pDir); -friend void detail::close_dir(Directory& pDir); -private: +class Directory { + friend mcld::sys::fs::PathCache::entry_type* detail::bring_one_into_cache( + DirIterator& pIter); + friend void detail::open_dir(Directory& pDir); + friend void detail::close_dir(Directory& pDir); + + private: friend class DirIterator; -public: + public: typedef DirIterator iterator; -public: + public: /// default constructor Directory(); @@ -48,6 +49,10 @@ FileStatus st = FileStatus(), FileStatus symlink_st = FileStatus()); + explicit Directory(const char* pPath, + FileStatus st = FileStatus(), + FileStatus symlink_st = FileStatus()); + /// copy constructor /// when a copying construction happens, the cache is not copied. Directory(const Directory& pCopy); @@ -70,8 +75,7 @@ bool isGood() const; /// path - the path of the directory - const Path& path() const - { return m_Path; } + const Path& path() const { return m_Path; } FileStatus status() const; FileStatus symlinkStatus() const; @@ -82,7 +86,7 @@ iterator begin(); iterator end(); -protected: + protected: mcld::sys::fs::Path m_Path; mutable FileStatus m_FileStatus; mutable FileStatus m_SymLinkStatus; @@ -102,28 +106,28 @@ * * @see Directory */ -class DirIterator -{ -friend mcld::sys::fs::PathCache::entry_type* detail::bring_one_into_cache(DirIterator& pIter); -friend class Directory; -public: - typedef mcld::sys::fs::PathCache DirCache; +class DirIterator { + friend mcld::sys::fs::PathCache::entry_type* detail::bring_one_into_cache( + DirIterator& pIter); + friend class Directory; -public: - typedef Directory value_type; - typedef ConstTraits<Directory> const_traits; - typedef NonConstTraits<Directory> non_const_traits; - typedef std::input_iterator_tag iterator_category; - typedef size_t size_type; - typedef ptrdiff_t difference_type; + public: + typedef mcld::sys::fs::PathCache DirCache; -private: - explicit DirIterator(Directory* pParent, - const DirCache::iterator& pIter); + public: + typedef Directory value_type; + typedef ConstTraits<Directory> const_traits; + typedef NonConstTraits<Directory> non_const_traits; + typedef std::input_iterator_tag iterator_category; + typedef size_t size_type; + typedef ptrdiff_t difference_type; -public: + private: + explicit DirIterator(Directory* pParent, const DirCache::iterator& pIter); + + public: // Since StringMapIterator has no default constructor, we also have none. - DirIterator(const DirIterator &X); + DirIterator(const DirIterator& X); ~DirIterator(); DirIterator& operator=(const DirIterator& pCopy); @@ -138,14 +142,14 @@ bool operator==(const DirIterator& y) const; bool operator!=(const DirIterator& y) const; -private: - Directory* m_pParent; // get handler - DirCache::iterator m_Iter; // for full situation + private: + Directory* m_pParent; // get handler + DirCache::iterator m_Iter; // for full situation DirCache::entry_type* m_pEntry; }; -} // namespace of fs -} // namespace of sys -} // namespace of mcld +} // namespace fs +} // namespace sys +} // namespace mcld -#endif +#endif // MCLD_SUPPORT_DIRECTORY_H_
diff --git a/include/mcld/Support/ELF.h b/include/mcld/Support/ELF.h index 321c3c6..d1cdc0c 100644 --- a/include/mcld/Support/ELF.h +++ b/include/mcld/Support/ELF.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_ELF_H -#define MCLD_SUPPORT_ELF_H +#ifndef MCLD_SUPPORT_ELF_H_ +#define MCLD_SUPPORT_ELF_H_ namespace mcld { namespace ELF { @@ -18,17 +18,11 @@ // other sections of the same type. SHF_ORDERED = 0x40000000, - // This section is excluded from input of an executable or shared object. - // Ignore this flag if SHF_ALLOC is also set or if a relocation refers to - // the section - SHF_EXCLUDE = 0x80000000, - // Section with data that is GP relative addressable. SHF_MIPS_GPREL = 0x10000000 -}; // enum SHF +}; // enum SHF -} // namespace of ELF -} // namespace of mcld +} // namespace ELF +} // namespace mcld -#endif - +#endif // MCLD_SUPPORT_ELF_H_
diff --git a/include/mcld/Support/FileHandle.h b/include/mcld/Support/FileHandle.h index ecd335c..96467f1 100644 --- a/include/mcld/Support/FileHandle.h +++ b/include/mcld/Support/FileHandle.h
@@ -6,10 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_FILEHANDLE_H -#define MCLD_SUPPORT_FILEHANDLE_H -#include <mcld/Support/Path.h> -#include <mcld/ADT/Flags.h> +#ifndef MCLD_SUPPORT_FILEHANDLE_H_ +#define MCLD_SUPPORT_FILEHANDLE_H_ +#include "mcld/ADT/Flags.h" +#include "mcld/Support/Path.h" #include <errno.h> @@ -22,50 +22,46 @@ * Operators of FileHandle should neither throw exceptions nor call expressive * diagnostic output. */ -class FileHandle -{ -public: - enum IOState - { - GoodBit = 0, // no error - BadBit = 1L << 0, // error due to the inappropriate operation - EOFBit = 1L << 1, // reached End-Of-File - FailBit = 1L << 2, // internal logic fail - DeputedBit = 1L << 3, // the file descriptor is delegated +class FileHandle { + public: + enum IOState { + GoodBit = 0, // no error + BadBit = 1L << 0, // error due to the inappropriate operation + EOFBit = 1L << 1, // reached End-Of-File + FailBit = 1L << 2, // internal logic fail + DeputedBit = 1L << 3, // the file descriptor is delegated IOStateEnd = 1L << 16 }; - enum OpenModeEnum - { - NotOpen = 0x00, - ReadOnly = 0x01, + enum OpenModeEnum { + NotOpen = 0x00, + ReadOnly = 0x01, WriteOnly = 0x02, ReadWrite = ReadOnly | WriteOnly, - Append = 0x04, - Create = 0x08, - Truncate = 0x10, - Unknown = 0xFF + Append = 0x04, + Create = 0x08, + Truncate = 0x10, + Unknown = 0xFF }; typedef Flags<OpenModeEnum> OpenMode; - enum PermissionEnum - { - ReadOwner = 0x0400, - WriteOwner = 0x0200, - ExeOwner = 0x0100, - ReadGroup = 0x0040, - WriteGroup = 0x0020, - ExeGroup = 0x0010, - ReadOther = 0x0004, - WriteOther = 0x0002, - ExeOther = 0x0001, - System = 0xFFFF + enum PermissionEnum { + ReadOwner = 0x0400, + WriteOwner = 0x0200, + ExeOwner = 0x0100, + ReadGroup = 0x0040, + WriteGroup = 0x0020, + ExeGroup = 0x0010, + ReadOther = 0x0004, + WriteOther = 0x0002, + ExeOther = 0x0001, + System = 0xFFFF }; typedef Flags<PermissionEnum> Permission; -public: + public: FileHandle(); ~FileHandle(); @@ -73,11 +69,9 @@ /// open - open the file. /// @return if we meet any trouble during opening the file, return false. /// use rdstate() to see what happens. - bool open(const sys::fs::Path& pPath, - OpenMode pMode, - Permission pPerm = System); + bool open(const sys::fs::Path& pPath, OpenMode pMode, Permission pPerm); - bool delegate(int pFD, OpenMode pMode = Unknown); + bool delegate(int pFD, OpenModeEnum pMode = Unknown); bool close(); @@ -97,17 +91,13 @@ bool munmap(void* pMemBuffer, size_t pLength); // ----- observers ----- // - const sys::fs::Path& path() const - { return m_Path; } + const sys::fs::Path& path() const { return m_Path; } - size_t size() const - { return m_Size; } + size_t size() const { return m_Size; } - int handler() const - { return m_Handler; } + int handler() const { return m_Handler; } - uint16_t rdstate() const - { return m_State; } + uint16_t rdstate() const { return m_State; } bool isOpened() const; @@ -127,7 +117,7 @@ int error() const { return errno; } -private: + private: sys::fs::Path m_Path; int m_Handler; unsigned int m_Size; @@ -135,7 +125,6 @@ OpenMode m_OpenMode; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SUPPORT_FILEHANDLE_H_
diff --git a/include/mcld/Support/FileOutputBuffer.h b/include/mcld/Support/FileOutputBuffer.h index 6b48e14..afe670f 100644 --- a/include/mcld/Support/FileOutputBuffer.h +++ b/include/mcld/Support/FileOutputBuffer.h
@@ -6,13 +6,15 @@ // license. see license.txt for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_FILEOUTPUTBUFFER_H -#define MCLD_SUPPORT_FILEOUTPUTBUFFER_H +#ifndef MCLD_SUPPORT_FILEOUTPUTBUFFER_H_ +#define MCLD_SUPPORT_FILEOUTPUTBUFFER_H_ -#include <mcld/Support/MemoryRegion.h> +#include "mcld/Support/MemoryRegion.h" + #include <llvm/ADT/StringRef.h> #include <llvm/Support/DataTypes.h> #include <llvm/Support/FileSystem.h> + #include <system_error> namespace mcld { @@ -22,7 +24,7 @@ /// FileOutputBuffer - This interface is borrowed from llvm bassically, and we /// may use ostream to emit output later. class FileOutputBuffer { -public: + public: /// Factory method to create an OutputBuffer object which manages a read/write /// buffer of the specified size. When committed, the buffer will be written /// to the file at the specified path. @@ -32,18 +34,16 @@ /// Returns a pointer to the start of the buffer. uint8_t* getBufferStart() { - return (uint8_t*)m_pRegion->data(); + return reinterpret_cast<uint8_t*>(m_pRegion->data()); } /// Returns a pointer to the end of the buffer. uint8_t* getBufferEnd() { - return (uint8_t*)m_pRegion->data() + m_pRegion->size(); + return reinterpret_cast<uint8_t*>(m_pRegion->data()) + m_pRegion->size(); } /// Returns size of the buffer. - size_t getBufferSize() const { - return m_pRegion->size(); - } + size_t getBufferSize() const { return m_pRegion->size(); } MemoryRegion request(size_t pOffset, size_t pLength); @@ -52,9 +52,9 @@ ~FileOutputBuffer(); -private: - FileOutputBuffer(const FileOutputBuffer &); - FileOutputBuffer &operator=(const FileOutputBuffer &); + private: + FileOutputBuffer(const FileOutputBuffer&); + FileOutputBuffer& operator=(const FileOutputBuffer&); FileOutputBuffer(llvm::sys::fs::mapped_file_region* pRegion, FileHandle& pFileHandle); @@ -63,6 +63,6 @@ FileHandle& m_FileHandle; }; -} // namespace mcld +} // namespace mcld -#endif +#endif // MCLD_SUPPORT_FILEOUTPUTBUFFER_H_
diff --git a/include/mcld/Support/FileSystem.h b/include/mcld/Support/FileSystem.h index ba4edff..15b33f9 100644 --- a/include/mcld/Support/FileSystem.h +++ b/include/mcld/Support/FileSystem.h
@@ -10,23 +10,22 @@ // filesystem (v3), but modified to remove exception handling and the // path class. //===----------------------------------------------------------------------===// +#ifndef MCLD_SUPPORT_FILESYSTEM_H_ +#define MCLD_SUPPORT_FILESYSTEM_H_ -#ifndef MCLD_SUPPORT_FILESYSTEM_H -#define MCLD_SUPPORT_FILESYSTEM_H - +#include "mcld/Config/Config.h" #include "mcld/Support/PathCache.h" -#include <mcld/Config/Config.h> -#include <string> + #include <iosfwd> #include <locale> +#include <string> namespace mcld { namespace sys { namespace fs { -enum FileType -{ +enum FileType { StatusError, StatusUnknown = StatusError, FileNotFound, @@ -46,19 +45,16 @@ /** \class FileStatus * \brief FileStatus */ -class FileStatus -{ -public: - FileStatus() - : m_Value(StatusError) {} +class FileStatus { + public: + FileStatus() : m_Value(StatusError) {} - explicit FileStatus(FileType v) - : m_Value(v) {} + explicit FileStatus(FileType v) : m_Value(v) {} - void setType(FileType v) { m_Value = v; } - FileType type() const { return m_Value; } + void setType(FileType v) { m_Value = v; } + FileType type() const { return m_Value; } -private: + private: FileType m_Value; }; @@ -66,7 +62,7 @@ return rhs.type() == lhs.type(); } -inline bool operator!=(const FileStatus& rhs, const FileStatus& lhs ) { +inline bool operator!=(const FileStatus& rhs, const FileStatus& lhs) { return !(rhs == lhs); } @@ -74,8 +70,8 @@ class DirIterator; class Directory; -bool exists(const Path &pPath); -bool is_directory(const Path &pPath); +bool exists(const Path& pPath); +bool is_directory(const Path& pPath); namespace detail { @@ -100,14 +96,17 @@ ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset); ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset); int ftruncate(int pFD, size_t pLength); -void* mmap(void *pAddr, size_t pLen, - int pProt, int pFlags, int pFD, off_t pOffset); -int munmap(void *pAddr, size_t pLen); +void* mmap(void* pAddr, + size_t pLen, + int pProt, + int pFlags, + int pFD, + off_t pOffset); +int munmap(void* pAddr, size_t pLen); -} // namespace of detail -} // namespace of fs -} // namespace of sys -} // namespace of mcld +} // namespace detail +} // namespace fs +} // namespace sys +} // namespace mcld -#endif - +#endif // MCLD_SUPPORT_FILESYSTEM_H_
diff --git a/include/mcld/Support/GCFactory.h b/include/mcld/Support/GCFactory.h index 452f539..fd86cdd 100644 --- a/include/mcld/Support/GCFactory.h +++ b/include/mcld/Support/GCFactory.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_GCFACTORY_H -#define MCLD_SUPPORT_GCFACTORY_H +#ifndef MCLD_SUPPORT_GCFACTORY_H_ +#define MCLD_SUPPORT_GCFACTORY_H_ #include "mcld/ADT/TypeTraits.h" #include "mcld/Support/Allocators.h" @@ -15,24 +15,21 @@ #include <cstddef> #include <iterator> -namespace mcld -{ +namespace mcld { /** \class DataIteratorBase * \brief DataIteratorBase provides the basic functions of DataIterator * @see DataIterator */ -template<typename ChunkType> -struct DataIteratorBase -{ -public: +template <typename ChunkType> +struct DataIteratorBase { + public: ChunkType* m_pChunk; unsigned int m_Pos; -public: + public: DataIteratorBase(ChunkType* X, unsigned int pPos) - : m_pChunk(X), m_Pos(pPos) - { } + : m_pChunk(X), m_Pos(pPos) {} inline void advance() { ++m_Pos; @@ -44,55 +41,49 @@ } } - bool operator==(const DataIteratorBase& y) const - { return ((this->m_pChunk == y.m_pChunk) && (this->m_Pos == y.m_Pos)); } + bool operator==(const DataIteratorBase& y) const { + return ((this->m_pChunk == y.m_pChunk) && (this->m_Pos == y.m_Pos)); + } - bool operator!=(const DataIteratorBase& y) const - { return ((this->m_pChunk != y.m_pChunk) || (this->m_Pos != y.m_Pos)); } + bool operator!=(const DataIteratorBase& y) const { + return ((this->m_pChunk != y.m_pChunk) || (this->m_Pos != y.m_Pos)); + } }; /** \class DataIterator * \brief DataIterator provides STL compatible iterator for allocators */ -template<typename ChunkType, class Traits> -class DataIterator : public DataIteratorBase<ChunkType> -{ -public: - typedef typename ChunkType::value_type value_type; - typedef Traits traits; - typedef typename traits::pointer pointer; - typedef typename traits::reference reference; +template <typename ChunkType, class Traits> +class DataIterator : public DataIteratorBase<ChunkType> { + public: + typedef typename ChunkType::value_type value_type; + typedef Traits traits; + typedef typename traits::pointer pointer; + typedef typename traits::reference reference; typedef DataIterator<ChunkType, Traits> Self; - typedef DataIteratorBase<ChunkType> Base; + typedef DataIteratorBase<ChunkType> Base; - typedef typename traits::nonconst_traits nonconst_traits; + typedef typename traits::nonconst_traits nonconst_traits; typedef DataIterator<ChunkType, nonconst_traits> iterator; - typedef typename traits::const_traits const_traits; - typedef DataIterator<ChunkType, const_traits> const_iterator; - typedef std::forward_iterator_tag iterator_category; - typedef size_t size_type; - typedef ptrdiff_t difference_type; + typedef typename traits::const_traits const_traits; + typedef DataIterator<ChunkType, const_traits> const_iterator; + typedef std::forward_iterator_tag iterator_category; + typedef size_t size_type; + typedef ptrdiff_t difference_type; -public: - DataIterator() - : Base(0, 0) - { } + public: + DataIterator() : Base(NULL, 0) {} - DataIterator(ChunkType* pChunk, unsigned int pPos) - : Base(pChunk, pPos) - { } + DataIterator(ChunkType* pChunk, unsigned int pPos) : Base(pChunk, pPos) {} - DataIterator(const DataIterator& pCopy) - : Base(pCopy.m_pChunk, pCopy.m_Pos) - { } + DataIterator(const DataIterator& pCopy) : Base(pCopy.m_pChunk, pCopy.m_Pos) {} - ~DataIterator() - { } + ~DataIterator() {} // ----- operators ----- // reference operator*() { - if (0 == this->m_pChunk) - assert(0 && "data iterator goes to a invalid position"); + assert(this->m_pChunk != NULL && + "data iterator goes to a invalid position"); return this->m_pChunk->data[Base::m_Pos]; } @@ -108,39 +99,31 @@ } }; -template<typename Alloc> -class GCFactoryBase : public Alloc -{ -public: +template <typename Alloc> +class GCFactoryBase : public Alloc { + public: typedef DataIterator<typename Alloc::chunk_type, - NonConstTraits< - typename Alloc::value_type> > iterator; + NonConstTraits<typename Alloc::value_type> > iterator; typedef DataIterator<typename Alloc::chunk_type, - ConstTraits< - typename Alloc::value_type> > const_iterator; + ConstTraits<typename Alloc::value_type> > const_iterator; typedef typename Alloc::value_type value_type; - typedef typename Alloc::pointer pointer; - typedef typename Alloc::reference reference; - typedef typename Alloc::size_type size_type; + typedef typename Alloc::pointer pointer; + typedef typename Alloc::reference reference; + typedef typename Alloc::size_type size_type; -protected: - GCFactoryBase() - : Alloc(), m_NumAllocData(0) - { } + protected: + GCFactoryBase() : Alloc(), m_NumAllocData(0) {} - GCFactoryBase(size_t pNum) - : Alloc(pNum), m_NumAllocData(0) - { } + explicit GCFactoryBase(size_t pNum) : Alloc(pNum), m_NumAllocData(0) {} -public: - virtual ~GCFactoryBase() - { Alloc::clear(); } + public: + virtual ~GCFactoryBase() { Alloc::clear(); } // ----- modifiers ----- // value_type* allocate(size_t N) { value_type* result = Alloc::allocate(N); - if (0 != result) + if (result != NULL) m_NumAllocData += N; return result; } @@ -150,15 +133,15 @@ return Alloc::allocate(); } - void deallocate(pointer &pPtr, size_type N) { + void deallocate(pointer& pPtr, size_type N) { Alloc::deallocate(pPtr, N); - if (0 == pPtr) + if (pPtr == NULL) m_NumAllocData -= N; } - void deallocate(pointer &pPtr) { + void deallocate(pointer& pPtr) { Alloc::deallocate(pPtr); - if (0 == pPtr) + if (pPtr == NULL) --m_NumAllocData; } @@ -168,35 +151,30 @@ } // ----- iterators ----- // - iterator begin() - { return iterator(Alloc::m_pRoot, 0); } + iterator begin() { return iterator(Alloc::m_pRoot, 0); } - const_iterator begin() const - { return const_iterator(Alloc::m_pRoot, 0); } + const_iterator begin() const { return const_iterator(Alloc::m_pRoot, 0); } iterator end() { - return (0 == Alloc::m_pCurrent)? - begin(): - iterator(Alloc::m_pCurrent, Alloc::m_pCurrent->bound); + return (Alloc::m_pCurrent) == 0 + ? begin() + : iterator(Alloc::m_pCurrent, Alloc::m_pCurrent->bound); } const_iterator end() const { - return (0 == Alloc::m_pCurrent)? - begin(): - const_iterator(Alloc::m_pCurrent, Alloc::m_pCurrent->bound); + return (Alloc::m_pCurrent) == 0 + ? begin() + : const_iterator(Alloc::m_pCurrent, Alloc::m_pCurrent->bound); } // ----- observers ----- // - bool empty() const - { return Alloc::empty(); } + bool empty() const { return Alloc::empty(); } - unsigned int capacity() const - { return Alloc::max_size(); } + unsigned int capacity() const { return Alloc::max_size(); } - unsigned int size() const - { return m_NumAllocData; } + unsigned int size() const { return m_NumAllocData; } -protected: + protected: unsigned int m_NumAllocData; }; @@ -204,25 +182,20 @@ * \brief GCFactory provides a factory that guaratees to remove all allocated * data. */ -template<typename DataType, size_t ChunkSize> -class GCFactory : public GCFactoryBase<LinearAllocator<DataType, ChunkSize> > -{ -public: - GCFactory() - : GCFactoryBase<LinearAllocator<DataType, ChunkSize> >() - { } +template <typename DataType, size_t ChunkSize> +class GCFactory : public GCFactoryBase<LinearAllocator<DataType, ChunkSize> > { + public: + GCFactory() : GCFactoryBase<LinearAllocator<DataType, ChunkSize> >() {} }; -template<typename DataType> -class GCFactory<DataType, 0> : public GCFactoryBase<LinearAllocator<DataType, 0> > -{ -public: - GCFactory(size_t pNum) - : GCFactoryBase<LinearAllocator<DataType, 0> >(pNum) - { } +template <typename DataType> +class GCFactory<DataType, 0> + : public GCFactoryBase<LinearAllocator<DataType, 0> > { + public: + explicit GCFactory(size_t pNum) + : GCFactoryBase<LinearAllocator<DataType, 0> >(pNum) {} }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SUPPORT_GCFACTORY_H_
diff --git a/include/mcld/Support/GCFactoryListTraits.h b/include/mcld/Support/GCFactoryListTraits.h index 7a8871c..b8afe81 100644 --- a/include/mcld/Support/GCFactoryListTraits.h +++ b/include/mcld/Support/GCFactoryListTraits.h
@@ -6,11 +6,11 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_GCFACTORYLISTTRAITS_H -#define MCLD_SUPPORT_GCFACTORYLISTTRAITS_H +#ifndef MCLD_SUPPORT_GCFACTORYLISTTRAITS_H_ +#define MCLD_SUPPORT_GCFACTORYLISTTRAITS_H_ -#include <llvm/ADT/ilist_node.h> #include <llvm/ADT/ilist.h> +#include <llvm/ADT/ilist_node.h> #include <assert.h> @@ -20,44 +20,41 @@ * \brief GCFactoryListTraits provides trait class for llvm::iplist when * the nodes in the list is produced by GCFactory. */ -template<typename DataType> -class GCFactoryListTraits : public llvm::ilist_default_traits<DataType> -{ -private: - class SentinelNode : public DataType - { - public: - SentinelNode() { } +template <typename DataType> +class GCFactoryListTraits : public llvm::ilist_default_traits<DataType> { + private: + class SentinelNode : public DataType { + public: + SentinelNode() {} }; -public: + public: // override the traits provided in llvm::ilist_sentinel_traits since we've // defined our own sentinel. - DataType *createSentinel() const - { return reinterpret_cast<DataType*>(&mSentinel); } + DataType* createSentinel() const { + return reinterpret_cast<DataType*>(&mSentinel); + } - static void destroySentinel(DataType*) { } + static void destroySentinel(DataType* pData) {} - DataType *provideInitialHead() const - { return createSentinel(); } + DataType* provideInitialHead() const { return createSentinel(); } - DataType *ensureHead(DataType*) const - { return createSentinel(); } + DataType* ensureHead(DataType* pData) const { return createSentinel(); } - static void noteHead(DataType*, DataType*) { } + static void noteHead(DataType* pNew, DataType* pSentinel) {} // override the traits provided in llvm::ilist_node_traits since - static DataType *createNode(const DataType &V) { + static DataType* createNode(const DataType& V) { assert(false && "Only GCFactory knows how to create a node."); } - static void deleteNode(DataType *V) { + static void deleteNode(DataType* V) { // No action. GCFactory will handle it by itself. } -private: + private: mutable SentinelNode mSentinel; }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_SUPPORT_GCFACTORYLISTTRAITS_H_
diff --git a/include/mcld/Support/LEB128.h b/include/mcld/Support/LEB128.h index e90980f..2c6c1c8 100644 --- a/include/mcld/Support/LEB128.h +++ b/include/mcld/Support/LEB128.h
@@ -6,9 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// - -#ifndef MCLD_SUPPORT_LEB128_H -#define MCLD_SUPPORT_LEB128_H +#ifndef MCLD_SUPPORT_LEB128_H_ +#define MCLD_SUPPORT_LEB128_H_ #include <stdint.h> #include <sys/types.h> @@ -20,20 +19,20 @@ typedef unsigned char ByteType; /* Forward declarations */ -template<typename IntType> -size_t encode(ByteType *&pBuf, IntType pValue); +template <typename IntType> +size_t encode(ByteType*& pBuf, IntType pValue); -template<typename IntType> -IntType decode(const ByteType *pBuf, size_t &pSize); +template <typename IntType> +IntType decode(const ByteType* pBuf, size_t& pSize); -template<typename IntType> -IntType decode(const ByteType *&pBuf); +template <typename IntType> +IntType decode(const ByteType*& pBuf); /* * Given an integer, this function returns the number of bytes required to * encode it in ULEB128 format. */ -template<typename IntType> +template <typename IntType> size_t size(IntType pValue) { size_t size = 1; while (pValue > 0x80) { @@ -49,66 +48,66 @@ * given buffer pointer to the point just past the end of the write value and * return the number of bytes being written. */ -template<> -size_t encode<uint64_t>(ByteType *&pBuf, uint64_t pValue); +template <> +size_t encode<uint64_t>(ByteType*& pBuf, uint64_t pValue); -template<> -size_t encode<uint32_t>(ByteType *&pBuf, uint32_t pValue); +template <> +size_t encode<uint32_t>(ByteType*& pBuf, uint32_t pValue); /* * Encoding functions for signed LEB128. */ -template<> -size_t encode<int64_t>(ByteType *&pBuf, int64_t pValue); +template <> +size_t encode<int64_t>(ByteType*& pBuf, int64_t pValue); -template<> -size_t encode<int32_t>(ByteType *&pBuf, int32_t pValue); +template <> +size_t encode<int32_t>(ByteType*& pBuf, int32_t pValue); /* * Read an integer encoded in ULEB128 format from the given buffer. pSize will * contain the number of bytes used in the buffer to encode the returned * integer. */ -template<> -uint64_t decode<uint64_t>(const ByteType *pBuf, size_t &pSize); +template <> +uint64_t decode<uint64_t>(const ByteType* pBuf, size_t& pSize); /* * Read an integer encoded in ULEB128 format from the given buffer. Update the * given buffer pointer to the point just past the end of the read value. */ -template<> -uint64_t decode<uint64_t>(const ByteType *&pBuf); +template <> +uint64_t decode<uint64_t>(const ByteType*& pBuf); /* * Decoding functions for signed LEB128. */ -template<> -int64_t decode<int64_t>(const ByteType *pBuf, size_t &pSize); +template <> +int64_t decode<int64_t>(const ByteType* pBuf, size_t& pSize); -template<> -int64_t decode<int64_t>(const ByteType *&pBuf); +template <> +int64_t decode<int64_t>(const ByteType*& pBuf); /* * The functions below handle the signed byte stream. This helps the user to get * rid of annoying type conversions when using the LEB128 encoding/decoding APIs * defined above. */ -template<typename IntType> -size_t encode(char *&pBuf, IntType pValue) { +template <typename IntType> +size_t encode(char*& pBuf, IntType pValue) { return encode<IntType>(reinterpret_cast<ByteType*&>(pBuf), pValue); } -template<typename IntType> -IntType decode(const char *pBuf, size_t &pSize) { +template <typename IntType> +IntType decode(const char* pBuf, size_t& pSize) { return decode<IntType>(reinterpret_cast<const ByteType*>(pBuf), pSize); } -template<typename IntType> -IntType decode(const char *&pBuf) { +template <typename IntType> +IntType decode(const char*& pBuf) { return decode<IntType>(reinterpret_cast<const ByteType*&>(pBuf)); } -} // namespace of leb128 -} // namespace of mcld +} // namespace leb128 +} // namespace mcld -#endif +#endif // MCLD_SUPPORT_LEB128_H_
diff --git a/include/mcld/Support/MemoryArea.h b/include/mcld/Support/MemoryArea.h index 570e293..105b23a 100644 --- a/include/mcld/Support/MemoryArea.h +++ b/include/mcld/Support/MemoryArea.h
@@ -6,10 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_MEMORYAREA_H -#define MCLD_SUPPORT_MEMORYAREA_H +#ifndef MCLD_SUPPORT_MEMORYAREA_H_ +#define MCLD_SUPPORT_MEMORYAREA_H_ -#include <mcld/ADT/Uncopyable.h> +#include "mcld/Support/Compiler.h" #include <llvm/ADT/StringRef.h> #include <llvm/Support/MemoryBuffer.h> @@ -19,10 +19,10 @@ /** \class MemoryArea * \brief MemoryArea is used to manage input read-only memory space. */ -class MemoryArea : private Uncopyable -{ +class MemoryArea { friend class MemoryAreaFactory; -public: + + public: // constructor by file handler. // If the given file handler is read-only, client can not request a region // that out of the file size. @@ -39,10 +39,13 @@ size_t size() const; -private: + private: std::unique_ptr<llvm::MemoryBuffer> m_pMemoryBuffer; + + private: + DISALLOW_COPY_AND_ASSIGN(MemoryArea); }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_SUPPORT_MEMORYAREA_H_
diff --git a/include/mcld/Support/MemoryAreaFactory.h b/include/mcld/Support/MemoryAreaFactory.h index 8b6d879..348169b 100644 --- a/include/mcld/Support/MemoryAreaFactory.h +++ b/include/mcld/Support/MemoryAreaFactory.h
@@ -6,16 +6,16 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_MEMORYAREAFACTORY_H -#define MCLD_SUPPORT_MEMORYAREAFACTORY_H -#include <mcld/Support/GCFactory.h> -#include <mcld/Support/MemoryArea.h> -#include <mcld/Support/Path.h> -#include <mcld/Support/FileHandle.h> +#ifndef MCLD_SUPPORT_MEMORYAREAFACTORY_H_ +#define MCLD_SUPPORT_MEMORYAREAFACTORY_H_ +#include "mcld/Support/FileHandle.h" +#include "mcld/Support/GCFactory.h" +#include "mcld/Support/MemoryArea.h" +#include "mcld/Support/Path.h" + #include <llvm/ADT/StringMap.h> -namespace mcld -{ +namespace mcld { /** \class MemoryAreaFactory * \brief MemoryAreaFactory avoids creating duplicated MemoryAreas of the @@ -35,16 +35,14 @@ * * @see MemoryRegion */ -class MemoryAreaFactory : public GCFactory<MemoryArea, 0> -{ -public: +class MemoryAreaFactory : public GCFactory<MemoryArea, 0> { + public: explicit MemoryAreaFactory(size_t pNum); virtual ~MemoryAreaFactory(); // produce - create a MemoryArea and open its file. - MemoryArea* produce(const sys::fs::Path& pPath, - FileHandle::OpenMode pMode); + MemoryArea* produce(const sys::fs::Path& pPath, FileHandle::OpenMode pMode); // produce - create a MemoryArea and open its file. MemoryArea* produce(const sys::fs::Path& pPath, @@ -60,10 +58,11 @@ MemoryArea* produce(int pFD, FileHandle::OpenMode pMode); void destruct(MemoryArea* pArea); -private: + + private: llvm::StringMap<MemoryArea*> m_AreaMap; }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_SUPPORT_MEMORYAREAFACTORY_H_
diff --git a/include/mcld/Support/MemoryRegion.h b/include/mcld/Support/MemoryRegion.h index ff81a30..28205f1 100644 --- a/include/mcld/Support/MemoryRegion.h +++ b/include/mcld/Support/MemoryRegion.h
@@ -6,10 +6,11 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_MEMORYREGION_H -#define MCLD_SUPPORT_MEMORYREGION_H +#ifndef MCLD_SUPPORT_MEMORYREGION_H_ +#define MCLD_SUPPORT_MEMORYREGION_H_ -#include <mcld/ADT/TypeTraits.h> +#include "mcld/ADT/TypeTraits.h" + #include <llvm/ADT/ArrayRef.h> #include <llvm/Support/DataTypes.h> @@ -21,6 +22,6 @@ typedef llvm::ArrayRef<uint8_t> ConstMemoryRegion; typedef llvm::MutableArrayRef<uint8_t> MemoryRegion; -} // namespace mcld +} // namespace mcld -#endif +#endif // MCLD_SUPPORT_MEMORYREGION_H_
diff --git a/include/mcld/Support/MsgHandling.h b/include/mcld/Support/MsgHandling.h index 71d173e..5720ce5 100644 --- a/include/mcld/Support/MsgHandling.h +++ b/include/mcld/Support/MsgHandling.h
@@ -6,9 +6,9 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_MSGHANDLING_H -#define MCLD_SUPPORT_MSGHANDLING_H -#include <mcld/LD/MsgHandler.h> +#ifndef MCLD_SUPPORT_MSGHANDLING_H_ +#define MCLD_SUPPORT_MSGHANDLING_H_ +#include "mcld/LD/MsgHandler.h" namespace mcld { @@ -33,45 +33,37 @@ MsgHandler note(unsigned int pID); MsgHandler ignore(unsigned int pID); -} // namespace of mcld +} // namespace mcld //===----------------------------------------------------------------------===// // Inline functions //===----------------------------------------------------------------------===// -inline mcld::MsgHandler mcld::unreachable(unsigned int pID) -{ +inline mcld::MsgHandler mcld::unreachable(unsigned int pID) { return getDiagnosticEngine().report(pID, DiagnosticEngine::Unreachable); } -inline mcld::MsgHandler mcld::fatal(unsigned int pID) -{ +inline mcld::MsgHandler mcld::fatal(unsigned int pID) { return getDiagnosticEngine().report(pID, DiagnosticEngine::Fatal); } -inline mcld::MsgHandler mcld::error(unsigned int pID) -{ +inline mcld::MsgHandler mcld::error(unsigned int pID) { return getDiagnosticEngine().report(pID, DiagnosticEngine::Error); } -inline mcld::MsgHandler mcld::warning(unsigned int pID) -{ +inline mcld::MsgHandler mcld::warning(unsigned int pID) { return getDiagnosticEngine().report(pID, DiagnosticEngine::Warning); } -inline mcld::MsgHandler mcld::debug(unsigned int pID) -{ +inline mcld::MsgHandler mcld::debug(unsigned int pID) { return getDiagnosticEngine().report(pID, DiagnosticEngine::Debug); } -inline mcld::MsgHandler mcld::note(unsigned int pID) -{ +inline mcld::MsgHandler mcld::note(unsigned int pID) { return getDiagnosticEngine().report(pID, DiagnosticEngine::Note); } -inline mcld::MsgHandler mcld::ignore(unsigned int pID) -{ +inline mcld::MsgHandler mcld::ignore(unsigned int pID) { return getDiagnosticEngine().report(pID, DiagnosticEngine::Ignore); } -#endif - +#endif // MCLD_SUPPORT_MSGHANDLING_H_
diff --git a/include/mcld/Support/Path.h b/include/mcld/Support/Path.h index 9fdb95c..33f4705 100644 --- a/include/mcld/Support/Path.h +++ b/include/mcld/Support/Path.h
@@ -10,11 +10,12 @@ // filesystem (v3), but modified to remove exception handling and the // path class. //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_PATH_H -#define MCLD_SUPPORT_PATH_H +#ifndef MCLD_SUPPORT_PATH_H_ +#define MCLD_SUPPORT_PATH_H_ + +#include "mcld/Config/Config.h" #include <llvm/Support/raw_ostream.h> -#include <mcld/Config/Config.h> #include <iosfwd> #include <functional> @@ -22,8 +23,8 @@ #include <locale> namespace mcld { -namespace sys { -namespace fs { +namespace sys { +namespace fs { #if defined(MCLD_ON_WIN32) const char preferred_separator = '/'; @@ -40,29 +41,29 @@ * \brief Path provides an abstraction for the path to a file or directory in * the operating system's filesystem. */ -class Path -{ -public: - typedef char ValueType; - typedef std::string StringType; +class Path { + public: + typedef char ValueType; + typedef std::string StringType; -public: + public: Path(); - Path(const ValueType* s); - Path(const StringType &s); + explicit Path(const ValueType* s); + explicit Path(const StringType& s); Path(const Path& pCopy); virtual ~Path(); // ----- assignments ----- // template <class InputIterator> Path& assign(InputIterator begin, InputIterator end); - Path& assign(const StringType &s); + Path& assign(const StringType& s); Path& assign(const ValueType* s, unsigned int length); // ----- appends ----- // template <class InputIterator> Path& append(InputIterator begin, InputIterator end); Path& append(const Path& pPath); + Path& append(const StringType& pPath); // ----- observers ----- // bool empty() const; @@ -71,10 +72,9 @@ bool isFromPWD() const; const StringType& native() const { return m_PathName; } - StringType& native() { return m_PathName; } + StringType& native() { return m_PathName; } - const ValueType* c_str() const - { return m_PathName.c_str(); } + const ValueType* c_str() const { return m_PathName.c_str(); } // ----- decomposition ----- // Path parent_path() const; @@ -86,42 +86,41 @@ StringType generic_string() const; bool canonicalize(); -public: + public: StringType::size_type m_append_separator_if_needed(); void m_erase_redundant_separator(StringType::size_type sep_pos); -protected: + protected: StringType m_PathName; }; -bool operator==(const Path& pLHS,const Path& pRHS); -bool operator!=(const Path& pLHS,const Path& pRHS); +bool operator==(const Path& pLHS, const Path& pRHS); +bool operator!=(const Path& pLHS, const Path& pRHS); Path operator+(const Path& pLHS, const Path& pRHS); //===----------------------------------------------------------------------===// // Non-member Functions //===----------------------------------------------------------------------===// -bool exists(const Path &pPath); +bool exists(const Path& pPath); -bool is_directory(const Path &pPath); +bool is_directory(const Path& pPath); template <class Char, class Traits> -inline std::basic_ostream<Char, Traits>& -operator<<(std::basic_ostream<Char, Traits>& pOS, const Path& pPath) -{ +inline std::basic_ostream<Char, Traits>& operator<<( + std::basic_ostream<Char, Traits>& pOS, + const Path& pPath) { return pOS << pPath.native(); } template <class Char, class Traits> -inline std::basic_istream<Char, Traits>& -operator>>(std::basic_istream<Char, Traits>& pOS, Path& pPath) -{ +inline std::basic_istream<Char, Traits>& operator>>( + std::basic_istream<Char, Traits>& pOS, + Path& pPath) { return pOS >> pPath.native(); } -inline llvm::raw_ostream& -operator<<(llvm::raw_ostream& pOS, const Path& pPath) -{ +inline llvm::raw_ostream& operator<<(llvm::raw_ostream& pOS, + const Path& pPath) { return pOS << pPath.native(); } @@ -129,8 +128,7 @@ // class path member template implementation //===----------------------------------------------------------------------===// template <class InputIterator> -Path& Path::assign(InputIterator begin, InputIterator end) -{ +Path& Path::assign(InputIterator begin, InputIterator end) { m_PathName.clear(); if (begin != end) m_PathName.append<InputIterator>(begin, end); @@ -138,8 +136,7 @@ } template <class InputIterator> -Path& Path::append(InputIterator begin, InputIterator end) -{ +Path& Path::append(InputIterator begin, InputIterator end) { if (begin == end) return *this; StringType::size_type sep_pos(m_append_separator_if_needed()); @@ -149,28 +146,26 @@ return *this; } -} // namespace of fs -} // namespace of sys -} // namespace of mcld +} // namespace fs +} // namespace sys +} // namespace mcld //===----------------------------------------------------------------------===// // STL compatible functions //===----------------------------------------------------------------------===// namespace std { -template<> -struct less<mcld::sys::fs::Path> : public binary_function<mcld::sys::fs::Path, - mcld::sys::fs::Path, - bool> -{ - bool operator() (const mcld::sys::fs::Path& pX,const mcld::sys::fs::Path& pY) const { +template <> +struct less<mcld::sys::fs::Path> + : public binary_function<mcld::sys::fs::Path, mcld::sys::fs::Path, bool> { + bool operator()(const mcld::sys::fs::Path& pX, + const mcld::sys::fs::Path& pY) const { if (pX.generic_string().size() < pY.generic_string().size()) return true; return (pX.generic_string() < pY.generic_string()); } }; -} // namespace of std +} // namespace std -#endif - +#endif // MCLD_SUPPORT_PATH_H_
diff --git a/include/mcld/Support/PathCache.h b/include/mcld/Support/PathCache.h index aca49fb..8b61556 100644 --- a/include/mcld/Support/PathCache.h +++ b/include/mcld/Support/PathCache.h
@@ -6,29 +6,28 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_PATHCACHE_H -#define MCLD_SUPPORT_PATHCACHE_H +#ifndef MCLD_SUPPORT_PATHCACHE_H_ +#define MCLD_SUPPORT_PATHCACHE_H_ -#include <mcld/ADT/HashEntry.h> -#include <mcld/ADT/HashTable.h> -#include <mcld/ADT/StringHash.h> -#include <mcld/Support/Path.h> +#include "mcld/ADT/HashEntry.h" +#include "mcld/ADT/HashTable.h" +#include "mcld/ADT/StringHash.h" +#include "mcld/Support/Path.h" namespace mcld { -namespace sys { -namespace fs { +namespace sys { +namespace fs { -namespace { - typedef HashEntry<llvm::StringRef, - mcld::sys::fs::Path, - hash::StringCompare<llvm::StringRef> > HashEntryType; -} // anonymous namespace +typedef HashEntry<llvm::StringRef, + mcld::sys::fs::Path, + hash::StringCompare<llvm::StringRef> > HashEntryType; -typedef HashTable<HashEntryType, hash::StringHash<hash::BKDR>, EntryFactory<HashEntryType> > PathCache; +typedef HashTable<HashEntryType, + hash::StringHash<hash::DJB>, + EntryFactory<HashEntryType> > PathCache; -} // namespace of fs -} // namespace of sys -} // namespace of mcld +} // namespace fs +} // namespace sys +} // namespace mcld -#endif - +#endif // MCLD_SUPPORT_PATHCACHE_H_
diff --git a/include/mcld/Support/RealPath.h b/include/mcld/Support/RealPath.h index b630fd6..b5edc76 100644 --- a/include/mcld/Support/RealPath.h +++ b/include/mcld/Support/RealPath.h
@@ -6,64 +6,61 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_REALPATH_H -#define MCLD_SUPPORT_REALPATH_H +#ifndef MCLD_SUPPORT_REALPATH_H_ +#define MCLD_SUPPORT_REALPATH_H_ #include "mcld/Support/Path.h" + #include <string> namespace mcld { -namespace sys { -namespace fs { +namespace sys { +namespace fs { /** \class RealPath * \brief The canonicalized absolute pathname. * */ -class RealPath : public Path -{ -public: - typedef Path::ValueType ValueType; +class RealPath : public Path { + public: + typedef Path::ValueType ValueType; typedef Path::StringType StringType; -public: + public: RealPath(); - explicit RealPath(const ValueType* s ); - explicit RealPath(const StringType &s ); + explicit RealPath(const ValueType* s); + explicit RealPath(const StringType& s); explicit RealPath(const Path& pPath); ~RealPath(); RealPath& assign(const Path& pPath); -protected: + protected: void initialize(); }; -} // namespace of fs -} // namespace of sys -} // namespace of mcld +} // namespace fs +} // namespace sys +} // namespace mcld -//-------------------------------------------------------------------------// -// STL compatible functions // -//-------------------------------------------------------------------------// +//----------------------------------------------------------------------------// +// STL compatible functions // +//----------------------------------------------------------------------------// namespace std { -template<> -struct less<mcld::sys::fs::RealPath> : public binary_function< - mcld::sys::fs::RealPath, - mcld::sys::fs::RealPath, - bool> -{ - bool operator() (const mcld::sys::fs::RealPath& pX, - const mcld::sys::fs::RealPath& pY) const { +template <> +struct less<mcld::sys::fs::RealPath> + : public binary_function<mcld::sys::fs::RealPath, + mcld::sys::fs::RealPath, + bool> { + bool operator()(const mcld::sys::fs::RealPath& pX, + const mcld::sys::fs::RealPath& pY) const { if (pX.native().size() < pY.native().size()) return true; return (pX.native() < pY.native()); } }; -} // namespace of std +} // namespace std - -#endif - +#endif // MCLD_SUPPORT_REALPATH_H_
diff --git a/include/mcld/Support/SystemUtils.h b/include/mcld/Support/SystemUtils.h index 7057110..4502e20 100644 --- a/include/mcld/Support/SystemUtils.h +++ b/include/mcld/Support/SystemUtils.h
@@ -6,11 +6,13 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_SYSTEMUTILS_H -#define MCLD_SUPPORT_SYSTEMUTILS_H +#ifndef MCLD_SUPPORT_SYSTEMUTILS_H_ +#define MCLD_SUPPORT_SYSTEMUTILS_H_ + +#include "mcld/Config/Config.h" #include <llvm/Support/DataTypes.h> -#include <mcld/Config/Config.h> + #include <string> namespace mcld { @@ -22,7 +24,7 @@ /** \fn strerror * \brief system error message */ -char *strerror(int pErrnum); +char* strerror(int pErrnum); std::string getDefaultTargetTriple(); @@ -34,8 +36,7 @@ /// SetRandomSeed - set the initial seed value for future calls to random(). void SetRandomSeed(unsigned pSeed); -} // namespace of sys -} // namespace of mcld +} // namespace sys +} // namespace mcld -#endif - +#endif // MCLD_SUPPORT_SYSTEMUTILS_H_
diff --git a/include/mcld/Support/Target.h b/include/mcld/Support/Target.h index 021fc2e..703dc82 100644 --- a/include/mcld/Support/Target.h +++ b/include/mcld/Support/Target.h
@@ -6,16 +6,15 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_TARGET_H -#define MCLD_SUPPORT_TARGET_H +#ifndef MCLD_SUPPORT_TARGET_H_ +#define MCLD_SUPPORT_TARGET_H_ #include <string> -#include <list> namespace llvm { class Target; class Triple; class TargetMachine; -} // namespace of llvm +} // namespace llvm namespace mcld { @@ -32,32 +31,31 @@ /** \class Target * \brief Target collects target specific information */ -class Target -{ +class Target { friend class mcld::MCLDTargetMachine; friend class mcld::TargetRegistry; -public: + public: typedef unsigned int (*TripleMatchQualityFnTy)(const llvm::Triple& pTriple); - typedef MCLDTargetMachine *(*TargetMachineCtorTy)(const llvm::Target &, - const mcld::Target &, - llvm::TargetMachine &, + typedef MCLDTargetMachine* (*TargetMachineCtorTy)(const llvm::Target&, + const mcld::Target&, + llvm::TargetMachine&, const std::string&); - typedef MCLinker *(*MCLinkerCtorTy)(const std::string& pTriple, + typedef MCLinker* (*MCLinkerCtorTy)(const std::string& pTriple, LinkerConfig&, Module&, FileHandle& pFileHandle); typedef bool (*EmulationFnTy)(LinkerScript&, LinkerConfig&); - typedef TargetLDBackend *(*TargetLDBackendCtorTy)(const LinkerConfig&); + typedef TargetLDBackend* (*TargetLDBackendCtorTy)(const LinkerConfig&); - typedef DiagnosticLineInfo *(*DiagnosticLineInfoCtorTy)(const mcld::Target&, + typedef DiagnosticLineInfo* (*DiagnosticLineInfoCtorTy)(const mcld::Target&, const std::string&); -public: + public: Target(); /// getName - get the target name @@ -71,7 +69,7 @@ llvm::TargetMachine& pTM) const; /// createMCLinker - create target-specific MCLinker - MCLinker *createMCLinker(const std::string &pTriple, + MCLinker* createMCLinker(const std::string& pTriple, LinkerConfig& pConfig, Module& pModule, FileHandle& pFileHandle) const; @@ -84,10 +82,11 @@ TargetLDBackend* createLDBackend(const LinkerConfig& pConfig) const; /// createDiagnosticLineInfo - create target-specific DiagnosticLineInfo - DiagnosticLineInfo* createDiagnosticLineInfo(const mcld::Target& pTarget, - const std::string& pTriple) const; + DiagnosticLineInfo* createDiagnosticLineInfo( + const mcld::Target& pTarget, + const std::string& pTriple) const; -private: + private: /// Name - The target name const char* Name; @@ -99,7 +98,6 @@ DiagnosticLineInfoCtorTy DiagnosticLineInfoCtorFn; }; -} //end namespace mcld +} // namespace mcld -#endif - +#endif // MCLD_SUPPORT_TARGET_H_
diff --git a/include/mcld/Support/TargetRegistry.h b/include/mcld/Support/TargetRegistry.h index 1ae6245..c76ff74 100644 --- a/include/mcld/Support/TargetRegistry.h +++ b/include/mcld/Support/TargetRegistry.h
@@ -6,36 +6,36 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_TARGETREGISTRY_H -#define MCLD_SUPPORT_TARGETREGISTRY_H -#include <mcld/Support/Target.h> +#ifndef MCLD_SUPPORT_TARGETREGISTRY_H_ +#define MCLD_SUPPORT_TARGETREGISTRY_H_ +#include "mcld/Support/Target.h" + #include <llvm/ADT/Triple.h> -#include <string> #include <list> +#include <string> namespace llvm { class TargetMachine; class MCCodeEmitter; class MCContext; class AsmPrinter; -} // namespace of llvm +} // namespace llvm namespace mcld { /** \class TargetRegistry * \brief TargetRegistry is an object adapter of llvm::TargetRegistry */ -class TargetRegistry -{ -public: +class TargetRegistry { + public: typedef std::list<mcld::Target*> TargetListTy; typedef TargetListTy::iterator iterator; -private: + private: static TargetListTy s_TargetList; -public: + public: static iterator begin() { return s_TargetList.begin(); } static iterator end() { return s_TargetList.end(); } @@ -54,36 +54,13 @@ const char* pName, Target::TripleMatchQualityFnTy pQualityFn); - /// RegisterTargetMachine - Register a TargetMachine implementation for the - /// given target. - /// - /// @param T - The target being registered. - /// @param Fn - A function to construct a TargetMachine for the target. - static void RegisterTargetMachine(mcld::Target &T, mcld::Target::TargetMachineCtorTy Fn) - { - // Ignore duplicate registration. - if (!T.TargetMachineCtorFn) - T.TargetMachineCtorFn = Fn; - } - - /// RegisterMCLinker - Register a MCLinker implementation for the given - /// target. - /// - /// @param T - the target being registered - /// @param Fn - A function to create MCLinker for the target - static void RegisterMCLinker(mcld::Target &T, mcld::Target::MCLinkerCtorTy Fn) - { - if (!T.MCLinkerCtorFn) - T.MCLinkerCtorFn = Fn; - } - /// RegisterEmulation - Register a emulation function for the target. /// target. /// /// @param T - the target being registered /// @param Fn - A emulation function - static void RegisterEmulation(mcld::Target &T, mcld::Target::EmulationFnTy Fn) - { + static void RegisterEmulation(mcld::Target& T, + mcld::Target::EmulationFnTy Fn) { if (!T.EmulationFn) T.EmulationFn = Fn; } @@ -93,8 +70,8 @@ /// /// @param T - The target being registered /// @param Fn - A function to create TargetLDBackend for the target - static void RegisterTargetLDBackend(mcld::Target &T, mcld::Target::TargetLDBackendCtorTy Fn) - { + static void RegisterTargetLDBackend(mcld::Target& T, + mcld::Target::TargetLDBackendCtorTy Fn) { if (!T.TargetLDBackendCtorFn) T.TargetLDBackendCtorFn = Fn; } @@ -104,10 +81,9 @@ /// /// @param T - The target being registered /// @param Fn - A function to create DiagnosticLineInfo for the target - static void - RegisterDiagnosticLineInfo(mcld::Target &T, - mcld::Target::DiagnosticLineInfoCtorTy Fn) - { + static void RegisterDiagnosticLineInfo( + mcld::Target& T, + mcld::Target::DiagnosticLineInfoCtorTy Fn) { if (!T.DiagnosticLineInfoCtorFn) T.DiagnosticLineInfoCtorFn = Fn; } @@ -116,7 +92,7 @@ /// /// @param Triple - The Triple string /// @param Error - The returned error message - static const mcld::Target *lookupTarget(const std::string& pTriple, + static const mcld::Target* lookupTarget(const std::string& pTriple, std::string& pError); /// lookupTarget - Look up MCLinker target by an architecture name @@ -127,9 +103,9 @@ /// @param pArch - The architecture name /// @param pTriple - The target triple /// @param pError - The returned error message - static const mcld::Target *lookupTarget(const std::string& pArchName, + static const mcld::Target* lookupTarget(const std::string& pArchName, llvm::Triple& pTriple, - std::string &Error); + std::string& Error); }; /// RegisterTarget - Helper function for registering a target, for use in the @@ -140,15 +116,14 @@ /// extern "C" void MCLDInitializeFooTargetInfo() { /// RegisterTarget<llvm::Foo> X(TheFooTarget, "foo", "Foo description"); /// } -template<llvm::Triple::ArchType TargetArchType = llvm::Triple::UnknownArch> -struct RegisterTarget -{ -public: - RegisterTarget(mcld::Target &pTarget, const char* pName) { +template <llvm::Triple::ArchType TargetArchType = llvm::Triple::UnknownArch> +struct RegisterTarget { + public: + RegisterTarget(mcld::Target& pTarget, const char* pName) { // if we've registered one, then return immediately. TargetRegistry::iterator target, ie = TargetRegistry::end(); for (target = TargetRegistry::begin(); target != ie; ++target) { - if (0 == strcmp((*target)->name(), pName)) + if (strcmp((*target)->name(), pName) == 0) return; } @@ -162,31 +137,6 @@ } }; -/// RegisterTargetMachine - Helper template for registering a target machine -/// implementation, for use in the target machine initialization -/// function. Usage: -/// -/// extern "C" void MCLDInitializeFooTarget() { -/// extern mcld::Target TheFooTarget; -/// RegisterTargetMachine<mcld::FooTargetMachine> X(TheFooTarget); -/// } -template<class TargetMachineImpl> -struct RegisterTargetMachine -{ - RegisterTargetMachine(mcld::Target &T) { - TargetRegistry::RegisterTargetMachine(T, &Allocator); - } +} // namespace mcld -private: - static MCLDTargetMachine *Allocator(const llvm::Target& pLLVMTarget, - const mcld::Target& pMCLDTarget, - llvm::TargetMachine& pTM, - const std::string& pTriple) { - return new TargetMachineImpl(pTM, pLLVMTarget, pMCLDTarget, pTriple); - } -}; - -} //end namespace mcld - -#endif - +#endif // MCLD_SUPPORT_TARGETREGISTRY_H_
diff --git a/include/mcld/Support/TargetSelect.h b/include/mcld/Support/TargetSelect.h index 32e568b..96bd510 100644 --- a/include/mcld/Support/TargetSelect.h +++ b/include/mcld/Support/TargetSelect.h
@@ -6,94 +6,69 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_TARGETSELECT_H -#define MCLD_SUPPORT_TARGETSELECT_H +#ifndef MCLD_SUPPORT_TARGETSELECT_H_ +#define MCLD_SUPPORT_TARGETSELECT_H_ extern "C" { - // Declare all of the target-initialization functions that are available. +// Declare all of the target-initialization functions that are available. #define MCLD_TARGET(TargetName) void MCLDInitialize##TargetName##LDTargetInfo(); -#include "mcld/Config/Targets.def" +#include "mcld/Config/Targets.def" // NOLINT [build/include] [4] - // Declare all of the target-dependent functions that are available. -#define MCLD_TARGET(TargetName) void MCLDInitialize##TargetName##LDTarget(); -#include "mcld/Config/Targets.def" - - // Declare all of the target-depedent linker information -#define MCLD_LINKER(TargetName) void MCLDInitialize##TargetName##LDInfo(); -#include "mcld/Config/Linkers.def" - - // Declare all of the available linker environment. -#define MCLD_LINKER(TargetName) void MCLDInitialize##TargetName##MCLinker(); -#include "mcld/Config/Linkers.def" - - // Declare all of the available emulators. +// Declare all of the available emulators. #define MCLD_TARGET(TargetName) void MCLDInitialize##TargetName##Emulation(); -#include "mcld/Config/Targets.def" +#include "mcld/Config/Targets.def" // NOLINT [build/include] [4] - // Declare all of the available target-specific linker +// Declare all of the available target-specific linker #define MCLD_LINKER(TargetName) void MCLDInitialize##TargetName##LDBackend(); -#include "mcld/Config/Linkers.def" +#include "mcld/Config/Linkers.def" // NOLINT [build/include] [4] - // Declare all of the available target-specific diagnostic line infomation -#define MCLD_LINKER(TargetName) void MCLDInitialize##TargetName##DiagnosticLineInfo(); -#include "mcld/Config/Linkers.def" +// Declare all of the available target-specific diagnostic line infomation +#define MCLD_LINKER(TargetName) \ + void MCLDInitialize##TargetName##DiagnosticLineInfo(); +#include "mcld/Config/Linkers.def" // NOLINT [build/include] [4] -} // extern "C" +} // extern "C" -namespace mcld -{ - /// InitializeAllTargetInfos - The main program should call this function if - /// it wants access to all available targets that MCLD is configured to - /// support, to make them available via the TargetRegistry. - /// - /// It is legal for a client to make multiple calls to this function. - inline void InitializeAllTargetInfos() { +namespace mcld { +/// InitializeAllTargetInfos - The main program should call this function if +/// it wants access to all available targets that MCLD is configured to +/// support, to make them available via the TargetRegistry. +/// +/// It is legal for a client to make multiple calls to this function. +inline void InitializeAllTargetInfos() { #define MCLD_TARGET(TargetName) MCLDInitialize##TargetName##LDTargetInfo(); -#include "mcld/Config/Targets.def" - } +#include "mcld/Config/Targets.def" // NOLINT [build/include] [4] +} - /// InitializeAllTargets - The main program should call this function if it - /// wants access to all available target machines that MCLD is configured to - /// support, to make them available via the TargetRegistry. - /// - /// It is legal for a client to make multiple calls to this function. - inline void InitializeAllTargets() { - mcld::InitializeAllTargetInfos(); +/// InitializeAllTargets - The main program should call this function if it +/// wants access to all available target machines that MCLD is configured to +/// support, to make them available via the TargetRegistry. +/// +/// It is legal for a client to make multiple calls to this function. +inline void InitializeAllTargets() { + mcld::InitializeAllTargetInfos(); #define MCLD_TARGET(TargetName) MCLDInitialize##TargetName##LDBackend(); -#include "mcld/Config/Targets.def" - } +#include "mcld/Config/Targets.def" // NOLINT [build/include] [4] +} - /// InitializeAllEmulations - The main program should call this function if - /// it wants all emulations to be configured to support. This function makes - /// all emulations available via the TargetRegistry. - inline void InitializeAllEmulations() { +/// InitializeAllEmulations - The main program should call this function if +/// it wants all emulations to be configured to support. This function makes +/// all emulations available via the TargetRegistry. +inline void InitializeAllEmulations() { #define MCLD_TARGET(TargetName) MCLDInitialize##TargetName##Emulation(); -#include "mcld/Config/Targets.def" - } +#include "mcld/Config/Targets.def" // NOLINT [build/include] [4] +} - /// InitializeAllLinkers - The main program should call this function if it - /// wants all linkers that is configured to support, to make them - /// available via the TargetRegistry. - /// - /// It is legal for a client to make multiple calls to this function. - inline void InitializeAllLinkers() { -#define MCLD_TARGET(TargetName) MCLDInitialize##TargetName##LDTarget(); -#include "mcld/Config/Targets.def" +/// InitializeMsgHandler - The main program should call this function if it +/// wants to print linker-specific messages. To make them available via the +/// TargetRegistry. +inline void InitializeAllDiagnostics() { +#define MCLD_LINKER(TargetName) \ + MCLDInitialize##TargetName##DiagnosticLineInfo(); +#include "mcld/Config/Linkers.def" // NOLINT [build/include] [4] +} -#define MCLD_LINKER(TargetName) MCLDInitialize##TargetName##MCLinker(); -#include "mcld/Config/Linkers.def" - } +} // namespace mcld - /// InitializeMsgHandler - The main program should call this function if it - /// wants to print linker-specific messages. To make them available via the - /// TargetRegistry. - inline void InitializeAllDiagnostics() { -#define MCLD_LINKER(TargetName) MCLDInitialize##TargetName##DiagnosticLineInfo(); -#include "mcld/Config/Linkers.def" - } - -} // namespace of mcld - -#endif - +#endif // MCLD_SUPPORT_TARGETSELECT_H_
diff --git a/include/mcld/Support/UniqueGCFactory.h b/include/mcld/Support/UniqueGCFactory.h index 8d7927b..a0d5a8f 100644 --- a/include/mcld/Support/UniqueGCFactory.h +++ b/include/mcld/Support/UniqueGCFactory.h
@@ -6,39 +6,36 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_UNIQUEGCFACTORY_H -#define MCLD_SUPPORT_UNIQUEGCFACTORY_H +#ifndef MCLD_SUPPORT_UNIQUEGCFACTORY_H_ +#define MCLD_SUPPORT_UNIQUEGCFACTORY_H_ #include "mcld/Support/GCFactory.h" + #include <map> #include <utility> -namespace mcld -{ +namespace mcld { /** \class UniqueGCFactoryBase * \brief UniqueGCFactories are unique associative factories, meaning that * no two elements have the same key. */ -template<typename KeyType, typename DataType, size_t ChunkSize> -class UniqueGCFactoryBase : public GCFactoryBase<LinearAllocator<DataType, ChunkSize> > -{ -protected: +template <typename KeyType, typename DataType, size_t ChunkSize> +class UniqueGCFactoryBase + : public GCFactoryBase<LinearAllocator<DataType, ChunkSize> > { + protected: typedef GCFactoryBase<LinearAllocator<DataType, ChunkSize> > Alloc; typedef std::map<KeyType, DataType*> KeyMap; -protected: + protected: UniqueGCFactoryBase() - : GCFactoryBase<LinearAllocator<DataType, ChunkSize> >() - { } + : GCFactoryBase<LinearAllocator<DataType, ChunkSize> >() {} - UniqueGCFactoryBase(size_t pNum) - : GCFactoryBase<LinearAllocator<DataType, ChunkSize> >(pNum) - { } + explicit UniqueGCFactoryBase(size_t pNum) + : GCFactoryBase<LinearAllocator<DataType, ChunkSize> >(pNum) {} -public: - virtual ~UniqueGCFactoryBase() - { f_KeyMap.clear(); } + public: + virtual ~UniqueGCFactoryBase() { f_KeyMap.clear(); } DataType* find(const KeyType& pKey) { typename KeyMap::iterator dataIter = f_KeyMap.find(pKey); @@ -80,12 +77,10 @@ return data; } -protected: + protected: KeyMap f_KeyMap; - }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SUPPORT_UNIQUEGCFACTORY_H_
diff --git a/include/mcld/Support/raw_ostream.h b/include/mcld/Support/raw_ostream.h index aae2336..b3a9f83 100644 --- a/include/mcld/Support/raw_ostream.h +++ b/include/mcld/Support/raw_ostream.h
@@ -6,17 +6,17 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_SUPPORT_RAWOSTREAM_H -#define MCLD_SUPPORT_RAWOSTREAM_H -#include <string> +#ifndef MCLD_SUPPORT_RAW_OSTREAM_H_ +#define MCLD_SUPPORT_RAW_OSTREAM_H_ #include <llvm/Support/FileSystem.h> #include <llvm/Support/raw_ostream.h> +#include <string> + namespace mcld { -class raw_fd_ostream : public llvm::raw_fd_ostream -{ -public: +class raw_fd_ostream : public llvm::raw_fd_ostream { + public: /// raw_fd_ostream - Open the specified file for writing. If an error occurs, /// information about the error is put into ErrorInfo, and the stream should /// be immediately destroyed; the string will be empty if no error occurred. @@ -27,44 +27,41 @@ /// itself to own the file descriptor. In particular, it will close the /// file descriptor when it is done (this is necessary to detect /// output errors). - raw_fd_ostream(const char *pFilename, - std::string &pErrorInfo, + raw_fd_ostream(const char* pFilename, + std::error_code& pErrorCode, llvm::sys::fs::OpenFlags pFlags = llvm::sys::fs::F_None); /// raw_fd_ostream ctor - FD is the file descriptor that this writes to. If /// ShouldClose is true, this closes the file when the stream is destroyed. - raw_fd_ostream(int pFD, bool pShouldClose, bool pUnbuffered=false); + raw_fd_ostream(int pFD, bool pShouldClose, bool pUnbuffered = false); virtual ~raw_fd_ostream(); void setColor(bool pEnable = true); + llvm::raw_ostream& changeColor(enum llvm::raw_ostream::Colors pColors, + bool pBold = false, + bool pBackground = false); - llvm::raw_ostream &changeColor(enum llvm::raw_ostream::Colors pColors, - bool pBold=false, - bool pBackground=false); + llvm::raw_ostream& resetColor(); - llvm::raw_ostream &resetColor(); - - llvm::raw_ostream &reverseColor(); + llvm::raw_ostream& reverseColor(); bool is_displayed() const; -private: + private: bool m_bConfigColor : 1; bool m_bSetColor : 1; - }; /// outs() - This returns a reference to a raw_ostream for standard output. /// Use it like: outs() << "foo" << "bar"; -mcld::raw_fd_ostream &outs(); +mcld::raw_fd_ostream& outs(); /// errs() - This returns a reference to a raw_ostream for standard error. /// Use it like: errs() << "foo" << "bar"; -mcld::raw_fd_ostream &errs(); +mcld::raw_fd_ostream& errs(); -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_SUPPORT_RAW_OSTREAM_H_
diff --git a/include/mcld/Target/DarwinLDBackend.h b/include/mcld/Target/DarwinLDBackend.h index f4bc29f..bc2fd2b 100644 --- a/include/mcld/Target/DarwinLDBackend.h +++ b/include/mcld/Target/DarwinLDBackend.h
@@ -6,23 +6,19 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGET_DARWINLDBACKEND_H -#define MCLD_TARGET_DARWINLDBACKEND_H +#ifndef MCLD_TARGET_DARWINLDBACKEND_H_ +#define MCLD_TARGET_DARWINLDBACKEND_H_ -namespace mcld -{ +namespace mcld { /** \class DarwinLDBackend - * \brief DarwinLDBackend provides a common interface for all Darwin OS LDBackend. + * \brief DarwinLDBackend provides a common interface for all Darwin OS + * LDBackend. * * \see */ -class DarwinLDBackend -{ +class DarwinLDBackend {}; -}; +} // namespace mcld -} // namespace of mcld - -#endif - +#endif // MCLD_TARGET_DARWINLDBACKEND_H_
diff --git a/include/mcld/Target/ELFAttribute.h b/include/mcld/Target/ELFAttribute.h index aa2d8ea..a50e13e 100644 --- a/include/mcld/Target/ELFAttribute.h +++ b/include/mcld/Target/ELFAttribute.h
@@ -6,11 +6,11 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGET_ELFATTRIBUTE_H -#define MCLD_TARGET_ELFATTRIBUTE_H +#ifndef MCLD_TARGET_ELFATTRIBUTE_H_ +#define MCLD_TARGET_ELFATTRIBUTE_H_ -#include <mcld/Support/MemoryRegion.h> -#include <mcld/Target/ELFAttributeData.h> +#include "mcld/Support/MemoryRegion.h" +#include "mcld/Target/ELFAttributeData.h" #include <llvm/ADT/SmallVector.h> #include <llvm/ADT/StringRef.h> @@ -26,97 +26,95 @@ /** \class ELFAttribute * \brief ELFAttribute is the attribute section in an ELF file. */ -class ELFAttribute -{ -public: +class ELFAttribute { + public: // ARM [ABI-addenda], 2.2.3. - static const char FormatVersion = 'A'; - static const size_t FormatVersionFieldSize = sizeof(FormatVersion); // a byte - static const size_t SubsectionLengthFieldSize = 4; // a 4-byte integer + static const char FormatVersion = 'A'; + static const size_t FormatVersionFieldSize = sizeof(FormatVersion); // a byte + static const size_t SubsectionLengthFieldSize = 4; // a 4-byte integer // MinimalELFAttributeSubsectionSize is the minimal number of bytes a valid // subsection in ELF attribute section should have. - static const size_t MinimalELFAttributeSubsectionSize - = 1 /* Tag_File, see ARM [ABI-addenda], 2.2.4 */ + - 4 /* byte-size, see ARM [ABI-addenda], 2.2.4 */; + static const size_t MinimalELFAttributeSubsectionSize = + 1 /* Tag_File, see ARM [ABI-addenda], 2.2.4 */ + + 4 /* byte-size, see ARM [ABI-addenda], 2.2.4 */; // MinimalELFAttributeSectionSize is the minimal number of bytes a valid ELF // attribute section should have. - static const size_t MinimalELFAttributeSectionSize - = FormatVersionFieldSize + SubsectionLengthFieldSize + - 2 /* vendor-name, a char plus '\0', see ARM [ABI-addenda], 2.2.3 */ + - 1 * MinimalELFAttributeSubsectionSize; + static const size_t MinimalELFAttributeSectionSize = + FormatVersionFieldSize + SubsectionLengthFieldSize + + 2 /* vendor-name, a char plus '\0', see ARM [ABI-addenda], 2.2.3 */ + + 1 * MinimalELFAttributeSubsectionSize; -public: - ELFAttribute(const GNULDBackend &pBackend, const LinkerConfig& pConfig) - : m_Backend(pBackend), m_Config(pConfig) { } + public: + ELFAttribute(const GNULDBackend& pBackend, const LinkerConfig& pConfig) + : m_Backend(pBackend), m_Config(pConfig) {} ~ELFAttribute(); -public: + public: /// merge - merge attributes from input (attribute) section - bool merge(const Input &pInput, LDSection &pInputAttrSectHdr); + bool merge(const Input& pInput, LDSection& pInputAttrSectHdr); /// sizeOutput - calculate the number of bytes required to encode this /// attribute data section size_t sizeOutput() const; /// emit - encode and write out this attribute section - size_t emit(MemoryRegion &pRegion) const; + size_t emit(MemoryRegion& pRegion) const; - inline const GNULDBackend &backend() const { return m_Backend; } + inline const GNULDBackend& backend() const { return m_Backend; } - inline const LinkerConfig &config() const { return m_Config; } + inline const LinkerConfig& config() const { return m_Config; } // Place vendor's attribute data under the management. void registerAttributeData(ELFAttributeData& pAttrData); -private: + private: /** \class Subsection * \brief A helper class to wrap ELFAttributeData and to provide general * interfaces for ELFAttribute to operate on */ class Subsection { - public: - Subsection(ELFAttribute &pParent, ELFAttributeData &pAttrData) - : m_Parent(pParent), m_AttrData(pAttrData) { } + public: + Subsection(ELFAttribute& pParent, ELFAttributeData& pAttrData) + : m_Parent(pParent), m_AttrData(pAttrData) {} - public: - bool isMyAttribute(llvm::StringRef pVendorName) const - { + public: + bool isMyAttribute(llvm::StringRef pVendorName) const { return (m_AttrData.getVendorName() == pVendorName); } /// merge - Merge the attributes from the section in the input data. - bool merge(const Input &pInput, ConstAddress pData, size_t pSize); + bool merge(const Input& pInput, ConstAddress pData, size_t pSize); /// sizeOutput - calculate the number of bytes required to encode this /// subsection size_t sizeOutput() const; /// emit - write out this attribute subsection to the buffer. - size_t emit(char *pBuf) const; + size_t emit(char* pBuf) const; - private: + private: // The attribute section this subsection belongs to - ELFAttribute &m_Parent; + ELFAttribute& m_Parent; // The attribute data containing in this subsection - ELFAttributeData &m_AttrData; + ELFAttributeData& m_AttrData; }; // Obtain the corresponding subsection of the specified vendor - Subsection *getSubsection(llvm::StringRef pVendorName) const; + Subsection* getSubsection(llvm::StringRef pVendorName) const; -private: - const GNULDBackend &m_Backend; + private: + const GNULDBackend& m_Backend; - const LinkerConfig &m_Config; + const LinkerConfig& m_Config; // There is at most two subsections ("aeabi" and "gnu") in most cases. llvm::SmallVector<Subsection*, 2> m_Subsections; }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_TARGET_ELFATTRIBUTE_H_
diff --git a/include/mcld/Target/ELFAttributeData.h b/include/mcld/Target/ELFAttributeData.h index 1480bb7..0c58366 100644 --- a/include/mcld/Target/ELFAttributeData.h +++ b/include/mcld/Target/ELFAttributeData.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGET_ELFATTRIBUTEDATA_H -#define MCLD_TARGET_ELFATTRIBUTEDATA_H +#ifndef MCLD_TARGET_ELFATTRIBUTEDATA_H_ +#define MCLD_TARGET_ELFATTRIBUTEDATA_H_ #include <stdint.h> #include <string> @@ -22,30 +22,29 @@ /** \class ELFAttributeData * \brief ELFAttributeData handles data in vendor attribute subsection. */ -class ELFAttributeData -{ -public: +class ELFAttributeData { + public: typedef uint32_t TagType; // Generic attribute tags shared between all vendors enum { - Tag_NULL = 0, - Tag_File = 1, - Tag_Section = 2, - Tag_Symbol = 3, + Tag_NULL = 0, + Tag_File = 1, + Tag_Section = 2, + Tag_Symbol = 3, }; -public: - ELFAttributeData(const char* pVendor) : m_Vendor(pVendor) { } + public: + explicit ELFAttributeData(const char* pVendor) : m_Vendor(pVendor) {} - virtual ~ELFAttributeData() { } + virtual ~ELFAttributeData() {} -public: - inline const std::string &getVendorName() const { return m_Vendor; } + public: + inline const std::string& getVendorName() const { return m_Vendor; } /// getAttributeValue - query the data store for the attribute value of the /// given tag. - virtual const ELFAttributeValue *getAttributeValue(TagType pTag) const = 0; + virtual const ELFAttributeValue* getAttributeValue(TagType pTag) const = 0; /// getOrCreateAttributeValue - obtain attribute value for the given tag and /// create if it does not exist. @@ -53,45 +52,49 @@ /// It returns a pair containing the attribute value instance (guaranteed to /// be non-NULL) and a boolean value indicating whether the instance is newly /// created (true) or not (false.) - virtual std::pair<ELFAttributeValue*, bool> - getOrCreateAttributeValue(TagType pTag) = 0; + virtual std::pair<ELFAttributeValue*, bool> getOrCreateAttributeValue( + TagType pTag) = 0; /// preMerge - hooks to call before starting merge the attribute data in an /// input. - virtual bool preMerge(const Input &pInput) { return true; } + virtual bool preMerge(const Input& pInput) { return true; } /// merge - implement logics to merge input attribute to the output. - virtual bool merge(const LinkerConfig& pConfig, const Input &pInput, - TagType pTag, const ELFAttributeValue& pInAttr) = 0; + virtual bool merge(const LinkerConfig& pConfig, + const Input& pInput, + TagType pTag, + const ELFAttributeValue& pInAttr) = 0; /// postMerge - hooks to call after finishing merge the attribute data from an /// input. - virtual bool postMerge(const LinkerConfig& pConfig, const Input &pInput) - { return true; } + virtual bool postMerge(const LinkerConfig& pConfig, const Input& pInput) { + return true; + } /// sizeOutput - obtain number of bytes required to encode the attribute data. virtual size_t sizeOutput() const = 0; /// emit - write out attribute data to the buffer and return the number of /// bytes written - virtual size_t emit(char *pBuf) const = 0; + virtual size_t emit(char* pBuf) const = 0; -public: + public: /// ReadTag - read an attribute tag from input buffer. /// /// If the read succeeds, pBuf moves to the new position just pass the end of /// the tag in the buffer and pBufSize decreases the size of tag in the /// buffer. Otherwise, this function will return false and change nothing /// except leaving undefined value in pTag. - static bool ReadTag(TagType& pTag, const char* &pBuf, size_t &pBufSize); + static bool ReadTag(TagType& pTag, const char*& pBuf, size_t& pBufSize); /// ReadValue - read an attribute value from input buffer /// /// Similar with ReadTag() while this reads attribute value from the input /// buffer. Note that the value type of the attribute must be properly set in /// pValue prior the call. - static bool ReadValue(ELFAttributeValue& pValue, const char* &pBuf, - size_t &pBufSize); + static bool ReadValue(ELFAttributeValue& pValue, + const char*& pBuf, + size_t& pBufSize); /// WriteAttribute - write an attribute tag plus value to buffer. /// @@ -99,13 +102,14 @@ /// attribute data just written. Otherwise, it returns false and leaves pBuf /// in an undefined position. Note that buffer is guaranteed to be able to /// contain the attribute data. - static bool WriteAttribute(TagType pTag, const ELFAttributeValue& pValue, - char* &pBuf); + static bool WriteAttribute(TagType pTag, + const ELFAttributeValue& pValue, + char*& pBuf); -private: + private: const std::string m_Vendor; }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_TARGET_ELFATTRIBUTEDATA_H_
diff --git a/include/mcld/Target/ELFAttributeValue.h b/include/mcld/Target/ELFAttributeValue.h index f4ee3dc..e654a6c 100644 --- a/include/mcld/Target/ELFAttributeValue.h +++ b/include/mcld/Target/ELFAttributeValue.h
@@ -6,85 +6,75 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGET_ELFATTRIBUTEVALUE_H -#define MCLD_TARGET_ELFATTRIBUTEVALUE_H +#ifndef MCLD_TARGET_ELFATTRIBUTEVALUE_H_ +#define MCLD_TARGET_ELFATTRIBUTEVALUE_H_ #include <string> -namespace mcld -{ +namespace mcld { /** \class ELFAttributeValue * \brief ELFAttributeValue stroes the value of an attribute tag. The attribtue * tag itself is not stored in this object. */ -class ELFAttributeValue -{ -public: +class ELFAttributeValue { + public: // Type of value that an attribute tag holds. enum Type { // The value contains no data and has unknown type. Uninitialized = 0, // The value contains integer data. - Int = 1L << 0, + Int = 1L << 0, // The value contains string data. - String = 1L << 1, + String = 1L << 1, // This is for attribute in which "default value" (0 for int type and empty // string for string type) has special meaning for them. That is, the // default value is "disabled" and meaningful for those attribute. - NoDefault = 1L << 2, + NoDefault = 1L << 2, }; -public: - ELFAttributeValue() - : m_Type(Uninitialized), m_IntValue(0), m_StringValue() { } + public: + ELFAttributeValue() : m_Type(Uninitialized), m_IntValue(0), m_StringValue() {} - ~ELFAttributeValue() { } + ~ELFAttributeValue() {} -public: - unsigned int type() const - { return m_Type; } + public: + unsigned int type() const { return m_Type; } - void setType(unsigned int pType) - { m_Type = pType; } + void setType(unsigned int pType) { m_Type = pType; } - unsigned int getIntValue() const - { return m_IntValue; } + unsigned int getIntValue() const { return m_IntValue; } - void setIntValue(unsigned int pIntValue) - { m_IntValue = pIntValue; } + void setIntValue(unsigned int pIntValue) { m_IntValue = pIntValue; } - const std::string &getStringValue() const - { return m_StringValue; } + const std::string& getStringValue() const { return m_StringValue; } - void setStringValue(const std::string &pStringValue) - { m_StringValue = pStringValue; } + void setStringValue(const std::string& pStringValue) { + m_StringValue = pStringValue; + } - void setStringValue(const char *pStringValue, size_t pSize) - { m_StringValue.assign(pStringValue, pSize); } + void setStringValue(const char* pStringValue, size_t pSize) { + m_StringValue.assign(pStringValue, pSize); + } - void setStringValue(const char *pStringValue) - { m_StringValue.assign(pStringValue); } + void setStringValue(const char* pStringValue) { + m_StringValue.assign(pStringValue); + } size_t getSize() const; - inline bool isUninitialized() const - { return (m_Type == Uninitialized); } + inline bool isUninitialized() const { return (m_Type == Uninitialized); } - inline bool isInitialized() const - { return !isUninitialized(); } + inline bool isInitialized() const { return !isUninitialized(); } - inline bool isIntValue() const - { return (m_Type & Int); } + inline bool isIntValue() const { return (m_Type & Int); } - inline bool isStringValue() const - { return (m_Type & String); } + inline bool isStringValue() const { return (m_Type & String); } - inline bool hasNoDefault() const - { return (m_Type & NoDefault); } + inline bool hasNoDefault() const { return (m_Type & NoDefault); } bool isDefaultValue() const; @@ -96,27 +86,28 @@ bool equals(const ELFAttributeValue& pValue) const; - bool operator==(const ELFAttributeValue& pValue) const - { return equals(pValue); } - bool operator!=(const ELFAttributeValue& pValue) const - { return !equals(pValue); } + bool operator==(const ELFAttributeValue& pValue) const { + return equals(pValue); + } + bool operator!=(const ELFAttributeValue& pValue) const { + return !equals(pValue); + } /// reset - reset this value to the uninitialized state - void reset() - { + void reset() { m_Type = Uninitialized; m_IntValue = 0; m_StringValue.clear(); return; } -private: + private: unsigned int m_Type; unsigned int m_IntValue; std::string m_StringValue; }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_TARGET_ELFATTRIBUTEVALUE_H_
diff --git a/include/mcld/Target/ELFDynamic.h b/include/mcld/Target/ELFDynamic.h index 87d0f0f..42feeb6 100644 --- a/include/mcld/Target/ELFDynamic.h +++ b/include/mcld/Target/ELFDynamic.h
@@ -6,11 +6,11 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGET_ELFDYNAMIC_H -#define MCLD_TARGET_ELFDYNAMIC_H +#ifndef MCLD_TARGET_ELFDYNAMIC_H_ +#define MCLD_TARGET_ELFDYNAMIC_H_ -#include <mcld/LD/LDSection.h> -#include <mcld/Support/FileOutputBuffer.h> +#include "mcld/LD/LDSection.h" +#include "mcld/Support/FileOutputBuffer.h" #include <llvm/Support/ELF.h> #include <vector> #include <cstring> @@ -27,12 +27,11 @@ * \brief EntryIF provides a common interface for one entry in the dynamic * section */ -class EntryIF -{ -protected: +class EntryIF { + protected: EntryIF(); -public: + public: virtual ~EntryIF(); virtual EntryIF* clone() const = 0; @@ -44,100 +43,86 @@ virtual void setValue(uint64_t pTag, uint64_t pValue) = 0; }; -template<size_t BITNUMBER, bool LITTLEENDIAN> -class Entry -{ }; +template <size_t BITNUMBER, bool LITTLEENDIAN> +class Entry {}; -template<> -class Entry<32, true> : public EntryIF -{ -public: - typedef llvm::ELF::Elf32_Dyn Pair; - typedef llvm::ELF::Elf32_Sym Symbol; - typedef llvm::ELF::Elf32_Rel Rel; +template <> +class Entry<32, true> : public EntryIF { + public: + typedef llvm::ELF::Elf32_Dyn Pair; + typedef llvm::ELF::Elf32_Sym Symbol; + typedef llvm::ELF::Elf32_Rel Rel; typedef llvm::ELF::Elf32_Rela Rela; -public: + public: inline Entry(); inline ~Entry(); - Entry* clone() const - { return new Entry(); } + Entry* clone() const { return new Entry(); } - size_t size() const - { return sizeof(Pair); } + size_t size() const { return sizeof(Pair); } - size_t symbolSize() const - { return sizeof(Symbol); } + size_t symbolSize() const { return sizeof(Symbol); } - size_t relSize() const - { return sizeof(Rel); } + size_t relSize() const { return sizeof(Rel); } - size_t relaSize() const - { return sizeof(Rela); } + size_t relaSize() const { return sizeof(Rela); } inline void setValue(uint64_t pTag, uint64_t pValue); inline size_t emit(uint8_t* pAddress) const; -private: + private: Pair m_Pair; }; -template<> -class Entry<64, true> : public EntryIF -{ -public: - typedef llvm::ELF::Elf64_Dyn Pair; - typedef llvm::ELF::Elf64_Sym Symbol; - typedef llvm::ELF::Elf64_Rel Rel; +template <> +class Entry<64, true> : public EntryIF { + public: + typedef llvm::ELF::Elf64_Dyn Pair; + typedef llvm::ELF::Elf64_Sym Symbol; + typedef llvm::ELF::Elf64_Rel Rel; typedef llvm::ELF::Elf64_Rela Rela; -public: + public: inline Entry(); inline ~Entry(); - Entry* clone() const - { return new Entry(); } + Entry* clone() const { return new Entry(); } - size_t size() const - { return sizeof(Pair); } + size_t size() const { return sizeof(Pair); } - size_t symbolSize() const - { return sizeof(Symbol); } + size_t symbolSize() const { return sizeof(Symbol); } - size_t relSize() const - { return sizeof(Rel); } + size_t relSize() const { return sizeof(Rel); } - size_t relaSize() const - { return sizeof(Rela); } + size_t relaSize() const { return sizeof(Rela); } inline void setValue(uint64_t pTag, uint64_t pValue); inline size_t emit(uint8_t* pAddress) const; -private: + private: Pair m_Pair; }; #include "ELFDynamic.tcc" -} // namespace of elf_dynamic +} // namespace elf_dynamic /** \class ELFDynamic * \brief ELFDynamic is the .dynamic section in ELF shared and executable * files. */ -class ELFDynamic -{ -public: +class ELFDynamic { + public: typedef std::vector<elf_dynamic::EntryIF*> EntryListType; typedef EntryListType::iterator iterator; typedef EntryListType::const_iterator const_iterator; -public: + public: ELFDynamic(const GNULDBackend& pBackend, const LinkerConfig& pConfig); virtual ~ELFDynamic(); @@ -160,22 +145,22 @@ void applySoname(uint64_t pStrTabIdx); const_iterator needBegin() const { return m_NeedList.begin(); } - iterator needBegin() { return m_NeedList.begin(); } + iterator needBegin() { return m_NeedList.begin(); } const_iterator needEnd() const { return m_NeedList.end(); } - iterator needEnd() { return m_NeedList.end(); } + iterator needEnd() { return m_NeedList.end(); } /// emit void emit(const LDSection& pSection, MemoryRegion& pRegion) const; -protected: + protected: /// reserveTargetEntries - reserve target dependent entries virtual void reserveTargetEntries(const ELFFileFormat& pFormat) = 0; /// applyTargetEntries - apply target-dependant virtual void applyTargetEntries(const ELFFileFormat& pFormat) = 0; -protected: + protected: void reserveOne(uint64_t pTag); void applyOne(uint64_t pTag, uint64_t pValue); @@ -184,7 +169,7 @@ const LinkerConfig& config() const { return m_Config; } -private: + private: EntryListType m_EntryList; EntryListType m_NeedList; elf_dynamic::EntryIF* m_pEntryFactory; @@ -197,7 +182,6 @@ size_t m_Idx; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_TARGET_ELFDYNAMIC_H_
diff --git a/include/mcld/Target/ELFDynamic.tcc b/include/mcld/Target/ELFDynamic.tcc index 5d67be4..2a00c79 100644 --- a/include/mcld/Target/ELFDynamic.tcc +++ b/include/mcld/Target/ELFDynamic.tcc
@@ -9,24 +9,20 @@ //===----------------------------------------------------------------------===// /// 32-bit dynamic entry -Entry<32, true>::Entry() -{ +Entry<32, true>::Entry() { m_Pair.d_tag = 0; m_Pair.d_un.d_val = 0; } -Entry<32, true>::~Entry() -{ +Entry<32, true>::~Entry() { } -void Entry<32, true>::setValue(uint64_t pTag, uint64_t pValue) -{ +void Entry<32, true>::setValue(uint64_t pTag, uint64_t pValue) { m_Pair.d_tag = pTag; m_Pair.d_un.d_val = pValue; } -size_t Entry<32, true>::emit(uint8_t* pAddress) const -{ +size_t Entry<32, true>::emit(uint8_t* pAddress) const { memcpy(reinterpret_cast<void*>(pAddress), reinterpret_cast<const void*>(&m_Pair), sizeof(Pair)); @@ -35,27 +31,22 @@ //===----------------------------------------------------------------------===// /// 64-bit dynamic entry -Entry<64, true>::Entry() -{ +Entry<64, true>::Entry() { m_Pair.d_tag = 0; m_Pair.d_un.d_val = 0; } -Entry<64, true>::~Entry() -{ +Entry<64, true>::~Entry() { } -void Entry<64, true>::setValue(uint64_t pTag, uint64_t pValue) -{ +void Entry<64, true>::setValue(uint64_t pTag, uint64_t pValue) { m_Pair.d_tag = pTag; m_Pair.d_un.d_val = pValue; } -size_t Entry<64, true>::emit(uint8_t* pAddress) const -{ +size_t Entry<64, true>::emit(uint8_t* pAddress) const { memcpy(reinterpret_cast<void*>(pAddress), reinterpret_cast<const void*>(&m_Pair), sizeof(Pair)); return sizeof(Pair); } -
diff --git a/include/mcld/Target/ELFEmulation.h b/include/mcld/Target/ELFEmulation.h index 0e9a1ec..3c6e6f7 100644 --- a/include/mcld/Target/ELFEmulation.h +++ b/include/mcld/Target/ELFEmulation.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGET_ELFEMULATION_H -#define MCLD_TARGET_ELFEMULATION_H +#ifndef MCLD_TARGET_ELFEMULATION_H_ +#define MCLD_TARGET_ELFEMULATION_H_ namespace mcld { @@ -16,7 +16,6 @@ bool MCLDEmulateELF(LinkerScript& pScript, LinkerConfig& pConfig); -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_TARGET_ELFEMULATION_H_
diff --git a/include/mcld/Target/GNUInfo.h b/include/mcld/Target/GNUInfo.h index 2eb53da..2a55688 100644 --- a/include/mcld/Target/GNUInfo.h +++ b/include/mcld/Target/GNUInfo.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGET_GNUINFO_H -#define MCLD_TARGET_GNUINFO_H +#ifndef MCLD_TARGET_GNUINFO_H_ +#define MCLD_TARGET_GNUINFO_H_ #include <llvm/ADT/Triple.h> #include <llvm/Support/ELF.h> @@ -16,12 +16,11 @@ /** \class GNUInfo * \brief GNUInfo records ELF-dependent and target-dependnet data fields */ -class GNUInfo -{ -public: - GNUInfo(const llvm::Triple& pTriple); +class GNUInfo { + public: + explicit GNUInfo(const llvm::Triple& pTriple); - virtual ~GNUInfo() { } + virtual ~GNUInfo() {} /// ELFVersion - the value of e_ident[EI_VERSION] virtual uint8_t ELFVersion() const { return llvm::ELF::EV_CURRENT; } @@ -35,7 +34,8 @@ /// ABIVersion - the value of e_ident[EI_ABIVRESION] virtual uint8_t ABIVersion() const { return 0x0; } - /// defaultTextSegmentAddr - target should specify its own default start address + /// defaultTextSegmentAddr - target should specify its own default start + /// address /// of the text segment. esp. for exec. virtual uint64_t defaultTextSegmentAddr() const { return 0x0; } @@ -62,11 +62,10 @@ /// here. If target favors the different size, please override this function virtual uint64_t abiPageSize() const { return 0x1000; } -protected: + protected: const llvm::Triple& m_Triple; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_TARGET_GNUINFO_H_
diff --git a/include/mcld/Target/GNULDBackend.h b/include/mcld/Target/GNULDBackend.h index 351111d..93f7b1b 100644 --- a/include/mcld/Target/GNULDBackend.h +++ b/include/mcld/Target/GNULDBackend.h
@@ -6,16 +6,16 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGET_GNULDBACKEND_H -#define MCLD_TARGET_GNULDBACKEND_H -#include <mcld/Target/TargetLDBackend.h> +#ifndef MCLD_TARGET_GNULDBACKEND_H_ +#define MCLD_TARGET_GNULDBACKEND_H_ -#include <mcld/Module.h> -#include <mcld/LD/GNUArchiveReader.h> -#include <mcld/LD/ELFDynObjReader.h> -#include <mcld/LD/ELFBinaryReader.h> -#include <mcld/LD/ELFObjectReader.h> -#include <mcld/LD/ELFObjectWriter.h> +#include "mcld/Module.h" +#include "mcld/LD/ELFBinaryReader.h" +#include "mcld/LD/ELFDynObjReader.h" +#include "mcld/LD/ELFObjectReader.h" +#include "mcld/LD/ELFObjectWriter.h" +#include "mcld/LD/GNUArchiveReader.h" +#include "mcld/Target/TargetLDBackend.h" #include <llvm/Support/ELF.h> @@ -23,34 +23,33 @@ namespace mcld { -class Module; -class LinkerConfig; -class IRBuilder; -class Layout; -class EhFrameHdr; class BranchIslandFactory; -class StubFactory; -class GNUInfo; -class ELFFileFormat; -class ELFSegmentFactory; +class EhFrameHdr; class ELFAttribute; class ELFDynamic; class ELFDynObjFileFormat; class ELFExecFileFormat; +class ELFFileFormat; class ELFObjectFileFormat; +class ELFSegmentFactory; +class GNUInfo; +class IRBuilder; +class Layout; +class LinkerConfig; class LinkerScript; +class Module; class Relocation; +class StubFactory; /** \class GNULDBackend * \brief GNULDBackend provides a common interface for all GNU Unix-OS * LDBackend. */ -class GNULDBackend : public TargetLDBackend -{ -protected: +class GNULDBackend : public TargetLDBackend { + protected: GNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo); -public: + public: virtual ~GNULDBackend(); // ----- readers/writers ----- // @@ -66,7 +65,7 @@ /// getOutputFormat - get the sections of the output file. const ELFFileFormat* getOutputFormat() const; - ELFFileFormat* getOutputFormat(); + ELFFileFormat* getOutputFormat(); // ----- target symbols ----- // /// initStandardSymbols - initialize standard symbols. @@ -83,8 +82,7 @@ /// @return ture - if backend set the symbol value sucessfully /// @return false - if backend do not recognize the symbol bool finalizeSymbols() { - return (finalizeStandardSymbols() && - finalizeTargetSymbols()); + return (finalizeStandardSymbols() && finalizeTargetSymbols()); } /// finalizeStandardSymbols - set the value of standard symbols @@ -99,13 +97,13 @@ size_t sectionStartOffset() const; const GNUInfo& getInfo() const { return *m_pInfo; } - GNUInfo& getInfo() { return *m_pInfo; } + GNUInfo& getInfo() { return *m_pInfo; } bool hasTextRel() const { return m_bHasTextRel; } bool hasStaticTLS() const { return m_bHasStaticTLS; } - /// getSegmentStartAddr - this function returns the start address of the segment + /// getSegmentStartAddr - return the start address of the segment uint64_t getSegmentStartAddr(const LinkerScript& pScript) const; /// sizeShstrtab - compute the size of .shstrtab @@ -121,7 +119,8 @@ MemoryRegion& pRegion) const = 0; /// emitRegNamePools - emit regular name pools - .symtab, .strtab - virtual void emitRegNamePools(const Module& pModule, FileOutputBuffer& pOutput); + virtual void emitRegNamePools(const Module& pModule, + FileOutputBuffer& pOutput); /// emitNamePools - emit dynamic name pools - .dyntab, .dynstr, .hash virtual void emitDynNamePools(Module& pModule, FileOutputBuffer& pOutput); @@ -147,8 +146,7 @@ /// orderSymbolTable - order symbol table before emitting virtual void orderSymbolTable(Module& pModule); - void setHasStaticTLS(bool pVal = true) - { m_bHasStaticTLS = pVal; } + void setHasStaticTLS(bool pVal = true) { m_bHasStaticTLS = pVal; } /// getSectionOrder - compute the layout order of the section /// Layout calls this function to get the default order of the pSectHdr. @@ -167,11 +165,12 @@ /// /// By default, this function returns the maximun order, and pSectHdr /// will be the last section to be laid out. - virtual unsigned int getTargetSectionOrder(const LDSection& pSectHdr) const - { return (unsigned int)-1; } + virtual unsigned int getTargetSectionOrder(const LDSection& pSectHdr) const { + return (unsigned int)-1; + } /// elfSegmentTable - return the reference of the elf segment table - ELFSegmentFactory& elfSegmentTable(); + ELFSegmentFactory& elfSegmentTable(); /// elfSegmentTable - return the reference of the elf segment table const ELFSegmentFactory& elfSegmentTable() const; @@ -247,7 +246,6 @@ int64_t pAddend) const; /// symbolNeedsPLT - return whether the symbol needs a PLT entry - /// @ref Google gold linker, symtab.h:596 bool symbolNeedsPLT(const ResolveInfo& pSym) const; /// symbolNeedsCopyReloc - return whether the symbol needs a copy relocation @@ -255,14 +253,12 @@ const ResolveInfo& pSym) const; /// symbolNeedsDynRel - return whether the symbol needs a dynamic relocation - /// @ref Google gold linker, symtab.h:645 bool symbolNeedsDynRel(const ResolveInfo& pSym, bool pSymHasPLT, bool isAbsReloc) const; /// isSymbolPreemptible - whether the symbol can be preemted by other link /// units - /// @ref Google gold linker, symtab.h:551 bool isSymbolPreemptible(const ResolveInfo& pSym) const; /// symbolHasFinalValue - return true if the symbol's value can be decided at @@ -270,22 +266,20 @@ bool symbolFinalValueIsKnown(const ResolveInfo& pSym) const; /// isDynamicSymbol - /// @ref Google gold linker: symtab.cc:311 bool isDynamicSymbol(const LDSymbol& pSymbol) const; /// isDynamicSymbol - /// @ref Google gold linker: symtab.cc:311 bool isDynamicSymbol(const ResolveInfo& pResolveInfo) const; virtual ResolveInfo::Desc getSymDesc(uint16_t pShndx) const { return ResolveInfo::Define; } - bool hasTDATASymbol() const { return (NULL != f_pTDATA); } - bool hasTBSSSymbol() const { return (NULL != f_pTBSS); } + bool hasTDATASymbol() const { return (f_pTDATA != NULL); } + bool hasTBSSSymbol() const { return (f_pTBSS != NULL); } void setTDATASymbol(LDSymbol& pTDATA) { f_pTDATA = &pTDATA; } - void setTBSSSymbol(LDSymbol& pTBSS) { f_pTBSS = &pTBSS; } + void setTBSSSymbol(LDSymbol& pTBSS) { f_pTBSS = &pTBSS; } // getTDATASymbol - get section symbol of .tdata LDSymbol& getTDATASymbol(); @@ -309,7 +303,7 @@ BranchIslandFactory* getBRIslandFactory() { return m_pBRIslandFactory; } /// getStubFactory - StubFactory* getStubFactory() { return m_pStubFactory; } + StubFactory* getStubFactory() { return m_pStubFactory; } /// maxFwdBranchOffset - return the max forward branch offset of the backend. /// Target can override this function if needed. @@ -340,7 +334,7 @@ /// function pointer access bool mayHaveUnsafeFunctionPointerAccess(const LDSection& pSection) const; -protected: + protected: /// getRelEntrySize - the size in BYTE of rel type relocation virtual size_t getRelEntrySize() = 0; @@ -359,11 +353,9 @@ virtual bool isTemporary(const LDSymbol& pSymbol) const; /// getHashBucketCount - calculate hash bucket count. - /// @ref Google gold linker, dynobj.cc:791 static unsigned getHashBucketCount(unsigned pNumOfSymbols, bool pIsGNUStyle); /// getGNUHashMaskbitslog2 - calculate the number of mask bits in log2 - /// @ref binutils gold, dynobj.cc:1165 unsigned getGNUHashMaskbitslog2(unsigned pNumOfSymbols) const; /// emitSymbol32 - emit an ELF32 symbol @@ -380,7 +372,7 @@ size_t pStrtabsize, size_t pSymtabIdx); -private: + private: /// createProgramHdrs - base on output sections to create the program headers void createProgramHdrs(Module& pModule); @@ -442,71 +434,66 @@ /// implementation. Return true if the output (e.g., .text) is "relaxed" /// (i.e. layout is changed), and set pFinished to true if everything is fit, /// otherwise set it to false. - virtual bool doRelax(Module& pModule, IRBuilder& pBuilder, bool& pFinished) - { return false; } + virtual bool doRelax(Module& pModule, IRBuilder& pBuilder, bool& pFinished) { + return false; + } -protected: - // Based on Kind in LDFileFormat to define basic section orders for ELF, and - // refer gold linker to add more enumerations to handle Regular and BSS kind + protected: + // Based on Kind in LDFileFormat to define basic section orders for ELF. enum SectionOrder { - SHO_NULL = 0, // NULL - SHO_INTERP, // .interp - SHO_RO_NOTE, // .note.ABI-tag, .note.gnu.build-id - SHO_NAMEPOOL, // *.hash, .dynsym, .dynstr - SHO_RELOCATION, // .rel.*, .rela.* - SHO_REL_PLT, // .rel.plt should come after other .rel.* - SHO_INIT, // .init - SHO_PLT, // .plt - SHO_TEXT, // .text - SHO_FINI, // .fini - SHO_RO, // .rodata - SHO_EXCEPTION, // .eh_frame_hdr, .eh_frame, .gcc_except_table - SHO_TLS_DATA, // .tdata - SHO_TLS_BSS, // .tbss - SHO_RELRO_LOCAL, // .data.rel.ro.local - SHO_RELRO, // .data.rel.ro, - SHO_RELRO_LAST, // for x86 to adjust .got if needed - SHO_NON_RELRO_FIRST, // for x86 to adjust .got.plt if needed - SHO_DATA, // .data - SHO_LARGE_DATA, // .ldata - SHO_RW_NOTE, // - SHO_SMALL_DATA, // .sdata - SHO_SMALL_BSS, // .sbss - SHO_BSS, // .bss - SHO_LARGE_BSS, // .lbss - SHO_UNDEFINED, // default order - SHO_STRTAB // .strtab + SHO_NULL = 0, // NULL + SHO_INTERP, // .interp + SHO_RO_NOTE, // .note.ABI-tag, .note.gnu.build-id + SHO_NAMEPOOL, // *.hash, .dynsym, .dynstr + SHO_RELOCATION, // .rel.*, .rela.* + SHO_REL_PLT, // .rel.plt should come after other .rel.* + SHO_INIT, // .init + SHO_PLT, // .plt + SHO_TEXT, // .text + SHO_FINI, // .fini + SHO_RO, // .rodata + SHO_EXCEPTION, // .eh_frame_hdr, .eh_frame, .gcc_except_table + SHO_TLS_DATA, // .tdata + SHO_TLS_BSS, // .tbss + SHO_RELRO_LOCAL, // .data.rel.ro.local + SHO_RELRO, // .data.rel.ro, + SHO_RELRO_LAST, // for x86 to adjust .got if needed + SHO_NON_RELRO_FIRST, // for x86 to adjust .got.plt if needed + SHO_DATA, // .data + SHO_LARGE_DATA, // .ldata + SHO_RW_NOTE, // + SHO_SMALL_DATA, // .sdata + SHO_SMALL_BSS, // .sbss + SHO_BSS, // .bss + SHO_LARGE_BSS, // .lbss + SHO_UNDEFINED, // default order + SHO_STRTAB // .strtab }; // for -z combreloc - struct RelocCompare - { - RelocCompare(const GNULDBackend& pBackend) - : m_Backend(pBackend) { - } + struct RelocCompare { + explicit RelocCompare(const GNULDBackend& pBackend) : m_Backend(pBackend) {} bool operator()(const Relocation* X, const Relocation* Y) const; - private: + + private: const GNULDBackend& m_Backend; }; // for gnu style hash table - struct DynsymCompare - { + struct DynsymCompare { bool needGNUHash(const LDSymbol& X) const; bool operator()(const LDSymbol* X, const LDSymbol* Y) const; }; - struct SymCompare - { - bool operator()(const LDSymbol* X, const LDSymbol* Y) const - { return (X==Y); } + struct SymCompare { + bool operator()(const LDSymbol* X, const LDSymbol* Y) const { + return (X == Y); + } }; - struct SymPtrHash - { - size_t operator()(const LDSymbol* pKey) const - { + struct SymPtrHash { + size_t operator()(const LDSymbol* pKey) const { return (unsigned((uintptr_t)pKey) >> 4) ^ (unsigned((uintptr_t)pKey) >> 9); } @@ -517,13 +504,12 @@ SymPtrHash, EntryFactory<SymHashEntryType> > HashTableType; - -protected: + protected: ELFObjectReader* m_pObjectReader; // ----- file formats ----- // ELFDynObjFileFormat* m_pDynObjFileFormat; - ELFExecFileFormat* m_pExecFileFormat; + ELFExecFileFormat* m_pExecFileFormat; ELFObjectFileFormat* m_pObjectFileFormat; // GNUInfo @@ -581,7 +567,6 @@ LDSymbol* f_p_End; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_TARGET_GNULDBACKEND_H_
diff --git a/include/mcld/Target/GOT.h b/include/mcld/Target/GOT.h index 01d540f..f458644 100644 --- a/include/mcld/Target/GOT.h +++ b/include/mcld/Target/GOT.h
@@ -6,12 +6,12 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGET_GOT_H -#define MCLD_TARGET_GOT_H +#ifndef MCLD_TARGET_GOT_H_ +#define MCLD_TARGET_GOT_H_ -#include <mcld/LD/LDSection.h> -#include <mcld/LD/SectionData.h> -#include <mcld/Fragment/TargetFragment.h> +#include "mcld/Fragment/TargetFragment.h" +#include "mcld/LD/LDSection.h" +#include "mcld/LD/SectionData.h" namespace mcld { @@ -22,44 +22,37 @@ /** \class GOT * \brief The Global Offset Table */ -class GOT -{ -protected: - GOT(LDSection& pSection); +class GOT { + protected: + explicit GOT(LDSection& pSection); -public: + public: typedef SectionData::iterator iterator; typedef SectionData::const_iterator const_iterator; - template<size_t SIZE> - class Entry : public TargetFragment - { - public: + template <size_t SIZE> + class Entry : public TargetFragment { + public: enum { EntrySize = SIZE }; - public: + public: Entry(uint64_t pValue, SectionData* pParent) - : TargetFragment(Fragment::Target, pParent), - f_Value(pValue) { - } + : TargetFragment(Fragment::Target, pParent), f_Value(pValue) {} virtual ~Entry() {} - uint64_t getValue() const - { return f_Value; } + uint64_t getValue() const { return f_Value; } - void setValue(uint64_t pValue) - { f_Value = pValue; } + void setValue(uint64_t pValue) { f_Value = pValue; } // Override pure virtual function - size_t size() const - { return EntrySize; } + size_t size() const { return EntrySize; } - protected: + protected: uint64_t f_Value; }; -public: + public: virtual ~GOT(); // ----- observers -----// @@ -67,22 +60,20 @@ uint64_t size() const { return m_Section.size(); } const_iterator begin() const { return m_SectionData->begin(); } - iterator begin() { return m_SectionData->begin(); } - const_iterator end () const { return m_SectionData->end(); } - iterator end () { return m_SectionData->end(); } + iterator begin() { return m_SectionData->begin(); } + const_iterator end() const { return m_SectionData->end(); } + iterator end() { return m_SectionData->end(); } - bool empty() const - { return m_SectionData->empty(); } + bool empty() const { return m_SectionData->empty(); } // finalizeSectionSize - set LDSection size virtual void finalizeSectionSize(); -protected: + protected: LDSection& m_Section; SectionData* m_SectionData; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_TARGET_GOT_H_
diff --git a/include/mcld/Target/KeyEntryMap.h b/include/mcld/Target/KeyEntryMap.h index ac11a22..6ff9656 100644 --- a/include/mcld/Target/KeyEntryMap.h +++ b/include/mcld/Target/KeyEntryMap.h
@@ -6,29 +6,27 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGET_KEYENTRYMAP_H -#define MCLD_TARGET_KEYENTRYMAP_H +#ifndef MCLD_TARGET_KEYENTRYMAP_H_ +#define MCLD_TARGET_KEYENTRYMAP_H_ -#include <vector> #include <list> +#include <vector> namespace mcld { /** \class KeyEntryMap * \brief KeyEntryMap is a <const KeyType*, ENTRY*> map. */ -template<typename KEY, typename ENTRY> -class KeyEntryMap -{ -public: - typedef KEY KeyType; +template <typename KEY, typename ENTRY> +class KeyEntryMap { + public: + typedef KEY KeyType; typedef ENTRY EntryType; -private: + private: struct EntryPair { EntryPair(EntryType* pEntry1, EntryType* pEntry2) - : entry1(pEntry1), entry2(pEntry2) - {} + : entry1(pEntry1), entry2(pEntry2) {} EntryType* entry1; EntryType* entry2; @@ -49,49 +47,46 @@ typedef std::vector<Mapping> KeyEntryPool; typedef std::list<EntryPair> PairListType; -public: + public: typedef typename KeyEntryPool::iterator iterator; typedef typename KeyEntryPool::const_iterator const_iterator; -public: + public: /// lookUp - look up the entry mapping to pKey const EntryType* lookUp(const KeyType& pKey) const; - EntryType* lookUp(const KeyType& pKey); + EntryType* lookUp(const KeyType& pKey); /// lookUpFirstEntry - look up the first entry mapping to pKey const EntryType* lookUpFirstEntry(const KeyType& pKey) const; - EntryType* lookUpFirstEntry(const KeyType& pKey); + EntryType* lookUpFirstEntry(const KeyType& pKey); /// lookUpSecondEntry - look up the second entry mapping to pKey const EntryType* lookUpSecondEntry(const KeyType& pKey) const; - EntryType* lookUpSecondEntry(const KeyType& pKey); + EntryType* lookUpSecondEntry(const KeyType& pKey); void record(const KeyType& pKey, EntryType& pEntry); - void record(const KeyType& pKey, - EntryType& pEntry1, - EntryType& pEntry2); + void record(const KeyType& pKey, EntryType& pEntry1, EntryType& pEntry2); - bool empty() const { return m_Pool.empty(); } - size_t size () const { return m_Pool.size(); } + bool empty() const { return m_Pool.empty(); } + size_t size() const { return m_Pool.size(); } const_iterator begin() const { return m_Pool.begin(); } - iterator begin() { return m_Pool.begin(); } - const_iterator end () const { return m_Pool.end(); } - iterator end () { return m_Pool.end(); } + iterator begin() { return m_Pool.begin(); } + const_iterator end() const { return m_Pool.end(); } + iterator end() { return m_Pool.end(); } void reserve(size_t pSize) { m_Pool.reserve(pSize); } -private: + private: KeyEntryPool m_Pool; /// m_Pairs - the EntryPairs PairListType m_Pairs; }; -template<typename KeyType, typename EntryType> -const EntryType* -KeyEntryMap<KeyType, EntryType>::lookUp(const KeyType& pKey) const -{ +template <typename KeyType, typename EntryType> +const EntryType* KeyEntryMap<KeyType, EntryType>::lookUp( + const KeyType& pKey) const { const_iterator mapping, mEnd = m_Pool.end(); for (mapping = m_Pool.begin(); mapping != mEnd; ++mapping) { if (mapping->key == &pKey) { @@ -102,10 +97,8 @@ return NULL; } -template<typename KeyType, typename EntryType> -EntryType* -KeyEntryMap<KeyType, EntryType>::lookUp(const KeyType& pKey) -{ +template <typename KeyType, typename EntryType> +EntryType* KeyEntryMap<KeyType, EntryType>::lookUp(const KeyType& pKey) { iterator mapping, mEnd = m_Pool.end(); for (mapping = m_Pool.begin(); mapping != mEnd; ++mapping) { if (mapping->key == &pKey) { @@ -116,10 +109,9 @@ return NULL; } -template<typename KeyType, typename EntryType> -const EntryType* -KeyEntryMap<KeyType, EntryType>::lookUpFirstEntry(const KeyType& pKey) const -{ +template <typename KeyType, typename EntryType> +const EntryType* KeyEntryMap<KeyType, EntryType>::lookUpFirstEntry( + const KeyType& pKey) const { const_iterator mapping, mEnd = m_Pool.end(); for (mapping = m_Pool.begin(); mapping != mEnd; ++mapping) { if (mapping->key == &pKey) { @@ -130,10 +122,9 @@ return NULL; } -template<typename KeyType, typename EntryType> -EntryType* -KeyEntryMap<KeyType, EntryType>::lookUpFirstEntry(const KeyType& pKey) -{ +template <typename KeyType, typename EntryType> +EntryType* KeyEntryMap<KeyType, EntryType>::lookUpFirstEntry( + const KeyType& pKey) { const_iterator mapping, mEnd = m_Pool.end(); for (mapping = m_Pool.begin(); mapping != mEnd; ++mapping) { if (mapping->key == &pKey) { @@ -144,10 +135,9 @@ return NULL; } -template<typename KeyType, typename EntryType> -const EntryType* -KeyEntryMap<KeyType, EntryType>::lookUpSecondEntry(const KeyType& pKey) const -{ +template <typename KeyType, typename EntryType> +const EntryType* KeyEntryMap<KeyType, EntryType>::lookUpSecondEntry( + const KeyType& pKey) const { const_iterator mapping, mEnd = m_Pool.end(); for (mapping = m_Pool.begin(); mapping != mEnd; ++mapping) { if (mapping->key == &pKey) { @@ -158,10 +148,9 @@ return NULL; } -template<typename KeyType, typename EntryType> -EntryType* -KeyEntryMap<KeyType, EntryType>::lookUpSecondEntry(const KeyType& pKey) -{ +template <typename KeyType, typename EntryType> +EntryType* KeyEntryMap<KeyType, EntryType>::lookUpSecondEntry( + const KeyType& pKey) { const_iterator mapping, mEnd = m_Pool.end(); for (mapping = m_Pool.begin(); mapping != mEnd; ++mapping) { if (mapping->key == &pKey) { @@ -172,22 +161,19 @@ return NULL; } -template<typename KeyType, typename EntryType> -void -KeyEntryMap<KeyType, EntryType>::record(const KeyType& pKey, EntryType& pEntry) -{ +template <typename KeyType, typename EntryType> +void KeyEntryMap<KeyType, EntryType>::record(const KeyType& pKey, + EntryType& pEntry) { Mapping mapping; mapping.key = &pKey; mapping.entry.entry_ptr = &pEntry; m_Pool.push_back(mapping); } -template<typename KeyType, typename EntryType> -void -KeyEntryMap<KeyType, EntryType>::record(const KeyType& pKey, - EntryType& pEntry1, - EntryType& pEntry2) -{ +template <typename KeyType, typename EntryType> +void KeyEntryMap<KeyType, EntryType>::record(const KeyType& pKey, + EntryType& pEntry1, + EntryType& pEntry2) { Mapping mapping; mapping.key = &pKey; m_Pairs.push_back(EntryPair(&pEntry1, &pEntry2)); @@ -195,7 +181,6 @@ m_Pool.push_back(mapping); } -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_TARGET_KEYENTRYMAP_H_
diff --git a/include/mcld/Target/OutputRelocSection.h b/include/mcld/Target/OutputRelocSection.h index 9bf31cc..77cf6c8 100644 --- a/include/mcld/Target/OutputRelocSection.h +++ b/include/mcld/Target/OutputRelocSection.h
@@ -6,13 +6,12 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGET_OUTPUTRELOCSECTION_H -#define MCLD_TARGET_OUTPUTRELOCSECTION_H +#ifndef MCLD_TARGET_OUTPUTRELOCSECTION_H_ +#define MCLD_TARGET_OUTPUTRELOCSECTION_H_ -#include <mcld/LD/RelocData.h> +#include "mcld/LD/RelocData.h" -namespace mcld -{ +namespace mcld { class LDSymbol; class Module; @@ -22,9 +21,8 @@ /** \class OutputRelocSection * \brief Dynamic relocation section for ARM .rel.dyn and .rel.plt */ -class OutputRelocSection -{ -public: +class OutputRelocSection { + public: OutputRelocSection(Module& pModule, LDSection& pSection); ~OutputRelocSection(); @@ -32,7 +30,7 @@ /// create - create an dynamic relocation entry Relocation* create(); - void reserveEntry(size_t pNum=1); + void reserveEntry(size_t pNum = 1); Relocation* consumeEntry(); @@ -41,15 +39,14 @@ bool addSymbolToDynSym(LDSymbol& pSymbol); // ----- observers ----- // - bool empty() - { return m_pRelocData->empty(); } + bool empty() { return m_pRelocData->empty(); } size_t numOfRelocs(); -private: + private: typedef RelocData::iterator RelocIterator; -private: + private: Module& m_Module; /// m_RelocData - the output RelocData which contains the dynamic @@ -63,7 +60,6 @@ RelocIterator m_ValidEntryIterator; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_TARGET_OUTPUTRELOCSECTION_H_
diff --git a/include/mcld/Target/PLT.h b/include/mcld/Target/PLT.h index da6d86f..58f7676 100644 --- a/include/mcld/Target/PLT.h +++ b/include/mcld/Target/PLT.h
@@ -6,12 +6,12 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGET_PLT_H -#define MCLD_TARGET_PLT_H +#ifndef MCLD_TARGET_PLT_H_ +#define MCLD_TARGET_PLT_H_ -#include <mcld/LD/LDSection.h> -#include <mcld/LD/SectionData.h> -#include <mcld/Fragment/TargetFragment.h> +#include "mcld/Fragment/TargetFragment.h" +#include "mcld/LD/LDSection.h" +#include "mcld/LD/SectionData.h" namespace mcld { @@ -21,60 +21,47 @@ /** \class PLTEntryDefaultBase * \brief PLTEntryDefaultBase provides the default interface for PLT Entry */ -class PLTEntryBase : public TargetFragment -{ -public: - PLTEntryBase(SectionData& pParent) - : TargetFragment(Fragment::Target, &pParent), m_pValue(NULL) - {} +class PLTEntryBase : public TargetFragment { + public: + explicit PLTEntryBase(SectionData& pParent) + : TargetFragment(Fragment::Target, &pParent), m_pValue(NULL) {} - virtual ~PLTEntryBase() - { - free(m_pValue); - } + virtual ~PLTEntryBase() { free(m_pValue); } - void setValue(unsigned char* pValue) - { m_pValue = pValue; } + void setValue(unsigned char* pValue) { m_pValue = pValue; } - const unsigned char* getValue() const - { return m_pValue; } + const unsigned char* getValue() const { return m_pValue; } - //Used by llvm::cast<>. - static bool classof(const Fragment *O) - { return true; } + // Used by llvm::cast<>. + static bool classof(const Fragment* O) { return true; } -protected: + protected: unsigned char* m_pValue; }; /** \class PLT * \brief Procedure linkage table */ -class PLT -{ -public: +class PLT { + public: typedef SectionData::iterator iterator; typedef SectionData::const_iterator const_iterator; - template<size_t SIZE, typename EntryBase = PLTEntryBase> - class Entry : public EntryBase - { - public: + template <size_t SIZE, typename EntryBase = PLTEntryBase> + class Entry : public EntryBase { + public: enum { EntrySize = SIZE }; - public: - Entry(SectionData& pParent) - : EntryBase(pParent) - {} + public: + explicit Entry(SectionData& pParent) : EntryBase(pParent) {} virtual ~Entry() {} - size_t size() const - { return EntrySize; } + size_t size() const { return EntrySize; } }; -public: - PLT(LDSection& pSection); + public: + explicit PLT(LDSection& pSection); virtual ~PLT(); @@ -84,16 +71,15 @@ uint64_t addr() const { return m_Section.addr(); } const_iterator begin() const { return m_pSectionData->begin(); } - iterator begin() { return m_pSectionData->begin(); } - const_iterator end () const { return m_pSectionData->end(); } - iterator end () { return m_pSectionData->end(); } + iterator begin() { return m_pSectionData->begin(); } + const_iterator end() const { return m_pSectionData->end(); } + iterator end() { return m_pSectionData->end(); } -protected: + protected: LDSection& m_Section; SectionData* m_pSectionData; }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_TARGET_PLT_H_
diff --git a/include/mcld/Target/TargetLDBackend.h b/include/mcld/Target/TargetLDBackend.h index a1a5f1c..858c66e 100644 --- a/include/mcld/Target/TargetLDBackend.h +++ b/include/mcld/Target/TargetLDBackend.h
@@ -6,29 +6,28 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGET_TARGETLDBACKEND_H -#define MCLD_TARGET_TARGETLDBACKEND_H +#ifndef MCLD_TARGET_TARGETLDBACKEND_H_ +#define MCLD_TARGET_TARGETLDBACKEND_H_ +#include "mcld/LD/GarbageCollection.h" +#include "mcld/Support/Compiler.h" #include <llvm/ADT/StringRef.h> #include <llvm/Support/DataTypes.h> -#include <mcld/LD/GarbageCollection.h> namespace mcld { class ArchiveReader; +class BranchIslandFactory; class BinaryReader; class BinaryWriter; -class BranchIslandFactory; class DynObjReader; class DynObjWriter; class ExecWriter; class FileOutputBuffer; -class SectionReachedListMap; class IRBuilder; class Input; class LDSection; class LDSymbol; -class Layout; class LinkerConfig; class Module; class ObjectBuilder; @@ -37,27 +36,24 @@ class Relocator; class ResolveInfo; class SectionData; +class SectionReachedListMap; class StubFactory; //===----------------------------------------------------------------------===// /// TargetLDBackend - Generic interface to target specific assembler backends. //===----------------------------------------------------------------------===// -class TargetLDBackend -{ - TargetLDBackend(const TargetLDBackend &); // DO NOT IMPLEMENT - void operator=(const TargetLDBackend &); // DO NOT IMPLEMENT +class TargetLDBackend { + protected: + explicit TargetLDBackend(const LinkerConfig& pConfig); -protected: - TargetLDBackend(const LinkerConfig& pConfig); - -public: + public: virtual ~TargetLDBackend(); // ----- target dependent ----- // - virtual void initTargetSegments(IRBuilder& pBuilder) { } - virtual void initTargetSections(Module& pModule, ObjectBuilder& pBuilder) { } - virtual void initTargetSymbols(IRBuilder& pBuilder, Module& pModule) { } - virtual void initTargetRelocation(IRBuilder& pBuilder) { } + virtual void initTargetSegments(IRBuilder& pBuilder) {} + virtual void initTargetSections(Module& pModule, ObjectBuilder& pBuilder) {} + virtual void initTargetSymbols(IRBuilder& pBuilder, Module& pModule) {} + virtual void initTargetRelocation(IRBuilder& pBuilder) {} virtual bool initStandardSymbols(IRBuilder& pBuilder, Module& pModule) = 0; virtual bool initRelocator() = 0; @@ -67,10 +63,10 @@ // ----- format dependent ----- // virtual ArchiveReader* createArchiveReader(Module&) = 0; - virtual ObjectReader* createObjectReader(IRBuilder&) = 0; - virtual DynObjReader* createDynObjReader(IRBuilder&) = 0; - virtual BinaryReader* createBinaryReader(IRBuilder&) = 0; - virtual ObjectWriter* createWriter() = 0; + virtual ObjectReader* createObjectReader(IRBuilder&) = 0; + virtual DynObjReader* createDynObjReader(IRBuilder&) = 0; + virtual BinaryReader* createBinaryReader(IRBuilder&) = 0; + virtual ObjectWriter* createWriter() = 0; virtual bool initStdSections(ObjectBuilder& pBuilder) = 0; @@ -114,25 +110,27 @@ /// mergeSection - merge target dependent sections. virtual bool mergeSection(Module& pModule, const Input& pInputFile, - LDSection& pInputSection) - { return true; } + LDSection& pInputSection) { + return true; + } /// setUpReachedSectionsForGC - set the reference between two sections for /// some special target sections. GC will set up the reference for the Regular /// and BSS sections. Backends can also set up the reference if need. - virtual void setUpReachedSectionsForGC(const Module& pModule, - GarbageCollection::SectionReachedListMap& pSectReachedListMap) const { } + virtual void setUpReachedSectionsForGC( + const Module& pModule, + GarbageCollection::SectionReachedListMap& pSectReachedListMap) const {} /// updateSectionFlags - update pTo's flags when merging pFrom /// update the output section flags based on input section flags. /// FIXME: (Luba) I know ELF need to merge flags, but I'm not sure if /// MachO and COFF also need this. - virtual bool updateSectionFlags(LDSection& pTo, const LDSection& pFrom) - { return true; } + virtual bool updateSectionFlags(LDSection& pTo, const LDSection& pFrom) { + return true; + } /// readSection - read a target dependent section - virtual bool readSection(Input& pInput, SectionData& pSD) - { return true; } + virtual bool readSection(Input& pInput, SectionData& pSD) { return true; } /// sizeInterp - compute the size of program interpreter's name /// In ELF executables, this is the length of dynamic linker's path name @@ -147,7 +145,7 @@ virtual bool initTargetStubs() { return true; } virtual BranchIslandFactory* getBRIslandFactory() = 0; - virtual StubFactory* getStubFactory() = 0; + virtual StubFactory* getStubFactory() = 0; /// relax - the relaxation pass virtual bool relax(Module& pModule, IRBuilder& pBuilder) = 0; @@ -175,16 +173,19 @@ /// mayHaveUnsafeFunctionPointerAccess - check if the section may have unsafe /// function pointer access - virtual bool mayHaveUnsafeFunctionPointerAccess(const LDSection& pSection) - const = 0; + virtual bool mayHaveUnsafeFunctionPointerAccess( + const LDSection& pSection) const = 0; -protected: + protected: const LinkerConfig& config() const { return m_Config; } -private: + private: const LinkerConfig& m_Config; + + private: + DISALLOW_COPY_AND_ASSIGN(TargetLDBackend); }; -} // End mcld namespace +} // namespace mcld -#endif +#endif // MCLD_TARGET_TARGETLDBACKEND_H_
diff --git a/include/mcld/TargetOptions.h b/include/mcld/TargetOptions.h index c856104..9672054 100644 --- a/include/mcld/TargetOptions.h +++ b/include/mcld/TargetOptions.h
@@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_TARGETOPTIONS_H -#define MCLD_TARGETOPTIONS_H +#ifndef MCLD_TARGETOPTIONS_H_ +#define MCLD_TARGETOPTIONS_H_ #include <llvm/ADT/Triple.h> @@ -19,19 +19,14 @@ * \brief TargetOptions collects the options that dependent on a target * backend. */ -class TargetOptions -{ -public: - enum Endian { - Little, - Big, - Unknown - }; +class TargetOptions { + public: + enum Endian { Little, Big, Unknown }; -public: + public: TargetOptions(); - TargetOptions(const std::string& pTriple); + explicit TargetOptions(const std::string& pTriple); ~TargetOptions(); @@ -58,7 +53,7 @@ void setEndian(Endian pEndian) { m_Endian = pEndian; } bool isLittleEndian() const { return (Little == m_Endian); } - bool isBigEndian () const { return (Big == m_Endian); } + bool isBigEndian() const { return (Big == m_Endian); } unsigned int bitclass() const { return m_BitClass; } @@ -67,17 +62,15 @@ bool is32Bits() const { return (32 == m_BitClass); } bool is64Bits() const { return (64 == m_BitClass); } -private: + private: llvm::Triple m_Triple; std::string m_ArchName; std::string m_TargetCPU; std::string m_TargetFS; Endian m_Endian; unsigned int m_BitClass; - }; -} // namespace of mcld +} // namespace mcld -#endif - +#endif // MCLD_TARGETOPTIONS_H_