Index: trunk/platforms/tsar_generic_xbar/tsar_xbar_cluster/caba/source/include/tsar_xbar_cluster.h
===================================================================
--- trunk/platforms/tsar_generic_xbar/tsar_xbar_cluster/caba/source/include/tsar_xbar_cluster.h	(revision 504)
+++ trunk/platforms/tsar_generic_xbar/tsar_xbar_cluster/caba/source/include/tsar_xbar_cluster.h	(revision 508)
@@ -47,4 +47,7 @@
 {
     public:
+
+    // Used in destructor
+    size_t n_procs;
 
     // Ports
@@ -269,4 +272,6 @@
                      bool                               proc_debug_ok);
 
+    ~TsarXbarCluster();
+
 };
 }}
Index: trunk/platforms/tsar_generic_xbar/tsar_xbar_cluster/caba/source/src/tsar_xbar_cluster.cpp
===================================================================
--- trunk/platforms/tsar_generic_xbar/tsar_xbar_cluster/caba/source/src/tsar_xbar_cluster.cpp	(revision 504)
+++ trunk/platforms/tsar_generic_xbar/tsar_xbar_cluster/caba/source/src/tsar_xbar_cluster.cpp	(revision 508)
@@ -86,9 +86,12 @@
 
 {
+
+    n_procs = nb_procs;
+
     // Vectors of ports definition
-    p_cmd_in        = alloc_elems<DspinInput<dspin_cmd_width> >("p_cmd_in", 4, 3);
-    p_cmd_out       = alloc_elems<DspinOutput<dspin_cmd_width> >("p_cmd_out", 4, 3);
-    p_rsp_in        = alloc_elems<DspinInput<dspin_rsp_width> >("p_rsp_in", 4, 2);
-    p_rsp_out       = alloc_elems<DspinOutput<dspin_rsp_width> >("p_rsp_out", 4, 2);
+    p_cmd_in  = alloc_elems<DspinInput<dspin_cmd_width> >  ("p_cmd_in",  4, 3);
+    p_cmd_out = alloc_elems<DspinOutput<dspin_cmd_width> > ("p_cmd_out", 4, 3);
+    p_rsp_in  = alloc_elems<DspinInput<dspin_rsp_width> >  ("p_rsp_in",  4, 2);
+    p_rsp_out = alloc_elems<DspinOutput<dspin_rsp_width> > ("p_rsp_out", 4, 2);
 
     /////////////////////////////////////////////////////////////////////////////
@@ -105,5 +108,5 @@
                                          GdbServer<Mips32ElIss> >(
                       sproc.str().c_str(),
-                      cluster_id*nb_procs + p,        // GLOBAL PROC_ID
+                      cluster_id * nb_procs + p,      // GLOBAL PROC_ID
                       mtd,                            // Mapping Table
                       IntTab(cluster_id,p),           // SRCID
@@ -113,6 +116,6 @@
                       8,                              // DTLB ways
                       8,                              // DTLB sets
-                      l1_i_ways,l1_i_sets,16,         // ICACHE size
-                      l1_d_ways,l1_d_sets,16,         // DCACHE size
+                      l1_i_ways,l1_i_sets, 16,        // ICACHE size
+                      l1_d_ways,l1_d_sets, 16,        // DCACHE size
                       4,                              // WBUF nlines
                       4,                              // WBUF nwords
@@ -154,5 +157,5 @@
                      8,                                  // INVALIDATE TABLE DEPTH
                      debug_start_cycle,
-                     memc_debug_ok );
+                     memc_debug_ok);
 
     wt_memc = new VciDspinTargetWrapper<vci_param_int,
@@ -216,5 +219,5 @@
     size_t nb_direct_initiators      = nb_procs + 1;
     size_t nb_direct_targets         = 3;
-    if ( io )
+    if (io)
     {
         nb_direct_initiators         = nb_procs + 3;
@@ -303,5 +306,5 @@
 
     // IO cluster components
-    if ( io )
+    if (io)
     {
         /////////////////////////////////////////////
@@ -335,5 +338,5 @@
                      "bdev",
                      mtd,
-                     IntTab(cluster_id, nb_procs+1),
+                     IntTab(cluster_id, nb_procs + 1),
                      IntTab(cluster_id, tgtid_bdev),
                      disk_name,
@@ -394,5 +397,5 @@
         /////////////////////////////////////////////
         std::vector<std::string> vect_names;
-        for( size_t tid = 0 ; tid < (nb_ttys) ; tid++ )
+        for (size_t tid = 0; tid < nb_ttys; tid++)
         {
             std::ostringstream term_name;
@@ -423,5 +426,5 @@
     router_rsp->p_resetn                     (this->p_resetn);
 
-    for(int i = 0; i < 4; i++)
+    for (int i = 0; i < 4; i++)
     {
         for (int k = 0; k < 3; k++)
@@ -468,5 +471,5 @@
         xbar_cmd_d->p_local_in[p]                (signal_dspin_cmd_proc_i[p]);
 
-    if ( io )
+    if (io)
     {
         xbar_cmd_d->p_local_out[tgtid_mtty]      (signal_dspin_cmd_mtty_t);
@@ -475,8 +478,8 @@
         xbar_cmd_d->p_local_out[tgtid_fbuf]      (signal_dspin_cmd_fbuf_t);
         xbar_cmd_d->p_local_out[tgtid_mnic]      (signal_dspin_cmd_mnic_t);
-        xbar_cmd_d->p_local_out[tgtid_chbuf]      (signal_dspin_cmd_chbuf_t);
-
-        xbar_cmd_d->p_local_in[nb_procs+1]       (signal_dspin_cmd_bdev_i);
-        xbar_cmd_d->p_local_in[nb_procs+2]       (signal_dspin_cmd_chbuf_i);
+        xbar_cmd_d->p_local_out[tgtid_chbuf]     (signal_dspin_cmd_chbuf_t);
+
+        xbar_cmd_d->p_local_in[nb_procs + 1]     (signal_dspin_cmd_bdev_i);
+        xbar_cmd_d->p_local_in[nb_procs + 2]     (signal_dspin_cmd_chbuf_i);
     }
 
@@ -498,5 +501,5 @@
         xbar_rsp_d->p_local_out[p]               (signal_dspin_rsp_proc_i[p]);
 
-    if ( io )
+    if (io)
     {
         xbar_rsp_d->p_local_in[tgtid_mtty]       (signal_dspin_rsp_mtty_t);
@@ -505,8 +508,8 @@
         xbar_rsp_d->p_local_in[tgtid_fbuf]       (signal_dspin_rsp_fbuf_t);
         xbar_rsp_d->p_local_in[tgtid_mnic]       (signal_dspin_rsp_mnic_t);
-        xbar_rsp_d->p_local_in[tgtid_chbuf]       (signal_dspin_rsp_chbuf_t);
-
-        xbar_rsp_d->p_local_out[nb_procs+1]      (signal_dspin_rsp_bdev_i);
-        xbar_rsp_d->p_local_out[nb_procs+2]      (signal_dspin_rsp_chbuf_i);
+        xbar_rsp_d->p_local_in[tgtid_chbuf]      (signal_dspin_rsp_chbuf_t);
+
+        xbar_rsp_d->p_local_out[nb_procs + 1]    (signal_dspin_rsp_bdev_i);
+        xbar_rsp_d->p_local_out[nb_procs + 2]    (signal_dspin_rsp_chbuf_i);
     }
 
@@ -531,5 +534,5 @@
     xbar_clack_c->p_local_in[0]                  (signal_dspin_clack_memc);
     for (size_t p = 0; p < nb_procs; p++)
-        xbar_clack_c->p_local_out[p]               (signal_dspin_clack_proc[p]);
+        xbar_clack_c->p_local_out[p]             (signal_dspin_clack_proc[p]);
 
     std::cout << "  - Clack Coherence crossbar connected" << std::endl;
@@ -575,16 +578,16 @@
     xicu->p_resetn                     (this->p_resetn);
     xicu->p_vci                        (signal_vci_tgt_xicu);
-    for ( size_t p=0 ; p<nb_procs ; p++)
+    for (size_t p = 0; p < nb_procs; p++)
     {
         xicu->p_irq[p]                 (signal_proc_it[p]);
     }
-    for ( size_t i=0 ; i<32 ; i++)
-    {
-        if ( io ) // I/O cluster
+    for (size_t i = 0; i < 32; i++)
+    {
+        if (io) // I/O cluster
         {
             if      (i < 8)                  xicu->p_hwi[i] (signal_false);
-            else if (i < (8 + nb_dmas))      xicu->p_hwi[i] (signal_irq_mdma[i-8]);
+            else if (i < (8 + nb_dmas))      xicu->p_hwi[i] (signal_irq_mdma[i - 8]);
             else if (i < 16)                 xicu->p_hwi[i] (signal_false);
-            else if (i < (16 + nb_ttys))     xicu->p_hwi[i] (signal_irq_mtty[i-16]);
+            else if (i < (16 + nb_ttys))     xicu->p_hwi[i] (signal_irq_mtty[i - 16]);
             else if (i < 31)                 xicu->p_hwi[i] (signal_false);
             else                             xicu->p_hwi[i] (signal_irq_bdev);
@@ -593,5 +596,5 @@
         {
             if      (i < 8)                  xicu->p_hwi[i] (signal_false);
-            else if (i < (8 + nb_dmas))      xicu->p_hwi[i] (signal_irq_mdma[i-8]);
+            else if (i < (8 + nb_dmas))      xicu->p_hwi[i] (signal_irq_mdma[i - 8]);
             else                             xicu->p_hwi[i] (signal_false);
         }
@@ -637,5 +640,5 @@
     mdma->p_vci_target                 (signal_vci_tgt_mdma);
     mdma->p_vci_initiator              (signal_vci_ini_mdma);
-    for (size_t i=0 ; i<nb_dmas ; i++)
+    for (size_t i = 0; i < nb_dmas; i++)
         mdma->p_irq[i]                 (signal_irq_mdma[i]);
 
@@ -658,5 +661,5 @@
     /////////////////////////////// Components in I/O cluster
 
-    if ( io )
+    if (io)
     {
         // BDEV
@@ -701,5 +704,5 @@
         mnic->p_resetn                 (this->p_resetn);
         mnic->p_vci                    (signal_vci_tgt_mnic);
-        for ( size_t i=0 ; i<nic_channels ; i++ )
+        for (size_t i = 0; i < nic_channels; i++)
         {
             mnic->p_rx_irq[i]          (signal_irq_mnic_rx[i]);
@@ -721,5 +724,5 @@
         chbuf->p_vci_target             (signal_vci_tgt_chbuf);
         chbuf->p_vci_initiator          (signal_vci_ini_chbuf);
-        for ( size_t i=0 ; i < chbufdma_channels ; i++ )
+        for (size_t i = 0; i < chbufdma_channels; i++)
         {
             chbuf->p_irq[i]          (signal_irq_chbuf[i]);
@@ -760,5 +763,5 @@
         mtty->p_resetn                 (this->p_resetn);
         mtty->p_vci                    (signal_vci_tgt_mtty);
-        for ( size_t i=0 ; i<nb_ttys ; i++ )
+        for (size_t i = 0; i < nb_ttys; i++)
         {
             mtty->p_irq[i]             (signal_irq_mtty[i]);
@@ -776,15 +779,66 @@
 } // end constructor
 
+
+
+template<size_t dspin_cmd_width,
+         size_t dspin_rsp_width,
+         typename vci_param_int,
+         typename vci_param_ext> TsarXbarCluster<dspin_cmd_width,
+                                                 dspin_rsp_width,
+                                                 vci_param_int,
+                                                 vci_param_ext>::~TsarXbarCluster() {
+
+    for (size_t p = 0; p < n_procs; p++)
+    {
+        delete proc[p];
+        delete wi_proc[p];
+    }
+
+    delete memc;
+    delete wt_memc;
+    delete xram;
+    delete xicu;
+    delete wt_xicu;
+    delete mdma;
+    delete wt_mdma;
+    delete wi_mdma;
+    delete xbar_cmd_d;
+    delete xbar_rsp_d;
+    delete xbar_m2p_c;
+    delete xbar_p2m_c;
+    delete xbar_clack_c;
+    delete router_cmd;
+    delete router_rsp;
+    if (brom != NULL)
+    {
+        delete brom;
+        delete wt_brom;
+        delete fbuf;
+        delete wt_fbuf;
+        delete bdev;
+        delete wt_bdev;
+        delete wi_bdev;
+        delete mnic;
+        delete wt_mnic;
+        delete chbuf;
+        delete wt_chbuf;
+        delete wi_chbuf;
+        delete mtty;
+        delete wt_mtty;
+    }
+}
+
+
 }}
 
 // Local Variables:
-// tab-width: 3
-// c-basic-offset: 3
+// tab-width: 4
+// c-basic-offset: 4
 // c-file-offsets:((innamespace . 0)(inline-open . 0))
 // indent-tabs-mode: nil
 // End:
 
-// vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3
-
-
-
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
+
+
