• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- FileAction.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/MC/FileAction.h"
10 
11 #include "mcld/MC/Input.h"
12 #include "mcld/MC/InputBuilder.h"
13 
14 namespace mcld {
15 
16 //===----------------------------------------------------------------------===//
17 // ContextAction
18 //===----------------------------------------------------------------------===//
ContextAction(unsigned int pPosition)19 ContextAction::ContextAction(unsigned int pPosition) : InputAction(pPosition) {
20 }
21 
activate(InputBuilder & pBuilder) const22 bool ContextAction::activate(InputBuilder& pBuilder) const {
23   Input* input = *pBuilder.getCurrentNode();
24 
25   if (input->hasContext())
26     return false;
27 
28   // already got type - for example, bitcode
29   if (input->type() == Input::Script || input->type() == Input::Object ||
30       input->type() == Input::DynObj || input->type() == Input::Archive)
31     return false;
32 
33   return pBuilder.setContext(*input);
34 }
35 
36 //===----------------------------------------------------------------------===//
37 // MemoryAreaAction
38 //===----------------------------------------------------------------------===//
MemoryAreaAction(unsigned int pPosition,FileHandle::OpenModeEnum pMode,FileHandle::PermissionEnum pPerm)39 MemoryAreaAction::MemoryAreaAction(unsigned int pPosition,
40                                    FileHandle::OpenModeEnum pMode,
41                                    FileHandle::PermissionEnum pPerm)
42     : InputAction(pPosition), m_Mode(pMode), m_Permission(pPerm) {
43 }
44 
activate(InputBuilder & pBuilder) const45 bool MemoryAreaAction::activate(InputBuilder& pBuilder) const {
46   Input* input = *pBuilder.getCurrentNode();
47 
48   if (input->hasMemArea())
49     return false;
50 
51   // already got type - for example, bitcode
52   if (input->type() == Input::Script || input->type() == Input::Object ||
53       input->type() == Input::DynObj || input->type() == Input::Archive)
54     return false;
55 
56   return pBuilder.setMemory(*input, m_Mode, m_Permission);
57 }
58 
59 }  // namespace mcld
60