• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- RPNExpr.cpp --------------------------------------------------------===//
2 //
3 //                     The MCLinker Project
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #include "mcld/Script/RpnExpr.h"
10 
11 #include "mcld/Script/ExprToken.h"
12 #include "mcld/Script/Operand.h"
13 #include "mcld/Script/Operator.h"
14 #include "mcld/Support/GCFactory.h"
15 #include "mcld/Support/raw_ostream.h"
16 
17 #include <llvm/Support/ManagedStatic.h>
18 #include <llvm/Support/Casting.h>
19 
20 namespace mcld {
21 
22 typedef GCFactory<RpnExpr, MCLD_SYMBOLS_PER_INPUT> ExprFactory;
23 static llvm::ManagedStatic<ExprFactory> g_ExprFactory;
24 
25 //===----------------------------------------------------------------------===//
26 // RpnExpr
27 //===----------------------------------------------------------------------===//
RpnExpr()28 RpnExpr::RpnExpr() {
29 }
30 
~RpnExpr()31 RpnExpr::~RpnExpr() {
32 }
33 
hasDot() const34 bool RpnExpr::hasDot() const {
35   for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
36     if ((*it)->kind() == ExprToken::OPERAND &&
37         llvm::cast<Operand>(*it)->isDot())
38       return true;
39   }
40   return false;
41 }
42 
dump() const43 void RpnExpr::dump() const {
44   for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
45     (*it)->dump();
46     mcld::outs() << " ";
47   }
48 }
49 
push_back(ExprToken * pToken)50 void RpnExpr::push_back(ExprToken* pToken) {
51   m_TokenQueue.push_back(pToken);
52 }
53 
create()54 RpnExpr* RpnExpr::create() {
55   RpnExpr* result = g_ExprFactory->allocate();
56   new (result) RpnExpr();
57   return result;
58 }
59 
destroy(RpnExpr * & pRpnExpr)60 void RpnExpr::destroy(RpnExpr*& pRpnExpr) {
61   g_ExprFactory->destroy(pRpnExpr);
62   g_ExprFactory->deallocate(pRpnExpr);
63   pRpnExpr = NULL;
64 }
65 
clear()66 void RpnExpr::clear() {
67   g_ExprFactory->clear();
68 }
69 
insert(iterator pPosition,ExprToken * pToken)70 RpnExpr::iterator RpnExpr::insert(iterator pPosition, ExprToken* pToken) {
71   return m_TokenQueue.insert(pPosition, pToken);
72 }
73 
erase(iterator pPosition)74 void RpnExpr::erase(iterator pPosition) {
75   m_TokenQueue.erase(pPosition);
76 }
77 
78 // buildHelperExpr - build the helper expr:
79 //                   ADDR ( `output_sect' ) + SIZEOF ( `output_sect' )
buildHelperExpr(SectionMap::iterator pIter)80 RpnExpr* RpnExpr::buildHelperExpr(SectionMap::iterator pIter) {
81   RpnExpr* expr = RpnExpr::create();
82   expr->push_back(SectDescOperand::create(*pIter));
83   expr->push_back(&Operator::create<Operator::ADDR>());
84   expr->push_back(SectDescOperand::create(*pIter));
85   expr->push_back(&Operator::create<Operator::SIZEOF>());
86   expr->push_back(&Operator::create<Operator::ADD>());
87   return expr;
88 }
89 
90 // buildHelperExpr - build the helper expr: `fragment'
buildHelperExpr(Fragment & pFrag)91 RpnExpr* RpnExpr::buildHelperExpr(Fragment& pFrag) {
92   RpnExpr* expr = RpnExpr::create();
93   expr->push_back(FragOperand::create(pFrag));
94   return expr;
95 }
96 
97 }  // namespace mcld
98