+2005-11-06 Borut Razem <borut.razem AT siol.net>
+
+ * sim/ucsim/error.cc, sim/ucsim/errorcl.h,
+ sim/ucsim/sim.src/stack.cc, sim/ucsim/sim.src/stackcl.h,
+ sim/ucsim/sim.src/uc.cc, sim/ucsim/sim.src/uccl.h,
+ sim/ucsim/sim.src/mem.cc, sim/ucsim/sim.src/memcl.h,
+ sim/ucsim/cmd.src/set.cc, sim/ucsim/cmd.src/show.cc:
+ dynamic construction of cl_error_class and derivates - 2.nd try
+
2005-11-05 Borut Razem <borut.razem AT siol.net>
* sim/ucsim/sim.src/error.cc: fixed uninitialized class member variable
else
con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+ class cl_list *registered_errors = cl_error_registry::get_list();
if (error_name &&
value &&
registered_errors)
else
con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
*/
+ class cl_list *registered_errors = cl_error_registry::get_list();
int i;
for (i= 0; i < registered_errors->count; i++)
{
{ 0 , 0 }
};
-class cl_list *registered_errors= NIL;
+static class cl_error_registry error_registry;
+
+class cl_list *cl_error_registry::registered_errors= NIL;
/*
*/
type= typ;
on= be_on;
set_name(aname, "not-known");
- if (!registered_errors)
- registered_errors= new cl_list(2, 2, "registered errors");
- registered_errors->add(this);
}
cl_error_class::cl_error_class(enum error_type typ, char *aname,
type= typ;
on= be_on;
set_name(aname, "not-known");
- if (!registered_errors)
- registered_errors= new cl_list(2, 2, "registered errors");
- registered_errors->add(this);
if (parent)
parent->add_child(this);
}
/*
*/
-class cl_error_class *cl_error::error_class_base;
-
cl_error::cl_error(void):
cl_base()
{
- if (NULL == error_class_base)
- error_class_base = new cl_error_class(err_error, "non-classified", ERROR_ON);
- //type= err_unknown;
- classification= error_class_base;
+ classification= error_registry.find("non-classified");
}
cl_error::~cl_error(void)
return(get_id_string(error_type_names, type, "untyped"));
}
+cl_error_registry::cl_error_registry(void)
+{
+ if (NULL == error_registry.find("non-classified"))
+ register_error(new cl_error_class(err_error, "non-classified", ERROR_ON));
+}
+
/* End of sim.src/error.cc */
#ifndef ERRORCL_HEADER
#define ERRORCL_HEADER
+#include <string.h>
+
// prj
#include "pobjcl.h"
#include "stypes.h"
const int err_stop= (err_unknown|err_error);
-extern class cl_list *registered_errors;
-
class cl_error_class: public cl_base
{
protected:
//char *get_name(void);
};
+class cl_error_registry
+{
+public:
+ cl_error_registry(void);
+ class cl_error_class *find(char *type_name)
+ {
+ if (NIL == registered_errors)
+ return NIL;
+ return static_cast<class cl_error_class *>(registered_errors->first_that(compare, static_cast<void *>(type_name)));
+ }
+ static class cl_list *get_list(void)
+ {
+ return registered_errors;
+ }
+
+protected:
+ class cl_error_class *register_error(class cl_error_class *error_class)
+ {
+ if (!registered_errors)
+ registered_errors= new cl_list(2, 2, "registered errors");
+ registered_errors->add(error_class);
+ return error_class;
+ }
+
+private:
+ static class cl_list *registered_errors;
+ static int compare(void *obj1, void *obj2)
+ {
+ return (static_cast<class cl_base *>(obj1))->is_named(static_cast<char *>(obj2));
+ }
+};
+
class cl_commander; //forward
class cl_error: public cl_base
{
-private:
- static class cl_error_class *error_class_base;
protected:
class cl_error_class *classification;
public:
virtual char *get_type_name();
};
-
#endif
+
/* End of sim.src/errorcl.h */
#include "hwcl.h"
+static class cl_mem_error_registry mem_error_registry;
+
/*
* 3rd version of memory system
*/
/* All of memory errors */
-class cl_error_class *cl_error_mem::error_mem_class;
-
cl_error_mem::cl_error_mem(class cl_memory *amem, t_addr aaddr)
{
mem= amem;
addr= aaddr;
- if (NULL == error_mem_class)
- error_mem_class= new cl_error_class(err_error, "memory", classification, ERROR_OFF);
- classification= error_mem_class;
+ classification= mem_error_registry.find("memory");
}
/* Invalid address in memory access */
-class cl_error_class *cl_error_mem_invalid_address::error_mem_invalid_address_class;
-
cl_error_mem_invalid_address::
cl_error_mem_invalid_address(class cl_memory *amem, t_addr aaddr):
cl_error_mem(amem, aaddr)
{
- if (NULL == error_mem_invalid_address_class)
- error_mem_invalid_address_class= new cl_error_class(err_error, "invalid_address", classification);
- classification= error_mem_invalid_address_class;
+ classification= mem_error_registry.find("invalid_address");
}
void
/* Non-decoded address space access */
-class cl_error_class *cl_error_mem_non_decoded::error_mem_non_decoded_class;
-
cl_error_mem_non_decoded::
cl_error_mem_non_decoded(class cl_memory *amem, t_addr aaddr):
cl_error_mem(amem, aaddr)
{
- if (NULL == error_mem_non_decoded_class)
- error_mem_non_decoded_class= new cl_error_class(err_error, "non_decoded", classification);
- classification= error_mem_non_decoded_class;
+ classification= mem_error_registry.find("non_decoded");
}
void
cmd_fprintf(f, " in memory %s.\n", mem->get_name());
}
+cl_mem_error_registry::cl_mem_error_registry(void)
+{
+ class cl_error_class *prev = mem_error_registry.find("non-classified");
+ prev = register_error(new cl_error_class(err_error, "memory", prev, ERROR_OFF));
+ prev = register_error(new cl_error_class(err_error, "invalid_address", prev));
+ prev = register_error(new cl_error_class(err_error, "non_decoded", prev));
+}
+
/* End of mem.cc */
class cl_error_mem: public cl_error
{
-private:
- static class cl_error_class *error_mem_class;
protected:
class cl_memory *mem;
t_addr addr;
class cl_error_mem_invalid_address: public cl_error_mem
{
-private:
- static class cl_error_class *error_mem_invalid_address_class;
public:
cl_error_mem_invalid_address(class cl_memory *amem, t_addr aaddr);
class cl_error_mem_non_decoded: public cl_error_mem
{
-private:
- static class cl_error_class *error_mem_non_decoded_class;
public:
cl_error_mem_non_decoded(class cl_memory *amem, t_addr aaddr);
virtual void print(class cl_commander *c);
};
+class cl_mem_error_registry: public cl_error_registry
+{
+public:
+ cl_mem_error_registry(void);
+};
#endif
+
/* End of memcl.h */
#include "stackcl.h"
+static class cl_stack_error_registry stack_error_registry;
+
cl_stack_op::cl_stack_op(enum stack_op op,
t_addr iPC,
t_addr iSP_before, t_addr iSP_after):
* Stack Errors
*/
-class cl_error_class *cl_error_stack::error_stack_class;
-
cl_error_stack::cl_error_stack(void)
{
- if (NULL == error_stack_class)
- error_stack_class= new cl_error_class(err_error, "stack", classification, ERROR_OFF);
- classification= error_stack_class;
+ classification = stack_error_registry.find("stack");
}
/* Stack Tracker Errors */
-class cl_error_class *cl_error_stack_tracker::error_stack_tracker_class;
-
cl_error_stack_tracker::cl_error_stack_tracker(void)
{
-// cl_error_class *error_stack_tracker_class = new cl_error_class(err_error, "stack_tracker", error_stack_class, ERROR_OFF);
-// classification= &error_stack_tracker_class;
- if (NULL == error_stack_tracker_class)
- error_stack_tracker_class= new cl_error_class(err_error, "stack_tracker", classification);
- classification= error_stack_tracker_class;
+ classification = stack_error_registry.find("stack_tracker");
}
/* Stack Tracker: wrong handle */
-class cl_error_class *cl_error_stack_tracker_wrong_handle::error_stack_tracker_wrong_handle_class;
-
cl_error_stack_tracker_wrong_handle::cl_error_stack_tracker_wrong_handle(bool write_op):
cl_error_stack_tracker()
{
write_operation= write_op;
- if (NULL == error_stack_tracker_wrong_handle_class)
- error_stack_tracker_wrong_handle_class= new cl_error_class(err_error, "stack_tracker_wrong_handle", classification);
- classification= error_stack_tracker_wrong_handle_class;
+ classification = stack_error_registry.find("stack_tracker_wrong_handle");
}
void
/* Stack Tracker: operation on empty stack */
-class cl_error_class *cl_error_stack_tracker_empty::error_stack_tracker_empty_class;
-
cl_error_stack_tracker_empty::
cl_error_stack_tracker_empty(class cl_stack_op *op):
cl_error_stack_tracker()
{
operation= op->mk_copy();
- if (NULL == error_stack_tracker_empty_class)
- error_stack_tracker_empty_class= new cl_error_class(err_error, "operation_on_empty_stack", classification);
- classification= error_stack_tracker_empty_class;
+ classification = stack_error_registry.find("operation_on_empty_stack");
}
cl_error_stack_tracker_empty::~cl_error_stack_tracker_empty(void)
/* Stack Tracker: operation on empty stack */
-class cl_error_class *cl_error_stack_tracker_unmatch::error_stack_tracker_unmatch_class;
-
cl_error_stack_tracker_unmatch::
cl_error_stack_tracker_unmatch(class cl_stack_op *Top, class cl_stack_op *op):
cl_error_stack_tracker()
{
top= Top->mk_copy();
operation= op->mk_copy();
- if (NULL == error_stack_tracker_unmatch_class)
- error_stack_tracker_unmatch_class= new cl_error_class(err_warning, "stack_operation_unmatched_to_top_of_stack", classification);
- classification= error_stack_tracker_unmatch_class;
+ classification = stack_error_registry.find("stack_operation_unmatched_to_top_of_stack");
}
cl_error_stack_tracker_unmatch::~cl_error_stack_tracker_unmatch(void)
/* Stack Tracker: stack is inconsistent */
-class cl_error_class *cl_error_stack_tracker_inconsistent::error_stack_tracker_inconsistent_class;
-
cl_error_stack_tracker_inconsistent::
cl_error_stack_tracker_inconsistent(class cl_stack_op *op,
int the_unread_data_size)
{
operation= op->mk_copy();
unread_data_size= the_unread_data_size;
- if (NULL == error_stack_tracker_inconsistent_class)
- error_stack_tracker_inconsistent_class= new cl_error_class(err_warning, "stack_looks_corrupted", classification);
- classification= error_stack_tracker_inconsistent_class;
+ classification = stack_error_registry.find("stack_looks_corrupted");
}
cl_error_stack_tracker_inconsistent::~cl_error_stack_tracker_inconsistent(void)
unread_data_size);
}
+cl_stack_error_registry::cl_stack_error_registry(void)
+{
+ class cl_error_class *prev = stack_error_registry.find("non-classified");
+ prev = register_error(new cl_error_class(err_error, "stack", prev, ERROR_OFF));
+ prev = register_error(new cl_error_class(err_error, "stack_tracker", prev));
+ prev = register_error(new cl_error_class(err_error, "stack_tracker_wrong_handle", prev));
+ prev = register_error(new cl_error_class(err_error, "operation_on_empty_stack", prev));
+ prev = register_error(new cl_error_class(err_warning, "stack_operation_unmatched_to_top_of_stack", prev));
+ prev = register_error(new cl_error_class(err_warning, "stack_looks_corrupted", prev));
+}
+
/* End of sim.src/stack.cc */
/*
* All kind of stack errors
*/
-//extern class cl_error_class error_stack_class;
-//class cl_error_stack: public cl_error
class cl_error_stack: public cl_error
{
private:
*/
class cl_error_stack_tracker: public cl_error_stack
{
-private:
- static class cl_error_class *error_stack_tracker_class;
public:
cl_error_stack_tracker(void);
};
class cl_error_stack_tracker_wrong_handle: public cl_error_stack_tracker
{
-private:
- static class cl_error_class *error_stack_tracker_wrong_handle_class;
public:
bool write_operation;
public:
class cl_error_stack_tracker_empty: public cl_error_stack_tracker
{
-private:
- static class cl_error_class *error_stack_tracker_empty_class;
protected:
class cl_stack_op *operation;
public:
class cl_error_stack_tracker_unmatch: public cl_error_stack_tracker
{
-private:
- static class cl_error_class *error_stack_tracker_unmatch_class;
protected:
class cl_stack_op *top, *operation;
public:
class cl_error_stack_tracker_inconsistent: public cl_error_stack_tracker
{
-private:
- static class cl_error_class *error_stack_tracker_inconsistent_class;
protected:
class cl_stack_op *operation;
int unread_data_size;
virtual void print(class cl_commander *c);
};
+class cl_stack_error_registry: public cl_error_registry
+{
+public:
+ cl_stack_error_registry(void);
+};
#endif
+
/* End of sim.src/stackcl.h */
#include "simcl.h"
#include "itsrccl.h"
+static class cl_uc_error_registry uc_error_registry;
/*
* Clock counter
*----------------------------------------------------------------------------
*/
-class cl_error_class *cl_error_unknown_code::error_unknown_code_class;
-
cl_error_unknown_code::cl_error_unknown_code(class cl_uc *the_uc)
{
uc= the_uc;
- if (NULL == error_unknown_code_class)
- error_unknown_code_class= new cl_error_class(err_error, "unknown_code", classification, ERROR_OFF);
- classification= error_unknown_code_class;
+ classification= uc_error_registry.find("unknown_code");
}
void
cmd_fprintf(f, "\n");
}
+cl_uc_error_registry::cl_uc_error_registry(void)
+{
+ class cl_error_class *prev = uc_error_registry.find("non-classified");
+ prev = register_error(new cl_error_class(err_error, "unknown_code", prev, ERROR_OFF));
+}
+
/* End of uc.cc */
class cl_error_unknown_code: public cl_error
{
-private:
- static class cl_error_class *error_unknown_code_class;
protected:
class cl_uc *uc;
public:
virtual void print(class cl_commander *c);
};
+class cl_uc_error_registry: public cl_error_registry
+{
+public:
+ cl_uc_error_registry(void);
+};
#endif
+
/* End of uccl.h */