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

Subversion Repositories lxp32

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 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
public:
23
        virtual ~OutputWriter() {}
24
        virtual void write(const char *data,std::size_t n)=0;
25
        virtual void abort() {}
26
        void pad(std::size_t size);
27
};
28
 
29
/*
30
 * Write a regular binary file
31
 */
32
 
33
class BinaryOutputWriter : public OutputWriter {
34
        std::string _filename;
35
        std::ofstream _os;
36
public:
37
        BinaryOutputWriter(const std::string &filename);
38
        virtual void write(const char *data,std::size_t n) override;
39
        virtual void abort() override;
40
};
41
 
42
/*
43
 * Write a text file (one word per line)
44
 */
45
 
46
class TextOutputWriter : public OutputWriter {
47
public:
48
        enum Format {Bin,Dec,Hex};
49
private:
50
        std::string _filename;
51
        std::ofstream _os;
52
        std::string _buf;
53
        Format _fmt;
54
public:
55
        TextOutputWriter(const std::string &filename,Format f);
56
        ~TextOutputWriter();
57
        virtual void write(const char *data,std::size_t n) override;
58
        virtual void abort() override;
59
};
60
 
61
#endif

powered by: WebSVN 2.1.0

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