OpenCores
URL https://opencores.org/ocsvn/lxp32/lxp32/trunk

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [tools/] [src/] [lxp32asm/] [outputwriter.h] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 ring0_mipt
/*
2
 * Copyright (c) 2016 by Alex I. Kuznetsov.
3
 *
4
 * Part of the LXP32 CPU IP core.
5
 *
6
 * This module defines the OutputWriter abstract class and its
7
 * derived classes. These classes are used to write LXP32 executable
8
 * code in different formats.
9
 */
10
 
11
#ifndef OUTPUTWRITER_H_INCLUDED
12
#define OUTPUTWRITER_H_INCLUDED
13
 
14
#include <fstream>
15
#include <string>
16
 
17
/*
18
 * An abstract base class for all writers
19
 */
20
 
21
class OutputWriter {
22
        std::size_t _size=0;
23
public:
24
        virtual ~OutputWriter() {}
25
        virtual void write(const char *data,std::size_t n);
26
        virtual void abort() {}
27
        void pad(std::size_t size);
28
        std::size_t size() const;
29
protected:
30
        virtual void writeData(const char *data,std::size_t n)=0;
31
};
32
 
33
/*
34
 * Write a regular binary file
35
 */
36
 
37
class BinaryOutputWriter : public OutputWriter {
38
        std::string _filename;
39
        std::ofstream _os;
40
public:
41
        BinaryOutputWriter(const std::string &filename);
42
        virtual void abort() override;
43
protected:
44
        virtual void writeData(const char *data,std::size_t n) override;
45
};
46
 
47
/*
48
 * Write a text file (one word per line)
49
 */
50
 
51
class TextOutputWriter : public OutputWriter {
52
public:
53
        enum Format {Bin,Dec,Hex};
54
private:
55
        std::string _filename;
56
        std::ofstream _os;
57
        std::string _buf;
58
        Format _fmt;
59
public:
60
        TextOutputWriter(const std::string &filename,Format f);
61
        ~TextOutputWriter();
62
        virtual void abort() override;
63
protected:
64
        virtual void writeData(const char *data,std::size_t n) override;
65
};
66
 
67
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.