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