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