1/*
2    Title:     Export memory in a portable format
3    Author:    David C. J. Matthews.
4
5    Copyright (c) 2006, 2015, 2017 David C. J. Matthews
6
7
8    This library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public
10    License version 2.1 as published by the Free Software Foundation.
11
12    This library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR H PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
16
17    You should have received a copy of the GNU Lesser General Public
18    License along with this library; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20*/
21
22#ifndef PEXPORT_H_INCLUDED
23#define PEXPORT_H_INCLUDED
24
25#ifdef HAVE_TCHAR_H
26#include <tchar.h>
27#else
28typedef char TCHAR;
29#endif
30
31#include <vector>
32
33#include "scanaddrs.h" // For base class
34#include "exporter.h"
35#include "globals.h"
36
37class PExport: public Exporter, public ScanAddress
38{
39public:
40    PExport();
41    virtual ~PExport();
42public:
43    virtual void exportStore(void);
44
45private:
46    // ScanAddress overrides
47    virtual void ScanConstant(PolyObject *base, byte *addrOfConst, ScanRelocationKind code);
48    // At the moment we should only get calls to ScanConstant.
49    virtual PolyObject *ScanObjectAddress(PolyObject *base) { return base; }
50
51private:
52    size_t getIndex(PolyObject *p);
53    void printAddress(void *p);
54    void printValue(PolyWord q);
55    void printObject(PolyObject *p);
56
57    // We don't use the relocation code so just provide a dummy function here.
58    virtual PolyWord createRelocation(PolyWord p, void *relocAddr) { return p; }
59
60    std::vector<PolyObject *> pMap;
61
62};
63
64// Import a file in the portable format and return a pointer to the root object.
65PolyObject *ImportPortable(const TCHAR *fileName);
66
67#endif
68