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