* sim/ucsim/*.*, sim/ucsim/configure, sim/ucsim/configure.in:
[fw/sdcc] / sim / ucsim / sim.src / stack.cc
index f10ab8fc077b273db6fcaaa1eb71e9a77ffb116c..60e13ad16dfa8bafb6d62939e086697be541006d 100644 (file)
@@ -34,9 +34,11 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #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):
+                         t_addr iPC,
+                         t_addr iSP_before, t_addr iSP_after):
   cl_base()
 {
   operation= op;
@@ -60,13 +62,13 @@ cl_stack_op::mk_copy(void)
 }
 
 void
-cl_stack_op::info_head(class cl_console *con)
+cl_stack_op::info_head(class cl_console_base *con)
 {
   con->dd_printf("OP   SP before-after   L DATA/ADDR   INSTRUCTION\n");
 }
 
 void
-cl_stack_op::info(class cl_console *con, class cl_uc *uc)
+cl_stack_op::info(class cl_console_base *con, class cl_uc *uc)
 {
   con->dd_printf("%-4s 0x%06"_A_"x-0x%06"_A_"x %d ",
                 get_op_name(), SP_before, SP_after, abs(SP_before-SP_after));
@@ -76,14 +78,14 @@ cl_stack_op::info(class cl_console *con, class cl_uc *uc)
   //con->dd_printf("\n");
 }
 
-char *
+const char *
 cl_stack_op::get_op_name(void)
 {
   return("op");
 }
 
 void
-cl_stack_op::print_info(class cl_console *con)
+cl_stack_op::print_info(class cl_console_base *con)
 {
   con->dd_printf("-");
 }
@@ -155,19 +157,19 @@ cl_stack_call::mk_copy(void)
   return(so);
 }
 
-char *
+const char *
 cl_stack_call::get_op_name(void)
 {
   return("call");
 }
 
 void
-cl_stack_call::print_info(class cl_console *con)
+cl_stack_call::print_info(class cl_console_base *con)
 {
   con->dd_printf("0x%06"_A_"x", called_addr);
 }
 
-char *
+const char *
 cl_stack_call::get_matching_name(void)
 {
   return("ret");
@@ -206,19 +208,19 @@ cl_stack_intr::mk_copy(void)
   return(so);
 }
 
-char *
+const char *
 cl_stack_intr::get_op_name(void)
 {
   return("intr");
 }
 
 void
-cl_stack_intr::print_info(class cl_console *con)
+cl_stack_intr::print_info(class cl_console_base *con)
 {
   con->dd_printf("0x%06"_A_"x", called_addr);
 }
 
-char *
+const char *
 cl_stack_intr::get_matching_name(void)
 {
   return("iret");
@@ -255,13 +257,13 @@ cl_stack_push::mk_copy(void)
   return(so);
 }
 
-char *
+const char *
 cl_stack_push::get_op_name(void)
 {
   return("push");
 }
 
-char *
+const char *
 cl_stack_push::get_matching_name(void)
 {
   return("pop");
@@ -274,7 +276,7 @@ cl_stack_push::get_matching_op(void)
 }
 
 void
-cl_stack_push::print_info(class cl_console *con)
+cl_stack_push::print_info(class cl_console_base *con)
 {
   t_addr d= data;
   con->dd_printf("0x%06"_A_"x", d);
@@ -305,13 +307,13 @@ cl_stack_ret::mk_copy(void)
   return(so);
 }
 
-char *
+const char *
 cl_stack_ret::get_op_name(void)
 {
   return("ret");
 }
 
-char *
+const char *
 cl_stack_ret::get_matching_name(void)
 {
   return("call");
@@ -348,13 +350,13 @@ cl_stack_iret::mk_copy(void)
   return(so);
 }
 
-char *
+const char *
 cl_stack_iret::get_op_name(void)
 {
   return("iret");
 }
 
-char *
+const char *
 cl_stack_iret::get_matching_name(void)
 {
   return("intr");
@@ -391,13 +393,13 @@ cl_stack_pop::mk_copy(void)
   return(so);
 }
 
-char *
+const char *
 cl_stack_pop::get_op_name(void)
 {
   return("pop");
 }
 
-char *
+const char *
 cl_stack_pop::get_matching_name(void)
 {
   return("push");
@@ -420,60 +422,42 @@ cl_stack_pop::match(class cl_stack_op *op)
  * 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
-cl_error_stack_tracker_wrong_handle::print(class cl_commander *c)
+cl_error_stack_tracker_wrong_handle::print(class cl_commander_base *c)
 {
   c->dd_printf("%s: wrong stack tracker handle called for %s operation\n",
-              get_type_name(), write_operation?"write":"read");
+               get_type_name(), write_operation?"write":"read");
 }
 
 /* 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)
@@ -482,27 +466,23 @@ cl_error_stack_tracker_empty::~cl_error_stack_tracker_empty(void)
 }
 
 void
-cl_error_stack_tracker_empty::print(class cl_commander *c)
+cl_error_stack_tracker_empty::print(class cl_commander_base *c)
 {
   c->dd_printf("%s(0x%06"_A_"x: %s on empty stack, PC="
-              "0x06"_A_"x, SP=0x%06"_A_"x->0x%06"_A_"x\n",
-              get_type_name(), operation->get_pc(), operation->get_op_name(),
-              operation->get_before(), operation->get_after());
+               "0x06"_A_"x, SP=0x%06"_A_"x->0x%06"_A_"x\n",
+               get_type_name(), operation->get_pc(), operation->get_op_name(),
+               operation->get_before(), operation->get_after());
 }
 
 /* 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)
@@ -512,28 +492,24 @@ cl_error_stack_tracker_unmatch::~cl_error_stack_tracker_unmatch(void)
 }
 
 void
-cl_error_stack_tracker_unmatch::print(class cl_commander *c)
+cl_error_stack_tracker_unmatch::print(class cl_commander_base *c)
 {
   c->dd_printf("%s(0x%06"_A_"x): %s when %s expected, "
-              "SP=0x%06"_A_"x->0x%06"_A_"x\n",
-              get_type_name(), operation->get_pc(),
-              operation->get_op_name(), top->get_matching_name(),
-              operation->get_before(), operation->get_after());
+               "SP=0x%06"_A_"x->0x%06"_A_"x\n",
+               get_type_name(), operation->get_pc(),
+               operation->get_op_name(), top->get_matching_name(),
+               operation->get_before(), operation->get_after());
 }
 
 /* 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)
@@ -542,11 +518,22 @@ cl_error_stack_tracker_inconsistent::~cl_error_stack_tracker_inconsistent(void)
 }
 
 void
-cl_error_stack_tracker_inconsistent::print(class cl_commander *c)
+cl_error_stack_tracker_inconsistent::print(class cl_commander_base *c)
 {
   c->dd_printf("%s(0x%06"_A_"x): %d byte(s) unread from the stack\n",
-              get_type_name(), operation->get_pc(),
-              unread_data_size);
+               get_type_name(), operation->get_pc(),
+               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));
 }