libwreport  2.8
opcode.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005--2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Author: Enrico Zini <enrico@enricozini.com>
18  */
19 
20 #ifndef WREPORT_OPCODE_H
21 #define WREPORT_OPCODE_H
22 
29 #include <wreport/varinfo.h>
30 #include <vector>
31 #include <cstdio>
32 
33 namespace wreport {
34 
35 namespace opcode {
36 struct Visitor;
37 }
38 
39 struct Vartable;
40 struct DTable;
41 
50 struct Opcodes
51 {
53  const std::vector<Varcode>& vals;
55  unsigned begin;
57  unsigned end;
58 
60  Opcodes(const std::vector<Varcode>& vals) : vals(vals), begin(0), end(vals.size()) {}
62  Opcodes(const std::vector<Varcode>& vals, unsigned begin, unsigned end)
63  : vals(vals), begin(begin), end(end) {}
65  Opcodes(const Opcodes& o) : vals(o.vals), begin(o.begin), end(o.end) {}
66 
73  {
74  begin = o.begin;
75  end = o.end;
76  return *this;
77  }
78 
80  Varcode operator[](unsigned i) const
81  {
82  if (begin + i > end)
83  return 0;
84  else
85  return vals[begin + i];
86  }
87 
89  unsigned size() const { return end - begin; }
90 
92  bool empty() const { return begin == end; }
93 
95  Varcode head() const
96  {
97  if (begin == end)
98  return 0;
99  return vals[begin];
100  }
101 
107  Opcodes next() const
108  {
109  if (begin == end)
110  return *this;
111  else
112  return Opcodes(vals, begin+1, end);
113  }
114 
116  Opcodes sub(unsigned skip) const
117  {
118  if (begin + skip > end)
119  return Opcodes(vals, end, end);
120  else
121  return Opcodes(vals, begin + skip, end);
122  }
123 
125  Opcodes sub(unsigned skip, unsigned len) const
126  {
127  if (begin + skip > end)
128  return Opcodes(vals, end, end);
129  else if (begin + skip + len > end)
130  return Opcodes(vals, begin + skip, end);
131  else
132  return Opcodes(vals, begin + skip, begin + skip + len);
133  }
134 
140  void visit(opcode::Visitor& e, const DTable& dtable) const;
141 
147  void visit(opcode::Visitor& e) const;
148 
150  void print(FILE* out) const;
151 };
152 
153 namespace opcode
154 {
155 
167 struct Visitor
168 {
174  const DTable* dtable;
175 
176  Visitor();
177  virtual ~Visitor();
178 
185  virtual void b_variable(Varcode code);
186 
196  virtual void c_modifier(Varcode code);
197 
206  virtual void c_change_data_width(Varcode code, int change);
207 
216  virtual void c_change_data_scale(Varcode code, int change);
217 
229  virtual void c_associated_field(Varcode code, Varcode sig_code, unsigned nbits);
230 
237  virtual void c_char_data(Varcode code);
238 
247  virtual void c_char_data_override(Varcode code, unsigned new_length);
248 
255  virtual void c_quality_information_bitmap(Varcode code);
256 
263  virtual void c_substituted_value_bitmap(Varcode code);
264 
271  virtual void c_substituted_value(Varcode code);
272 
283  virtual void c_local_descriptor(Varcode code, Varcode desc_code, unsigned nbits);
284 
296  virtual void r_replication(Varcode code, Varcode delayed_code, const Opcodes& ops);
297 
304  virtual void d_group_begin(Varcode code);
305 
312  virtual void d_group_end(Varcode code);
313 };
314 
319 class Printer : public Visitor
320 {
321 protected:
328  void print_lead(Varcode code);
329 
330 public:
336  FILE* out;
337 
344  const Vartable* btable;
345 
352  unsigned indent;
353 
355  unsigned indent_step;
356 
357  Printer();
358  virtual void b_variable(Varcode code);
359  virtual void c_modifier(Varcode code);
360  virtual void c_change_data_width(Varcode code, int change);
361  virtual void c_change_data_scale(Varcode code, int change);
362  virtual void c_associated_field(Varcode code, Varcode sig_code, unsigned nbits);
363  virtual void c_char_data(Varcode code);
364  virtual void c_char_data_override(Varcode code, unsigned new_length);
365  virtual void c_quality_information_bitmap(Varcode code);
366  virtual void c_substituted_value_bitmap(Varcode code);
367  virtual void c_substituted_value(Varcode code);
368  virtual void c_local_descriptor(Varcode code, Varcode desc_code, unsigned nbits);
369  virtual void r_replication(Varcode code, Varcode delayed_code, const Opcodes& ops);
370  virtual void d_group_begin(Varcode code);
371  virtual void d_group_end(Varcode code);
372 };
373 
374 }
375 
376 }
377 
378 #endif