Home | History | Annotate | Download | only in Script
      1 //===- ScriptReader.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/ScriptReader.h>
     10 #include <mcld/Script/ScriptScanner.h>
     11 #include <mcld/Script/ScriptFile.h>
     12 #include <mcld/MC/Input.h>
     13 #include <mcld/Support/MemoryArea.h>
     14 
     15 #include <llvm/ADT/StringRef.h>
     16 
     17 #include <istream>
     18 #include <sstream>
     19 
     20 using namespace mcld;
     21 
     22 ScriptReader::ScriptReader(GroupReader& pGroupReader)
     23   : m_GroupReader(pGroupReader)
     24 {
     25 }
     26 
     27 ScriptReader::~ScriptReader()
     28 {
     29 }
     30 
     31 /// isMyFormat
     32 bool ScriptReader::isMyFormat(Input& input, bool &doContinue) const
     33 {
     34   doContinue = true;
     35   // always return true now
     36   return true;
     37 }
     38 
     39 bool ScriptReader::readScript(const LinkerConfig& pConfig,
     40                               ScriptFile& pScriptFile)
     41 {
     42   bool result = false;
     43   Input& input = pScriptFile.input();
     44   size_t size = input.memArea()->size();
     45   llvm::StringRef region = input.memArea()->request(input.fileOffset(), size);
     46   std::stringbuf buf(region.data());
     47 
     48   std::istream in(&buf);
     49   ScriptScanner scanner(&in);
     50   ScriptParser parser(pConfig,
     51                       pScriptFile,
     52                       scanner,
     53                       m_GroupReader);
     54   result = (0 == parser.parse());;
     55 
     56   return result;
     57 }
     58 
     59