aboutsummaryrefslogtreecommitdiff
path: root/lib/MC/FileAction.cpp
blob: 6e6199d909c6e90a89139b9738fdf27a05500e33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//===- FileAction.cpp -----------------------------------------------------===//
//
//                     The MCLinker Project
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <mcld/MC/FileAction.h>

#include <mcld/MC/Input.h>
#include <mcld/MC/InputBuilder.h>

using namespace mcld;

//===----------------------------------------------------------------------===//
// ContextAction
//===----------------------------------------------------------------------===//
ContextAction::ContextAction(unsigned int pPosition) : InputAction(pPosition) {
}

bool ContextAction::activate(InputBuilder& pBuilder) const {
  Input* input = *pBuilder.getCurrentNode();

  if (input->hasContext())
    return false;

  // already got type - for example, bitcode
  if (input->type() == Input::Script || input->type() == Input::Object ||
      input->type() == Input::DynObj || input->type() == Input::Archive)
    return false;

  return pBuilder.setContext(*input);
}

//===----------------------------------------------------------------------===//
// MemoryAreaAction
//===----------------------------------------------------------------------===//
MemoryAreaAction::MemoryAreaAction(unsigned int pPosition,
                                   FileHandle::OpenModeEnum pMode,
                                   FileHandle::PermissionEnum pPerm)
    : InputAction(pPosition), m_Mode(pMode), m_Permission(pPerm) {
}

bool MemoryAreaAction::activate(InputBuilder& pBuilder) const {
  Input* input = *pBuilder.getCurrentNode();

  if (input->hasMemArea())
    return false;

  // already got type - for example, bitcode
  if (input->type() == Input::Script || input->type() == Input::Object ||
      input->type() == Input::DynObj || input->type() == Input::Archive)
    return false;

  return pBuilder.setMemory(*input, m_Mode, m_Permission);
}