srecord  1.65.0
c.h
Go to the documentation of this file.
1 //
2 // srecord - manipulate eprom load files
3 // Copyright (C) 1998, 1999, 2001-2003, 2005-2008, 2010 Peter Miller
4 // Copyright (C) 2014 Scott Finneran
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this program. If not, see
18 // <http://www.gnu.org/licenses/>.
19 //
20 
21 #ifndef SRECORD_OUTPUT_FILE_C_H
22 #define SRECORD_OUTPUT_FILE_C_H
23 
24 #include <srecord/output/file.h>
25 #include <srecord/interval.h>
26 
27 namespace srecord
28 {
29 
30 /**
31  * The srecord::output_file_c class is used to represent an output file
32  * which emits C code.
33  */
35  public output_file
36 {
37 public:
38  /**
39  * The destructor.
40  */
41  virtual ~output_file_c();
42 
43 private:
44  /**
45  * The constructor.
46  *
47  * @param file_name
48  * The file name to open to write data to. The name "-" is
49  * understood to mean the standard output.
50  */
51  output_file_c(const std::string &file_name);
52 
53 public:
54  /**
55  * The create class method is used to create new dynamically
56  * allocated instances of this class.
57  *
58  * @param file_name
59  * The file name to open to write data to. The name "-" is
60  * understood to mean the standard output.
61  */
62  static pointer create(const std::string &file_name);
63 
64 protected:
65  // See base class for documentation.
66  void write(const record &);
67 
68  // See base class for documentation.
69  void line_length_set(int);
70 
71  // See base class for documentation.
72  void address_length_set(int);
73 
74  // See base class for documentation.
76 
77  // See base class for documentation.
78  bool preferred_block_size_set(int nbytes);
79 
80  // See base class for documentation.
81  void command_line(arglex_tool *cmdln);
82 
83  // See base class for documentation.
84  const char *format_name() const;
85 
86 private:
87  /**
88  * The prefix instance variable is used to remember the variable
89  * name prefix to be used in the output.
90  */
91  std::string prefix;
92 
93  /**
94  * The prefix instance variable is used to remember the definition
95  * prefix to be emitted in the header.
96  */
97  std::string header_prefix;
98 
99  /**
100  * The postfix instance variable is used to remember the definition
101  * postfix to be emitted in the header.
102  */
103  std::string header_postfix;
104 
105  /**
106  * The taddr instance variable is used to remember the
107  * termination address, to be emitted in the footer.
108  */
109  unsigned long taddr;
110 
111  /**
112  * The range instance variable is used to remember the range
113  * of addresses present in the output.
114  */
115  interval range;
116 
117  /**
118  * The header_done instance variable is used t remember whether
119  * the emit_header method has been called.
120  */
121  bool header_done;
122 
123  /**
124  * The column instance variable is used to remember the current
125  * printing column on the line.
126  */
127  int column;
128 
129  /**
130  * The current_address instance variabel is used to remember
131  * the current address that the file is positioned at. This is
132  * used to know whether we need to add padding.
133  */
134  unsigned long current_address;
135 
136  /**
137  * The line_length instance variable is used to remember the
138  * maximum line length. The output usually does not exceed it.
139  */
140  int line_length;
141 
142  /**
143  * The address_length instance variable is used toremember how
144  * many bytes to emit when emitting addresses.
145  */
146  int address_length;
147 
148  /**
149  * The constant instance variable is used to remember whether or
150  * not to use the "const" keyword.
151  */
152  bool constant;
153 
154  /**
155  * The include instance variable is used to remember whether or not
156  * to generate an include file.
157  */
158  bool include;
159 
160  /**
161  * The include_file_name instance variable is used to remember the
162  * name of the include file to be generated.
163  */
164  std::string include_file_name;
165 
166  /**
167  * The output_word instance variable is used to remember whether or not
168  * the input bytes should be emitted as word.
169  */
170  bool output_word;
171 
172  /**
173  * The hex_style instance variable is used to remember whether or
174  * not we are to output number in hexadecimal (true) or decimal
175  * (false).
176  */
177  bool hex_style;
178 
179  /**
180  * The section_style instance variable is used to remember whether
181  * or not the output is to contain "sections".
182  *
183  * In non-section output, padding of 0xFF is used to pad the data
184  * for correct addressing. In section output, tables of addresses
185  * and lenthgs are emitted, and the actual data is intended to be
186  * relocated at run time.
187  */
188  bool section_style;
189 
190  /**
191  * The emit_header method is used to emit the initial portion
192  * of the array declaration. It does nothing if header_done
193  * is true.
194  */
195  void emit_header();
196 
197  /**
198  * The emit_byte method is used to emit a single byte. It uses
199  * column to track the position, so as not to exceed line_length.
200  */
201  void emit_byte(int);
202 
203  /**
204  * The emit_byte method is used to emit a single byte. It uses
205  * column to track the position, so as not to exceed line_length.
206  */
207  void emit_word(unsigned int);
208 
209  /**
210  * The format_address method is used to format an address, taking
211  * the hex_style and address_length instance variable settings.
212  *
213  * @param addr
214  * The adress to be formatted
215  */
216  std::string format_address(unsigned long addr);
217 
218  /**
219  * The default constructor. Do not use.
220  */
221  output_file_c();
222 
223  /**
224  * The copy constructor. Do not use.
225  */
226  output_file_c(const output_file_c &);
227 
228  /**
229  * The assignment operator. Do not use.
230  */
231  output_file_c &operator=(const output_file_c &);
232 };
233 
234 };
235 
236 // vim: set ts=8 sw=4 et :
237 #endif // SRECORD_OUTPUT_FILE_C_H
The srecord::arglex_tool is used to parse command line with srec-specific arguments.
Definition: tool.h:41
The interval class is used to represent a set of integer values, usually composed of runs of adjacent...
Definition: interval.h:36
The srecord::output_file_c class is used to represent an output file which emits C code.
Definition: c.h:36
bool preferred_block_size_set(int nbytes)
The preferred_block_size_set method is is to set a precific number of bytes for the preferred block s...
void command_line(arglex_tool *cmdln)
The command_line method is used by arglex_srec::get_output when parsing the command line,...
const char * format_name() const
The format_name method is used to obtain the name of this output format.
void address_length_set(int)
The address_length_set method is used to set the minimum number of bytes to be written for addresses ...
void line_length_set(int)
The set_line_length method is used to set the maximum length of an output line, for those formats for...
static pointer create(const std::string &file_name)
The create class method is used to create new dynamically allocated instances of this class.
int preferred_block_size_get() const
The preferred_block_size_get method is used to get the proferred block size of the output fformat.
virtual ~output_file_c()
The destructor.
void write(const record &)
The write method is used to write a recordonto an output.
The srecord::output_file class is used to represent a generic output file.
Definition: file.h:35
std::shared_ptr< output > pointer
Definition: output.h:41
The srecord::record class is used to represent a data record read from a file.
Definition: record.h:35