* sim/ucsim/error.cc, sim/ucsim/errorcl.h,
[fw/sdcc] / sim / ucsim / errorcl.h
1 /*
2  * Simulator of microcontrollers (errorcl.h)
3  *
4  * Copyright (C) 2001,01 Drotos Daniel, Talker Bt.
5  * 
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /*
11   This file is part of microcontroller simulator: ucsim.
12
13   UCSIM is free software; you can redistribute it and/or modify
14   it under the terms of the GNU General Public License as published by
15   the Free Software Foundation; either version 2 of the License, or
16   (at your option) any later version.
17
18   UCSIM is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21   GNU General Public License for more details.
22
23   You should have received a copy of the GNU General Public License
24   along with UCSIM; see the file COPYING.  If not, write to the Free
25   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26   02111-1307, USA.
27 */
28 /*@1@*/
29
30 #ifndef ERRORCL_HEADER
31 #define ERRORCL_HEADER
32
33 #include <string.h>
34
35 // prj
36 #include "pobjcl.h"
37 #include "stypes.h"
38
39 extern struct id_element error_on_off_names[];
40
41 enum error_on_off {
42   ERROR_PARENT,
43   ERROR_ON,
44   ERROR_OFF
45 };
46
47 const int err_stop= (err_unknown|err_error);
48
49 class cl_error_class: public cl_base
50 {
51 protected:
52   enum error_type type;
53   //char *name;
54   enum error_on_off on;
55 public:
56   cl_error_class(enum error_type typ, char *aname,
57                  enum error_on_off be_on= ERROR_PARENT);
58   cl_error_class(enum error_type typ, char *aname,
59                  class cl_error_class *parent,
60                  enum error_on_off be_on= ERROR_PARENT);
61   
62   enum error_on_off get_on(void) { return(on); }
63   void set_on(enum error_on_off val);
64   bool is_on(void);
65   enum error_type get_type(void);
66   char *get_type_name(void);
67   //char *get_name(void);
68 };
69
70 class cl_error_registry
71 {
72 public:
73   cl_error_registry(void);
74   class cl_error_class *find(char *type_name)
75   {
76     if (NIL == registered_errors)
77       return NIL;
78     return static_cast<class cl_error_class *>(registered_errors->first_that(compare, static_cast<void *>(type_name)));
79   }
80   static class cl_list *get_list(void)
81   {
82     return registered_errors;
83   }
84
85 protected:
86   class cl_error_class *register_error(class cl_error_class *error_class)
87   {
88     if (!registered_errors)
89       registered_errors= new cl_list(2, 2, "registered errors");
90     registered_errors->add(error_class);
91     return error_class;
92   }
93
94 private:
95   static class cl_list *registered_errors;
96   static int compare(void *obj1, void *obj2)
97   {
98     return (static_cast<class cl_base *>(obj1))->is_named(static_cast<char *>(obj2));
99   }
100 };
101
102 class cl_commander; //forward
103
104 class cl_error: public cl_base
105 {
106 protected:
107   class cl_error_class *classification;
108 public:
109   bool inst;    // Occured during instruction execution
110   t_addr PC;    // Address of the instruction
111 public:
112   cl_error(void);
113   virtual ~cl_error(void);
114   virtual int init(void);
115
116 public:
117   virtual enum error_type get_type(void);
118   virtual enum error_on_off get_on(void);
119   virtual bool is_on(void);
120   virtual class cl_error_class *get_class(void) { return(classification); }
121
122   virtual void print(class cl_commander *c);
123   virtual char *get_type_name();
124 };
125
126 #endif
127
128
129 /* End of sim.src/errorcl.h */