OpenASIP 2.2
Loading...
Searching...
No Matches
BinaryWriter.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file BinaryWriter.cc
26 *
27 * Definition of BinaryWriter class.
28 *
29 * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
30 * @author Pekka Jääskeläinen 2006 (pjaaskel-no.spam-cs.tut.fi)
31 *
32 * @note rating: yellow
33 */
34
35#include "BinaryWriter.hh"
36
37#include "SectionWriter.hh"
38#include "ValueReplacer.hh"
40
41namespace TPEF {
42
43using ReferenceManager::SafePointer;
44
45/**
46 * Constructor.
47 */
50
51/**
52 * Destructor.
53 */
56
57/**
58 * Stores a binary program representation to given binary stream.
59 *
60 * @param stream Stream where to write the program representation.
61 * @param bin Binary class hierarchy to write.
62 */
63void
64BinaryWriter::writeBinary(BinaryStream& stream, const Binary* bin) const {
65
66 assert(writerToUse_ != NULL);
67
68 // init referencemanager and replacers
72
73 try {
74 writerToUse_->actualWriteBinary(stream, bin);
75 } catch (Exception& e) {
76 std::cerr << "Failed to write binary. Maybe the disk is full?" << std::endl << std::endl;;
77 exit(-1);
78 }
79
80 // try catch blocks are just for debug use right now
81 try {
83 } catch(const MissingKeys &e) {
84 std::cerr << "Missing keys during writing binary file! : \n"
85 << e.procedureName() << std::endl
86 << e.errorMessage() << std::endl
87 << std::endl;
88
89 assert(false);
90 } catch( ... ) {
91 std::cerr << "Problems with stream during writing binary file"
92 << std::endl;
93 assert(false);
94 }
95
96 // finalize was called successfully so init must be run again
98
99 try {
101 } catch (Exception& e) {
102 std::cerr << "Failed to finalize binary." << std::endl;
103 exit(-1);
104 }
105
106 // try catch blocks are just for debug use right now
107 try {
109 } catch(const MissingKeys &e) {
110 std::cerr << "Missing keys during finalization of writing! \n"
111 << e.procedureName() << std::endl
112 << e.errorMessage() << std::endl
113 << std::endl;
114 assert(false);
115 } catch( ... ) {
116 std::cerr << "Problems with stream during finalization of writing"
117 << std::endl;
118 assert(false);
119 }
120
122}
123
124/**
125 * Sets the concrete binary writer to be used for writing binary program
126 * representations to a binary stream.
127 *
128 * @param writer Writer instance that we use for writing binary.
129 */
130void
132 writerToUse_ = writer;
133}
134
135}
#define assert(condition)
std::string errorMessage() const
Definition Exception.cc:123
std::string procedureName() const
void setWriter(const BinaryWriter *writer)
virtual ~BinaryWriter()
const BinaryWriter * writerToUse_
Contains concrete writer instance that is used for writing binary.
virtual void actualWriteBinary(BinaryStream &stream, const Binary *bin) const =0
Does real writing of binary.
void writeBinary(BinaryStream &stream, const Binary *bin) const
static void finalizeBinary(BinaryStream &stream, const Binary *binaryToFinalize, const BinaryWriter *writer)
static void finalize()
static void initialize(BinaryStream &stream)