libwreport  2.4
opcode.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005--2010  ARPA-SIM <urpsim@smr.arpa.emr.it>
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Author: Enrico Zini <enrico@enricozini.com>
00018  */
00019 
00020 #ifndef WREPORT_OPCODE_H
00021 #define WREPORT_OPCODE_H
00022 
00029 #include <wreport/varinfo.h>
00030 #include <vector>
00031 #include <cstdio>
00032 
00033 namespace wreport {
00034 
00035 namespace opcode {
00036 struct Visitor;
00037 }
00038 
00039 struct Vartable;
00040 struct DTable;
00041 
00050 struct Opcodes
00051 {
00053     const std::vector<Varcode>& vals;
00055     unsigned begin;
00057     unsigned end;
00058 
00060     Opcodes(const std::vector<Varcode>& vals) : vals(vals), begin(0), end(vals.size()) {}
00062     Opcodes(const std::vector<Varcode>& vals, unsigned begin, unsigned end)
00063         : vals(vals), begin(begin), end(end) {}
00065     Opcodes(const Opcodes& o) : vals(o.vals), begin(o.begin), end(o.end) {}
00066 
00072     Opcodes& operator=(const Opcodes& o)
00073     {
00074         begin = o.begin;
00075         end = o.end;
00076         return *this;
00077     }
00078 
00080     Varcode operator[](unsigned i) const
00081     {
00082         if (begin + i > end)
00083             return 0;
00084         else
00085             return vals[begin + i];
00086     }
00087 
00089     unsigned size() const { return end - begin; }
00090 
00092     bool empty() const { return begin == end; }
00093 
00095     Varcode head() const
00096     {
00097         if (begin == end)
00098             return 0;
00099         return vals[begin];
00100     }
00101 
00107     Opcodes next() const
00108     {
00109         if (begin == end)
00110             return *this;
00111         else
00112             return Opcodes(vals, begin+1, end);
00113     }
00114 
00116     Opcodes sub(unsigned skip) const
00117     {
00118         if (begin + skip > end)
00119             return Opcodes(vals, end, end);
00120         else
00121             return Opcodes(vals, begin + skip, end);
00122     }
00123 
00125     Opcodes sub(unsigned skip, unsigned len) const
00126     {
00127         if (begin + skip > end)
00128             return Opcodes(vals, end, end);
00129         else if (begin + skip + len > end)
00130             return Opcodes(vals, begin + skip, end);
00131         else
00132             return Opcodes(vals, begin + skip, begin + skip + len);
00133     }
00134 
00140     void visit(opcode::Visitor& e, const DTable& dtable) const;
00141 
00147     void visit(opcode::Visitor& e) const;
00148 
00150     void print(FILE* out) const;
00151 };
00152 
00153 namespace opcode
00154 {
00155 
00167 struct Visitor
00168 {
00174     const DTable* dtable;
00175 
00176     Visitor();
00177     virtual ~Visitor();
00178 
00185     virtual void b_variable(Varcode code);
00186 
00196     virtual void c_modifier(Varcode code);
00197 
00206     virtual void c_change_data_width(Varcode code, int change);
00207 
00216     virtual void c_change_data_scale(Varcode code, int change);
00217 
00229     virtual void c_associated_field(Varcode code, Varcode sig_code, unsigned nbits);
00230 
00237     virtual void c_char_data(Varcode code);
00238 
00247     virtual void c_char_data_override(Varcode code, unsigned new_length);
00248 
00255     virtual void c_quality_information_bitmap(Varcode code);
00256 
00263     virtual void c_substituted_value_bitmap(Varcode code);
00264 
00271     virtual void c_substituted_value(Varcode code);
00272 
00283     virtual void c_local_descriptor(Varcode code, Varcode desc_code, unsigned nbits);
00284 
00296     virtual void r_replication(Varcode code, Varcode delayed_code, const Opcodes& ops);
00297 
00304     virtual void d_group_begin(Varcode code);
00305 
00312     virtual void d_group_end(Varcode code);
00313 };
00314 
00319 class Printer : public Visitor
00320 {
00321 protected:
00328     void print_lead(Varcode code);
00329 
00330 public:
00336     FILE* out;
00337 
00344     const Vartable* btable;
00345 
00352     unsigned indent;
00353 
00355     unsigned indent_step;
00356 
00357     Printer();
00358     virtual void b_variable(Varcode code);
00359     virtual void c_modifier(Varcode code);
00360     virtual void c_change_data_width(Varcode code, int change);
00361     virtual void c_change_data_scale(Varcode code, int change);
00362     virtual void c_associated_field(Varcode code, Varcode sig_code, unsigned nbits);
00363     virtual void c_char_data(Varcode code);
00364     virtual void c_char_data_override(Varcode code, unsigned new_length);
00365     virtual void c_quality_information_bitmap(Varcode code);
00366     virtual void c_substituted_value_bitmap(Varcode code);
00367     virtual void c_substituted_value(Varcode code);
00368     virtual void c_local_descriptor(Varcode code, Varcode desc_code, unsigned nbits);
00369     virtual void r_replication(Varcode code, Varcode delayed_code, const Opcodes& ops);
00370     virtual void d_group_begin(Varcode code);
00371     virtual void d_group_end(Varcode code);
00372 };
00373 
00374 }
00375 
00376 }
00377 
00378 #endif