Changeset 52 for sources/src
- Timestamp:
- Jan 22, 2013, 4:23:22 PM (12 years ago)
- Location:
- sources/src
- Files:
-
- 107 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
sources/src/Makefile.am
r48 r52 1 sclibdir=$(prefix)/lib-@SC_LIB_TARGET@ 1 2 sclibdir = $(prefix)/lib-@SC_LIB_TARGET@ 2 3 3 4 sclib_LTLIBRARIES = libsystemc.la 4 5 5 libsystemc_objects= alias.o bit2string.o dump_dot.o dump_used_env.o 6 dump_used_options.o entity.o global_functions.o graph.o graph_cass.o 7 graph_signals.o hex2string.o methodprocess_dependency.o 8 module_hierarchy.o module_hierarchy2dot.o mouchard_scheduling.o 9 port_dependency.o process_dependency.o sc_clock.o sc_event.o 10 sc_event_finder.o sc_interface.o sc_main.o sc_module.o sc_numrep.o 11 sc_object.o sc_pat_trace.o sc_port.o sc_sensitive.o sc_time.o 12 sc_trace.o sc_uint_subref_r.o sc_vcd_trace.o sc_ver.o schedulers.o 6 libsystemc_objects= alias.o bit2string.o dump_dot.o dump_used_env.o \ 7 dump_used_options.o entity.o global_functions.o graph.o graph_cass.o \ 8 graph_signals.o hex2string.o methodprocess_dependency.o \ 9 module_hierarchy.o module_hierarchy2dot.o mouchard_scheduling.o \ 10 port_dependency.o process_dependency.o sc_clock.o sc_event.o \ 11 sc_event_finder.o sc_interface.o sc_main.o sc_module.o sc_numrep.o \ 12 sc_object.o sc_pat_trace.o sc_port.o sc_sensitive.o sc_time.o \ 13 sc_trace.o sc_uint_subref_r.o sc_vcd_trace.o sc_ver.o schedulers.o \ 13 14 serialization.o signal_dependency.o simplify_string.o 14 15 # sc_logic.o 15 16 16 libsystemc_headers= graph_cass.h sc_biguint.h sc_nbdefs.h 17 sc_unsigned.h alias.h sc_bit.h graph_signals.h sc_bv.h sc_numrep.h 18 sc_vcd_trace.h bit2string.h sc_clock.h sc_object.h sc_ver.h casc.h 19 hex2string.h sc_clock_ext.h sc_ver_ext.h data_field.h internal.h 20 sc_pat_trace.h internal_ext.h sc_event.h schedulers.h dump_dot.h 21 sc_port.h methodprocess_dependency.h sc_event_finder.h sc_port_ext.h 22 serialization.h dump_used_env.h sc_fwd.h serialization_ext.h 23 module_hierarchy.h sc_int.h sc_sensitive.h dump_used_options.h 24 sc_signal.h signal_dependency.h module_hierarchy2dot.h sc_interface.h 25 sc_signed.h entity.h module_hierarchy_ext.h sc_localvar.h sc_string.h 26 simplify_string.h fsm_rules.h systemc mouchard_scheduling.h sc_logic.h 27 sc_time.h systemc.h gen_code.h sc_lv.h systemcass_version_ext.h 28 port_dependency.h sc_trace.h usage.h global_functions.h 29 port_dependency_ext.h sc_trace_ext.h utils.h sc_module.h sc_uint.h 30 graph.h process_dependency.h sc_module_ext.h sc_bigint.h 17 libsystemc_headers= graph_cass.h sc_biguint.h sc_nbdefs.h \ 18 sc_unsigned.h alias.h sc_bit.h graph_signals.h sc_bv.h sc_numrep.h \ 19 sc_vcd_trace.h bit2string.h sc_clock.h sc_object.h sc_ver.h casc.h \ 20 hex2string.h sc_clock_ext.h sc_ver_ext.h data_field.h internal.h \ 21 sc_pat_trace.h internal_ext.h sc_event.h schedulers.h dump_dot.h \ 22 sc_port.h methodprocess_dependency.h sc_event_finder.h sc_port_ext.h \ 23 serialization.h dump_used_env.h sc_fwd.h serialization_ext.h \ 24 module_hierarchy.h sc_int.h sc_sensitive.h dump_used_options.h \ 25 sc_signal.h signal_dependency.h module_hierarchy2dot.h sc_interface.h \ 26 sc_signed.h entity.h module_hierarchy_ext.h sc_localvar.h sc_string.h \ 27 simplify_string.h fsm_rules.h systemc mouchard_scheduling.h sc_logic.h \ 28 sc_time.h systemc.h gen_code.h sc_lv.h systemcass_version_ext.h \ 29 port_dependency.h sc_trace.h usage.h global_functions.h \ 30 port_dependency_ext.h sc_trace_ext.h utils.h sc_module.h sc_uint.h \ 31 graph.h process_dependency.h sc_module_ext.h sc_bigint.h \ 31 32 sc_module_name.h sc_unit.h 32 33 … … 34 35 35 36 if WITH_ALLIANCE 36 ALLIANCE_LIBS = -L$(ALLIANCE_PATH)/lib -lMut -lPat -lPpt -lPgn37 ALLIANCE_LIBS = -L$(ALLIANCE_PATH)/lib -lMut -lPat -lPpt -lPgn 37 38 endif 38 39 … … 42 43 noinst_LTLIBRARIES = libgen_code.la 43 44 libgen_code_la_SOURCES = gen_code.cc 44 libgen_code_la_CXXFLAGS =-DGENERATED_MODULE_CFLAGS='"$(CXXFLAGS) -I$(prefix)/include"' @OPENMP_CFLAGS@45 libgen_code_la_CXXFLAGS = -DGENERATED_MODULE_CFLAGS='"$(CXXFLAGS) -I$(prefix)/include"' @OPENMP_CFLAGS@ 45 46 46 47 include_HEADERS = alias.h casc.h data_field.h global_functions.h internal_ext.h module_hierarchy_ext.h port_dependency_ext.h sc_bigint.h sc_biguint.h sc_bit.h sc_bv.h sc_clock_ext.h sc_event.h sc_fwd.h sc_int.h sc_interface.h sc_localvar.h sc_logic.h sc_lv.h sc_module_ext.h sc_module_name.h sc_nbdefs.h sc_numrep.h sc_object.h sc_pat_trace.h sc_port_ext.h sc_sensitive.h sc_signal.h sc_signed.h sc_string.h sc_time.h sc_trace_ext.h sc_uint.h sc_unit.h sc_unsigned.h sc_vcd_trace.h sc_ver_ext.h serialization_ext.h systemc systemc.h systemcass_version_ext.h 48 -
sources/src/alias.cc
r27 r52 34 34 35 35 #include "alias.h" 36 36 37 #include <iostream> 37 38 #ifdef HAVE_CONFIG_H … … 39 40 #endif 40 41 41 const char * alias () 42 { 42 const char * alias () { 43 43 static int i = 0; 44 char * buf = new char[4];44 char * buf = new char[4]; 45 45 buf[3] = '\0'; 46 46 buf[2] = 'a' + i % 26; -
sources/src/alias.h
r1 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef ALIAS_H 13 14 #define ALIAS_H … … 16 17 17 18 #endif 19 -
sources/src/bit2string.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : bit2string.cc |6 | |7 | Author : Kingbo Paul-Jerome |8 | Buchmann Richard |9 | |10 | Date : 09_07_2004 |11 | |12 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : bit2string.cc | 6 | | 7 | Author : Kingbo Paul-Jerome | 8 | Buchmann Richard | 9 | | 10 | Date : 09_07_2004 | 11 | | 12 \------------------------------------------------------------*/ 13 13 14 14 /* … … 37 37 #include "bit2string.h" 38 38 #include "sc_unit.h" 39 39 40 #include <cstdarg> 40 41 #include <cstdio> 41 42 #include <cstdlib> 42 43 #include <iostream> 44 43 45 #ifdef HAVE_CONFIG_H 44 46 #include "config.h" 45 47 #endif 46 48 47 49 using namespace std; 48 50 49 51 namespace sc_core { 50 52 51 static 52 void bit2string_64 (char *buf, tab_t *val,int size) 53 { 54 typedef sc_dt::s_uint_type<64>::uint_type data_type; 55 data_type tmp=*((data_type*)val); 56 //cout << "tmp = " << tmp << "\n"; 57 buf[size]='\0'; 58 for (int i=size-1; i>=0;--i) 59 { 60 buf[i]=(tmp&1)?'1':'0'; 61 tmp>>=1; 62 } 63 #if 0 64 cout << buf << "\n"; 65 #endif 53 static void bit2string_64(char * buf, tab_t * val, int size) { 54 typedef sc_dt::s_uint_type<64>::uint_type data_type; 55 data_type tmp = *((data_type *) val); 56 buf[size] = '\0'; 57 for (int i = size - 1; i >= 0; --i) { 58 buf[i] = (tmp & 1) ? '1' : '0'; 59 tmp >>= 1; 60 } 66 61 } 67 62 68 static 69 void bit2string_32 (char *buf, tab_t *val,int size) 70 { 71 typedef sc_dt::s_uint_type<32>::uint_type data_type; 72 data_type tmp=*((data_type*)val); 73 //cout << "tmp = " << tmp << "\n"; 74 buf[size]='\0'; 75 for (int i=size-1; i>=0;--i) 76 { 77 buf[i]=(tmp&1)?'1':'0'; 78 tmp>>=1; 79 } 80 #if 0 81 cout << buf << "\n"; 82 #endif 63 static void bit2string_32(char * buf, tab_t * val, int size) { 64 typedef sc_dt::s_uint_type<32>::uint_type data_type; 65 data_type tmp = *((data_type *) val); 66 buf[size] = '\0'; 67 for (int i = size - 1; i >= 0; --i) { 68 buf[i] = (tmp & 1) ? '1' : '0'; 69 tmp >>= 1; 70 } 83 71 } 84 72 85 void bit2string(char *buf, tab_t *val,int bit_number) 86 { 87 if (bit_number > 32) 88 { 89 bit2string_64 (buf, (tab_t*)val, bit_number); 90 return; 91 } else if (bit_number > 16) 92 { 93 bit2string_32 (buf, (tab_t*)val, bit_number); 94 return; 95 } 96 tab_t tmp=*((tab_t*)val); 97 //cout << "tmp = " << tmp << "\n"; 98 buf[bit_number]='\0'; 99 for (int i=bit_number-1; i>=0;--i) 100 { 101 buf[i]=(tmp&1)?'1':'0'; 102 tmp>>=1; 103 } 104 73 void bit2string(char * buf, tab_t * val, int bit_number) { 74 if (bit_number > 32) { 75 bit2string_64(buf, (tab_t *) val, bit_number); 76 return; 77 } 78 else if (bit_number > 16) { 79 bit2string_32(buf, (tab_t *) val, bit_number); 80 return; 81 } 82 tab_t tmp = *((tab_t *) val); 83 buf[bit_number] = '\0'; 84 for (int i = bit_number - 1; i >= 0; --i) { 85 buf[i] = (tmp & 1) ? '1' : '0'; 86 tmp >>= 1; 87 } 88 105 89 } 106 90 107 char * strip (char * buf)108 { 109 int cpt=0; 110 while ( (buf[cpt] == '0') && (buf[cpt+1] != '\0') ) //tant que bit == 0 111 cpt++; 112 return (buf+cpt);91 char * strip(char * buf) { 92 int cpt = 0; 93 while ((buf[cpt] == '0') && (buf[cpt + 1] != '\0')) {// tant que bit == 0 94 cpt++; 95 } 96 return (buf + cpt); 113 97 } 114 98 115 99 } // end of sc_core namespace 116 100 101 102 /* 103 # Local Variables: 104 # tab-width: 4; 105 # c-basic-offset: 4; 106 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 107 # indent-tabs-mode: nil; 108 # End: 109 # 110 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 111 */ 112 -
sources/src/bit2string.h
r1 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef BIT2STRING_H 13 14 #define BIT2STRING_H … … 17 18 namespace sc_core { 18 19 19 extern void bit2string (char *buf,tab_t *val,int bit_number);20 extern char * strip (char *bitstring);20 extern void bit2string(char * buf, tab_t * val, int bit_number); 21 extern char * strip(char * bitstring); 21 22 22 23 } // end of sc_core namespace 23 24 24 25 #endif 26 -
sources/src/casc.h
r47 r52 1 1 /*------------------------------------------------------------\ 2 | | 3 | Tool : systemcass | 4 | | 5 | File : casc.h | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 09_07_2004 | 10 | | 11 \------------------------------------------------------------*/ 2 | | 3 | Tool : systemcass | 4 | | 5 | File : casc.h | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 09_07_2004 | 10 | | 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __CASC_H__ 13 14 #define __CASC_H__ … … 26 27 27 28 namespace sc_core { 28 29 struct sc_module; 30 31 inline void transition (void); 32 EXTERN void update (void); 33 inline void moore_generation (void); 34 EXTERN void mealy_generation (void); 35 EXTERN bool casc_check_version(const char*); 29 struct sc_module; 30 inline void transition (void); 31 EXTERN void update (void); 32 inline void moore_generation (void); 33 EXTERN void mealy_generation (void); 34 EXTERN bool casc_check_version(const char *); 36 35 } 37 36 … … 41 40 namespace sc_core { 42 41 43 EXTERN void initialize () 44 { 45 casc_check_version (SYSTEMC_VERSION); 46 } 42 EXTERN void initialize() { 43 casc_check_version(SYSTEMC_VERSION); 44 } 47 45 48 EXTERN void simulate_1_cycle (void) 49 { 50 transition (); 51 update (); 52 moore_generation (); 53 mealy_generation (); 54 } 46 EXTERN void simulate_1_cycle(void) { 47 transition(); 48 update(); 49 moore_generation(); 50 mealy_generation(); 51 } 55 52 } // end of sc_core namespace 56 53 57 54 #endif 58 55 59 60 56 #endif 61 57 58 /* 59 # Local Variables: 60 # tab-width: 4; 61 # c-basic-offset: 4; 62 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 63 # indent-tabs-mode: nil; 64 # End: 65 # 66 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 67 */ 68 -
sources/src/data_field.h
r27 r52 13 13 #define __DATA_FIELD_H__ 14 14 15 template<int WIDTH, 16 int PADDING, 17 typename data_type> 15 template <int WIDTH, int PADDING, typename data_type> 18 16 struct val_field { 19 17 data_type valW:WIDTH; 20 18 }; 21 19 22 template<int WIDTH, 23 typename data_type> 24 struct val_field<WIDTH,0,data_type> { 20 template <int WIDTH, typename data_type> 21 struct val_field<WIDTH, 0, data_type> { 25 22 data_type valW:WIDTH; 26 23 }; -
sources/src/dump_dot.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : dump_dot.cc |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : 09_07_2004 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : dump_dot.cc | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 09_07_2004 | 10 | | 11 \------------------------------------------------------------*/ 12 12 13 13 /* … … 44 44 #endif 45 45 46 typedef std::list<sc_core::sc_port_base*> port_list_t; 46 typedef std::list<sc_core::sc_port_base *> port_list_t; 47 47 48 using namespace std; 48 49 … … 52 53 53 54 // Build a port list owned by the module mod 54 static void 55 get_out_port_list (const sc_module &mod, port_list_t &pl) 56 { 57 port2module_t::iterator i; 58 for (i = port2module.begin (); i != port2module.end (); ++i) { 59 if ((i->second == &mod) && (i->first)) { 60 pl.push_back ((sc_port_base*)(i->first)); 61 } 62 } 55 static void get_out_port_list(const sc_module & mod, port_list_t & pl) { 56 port2module_t::iterator i; 57 for (i = port2module.begin(); i != port2module.end(); ++i) { 58 if ((i->second == &mod) && (i->first)) { 59 pl.push_back((sc_port_base *) (i->first)); 60 } 61 } 63 62 } 64 63 65 static void 66 dump_dot (ofstream &o, method_process_t &m) 67 { 68 port_list_t port_list; 69 get_out_port_list (*(m.module),port_list); 70 port_list_t::iterator op; 71 for (op = port_list.begin (); op != port_list.end (); ++op) 72 { 73 sensitivity_list_t::iterator ip; 74 for (ip = m.sensitivity_list.begin(); ip != m.sensitivity_list.end();++ip) 75 { 76 if (is_clock (ip->get_interface())) 77 continue; 78 const char *in = get_name (ip->get_interface().get_pointer()); 79 const char *out = (*op)->name (); 80 string s; 81 o << simplify_name(in,s); 82 o << "->"; 83 o << simplify_name(out,s); 84 o << ";\n"; 85 } 86 } 64 static void dump_dot(ofstream & o, method_process_t & m) { 65 port_list_t port_list; 66 get_out_port_list(*(m.module), port_list); 67 port_list_t::iterator op; 68 for (op = port_list.begin(); op != port_list.end(); ++op) { 69 sensitivity_list_t::iterator ip; 70 for (ip = m.sensitivity_list.begin(); ip != m.sensitivity_list.end(); ++ip) { 71 if (is_clock(ip->get_interface())) { 72 continue; 73 } 74 const char * in = get_name(ip->get_interface().get_pointer()); 75 const char * out = (*op)->name(); 76 string s; 77 o << simplify_name(in, s); 78 o << "->"; 79 o << simplify_name(out, s); 80 o << ";\n"; 81 } 82 } 87 83 } 88 84 89 static void 90 dump_all (ofstream &o, method_process_list_t &lm) 91 { 92 method_process_list_t::iterator it; 93 for (it = lm.begin (); it != lm.end (); ++it) 94 dump_dot (o,**it); 85 86 static void dump_all(ofstream & o, method_process_list_t & lm) { 87 method_process_list_t::iterator it; 88 for (it = lm.begin(); it != lm.end(); ++it) { 89 dump_dot(o, **it); 90 } 95 91 } 96 92 97 static void 98 dump_all (ofstream &o, const Vertex & v) 99 { 100 if (v.arcs == NULL) 101 return; 102 Arc *a; 103 for (a = v.arcs; a; a = a->next) 104 { 105 method_process_t *m = (method_process_t*)v.data; 106 method_process_t *m2 = (method_process_t*)a->tip->data; 107 o << m->module->name (); 108 o << " -> " 109 << m2->module->name () 110 << "\n"; 111 } 93 94 static void dump_all(ofstream & o, const Vertex & v) { 95 if (v.arcs == NULL) { 96 return; 97 } 98 Arc * a; 99 for (a = v.arcs; a != NULL; a = a->next) { 100 method_process_t * m = (method_process_t *) v.data; 101 method_process_t * m2 = (method_process_t *) a->tip->data; 102 o << m->module->name(); 103 o << " -> " << m2->module->name() << "\n"; 104 } 112 105 } 113 106 114 static void 115 dump_all (ofstream &o, Graph &g) 116 { 117 Vertex *v; 118 for (v = g.vertices; v < g.vertices + g.n; v++) 119 { 120 dump_all (o,*v); 121 } 107 108 static void dump_all(ofstream & o, Graph & g) { 109 Vertex *v; 110 for (v = g.vertices; v < g.vertices + g.n; v++) { 111 dump_all(o, *v); 112 } 122 113 } 123 114 124 bool 125 SignalDependancyGraph2dot (const char *name, method_process_list_t &lm) 126 {127 if (!name) 128 return false; 129 130 filename =name;131 132 133 o.open (filename.c_str(),ios::out | ios::trunc);134 if (o.is_open () == false) 135 136 o << "// Signal dependency graph\n" 137 "// Generated by"138 << sc_version() << "\n";139 140 dump_all (o,lm);141 142 o.close();143 115 116 bool SignalDependancyGraph2dot(const char * name, method_process_list_t & lm) { 117 if (!name) { 118 return false; 119 } 120 string filename; 121 filename = name; 122 filename += ".dot"; 123 ofstream o; 124 o.open(filename.c_str(), ios::out | ios::trunc); 125 if (o.is_open() == false) { 126 return false; 127 } 128 o << "// Signal dependency graph\n" 129 "// Generated by " << sc_version() << "\n"; 130 o << "strict digraph " << name << " {\n"; 131 dump_all(o, lm); 132 o << "}\n"; 133 o.close(); 134 return true; 144 135 } 145 136 146 137 147 138 148 bool 149 FctDependancyGraph2dot (const char *name, Graph *g) 150 { 151 if (!name) 152 return false; 153 if (!g) 154 return false; 155 156 filename =name;157 158 159 o.open (filename.c_str(),ios::out | ios::trunc);160 if (o.is_open () == false) 161 162 o << "// Function dependency graph\n" 163 "// Generated by"164 << sc_version() << "\n";165 166 dump_all (o,*g);167 168 o.close();169 139 bool FctDependancyGraph2dot(const char * name, Graph * g) { 140 if (!name) { 141 return false; 142 } 143 if (!g) { 144 return false; 145 } 146 string filename; 147 filename = name; 148 filename += ".dot"; 149 ofstream o; 150 o.open(filename.c_str(), ios::out | ios::trunc); 151 if (o.is_open() == false) { 152 return false; 153 } 154 o << "// Function dependency graph\n" 155 "// Generated by " << sc_version() << "\n"; 156 o << "digraph " << name << " {\n"; 157 dump_all(o, *g); 158 o << "}\n"; 159 o.close(); 160 return true; 170 161 } 171 162 172 163 } // end of sc_core namespace 173 164 165 /* 166 # Local Variables: 167 # tab-width: 4; 168 # c-basic-offset: 4; 169 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 170 # indent-tabs-mode: nil; 171 # End: 172 # 173 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 174 */ -
sources/src/dump_dot.h
r1 r52 14 14 15 15 #include <list> 16 16 17 #include "sc_fwd.h" 17 18 #include "graph.h" 18 19 19 20 namespace sc_core { 20 extern bool SignalDependancyGraph2dot (const char *name, method_process_list_t &lm); 21 extern bool FctDependancyGraph2dot (const char *name, Graph*); 21 22 extern bool SignalDependancyGraph2dot(const char * name, method_process_list_t & lm); 23 extern bool FctDependancyGraph2dot(const char * name, Graph *); 24 22 25 } 23 26 24 27 #endif 28 -
sources/src/dump_used_env.cc
r42 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : dump_used_env.cc |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : 10_MAY_2005 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : dump_used_env.cc | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 10_MAY_2005 | 10 | | 11 \------------------------------------------------------------*/ 12 12 13 13 /* … … 35 35 36 36 #include <cstdlib> 37 37 38 #include "dump_used_env.h" 38 39 #ifdef HAVE_CONFIG_H … … 40 41 #endif 41 42 42 std::string 43 sc_core::get_used_env() 44 { 45 const char *compiler = getenv ("GCC"); 46 const char *systemc_dir = getenv ("SYSTEMCASS"); 47 const char *target_arch = getenv ("TARGET_ARCH"); 48 if (compiler == NULL) 49 compiler = "undefined"; 50 if (systemc_dir == NULL) 51 systemc_dir = "undefined"; 52 if (target_arch == NULL) 53 target_arch = "undefined"; 54 std::string used_env; 55 used_env += "GCC = "; 56 used_env += compiler; 57 used_env += "\nSYSTEMCASS = "; 58 used_env += systemc_dir; 59 used_env += "\nTARGET_ARCH = "; 60 used_env += target_arch; 61 return used_env; 43 std::string sc_core::get_used_env() { 44 const char * compiler = getenv("GCC"); 45 const char * systemc_dir = getenv("SYSTEMCASS"); 46 const char * target_arch = getenv("TARGET_ARCH"); 47 48 if (compiler == NULL) { 49 compiler = "undefined"; 50 } 51 52 if (systemc_dir == NULL) { 53 systemc_dir = "undefined"; 54 } 55 56 if (target_arch == NULL) { 57 target_arch = "undefined"; 58 } 59 60 std::string used_env; 61 used_env += "GCC = "; 62 used_env += compiler; 63 used_env += "\nSYSTEMCASS = "; 64 used_env += systemc_dir; 65 used_env += "\nTARGET_ARCH = "; 66 used_env += target_arch; 67 68 return used_env; 62 69 } 70 71 /* 72 # Local Variables: 73 # tab-width: 4; 74 # c-basic-offset: 4; 75 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 76 # indent-tabs-mode: nil; 77 # End: 78 # 79 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 80 */ 81 -
sources/src/dump_used_env.h
r1 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef DUMP_USED_ENV_H 13 14 #define DUMP_USED_ENV_H -
sources/src/dump_used_options.cc
r47 r52 35 35 36 36 #include "dump_used_options.h" 37 37 38 #ifdef HAVE_CONFIG_H 38 39 #include "config.h" … … 41 42 namespace sc_core { 42 43 43 static 44 const char used_options[] = 44 static const char used_options[] = 45 45 "Used Options :\n" 46 46 #ifdef USE_PORT_DEPENDENCY … … 94 94 "..."; 95 95 96 const char* 97 get_used_options() 98 { 96 const char * get_used_options() { 99 97 return used_options; 100 98 } … … 102 100 } // end of sc_core namespace 103 101 102 /* 103 # Local Variables: 104 # tab-width: 4; 105 # c-basic-offset: 4; 106 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 107 # indent-tabs-mode: nil; 108 # End: 109 # 110 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 111 */ 112 113 -
sources/src/dump_used_options.h
r1 r52 15 15 namespace sc_core { 16 16 17 extern const char * get_used_options();17 extern const char * get_used_options(); 18 18 19 19 } -
sources/src/entity.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : entity.cc |6 | |7 | Author : Buchmann Richard |8 | Taktak Sami |9 | |10 | Date : 09_07_2004 |11 | |12 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : entity.cc | 6 | | 7 | Author : Buchmann Richard | 8 | Taktak Sami | 9 | | 10 | Date : 09_07_2004 | 11 | | 12 \------------------------------------------------------------*/ 13 13 14 14 /* … … 40 40 #include <map> 41 41 #include <vector> 42 43 42 #include <cassert> 43 44 44 #include "entity.h" 45 45 #include "sc_port.h" 46 46 #include "sc_signal.h" 47 47 #include "sc_module.h" 48 48 49 #ifdef HAVE_CONFIG_H 49 50 #include "config.h" … … 53 54 54 55 namespace sc_core { 55 equi_list_t equi_list; 56 equi_table_t equi_table = NULL; 57 58 ostream& operator << (ostream &, const entity &); 59 ostream& operator << (ostream &, const equi_t &); 60 61 struct predic4entity2equi_t_t 62 { 63 bool operator()(const entity &e1, const entity &e2) const 64 { 65 return e1.interface < e2.interface; 66 } 67 }; 68 69 typedef std::map<entity,equi_list_t::iterator,predic4entity2equi_t_t> entity2equi_it_t; 70 71 ostream& operator << (ostream& o, const entity2equi_it_t &m) 72 { 56 57 equi_list_t equi_list; 58 equi_table_t equi_table = NULL; 59 60 ostream & operator << (ostream &, const entity &); 61 ostream & operator << (ostream &, const equi_t &); 62 63 struct predic4entity2equi_t_t { 64 bool operator() (const entity & e1, const entity & e2) const { 65 return e1.interface < e2.interface; 66 } 67 }; 68 69 typedef std::map <entity, equi_list_t::iterator, predic4entity2equi_t_t> entity2equi_it_t; 70 71 72 ostream & operator << (ostream & o, const entity2equi_it_t & m) { 73 73 entity2equi_it_t::const_iterator i; 74 for (i = m.begin(); i != m.end(); ++i) 75 { 76 o << (i->first) << " : " << *(i->second) << "\n"; 74 for (i = m.begin(); i != m.end(); ++i) { 75 o << (i->first) << " : " << *(i->second) << "\n"; 77 76 } 78 77 return o; 79 } 80 entity2equi_it_t equi_map; 81 82 const equi_list_t& get_equi_list () 83 { 78 } 79 80 entity2equi_it_t equi_map; 81 82 83 const equi_list_t & get_equi_list() { 84 84 return equi_list; 85 } 86 87 unsigned int 88 max (unsigned int a, unsigned int b) 89 { 90 return (a > b)?a:b; 91 } 92 93 static 94 int get_signal_table_size (const equi_list_t &e) 95 { 96 // bug fix : remove the 0x0 equi from the list 85 } 86 87 88 unsigned int max(unsigned int a, unsigned int b) { 89 return (a > b) ? a : b; 90 } 91 92 93 static int get_signal_table_size(const equi_list_t & e) { 94 // bug fix : remove the 0x0 equi from the list 97 95 equi_list_t::const_iterator i; 98 96 int capacity = 0; 99 for (i = e.begin (); i != e.end(); ++i) {100 //cerr << i->begin()->object->name ();101 const entity &ent = *(i->begin());102 intdata_size = ent.data_size_in_bytes();103 intnumber_of_part = ((data_size - 1) / sizeof(tab_t)) + 1;104 capacity += number_of_part;97 for (i = e.begin(); i != e.end(); ++i) { 98 //cerr << i->begin()->object->name (); 99 const entity & ent = *(i->begin()); 100 int data_size = ent.data_size_in_bytes(); 101 int number_of_part = ((data_size - 1) / sizeof(tab_t)) + 1; 102 capacity += number_of_part; 105 103 } 106 104 return capacity; 107 } 108 109 int get_signal_table_size () 110 { 111 return get_signal_table_size (equi_list); 112 } 113 114 sc_port_base* 115 get_out_port (const equi_t &eq) 116 { 117 equi_t::const_iterator i; 118 for (i = eq.begin (); i != eq.end (); ++i) { 119 const char *type = i->kind (); 120 if ((type == sc_core::sc_out_string)||(type == sc_core::sc_inout_string)) 121 return i->port; 122 } 123 /* 124 cerr << "Internal error : can't find out port in " 125 << eq << ".\n"; 126 exit(32); 127 */ 128 return NULL; 129 } 130 131 static 132 sc_port_base* 133 get_localvar (equi_t &eq) 134 { 135 equi_t::iterator i; 136 for (i = eq.begin (); i != eq.end (); ++i) { 137 const char *type = i->kind (); 138 if (strcmp (type, "sc_localvar") == 0) 139 return i->port; 140 } 141 return NULL; 142 } 143 144 static 145 sc_port_base* 146 get_signal (equi_t &eq) 147 { 148 equi_t::iterator i; 149 for (i = eq.begin (); i != eq.end (); ++i) { 150 const char *type = i->kind (); 151 if (strcmp (type, "sc_signal") == 0) 152 return i->port; 153 } 154 return NULL; 155 } 156 157 equi_t& 158 get_equi (const sc_interface &i) 159 { 160 return get_equi (i.get_pointer ()); 161 } 162 163 struct predic4tab_t2equi_t_t 164 { 165 bool operator()(const tab_t *t1, const tab_t *t2) const 166 { 167 return t1 < t2; 168 } 169 }; 105 } 106 107 108 int get_signal_table_size() { 109 return get_signal_table_size(equi_list); 110 } 111 112 113 sc_port_base * get_out_port(const equi_t & eq) { 114 equi_t::const_iterator i; 115 for (i = eq.begin(); i != eq.end(); ++i) { 116 const char * type = i->kind(); 117 if ((type == sc_core::sc_out_string) || (type == sc_core::sc_inout_string)) { 118 return i->port; 119 } 120 } 121 return NULL; 122 } 123 124 static sc_port_base *get_localvar(equi_t & eq) { 125 equi_t::iterator i; 126 for (i = eq.begin(); i != eq.end(); ++i) { 127 const char *type = i->kind(); 128 if (strcmp(type, "sc_localvar") == 0) { 129 return i->port; 130 } 131 } 132 return NULL; 133 } 134 135 136 static sc_port_base *get_signal(equi_t & eq) { 137 equi_t::iterator i; 138 for (i = eq.begin(); i != eq.end(); ++i) { 139 const char * type = i->kind(); 140 if (strcmp(type, "sc_signal") == 0) { 141 return i->port; 142 } 143 } 144 return NULL; 145 } 146 147 148 equi_t & get_equi(const sc_interface & i) { 149 return get_equi(i.get_pointer()); 150 } 151 152 153 struct predic4tab_t2equi_t_t { 154 bool operator() (const tab_t * t1, const tab_t * t2) const { 155 return t1 < t2; 156 } 157 }; 158 170 159 171 160 #define get_equi_SPEEDUP 172 equi_t& 173 get_equi (const tab_t *pointer) 174 { 161 equi_t & get_equi(const tab_t * pointer) { 175 162 // result variable 176 163 equi_list_t::iterator i; 177 164 #if defined(get_equi_SPEEDUP) 178 typedef std::map <const tab_t *,equi_list_t::iterator,predic4tab_t2equi_t_t> tab_t2equi_it_t;165 typedef std::map <const tab_t *, equi_list_t::iterator, predic4tab_t2equi_t_t> tab_t2equi_it_t; 179 166 static tab_t2equi_it_t tab2equi_map; 180 167 assert(pointer != NULL); 181 168 182 169 // boost 183 tab_t2equi_it_t::/*const_*/iterator it = tab2equi_map.find (pointer); 184 if (it != tab2equi_map.end ()) 185 { 186 i = it->second; 187 return *i; 188 } 189 #endif 190 // 191 for (i = equi_list.begin (); i != equi_list.end (); ++i) { 192 const equi_t::iterator &j = i->begin(); 193 const entity &e = *j; 194 const sc_interface *f = e.interface; 195 const tab_t *p = f->get_pointer (); 196 if (p == pointer) 197 { 170 tab_t2equi_it_t:: /*const_ */ iterator it = tab2equi_map.find(pointer); 171 if (it != tab2equi_map.end()) { 172 i = it->second; 173 return *i; 174 } 175 #endif 176 177 178 for (i = equi_list.begin(); i != equi_list.end(); ++i) { 179 const equi_t::iterator & j = i->begin(); 180 const entity & e = *j; 181 const sc_interface * f = e.interface; 182 const tab_t * p = f->get_pointer(); 183 if (p == pointer) { 198 184 #if defined(get_equi_SPEEDUP) 199 tab2equi_map[pointer] = i;200 #endif 201 202 }203 204 cerr << "Internal error : get_equi(" << pointer << ")\n"; 205 exit(11);206 185 tab2equi_map[pointer] = i; 186 #endif 187 return *i; 188 } 189 } 190 cerr << "Internal error : get_equi(" << pointer << ")\n"; 191 exit(11); 192 } 207 193 #undef get_equi_SPEEDUP 208 194 209 bool 210 has_equi (/*const*/ sc_port_base &port) 211 { 195 196 bool has_equi( /*const */ sc_port_base & port) { 212 197 entity e(port); 213 entity2equi_it_t::/*const_*/iterator it = equi_map.find (e); 214 if (it == equi_map.end ()) 215 { 216 return false; 198 entity2equi_it_t::/*const_ */iterator it = equi_map.find(e); 199 if (it == equi_map.end()) { 200 return false; 217 201 } 218 202 return true; 219 } 220 221 static 222 bool 223 is_register (const equi_t &eq) 224 { 225 return eq.size () == 1; 226 } 227 228 static 229 int 230 count_level (const char *s, char c) 231 { 232 int i; 233 int counter = 0; 234 for (i = 0; s[i] != '\0'; ++i) { 235 if (s[i] == c) 236 ++counter; 237 } 238 return counter; 239 } 240 241 const char* 242 get_name (const equi_t& e) 243 { 244 equi_t::const_iterator top_iter = e.begin (); 203 } 204 205 206 static bool is_register(const equi_t & eq) { 207 return eq.size() == 1; 208 } 209 210 static int count_level(const char * s, char c) { 211 int i; 212 int counter = 0; 213 for (i = 0; s[i] != '\0'; ++i) { 214 if (s[i] == c) { 215 ++counter; 216 } 217 } 218 return counter; 219 } 220 221 222 const char * get_name(const equi_t & e) { 223 equi_t::const_iterator top_iter = e.begin(); 245 224 #ifdef CONFIG_DEBUG 246 if (top_iter == e.end()) {247 248 exit(25);249 250 251 252 253 254 exit(26);255 256 if (top_iter->object->name() == NULL) {257 258 259 260 261 #endif 262 int top_level = count_level (top_iter->object->name (),'.');263 264 for (i = ++(e.begin ()); i != e.end(); ++i) {265 int current_level = count_level (i->object->name (),'.');266 267 268 269 270 225 if (top_iter == e.end()) { 226 cerr << "Internal error : no signal in " << e << endl; 227 exit(25); 228 } 229 if (top_iter->object == NULL) { 230 cerr << "Internal error : no object bound to "; 231 cerr << *top_iter; 232 cerr << endl; 233 exit(26); 234 } 235 if (top_iter->object->name() == NULL) { 236 cerr << "Internal error : signal has no name.\n"; 237 cerr << *top_iter; 238 cerr << endl; 239 } 240 #endif 241 int top_level = count_level(top_iter->object->name(), '.'); 242 equi_t::const_iterator i; 243 for (i = ++(e.begin()); i != e.end(); ++i) { 244 int current_level = count_level(i->object->name(), '.'); 245 if (current_level < top_level) { 246 top_iter = i; 247 top_level = current_level; 248 } 249 } 271 250 #if 0 272 cerr << "get_name of " << e; 273 cerr << " return " << top_iter->object->name () << endl; 274 #endif 275 return top_iter->object->name (); 276 } 277 278 const char* 279 get_name (const tab_t *pointer) 280 { 281 return get_name (get_equi (pointer)); 282 } 283 284 static 285 const sc_module& 286 get_module (const string &s) 287 { 288 instances_set_t::iterator i; 289 for (i = instances_set.begin (); i != instances_set.end (); ++i) { 290 if (strcmp ((*i)->name (), s.c_str ()) == 0) 291 return **i; 292 } 293 cerr << "Internal error : get_module\n"; 294 exit (27); 295 } 296 297 template<typename T> static 298 equi_list_t::iterator get_equi (T &e) 299 { 300 entity2equi_it_t::iterator it = equi_map.find (entity(e)); 301 if (it == equi_map.end()) 302 { 303 // cerr << "Internal error : get_equi (T &)"; 304 return equi_list.end (); 251 cerr << "get_name of " << e; 252 cerr << " return " << top_iter->object->name() << endl; 253 #endif 254 return top_iter->object->name(); 255 } 256 257 258 const char *get_name(const tab_t * pointer) { 259 return get_name(get_equi(pointer)); 260 } 261 262 263 static const sc_module & get_module(const string & s) { 264 instances_set_t::iterator i; 265 for (i = instances_set.begin(); i != instances_set.end(); ++i) { 266 if (strcmp((*i)->name(), s.c_str()) == 0) { 267 return **i; 268 } 269 } 270 cerr << "Internal error : get_module\n"; 271 exit(27); 272 } 273 274 275 template < typename T > static equi_list_t::iterator get_equi(T & e) { 276 entity2equi_it_t::iterator it = equi_map.find(entity(e)); 277 if (it == equi_map.end()) { 278 return equi_list.end(); 305 279 } 306 280 return it->second; 307 } 308 309 template<typename T> static 310 void 311 add_equi (equi_list_t::iterator &x, T &y) 312 { 281 } 282 283 284 template < typename T > static void add_equi(equi_list_t::iterator & x, T & y) { 313 285 entity e(y); 314 x->push_back 286 x->push_back(e); 315 287 equi_map[e] = x; 316 } 317 318 template<typename T> static 319 equi_list_t::iterator 320 new_equi (T &x) /* parameter is not 'const' because we need to modify pointer port/signal at end of elaboration step */ 321 { 322 equi_list_t::iterator it = equi_list.insert (equi_list.begin (),equi_t(1,entity(x))); 288 } 289 290 291 template < typename T > static 292 equi_list_t::iterator new_equi(T & x) { /* parameter is not 'const' because we need to modify pointer port/signal at end of elaboration step */ 293 equi_list_t::iterator it = equi_list.insert(equi_list.begin(), equi_t(1, entity(x))); 323 294 equi_map[entity(x)] = it; 324 295 return it; 325 } 326 327 // sort by number of connected ports bound to the signal 328 static 329 int 330 operator<(const equi_t &e1, const equi_t &e2) 331 { 332 return (e1.size() < e2.size ()); 333 } 334 335 // sort by data size 336 /* 337 int operator<(const equi_t &e1, const equi_t &e2) 338 { 339 return (e1.begin()->data_size () < e2.begin()->data_size ()); 340 } 341 */ 342 // random sort 343 /* 344 int operator<(const equi_t &e1, const equi_t &e2) 345 { 346 typedef std::map<const equi_t*,int> m_t; 347 static m_t m; 348 if (m[&e1] == 0) 349 m[&e1] = rand (); 350 if (m[&e2] == 0) 351 m[&e2] = rand (); 352 return m[&e1] < m[&e2]; 353 } 354 */ 355 void sort_equi_list () 356 { 357 //load (); 358 equi_list.sort (); 296 } 297 298 299 // sort by number of connected ports bound to the signal 300 static int operator <(const equi_t & e1, const equi_t & e2) { 301 return (e1.size() < e2.size()); 302 } 303 304 // sort by data size 305 /* 306 int operator<(const equi_t &e1, const equi_t &e2) 307 { 308 return (e1.begin()->data_size () < e2.begin()->data_size ()); 309 } 310 */ 311 // random sort 312 /* 313 int operator<(const equi_t &e1, const equi_t &e2) 314 { 315 typedef std::map<const equi_t*,int> m_t; 316 static m_t m; 317 if (m[&e1] == 0) 318 m[&e1] = rand (); 319 if (m[&e2] == 0) 320 m[&e2] = rand (); 321 return m[&e1] < m[&e2]; 322 } 323 */ 324 325 void sort_equi_list() { 326 //load (); 327 equi_list.sort(); 359 328 //equi_list.reverse (); 360 } 361 329 } 330 331 362 332 #if defined(DUMP_SIGNAL_STATS) 363 static unsigned int equi_real_size; 364 #endif 365 366 unsigned int 367 get_sizeof_signals_table () 368 { 333 static unsigned int equi_real_size; 334 #endif 335 336 unsigned int get_sizeof_signals_table() { 369 337 equi_list_t::iterator i; 370 338 int table_size = 0; 371 //cerr << "external table includes :\n"; 372 for (i = equi_list.begin (); i != equi_list.end (); ++i) { 373 if (get_out_port (*i)) 374 continue; 375 if (get_signal (*i)) 376 continue; 377 //cerr << get_name (*i) << " "; 378 const entity &ent = *(i->begin()); 379 int data_size = ent.data_size_in_bytes(); 380 int number_of_part = ((data_size - 1) / sizeof(tab_t)) + 1; 381 table_size += number_of_part; 382 } 339 //cerr << "external table includes :\n"; 340 for (i = equi_list.begin(); i != equi_list.end(); ++i) { 341 if (get_out_port(*i)) { 342 continue; 343 } 344 if (get_signal(*i)) { 345 continue; 346 } 347 //cerr << get_name (*i) << " "; 348 const entity & ent = *(i->begin()); 349 int data_size = ent.data_size_in_bytes(); 350 int number_of_part = ((data_size - 1) / sizeof(tab_t)) + 1; 351 table_size += number_of_part; 352 } 383 353 return table_size; 384 } 385 386 void 387 create_signals_table () 388 { 389 if (dump_stage) 390 cerr << "Allocating signals table.\n"; 391 //cerr << "\n"; 392 unsigned int table_size = get_sizeof_signals_table (); 393 equi_table = new tab_t[table_size]; //(0xCD); 354 } 355 356 357 void create_signals_table() { 358 if (dump_stage) { 359 cerr << "Allocating signals table.\n"; 360 } 361 unsigned int table_size = get_sizeof_signals_table(); 362 equi_table = new tab_t[table_size]; //(0xCD); 394 363 #if defined(DUMP_SIGNAL_STATS) 395 364 equi_real_size = table_size; 396 365 #endif 397 366 #if defined(INIT_SIGNALS_TO_ZERO) 398 memset (equi_table, 0, sizeof(tab_t) * table_size);367 memset(equi_table, 0, sizeof(tab_t) * table_size); 399 368 #else 400 memset (equi_table, 0xCD, sizeof (tab_t) * table_size); 401 #endif 402 } 403 404 static 405 void 406 bind_equi_to_table (equi_t &e, tab_t * const pointer) 407 { 369 memset(equi_table, 0xCD, sizeof(tab_t) * table_size); 370 #endif 371 } 372 373 374 static void bind_equi_to_table(equi_t & e, tab_t * const pointer) { 408 375 assert(pointer != NULL); 409 376 equi_t::iterator i; 410 for (i = e.begin (); i != e.end(); ++i) {411 sc_interface *const inter = i->interface;412 inter->set_pointer(pointer);413 // We can't initialize data to zero there414 // because we can't write the right amount of bits.415 // It may produce some segmentation fault errors.416 // The pointer is aligned to 32 bits.417 } 418 419 420 void 421 bind_to_table () 422 {423 if (dump_stage)424 cerr << "Binding ports/signals to the table.\n";377 for (i = e.begin(); i != e.end(); ++i) { 378 sc_interface *const inter = i->interface; 379 inter->set_pointer(pointer); 380 // We can't initialize data to zero there 381 // because we can't write the right amount of bits. 382 // It may produce some segmentation fault errors. 383 // The pointer is aligned to 32 bits. 384 } 385 } 386 387 388 void bind_to_table() { 389 if (dump_stage) { 390 cerr << "Binding ports/signals to the table.\n"; 391 } 425 392 equi_list_t::iterator i; 426 393 int index = 0; 427 for (i = equi_list.begin (); i != equi_list.end (); ++i) { 428 sc_interface *out = get_out_port (*i); 429 if (out) { 430 bind_equi_to_table (*i, out->get_pointer ()); 431 } else { 432 sc_interface *reg = get_signal (*i); 433 if (reg == NULL) 434 reg = get_localvar (*i); 435 if (reg) { 436 bind_equi_to_table (*i, reg->get_pointer ()); 437 } else { 438 bind_equi_to_table (*i, &(equi_table[index])); 439 index += (i->begin()->data_size_in_bytes() - 1) / sizeof(tab_t) + 1; 440 } 441 } 442 } 443 } 444 445 ostream& 446 operator << (ostream &o, const entity &e) 447 { 394 for (i = equi_list.begin(); i != equi_list.end(); ++i) { 395 sc_interface *out = get_out_port(*i); 396 if (out) { 397 bind_equi_to_table(*i, out->get_pointer()); 398 } 399 else { 400 sc_interface * reg = get_signal(*i); 401 if (reg == NULL) { 402 reg = get_localvar(*i); 403 } 404 if (reg) { 405 bind_equi_to_table(*i, reg->get_pointer()); 406 } 407 else { 408 bind_equi_to_table(*i, &(equi_table[index])); 409 index += (i->begin()->data_size_in_bytes() - 1) / sizeof(tab_t) + 1; 410 } 411 } 412 } 413 } 414 415 416 ostream & operator <<(ostream & o, const entity & e) { 448 417 #if 0 449 418 o << "entity ("; 450 419 if (e.object) 451 o << e.object->name();420 o << e.object->name(); 452 421 else 453 o << "no object";422 o << "no object"; 454 423 if (e.interface) 455 o << ", pointer = 0x" << hex << e.interface->get_pointer();424 o << ", pointer = 0x" << hex << e.interface->get_pointer(); 456 425 else 457 o << ", no interface";426 o << ", no interface"; 458 427 o << ")"; 459 428 #else 460 assert(e.object != NULL);461 o << e.object->name();429 assert(e.object != NULL); 430 o << e.object->name(); 462 431 #endif 463 432 return o; 464 } 465 466 ostream& 467 operator << (ostream &o, const equi_t &e) 468 { 433 } 434 435 ostream & operator <<(ostream & o, const equi_t & e) { 469 436 bool nb = 0; 470 437 equi_t::const_iterator i; 471 for (i = e.begin (); i != e.end(); ++i) {472 const entity &ity = *i;473 o << ((nb++)?" = ":"") << ity;474 } 438 for (i = e.begin(); i != e.end(); ++i) { 439 const entity & ity = *i; 440 o << ((nb++) ? " = " : "") << ity; 441 } 475 442 return o; 476 } 477 478 void 479 print_table (ostream &o) 480 { 481 o << "Signal list\n" 482 << "-----------\n"; 443 } 444 445 446 void print_table(ostream & o) { 447 o << "Signal list\n" << "-----------\n"; 483 448 equi_list_t::const_iterator i; 484 for (i = equi_list.begin (); i != equi_list.end(); ++i) {485 const equi_t &eq = *i;449 for (i = equi_list.begin(); i != equi_list.end(); ++i) { 450 const equi_t & eq = *i; 486 451 #if 0 487 o << i->begin()->interface->get_pointer() << " : ";488 489 452 o << i->begin()->interface->get_pointer() << " : "; 453 o << (*i); 454 o << "\n"; 490 455 #else 491 o << "(" << get_name (eq) << ") <=> " << eq << ".\n"; 492 #endif 493 } 494 } 495 496 void 497 print_table_stats (ostream &o) 498 { 456 o << "(" << get_name(eq) << ") <=> " << eq << ".\n"; 457 #endif 458 } 459 } 460 461 void print_table_stats(ostream & o) { 499 462 #if defined(DUMP_SIGNAL_STATS) 500 501 502 503 504 463 int nb_reg = 0; 464 int nb_sig = 0; 465 int real_size = 0; 466 467 // count 505 468 equi_list_t::const_iterator i; 506 int num; 507 for (num = 0, i = equi_list.begin (); i != equi_list.end (); ++num, ++i) { 508 if (is_register (*i)) 509 ++nb_reg; 510 else 511 ++nb_sig; 512 } 513 514 // print results 515 o << "Statistics :\n"; 516 o << "#registers : " << nb_reg << endl; 517 o << "#signals : " << nb_sig << endl; 518 o << "current table size : " << equi_real_size << endl; 519 #endif 520 } 469 int num; 470 for (num = 0, i = equi_list.begin(); i != equi_list.end(); ++num, ++i) { 471 if (is_register(*i)) { 472 ++nb_reg; 473 } 474 else { 475 ++nb_sig; 476 } 477 } 478 479 // print results 480 o << "Statistics :\n"; 481 o << "#registers : " << nb_reg << endl; 482 o << "#signals : " << nb_sig << endl; 483 o << "current table size : " << equi_real_size << endl; 484 #endif 485 } 486 521 487 522 488 #ifdef DUMP_SIGNAL_STATS 523 typedef map <tab_t*,long long int> counter_t;524 static counter_t 489 typedef map < tab_t *, long long int > counter_t; 490 static counter_t counter; 525 491 long long int unnecessary = 0; 526 492 long long int total_assig = 0; 527 493 #endif 528 494 529 const char* 530 get_module_name (const equi_t &eq) 531 { 532 if (!is_register (eq)) { 533 /* 534 cerr << "get_module_name doesn't work yet upon non-register.\n"; 535 536 const sc_port_base &port = *(i->port); 537 const sc_module &module = port.get_module (); 538 */ 539 return "top_level"; 540 } 541 const entity &ent = *(eq.begin ()); 495 const char * get_module_name(const equi_t & eq) { 496 if (!is_register(eq)) { 497 /* 498 cerr << "get_module_name doesn't work yet upon non-register.\n"; 499 */ 500 return "top_level"; 501 } 502 const entity & ent = *(eq.begin()); 503 542 504 #ifdef CONFIG_DEBUG 543 if (ent.type != sc_core::entity::SIGNAL) 544 exit(28); 545 #endif 546 // get module name from sc_signal used like a register 547 const char *sig_name = ent.object->name (); 548 const char *sep = strchr (sig_name,'.'); 505 if (ent.type != sc_core::entity::SIGNAL) { 506 exit(28); 507 } 508 #endif 509 510 // get module name from sc_signal used like a register 511 const char * sig_name = ent.object->name(); 512 const char * sep = strchr(sig_name, '.'); 513 549 514 #ifdef CONFIG_DEBUG 550 if (sep == NULL) { 551 exit (30); 552 } 553 #endif 554 int end_pos = sep - sig_name; 555 string module_name (sig_name, end_pos); 556 // can't return the char* pointer from string since it will be invalid. 557 return get_module (module_name).name (); 558 } 559 560 static 561 void 562 merge_equi (equi_list_t::iterator &x, equi_list_t::iterator &y) 563 { 564 equi_t::iterator i; 565 equi_t &y2 = *y; 566 for (i = y2.begin(); i != y2.end(); ++i) 567 { 568 entity &e = *i; 569 equi_map[e] = x; 570 } 571 572 x->merge (*y); 573 equi_list.erase (y); 574 } 575 515 if (sep == NULL) { 516 exit(30); 517 } 518 #endif 519 520 int end_pos = sep - sig_name; 521 string module_name(sig_name, end_pos); 522 // can't return the char* pointer from string since it will be invalid. 523 return get_module(module_name).name(); 524 } 525 526 527 static void merge_equi(equi_list_t::iterator & x, equi_list_t::iterator & y) { 528 equi_t::iterator i; 529 equi_t & y2 = *y; 530 for (i = y2.begin(); i != y2.end(); ++i) { 531 entity & e = *i; 532 equi_map[e] = x; 533 } 534 535 x->merge(*y); 536 equi_list.erase(y); 537 } 538 539 576 540 // sort by data size 577 541 #ifdef DATASIZE_SORT 578 int 579 operator<(const equi_t &e1, const equi_t &e2) 580 { 581 return (e1.begin()->data_size () < e2.begin()->data_size ()); 582 } 583 #endif 542 int operator< (const equi_t & e1, const equi_t & e2) { 543 return (e1.begin()->data_size() < e2.begin()->data_size()); 544 } 545 #endif 546 584 547 585 548 // random sort 586 549 #ifdef RANDOM_SORT 587 int 588 operator<(const equi_t &e1, const equi_t &e2) 589 { 590 typedef std::map<const equi_t*,int> m_t; 591 static m_t m; 592 if (m[&e1] == 0) 593 m[&e1] = rand (); 594 if (m[&e2] == 0) 595 m[&e2] = rand (); 596 return m[&e1] < m[&e2]; 597 } 598 #endif 550 int operator< (const equi_t & e1, const equi_t & e2) { 551 typedef std::map < const equi_t *, int > m_t; 552 static m_t m; 553 if (m[&e1] == 0) { 554 m[&e1] = rand(); 555 } 556 if (m[&e2] == 0) { 557 m[&e2] = rand(); 558 } 559 return m[&e1] < m[&e2]; 560 } 561 #endif 562 599 563 600 564 #if defined(DUMP_SIGNAL_STATS) … … 602 566 #endif 603 567 604 void 605 bind (sc_signal_base &x) 606 { 607 #if 0 608 //defined(CONFIG_DEBUG) 609 equi_list_t::iterator x_equi = get_equi (x); 610 if ((x_equi != equi_list.end())) { 611 cerr << "Internal error : Signal already in the table\n"; 612 return; 613 } 614 #endif 615 new_equi (x); 616 } 617 618 void 619 bind (sc_port_base &x) 620 { 621 new_equi (x); 622 } 623 624 template <typename T> static 625 void 626 test_before_bind (sc_port_base& p1,T& p2) 627 { 628 bool t1 = (p1.kind () != NULL); 629 bool t2 = (p2.kind () != NULL); 630 if (t1 && t2) 631 return; 632 if (t1 == true) 633 cerr << "Trying to bind '" << p1.name() << "' to an unknown type.\n"; 634 else if (t2 == true) 635 cerr << "Trying to bind '" << p2.name() << "' to an unknown type.\n"; 636 else 637 cerr << "Binding failed. Please check the netlist description.\n"; 638 exit (20040525); 639 } 640 641 template <typename T> static 642 void 643 tbind (sc_port_base &x,T &y) 644 { 645 // assert(x.get_pointer () != NULL); // x pointer may be NULL 646 // assert(y.get_pointer () != NULL); // y pointer may be NULL 647 equi_list_t::iterator x_equi = get_equi (x); 648 equi_list_t::iterator y_equi = get_equi (y); 649 if ((x_equi != equi_list.end()) && (y_equi != equi_list.end())) { 650 // 2 equipotentials are equals 651 merge_equi (x_equi, y_equi); 652 } else if ((x_equi != equi_list.end())) { 653 // add y 654 add_equi (x_equi,y); 655 } else if ((y_equi != equi_list.end())) { 656 // add y 657 add_equi (y_equi,x); 658 } else { 659 // add a new equi 660 x_equi = new_equi (x); 661 add_equi (x_equi, y); 662 } 663 } 664 665 void 666 bind (sc_port_base& p1,sc_port_base& p2) 667 { test_before_bind (p1, p2); tbind (p1, p2); } 668 669 void 670 bind (sc_port_base& p1,sc_signal_base& s1) 671 { test_before_bind (p1, s1); tbind (p1, s1); } 568 569 void bind(sc_signal_base & x) { 570 #if 0 571 //defined(CONFIG_DEBUG) 572 equi_list_t::iterator x_equi = get_equi(x); 573 if ((x_equi != equi_list.end())) { 574 cerr << "Internal error : Signal already in the table\n"; 575 return; 576 } 577 #endif 578 new_equi(x); 579 } 580 581 582 void bind(sc_port_base & x) { 583 new_equi(x); 584 } 585 586 587 template < typename T > static void test_before_bind(sc_port_base & p1, T & p2) { 588 bool t1 = (p1.kind() != NULL); 589 bool t2 = (p2.kind() != NULL); 590 if (t1 && t2) { 591 return; 592 } 593 if (t1 == true) { 594 cerr << "Trying to bind '" << p1.name() << "' to an unknown type.\n"; 595 } 596 else if (t2 == true) { 597 cerr << "Trying to bind '" << p2.name() << "' to an unknown type.\n"; 598 } 599 else { 600 cerr << "Binding failed. Please check the netlist description.\n"; 601 } 602 exit(20040525); 603 } 604 605 606 template < typename T > static void tbind(sc_port_base & x, T & y) { 607 // assert(x.get_pointer () != NULL); // x pointer may be NULL 608 // assert(y.get_pointer () != NULL); // y pointer may be NULL 609 equi_list_t::iterator x_equi = get_equi(x); 610 equi_list_t::iterator y_equi = get_equi(y); 611 if ((x_equi != equi_list.end()) && (y_equi != equi_list.end())) { 612 // 2 equipotentials are equals 613 merge_equi(x_equi, y_equi); 614 } 615 else if ((x_equi != equi_list.end())) { 616 // add y 617 add_equi(x_equi, y); 618 } 619 else if ((y_equi != equi_list.end())) { 620 // add y 621 add_equi(y_equi, x); 622 } 623 else { 624 // add a new equi 625 x_equi = new_equi(x); 626 add_equi(x_equi, y); 627 } 628 } 629 630 631 void bind(sc_port_base & p1, sc_port_base & p2) { 632 test_before_bind(p1, p2); 633 tbind(p1, p2); 634 } 635 636 637 void bind(sc_port_base & p1, sc_signal_base & s1) { 638 test_before_bind(p1, s1); 639 tbind(p1, s1); 640 } 672 641 673 642 674 643 } // end of sc_core namespace 675 644 645 /* 646 # Local Variables: 647 # tab-width: 4; 648 # c-basic-offset: 4; 649 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 650 # indent-tabs-mode: nil; 651 # End: 652 # 653 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 654 */ 655 -
sources/src/entity.h
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : entity.h |6 | |7 | Author : Buchmann Richard |8 | Taktak Sami |9 | |10 | Date : 09_07_2004 |11 | |12 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : entity.h | 6 | | 7 | Author : Buchmann Richard | 8 | Taktak Sami | 9 | | 10 | Date : 09_07_2004 | 11 | | 12 \------------------------------------------------------------*/ 13 13 #ifndef __ENTITY_H__ 14 14 #define __ENTITY_H__ … … 22 22 namespace sc_core { 23 23 24 25 24 // Entity class 25 struct entity { 26 26 enum { SIGNAL, PORT } type; 27 union { // port & signal aren't const because we need to modify 28 // some fields in elaboration step. 29 sc_port_base *port; 30 sc_signal_base *signal; 31 }; 32 sc_object *object; 33 sc_interface *interface; 34 // tab_t *pointer; 35 bool operator == (const sc_port_base &port_) 36 { return (type == PORT) && (&port_ == port); } 37 bool operator == (const sc_signal_base &signal_) 38 { return (type == SIGNAL) && (&signal_ == signal); } 39 bool operator < (const entity &e_) const 40 { return (void*) this < (void*) &e_; } // casting to "unsigned int" causes warnings 41 const char *kind () const 42 { return object->kind (); } 43 size_t data_size_in_bytes () const 44 { return interface->data_size_in_bytes (); } 45 entity (/*const*/ sc_port_base &port_) 46 { type = PORT; port = &port_; object = &port_; interface = &port_; } 47 entity (/*const*/ sc_signal_base &signal_) 48 { type = SIGNAL; signal = &signal_; object = &signal_; interface = &signal_; } 49 }; 27 union { 28 // port & signal aren't const because we need to modify 29 // some fields in elaboration step. 30 sc_port_base * port; 31 sc_signal_base * signal; 32 }; 33 sc_object * object; 34 sc_interface * interface; 35 bool operator ==(const sc_port_base & port_) { 36 return (type == PORT) && (&port_ == port); 37 } 50 38 51 // list52 typedef std::list<entity> equi_t;53 typedef std::list<equi_t> equi_list_t;39 bool operator ==(const sc_signal_base & signal_) { 40 return (type == SIGNAL) && (&signal_ == signal); 41 } 54 42 55 // Miscellanous functions 56 equi_t& get_equi (const sc_interface &); 57 equi_t& get_equi (const tab_t *pointer); 58 bool has_equi (/*const*/ sc_port_base &); 59 equi_t& merge_equi (const tab_t *pointer); 60 sc_port_base *get_out_port (const equi_t&); 61 const char *get_name (const equi_t&); 62 const char* get_module_name (const equi_t &); 63 std::ostream& operator << (std::ostream &, const equi_t &); 64 std::ostream& operator << (std::ostream &, const entity &); 43 bool operator <(const entity & e_) const { 44 return (void *) this < (void *) &e_; 45 } // casting to "unsigned int" causes warnings 65 46 66 const equi_list_t &get_equi_list (); 67 int get_signal_table_size (); 47 const char * kind() const { 48 return object->kind(); 49 } 68 50 69 // Bind functions 70 void bind (sc_port_base& p1,sc_port_base& p2); 71 void bind (sc_port_base& p1,sc_signal_base& s1); 51 size_t data_size_in_bytes() const { 52 return interface->data_size_in_bytes(); 53 } 54 55 entity(/*const */sc_port_base & port_) { 56 type = PORT; 57 port = &port_; 58 object = &port_; 59 interface = &port_; 60 } 61 62 entity(/*const */sc_signal_base & signal_) { 63 type = SIGNAL; 64 signal = &signal_; 65 object = &signal_; 66 interface = &signal_; 67 } 68 }; 69 70 // list 71 typedef std::list < entity > equi_t; 72 typedef std::list < equi_t > equi_list_t; 73 74 // Miscellanous functions 75 equi_t & get_equi(const sc_interface &); 76 equi_t & get_equi(const tab_t * pointer); 77 bool has_equi(/*const */sc_port_base &); 78 equi_t & merge_equi(const tab_t * pointer); 79 sc_port_base * get_out_port(const equi_t &); 80 const char * get_name(const equi_t &); 81 const char * get_module_name(const equi_t &); 82 std::ostream & operator <<(std::ostream &, const equi_t &); 83 std::ostream & operator <<(std::ostream &, const entity &); 84 85 const equi_list_t & get_equi_list(); 86 int get_signal_table_size(); 87 88 // Bind functions 89 void bind(sc_port_base & p1, sc_port_base & p2); 90 void bind(sc_port_base & p1, sc_signal_base & s1); 72 91 73 92 } // end of sc_core namespace 74 93 75 94 #endif /* __ENTITY_H__ */ 76 95 96 /* 97 # Local Variables: 98 # tab-width: 4; 99 # c-basic-offset: 4; 100 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 101 # indent-tabs-mode: nil; 102 # End: 103 # 104 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 105 */ -
sources/src/gen_code.cc
r47 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : gen_code.cc |6 | |7 | Author : Taktak Sami |8 | Buchmann Richard |9 | |10 | Date : 09_07_2004 |11 | |12 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : gen_code.cc | 6 | | 7 | Author : Taktak Sami | 8 | Buchmann Richard | 9 | | 10 | Date : 09_07_2004 | 11 | | 12 \------------------------------------------------------------*/ 13 13 14 14 /* … … 34 34 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 35 35 */ 36 36 37 #if defined(__linux__) 37 38 #include <linux/limits.h> … … 39 40 #include <windows.h> 40 41 #endif 42 41 43 #include <cstring> 42 44 #include <cstdio> … … 50 52 #include "sc_ver.h" 51 53 #include "process_dependency.h" 54 52 55 #ifdef HAVE_CONFIG_H 53 56 #include "config.h" … … 67 70 namespace sc_core { 68 71 69 static void PrintCall(std::ostream &, const method_process_t &);70 static void open_temp(std::ofstream &, char *);72 static void PrintCall(std::ostream &, const method_process_t &); 73 static void open_temp(std::ofstream &, char *); 71 74 typedef void (*CASC_ENTRY_FUNC) (void *); 72 typedef union { unsigned long long int integer; SC_ENTRY_FUNC pmf; CASC_ENTRY_FUNC pf; } fct;73 74 const char * 75 get_pmf_type () 76 { 77 switch (sizeof (SC_ENTRY_FUNC)) { 78 case 4: 79 // G4 pointer-to-member-function style 80 return "unsigned long int";81 case 8:82 // PCpointer-to-member-function style83 return "unsigned longlong int";84 default:85 cerr << "Internal Error : Unsupported pointer-to-member-function"86 "(size: " << sizeof (SC_ENTRY_FUNC) << ").\n"87 "Please try --nodynamiclink option.\n";88 exit(21072009);89 };90 } 91 92 static 93 ostream& operator << (ostream &o, const SC_ENTRY_FUNC &f) 94 { 95 register fct p; 96 p.integer = 0; 97 p.pmf = f; 98 return o << "0x" << hex << p.integer << "ULL";99 } 100 101 static 102 void 103 PrintCall (std::ostream &o, 104 const method_process_t &m) 105 {106 SC_ENTRY_FUNC func= m.func;107 if (print_schedule)108 o << " fprintf(stderr,\"evaluation de "109 << m.module->name() << "->" << m.name << "()\\n\");\n";110 o << " p.integer = " << func << ";\n";75 typedef union { 76 unsigned long long int integer; 77 SC_ENTRY_FUNC pmf; 78 CASC_ENTRY_FUNC pf; 79 } fct; 80 81 82 const char * get_pmf_type() { 83 switch (sizeof(SC_ENTRY_FUNC)) { 84 case 4: 85 // G4 pointer-to-member-function style 86 return "unsigned long int"; 87 case 8: 88 // PC pointer-to-member-function style 89 return "unsigned long long int"; 90 default: 91 cerr << 92 "Internal Error : Unsupported pointer-to-member-function" 93 "(size: " << sizeof(SC_ENTRY_FUNC) << ").\n" 94 "Please try --nodynamiclink option.\n"; 95 exit(21072009); 96 }; 97 } 98 99 100 static ostream & operator <<(ostream & o, const SC_ENTRY_FUNC & f) { 101 register fct p; 102 p.integer = 0; 103 p.pmf = f; 104 return o << "0x" << hex << p.integer << "ULL"; 105 } 106 107 108 static void PrintCall(std::ostream & o, const method_process_t & m) { 109 SC_ENTRY_FUNC func = m.func; 110 if (print_schedule) { 111 o << " fprintf(stderr,\"evaluation de " << m.module->name() << "->" << m.name << "()\\n\");\n"; 112 } 113 o << " p.integer = " << func << ";\n"; 111 114 #ifdef CPP_CALL 112 o << " (((sc_module*)(" << m.module << "))->*(p.pmf)) (); /* " 113 << m.module->name () << "->" << m.name << "() */\n"; 115 o << " (((sc_module*)(" << m.module << "))->*(p.pmf)) (); /* " << m.module->name() << "->" << m.name << "() */\n"; 114 116 #else 115 o << " p.pf((void *)" 116 << m.module << "); /* " 117 << m.module->name () << "->" << m.name << "() */\n"; 118 #endif 119 } 120 121 static 122 bool 123 is_exist (const char *temp) 124 { 125 #if 0 126 cerr << "testing " << temp << "\n"; 127 #endif 128 ifstream o; 129 o.open (temp,ios::in); 130 if (o.is_open () == false) 131 return false; 132 #if 0 133 cerr << "opened\n"; 134 cerr << "peek : " << (int) o.peek() << endl; 135 #endif 136 if (o.peek () == -1) 137 return false; 138 return true; 139 } 140 141 static 142 void 143 open_temp (ofstream &o, 144 char *temp) 145 { 146 /* 147 srand (time (NULL)); 148 int r = rand () % 1000; 149 */ 150 pid_t pid = getpid(); 151 int r = -1; 152 do { 153 sprintf (temp, "%s/scheduling-%d-%x.cc", temporary_dir, pid, ++r); 154 } while (is_exist (temp)); 155 156 o.open (temp,ios::out); 157 if (o.is_open () == false) 158 { 159 cerr << "Error : Unable to open a file to write scheduling code.\n"; 160 exit (30032005); 161 } 162 117 o << " p.pf((void *)" << m.module << "); /* " << m.module->name() << "->" << m.name << "() */\n"; 118 #endif 119 } 120 121 122 static bool is_exist(const char * temp) { 123 ifstream o; 124 o.open(temp, ios::in); 125 if (o.is_open() == false) { 126 return false; 127 } 128 if (o.peek() == -1) { 129 return false; 130 } 131 return true; 132 } 133 134 135 static void open_temp(ofstream & o, char * temp) { 136 /* 137 srand (time (NULL)); 138 int r = rand () % 1000; 139 */ 140 pid_t pid = getpid(); 141 int r = -1; 142 do { 143 sprintf(temp, "%s/scheduling-%d-%x.cc", temporary_dir, pid, ++r); 144 } while (is_exist(temp)); 145 146 o.open(temp, ios::out); 147 if (o.is_open() == false) { 148 cerr << "Error : Unable to open a file to write scheduling code.\n"; 149 exit(30032005); 150 } 163 151 #ifdef CONFIG_DEBUG 164 cerr << "opened temporary filename : " << temp << "\n"; 165 #endif 166 167 sprintf (temp, "scheduling-%d-%x", pid, r++); 168 } 169 170 static 171 char * 172 gen_transition (ofstream &o, 173 method_process_list_t &transition_func_list) 174 { 175 // transitions 176 o << "\ninline void transition(void)\n{\n"; 177 if (transition_func_list.empty () == false) { 178 o << " /* fonctions de transition */\n" 179 << " register fct p;\n"; 180 method_process_list_t::iterator mm; 181 for( mm = transition_func_list.begin(); mm != transition_func_list.end(); ++mm) 182 { 183 PrintCall (o, **mm); 184 } 185 } 186 o << "}\n"; 187 } 188 189 static 190 char * 191 gen_moore (ofstream &o, 192 method_process_list_t &moore_func_list) 193 { 194 // Moore generations (sequential functions) 195 o << "\ninline void moore_generation (void)\n{\n"; 196 if (moore_func_list.empty () == false) { 197 o << " /* fonctions de generation de Moore */\n" 198 << " register fct p;\n"; 199 method_process_list_t::reverse_iterator mm; 200 for( mm = moore_func_list.rbegin(); mm != moore_func_list.rend(); ++mm) 201 { 202 PrintCall (o, **mm); 203 } 204 } 205 o << " \n}\n"; 206 } 207 208 static 209 char * 210 gen_mealy (ofstream &o, 211 strong_component_list_t &strongcomponents) 212 { 213 // Mealy generations (combinational functions only) 214 o << "\nextern void mealy_generation (void)\n{\n"; 215 if (strongcomponents.empty ()) 216 return NULL; 217 o << " register fct p;\n" 218 << "\n\n /* fonctions de mealy */\n"; 152 cerr << "opened temporary filename : " << temp << "\n"; 153 #endif 154 sprintf(temp, "scheduling-%d-%x", pid, r++); 155 } 156 157 158 static char * gen_transition(ofstream & o, method_process_list_t & transition_func_list) { 159 // transitions 160 o << "\ninline void transition(void)\n{\n"; 161 if (transition_func_list.empty() == false) { 162 o << " /* fonctions de transition */\n" << " register fct p;\n"; 163 method_process_list_t::iterator mm; 164 for (mm = transition_func_list.begin(); mm != transition_func_list.end(); ++mm) { 165 PrintCall(o, **mm); 166 } 167 } 168 o << "}\n"; 169 } 170 171 172 static char * gen_moore(ofstream & o, method_process_list_t & moore_func_list) { 173 // Moore generations (sequential functions) 174 o << "\ninline void moore_generation (void)\n{\n"; 175 if (moore_func_list.empty() == false) { 176 o << " /* fonctions de generation de Moore */\n" 177 << " register fct p;\n"; 178 method_process_list_t::reverse_iterator mm; 179 for (mm = moore_func_list.rbegin(); 180 mm != moore_func_list.rend(); ++mm) { 181 PrintCall(o, **mm); 182 } 183 } 184 o << " \n}\n"; 185 } 186 187 188 static char * gen_mealy(ofstream & o, strong_component_list_t & strongcomponents) { 189 // Mealy generations (combinational functions only) 190 o << "\nextern void mealy_generation (void)\n{\n"; 191 if (strongcomponents.empty()) { 192 return NULL; 193 } 194 o << " register fct p;\n" << "\n\n /* fonctions de mealy */\n"; 219 195 #ifdef NO_STATIC_SCHEDULE 220 o << "\n do {\n unstable = 0;\n"; 221 #endif 222 strong_component_list_t::iterator ss; 223 for ( ss = strongcomponents.begin(); ss != strongcomponents.end(); ++ss) { 224 if ( (*ss)->size() == 1) { 225 /* un seul element dans le strong component */ 226 method_process_t *m = (method_process_t*)(*((*ss)->begin ())); 227 PrintCall (o, *m); 228 continue; 229 } else { 230 /* plusieurs elements dans le strong component */ 196 o << "\n do {\n unstable = 0;\n"; 197 #endif 198 strong_component_list_t::iterator ss; 199 for (ss = strongcomponents.begin(); ss != strongcomponents.end(); ++ss) { 200 if ((*ss)->size() == 1) { 201 /* un seul element dans le strong component */ 202 method_process_t *m = (method_process_t *) (*((*ss)->begin())); 203 PrintCall(o, *m); 204 continue; 205 } 206 else { 207 /* plusieurs elements dans le strong component */ 231 208 #ifndef NO_STATIC_SCHEDULE 232 o << "\n do {\n unstable = 0;\n";233 #endif 234 component_list_t::reverse_iterator rev_mm;235 for(rev_mm = (*ss)->rbegin(); rev_mm != (*ss)->rend(); ++rev_mm) {236 method_process_t *m = (method_process_t*) *rev_mm;237 PrintCall(o, *m);238 }209 o << "\n do {\n unstable = 0;\n"; 210 #endif 211 component_list_t::reverse_iterator rev_mm; 212 for (rev_mm = (*ss)->rbegin(); rev_mm != (*ss)->rend(); ++rev_mm) { 213 method_process_t * m = (method_process_t *) * rev_mm; 214 PrintCall(o, *m); 215 } 239 216 #ifndef NO_STATIC_SCHEDULE 240 o << " } while ( unstable );\n\n";241 #endif 242 }243 }217 o << " } while ( unstable );\n\n"; 218 #endif 219 } 220 } 244 221 #ifdef NO_STATIC_SCHEDULE 245 o << " } while ( unstable );\n\n";222 o << " } while ( unstable );\n\n"; 246 223 #else 247 o << "\tunstable = 0;\n"; 248 #endif 249 } 250 251 static 252 char * 253 gen_mealy (ofstream &o, 254 ProcessDependencyList &mealy_func_list) 255 { 256 // Mealy generations (combinational functions only) 257 o << "\nextern void mealy_generation (void)\n{\n"; 258 o << " register fct p;\n" 259 << "\n\n /* fonctions de mealy */\n"; 260 ProcessDependencyList::iterator it; 261 for (it = mealy_func_list.begin(); it != mealy_func_list.end(); ++it) 262 { 263 const method_process_t *m = *it; 264 PrintCall (o, *m); 265 } 266 } 267 268 char * 269 gen_scheduling_code_for_dynamic_link ( 270 method_process_list_t &transition_func_list, 271 method_process_list_t &moore_func_list, 272 strong_component_list_t &strongcomponents) 273 { 274 if (dump_stage) 275 cerr << "Generating C code for scheduling...\n"; 276 277 // open temporary file 278 ofstream o; 279 char base_name[PATH_MAX]; 280 open_temp (o, base_name); 281 282 if (! o.good ()) { 283 perror("scheduling: open file\n"); 284 exit(-1); 285 } 286 287 o << "// generated by " << sc_version () << endl 288 << "#include <casc.h>\n\n" 289 << "#include <cstdio>\n\n" 290 // << "#include <iostream>\n\n" 291 << "namespace sc_core {\n" 292 << " typedef void (sc_module::*SC_ENTRY_FUNC)();\n" 293 << " typedef void (*CASC_ENTRY_FUNC)(void *);\n"; 294 295 const char *pmf_type = get_pmf_type (); 296 297 o << " typedef union { " 298 << pmf_type 299 << " integer; SC_ENTRY_FUNC pmf; CASC_ENTRY_FUNC pf; } fct;\n"; 300 301 gen_transition (o, transition_func_list); 302 gen_moore (o, moore_func_list); 303 gen_mealy (o, strongcomponents); 304 305 o << " \n}\n"; 306 o << "\n} // end of sc_core namespace\n"; 307 308 o.flush (); 309 o.close (); 310 311 // add "cc" extension 312 char file_name[PATH_MAX]; 313 strncpy(file_name, base_name, PATH_MAX); 314 file_name[strlen (base_name)] = '\0'; 315 strcat(file_name, ".cc"); 316 rename (base_name, file_name); 317 318 if (edit_schedule) 319 run_schedule_editor (file_name); 320 321 if (dump_stage) 322 cerr << "Generating C code for scheduling done.\n"; 323 324 return strdup(base_name); 325 } 326 327 char * 328 gen_scheduling_code_for_dynamic_link ( 329 method_process_list_t &transition_func_list, 330 method_process_list_t &moore_func_list, 331 ProcessDependencyList &mealy_func_list) 332 { 333 if (dump_stage) 334 cerr << "Generating C code for scheduling...\n"; 335 336 // open temporary file 337 ofstream o; 338 char base_name[PATH_MAX]; 339 open_temp (o, base_name); 340 341 if (! o.good ()) { 342 perror("scheduling: open file\n"); 343 exit(-1); 344 } 345 346 o << "// generated by " << sc_version () << endl 347 << "#include <casc.h>\n\n" 348 << "#include <cstdio>\n\n" 349 // << "#include <iostream>\n\n" 350 << "namespace sc_core {\n" 351 << " typedef void (sc_module::*SC_ENTRY_FUNC)();\n" 352 << " typedef void (*CASC_ENTRY_FUNC)(void *);\n" 353 << " typedef union { unsigned long long int integer; SC_ENTRY_FUNC pmf; CASC_ENTRY_FUNC pf; } fct;\n"; 354 355 gen_transition (o, transition_func_list); 356 gen_moore (o, moore_func_list); 357 gen_mealy (o, mealy_func_list); 358 359 o << "\n}\n"; 360 o << "\n} // end of sc_core namespace\n"; 361 362 o.flush (); 363 o.close (); 364 365 // add "cc" extension 366 char file_name[PATH_MAX]; 367 strncpy(file_name, base_name, PATH_MAX); 368 file_name[strlen (base_name)] = '\0'; 369 strcat(file_name, ".cc"); 370 rename (base_name, file_name); 371 372 if (edit_schedule) 373 run_schedule_editor (file_name); 374 375 if (dump_stage) 376 cerr << "Generating C code for scheduling done.\n"; 377 378 return strdup(base_name); 379 } 224 o << "\tunstable = 0;\n"; 225 #endif 226 } 227 228 229 static char * gen_mealy(ofstream & o, ProcessDependencyList & mealy_func_list) { 230 // Mealy generations (combinational functions only) 231 o << "\nextern void mealy_generation (void)\n{\n"; 232 o << " register fct p;\n" << "\n\n /* fonctions de mealy */\n"; 233 ProcessDependencyList::iterator it; 234 for (it = mealy_func_list.begin(); it != mealy_func_list.end(); ++it) { 235 const method_process_t * m = *it; 236 PrintCall(o, *m); 237 } 238 } 239 240 241 char * gen_scheduling_code_for_dynamic_link(method_process_list_t & 242 transition_func_list, 243 method_process_list_t & 244 moore_func_list, 245 strong_component_list_t & 246 strongcomponents) { 247 if (dump_stage) { 248 cerr << "Generating C code for scheduling...\n"; 249 } 250 251 // open temporary file 252 ofstream o; 253 char base_name[PATH_MAX]; 254 open_temp(o, base_name); 255 256 if (!o.good()) { 257 perror("scheduling: open file\n"); 258 exit(-1); 259 } 260 261 o << "// generated by " << sc_version() << endl 262 << "#include <casc.h>\n\n" << "#include <cstdio>\n\n" 263 // << "#include <iostream>\n\n" 264 << "namespace sc_core {\n" 265 << " typedef void (sc_module::*SC_ENTRY_FUNC)();\n" 266 << " typedef void (*CASC_ENTRY_FUNC)(void *);\n"; 267 268 const char * pmf_type = get_pmf_type(); 269 270 o << " typedef union { " 271 << pmf_type 272 << " integer; SC_ENTRY_FUNC pmf; CASC_ENTRY_FUNC pf; } fct;\n"; 273 274 gen_transition(o, transition_func_list); 275 gen_moore(o, moore_func_list); 276 gen_mealy(o, strongcomponents); 277 278 o << " \n}\n"; 279 o << "\n} // end of sc_core namespace\n"; 280 281 o.flush(); 282 o.close(); 283 284 // add "cc" extension 285 char file_name[PATH_MAX]; 286 strncpy(file_name, base_name, PATH_MAX); 287 file_name[strlen(base_name)] = '\0'; 288 strcat(file_name, ".cc"); 289 rename(base_name, file_name); 290 291 if (edit_schedule) { 292 run_schedule_editor(file_name); 293 } 294 295 if (dump_stage) { 296 cerr << "Generating C code for scheduling done.\n"; 297 } 298 299 return strdup(base_name); 300 } 301 302 303 char * gen_scheduling_code_for_dynamic_link(method_process_list_t & 304 transition_func_list, 305 method_process_list_t & 306 moore_func_list, 307 ProcessDependencyList & 308 mealy_func_list) { 309 if (dump_stage) { 310 cerr << "Generating C code for scheduling...\n"; 311 } 312 313 // open temporary file 314 ofstream o; 315 char base_name[PATH_MAX]; 316 open_temp(o, base_name); 317 318 if (!o.good()) { 319 perror("scheduling: open file\n"); 320 exit(-1); 321 } 322 323 o << "// generated by " << sc_version() << endl 324 << "#include <casc.h>\n\n" << "#include <cstdio>\n\n" 325 << "namespace sc_core {\n" 326 << " typedef void (sc_module::*SC_ENTRY_FUNC)();\n" 327 << " typedef void (*CASC_ENTRY_FUNC)(void *);\n" 328 << 329 " typedef union { unsigned long long int integer; SC_ENTRY_FUNC pmf; CASC_ENTRY_FUNC pf; } fct;\n"; 330 331 gen_transition(o, transition_func_list); 332 gen_moore(o, moore_func_list); 333 gen_mealy(o, mealy_func_list); 334 335 o << "\n}\n"; 336 o << "\n} // end of sc_core namespace\n"; 337 338 o.flush(); 339 o.close(); 340 341 // add "cc" extension 342 char file_name[PATH_MAX]; 343 strncpy(file_name, base_name, PATH_MAX); 344 file_name[strlen(base_name)] = '\0'; 345 strcat(file_name, ".cc"); 346 rename(base_name, file_name); 347 348 if (edit_schedule) { 349 run_schedule_editor(file_name); 350 } 351 352 if (dump_stage) { 353 cerr << "Generating C code for scheduling done.\n"; 354 } 355 356 return strdup(base_name); 357 } 358 380 359 381 360 /* base_name est la base du nom du fichier C++ 382 361 * casc_cflags est une string qui correspond à $(INCLUDE) d'un Makefile 383 362 */ 384 void 385 compile_code (const char *base_name, 386 const char *casc_cflags2) 387 { 388 if (dump_stage) 389 cerr << "Compiling C/C++ code for scheduling...\n"; 390 char compil_str[512]; 391 const char *compiler = getenv ("CXX"); 392 const char *systemc_dir = getenv ("SYSTEMCASS"); 393 // const char *target_arch = getenv ("TARGET_ARCH"); 394 const char *default_compiler = 363 void compile_code(const char * base_name, const char * casc_cflags2) { 364 if (dump_stage) { 365 cerr << "Compiling C/C++ code for scheduling...\n"; 366 } 367 char compil_str[512]; 368 const char * compiler = getenv("CXX"); 369 const char * systemc_dir = getenv("SYSTEMCASS"); 370 const char * default_compiler = 395 371 #ifdef CPP_CALL 396 "g++";372 "g++"; 397 373 #else 398 374 "gcc"; 399 375 #endif 400 376 401 compiler = (compiler == NULL)?default_compiler:compiler; 402 if (systemc_dir == NULL) { 403 systemc_dir = getenv ("SYSTEMC"); 377 compiler = (compiler == NULL) ? default_compiler : compiler; 404 378 if (systemc_dir == NULL) { 405 cerr << "Error : set SYSTEMCASS or SYSTEMC environnement variable " 406 "to the SYSTEMCASS directory.\n"; 407 exit (-1); 408 } 409 } 410 //target_arch = (target_arch == NULL)?"":target_arch; 411 412 char target_name[128]; 413 char source_name[128]; 414 sprintf (target_name, "%s.lo", base_name); 415 sprintf (source_name, "%s.cc", base_name); 416 417 if (keep_generated_code) 418 { 419 char lg_cde[256]; 420 sprintf (lg_cde, "mkdir -p %s", generated_files_dir); 421 system(lg_cde); 422 sprintf(lg_cde, "cp %s/%s %s/", 423 temporary_dir, source_name, generated_files_dir); 424 if (dump_stage) 425 cerr << "$ " << lg_cde << "\n"; 426 system(lg_cde); 427 sprintf(lg_cde, "(cd %s ; indent %s)", 428 generated_files_dir, source_name); 429 if (dump_stage) 430 cerr << "$ " << lg_cde << "\n"; 431 system(lg_cde); 432 } 433 /* ******* */ 434 /* COMPILE */ 435 /* ******* */ 436 const char *commandline_template = 379 systemc_dir = getenv("SYSTEMC"); 380 if (systemc_dir == NULL) { 381 cerr << "Error : set SYSTEMCASS or SYSTEMC environnement variable to the SYSTEMCASS directory.\n"; 382 exit(-1); 383 } 384 } 385 386 char target_name[128]; 387 char source_name[128]; 388 sprintf(target_name, "%s.lo", base_name); 389 sprintf(source_name, "%s.cc", base_name); 390 391 if (keep_generated_code) { 392 char lg_cde[256]; 393 sprintf(lg_cde, "mkdir -p %s", generated_files_dir); 394 system(lg_cde); 395 sprintf(lg_cde, "cp %s/%s %s/", temporary_dir, source_name, generated_files_dir); 396 if (dump_stage) { 397 cerr << "$ " << lg_cde << "\n"; 398 } 399 system(lg_cde); 400 sprintf(lg_cde, "(cd %s ; indent %s)", generated_files_dir, source_name); 401 if (dump_stage) { 402 cerr << "$ " << lg_cde << "\n"; 403 } 404 system(lg_cde); 405 } 406 /* ******* */ 407 /* COMPILE */ 408 /* ******* */ 409 const char * commandline_template = 437 410 #if defined(CONFIG_OS_DARWIN) 438 "(cd %s ;" " %s %s -DSCHEDULING_BY_CASC -I%s/include -fno-common -dynamic -o %s -c %s)" 411 "(cd %s ;" 412 " %s %s -DSCHEDULING_BY_CASC -I%s/include -fno-common -dynamic -o %s -c %s)" 439 413 #elif defined(CONFIG_OS_LINUX) 440 "(cd %s ; libtool --mode=compile %s %s -DSCHEDULING_BY_CASC -I%s/include -shared -o %s -c %s)"414 "(cd %s ; libtool --mode=compile %s %s -DSCHEDULING_BY_CASC -I%s/include -shared -o %s -c %s)" 441 415 #else 442 "(cd %s ;" " %s %s -DSCHEDULING_BY_CASC -I%s/include -dynamiclib -o %s -c %s)" 443 #endif 444 ; 445 446 string cflags = casc_cflags; 447 if (use_openmp) 448 cflags += " -fopenmp"; 449 450 sprintf(compil_str, 451 commandline_template, 452 temporary_dir, 453 compiler, 454 cflags.c_str(), 455 systemc_dir, 456 target_name, 457 source_name); 458 459 if (dump_stage) 460 cerr << "Executing command : " << compil_str << "\n"; 461 462 if (system(compil_str)) { 463 perror("compil : system"); 464 exit(-1); 465 } 466 467 /* **** */ 468 /* LINK */ 469 /* **** */ 470 sprintf (target_name, "%s.la", base_name); 416 "(cd %s ;" 417 " %s %s -DSCHEDULING_BY_CASC -I%s/include -dynamiclib -o %s -c %s)" 418 #endif 419 ; 420 421 string cflags = casc_cflags; 422 if (use_openmp) { 423 cflags += " -fopenmp"; 424 } 425 426 sprintf(compil_str, commandline_template, temporary_dir, compiler, cflags.c_str(), systemc_dir, target_name, source_name); 427 428 if (dump_stage) { 429 cerr << "Executing command : " << compil_str << "\n"; 430 } 431 432 if (system(compil_str)) { 433 perror("compil : system"); 434 exit(-1); 435 } 436 437 /* **** */ 438 /* LINK */ 439 /* **** */ 440 sprintf(target_name, "%s.la", base_name); 471 441 472 442 #ifdef CONFIG_OS_LINUX 473 sprintf(source_name, "%s.lo", base_name);474 sprintf(compil_str, "(cd %s ; pwd ; libtool --mode=link %s %s -module -shared -o %s %s -rpath /tmp)", /* -L. -L%s/lib-%s */475 temporary_dir, compiler, casc_cflags, /*systemc_dir, target_arch,*/476 target_name, source_name);443 sprintf(source_name, "%s.lo", base_name); 444 sprintf(compil_str, "(cd %s ; pwd ; libtool --mode=link %s %s -module -shared -o %s %s -rpath /tmp)", /* -L. -L%s/lib-%s */ 445 temporary_dir, compiler, casc_cflags, /*systemc_dir, target_arch, */ 446 target_name, source_name); 477 447 #else 478 sprintf (source_name, "%s.o", base_name); 479 sprintf(compil_str, "(cd %s ; pwd ; libtool -dynamic -o %s %s)", 480 temporary_dir, target_name, source_name); 481 #endif 482 483 if (dump_stage) 484 cerr << "Executing command : " << compil_str << "\n"; 485 486 if (system(compil_str)) { 487 perror("compil : system"); 488 exit(-1); 489 } 490 491 /* 492 sprintf(compil_str, "(cd %s ; rm -f %s.o %s.lo)", 493 temporary_dir, base_name, base_name); 494 if (dump_stage) 495 cerr << "$ " << compil_str << "\n"; 496 */ 497 498 system(compil_str); 499 if (dump_stage) 500 cerr << "Compiling done.\n"; 501 } 448 sprintf(source_name, "%s.o", base_name); 449 sprintf(compil_str, "(cd %s ; pwd ; libtool -dynamic -o %s %s)", temporary_dir, target_name, source_name); 450 #endif 451 452 if (dump_stage) { 453 cerr << "Executing command : " << compil_str << "\n"; 454 } 455 456 if (system(compil_str)) { 457 perror("compil : system"); 458 exit(-1); 459 } 460 461 system(compil_str); 462 if (dump_stage) { 463 cerr << "Compiling done.\n"; 464 } 465 } 466 502 467 503 468 /* ******************************** … … 505 470 */ 506 471 struct function_call { 507 fct *function;508 void **instance;509 intfunc_number;472 fct * function; 473 void ** instance; 474 int func_number; 510 475 }; 511 476 static function_call pf[3]; 512 477 513 void 514 get_function_call (function_call &pf, 515 method_process_list_t &func_list) 516 { 517 pf.func_number = func_list.size (); 518 pf.function = (fct*) malloc (sizeof (fct) * pf.func_number); 519 pf.instance = (void**) malloc (sizeof (void*) * pf.func_number); 520 method_process_list_t::iterator mm; 521 int i; 522 for (mm = func_list.begin(), i = 0; mm != func_list.end(); ++mm, ++i) 523 { 524 const method_process_t *mp = *mm; 525 pf.function[i].pmf = (mp->func); 526 pf.instance[i] = (void*)(mp->module); 527 } 528 } 529 530 void 531 get_function_call (function_call &pf, 532 ProcessDependencyList &func_list) 533 { 534 pf.func_number = func_list.size (); 535 pf.function = (fct*) malloc (sizeof (fct) * pf.func_number); 536 pf.instance = (void**) malloc (sizeof (void*) * pf.func_number); 537 ProcessDependencyList::iterator it; 538 int i; 539 for (i = 0, it = func_list.begin(); it != func_list.end(); ++it, ++i) 540 { 541 const method_process_t *mp = *it; 542 pf.function[i].pmf = (mp->func); 543 pf.instance[i] = (void*)(mp->module); 544 } 545 } 546 547 void 548 gen_scheduling_code_for_static_func ( 549 method_process_list_t &transition_func_list, 550 method_process_list_t &moore_func_list, 551 ProcessDependencyList &mealy_func_list) 552 { 553 if (dump_stage) 554 cerr << "Generating scheduling...\n"; 555 556 get_function_call (pf[0], transition_func_list); 557 get_function_call (pf[1], moore_func_list); 558 get_function_call (pf[2], mealy_func_list); 559 560 if (dump_stage) 561 cerr << "Generating scheduling done.\n"; 562 } 563 564 void 565 call_functions (function_call &fc) 566 { 567 int n = fc.func_number; 568 int i; 569 for (i = 0; i < n; ++i) 570 { 571 #if 0 //defined(CONFIG_DEBUG) 572 sc_module *m = (sc_module*)(fc.instance[i]); 573 cerr << m->name () << endl; 574 #endif 575 fc.function[i].pf (fc.instance[i]); 576 } 577 } 578 579 void 580 call_functions_in_parallel (function_call &fc) 581 { 582 int n = fc.func_number; 583 int i; 584 #pragma omp parallel for 585 for (i = 0; i < n; ++i) 586 { 587 #if 0 //defined(CONFIG_DEBUG) 588 sc_module *m = (sc_module*)(fc.instance[i]); 589 cerr << m->name () << endl; 590 cerr << "thread #" << omp_get_thread_num () << endl; 591 #endif 592 fc.function[i].pf (fc.instance[i]); 593 } 594 } 595 596 void static_mealy_generation () 597 { 598 call_functions (pf[2]); 599 } 600 601 void static_simulate_1_cycle (void) 602 { 603 call_functions (pf[0]); // transition 604 update (); 605 call_functions_in_parallel (pf[1]); // moore generation 606 call_functions (pf[2]); // mealy generation 607 } 478 479 void get_function_call(function_call & pf, method_process_list_t & func_list) { 480 pf.func_number = func_list.size(); 481 pf.function = (fct *) malloc(sizeof(fct) * pf.func_number); 482 pf.instance = (void **) malloc(sizeof(void *) * pf.func_number); 483 method_process_list_t::iterator mm; 484 int i; 485 for (mm = func_list.begin(), i = 0; mm != func_list.end(); ++mm, ++i) { 486 const method_process_t * mp = *mm; 487 pf.function[i].pmf = (mp->func); 488 pf.instance[i] = (void *) (mp->module); 489 } 490 } 491 492 493 void get_function_call(function_call & pf, ProcessDependencyList & func_list) { 494 pf.func_number = func_list.size(); 495 pf.function = (fct *) malloc(sizeof(fct) * pf.func_number); 496 pf.instance = (void **) malloc(sizeof(void *) * pf.func_number); 497 ProcessDependencyList::iterator it; 498 int i; 499 for (i = 0, it = func_list.begin(); it != func_list.end(); ++it, ++i) { 500 const method_process_t * mp = *it; 501 pf.function[i].pmf = (mp->func); 502 pf.instance[i] = (void *) (mp->module); 503 } 504 } 505 506 507 void gen_scheduling_code_for_static_func(method_process_list_t & 508 transition_func_list, 509 method_process_list_t & 510 moore_func_list, 511 ProcessDependencyList & 512 mealy_func_list) { 513 if (dump_stage) { 514 cerr << "Generating scheduling...\n"; 515 } 516 517 get_function_call(pf[0], transition_func_list); 518 get_function_call(pf[1], moore_func_list); 519 get_function_call(pf[2], mealy_func_list); 520 521 if (dump_stage) { 522 cerr << "Generating scheduling done.\n"; 523 } 524 } 525 526 527 void call_functions(function_call & fc) { 528 int n = fc.func_number; 529 int i; 530 for (i = 0; i < n; ++i) { 531 #if 0 532 //defined(CONFIG_DEBUG) 533 sc_module *m = (sc_module *) (fc.instance[i]); 534 cerr << m->name() << endl; 535 #endif 536 fc.function[i].pf(fc.instance[i]); 537 } 538 } 539 540 541 void call_functions_in_parallel(function_call & fc) { 542 int n = fc.func_number; 543 int i; 544 #pragma omp parallel for 545 for (i = 0; i < n; ++i) { 546 #if 0 547 //defined(CONFIG_DEBUG) 548 sc_module *m = (sc_module *) (fc.instance[i]); 549 cerr << m->name() << endl; 550 cerr << "thread #" << omp_get_thread_num() << endl; 551 #endif 552 fc.function[i].pf(fc.instance[i]); 553 } 554 } 555 556 557 void static_mealy_generation() { 558 call_functions(pf[2]); 559 } 560 561 562 void static_simulate_1_cycle(void) { 563 call_functions(pf[0]); // transition 564 update(); 565 call_functions_in_parallel(pf[1]); // moore generation 566 call_functions(pf[2]); // mealy generation 567 } 568 608 569 609 570 /* *************************************** … … 611 572 */ 612 573 613 static method_process_list_t 574 static method_process_list_t func_list[2]; 614 575 static strong_component_list_t quasistatic_list; 615 576 616 static 617 void 618 Call (const method_process_t &m) 619 { 620 sc_module *mod = m.module; 621 SC_ENTRY_FUNC func = m.func; 622 // CASC_ENTRY_FUNC func = reinterpret_cast<CASC_ENTRY_FUNC> (m.func); 623 (mod->*func) (); 624 } 625 626 void quasistatic_mealy_generation () 627 { 628 strong_component_list_t::iterator ss; 629 for ( ss = quasistatic_list.begin(); ss != quasistatic_list.end(); ++ss) { 630 if ( (*ss)->size() == 1) { 631 /* un seul element dans le strong component */ 632 method_process_t *m = (method_process_t*)(*((*ss)->begin ())); 633 Call (*m); 634 continue; 635 } else { 636 /* plusieurs elements dans le strong component */ 637 do { 638 unstable = 0; 639 component_list_t::reverse_iterator rev_mm; 640 for( rev_mm = (*ss)->rbegin(); rev_mm != (*ss)->rend(); ++rev_mm) { 641 method_process_t *m = (method_process_t*) *rev_mm; 642 Call (*m); 643 } 644 } while ( unstable ); 645 } 646 } 647 } 648 649 void quasistatic_simulate_1_cycle (void) 650 { 651 method_process_list_t::iterator mm; 652 for( mm = func_list[0].begin(); mm != func_list[0].end(); ++mm) 653 { 654 method_process_t &m = **mm; 655 Call (m); 656 } 657 update (); 658 for( mm = func_list[1].begin(); mm != func_list[1].end(); ++mm) 659 { 660 method_process_t &m = **mm; 661 Call (m); 662 } 663 quasistatic_mealy_generation (); 664 } 665 666 void 667 gen_scheduling_code_for_quasistatic_func ( 668 method_process_list_t &transition_func_list, 669 method_process_list_t &moore_func_list, 670 strong_component_list_t &mealy_func_list) 671 { 672 if (dump_stage) 673 cerr << "Generating quasi static scheduling...\n"; 674 675 func_list[0] = transition_func_list; 676 func_list[1] = moore_func_list; 677 quasistatic_list = mealy_func_list; 678 679 if (dump_stage) 680 cerr << "Generating quasi static scheduling done.\n"; 577 static void Call(const method_process_t & m) { 578 sc_module * mod = m.module; 579 SC_ENTRY_FUNC func = m.func; 580 // CASC_ENTRY_FUNC func = reinterpret_cast<CASC_ENTRY_FUNC> (m.func); 581 (mod->*func) (); 582 } 583 584 585 void quasistatic_mealy_generation() { 586 strong_component_list_t::iterator ss; 587 for (ss = quasistatic_list.begin(); ss != quasistatic_list.end(); ++ss) { 588 if ((*ss)->size() == 1) { 589 /* un seul element dans le strong component */ 590 method_process_t * m = (method_process_t *) (*((*ss)->begin())); 591 Call(*m); 592 continue; 593 } 594 else { 595 /* plusieurs elements dans le strong component */ 596 do { 597 unstable = 0; 598 component_list_t::reverse_iterator rev_mm; 599 for (rev_mm = (*ss)->rbegin(); rev_mm != (*ss)->rend(); ++rev_mm) { 600 method_process_t * m = (method_process_t *) * rev_mm; 601 Call(*m); 602 } 603 } while (unstable); 604 } 605 } 606 } 607 608 609 void quasistatic_simulate_1_cycle(void) { 610 method_process_list_t::iterator mm; 611 for (mm = func_list[0].begin(); mm != func_list[0].end(); ++mm) { 612 method_process_t & m = **mm; 613 Call(m); 614 } 615 update(); 616 for (mm = func_list[1].begin(); mm != func_list[1].end(); ++mm) { 617 method_process_t & m = **mm; 618 Call(m); 619 } 620 quasistatic_mealy_generation(); 621 } 622 623 624 void gen_scheduling_code_for_quasistatic_func(method_process_list_t & 625 transition_func_list, 626 method_process_list_t & 627 moore_func_list, 628 strong_component_list_t & 629 mealy_func_list) { 630 if (dump_stage) { 631 cerr << "Generating quasi static scheduling...\n"; 632 } 633 634 func_list[0] = transition_func_list; 635 func_list[1] = moore_func_list; 636 quasistatic_list = mealy_func_list; 637 638 if (dump_stage) { 639 cerr << "Generating quasi static scheduling done.\n"; 640 } 681 641 } 682 642 } // end of sc_core namespace 683 643 684 644 645 /* 646 # Local Variables: 647 # tab-width: 4; 648 # c-basic-offset: 4; 649 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 650 # indent-tabs-mode: nil; 651 # End: 652 # 653 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 654 */ -
sources/src/gen_code.h
r47 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : gen_code.h |6 | |7 | Author : Taktak Sami |8 | Buchmann Richard |9 | |10 | Date : 09_07_2004 |11 | |12 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : gen_code.h | 6 | | 7 | Author : Taktak Sami | 8 | Buchmann Richard | 9 | | 10 | Date : 09_07_2004 | 11 | | 12 \------------------------------------------------------------*/ 13 13 #ifndef __GEN_CODE_H__ 14 14 #define __GEN_CODE_H__ … … 31 31 namespace sc_core { 32 32 33 extern strong_component_list_t * strong;33 extern strong_component_list_t * strong; 34 34 35 35 /* compile scheduling code to link dynamically later */ 36 extern void compile_code(const char * base_name, const char *cflags2 = "");36 extern void compile_code(const char * base_name, const char * cflags2 = ""); 37 37 38 38 /* generate a scheduling code */ 39 39 extern void gen_scheduling_code_for_quasistatic_func( 40 method_process_list_t &transition_list, 41 method_process_list_t &moore_list, 42 strong_component_list_t &mealy_list); 40 method_process_list_t &transition_list, 41 method_process_list_t &moore_list, 42 strong_component_list_t &mealy_list); 43 43 44 extern void gen_scheduling_code_for_static_func( 44 method_process_list_t &transition_list, 45 method_process_list_t &moore_list, 46 ProcessDependencyList &mealy_list); 47 extern char *gen_scheduling_code_for_dynamic_link( 48 method_process_list_t &transition_list, 49 method_process_list_t &moore_list, 50 ProcessDependencyList &mealy_list); 51 extern char *gen_scheduling_code_for_dynamic_link( 52 method_process_list_t &transition_list, 53 method_process_list_t &moore_list, 54 strong_component_list_t &strongcomponents); 45 method_process_list_t &transition_list, 46 method_process_list_t &moore_list, 47 ProcessDependencyList &mealy_list); 48 49 extern char * gen_scheduling_code_for_dynamic_link( 50 method_process_list_t &transition_list, 51 method_process_list_t &moore_list, 52 ProcessDependencyList &mealy_list); 53 54 extern char * gen_scheduling_code_for_dynamic_link( 55 method_process_list_t &transition_list, 56 method_process_list_t &moore_list, 57 strong_component_list_t &strongcomponents); 55 58 56 59 /* function when any dynamic link is impossible */ … … 61 64 #endif 62 65 63 EXTERN void static_simulate_1_cycle 64 EXTERN void static_mealy_generation 65 EXTERN void quasistatic_simulate_1_cycle 66 EXTERN void quasistatic_mealy_generation 66 EXTERN void static_simulate_1_cycle(); 67 EXTERN void static_mealy_generation(); 68 EXTERN void quasistatic_simulate_1_cycle(); 69 EXTERN void quasistatic_mealy_generation(); 67 70 68 71 /* internal functions */ 69 inline void switch_to_moore 70 inline void internal_sc_cycle2 71 inline void internal_sc_cycle1 72 inline void internal_sc_cycle0( double duration) INLINE;72 inline void switch_to_moore() INLINE; 73 inline void internal_sc_cycle2() INLINE; 74 inline void internal_sc_cycle1(int number_of_cycles) INLINE; 75 inline void internal_sc_cycle0(double duration) INLINE; 73 76 74 77 /* ***************** */ … … 76 79 /* ***************** */ 77 80 78 inline void 79 internal_sc_cycle2 () 80 { 81 inline void internal_sc_cycle2() { 81 82 #ifdef DUMP_STAGE 82 std::cerr << "begin of cycle #" << sc_simulation_time () << "\n";83 std::cerr << "begin of cycle #" << sc_simulation_time () << "\n"; 83 84 #endif 84 func_simulate_1_cycle();85 ++nb_cycles;85 func_simulate_1_cycle(); 86 ++nb_cycles; 86 87 #ifdef DUMP_STAGE 87 std::cerr << "end of cycle\n";88 std::cerr << "end of cycle\n"; 88 89 #endif 89 90 } 90 91 91 inline void 92 internal_sc_cycle1 (int number_of_cycles) 93 { 94 //while ((! have_to_stop) && (number_of_cycles != 0)) { 95 while (!((have_to_stop) | (number_of_cycles == 0))) { 96 trace_all (false); 97 internal_sc_cycle2 (); 98 trace_all (true); 99 number_of_cycles = (number_of_cycles<0)?number_of_cycles:number_of_cycles-1; 100 } 92 93 inline void internal_sc_cycle1(int number_of_cycles) { 94 //while ((! have_to_stop) && (number_of_cycles != 0)) { 95 while (!((have_to_stop) | (number_of_cycles == 0))) { 96 trace_all(false); 97 internal_sc_cycle2(); 98 trace_all(true); 99 number_of_cycles = (number_of_cycles<0) ? number_of_cycles:number_of_cycles - 1; 100 } 101 101 } 102 102 103 inline 104 void 105 internal_sc_cycle0( double duration )// in default time units106 { 103 104 inline void internal_sc_cycle0(double duration) { 105 // in default time units 106 107 107 #ifdef CONFIG_DEBUG 108 109 if ((func_combinationals == NULL) || (func_simulate_1_cycle == NULL)) {110 std::cerr << "Main execution loop is not yet generated.\n";111 }108 // Check dynamic linkage 109 if ((func_combinationals == NULL) || (func_simulate_1_cycle == NULL)) { 110 std::cerr << "Main execution loop is not yet generated.\n"; 111 } 112 112 113 if (duration < -1) 114 std::cerr << "Invalid duration.\n"; 113 if (duration < -1) { 114 std::cerr << "Invalid duration.\n"; 115 } 115 116 #endif 116 117 if (is_posted_write ()) {118 // update posted value to external signals119 #if 0120 std::cerr << "update\n";121 #endif122 update ();123 func_combinationals ();124 }125 126 internal_sc_cycle1 ((int)duration);127 117 128 // don't need to do func_combinationals since 'unstable' flag is now false 129 if (is_posted_write ()) { 130 update (); 131 func_combinationals (); 132 } 118 if (is_posted_write ()) { 119 // update posted value to external signals 120 update (); 121 func_combinationals (); 122 } 123 124 internal_sc_cycle1 ((int) duration); 125 126 // don't need to do func_combinationals since 'unstable' flag is now false 127 if (is_posted_write()) { 128 update(); 129 func_combinationals(); 130 } 133 131 } 134 132 … … 145 143 146 144 #endif /* __GEN_CODE_H__ */ 145 146 /* 147 # Local Variables: 148 # tab-width: 4; 149 # c-basic-offset: 4; 150 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 151 # indent-tabs-mode: nil; 152 # End: 153 # 154 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 155 */ 156 -
sources/src/global_functions.cc
r47 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : global_functions.cc |6 | |7 | Author : Buchmann Richard |8 | Nicolas Pouillon |9 | |10 | Date : 21_09_2005 |11 | |12 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : global_functions.cc | 6 | | 7 | Author : Buchmann Richard | 8 | Nicolas Pouillon | 9 | | 10 | Date : 21_09_2005 | 11 | | 12 \------------------------------------------------------------*/ 13 13 14 14 /* … … 38 38 #include <iostream> 39 39 #include <dlfcn.h> 40 #include "schedulers.h" // get_scheduling & run_schedule_editor 41 #include "sc_module.h" // check_all_method_process 42 #include "gen_code.h" // gen_scheduling_code_for_dynamic_link & gen_scheduling_code_for_static_func 40 41 #include "schedulers.h" // get_scheduling & run_schedule_editor 42 #include "sc_module.h" // check_all_method_process 43 #include "gen_code.h" // gen_scheduling_code_for_dynamic_link & gen_scheduling_code_for_static_func 43 44 #include "sc_clock_ext.h" // clock list 44 45 #include "usage.h" 45 46 #include "module_hierarchy2dot.h" 46 47 #include "assert.h" 48 47 49 #ifdef HAVE_CONFIG_H 48 50 #include "config.h" … … 53 55 namespace sc_core { 54 56 55 const char * temporary_dir = "/tmp";56 const char * generated_files_dir = "./generated_by_systemcass";57 const char * temporary_dir = "/tmp"; 58 const char * generated_files_dir = "./generated_by_systemcass"; 57 59 58 60 static usage_t usage; … … 62 64 /* ***************************** */ 63 65 64 template <typename T> 65 ostream& operator << (ostream &o, const vector<T*> &v) 66 { 67 typename vector<T*>::const_iterator i; 68 for (i = v.begin(); i != v.end(); ++i) { 69 o << **i << " "; 70 } 71 return o; 66 template < typename T > ostream & operator <<(ostream & o, const vector < T * > & v) { 67 typename vector < T * >::const_iterator i; 68 for (i = v.begin(); i != v.end(); ++i) { 69 o << **i << " "; 70 } return o; 72 71 } 73 72 … … 76 75 /****************/ 77 76 78 typedef std::set<const sc_clock*> clock_list_t; 79 80 ostream& 81 operator << (ostream &o, 82 const clock_list_t &cl) 83 { 84 clock_list_t::const_iterator i; 85 for (i = cl.begin(); i != cl.end(); ++i) { 86 o << (*i)->name () << " "; 87 } 88 return o; 89 } 77 typedef std::set<const sc_clock *> clock_list_t; 78 79 ostream & operator <<(ostream & o, const clock_list_t & cl) { 80 clock_list_t::const_iterator i; 81 for (i = cl.begin(); i != cl.end(); ++i) { 82 o << (*i)->name() << " "; 83 } 84 return o; 85 } 86 90 87 91 88 // clock list 92 void 93 create_clock_list (clock_list_t &c, 94 const equi_list_t &el) 95 { 96 equi_list_t::const_iterator i; 97 for (i = el.begin (); i != el.end(); ++i) { 98 equi_t::const_iterator j; 99 for (j = i->begin (); j != i->end (); ++j) { 100 if (j->kind () == sc_clock::kind_string) 101 c.insert ((const sc_clock*)j->object); 102 } 103 } 89 void create_clock_list(clock_list_t & c, const equi_list_t & el) { 90 equi_list_t::const_iterator i; 91 for (i = el.begin(); i != el.end(); ++i) { 92 equi_t::const_iterator j; 93 for (j = i->begin(); j != i->end(); ++j) { 94 if (j->kind() == sc_clock::kind_string) 95 c.insert((const sc_clock *) j->object); 96 } 97 } 104 98 } 105 99 … … 116 110 /* ************ */ 117 111 118 static void *handle = NULL; 119 120 static 121 void 122 link (const char *lib) 123 { 124 // chargement du code de simulate_1_cycle 125 handle = dlopen(lib, RTLD_GLOBAL | RTLD_NOW); 126 //handle = dlopen(lib, RTLD_LAZY | RTLD_GLOBAL | RTLD_NOW); 127 128 if (handle == NULL) { 129 const char *error = dlerror (); 130 if (error) 131 fprintf (stderr, "dlopen: %s\n",error); 132 fprintf (stderr, 133 "Is there -rdynamic option into your command line ? " 134 "If not, please do it.\n"); 135 exit(18); 136 } 137 138 union uni_fct_t { 139 evaluation_fct_t fct_type; 140 void *dl_pointer_type; 141 }; 142 uni_fct_t temp; 143 temp.dl_pointer_type = dlsym (handle,"initialize"); 144 if (temp.dl_pointer_type == NULL) { 145 const char *error = dlerror (); 146 if (error) 147 fprintf (stderr, "dlsym: %s\n",error); 148 exit(19); 149 } 150 evaluation_fct_t func_initialize; 151 func_initialize = temp.fct_type; 152 func_initialize (); 153 154 temp.dl_pointer_type = dlsym (handle,"simulate_1_cycle"); 155 if (temp.dl_pointer_type == NULL) { 156 const char *error = dlerror (); 157 if (error) 158 fprintf (stderr, "dlsym: %s\n",error); 159 exit(20); 160 } 161 func_simulate_1_cycle = temp.fct_type; 162 163 temp.dl_pointer_type = dlsym (handle,"mealy_generation"); 164 if (temp.dl_pointer_type == NULL) { 165 const char *error = dlerror (); 166 if (error) 167 fprintf (stderr, "dlsym: %s\n",error); 168 exit(21); 169 } 170 func_combinationals = temp.fct_type; 171 172 /* 173 * 174 */ 175 if (dump_stage) 176 cerr << "dynamic link done\n"; 177 } 178 179 static 180 void 181 unlink () 182 { 183 if (handle) 184 { 185 if (dlclose (handle) != 0) 186 cerr << "Warning : dlclose returns an error.\n" 187 << dlerror () << endl; 188 handle = NULL; 189 } 112 static void * handle = NULL; 113 114 static void link(const char * lib) { 115 // chargement du code de simulate_1_cycle 116 handle = dlopen(lib, RTLD_GLOBAL | RTLD_NOW); 117 //handle = dlopen(lib, RTLD_LAZY | RTLD_GLOBAL | RTLD_NOW); 118 119 if (handle == NULL) { 120 const char * error = dlerror(); 121 if (error) { 122 fprintf(stderr, "dlopen: %s\n", error); 123 } 124 fprintf(stderr, "Is there -rdynamic option into your command line ? If not, please do it.\n"); 125 exit(18); 126 } 127 128 union uni_fct_t { 129 evaluation_fct_t fct_type; 130 void * dl_pointer_type; 131 }; 132 uni_fct_t temp; 133 temp.dl_pointer_type = dlsym(handle, "initialize"); 134 if (temp.dl_pointer_type == NULL) { 135 const char * error = dlerror(); 136 if (error) { 137 fprintf(stderr, "dlsym: %s\n", error); 138 } 139 exit(19); 140 } 141 evaluation_fct_t func_initialize; 142 func_initialize = temp.fct_type; 143 func_initialize(); 144 145 temp.dl_pointer_type = dlsym(handle, "simulate_1_cycle"); 146 if (temp.dl_pointer_type == NULL) { 147 const char * error = dlerror(); 148 if (error) { 149 fprintf(stderr, "dlsym: %s\n", error); 150 exit(20); 151 } 152 func_simulate_1_cycle = temp.fct_type; 153 154 temp.dl_pointer_type = dlsym(handle, "mealy_generation"); 155 if (temp.dl_pointer_type == NULL) { 156 const char * error = dlerror(); 157 if (error) { 158 fprintf(stderr, "dlsym: %s\n", error); 159 } 160 exit(21); 161 } 162 func_combinationals = temp.fct_type; 163 164 /* 165 * 166 */ 167 if (dump_stage) { 168 cerr << "dynamic link done\n"; 169 } 170 } 171 } 172 173 174 static void unlink() { 175 if (handle) { 176 if (dlclose(handle) != 0) { 177 cerr << "Warning : dlclose returns an error.\n" << dlerror() << endl; 178 } 179 handle = NULL; 180 } 190 181 } 191 182 … … 194 185 /* ************ */ 195 186 196 bool already_initialized = false; 197 198 static 199 void 200 use_static_func () 201 { 202 if (dump_stage) 203 cerr << "Using static functions to schedule SystemC processes.\n"; 204 if (scheduling_method == CASS_SCHEDULING) 205 { 206 func_simulate_1_cycle = (evaluation_fct_t)sc_core::quasistatic_simulate_1_cycle; 207 func_combinationals = (evaluation_fct_t)sc_core::quasistatic_mealy_generation; 208 } else { 209 func_simulate_1_cycle = (evaluation_fct_t)sc_core::static_simulate_1_cycle; 210 func_combinationals = (evaluation_fct_t)sc_core::static_mealy_generation; 211 } 212 } 213 214 static 215 void 216 compile_and_link (const char *base_name) 217 { 218 if (dump_stage) 219 cerr << "Using dynamically loaded functions to schedule SystemC processes.\n"; 220 // compilation du code de simulate_1_cycle 221 compile_code(base_name); 222 223 char lib_absolutepath[256]; 187 bool already_initialized = false; 188 189 static void use_static_func() { 190 if (dump_stage) { 191 cerr << "Using static functions to schedule SystemC processes.\n"; 192 } 193 if (scheduling_method == CASS_SCHEDULING) { 194 func_simulate_1_cycle = (evaluation_fct_t) sc_core::quasistatic_simulate_1_cycle; 195 func_combinationals = (evaluation_fct_t) sc_core::quasistatic_mealy_generation; 196 } 197 else { 198 func_simulate_1_cycle = (evaluation_fct_t) sc_core::static_simulate_1_cycle; 199 func_combinationals = (evaluation_fct_t) sc_core::static_mealy_generation; 200 } 201 } 202 203 204 static void compile_and_link(const char *base_name) { 205 if (dump_stage) { 206 cerr << "Using dynamically loaded functions to schedule SystemC processes.\n"; 207 } 208 // compilation du code de simulate_1_cycle 209 compile_code(base_name); 210 211 char lib_absolutepath[256]; 224 212 #if defined(CONFIG_OS_DARWIN) 225 sprintf(lib_absolutepath, "/tmp/%s.so", base_name);213 sprintf(lib_absolutepath, "/tmp/%s.so", base_name); 226 214 #elif defined(CONFIG_OS_LINUX) 227 sprintf(lib_absolutepath, "/tmp/.libs/%s.so.0", base_name);215 sprintf(lib_absolutepath, "/tmp/.libs/%s.so.0", base_name); 228 216 #else 229 cerr << "ERROR\n"; exit (126); 230 #endif 231 232 link (lib_absolutepath); 233 } 234 235 static 236 void 237 internal_sc_initialize (void) 238 { 239 sort_equi_list (); 240 241 check_all_method_process (); 242 243 if (dump_netlist_info) 244 cerr << "Module instance list\n" 245 << "--------------------\n" 246 << instances_set << endl; 247 248 /* 249 * Initialize the signals table 250 */ 251 create_signals_table (); 252 bind_to_table (); 253 if (dump_netlist_info) 254 { 255 print_table (cerr); 256 cerr << endl; 257 print_table_stats (cerr); 258 cerr << endl; 259 } 260 261 // Init variables to be able to run combinational functions 262 pending_write_vector_capacity = get_signal_table_size (); 263 264 if (pending_write_vector_capacity == 0) 265 pending_write_vector = NULL; 266 else 267 pending_write_vector = (pending_write_vector_t) realloc (pending_write_vector, sizeof (pending_write_t) * pending_write_vector_capacity); 268 269 // create the clock list 270 clock_list_t clock_list; 271 create_clock_list (clock_list, get_equi_list ()); 272 if (dump_netlist_info) 273 cerr << "Clock list\n" 274 << "----------\n" 275 << clock_list << "\n\n"; 276 277 // Check if a clock exists in the system 278 if (clock_list.empty ()) { 279 cerr << "System need a clock.\n" 280 << "Please define system clock using special type \"sc_clock\".\n"; 281 exit (22); 282 } 283 284 // Check if any constructor wrote into registers 285 if (pending_write_vector_nb != 0) 286 { 287 cerr << "Error : Register/Signal writing is not allowed before sc_initialize.\n" 288 "Move initializations from constructors/sc_main to module reset sequences.\n"; 289 // we are unable to dump register(s) name(s) 290 // because the table binding is not yet completed. 291 exit (24); 292 } 293 294 string base_name = get_scheduling (scheduling_method); 295 296 if (dynamic_link_of_scheduling_code) 297 compile_and_link (base_name.c_str()); 298 else 299 use_static_func (); 300 301 pending_write_vector_nb = 0; 302 303 check_all_ports (); 304 usage.start (); 305 306 if (dump_stage) 307 cerr << "sc_initialize () done.\n"; 308 309 already_initialized = true; 310 } 311 312 inline 313 void 314 check_and_initialize () 315 { 316 if (already_initialized == false) { 217 cerr << "ERROR\n"; 218 exit(126); 219 #endif 220 link(lib_absolutepath); 221 } 222 223 224 static void internal_sc_initialize(void) { 225 sort_equi_list(); 226 227 check_all_method_process(); 228 229 if (dump_netlist_info) { 230 cerr << "Module instance list\n--------------------\n" << instances_set << endl; 231 } 232 233 /* 234 * Initialize the signals table 235 */ 236 create_signals_table(); 237 bind_to_table(); 238 if (dump_netlist_info) { 239 print_table(cerr); 240 cerr << endl; 241 print_table_stats(cerr); 242 cerr << endl; 243 } 244 // Init variables to be able to run combinational functions 245 pending_write_vector_capacity = get_signal_table_size(); 246 247 if (pending_write_vector_capacity == 0) { 248 pending_write_vector = NULL; 249 } 250 else { 251 pending_write_vector = (pending_write_vector_t) realloc(pending_write_vector, sizeof(pending_write_t) * pending_write_vector_capacity); 252 } 253 254 // create the clock list 255 clock_list_t clock_list; 256 create_clock_list(clock_list, get_equi_list()); 257 if (dump_netlist_info) { 258 cerr << "Clock list\n" << "----------\n" << clock_list << "\n\n"; 259 } 260 261 // Check if a clock exists in the system 262 if (clock_list.empty()) { 263 cerr << "System need a clock.\n" << 264 "Please define system clock using special type \"sc_clock\".\n"; 265 exit(22); 266 } 267 // Check if any constructor wrote into registers 268 if (pending_write_vector_nb != 0) { 269 cerr << 270 "Error : Register/Signal writing is not allowed before sc_initialize.\n" 271 "Move initializations from constructors/sc_main to module reset sequences.\n"; 272 // we are unable to dump register(s) name(s) 273 // because the table binding is not yet completed. 274 exit(24); 275 } 276 277 string base_name = get_scheduling(scheduling_method); 278 279 if (dynamic_link_of_scheduling_code) { 280 compile_and_link(base_name.c_str()); 281 } 282 else { 283 use_static_func(); 284 } 285 286 pending_write_vector_nb = 0; 287 288 check_all_ports(); 289 usage.start(); 290 291 if (dump_stage) { 292 cerr << "sc_initialize () done.\n"; 293 } 294 295 already_initialized = true; 296 } 297 298 299 inline void check_and_initialize() { 300 if (already_initialized == false) { 317 301 #if defined(SYSTEMC_VERSION_1_0) 318 std::cerr << "Warning : call sc_initialize before executiong simulation.\n";319 #endif 320 internal_sc_initialize();321 if (dump_module_hierarchy)322 module_hierarchy2dot(dump_module_hierarchy);323 if (nosimulation)324 {325 exit(0);326 }327 }328 } 329 330 void sc_initialize(void) 331 {332 cerr << "Warning : 'sc_initialize' function is deprecated since SystemC 2.1.\n";333 cerr << "Use 'sc_start(0)' instead.\n";334 check_and_initialize();302 cerr << "Warning : call sc_initialize before executiong simulation.\n"; 303 #endif 304 internal_sc_initialize(); 305 if (dump_module_hierarchy) { 306 module_hierarchy2dot(dump_module_hierarchy); 307 } 308 if (nosimulation) { 309 exit(0); 310 } 311 } 312 } 313 314 315 void sc_initialize(void) { 316 cerr << "Warning : 'sc_initialize' function is deprecated since SystemC 2.1.\n"; 317 cerr << "Use 'sc_start(0)' instead.\n"; 318 check_and_initialize(); 335 319 } 336 320 … … 339 323 /* ********** */ 340 324 341 inline 342 void 343 sc_cycle( double duration) 344 { 345 check_and_initialize (); 346 sc_core::internal_sc_cycle0(duration); 347 } 348 349 inline 350 void 351 sc_cycle( double duration, 352 sc_time_unit time_unit ) 353 { 354 check_and_initialize (); 355 sc_core::internal_sc_cycle0(duration); 356 } 357 358 void 359 sc_start(double d_val) 360 { 361 sc_cycle (d_val); 325 inline void sc_cycle(double duration) { 326 check_and_initialize(); 327 sc_core::internal_sc_cycle0(duration); 328 } 329 330 331 inline void sc_cycle(double duration, sc_time_unit time_unit) { 332 check_and_initialize(); 333 sc_core::internal_sc_cycle0(duration); 334 } 335 336 337 void sc_start(double d_val) { 338 sc_cycle(d_val); 362 339 #ifdef DUMP_SIGNAL_STATS 363 print_registers_writing_stats(cerr);340 print_registers_writing_stats(cerr); 364 341 #endif 365 342 #ifdef DUMP_SCHEDULE_STATS 366 print_schedule_stats (cerr); 367 #endif 368 } 369 370 void 371 sc_start() 372 { 373 sc_cycle (-1); 343 print_schedule_stats(cerr); 344 #endif 345 } 346 347 348 void sc_start() { 349 sc_cycle(-1); 374 350 #ifdef DUMP_SIGNAL_STATS 375 print_registers_writing_stats(cerr);351 print_registers_writing_stats(cerr); 376 352 #endif 377 353 #ifdef DUMP_SCHEDULE_STATS 378 print_schedule_stats (cerr); 379 #endif 380 } 381 382 void 383 sc_start (double d_val, 384 sc_time_unit d_tu) 385 { 386 sc_start (sc_time (d_val, d_tu)); 387 } 388 389 void 390 sc_start( const sc_time& duration ) 391 { 392 sc_cycle ((double)duration); 354 print_schedule_stats(cerr); 355 #endif 356 } 357 358 359 void sc_start(double d_val, sc_time_unit d_tu) { 360 sc_start(sc_time(d_val, d_tu)); 361 } 362 363 364 void sc_start(const sc_time & duration) { 365 sc_cycle((double) duration); 393 366 #ifdef DUMP_SIGNAL_STATS 394 print_registers_writing_stats(cerr);367 print_registers_writing_stats(cerr); 395 368 #endif 396 369 #ifdef DUMP_SCHEDULE_STATS 397 print_schedule_stats (cerr); 398 #endif 399 } 370 print_schedule_stats(cerr); 371 #endif 372 } 373 400 374 401 375 /* ****************** */ … … 403 377 /* ****************** */ 404 378 405 bool have_to_stop = false; 406 sc_stop_mode stop_mode = SC_STOP_FINISH_DELTA; 407 408 void 409 sc_stop () 410 { 411 switch (stop_mode) 412 { 413 case SC_STOP_IMMEDIATE : 414 exit (54); 415 break; 416 case SC_STOP_FINISH_DELTA : 417 default : 418 have_to_stop = true; 419 break; 420 } 421 } 422 423 void 424 sc_set_stop_mode (sc_stop_mode new_mode) 425 { 426 if (new_mode == SC_STOP_IMMEDIATE) 427 stop_mode = SC_STOP_IMMEDIATE; 428 } 429 430 sc_stop_mode 431 sc_get_stop_mode () 432 { 433 return stop_mode; 434 } 435 436 void 437 close_systemcass () 438 { 439 unlink (); 440 if (print_user_resources) 441 { 442 usage.stop (); 443 unsigned int d = usage; 444 cerr << "Performances\n" 445 "------------\n"; 446 cerr << "Time elapsed (sec) : " << d << endl; 447 cerr << "Cycles done : " << nb_cycles << endl; 448 //sc_simulation_time () << endl; 449 if (d == 0) 450 cerr << "Performance (c/s) : N/A" << endl; 451 else 452 cerr << "Performance (c/s) : " << nb_cycles / d << endl; 453 // cerr << "Memory used : " << usage.get_memory_size () << endl; 454 } 455 } 456 457 ///////////////////////// 379 bool have_to_stop = false; 380 sc_stop_mode stop_mode = SC_STOP_FINISH_DELTA; 381 382 void sc_stop() { 383 switch (stop_mode) { 384 case SC_STOP_IMMEDIATE: 385 exit(54); 386 break; 387 case SC_STOP_FINISH_DELTA: 388 default: 389 have_to_stop = true; 390 break; 391 } 392 } 393 394 395 void sc_set_stop_mode(sc_stop_mode new_mode) { 396 if (new_mode == SC_STOP_IMMEDIATE) { 397 stop_mode = SC_STOP_IMMEDIATE; 398 } 399 } 400 401 402 sc_stop_mode sc_get_stop_mode() { 403 return stop_mode; 404 } 405 406 407 void close_systemcass() { 408 unlink(); 409 if (print_user_resources) { 410 usage.stop(); 411 unsigned int d = usage; 412 cerr << "Performances\n" "------------\n"; 413 cerr << "Time elapsed (sec) : " << d << endl; 414 cerr << "Cycles done : " << nb_cycles << endl; 415 if (d == 0) { 416 cerr << "Performance (c/s) : N/A" << endl; 417 } 418 else { 419 cerr << "Performance (c/s) : " << nb_cycles / d << endl; 420 } 421 // cerr << "Memory used : " << usage.get_memory_size () << endl; 422 } 423 } 458 424 459 425 } // end of sc_core namespace 460 426 427 /* 428 # Local Variables: 429 # tab-width: 4; 430 # c-basic-offset: 4; 431 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 432 # indent-tabs-mode: nil; 433 # End: 434 # 435 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 436 */ 437 -
sources/src/global_functions.h
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : global_functions.h |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : 09_07_2004 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : global_functions.h | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 09_07_2004 | 10 | | 11 \------------------------------------------------------------*/ 12 12 #ifndef __GLOBAL_FUNCTIONS_H__ 13 13 #define __GLOBAL_FUNCTIONS_H__ … … 23 23 enum sc_stop_mode 24 24 { 25 SC_STOP_FINISH_DELTA,26 SC_STOP_IMMEDIATE25 SC_STOP_FINISH_DELTA, 26 SC_STOP_IMMEDIATE 27 27 }; 28 29 28 ///////////////////////// 30 29 31 32 extern int main(int argc, char *argv[]); 30 extern int main(int argc, char * argv[]); 33 31 34 32 extern void sc_initialize(void); 35 33 36 //extern void next_cycle(void); 37 extern void sc_start (double d_val) __attribute__((deprecated)); 38 extern void sc_start (); 39 extern void sc_start ( const sc_time& duration ); 40 extern void sc_start (double d_val, sc_time_unit d_tu); 41 extern void sc_stop (); 42 extern void sc_set_stop_mode (sc_stop_mode); 34 extern void sc_start(double d_val) __attribute__((deprecated)); 35 extern void sc_start(); 36 extern void sc_start(const sc_time & duration ); 37 extern void sc_start(double d_val, sc_time_unit d_tu); 38 extern void sc_stop(); 39 extern void sc_set_stop_mode (sc_stop_mode); 43 40 extern sc_stop_mode sc_get_stop_mode (); 44 41 45 extern const char * sc_gen_unique_name (const char *basename_);42 extern const char * sc_gen_unique_name(const char * basename_); 46 43 47 44 ///////////////////////// 48 45 ///// SYSTEMCASS_SPECIFIC 49 extern void close_systemcass (); 50 extern bool run_schedule_editor (const char*); 51 extern const char *temporary_dir; 52 extern const char *generated_files_dir; 46 47 extern void close_systemcass(); 48 extern bool run_schedule_editor(const char *); 49 extern const char * temporary_dir; 50 extern const char * generated_files_dir; 53 51 54 52 ///////////////////////// … … 65 63 #endif 66 64 65 /* 66 # Local Variables: 67 # tab-width: 4; 68 # c-basic-offset: 4; 69 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 70 # indent-tabs-mode: nil; 71 # End: 72 # 73 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 74 */ 75 -
sources/src/graph.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : graph.cc |6 | |7 | Author : Petrot Frédéric |8 | Taktak Sami |9 | Buchmann Richard |10 | |11 | Date : 09_07_2004 |12 | |13 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : graph.cc | 6 | | 7 | Author : Petrot Frédéric | 8 | Taktak Sami | 9 | Buchmann Richard | 10 | | 11 | Date : 09_07_2004 | 12 | | 13 \------------------------------------------------------------*/ 14 14 15 15 /* … … 121 121 /* Sorry for that, Mr Knuth :-) */ 122 122 123 Graph *gb_new_graph(int n) 124 { 125 Graph *g; 126 127 g = (Graph *) malloc(sizeof(Graph)); 128 g->n = n; 129 if (n) 130 { 131 g->vertices = (Vertex *) malloc(n * sizeof(Vertex)); 132 (void)memset(g->vertices, 0, n * sizeof(Vertex)); 133 } else { 134 g->vertices = NULL; 135 } 136 return g; 137 } 138 139 static void gb_new_arc(Vertex *u, Vertex *v, long l) 140 { 141 Arc *a; 142 143 a = (Arc *) malloc(sizeof(Arc)); 144 a->next = u->arcs; 145 u->arcs = a; 146 a->tip = v; 147 a->len = l; 123 Graph * gb_new_graph(int n) { 124 Graph * g; 125 126 g = (Graph *) malloc(sizeof(Graph)); 127 g->n = n; 128 if (n) { 129 g->vertices = (Vertex *) malloc(n * sizeof(Vertex)); 130 (void) memset(g->vertices, 0, n * sizeof(Vertex)); 131 } 132 else { 133 g->vertices = NULL; 134 } 135 return g; 136 } 137 138 139 static void gb_new_arc(Vertex * u, Vertex * v, long l) { 140 Arc * a; 141 a = (Arc *) malloc(sizeof(Arc)); 142 a->next = u->arcs; 143 u->arcs = a; 144 a->tip = v; 145 a->len = l; 148 146 } 149 147 … … 152 150 #define VERTEX 220898 153 151 154 #define type u.I 155 156 void new_arc(Vertex *u, Vertex *v) 157 { 158 Arc *a; 152 #define type u.I 153 154 void new_arc(Vertex * u, Vertex * v) { 155 Arc * a; 159 156 #ifdef CONFIG_DEBUG 160 if ((u == NULL) || (v == NULL)) 161 exit(29042004); 157 if ((u == NULL) || (v == NULL)) { 158 exit(29042004); 159 } 162 160 #endif 163 for (a = u->arcs; a; a = a->next) 164 if (a->tip == v) 165 return; 166 gb_new_arc(u, v, 0L); 167 } 161 for (a = u->arcs; a != NULL; a = a->next) { 162 if (a->tip == v) { 163 return; 164 } 165 } 166 gb_new_arc(u, v, 0L); 167 } 168 168 169 169 170 #define rank z.I … … 181 182 * to ones list the components contents (one or more vertices) */ 182 183 183 extern strong_component_list_t *strong_component(Graph *g) 184 { 185 long nn; 186 Vertex *active_stack; 187 Vertex *settled_stack; 188 Vertex *vv; 189 190 register Vertex *v; 191 192 strong_component_list_t *strongcomponents = new strong_component_list_t; 193 typedef std::vector<void*> void_list_t; 194 void_list_t *component; 195 196 if (g->vertices == NULL) 184 extern strong_component_list_t *strong_component(Graph * g) { 185 long nn; 186 Vertex * active_stack; 187 Vertex * settled_stack; 188 Vertex * vv; 189 190 register Vertex * v; 191 192 strong_component_list_t * strongcomponents = new strong_component_list_t; 193 typedef std::vector < void *>void_list_t; 194 void_list_t * component; 195 196 if (g->vertices == NULL) { 197 return strongcomponents; 198 } 199 200 /* Make all vertices unseen and all arcs untagged */ 201 for (v = g->vertices + g->n - 1; v >= g->vertices; v--) { 202 v->rank = 0; 203 v->untagged = v->arcs; 204 } 205 nn = 0; 206 active_stack = settled_stack = NULL; 207 208 for (vv = g->vertices; vv < g->vertices + g->n; vv++) { 209 if (vv->rank == 0) { /* vv is still unseen */ 210 v = vv; 211 v->parent = NULL; 212 213 v->rank = ++nn; 214 v->link = active_stack; 215 active_stack = v; 216 v->min = v; 217 218 do { /* Eplore one step from the current vertex v, possibly moving to another vertex 219 and calling it v */ 220 register Vertex *u; /* a vertex adjacent to v */ 221 register Arc *a = v->untagged; /* v's first remaining untagged arc, if any */ 222 if (a) { 223 u = a->tip; 224 v->untagged = a->next; /* tag the arc from v to u */ 225 if (u->rank) { /* we've seen u already */ 226 if (u->rank < v->min->rank) { /* non-tree arc, jutt update v->min */ 227 v->min = u; 228 } 229 } 230 else { /* u is presently unseen */ 231 u->parent = v; /* the arcfrom v to u is a new tree arc */ 232 v = u; /* u will now be the currnt vertex */ 233 v->rank = ++nn; /* make vertex v active */ 234 v->link = active_stack; 235 active_stack = v; 236 v->min = v; 237 } 238 } 239 else { /* all arcs from v are tagged, so v matures */ 240 u = v->parent; /* prepare to backtrack in the tree */ 241 if (v->min == v) { 242 /* Remove v and all its successors on the activestack from the tree, 243 and mark them as a strong component of the graph */ 244 register Vertex * t; /* runs though the vertices of the new strong component */ 245 246 t = active_stack; 247 active_stack = v->link; 248 v->link = settled_stack; 249 settled_stack = t; /* we've moved the top of one stack to the other */ 250 component = new void_list_t; 251 /* singe vetex */ 252 if (t != v) { /* NOT singe vetex */ 253 while (t != v) { 254 component->push_back(t->data); 255 t->rank = infinity; /* now t is settled */ 256 t->parent = v; /* and v represents the new strong component */ 257 t = t->link; 258 } 259 } 260 component->push_back(v->data); 261 strongcomponents->push_back(component); 262 v->rank = infinity; /* v too is settled */ 263 v->parent = v; /* and represents its own strong component */ 264 } 265 else { 266 /* the arc from u to v has just matured, making v->min visible from u */ 267 if (v->min->rank < u->min->rank) { 268 u->min = v->min; 269 } 270 } 271 v = u;/* the former parent of v is the new current vertex v */ 272 } 273 } while (v != NULL); 274 } 275 } 276 197 277 return strongcomponents; 198 199 /* Make all vertices unseen and all arcs untagged */ 200 for (v = g->vertices + g->n - 1; v >= g->vertices; v--) { 201 v->rank = 0; 202 v->untagged = v->arcs; 203 } 204 nn = 0; 205 active_stack = settled_stack = NULL; 206 207 for (vv = g->vertices; vv < g->vertices + g->n; vv++) 208 if (vv->rank == 0) { /* vv is still unseen */ 209 v = vv; 210 v->parent = NULL; 211 212 v->rank = ++nn; 213 v->link = active_stack; 214 active_stack = v; 215 v->min = v; 216 217 do { /* Eplore one step from the current vertex v, possibly moving to another vertex 218 and calling it v */ 219 register Vertex *u; /* a vertex adjacent to v */ 220 register Arc *a = v->untagged; /* v's first remaining untagged arc, if any */ 221 if (a) { 222 u = a->tip; 223 v->untagged = a->next; /* tag the arc from v to u */ 224 if (u->rank) { /* we've seen u already */ 225 if (u->rank < v->min->rank) /* non-tree arc, jutt update v->min */ 226 v->min = u; 227 } else { /* u is presently unseen */ 228 u->parent = v; /* the arcfrom v to u is a new tree arc */ 229 v = u; /* u will now be the currnt vertex */ 230 v->rank = ++nn; /* make vertex v active */ 231 v->link = active_stack; 232 active_stack = v; 233 v->min = v; 234 } 235 } else { /* all arcs from v are tagged, so v matures */ 236 u = v->parent; /* prepare to backtrack in the tree */ 237 if (v->min == v) { 238 /* Remove v and all its successors on the activestack from the tree, 239 and mark them as a strong component of the graph */ 240 register Vertex *t; /* runs though the vertices of the new strong component */ 241 242 t = active_stack; 243 active_stack = v->link; 244 v->link = settled_stack; 245 settled_stack = t; /* we've moved the top of one stack to the other */ 246 component = new void_list_t; 247 /* singe vetex */ 248 if (t != v) { /* NOT singe vetex */ 249 while (t != v) { 250 component->push_back(t->data); 251 t->rank = infinity; /* now t is settled */ 252 t->parent = v; /* and v represents the new strong component */ 253 t = t->link; 254 } 255 } 256 component->push_back(v->data); 257 strongcomponents->push_back(component); 258 v->rank = infinity; /* v too is settled */ 259 v->parent = v; /* and represents its own strong component */ 260 } else /* the arc from u to v has just matured, making v->min visible from u */ 261 if (v->min->rank < u->min->rank) u->min = v->min; 262 v = u; /* the former parent of v is the new current vertex v */ 263 } 264 } while (v != NULL); 265 } 266 267 return strongcomponents; 268 } 269 270 bool 271 has_cycle (const strong_component_list_t &l) 272 { 273 strong_component_list_t::const_iterator it; 274 for (it = l.begin (); it != l.end (); ++it) 275 { 276 if ((*it)->size() > 1) 277 return true; 278 } 279 return false; 280 } 281 282 #if 0 283 const component_list_t* 284 get_cycle (const strong_component_list_t &l) 285 { 286 strong_component_list_t::const_iterator it; 287 for (it = l.begin (); it != l.end (); ++it) 288 { 289 const component_list_t *c = *it; 290 if (c->size() > 1) 291 return c; 292 } 293 return NULL; 294 } 295 296 void 297 print_cycle (std::ostream &o, 298 const component_list_t *c) 299 { 300 if (c == NULL) 301 return; 302 component_list_t::const_iterator it; 303 for (it = c->begin (); it != c->end (); ++it) 304 { 305 void *v = *it; 306 o << hex << (int) v << " "; 307 } 308 o << "\n"; 309 } 310 #endif 311 278 } 279 280 281 bool has_cycle(const strong_component_list_t & l) { 282 strong_component_list_t::const_iterator it; 283 for (it = l.begin(); it != l.end(); ++it) { 284 if ((*it)->size() > 1) { 285 return true; 286 } 287 } 288 return false; 289 } 290 291 292 /* 293 # Local Variables: 294 # tab-width: 4; 295 # c-basic-offset: 4; 296 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 297 # indent-tabs-mode: nil; 298 # End: 299 # 300 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 301 */ 302 -
sources/src/graph.h
r1 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : graph.h |6 | |7 | Author : Pétrot Frédéric |8 | Taktak Sami |9 | Buchmann Richard |10 | |11 | Date : 09_07_2004 |12 | |13 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : graph.h | 6 | | 7 | Author : Pétrot Frédéric | 8 | Taktak Sami | 9 | Buchmann Richard | 10 | | 11 | Date : 09_07_2004 | 12 | | 13 \------------------------------------------------------------*/ 14 14 #ifndef __GRAPH_H__ 15 15 #define __GRAPH_H__ … … 26 26 27 27 enum vertex_type { 28 CONNECTOR = 0x0, INSTANCE = 0x4, STRONG_COMPONENT = 0x828 CONNECTOR = 0x0, INSTANCE = 0x4, STRONG_COMPONENT = 0x8 29 29 }; 30 30 31 #define KEEP_ARC 24089831 //#define KEEP_ARC 240898 32 32 33 33 typedef union { 34 struct vertex_struct *V;35 struct arc_struct *A;36 struct graph_struct *G;37 char *S;38 long I;34 struct vertex_struct * V; 35 struct arc_struct * A; 36 struct graph_struct * G; 37 char * S; 38 long I; 39 39 } util; 40 40 41 41 typedef struct vertex_struct { 42 struct arc_struct *arcs;43 44 void *data;45 46 util u, v, w, x, y, z;42 struct arc_struct * arcs; 43 union { 44 void * data; 45 }; 46 util u, v, w, x, y, z; 47 47 } Vertex; 48 48 49 49 typedef struct arc_struct { 50 struct vertex_struct *tip;51 struct arc_struct *next;52 long len;53 util a, b;50 struct vertex_struct * tip; 51 struct arc_struct * next; 52 long len; 53 util a, b; 54 54 } Arc; 55 55 56 #define ID_FIELD_SIZE 16156 //#define ID_FIELD_SIZE 161 57 57 typedef struct graph_struct { 58 Vertex *vertices;59 long n;60 long m;61 char *id;62 util uu, vv, ww, xx, yy, zz;58 Vertex * vertices; 59 long n; 60 long m; 61 char * id; 62 util uu, vv, ww, xx, yy, zz; 63 63 } Graph; 64 64 65 extern Graph * gb_new_graph(int n);66 extern void new_arc(Vertex * u, Vertex *v);65 extern Graph * gb_new_graph(int n); 66 extern void new_arc(Vertex * u, Vertex * v); 67 67 68 68 typedef std::vector<void *> component_list_t; 69 69 typedef std::vector<component_list_t *> strong_component_list_t; 70 extern strong_component_list_t * strong_component(Graph *g);70 extern strong_component_list_t * strong_component(Graph * g); 71 71 72 extern bool has_cycle (const strong_component_list_t&); 73 #if 0 74 extern const component_list_t* get_cycle (const strong_component_list_t&); 75 extern void print_cycle (std::ostream&,const component_list_t*); 76 #endif 72 extern bool has_cycle(const strong_component_list_t &); 77 73 78 74 #endif /* __GRAPH_H__ */ 75 76 /* 77 # Local Variables: 78 # tab-width: 4; 79 # c-basic-offset: 4; 80 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 81 # indent-tabs-mode: nil; 82 # End: 83 # 84 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 85 */ 86 -
sources/src/graph_cass.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : graph_cass.cc |6 | |7 | Author : Petrot Frédéric |8 | Taktak Sami |9 | Buchmann Richard |10 | |11 | Date : 09_07_2004 |12 | |13 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : graph_cass.cc | 6 | | 7 | Author : Petrot Frédéric | 8 | Taktak Sami | 9 | Buchmann Richard | 10 | | 11 | Date : 09_07_2004 | 12 | | 13 \------------------------------------------------------------*/ 14 14 15 15 /* … … 107 107 * bug fix : 108 108 * - allow the use of user-defined structs in sc_signal/sc_in/sc_out/sc_inout 109 110 111 112 113 114 115 116 109 * - use sc_dt namespace like official SystemC engine 110 * 111 * add : 112 * - dump the signal/port/module dependancy graph in dot format 113 * 114 * Graph library is now splitted from the SystemCASS specific code. 115 * 116 */ 117 117 118 118 #include <iostream> … … 129 129 #include "entity.h" 130 130 #include "simplify_string.h" // simplify_string 131 #include "sc_ver_ext.h" 131 #include "sc_ver_ext.h" // sc_version for dumping to DOT 132 132 #ifdef HAVE_CONFIG_H 133 133 #include "config.h" … … 138 138 namespace sc_core { 139 139 140 #if 0 141 static 142 ostream& operator << (ostream& o, 143 const Vertex & v) 144 { 145 #if 0 146 if (v.arcs == NULL) 147 o << v.name << "(" << v.module->ins_name << ")->(none)\n"; 148 Arc *a; 149 for (a = v.arcs; a; a = a->next) 150 o << v.name << "(" << v.module->ins_name << ")->" 151 << a->tip->name << "(" << a->tip->module << ")\n"; 152 return o; 153 #endif 154 method_process_t* m = (method_process_t*)(v.data); 155 if (v.arcs == NULL) 156 o << *m << "\n"; 157 Arc *a; 158 for (a = v.arcs; a; a = a->next) { 159 method_process_t* m2 = (method_process_t*)(a->tip->data); 160 o << *m << "->" 161 << *m2 << ")\n"; 162 } 163 return o; 164 165 } 166 #endif 167 168 #if 0 169 static 170 ostream& 171 operator << (ostream &o, 172 const Graph &g) 173 { 174 Vertex *v; 175 for (v = g.vertices; v < g.vertices + g.n; v++) { 176 o << *v; 177 } 178 return o; 179 } 180 #endif 181 182 std::map<const method_process_t*,Vertex*> m_v; 183 184 /* Ajoute un arc */ 185 void add_arcs(const method_process_t &mp, const sc_module &module) 186 { 187 std::map<const method_process_t*,Vertex*>::iterator i; 188 for (i = m_v.begin (); i != m_v.end (); ++i) { 189 if (i->first->module == &module) 190 new_arc (m_v[&mp],i->second); 191 } 192 } 193 194 /* Ajoute un arc */ 195 void add_arcs(const method_process_t &mp, 196 tab_t *signal_pointer) 197 { 198 equi_t &e = get_equi (signal_pointer); 199 equi_t::iterator i; 200 for (i = e.begin (); i != e.end (); ++i) { 201 const char *kind = i->kind (); 202 if (strstr (kind,"out")) { 203 const sc_port_base &port = *(i->port); 204 const sc_module &module = port.get_module (); 205 if (&module == mp.module) 206 continue; 207 add_arcs (mp, module); 208 break; 209 } 210 } 211 } 212 213 void 214 add_arcs(const method_process_t &mp) 215 { 216 sensitivity_list_t::const_iterator port_bound; 217 for (port_bound = mp.sensitivity_list.begin(); port_bound != mp.sensitivity_list.end(); ++port_bound) { 218 // pour tous les ports/signaux p associés à la fonction au couple m 219 /* si pp est un port de sortie d'une autre fonction de mealy, 220 crée un arc entre m et mm */ 221 /* on ne peut pas savoir si un port est la sortie d'une fonction de mealy. 222 on va donc chercher à savoir si c'est un port de sortie d'un automate de moore, 223 sinon on considère que c'est une sortie de mealy. 224 */ 225 226 add_arcs(mp, port_bound->get_interface().get_pointer ()); 227 } 228 } 140 std::map < const method_process_t *, Vertex * >m_v; 141 142 /* Ajoute un arc */ 143 void add_arcs(const method_process_t & mp, const sc_module & module) { 144 std::map < const method_process_t *, Vertex * >::iterator i; 145 for (i = m_v.begin(); i != m_v.end(); ++i) { 146 if (i->first->module == &module) 147 new_arc(m_v[&mp], i->second); 148 } 149 } 150 151 152 /* Ajoute un arc */ 153 void add_arcs(const method_process_t & mp, tab_t * signal_pointer) { 154 equi_t & e = get_equi(signal_pointer); 155 equi_t::iterator i; 156 for (i = e.begin(); i != e.end(); ++i) { 157 const char * kind = i->kind(); 158 if (strstr(kind, "out")) { 159 const sc_port_base & port = *(i->port); 160 const sc_module & module = port.get_module(); 161 if (&module == mp.module) { 162 continue; 163 } 164 add_arcs(mp, module); 165 break; 166 } 167 } 168 } 169 170 171 void add_arcs(const method_process_t & mp) { 172 sensitivity_list_t::const_iterator port_bound; 173 for (port_bound = mp.sensitivity_list.begin(); 174 port_bound != mp.sensitivity_list.end(); ++port_bound) { 175 // pour tous les ports/signaux p associés à la fonction au couple m 176 /* si pp est un port de sortie d'une autre fonction de mealy, 177 crée un arc entre m et mm */ 178 /* on ne peut pas savoir si un port est la sortie d'une fonction de mealy. 179 on va donc chercher à savoir si c'est un port de sortie d'un automate de moore, 180 sinon on considère que c'est une sortie de mealy. 181 */ 182 add_arcs(mp, port_bound->get_interface().get_pointer()); 183 } 184 } 185 229 186 230 187 /* Construit le graph de dépendance des signaux de Mealy */ … … 238 195 Vertex is an array of (method_process_t*) 239 196 Edge is a couple Vertex->Vertex. 197 */ 198 extern Graph * makegraph(const method_process_list_t * lm) { 199 method_process_list_t::const_iterator mp; 200 201 int n = 0; /* Number of vertices */ 202 Graph * g; 203 Vertex * v; 204 205 /* Compute the number of vertices in the graph: 206 * The vertices set is the method set. */ 207 208 /* for (m = lm->begin(); m != lm->end(); m++) 209 n++;*/ 210 n = lm->size(); 211 212 /* Create the graph */ 213 g = gb_new_graph(n); 214 215 /* Associate the netlist elements to the graph vertices, and vice-versa */ 216 v = g->vertices; 217 218 /* initialisation des vertices */ 219 for (mp = lm->begin(); mp != lm->end(); ++mp) { 220 v->data = *mp; 221 m_v[*mp] = v++; 222 } 223 224 for (mp = lm->begin(); mp != lm->end(); ++mp) { 225 // pour tous couples m, instance module/function de la liste lm 226 add_arcs(**mp); 227 } 228 229 return g; 230 } 231 232 233 static string & get_method_process_fullname(string & name, const method_process_t & mp) { 234 sc_module * module = mp.module; 235 name = module->name(); 236 name += "_"; 237 name += mp.name; 238 return name; 239 } 240 241 242 static bool dot_write(ofstream & o, const Graph & g) { 243 string name1, name2, s; 244 // Printing into dot file 245 for (int i = 0; i < g.n; ++i) { // Printing node list 246 Vertex * v = g.vertices + i; 247 method_process_t *mp = (method_process_t *) (v->data); 248 get_method_process_fullname(name1, *mp); 249 const char * pname1 = name1.c_str(); 250 o << "node [name="; 251 o.width(35); 252 o << simplify_name(pname1, s); 253 o << "];\n"; 254 } 255 for (int i = 0; i < g.n; ++i) { // Printing edge list 256 Vertex * v1 = g.vertices + i; 257 method_process_t *mp1 = (method_process_t *) (v1->data); 258 get_method_process_fullname(name1, *mp1); 259 const char * pname1 = name1.c_str(); 260 for (Arc * a = v1->arcs; a != NULL; a = a->next) { 261 Vertex *v2 = a->tip; 262 method_process_t * mp2 = (method_process_t *) (v2->data); 263 get_method_process_fullname(name2, *mp2); 264 const char * pname2 = name2.c_str(); 265 o.width(35); 266 o << simplify_name(pname2, s); 267 o << " -> "; 268 o.width(35); 269 o << simplify_name(pname1, s); 270 o << ";\n"; 271 } 272 } 273 return true; 274 } 275 276 extern bool graph2dot(const char * name, const Graph & g) { 277 if (!name) { 278 return false; 279 } 280 string filename; 281 filename = name; 282 filename += ".dot"; 283 ofstream o; 284 o.open(filename.c_str(), ios::out | ios::trunc); 285 if (o.is_open() == false) { 286 return false; 287 } 288 o << "// Module dependency graph\n// Generated by " << sc_version() << "\n"; 289 o << "strict digraph " << name << " {\n"; 290 o << "node [shape=box];\n"; 291 // "concentrate=true;\n"; 292 o << left; 293 dot_write(o, g); 294 // Closing dot file 295 o << "}\n"; 296 o.close(); 297 if (dump_stage) { 298 cerr << "Module dependency graph written into '" << filename << "'.\n"; 299 } 300 return true; 301 } 302 303 } // end of sc_core namespace 304 305 /* 306 # Local Variables: 307 # tab-width: 4; 308 # c-basic-offset: 4; 309 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 310 # indent-tabs-mode: nil; 311 # End: 312 # 313 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 240 314 */ 241 extern Graph* 242 makegraph (const method_process_list_t *lm) 243 { 244 method_process_list_t::const_iterator mp; 245 246 int n = 0; /* Number of vertices */ 247 Graph *g; 248 Vertex *v; 249 250 /* Compute the number of vertices in the graph: 251 * The vertices set is the method set. */ 252 253 /* for (m = lm->begin(); m != lm->end(); m++) 254 n++;*/ 255 n = lm->size (); 256 257 /* Create the graph */ 258 g = gb_new_graph(n); 259 260 /* Associate the netlist elements to the graph vertices, and vice-versa */ 261 v = g->vertices; 262 263 /* initialisation des vertices */ 264 for (mp = lm->begin(); mp != lm->end(); ++mp) { 265 v->data = *mp; 266 m_v[*mp] = v++; 267 } 268 269 for (mp = lm->begin(); mp != lm->end(); ++mp) { 270 // pour tous couples m, instance module/function de la liste lm 271 add_arcs (**mp); 272 } 273 274 return g; 275 } 276 277 /* 278 void 279 dot_write_edge (const method_process_t &mp, 280 tab_t *signal_pointer) 281 { 282 equi_t &e = get_equi (signal_pointer); 283 equi_t::iterator i; 284 for (i = e.begin (); i != e.end (); ++i) { 285 const char *kind = i->kind (); 286 if (strstr (kind,"out")) { 287 const sc_port_base &port = *(i->port); 288 const sc_module &module = port.get_module (); 289 if (&module == mp.module) 290 continue; 291 add_arcs (mp, module); 292 o << "edge [label=" 293 << "];\n"; 294 o << " -> "; 295 o << ";\n"; 296 } 297 } 298 } 299 300 static 301 bool 302 dot_write_edge (ofstream &o, 303 const method_process_t &mp) 304 { 305 sensitivity_list_t::const_iterator port_bound; 306 for (port_bound = mp.sensitivity_list.begin(); port_bound != mp.sensitivity_list.end(); ++port_bound) 307 dot_write_edge (o, mp, port_bound->get_interface().get_pointer ()); 308 } 309 310 static 311 bool 312 dot_write (ofstream &o, 313 const method_process_list_t &lm) 314 { 315 // Printing into dot file 316 string s; 317 method_process_list_t::const_iterator mp; 318 for (mp = lm.begin(); mp != lm.end(); ++mp) { 319 method_process_t *amp = *mp; 320 sc_module *module = amp->module; 321 o << "node [name=" 322 // << simplify_name(module.get_name().c_str(),s) 323 << "];\n"; 324 } 325 for (mp = lm->begin(); mp != lm->end(); ++mp) 326 dot_write (o, **mp); 327 } 328 */ 329 330 static 331 string& 332 get_method_process_fullname (string &name, 333 const method_process_t &mp) 334 { 335 sc_module *module = mp.module; 336 name = module->name (); 337 name += "_"; 338 name += mp.name; 339 return name; 340 } 341 342 static 343 bool 344 dot_write (ofstream &o, 345 const Graph &g) 346 { 347 string name1,name2,s; 348 // Printing into dot file 349 for (int i = 0; i < g.n; ++i) 350 { // Printing node list 351 Vertex *v = g.vertices + i; 352 method_process_t *mp = (method_process_t*) (v->data); 353 get_method_process_fullname (name1,*mp); 354 const char *pname1 = name1.c_str(); 355 o << "node [name="; 356 o.width (35); 357 o << simplify_name(pname1,s); 358 o << "];\n"; 359 } 360 for (int i = 0; i < g.n; ++i) 361 { // Printing edge list 362 Vertex *v1 = g.vertices + i; 363 method_process_t *mp1 = (method_process_t*) (v1->data); 364 get_method_process_fullname (name1,*mp1); 365 const char *pname1 = name1.c_str(); 366 for (Arc *a = v1->arcs; a != NULL; a = a->next) 367 { 368 Vertex *v2 = a->tip; 369 method_process_t *mp2 = (method_process_t*) (v2->data); 370 get_method_process_fullname (name2,*mp2); 371 const char *pname2 = name2.c_str(); 372 o.width (35); 373 o << simplify_name(pname2,s); 374 o << " -> "; 375 o.width (35); 376 o << simplify_name(pname1,s); 377 o << ";\n"; 378 } 379 } 380 381 return true; 382 } 383 384 extern bool 385 graph2dot (const char *name, 386 const Graph &g) 387 { 388 if (!name) 389 return false; 390 string filename; 391 filename = name; 392 filename += ".dot"; 393 ofstream o; 394 o.open (filename.c_str(),ios::out | ios::trunc); 395 if (o.is_open () == false) 396 return false; 397 o << "// Module dependency graph\n" 398 "// Generated by " 399 << sc_version () << "\n"; 400 o << "strict digraph " << name << " {\n"; 401 o << "node [shape=box];\n"; 402 // "concentrate=true;\n"; 403 o << left; 404 dot_write (o,g); 405 // Closing dot file 406 o << "}\n"; 407 o.close (); 408 if (dump_stage) 409 cerr << "Module dependency graph written into '" 410 << filename << "'.\n"; 411 return true; 412 } 413 414 } // end of sc_core namespace 415 315 -
sources/src/graph_cass.h
r1 r52 20 20 21 21 /* A unique exported function from all that */ 22 extern Graph * makegraph(const method_process_list_t *);23 extern bool graph2dot(const char*,const Graph&);22 extern Graph * makegraph(const method_process_list_t *); 23 extern bool graph2dot(const char *, const Graph&); 24 24 25 25 } // end of sc_core namespace -
sources/src/graph_signals.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : graph_signals.cc |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : 22_09_2004 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : graph_signals.cc | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 22_09_2004 | 10 | | 11 \------------------------------------------------------------*/ 12 12 13 13 /* … … 138 138 #include "sc_module.h" 139 139 #include "sc_port.h" 140 140 141 #ifdef HAVE_CONFIG_H 141 142 #include "config.h" … … 146 147 namespace sc_core { 147 148 148 #if 0 149 static 150 ostream& operator << (ostream& o, 151 const Vertex &v) 152 { 153 equi_t* m = (equi_t*)(v.data); 154 if (v.arcs == NULL) 155 o << get_name(*m) << "\n"; 156 Arc *a; 157 for (a = v.arcs; a; a = a->next) 158 { 159 equi_t* m2 = (equi_t*)(a->tip->data); 160 o << get_name(*m) << "->" 161 << get_name(*m2) << "\n"; 162 } 163 return o; 164 165 } 166 167 static 168 ostream& 169 operator << (ostream &o, 170 const Graph &g) 171 { 172 Vertex *v; 173 int i = 1; 174 for (v = g.vertices; v < g.vertices + g.n; ++v) { 175 o << i++ << " : " << *v; 176 } 177 return o; 178 } 179 #endif 180 181 typedef std::map<const equi_t*, Vertex*> nodes_set_t; 182 183 void 184 create_arcs (const SignalDependencyGraph& sig_g, nodes_set_t& s) 185 { 186 SignalDependencyGraph::const_iterator j; 187 for (j = sig_g.begin(); j != sig_g.end(); ++j) { 188 new_arc (s[j->source],s[j->destination]); 189 } 190 } 191 192 void 193 create_vertices_list (Graph *g, nodes_set_t& s) 194 { 195 Vertex *v = g->vertices; 196 if (v == NULL) 197 return; 198 nodes_set_t::iterator j; 199 for (j = s.begin(); j != s.end(); ++j) 200 { 201 v->data = (void*) (j->first); 202 j->second = v++; 203 } 204 } 205 206 nodes_set_t* 207 create_nodes_set (const SignalDependencyGraph& sig_g) 208 { 209 /* Create a signal set */ 210 nodes_set_t &s = *(new nodes_set_t); 211 212 SignalDependencyGraph::const_iterator j; 213 for (j = sig_g.begin(); j != sig_g.end(); ++j) 214 { 215 s[j->source] = NULL; 216 s[j->destination] = NULL; 217 } 218 return &s; 219 } 149 150 typedef std::map < const equi_t *, Vertex * >nodes_set_t; 151 152 void create_arcs(const SignalDependencyGraph & sig_g, nodes_set_t & s) { 153 SignalDependencyGraph::const_iterator j; 154 for (j = sig_g.begin(); j != sig_g.end(); ++j) { 155 new_arc(s[j->source], s[j->destination]); 156 } 157 } 158 159 160 void create_vertices_list(Graph * g, nodes_set_t & s) { 161 Vertex * v = g->vertices; 162 if (v == NULL) { 163 return; 164 } 165 nodes_set_t::iterator j; 166 for (j = s.begin(); j != s.end(); ++j) { 167 v->data = (void *) (j->first); 168 j->second = v++; 169 } 170 } 171 172 173 nodes_set_t * create_nodes_set(const SignalDependencyGraph & sig_g) { 174 /* Create a signal set */ 175 nodes_set_t & s = *(new nodes_set_t); 176 177 SignalDependencyGraph::const_iterator j; 178 for (j = sig_g.begin(); j != sig_g.end(); ++j) { 179 s[j->source] = NULL; 180 s[j->destination] = NULL; 181 } 182 return &s; 183 } 184 220 185 221 186 /* Construit le graph de dépendance des signaux de Mealy */ 222 187 /* g = Mealy signal dependancy graph */ 223 Graph *makegraph(const SignalDependencyGraph& sig_g) 224 { 225 int n = 0; /* Number of vertices */ 226 Graph *g; 227 //Vertex *v; 228 229 /* Create node set */ 230 nodes_set_t *sig_s = create_nodes_set (sig_g); 231 232 /* Compute the number of vertices in the graph */ 233 n = sig_s->size(); 234 235 /* Create the graph */ 236 g = gb_new_graph(n); 237 238 /* Associate the netlist elements to the graph vertices, and vice-versa */ 239 // v = g->vertices; 240 241 /* Create the node set */ 242 create_vertices_list (g,*sig_s); 243 244 /* initialisation des vertices */ 245 create_arcs (sig_g,*sig_s); 246 247 delete sig_s; 248 #if 0 249 cerr << *g << "\n"; 250 #endif 251 return g; 252 } 188 Graph * makegraph(const SignalDependencyGraph & sig_g) { 189 int n = 0; /* Number of vertices */ 190 Graph * g; 191 192 /* Create node set */ 193 nodes_set_t * sig_s = create_nodes_set(sig_g); 194 195 /* Compute the number of vertices in the graph */ 196 n = sig_s->size(); 197 198 /* Create the graph */ 199 g = gb_new_graph(n); 200 201 /* Create the node set */ 202 create_vertices_list(g, *sig_s); 203 204 /* initialisation des vertices */ 205 create_arcs(sig_g, *sig_s); 206 207 delete sig_s; 208 209 return g; 210 } 253 211 254 212 } // end of sc_core namespace 255 213 214 /* 215 # Local Variables: 216 # tab-width: 4; 217 # c-basic-offset: 4; 218 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 219 # indent-tabs-mode: nil; 220 # End: 221 # 222 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 223 */ 224 225 -
sources/src/graph_signals.h
r1 r52 19 19 namespace sc_core { 20 20 21 extern Graph * makegraph(const SignalDependencyGraph&);21 extern Graph * makegraph(const SignalDependencyGraph&); 22 22 23 23 } // end of sc_core namespace -
sources/src/hex2string.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : hex2string.cc |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : 09_07_2004 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : hex2string.cc | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 09_07_2004 | 10 | | 11 \------------------------------------------------------------*/ 12 12 13 13 /* … … 36 36 #include "hex2string.h" 37 37 38 //#include <string>39 38 #include <stdarg.h> 40 39 #include <cstdio> 41 40 #include <cstdlib> 42 41 #include <iostream> 42 43 43 #ifdef HAVE_CONFIG_H 44 44 #include "config.h" 45 45 #endif 46 46 47 47 using namespace std; 48 48 49 49 namespace sc_core { 50 50 51 void 52 hex2string(char *buf, 53 const tab_t *val, 54 int bit_number) 55 { 56 int tmp=*((const int*)val); 57 //cout << "tmp = " << tmp << "\n"; 58 buf[bit_number >> 2]='\0'; 59 for (int i = (bit_number >> 2) - 1; i >= 0 ;i--) 60 { 61 char value = tmp & 0x0F; 62 buf[i]=(value > 9)?('A' + value - 10):('0'+value); 63 tmp=tmp>>4; 64 } 65 #if 0 66 sscanf (buf, "%X", &tmp); 67 if (atoi (buf) != *val) 68 cerr << "hex2string (0x" << hex << *val << ") returns 0x" << buf << " KO !\n"; 69 #endif 51 void hex2string(char * buf, const tab_t * val, int bit_number) { 52 int tmp = *((const int *) val); 53 buf[bit_number >> 2]='\0'; 54 for (int i = (bit_number >> 2) - 1; i >= 0 ;i--) { 55 char value = tmp & 0x0F; 56 buf[i] = (value > 9) ? ('A' + value - 10) : ('0'+value); 57 tmp = tmp >> 4; 58 } 70 59 } 71 60 72 61 } // end of sc_core namespace 73 62 63 /* 64 # Local Variables: 65 # tab-width: 4; 66 # c-basic-offset: 4; 67 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 68 # indent-tabs-mode: nil; 69 # End: 70 # 71 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 72 */ 73 -
sources/src/hex2string.h
r1 r52 17 17 namespace sc_core { 18 18 19 extern void hex2string(char * buf,const tab_t *val,int bit_number);19 extern void hex2string(char * buf,const tab_t * val,int bit_number); 20 20 21 21 } // end of sc_core namespace 22 22 23 23 #endif 24 -
sources/src/internal.h
r38 r52 21 21 22 22 // Method Process List 23 extern method_process_t * method;23 extern method_process_t * method; 24 24 extern method_process_list_t method_process_list; 25 25 … … 29 29 30 30 // Hash Table Port -> Module 31 typedef std::map</*const */sc_port_base *, const sc_module*> port2module_t;31 typedef std::map</*const */sc_port_base *, const sc_module *> port2module_t; 32 32 extern port2module_t port2module; 33 33 34 34 // Functions for Elaboration step 35 void sort_equi_list 36 void create_signals_table 37 void bind_to_table 35 void sort_equi_list(); 36 void create_signals_table(); 37 void bind_to_table(); 38 38 39 39 // Debug Functions 40 void print_table 41 void print_table_stats 42 void print_registers_writing_stats 40 void print_table(std::ostream&); 41 void print_table_stats(std::ostream&); 42 void print_registers_writing_stats(std::ostream&); 43 43 44 extern bool is_clock(const sc_interface &inter);44 extern bool is_clock(const sc_interface &inter); 45 45 46 46 // Flags 47 extern bool 48 extern bool 49 extern const char * dump_module_hierarchy;50 extern bool 51 extern bool 52 extern bool 53 extern bool 54 extern bool 55 extern bool 56 extern bool 57 extern char *save_on_exit;58 extern int 59 extern bool 60 extern bool 47 extern bool check_port_dependencies; 48 extern bool dump_all_graph; 49 extern const char * dump_module_hierarchy; 50 extern bool dump_netlist_info; 51 extern bool dump_funclist_info; 52 extern bool dynamic_link_of_scheduling_code; 53 extern bool keep_generated_code; 54 extern bool nosimulation; 55 extern bool notrace; 56 extern bool print_user_resources; 57 extern char * save_on_exit; 58 extern int scheduling_method; 59 extern bool use_port_dependency; 60 extern bool use_openmp; 61 61 62 #define NO_SCHEDULING 63 #define BUCHMANN_SCHEDULING 64 #define MOUCHARD_SCHEDULING 65 #define CASS_SCHEDULING 62 #define NO_SCHEDULING 0 63 #define BUCHMANN_SCHEDULING 1 64 #define MOUCHARD_SCHEDULING 2 65 #define CASS_SCHEDULING 4 66 66 67 67 // More 68 68 69 extern uint64 trace_start; 70 69 71 } 70 72 -
sources/src/internal_ext.h
r37 r52 38 38 39 39 #include <list> 40 40 41 #include "sc_fwd.h" 41 42 #include "sc_nbdefs.h" 42 //#include "casc.h"43 43 44 44 /* … … 68 68 // Granularity of the posted write stack 69 69 #ifdef UINT64 70 typedef uint64tab_t;70 typedef uint64 tab_t; 71 71 #else 72 typedef uint32tab_t;73 // 72 typedef uint32 tab_t; 73 // typedef smallest_uint tab_t; // signals of 64 bits are wrong in trace file 74 74 #endif 75 typedef tab_t *equi_table_t;76 extern equi_table_t 75 typedef tab_t * equi_table_t; 76 extern equi_table_t equi_table; 77 77 78 78 // Flags 79 extern bool 80 extern bool 81 extern bool 79 extern bool dump_stage; 80 extern bool print_schedule; 81 extern bool edit_schedule; 82 82 83 83 } -
sources/src/methodprocess_dependency.cc
r27 r52 35 35 36 36 #include <cassert> 37 #include <iostream> 38 #include <fstream> 39 37 40 #include "methodprocess_dependency.h" 38 41 #include "simplify_string.h" 39 42 #include "sc_module.h" 40 #include <iostream> 41 #include <fstream> 43 42 44 #ifdef HAVE_CONFIG_H 43 45 #include "config.h" … … 47 49 namespace sc_core { 48 50 49 string 50 get_name (const method_process_t *method) 51 { 52 assert(method != NULL); 53 const sc_module *module = method->module; 54 assert(module != NULL); 55 const char *module_name = module->name (); 56 const char *function_name = method->name; 57 58 string name = module_name; 59 name += "_"; 60 name += function_name; 61 return name; 51 string get_name(const method_process_t * method) { 52 assert(method != NULL); 53 const sc_module *module = method->module; 54 assert(module != NULL); 55 const char * module_name = module->name(); 56 const char * function_name = method->name; 57 58 string name = module_name; 59 name += "_"; 60 name += function_name; 61 return name; 62 62 } 63 63 64 static65 bool66 dot_write (ofstream &o,67 const SignalDependencyGraph &sig)68 {69 // Preparing data70 typedef map<const equi_t *, const method_process_t *> table_t;71 table_t table;72 73 // For each arrow, add destination node into table74 SignalDependencyGraph::const_iterator sig_it;75 for (sig_it = sig.begin (); sig_it != sig.end (); ++sig_it)76 {77 const SignalDependency &sd = *sig_it;78 const equi_t *equi = sd.destination;79 const method_process_t *method = sd.method;80 table[equi] = method;81 }82 64 83 // Printing into dot file 84 string s; 85 SignalDependencyGraph::const_iterator it; 86 for (it = sig.begin (); it != sig.end (); ++it) 87 { 88 const SignalDependency &sd = *it; 89 const equi_t *source_equi = sd.source; 90 assert(source_equi != NULL); 91 const method_process_t *source_method = table[source_equi]; 92 if (source_method == NULL) 93 continue; 94 string source_method_name = get_name (source_method); 95 string source_equi_name = get_name (*source_equi); 96 const method_process_t *destination_method = sd.method; 97 string destination_method_name = get_name (destination_method); 98 o << "edge [label=" 99 << simplify_name(source_equi_name.c_str(),s) 100 << "];\n"; 101 o << simplify_name(source_method_name.c_str(),s); 102 o << " -> "; 103 o << simplify_name(destination_method_name.c_str(),s); 104 o << ";\n"; 105 } 65 static bool dot_write(ofstream & o, const SignalDependencyGraph & sig) { 66 // Preparing data 67 typedef map < const equi_t *, const method_process_t *>table_t; 68 table_t table; 69 70 // For each arrow, add destination node into table 71 SignalDependencyGraph::const_iterator sig_it; 72 for (sig_it = sig.begin(); sig_it != sig.end(); ++sig_it) { 73 const SignalDependency & sd = *sig_it; 74 const equi_t * equi = sd.destination; 75 const method_process_t * method = sd.method; 76 table[equi] = method; 77 } 78 79 // Printing into dot file 80 string s; 81 SignalDependencyGraph::const_iterator it; 82 for (it = sig.begin(); it != sig.end(); ++it) { 83 const SignalDependency & sd = *it; 84 const equi_t * source_equi = sd.source; 85 assert(source_equi != NULL); 86 const method_process_t * source_method = table[source_equi]; 87 if (source_method == NULL) { 88 continue; 89 } 90 string source_method_name = get_name(source_method); 91 string source_equi_name = get_name(*source_equi); 92 const method_process_t *destination_method = sd.method; 93 string destination_method_name = get_name(destination_method); 94 o << "edge [label=" << simplify_name(source_equi_name.c_str(), s) << "];\n"; 95 o << simplify_name(source_method_name.c_str(), s); 96 o << " -> "; 97 o << simplify_name(destination_method_name.c_str(), s); 98 o << ";\n"; 99 } 106 100 } 107 101 108 bool 109 MethodProcessDependencyGraph2dot (const char *name, 110 const SignalDependencyGraph& sig)111 { 112 if (!name) 113 return false;114 string filename;115 filename = name;116 filename += ".dot";117 ofstream o;118 o.open (filename.c_str(),ios::out | ios::trunc);119 if (o.is_open () == false) 120 return false; 121 122 dot_write (o,sig);123 // Closing dot file124 125 o.close();126 if (dump_stage)127 cerr << "MethodProcess dependency graph written into '"128 << filename << "'.\n";129 102 103 bool MethodProcessDependencyGraph2dot(const char * name, const SignalDependencyGraph & sig) { 104 if (!name) { 105 return false; 106 } 107 string filename; 108 filename = name; 109 filename += ".dot"; 110 ofstream o; 111 o.open(filename.c_str(), ios::out | ios::trunc); 112 if (o.is_open() == false) { 113 return false; 114 } 115 o << "strict digraph " << name << " {\n"; 116 dot_write(o, sig); 117 // Closing dot file 118 o << "}\n"; 119 o.close(); 120 if (dump_stage) { 121 cerr << "MethodProcess dependency graph written into '" << filename << "'.\n"; 122 } 123 return true; 130 124 } 131 125 132 126 } // end of sc_core namespace 133 127 128 /* 129 # Local Variables: 130 # tab-width: 4; 131 # c-basic-offset: 4; 132 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 133 # indent-tabs-mode: nil; 134 # End: 135 # 136 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 137 */ -
sources/src/methodprocess_dependency.h
r1 r52 16 16 17 17 namespace sc_core { 18 18 19 // Dump to dot file 19 20 extern bool MethodProcessDependencyGraph2dot (const char *name, const SignalDependencyGraph&); 21 20 22 } 21 23 -
sources/src/module_hierarchy.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : module_hierarchy.cc |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : 15_12_2005 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : module_hierarchy.cc | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 15_12_2005 | 10 | | 11 \------------------------------------------------------------*/ 12 12 13 13 /* … … 34 34 */ 35 35 36 #include "module_hierarchy.h"37 #include "sc_module.h"38 36 #include <cassert> 39 37 #include <map> 38 #include <cstdlib> 39 #include <cstring> 40 41 #include "sc_module.h" 42 #include "module_hierarchy.h" 43 40 44 #ifdef HAVE_CONFIG_H 41 45 #include "config.h" 42 46 #endif 43 #include <cstdlib> 44 #include <cstring> 47 45 48 46 49 using namespace std; … … 48 51 namespace sc_core { 49 52 50 typedef vector<sc_object *> sc_object_list_t;51 typedef map<const sc_object *,sc_object_list_t> sc_object2sc_object_list_t;52 typedef map<const sc_object*, sc_object *>sc_object2sc_object_t;53 typedef vector<sc_object *> sc_object_list_t; 54 typedef map<const sc_object *, sc_object_list_t> sc_object2sc_object_list_t; 55 typedef map<const sc_object*, sc_object *> sc_object2sc_object_t; 53 56 54 sc_object_list_t 55 sc_object2sc_object_list_t 56 sc_object2sc_object_t 57 sc_object_list_t top_level_objects; 58 sc_object2sc_object_list_t object2childs; 59 sc_object2sc_object_t object2parent; 57 60 58 void 59 set_parent (sc_module &mod, sc_module *parent) 60 { 61 object2parent[&mod] = parent; 62 sc_object_list_t &obj_list = (parent == NULL)?top_level_objects:object2childs[parent]; 63 obj_list.push_back (&mod); 61 62 void set_parent (sc_module &mod, sc_module * parent) { 63 object2parent[&mod] = parent; 64 sc_object_list_t &obj_list = (parent == NULL) ? top_level_objects : object2childs[parent]; 65 obj_list.push_back (&mod); 64 66 } 65 67 66 void 67 add_child (sc_object &obj) 68 { 69 sc_object_list_t *obj_list; 70 if (modules_stack.empty ()) 71 { 72 obj_list = &top_level_objects; 73 } else { 74 const sc_module *parent = modules_stack.top (); 75 if (parent == NULL) 76 return; //obj_list = &top_level_objects; 68 69 void add_child (sc_object &obj) { 70 sc_object_list_t * obj_list; 71 if (modules_stack.empty ()) { 72 obj_list = &top_level_objects; 73 } 77 74 else { 78 assert(parent != &obj); 79 const sc_object *pobj = (const sc_module *) parent; 80 obj_list = &(object2childs[pobj]); 75 const sc_module * parent = modules_stack.top (); 76 if (parent == NULL) { 77 return; //obj_list = &top_level_objects; 78 } 79 else { 80 assert(parent != &obj); 81 const sc_object * pobj = (const sc_module *) parent; 82 obj_list = &(object2childs[pobj]); 83 } 81 84 } 82 } 83 obj_list->push_back (&obj); 85 obj_list->push_back (&obj); 84 86 } 85 87 86 const std::vector<sc_object*>& 87 sc_get_top_level_objects() 88 { 89 return top_level_objects; 88 89 const std::vector<sc_object *>& sc_get_top_level_objects() { 90 return top_level_objects; 90 91 } 91 92 92 const sc_object* 93 sc_find_object (const char* name) 94 { 95 sc_object2sc_object_list_t::iterator i = object2childs.begin (); 96 while (i != object2childs.end ()) 97 { 98 const sc_object *obj = i->first; 99 const char *n = obj->name (); 100 if (strcmp (name, n) == 0) 101 return obj; 102 ++i; 103 } 104 return NULL; 105 } 106 107 const std::vector<sc_object*>& 108 get_child_objects (const sc_object &obj) 109 { 110 sc_object_list_t &l = object2childs[&obj]; 111 /* 112 * If the object is not in the objects list, 113 * get_child_objects returns an empty list. 114 */ 115 return l; 93 94 const sc_object * sc_find_object(const char * name) { 95 sc_object2sc_object_list_t::iterator i = object2childs.begin (); 96 while (i != object2childs.end()) { 97 const sc_object * obj = i->first; 98 const char * n = obj->name (); 99 if (strcmp (name, n) == 0) { 100 return obj; 101 } 102 ++i; 103 } 104 return NULL; 116 105 } 117 106 118 sc_object* 119 get_parent_object (const sc_object &obj) 120 { 121 return object2parent[&obj]; 107 108 const std::vector<sc_object *>& get_child_objects(const sc_object &obj) { 109 sc_object_list_t &l = object2childs[&obj]; 110 /* 111 * If the object is not in the objects list, 112 * get_child_objects returns an empty list. 113 */ 114 return l; 115 } 116 117 118 sc_object * get_parent_object(const sc_object &obj) { 119 return object2parent[&obj]; 122 120 } 123 121 … … 125 123 126 124 125 /* 126 # Local Variables: 127 # tab-width: 4; 128 # c-basic-offset: 4; 129 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 130 # indent-tabs-mode: nil; 131 # End: 132 # 133 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 134 */ 135 -
sources/src/module_hierarchy_ext.h
r1 r52 39 39 #include "sc_module_ext.h" 40 40 #include "sc_object.h" 41 41 42 #include <vector> 42 43 43 44 namespace sc_core { 44 45 45 extern const std::vector<sc_object *>&sc_get_top_level_objects();46 extern const sc_object * sc_find_object (const char* name);46 extern const std::vector<sc_object *>& sc_get_top_level_objects(); 47 extern const sc_object * sc_find_object(const char * name); 47 48 48 49 } // end of namespace sc_core -
sources/src/mouchard_scheduling.cc
r27 r52 37 37 #include <iostream> 38 38 #include <fstream> 39 39 40 #include "assert.h" 40 41 #include "process_dependency.h" … … 45 46 #include "sc_module.h" 46 47 #include "sc_ver.h" 48 47 49 #ifdef HAVE_CONFIG_H 48 50 #include "config.h" … … 54 56 55 57 typedef set<SignalDependency> signalDependencySet; 56 typedef set<const method_process_t *> processSet;58 typedef set<const method_process_t *> processSet; 57 59 58 static 59 void 60 getSource (signalDependencySet &ss, 61 const SignalDependencyGraph &sig_g) 62 { 63 typedef set<const equi_t *> nonSource_t; 64 nonSource_t nonSource; 65 SignalDependencyGraph::iterator it; 66 for (it = sig_g.begin(); it != sig_g.end(); ++it) 67 { 68 const SignalDependency &sigDep = *it; 69 const equi_t *dest = sigDep.destination; 70 nonSource.insert(dest); 71 } 72 for (it = sig_g.begin(); it != sig_g.end(); ++it) 73 { 74 const SignalDependency &sigDep = *it; 75 const equi_t *src = sigDep.source; 76 if (nonSource.find(src) == nonSource.end()) 77 ss.insert(sigDep); 78 } 60 static void getSource(signalDependencySet &ss, const SignalDependencyGraph &sig_g) { 61 typedef set<const equi_t *> nonSource_t; 62 nonSource_t nonSource; 63 SignalDependencyGraph::iterator it; 64 for (it = sig_g.begin(); it != sig_g.end(); ++it) { 65 const SignalDependency &sigDep = *it; 66 const equi_t * dest = sigDep.destination; 67 nonSource.insert(dest); 68 } 69 70 for (it = sig_g.begin(); it != sig_g.end(); ++it) { 71 const SignalDependency &sigDep = *it; 72 const equi_t * src = sigDep.source; 73 if (nonSource.find(src) == nonSource.end()) { 74 ss.insert(sigDep); 75 } 76 } 79 77 } 80 78 81 static 82 void 83 removeSignals (SignalDependencyGraph &sig_g, 84 signalDependencySet &ss) 85 { 86 SignalDependencyGraph::iterator it = sig_g.begin(); 87 while (it != sig_g.end()) 88 { 89 const SignalDependency &sigDep = *it; 90 if (ss.find(sigDep) != ss.end()) 91 { 92 SignalDependencyGraph::iterator jt = it++; 93 sig_g.erase (jt); 94 } else 95 ++it; 96 } 79 80 static void removeSignals(SignalDependencyGraph &sig_g, signalDependencySet &ss) { 81 SignalDependencyGraph::iterator it = sig_g.begin(); 82 while (it != sig_g.end()) { 83 const SignalDependency &sigDep = *it; 84 if (ss.find(sigDep) != ss.end()) { 85 SignalDependencyGraph::iterator jt = it++; 86 sig_g.erase(jt); 87 } 88 else { 89 ++it; 90 } 91 } 97 92 } 98 93 99 ProcessDependencyList* 100 MakeMouchardScheduling (const SignalDependencyGraph & _sig_g) 101 { 102 if (dump_stage) 103 cerr << "Making process dependency list...\n"; 104 ProcessDependencyList *mod_l = new ProcessDependencyList (); 105 SignalDependencyGraph sig_g = _sig_g; 106 while (!sig_g.empty ()) 107 { 108 signalDependencySet ss; 109 getSource (ss, sig_g); 110 removeSignals (sig_g, ss); 111 processSet ps; 112 signalDependencySet::iterator sit; 113 for (sit = ss.begin(); sit != ss.end(); ++sit) 114 { 115 const SignalDependency &sigdep = *sit; 116 const method_process_t *process = sigdep.method; 117 ps.insert(process); 94 95 ProcessDependencyList * MakeMouchardScheduling(const SignalDependencyGraph & _sig_g) { 96 if (dump_stage) { 97 cerr << "Making process dependency list...\n"; 118 98 } 119 processSet::iterator pit; 120 for (pit = ps.begin(); pit != ps.end(); ++pit) 121 { 122 const method_process_t *process = *pit; 123 mod_l->push_back(process); 124 #if 1 125 cerr << "Process found : " << *process << "\n"; 126 #endif 99 ProcessDependencyList * mod_l = new ProcessDependencyList (); 100 SignalDependencyGraph sig_g = _sig_g; 101 while (!sig_g.empty ()) { 102 signalDependencySet ss; 103 getSource(ss, sig_g); 104 removeSignals(sig_g, ss); 105 processSet ps; 106 signalDependencySet::iterator sit; 107 for (sit = ss.begin(); sit != ss.end(); ++sit) { 108 const SignalDependency & sigdep = *sit; 109 const method_process_t * process = sigdep.method; 110 ps.insert(process); 111 } 112 processSet::iterator pit; 113 for (pit = ps.begin(); pit != ps.end(); ++pit) { 114 const method_process_t * process = *pit; 115 mod_l->push_back(process); 116 if (dump_stage) { 117 cerr << "Process found : " << *process << "\n"; 118 } 119 } 127 120 } 128 } 129 130 return mod_l; 121 122 return mod_l; 131 123 } 132 124 133 125 } // end of sc_core namespace 134 126 127 /* 128 # Local Variables: 129 # tab-width: 4; 130 # c-basic-offset: 4; 131 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 132 # indent-tabs-mode: nil; 133 # End: 134 # 135 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 136 */ 137 -
sources/src/mouchard_scheduling.h
r1 r52 17 17 namespace sc_core { 18 18 19 ProcessDependencyList * MakeMouchardScheduling(const SignalDependencyGraph &);19 ProcessDependencyList * MakeMouchardScheduling(const SignalDependencyGraph &); 20 20 21 21 } // end of sc_core namespace -
sources/src/port_dependency.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : port_dependency.cc |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : 21_09_2004 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : port_dependency.cc | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 21_09_2004 | 10 | | 11 \------------------------------------------------------------*/ 12 12 13 13 /* … … 38 38 #include <iostream> 39 39 #include <fstream> 40 40 41 #include "port_dependency.h" 41 42 #include "simplify_string.h" … … 45 46 #include "sc_port.h" 46 47 #include "sc_ver_ext.h" 48 47 49 #ifdef HAVE_CONFIG_H 48 50 #include "config.h" … … 55 57 static PortDependencyGraph aPortDependencyGraph; 56 58 57 const PortDependencyGraph& 58 get_port_dependency_graph () 59 { 60 return aPortDependencyGraph; 59 const PortDependencyGraph & get_port_dependency_graph() { 60 return aPortDependencyGraph; 61 61 } 62 62 63 static 64 void 65 check_port_dependency_declaration (const sc_port_base* a, 66 const sc_port_base& b) 67 { 68 const sc_module &moduleA = a->get_module (); 69 const sc_module &moduleB = b.get_module (); 70 if (check_port_dependencies && (&moduleA != &moduleB)) 71 { 72 const char *module_nameA = moduleA.basename (); 73 const char *module_nameB = moduleB.basename (); 74 if (strlen (module_nameA) == 0) 75 module_nameA = "<top level>"; 76 cerr << "Error : Port dependency declaration in '" 77 << module_name_stack.back () << "' constructor is wrong.\n" 78 << "'" << a->name () << "' and '" << b.name () 79 << "' are ports of two differents modules (" 80 << module_nameA << " and " 81 << module_nameB << "). " 82 << "You can't declare any port dependency like that.\n"; 83 exit (37); //15092005); 84 } 85 if (module_name_stack.empty ()) 86 { 87 cerr << "Error : Port dependency declaration is wrong.\n" 88 << "The dependency declaration of '" 89 << a->name () << "' and '" << b.name () 90 << "' is not in any sc_module constructor.\n"; 91 exit (16092005); 92 } 93 if (method_process_list.empty ()) 94 { 95 cerr << "Error : Port dependency declaration in '" 96 << module_name_stack.back () << "' constructor is wrong.\n" 97 << "The dependency of '" << a->name () << "' and '" << b.name () 98 << "' should be linked to a SC_METHOD.\n"; 99 exit(165); //17092005); 100 } 63 64 static void check_port_dependency_declaration(const sc_port_base * a, const sc_port_base& b) { 65 const sc_module & moduleA = a->get_module(); 66 const sc_module & moduleB = b.get_module(); 67 if (check_port_dependencies && (&moduleA != &moduleB)) { 68 const char * module_nameA = moduleA.basename(); 69 const char * module_nameB = moduleB.basename(); 70 if (strlen(module_nameA) == 0) { 71 module_nameA = "<top level>"; 72 } 73 cerr << "Error : Port dependency declaration in '" 74 << module_name_stack.back () << "' constructor is wrong.\n" 75 << "'" << a->name () << "' and '" << b.name () 76 << "' are ports of two differents modules (" 77 << module_nameA << " and " 78 << module_nameB << "). " 79 << "You can't declare any port dependency like that.\n"; 80 exit (37); //15092005); 81 } 82 if (module_name_stack.empty()) { 83 cerr << "Error : Port dependency declaration is wrong.\n" 84 << "The dependency declaration of '" 85 << a->name () << "' and '" << b.name () 86 << "' is not in any sc_module constructor.\n"; 87 exit (16092005); 88 } 89 if (method_process_list.empty()) { 90 cerr << "Error : Port dependency declaration in '" 91 << module_name_stack.back () << "' constructor is wrong.\n" 92 << "The dependency of '" << a->name () << "' and '" << b.name () 93 << "' should be linked to a SC_METHOD.\n"; 94 exit(165); //17092005); 95 } 101 96 } 102 97 103 void 104 set_port_dependency (const sc_port_base* a, 105 const sc_port_base& b) 106 { 107 check_port_dependency_declaration (a,b); 108 PortDependency p; 109 p.method = method_process_list.back(); 110 p.source = a; 111 p.destination = &b; 112 aPortDependencyGraph.push_back (p); 98 99 void set_port_dependency(const sc_port_base * a, const sc_port_base & b) { 100 check_port_dependency_declaration(a,b); 101 PortDependency p; 102 p.method = method_process_list.back(); 103 p.source = a; 104 p.destination = &b; 105 aPortDependencyGraph.push_back(p); 113 106 #ifdef DUMP_PORT_DEPENDENCY 114 if (a) { 115 cerr << "'" << ((sc_object&)b).name() 116 << "' depends on '" 117 << ((sc_object*)a)->name () 118 << "' in '" << p.method->name << "' function.\n"; 119 } else 120 cerr << "'" << ((sc_object&)b).name() 121 << "' doesn't depend on anything" 122 << " in '" << p.method->name << "' function.\n"; 107 if (a) { 108 cerr << "'" << ((sc_object&)b).name() 109 << "' depends on '" 110 << ((sc_object*)a)->name() 111 << "' in '" << p.method->name << "' function.\n"; 112 } 113 else { 114 cerr << "'" << ((sc_object&)b).name() 115 << "' doesn't depend on anything" 116 << " in '" << p.method->name << "' function.\n"; 117 } 123 118 #endif 124 119 } 125 120 126 static 127 void 128 dot_write (ofstream &o, const PortDependencyGraph &g) 129 { 130 string s; 131 PortDependencyGraph::const_iterator it; 132 for (it = g.begin (); it != g.end (); ++it) 133 { 134 if (it->source == NULL) 135 continue; 136 const char *name; 137 name = ((sc_object*)it->source)->name(); 138 o << simplify_name(name,s); 139 o << " -> "; 140 name = ((sc_object*)it->destination)->name(); 141 o << simplify_name(name,s); 142 o << "\n"; 143 } 121 122 static void dot_write (ofstream & o, const PortDependencyGraph & g) { 123 string s; 124 PortDependencyGraph::const_iterator it; 125 for (it = g.begin (); it != g.end (); ++it) { 126 if (it->source == NULL) { 127 continue; 128 } 129 const char * name; 130 name = ((sc_object *)it->source)->name(); 131 o << simplify_name(name,s); 132 o << " -> "; 133 name = ((sc_object *)it->destination)->name(); 134 o << simplify_name(name,s); 135 o << "\n"; 136 } 144 137 } 145 138 146 bool 147 PortDependencyGraph2dot (const char *name, 148 const PortDependencyGraph& g)149 { 150 if (!name) 151 return false;152 string filename;153 filename = name;154 filename += ".dot";155 ofstream o;156 o.open (filename.c_str(),ios::out | ios::trunc);157 if (o.is_open () == false) 158 return false; 159 160 "// Generated by "161 << sc_version () << "\n";162 163 164 165 166 if (dump_stage)167 cerr << "Port Dependency Graph written into '"168 << filename << "'.\n";169 139 140 bool PortDependencyGraph2dot (const char * name, const PortDependencyGraph & g) { 141 if (!name) { 142 return false; 143 } 144 string filename; 145 filename = name; 146 filename += ".dot"; 147 ofstream o; 148 o.open(filename.c_str(),ios::out | ios::trunc); 149 if (o.is_open () == false) { 150 return false; 151 } 152 o << "// Port dependency graph\n" 153 "// Generated by " 154 << sc_version () << "\n"; 155 o << "strict digraph " << name << " {\n"; 156 dot_write (o,g); 157 o << "}\n"; 158 o.close (); 159 if (dump_stage) { 160 cerr << "Port Dependency Graph written into '" << filename << "'.\n"; 161 } 162 return true; 170 163 } 171 164 172 165 } // end of sc_core namespace 173 166 167 /* 168 # Local Variables: 169 # tab-width: 4; 170 # c-basic-offset: 4; 171 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 172 # indent-tabs-mode: nil; 173 # End: 174 # 175 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 176 */ 177 -
sources/src/port_dependency.h
r35 r52 22 22 // Port Dependency Graph 23 23 struct PortDependency { 24 const method_process_t * method;25 const sc_port_base *source;26 const sc_port_base *destination;24 const method_process_t * method; 25 const sc_port_base * source; 26 const sc_port_base * destination; 27 27 }; 28 28 29 typedef std::list<PortDependency> PortDependencyGraph; 29 30 … … 32 33 33 34 // Dump to dot file 34 extern bool PortDependencyGraph2dot (const char *name, const PortDependencyGraph& = get_port_dependency_graph());35 extern bool PortDependencyGraph2dot(const char * name, const PortDependencyGraph& = get_port_dependency_graph()); 35 36 36 37 } // end of sc_core namespace -
sources/src/port_dependency_ext.h
r1 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : port_dependancy_ext.h |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : 12_08_2004 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : port_dependancy_ext.h | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 12_08_2004 | 10 | | 11 \------------------------------------------------------------*/ 12 12 13 13 /* … … 40 40 41 41 // Declare dependancy 42 extern void set_port_dependency (const sc_port_base* source,const sc_port_base& destination);42 extern void set_port_dependency(const sc_port_base * source, const sc_port_base & destination); 43 43 44 44 template<typename T, size_t N1, size_t N2> 45 inline 46 void 47 set_port_dependency (sc_in<T> (&source)[N1], 48 sc_out<T> (&destination)[N2]) 49 { 50 int i; 51 for (i = 0; i < N1; ++i) 52 { 53 int j; 54 for (j = 0; j < N2; ++j) 55 { 56 set_port_dependency ((const sc_port_base*) &(source[i]), (const 57 sc_port_base&) (destination[j])); 45 inline void set_port_dependency(sc_in<T> (&source)[N1], sc_out<T> (&destination)[N2]) { 46 int i; 47 for (i = 0; i < N1; ++i) { 48 int j; 49 for (j = 0; j < N2; ++j) { 50 set_port_dependency ((const sc_port_base *) &(source[i]), (const sc_port_base&) (destination[j])); 51 } 58 52 } 59 }60 53 } 61 54 … … 63 56 64 57 #endif 58 59 /* 60 # Local Variables: 61 # tab-width: 4; 62 # c-basic-offset: 4; 63 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 64 # indent-tabs-mode: nil; 65 # End: 66 # 67 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 68 */ 69 -
sources/src/process_dependency.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : process_dependancy.cc |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : 21_09_2004 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : process_dependancy.cc | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 21_09_2004 | 10 | | 11 \------------------------------------------------------------*/ 12 12 13 13 /* … … 37 37 #include <iostream> 38 38 #include <fstream> 39 39 40 #include "assert.h" 40 41 #include "process_dependency.h" … … 44 45 #include "sc_module.h" 45 46 #include "sc_ver.h" 47 46 48 #ifdef HAVE_CONFIG_H 47 49 #include "config.h" … … 52 54 namespace sc_core { 53 55 54 bool 55 ProcessDependency::operator < (const ProcessDependency &a) const 56 { 57 if (a.source < source) 58 return false; 59 if (a.destination < destination) 60 return false; 61 return true; 62 } 63 64 static 65 void 66 dot_write (ofstream &o, 67 const ProcessDependencyGraph &g) 68 { 69 string s; 70 ProcessDependencyGraph::const_iterator it; 71 for (it = g.begin (); it != g.end (); ++it) 72 { 73 string name; 74 name = it->source->module->name(); 75 name += "_"; 76 name += it->source->name; 77 o << simplify_name(name.c_str(),s); 78 o << " -> "; 79 name = it->destination->module->name(); 80 name += "_"; 81 name += it->destination->name; 82 o << simplify_name(name.c_str(),s); 83 o << "\n"; 84 } 85 } 86 87 static 88 void 89 dot_write (ofstream &o, 90 const ProcessDependencyList &l) 91 { 92 const method_process_t *old = NULL; 93 string s; 94 ProcessDependencyList::const_iterator it; 95 for (it = l.begin (); it != l.end (); ++it) 96 { 97 const method_process_t *current = *it; 98 if (old) 99 { 100 string name; 101 name = old->module->name(); 102 name += "_"; 103 name += old->name; 104 o << simplify_name(name.c_str(),s); 105 o << " -> "; 106 name = current->module->name(); 107 name += "_"; 108 name += current->name; 109 o << simplify_name(name.c_str(),s); 110 o << "\n"; 111 } 112 old = current; 113 } 114 } 115 116 bool 117 ProcessDependencyGraph2dot (const char *name, 118 const ProcessDependencyGraph& g) 119 { 120 if (!name) 121 return false; 122 string filename; 123 filename = name; 124 filename += ".dot"; 125 ofstream o; 126 o.open (filename.c_str(),ios::out | ios::trunc); 127 if (o.is_open () == false) 128 return false; 129 o << "// Ordered process list\n" 130 "// Generated by " 131 << sc_version () << "\n"; 132 o << "strict digraph " << name << " {\n"; 133 dot_write (o,g); 134 o << "}\n"; 135 o.close (); 136 if (dump_stage) 137 cerr << "Port Dependency Graph written into '" 138 << filename << "'.\n"; 139 return true; 140 } 141 142 bool 143 ProcessDependencyList2dot (const char *name, 144 const ProcessDependencyList& l) 145 { 146 if (!name) 147 return false; 148 string filename; 149 filename = name; 150 filename += ".dot"; 151 ofstream o; 152 o.open (filename.c_str(),ios::out | ios::trunc); 153 if (o.is_open () == false) 154 return false; 155 o << "// Ordered process list\n" 156 "// Generated by " 157 << sc_version () << "\n"; 158 o << "digraph " << name << " {\n"; 159 dot_write (o,l); 160 o << "}\n"; 161 o.close (); 162 return true; 163 } 164 165 #if 0 166 ProcessDependencyGraph* 167 sc_core::MakeProcessDependencyGraph (const SignalDependencyGraph& g) 168 { 169 if (dump_stage) 170 cerr << "Making module dependency graph...\n"; 171 172 ProcessDependencyGraph *mod_g = new ProcessDependencyGraph (); 173 SignalDependencyGraph::const_iterator it; 174 for (it = g.begin(); it != g.end(); ++it) 175 { 176 ProcessDependency s; 177 s.destination = it->method; 178 SignalDependencyGraph::const_iterator it2; 179 for (it2 = g.begin(); it2 != g.end(); ++it2) 180 { 181 if (it2->source == it->destination) 182 { 183 s.source = it2->method; 184 mod_g->insert(s); 185 } 186 } 187 } 188 return mod_g; 189 } 190 191 static 192 const method_process_t* 193 get_method (const equi_t &e, const SignalDependencyGraph &sig) 194 { 195 SignalDependencyGraph::const_iterator it; 196 for (it = sig.begin (); it != sig.end (); ++it) 197 { 198 if (it->destination == &e) 199 return it->method; 200 } 201 return NULL; 202 } 203 #endif 204 205 206 static 207 bool 208 is_leef (const SignalDependencyGraph &g, 209 const equi_t *e) 210 { 211 SignalDependencyGraph::const_iterator it; 212 for (it = g.begin (); it != g.end (); ++it) 213 { 214 if (it->source == e) 215 return false; 216 } 217 return true; 218 } 219 220 static 221 bool 222 has_all_leef (const SignalDependencyGraph &sig, 223 const method_process_t *m) 224 { 225 SignalDependencyGraph::const_iterator sig_it; 226 for (sig_it = sig.begin (); sig_it != sig.end (); ++sig_it) 227 if ((sig_it->method == m) 228 && (!is_leef (sig, sig_it->destination))) 229 return false; 230 return true; 231 } 232 233 static 234 const method_process_t* 235 get_best_process (const SignalDependencyGraph &sig) 236 { 237 SignalDependencyGraph::const_iterator sig_it; 238 for (sig_it = sig.begin (); sig_it != sig.end (); ++sig_it) 239 { 240 if (has_all_leef (sig, sig_it->method)) 241 return sig_it->method; 242 } 243 return NULL; 244 } 56 bool ProcessDependency::operator < (const ProcessDependency &a) const { 57 if (a.source < source) { 58 return false; 59 } 60 if (a.destination < destination) { 61 return false; 62 } 63 return true; 64 } 65 66 67 static void dot_write (ofstream & o, const ProcessDependencyGraph & g) { 68 string s; 69 ProcessDependencyGraph::const_iterator it; 70 for (it = g.begin (); it != g.end (); ++it) { 71 string name; 72 name = it->source->module->name(); 73 name += "_"; 74 name += it->source->name; 75 o << simplify_name(name.c_str(),s); 76 o << " -> "; 77 name = it->destination->module->name(); 78 name += "_"; 79 name += it->destination->name; 80 o << simplify_name(name.c_str(),s); 81 o << "\n"; 82 } 83 } 84 85 86 static void dot_write(ofstream &o, const ProcessDependencyList &l) { 87 const method_process_t * old = NULL; 88 string s; 89 ProcessDependencyList::const_iterator it; 90 for (it = l.begin (); it != l.end (); ++it) { 91 const method_process_t * current = *it; 92 if (old) { 93 string name; 94 name = old->module->name(); 95 name += "_"; 96 name += old->name; 97 o << simplify_name(name.c_str(),s); 98 o << " -> "; 99 name = current->module->name(); 100 name += "_"; 101 name += current->name; 102 o << simplify_name(name.c_str(),s); 103 o << "\n"; 104 } 105 old = current; 106 } 107 } 108 109 110 bool ProcessDependencyGraph2dot(const char * name, const ProcessDependencyGraph& g) { 111 if (!name) { 112 return false; 113 } 114 string filename; 115 filename = name; 116 filename += ".dot"; 117 ofstream o; 118 o.open (filename.c_str(),ios::out | ios::trunc); 119 if (o.is_open () == false) { 120 return false; 121 } 122 o << "// Ordered process list\n" 123 "// Generated by " 124 << sc_version () << "\n"; 125 o << "strict digraph " << name << " {\n"; 126 dot_write (o,g); 127 o << "}\n"; 128 o.close (); 129 if (dump_stage) { 130 cerr << "Port Dependency Graph written into '" 131 << filename << "'.\n"; 132 } 133 return true; 134 } 135 136 137 bool ProcessDependencyList2dot(const char * name, const ProcessDependencyList& l) { 138 if (!name) { 139 return false; 140 } 141 string filename; 142 filename = name; 143 filename += ".dot"; 144 ofstream o; 145 o.open (filename.c_str(),ios::out | ios::trunc); 146 if (o.is_open () == false) { 147 return false; 148 } 149 o << "// Ordered process list\n" 150 "// Generated by " 151 << sc_version () << "\n"; 152 o << "digraph " << name << " {\n"; 153 dot_write (o,l); 154 o << "}\n"; 155 o.close (); 156 return true; 157 } 158 159 160 static bool is_leef(const SignalDependencyGraph & g, const equi_t * e) { 161 SignalDependencyGraph::const_iterator it; 162 for (it = g.begin(); it != g.end(); ++it) { 163 if (it->source == e) { 164 return false; 165 } 166 } 167 return true; 168 } 169 170 171 static bool has_all_leef(const SignalDependencyGraph & sig, const method_process_t * m) { 172 SignalDependencyGraph::const_iterator sig_it; 173 for (sig_it = sig.begin(); sig_it != sig.end(); ++sig_it) { 174 if ((sig_it->method == m) && (!is_leef (sig, sig_it->destination))) { 175 return false; 176 } 177 } 178 return true; 179 } 180 181 182 static const method_process_t * get_best_process(const SignalDependencyGraph & sig) { 183 SignalDependencyGraph::const_iterator sig_it; 184 for (sig_it = sig.begin(); sig_it != sig.end(); ++sig_it) { 185 if (has_all_leef(sig, sig_it->method)) { 186 return sig_it->method; 187 } 188 } 189 return NULL; 190 } 191 245 192 246 193 /* 247 194 * Remove signals 248 195 */ 249 static 250 void 251 remove_leefs (SignalDependencyGraph &g, 252 const method_process_t &m) 253 { 254 SignalDependencyGraph::iterator it; 255 it = g.begin (); 256 while (it != g.end ()) 257 { 258 const method_process_t *cur_m = it->method; 259 if ((cur_m == &m) && (is_leef (g,it->destination))) 260 { 261 SignalDependencyGraph::iterator x = it++; 262 g.erase (x); 263 } 264 else 265 ++it; 266 } 267 } 196 static void remove_leefs (SignalDependencyGraph & g, const method_process_t & m) { 197 SignalDependencyGraph::iterator it; 198 it = g.begin(); 199 while (it != g.end()) { 200 const method_process_t * cur_m = it->method; 201 if ((cur_m == &m) && (is_leef (g,it->destination))) { 202 SignalDependencyGraph::iterator x = it++; 203 g.erase (x); 204 } 205 else { 206 ++it; 207 } 208 } 209 } 210 268 211 269 212 #if defined(UNUSED) 270 static 271 void 272 print_signals (ostream &o, 273 const SignalDependencyGraph &sig, 274 const method_process_t *method, 275 bool source) 276 { 277 int count = 0; 278 SignalDependencyGraph::const_iterator it; 279 for (it = sig.begin (); it != sig.end (); ++it) 280 { 281 const SignalDependency &dep = *it; 282 const method_process_t *cur_m = dep.method; 283 if (cur_m == method) 284 { 285 const equi_t *e = (source)?dep.source:dep.destination; 286 o << ((count++)?",":"") << get_name (*e); 287 } 288 } 213 static void print_signals (ostream & o, 214 const SignalDependencyGraph & sig, 215 const method_process_t * method, 216 bool source) { 217 int count = 0; 218 SignalDependencyGraph::const_iterator it; 219 for (it = sig.begin(); it != sig.end(); ++it) { 220 const SignalDependency & dep = *it; 221 const method_process_t * cur_m = dep.method; 222 if (cur_m == method) { 223 const equi_t * e = (source) ? dep.source : dep.destination; 224 o << ((count++)?",":"") << get_name (*e); 225 } 226 } 289 227 } 290 228 #endif 291 229 292 static 293 void 294 print_leef_list (SignalDependencyGraph &sig) 295 { 296 typedef map<const equi_t *, const method_process_t *> table_t; 297 table_t table; 298 299 // For each arrow, add destination node into table 300 SignalDependencyGraph::const_iterator sig_it; 301 for (sig_it = sig.begin (); sig_it != sig.end (); ++sig_it) 302 { 303 const SignalDependency sd = *sig_it; 304 const equi_t *equi = sd.destination; 305 const method_process_t *method = sd.method; 306 table[equi] = method; 307 } 308 309 // For each arrow, remove source node into table 310 for (sig_it = sig.begin (); sig_it != sig.end (); ++sig_it) 311 { 312 const SignalDependency sd = *sig_it; 313 const equi_t *e = sd.source; 314 table_t::const_iterator tab_it = table.find (e); 315 if (tab_it != table.end ()) 316 table.erase (e); 317 } 318 319 typedef multimap<const method_process_t *, const equi_t *> table2_t; 320 typedef pair<const method_process_t *, const equi_t *> table2_pair_t; 321 table2_t table2; 322 323 // Build table2 324 table_t::const_iterator it; 325 for (it = table.begin(); it != table.end(); ++it) 326 { 327 const method_process_t *method = it->second; 328 const equi_t *equi = it->first; 329 table2_pair_t pair = table2_pair_t(method,equi); 330 table2.insert(pair); 331 } 332 333 // Print leef list 334 cerr << "Please split following methods :"; 335 table2_t::const_iterator low_it = table2.begin(); 336 table2_t::const_iterator up_it; 337 while (low_it != table2.end ()) 338 { 339 const method_process_t *method = low_it->first; 340 const char *method_name = method->name; 341 const sc_module *module = method->module; 342 const char *module_name = module->name(); 343 cerr << "\n\t - " << module_name << "::" << method_name; 344 cerr << "() to evaluate '"; 345 int count = 0; 346 up_it = table2.upper_bound(low_it->first); 347 table2_t::const_iterator it2; 348 for (it2 = low_it; it2 != up_it; ++it2) 349 { 350 const equi_t *equi = it2->second; 351 const char *signal_name = get_name (*equi); 352 cerr << ((count++)?",":"") << signal_name; 353 } 354 cerr << "' signal(s) separetly"; 355 low_it = up_it; 356 } 357 cerr << "\n"; 358 } 359 360 static 361 void 362 help2resolve (SignalDependencyGraph &sig) 363 { 364 print_leef_list (sig); 365 MethodProcessDependencyGraph2dot ("methodprocess_graph", sig); 366 cerr << "Please look at 'methodprocess_graph.dot' " 367 "to know how to get ride of circular dependencies.\n"; 368 if (dump_all_graph) 369 { 370 SignalDependencyGraph2dot ("reduced_signal_graph", sig); 371 } 372 } 373 374 ProcessDependencyList* 375 MakeProcessDependencyList (const SignalDependencyGraph & _sig_g) 376 { 377 if (dump_stage) 378 cerr << "Making process dependency list...\n"; 379 ProcessDependencyList *mod_l = new ProcessDependencyList (); 380 SignalDependencyGraph sig_g = _sig_g; 381 while (!sig_g.empty ()) 382 { 383 const method_process_t *process = get_best_process (sig_g); 384 #if 1 385 if (process == NULL) 386 { 387 cerr << "Internal Error : Unable to select the best process to schedule.\n"; 388 help2resolve (sig_g); 389 exit (31032005); // 197 390 } 391 #endif 392 mod_l->push_front(process); 393 #if 0 394 cerr << "Process found : " << *process << "\n"; 395 #endif 396 remove_leefs (sig_g, *process); 397 } 398 return mod_l; 230 231 static void print_leef_list (SignalDependencyGraph & sig) { 232 typedef map<const equi_t *, const method_process_t *> table_t; 233 table_t table; 234 235 // For each arrow, add destination node into table 236 SignalDependencyGraph::const_iterator sig_it; 237 for (sig_it = sig.begin(); sig_it != sig.end(); ++sig_it) { 238 const SignalDependency sd = *sig_it; 239 const equi_t * equi = sd.destination; 240 const method_process_t * method = sd.method; 241 table[equi] = method; 242 } 243 244 // For each arrow, remove source node into table 245 for (sig_it = sig.begin(); sig_it != sig.end(); ++sig_it) { 246 const SignalDependency sd = *sig_it; 247 const equi_t * e = sd.source; 248 table_t::const_iterator tab_it = table.find(e); 249 if (tab_it != table.end()) { 250 table.erase(e); 251 } 252 } 253 254 typedef multimap<const method_process_t *, const equi_t *> table2_t; 255 typedef pair<const method_process_t *, const equi_t *> table2_pair_t; 256 table2_t table2; 257 258 // Build table2 259 table_t::const_iterator it; 260 for (it = table.begin(); it != table.end(); ++it) { 261 const method_process_t * method = it->second; 262 const equi_t * equi = it->first; 263 table2_pair_t pair = table2_pair_t(method,equi); 264 table2.insert(pair); 265 } 266 267 // Print leef list 268 cerr << "Please split following methods :"; 269 table2_t::const_iterator low_it = table2.begin(); 270 table2_t::const_iterator up_it; 271 while (low_it != table2.end()) { 272 const method_process_t * method = low_it->first; 273 const char * method_name = method->name; 274 const sc_module * module = method->module; 275 const char * module_name = module->name(); 276 cerr << "\n\t - " << module_name << "::" << method_name; 277 cerr << "() to evaluate '"; 278 int count = 0; 279 up_it = table2.upper_bound(low_it->first); 280 table2_t::const_iterator it2; 281 for (it2 = low_it; it2 != up_it; ++it2) { 282 const equi_t * equi = it2->second; 283 const char * signal_name = get_name(*equi); 284 cerr << ((count++) ? ",":"") << signal_name; 285 } 286 cerr << "' signal(s) separetly"; 287 low_it = up_it; 288 } 289 cerr << "\n"; 290 } 291 292 293 static void help2resolve(SignalDependencyGraph & sig) { 294 print_leef_list(sig); 295 MethodProcessDependencyGraph2dot ("methodprocess_graph", sig); 296 cerr << "Please look at 'methodprocess_graph.dot' " 297 "to know how to get ride of circular dependencies.\n"; 298 if (dump_all_graph) { 299 SignalDependencyGraph2dot ("reduced_signal_graph", sig); 300 } 301 } 302 303 304 ProcessDependencyList * MakeProcessDependencyList(const SignalDependencyGraph & _sig_g) { 305 if (dump_stage) { 306 cerr << "Making process dependency list...\n"; 307 } 308 ProcessDependencyList * mod_l = new ProcessDependencyList(); 309 SignalDependencyGraph sig_g = _sig_g; 310 while (!sig_g.empty()) { 311 const method_process_t * process = get_best_process(sig_g); 312 if (process == NULL) 313 { 314 cerr << "Internal Error : Unable to select the best process to schedule.\n"; 315 help2resolve(sig_g); 316 exit (31032005); // 197 317 } 318 mod_l->push_front(process); 319 if (dump_stage) { 320 cerr << "Process found : " << *process << "\n"; 321 } 322 remove_leefs (sig_g, * process); 323 } 324 return mod_l; 399 325 } 400 326 401 327 } // end of sc_core namespace 402 328 329 /* 330 # Local Variables: 331 # tab-width: 4; 332 # c-basic-offset: 4; 333 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 334 # indent-tabs-mode: nil; 335 # End: 336 # 337 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 338 */ 339 340 -
sources/src/process_dependency.h
r35 r52 19 19 // Signal Dependency Graph 20 20 struct ProcessDependency { 21 const method_process_t *source;22 const method_process_t *destination;23 bool operator < (const ProcessDependency &) const;21 const method_process_t * source; 22 const method_process_t * destination; 23 bool operator < (const ProcessDependency &) const; 24 24 }; 25 25 26 typedef std::set<ProcessDependency> 27 typedef std::list<const method_process_t *> ProcessDependencyList;26 typedef std::set<ProcessDependency> ProcessDependencyGraph; 27 typedef std::list<const method_process_t *> ProcessDependencyList; 28 28 29 29 // Convert Port Dependency Graph to Signal Dependency Graph 30 extern ProcessDependencyGraph * MakeProcessDependencyGraph (const SignalDependencyGraph&);31 extern ProcessDependencyList * MakeProcessDependencyList (const SignalDependencyGraph&);30 extern ProcessDependencyGraph * MakeProcessDependencyGraph(const SignalDependencyGraph &); 31 extern ProcessDependencyList * MakeProcessDependencyList(const SignalDependencyGraph &); 32 32 33 33 // Dump to dot file 34 extern bool ProcessDependencyGraph2dot (const char *name, const ProcessDependencyGraph&);35 extern bool ProcessDependencyList2dot (const char *name, const ProcessDependencyList&);34 extern bool ProcessDependencyGraph2dot(const char * name, const ProcessDependencyGraph &); 35 extern bool ProcessDependencyList2dot(const char * name, const ProcessDependencyList &); 36 36 37 37 } // end of sc_core namespace … … 39 39 #endif 40 40 41 /* 42 # Local Variables: 43 # tab-width: 4; 44 # c-basic-offset: 4; 45 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 46 # indent-tabs-mode: nil; 47 # End: 48 # 49 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 50 */ 51 -
sources/src/sc_bigint.h
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : sc_bigint.h |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : 09_07_2004 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : sc_bigint.h | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 09_07_2004 | 10 | | 11 \------------------------------------------------------------*/ 12 12 #ifndef __SC_BIGINT_H__ 13 13 #define __SC_BIGINT_H__ … … 26 26 namespace sc_dt { 27 27 28 //29 28 #define MASK32(W) ((~ (const uint32)0) >> (sizeof (uint32) * 8 - W)) 30 29 #define MASK64(W) ((~ (const uint64)0) >> (sizeof (uint64) * 8 - W)) 31 //32 30 33 31 template<int W> struct s_bigint_type { typedef uint64 uint_type;}; 34 32 #define DECLAR_BIGINT_TYPE(W) template<> struct s_bigint_type<W> { typedef uint16 uint_type; }// not declared as uint16 because << operator threats like a character 35 DECLAR_BIGINT_TYPE( 36 DECLAR_BIGINT_TYPE( 37 DECLAR_BIGINT_TYPE( 38 DECLAR_BIGINT_TYPE( 39 DECLAR_BIGINT_TYPE( 40 DECLAR_BIGINT_TYPE( 41 DECLAR_BIGINT_TYPE( 42 DECLAR_BIGINT_TYPE( 33 DECLAR_BIGINT_TYPE(1); 34 DECLAR_BIGINT_TYPE(2); 35 DECLAR_BIGINT_TYPE(3); 36 DECLAR_BIGINT_TYPE(4); 37 DECLAR_BIGINT_TYPE(5); 38 DECLAR_BIGINT_TYPE(6); 39 DECLAR_BIGINT_TYPE(7); 40 DECLAR_BIGINT_TYPE(8); 43 41 #undef DECLAR_BIGINT_TYPE 42 44 43 #define DECLAR_BIGINT_TYPE(W) template<> struct s_bigint_type<W> { typedef uint16 uint_type; } 45 DECLAR_BIGINT_TYPE( 44 DECLAR_BIGINT_TYPE(9); 46 45 DECLAR_BIGINT_TYPE(10); 47 46 DECLAR_BIGINT_TYPE(11); … … 52 51 DECLAR_BIGINT_TYPE(16); 53 52 #undef DECLAR_BIGINT_TYPE 53 54 54 #define DECLAR_BIGINT_TYPE(W) template<> struct s_bigint_type<W> { typedef uint32 uint_type; } 55 55 DECLAR_BIGINT_TYPE(17); … … 72 72 73 73 template< int W /* = SC_INTWIDTH */> 74 class sc_bigint 75 { 76 typedef sc_bigint<W> this_type; 77 typedef typename s_int_type<W>::int_type data_type; 78 79 typedef data_type sc_uint_subref; 80 typedef data_type sc_uint_subref_r; 81 82 union { 83 data_type valW:W; 84 bool valB[W]; 85 data_type val; 86 }; 87 void check () 88 { if (W > 64) { std::cerr << "sc_bigint with W > 64 is not supported.\n"; exit (20040528); } } 89 public: 90 sc_bigint() { check (); val = 0; } 91 sc_bigint(data_type val_) { check (); val = 0; write (val_); } 92 template <int W2> explicit sc_bigint (const sc_bigint<W2> &val_) { write (val_.read());} 93 94 inline const data_type& read() const { return val; } 95 inline operator const data_type& () const { return read (); } 96 // inline void write(int64 val_) { val = val_ & MASK64(W); } 97 // inline void write(signed int val_) { val = val_ & MASK32(W); } 98 inline void write(data_type val_) { valW = val_; } 99 template <int W2> inline void write (const sc_bigint<W2> val_) { write (val_.read ()); } 100 inline void write (const sc_bigint<W> val_) { write (val_.read()); }; 101 template <typename T> inline sc_bigint& operator = (const T& val_) { write (val_); return *this; } 102 103 inline uint32 to_uint () const {return val & MASK32(W);}; 104 inline int32 to_int () const {return val & MASK32(W);}; 105 inline uint64 to_uint64 () const {return val & MASK64(W);}; 106 inline int64 to_int64 () const {return val & MASK64(W);}; 107 108 template <typename T> 109 inline sc_bigint& operator <<= (T v) 110 { valW <<= v; return *this; } 111 template <typename T> 112 inline sc_bigint& operator >>= (T v) 113 { valW >>= v; return *this; } 114 template <typename T> 115 inline sc_bigint& operator += (T v) 116 { valW += v; return *this; } 117 template <typename T> 118 inline sc_bigint& operator -= (T v) 119 { valW -= v; return *this; } 120 template <typename T> 121 inline sc_bigint& operator *= (T v) 122 { valW *= v; return *this; } 123 template <typename T> 124 inline sc_bigint& operator /= (T v) 125 { valW /= v; return *this; } 126 template <typename T> 127 inline sc_bigint& operator %= (T v) 128 { valW %= v; return *this; } 129 template <typename T> 130 inline sc_bigint& operator &= (T v) 131 { valW &= v; return *this; } 132 template <typename T> 133 inline sc_bigint& operator |= (T v) 134 { valW |= v; return *this; } 135 template <typename T> 136 inline sc_bigint& operator ^= (T v) 137 { valW ^= v; return *this; } 138 inline sc_uint_bit_ref& operator [] (int v) 139 { return valB[v]; } 140 inline sc_uint_bit_ref_r& operator [] (int v) const 141 { return valB[v]; } 142 inline sc_uint_subref range (int left, int right) 143 { return (((~0) >> (sizeof (data_type) * 8 - left)) & val) >> right; } 144 inline sc_uint_subref_r range (int left, int right) const 145 { return (((~0) >> (sizeof (data_type) * 8 - left)) & val) >> right; } 74 class sc_bigint { 75 typedef sc_bigint<W> this_type; 76 typedef typename s_int_type<W>::int_type data_type; 77 78 typedef data_type sc_uint_subref; 79 typedef data_type sc_uint_subref_r; 80 81 union { 82 data_type valW:W; 83 bool valB[W]; 84 data_type val; 85 }; 86 87 void check() { 88 if (W > 64) { 89 std::cerr << "sc_bigint with W > 64 is not supported.\n"; 90 exit (20040528); 91 } 92 } 93 94 public: 95 sc_bigint() { 96 check (); 97 val = 0; 98 } 99 100 sc_bigint(data_type val_) { 101 check (); 102 val = 0; 103 write (val_); 104 } 105 106 template <int W2> explicit sc_bigint(const sc_bigint<W2> & val_) { 107 write (val_.read()); 108 } 109 110 inline const data_type & read() const { 111 return val; 112 } 113 114 inline operator const data_type & () const { 115 return read (); 116 } 117 118 // inline void write(int64 val_) { val = val_ & MASK64(W); } 119 // inline void write(signed int val_) { val = val_ & MASK32(W); } 120 121 inline void write(data_type val_) { 122 valW = val_; 123 } 124 125 template <int W2> inline void write (const sc_bigint<W2> val_) { 126 write (val_.read ()); 127 } 128 129 inline void write (const sc_bigint<W> val_) { 130 write (val_.read()); 131 } 132 133 template <typename T> inline sc_bigint & operator = (const T & val_) { 134 write (val_); 135 return *this; 136 } 137 138 inline uint32 to_uint() const { 139 return val & MASK32(W); 140 } 141 142 inline int32 to_int() const { 143 return val & MASK32(W); 144 } 145 146 inline uint64 to_uint64() const { 147 return val & MASK64(W); 148 } 149 150 inline int64 to_int64() const { 151 return val & MASK64(W); 152 } 153 154 template <typename T> 155 inline sc_bigint & operator <<= (T v) { 156 valW <<= v; 157 return *this; 158 } 159 160 template <typename T> 161 inline sc_bigint & operator >>= (T v) { 162 valW >>= v; 163 return *this; 164 } 165 166 template <typename T> 167 inline sc_bigint & operator += (T v) { 168 valW += v; 169 return *this; 170 } 171 172 template <typename T> 173 inline sc_bigint & operator -= (T v) { 174 valW -= v; 175 return *this; 176 } 177 178 template <typename T> 179 inline sc_bigint & operator *= (T v) { 180 valW *= v; 181 return *this; 182 } 183 184 template <typename T> 185 inline sc_bigint & operator /= (T v) { 186 valW /= v; 187 return *this; 188 } 189 190 template <typename T> 191 inline sc_bigint & operator %= (T v) { 192 valW %= v; 193 return *this; 194 } 195 196 template <typename T> 197 inline sc_bigint & operator &= (T v) { 198 valW &= v; 199 return *this; 200 } 201 202 template <typename T> 203 inline sc_bigint & operator |= (T v) { 204 valW |= v; 205 return *this; 206 } 207 208 template <typename T> 209 inline sc_bigint & operator ^= (T v) { 210 valW ^= v; 211 return *this; 212 } 213 214 inline sc_uint_bit_ref & operator [] (int v) { 215 return valB[v]; 216 } 217 218 inline sc_uint_bit_ref_r& operator [] (int v) const { 219 return valB[v]; 220 } 221 222 inline sc_uint_subref range(int left, int right) { 223 return (((~0) >> (sizeof (data_type) * 8 - left)) & val) >> right; 224 } 225 226 inline sc_uint_subref_r range(int left, int right) const { 227 return (((~0) >> (sizeof (data_type) * 8 - left)) & val) >> right; 228 } 229 146 230 }; 147 231 … … 149 233 150 234 #endif /* __SC_BIGINT_H__ */ 235 236 237 /* 238 # Local Variables: 239 # tab-width: 4; 240 # c-basic-offset: 4; 241 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 242 # indent-tabs-mode: nil; 243 # End: 244 # 245 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 246 */ 247 -
sources/src/sc_biguint.h
r27 r52 22 22 namespace sc_dt { 23 23 24 //25 24 #define MASK32(W) ((~ (const uint32)0) >> (sizeof (uint32) * 8 - W)) 26 25 #define MASK64(W) ((~ (const uint64)0) >> (sizeof (uint64) * 8 - W)) 27 //28 26 29 27 template<int W> struct s_biguint_type { typedef uint64 uint_type;}; 28 30 29 #define DECLAR_BIGUINT_TYPE(W) template<> struct s_biguint_type<W> { typedef uint16 uint_type; }// not declared as uint16 because << operator threats like a character 31 DECLAR_BIGUINT_TYPE( 32 DECLAR_BIGUINT_TYPE( 33 DECLAR_BIGUINT_TYPE( 34 DECLAR_BIGUINT_TYPE( 35 DECLAR_BIGUINT_TYPE( 36 DECLAR_BIGUINT_TYPE( 37 DECLAR_BIGUINT_TYPE( 38 DECLAR_BIGUINT_TYPE( 30 DECLAR_BIGUINT_TYPE(1); 31 DECLAR_BIGUINT_TYPE(2); 32 DECLAR_BIGUINT_TYPE(3); 33 DECLAR_BIGUINT_TYPE(4); 34 DECLAR_BIGUINT_TYPE(5); 35 DECLAR_BIGUINT_TYPE(6); 36 DECLAR_BIGUINT_TYPE(7); 37 DECLAR_BIGUINT_TYPE(8); 39 38 #undef DECLAR_BIGUINT_TYPE 39 40 40 #define DECLAR_BIGUINT_TYPE(W) template<> struct s_biguint_type<W> { typedef uint16 uint_type; } 41 DECLAR_BIGUINT_TYPE( 41 DECLAR_BIGUINT_TYPE(9); 42 42 DECLAR_BIGUINT_TYPE(10); 43 43 DECLAR_BIGUINT_TYPE(11); … … 48 48 DECLAR_BIGUINT_TYPE(16); 49 49 #undef DECLAR_BIGUINT_TYPE 50 50 51 #define DECLAR_BIGUINT_TYPE(W) template<> struct s_biguint_type<W> { typedef uint32 uint_type; } 51 52 DECLAR_BIGUINT_TYPE(17); … … 67 68 #undef DECLAR_BIGUINT_TYPE 68 69 70 69 71 template< int W /* = SC_INTWIDTH */> 70 class sc_biguint 71 { 72 typedef sc_biguint<W> this_type; 73 typedef typename s_int_type<W>::int_type data_type; 74 75 typedef data_type sc_uint_subref; 76 typedef data_type sc_uint_subref_r; 77 78 union { 79 data_type valW:W; 80 bool valB[W]; 81 data_type val; 82 }; 83 void check () 84 { if (W > 64) { std::cerr << "sc_biguint with W > 64 is not supported.\n"; exit (20040528); } } 85 public: 86 sc_biguint() { check (); val = 0; } 87 sc_biguint(data_type val_) { check (); val = 0; write (val_); } 88 template <int W2> explicit sc_biguint (const sc_biguint<W2> &val_) { write (val_.read());} 89 90 inline const data_type& read() const { return val; } 91 inline operator const data_type& () const { return read (); } 92 // inline void write(int64 val_) { val = val_ & MASK64(W); } 93 // inline void write(signed int val_) { val = val_ & MASK32(W); } 94 inline void write(data_type val_) { valW = val_; } 95 template <int W2> inline void write (const sc_biguint<W2> val_) { write (val_.read ()); } 96 inline void write (const sc_biguint<W> val_) { write (val_.read()); }; 97 template <typename T> inline sc_biguint& operator = (const T& val_) { write (val_); return *this; } 98 99 inline uint32 to_uint () const {return val & MASK32(W);}; 100 inline int32 to_int () const {return val & MASK32(W);}; 101 inline uint64 to_uint64 () const {return val & MASK64(W);}; 102 inline int64 to_int64 () const {return val & MASK64(W);}; 103 104 template <typename T> 105 inline sc_biguint& operator <<= (T v) 106 { valW <<= v; return *this; } 107 template <typename T> 108 inline sc_biguint& operator >>= (T v) 109 { valW >>= v; return *this; } 110 template <typename T> 111 inline sc_biguint& operator += (T v) 112 { valW += v; return *this; } 113 template <typename T> 114 inline sc_biguint& operator -= (T v) 115 { valW -= v; return *this; } 116 template <typename T> 117 inline sc_biguint& operator *= (T v) 118 { valW *= v; return *this; } 119 template <typename T> 120 inline sc_biguint& operator /= (T v) 121 { valW /= v; return *this; } 122 template <typename T> 123 inline sc_biguint& operator %= (T v) 124 { valW %= v; return *this; } 125 template <typename T> 126 inline sc_biguint& operator &= (T v) 127 { valW &= v; return *this; } 128 template <typename T> 129 inline sc_biguint& operator |= (T v) 130 { valW |= v; return *this; } 131 template <typename T> 132 inline sc_biguint& operator ^= (T v) 133 { valW ^= v; return *this; } 134 inline sc_uint_bit_ref& operator [] (int v) 135 { return valB[v]; } 136 inline sc_uint_bit_ref_r& operator [] (int v) const 137 { return valB[v]; } 138 inline sc_uint_subref range (int left, int right) 139 { return (((~0) >> (sizeof (data_type) * 8 - left)) & val) >> right; } 140 inline sc_uint_subref_r range (int left, int right) const 141 { return (((~0) >> (sizeof (data_type) * 8 - left)) & val) >> right; } 72 class sc_biguint { 73 typedef sc_biguint<W> this_type; 74 typedef typename s_int_type<W>::int_type data_type; 75 76 typedef data_type sc_uint_subref; 77 typedef data_type sc_uint_subref_r; 78 79 union { 80 data_type valW:W; 81 bool valB[W]; 82 data_type val; 83 }; 84 85 void check () { 86 if (W > 64) { 87 std::cerr << "sc_biguint with W > 64 is not supported.\n"; 88 exit (20040528); 89 } 90 } 91 92 public: 93 94 sc_biguint() { 95 check (); 96 val = 0; 97 } 98 99 sc_biguint(data_type val_) { 100 check (); 101 val = 0; 102 write (val_); 103 } 104 105 template <int W2> explicit sc_biguint (const sc_biguint<W2> & val_) { 106 write (val_.read()); 107 } 108 109 inline const data_type & read() const { 110 return val; 111 } 112 113 inline operator const data_type & () const { 114 return read (); 115 } 116 117 inline void write(data_type val_) { 118 valW = val_; 119 } 120 121 template <int W2> inline void write (const sc_biguint<W2> val_) { 122 write (val_.read ()); 123 } 124 125 inline void write (const sc_biguint<W> val_) { 126 write (val_.read()); 127 } 128 129 template <typename T> inline sc_biguint & operator = (const T& val_) { 130 write (val_); 131 return *this; 132 } 133 134 inline uint32 to_uint() const { return val & MASK32(W); } 135 inline int32 to_int() const { return val & MASK32(W); } 136 inline uint64 to_uint64() const { return val & MASK64(W); } 137 inline int64 to_int64() const { return val & MASK64(W); } 138 139 template <typename T> 140 inline sc_biguint & operator <<= (T v) { 141 valW <<= v; 142 return *this; 143 } 144 145 template <typename T> 146 inline sc_biguint & operator >>= (T v) { 147 valW >>= v; 148 return *this; 149 } 150 151 template <typename T> 152 inline sc_biguint & operator += (T v) { 153 valW += v; 154 return *this; 155 } 156 157 template <typename T> 158 inline sc_biguint & operator -= (T v) { 159 valW -= v; 160 return *this; 161 } 162 163 template <typename T> 164 inline sc_biguint & operator *= (T v) { 165 valW *= v; 166 return *this; 167 } 168 169 template <typename T> 170 inline sc_biguint & operator /= (T v) { 171 valW /= v; 172 return *this; 173 } 174 175 template <typename T> 176 inline sc_biguint & operator %= (T v) { 177 valW %= v; 178 return *this; 179 } 180 181 template <typename T> 182 inline sc_biguint & operator &= (T v) { 183 valW &= v; 184 return *this; 185 } 186 187 template <typename T> 188 inline sc_biguint & operator |= (T v) { 189 valW |= v; 190 return *this; 191 } 192 193 template <typename T> 194 inline sc_biguint & operator ^= (T v) { 195 valW ^= v; 196 return *this; 197 } 198 199 inline sc_uint_bit_ref & operator [] (int v) { return valB[v]; } 200 inline sc_uint_bit_ref_r & operator [] (int v) const { return valB[v]; } 201 202 inline sc_uint_subref range (int left, int right) { 203 return (((~0) >> (sizeof(data_type) * 8 - left)) & val) >> right; 204 } 205 206 inline sc_uint_subref_r range (int left, int right) const { 207 return (((~0) >> (sizeof(data_type) * 8 - left)) & val) >> right; 208 } 209 142 210 }; 143 211 … … 145 213 146 214 #endif /* __SC_BIGUINT_H__ */ 215 216 /* 217 # Local Variables: 218 # tab-width: 4; 219 # c-basic-offset: 4; 220 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 221 # indent-tabs-mode: nil; 222 # End: 223 # 224 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 225 */ 226 -
sources/src/sc_bit.h
r27 r52 26 26 namespace sc_dt { 27 27 28 class sc_bit 29 { 30 ///////////////////////// 31 ///// SYSTEMCASS SPECIFIC 32 bool val; 33 ///////////////////////// 34 public: 35 // constructors & destructor 36 sc_bit () { val = false; } 37 explicit sc_bit (bool a) { val = a; } 38 explicit sc_bit (int a) { val = a > 0; } 39 explicit sc_bit (char a) { val = (a == '1')?true:false; } 40 explicit sc_bit (const sc_logic & a) { val = a.to_bool(); } 41 ~sc_bit () { }; 42 // copy constructor 43 sc_bit (const sc_bit & a) { val = a; } 44 // assignment operators 45 sc_bit & operator = (const sc_bit & b) { val = b.to_bool(); return *this; } 46 sc_bit & operator = (int b) { val = b > 0; return *this; } 47 sc_bit & operator = (bool b) { val = b; return *this; } 48 sc_bit & operator = (char b) { val = (b == '1')?true:false; return *this; } 49 sc_bit & operator = (const sc_logic & b) { val = b.to_bool(); return *this; } 50 51 // bitwise assignment operators 52 sc_bit & operator &= (const sc_bit & b) { val &= b.to_bool(); return *this; } 53 sc_bit & operator &= (int b) { val &= b > 0; return *this; } 54 sc_bit & operator &= (bool b) { val &= b; return *this; } 55 sc_bit & operator &= (char b) { val &= (b == '1')?true:false; return *this; } 56 sc_bit & operator |= (const sc_bit & b) { val |= b.val; return *this; } 57 sc_bit & operator |= (int b) { val |= b > 0; return *this; } 58 sc_bit & operator |= (bool b) { val |= b; return *this; } 59 sc_bit & operator |= (char b) { val |= (b == '1')?true:false; return *this; } 60 sc_bit & operator ^= (const sc_bit & b) { val ^= b.val; return *this; } 61 sc_bit & operator ^= (int b) { val ^= b > 0; return *this; } 62 sc_bit & operator ^= (bool b) { val ^= b; return *this; } 63 sc_bit & operator ^= (char b) { val ^= (b == '1')?true:false; return *this; } 64 65 // implicit conversion to bool 66 operator bool () const { return val; } 67 bool operator ! () const { return !val; } 68 69 // explicit conversion to character string 70 const sc_string to_string ( sc_numrep numrep = SC_DEC ) const 71 { return sc_string ((val)?"1":"0"); } 72 const sc_string to_dec() const { return to_string (SC_DEC); } 73 const sc_string to_bin() const { return to_string (SC_BIN); } 74 const sc_string to_oct() const { return to_string (SC_OCT); } 75 const sc_string to_hex() const { return to_string (SC_HEX); } 76 77 // others explicit conversions 78 bool to_bool () const { return val; } 79 char to_char () const { return (val)?'1':'0'; } 80 81 // relational operators and functions 82 friend bool operator == (const sc_bit & a, const sc_bit & b) { return a == 83 b; } 84 friend bool operator == (const sc_bit & a, int b); 85 friend bool operator == (const sc_bit & a, bool b); 86 friend bool operator == (const sc_bit & a, char b); 87 friend bool operator == (int a, const sc_bit & b); 88 89 friend bool operator == (bool a, const sc_bit & b); 90 friend bool operator == (char a, const sc_bit & b); 91 friend bool equal (const sc_bit & a, const sc_bit & b); 92 friend bool equal (const sc_bit & a, int b); 93 friend bool equal (const sc_bit & a, bool b); 94 friend bool equal (const sc_bit & a, char b); 95 friend bool equal (int a, const sc_bit & b); 96 friend bool equal (bool a, const sc_bit & b); 97 friend bool equal (char a, const sc_bit & b); 98 friend bool operator != (const sc_bit & a, const sc_bit & b); 99 friend bool operator != (const sc_bit & a, int b); 100 friend bool operator != (const sc_bit & a, bool b); 101 friend bool operator != (const sc_bit & a, char b); 102 friend bool operator != (int a, const sc_bit & b); 103 friend bool operator != (bool a, const sc_bit & b); 104 friend bool operator != (char a, const sc_bit & b); 105 friend bool not_equal (const sc_bit & a, const sc_bit & b); 106 friend bool not_equal (const sc_bit & a, int b); 107 friend bool not_equal (const sc_bit & a, bool b); 108 friend bool not_equal (const sc_bit & a, char b); 109 friend bool not_equal (int a, const sc_bit & b); 110 friend bool not_equal (bool a, const sc_bit & b); 111 friend bool not_equal (char a, const sc_bit & b); 112 // bitwise complement 113 friend const sc_bit operator ~ (const sc_bit & a); 114 sc_bit & b_not (); 115 friend void b_not (sc_bit & r, const sc_bit & a); 116 friend const sc_bit b_not (const sc_bit & a); 117 // bitwise or 118 friend const sc_bit operator | (const sc_bit & a, const sc_bit & b); 119 friend const sc_bit operator | (const sc_bit & a, int b); 120 friend const sc_bit operator | (const sc_bit & a, bool b); 121 friend const sc_bit operator | (const sc_bit & a, char b); 122 friend const sc_bit operator | (int a, const sc_bit & b); 123 friend const sc_bit operator | (bool a, const sc_bit & b); 124 friend const sc_bit operator | (char a, const sc_bit & b); 125 friend const sc_bit b_or (const sc_bit & a, const sc_bit & b); 126 friend const sc_bit b_or (const sc_bit & a, int b); 127 friend const sc_bit b_or (const sc_bit & a, bool b); 128 friend const sc_bit b_or (const sc_bit & a, char b); 129 friend const sc_bit b_or (int a, const sc_bit & b); 130 friend const sc_bit b_or (bool a, const sc_bit & b); 131 132 friend const sc_bit b_or (char a, const sc_bit & b); 133 friend void b_or (sc_bit & r, const sc_bit & a, const sc_bit & b); 134 friend void b_or (sc_bit & r, const sc_bit & a, int b); 135 friend void b_or (sc_bit & r, const sc_bit & a, bool b); 136 friend void b_or (sc_bit & r, const sc_bit & a, char b); 137 friend void b_or (sc_bit & r, int a, const sc_bit & b); 138 friend void b_or (sc_bit & r, bool a, const sc_bit & b); 139 friend void b_or (sc_bit & r, char a, const sc_bit & b); 140 // bitwise and 141 friend const sc_bit operator & (const sc_bit & a, const sc_bit & b); 142 friend const sc_bit operator & (const sc_bit & a, int b); 143 friend const sc_bit operator & (const sc_bit & a, bool b); 144 friend const sc_bit operator & (const sc_bit & a, char b); 145 friend const sc_bit operator & (int a, const sc_bit & b); 146 friend const sc_bit operator & (bool a, const sc_bit & b); 147 friend const sc_bit operator & (char a, const sc_bit & b); 148 friend const sc_bit b_and (const sc_bit & a, const sc_bit & b); 149 friend const sc_bit b_and (const sc_bit & a, int b); 150 friend const sc_bit b_and (const sc_bit & a, bool b); 151 friend const sc_bit b_and (const sc_bit & a, char b); 152 friend const sc_bit b_and (int a, const sc_bit & b); 153 friend const sc_bit b_and (bool a, const sc_bit & b); 154 friend const sc_bit b_and (char a, const sc_bit & b); 155 friend void b_and (sc_bit & r, const sc_bit & a, const sc_bit & b); 156 friend void b_and (sc_bit & r, const sc_bit & a, int b); 157 friend void b_and (sc_bit & r, const sc_bit & a, bool b); 158 friend void b_and (sc_bit & r, const sc_bit & a, char b); 159 friend void b_and (sc_bit & r, int a, const sc_bit & b); 160 friend void b_and (sc_bit & r, bool a, const sc_bit & b); 161 friend void b_and (sc_bit & r, char a, const sc_bit & b); 162 // bitwise exor 163 friend const sc_bit operator ^ (const sc_bit & a, const sc_bit & b); 164 friend const sc_bit operator ^ (const sc_bit & a, int b); 165 friend const sc_bit operator ^ (const sc_bit & a, bool b); 166 friend const sc_bit operator ^ (const sc_bit & a, char b); 167 friend const sc_bit operator ^ (int a, const sc_bit & b); 168 169 friend const sc_bit operator ^ (bool a, const sc_bit & b); 170 friend const sc_bit operator ^ (char a, const sc_bit & b); 171 friend const sc_bit b_xor (const sc_bit & a, const sc_bit & b); 172 friend const sc_bit b_xor (const sc_bit & a, int b); 173 friend const sc_bit b_xor (const sc_bit & a, bool b); 174 friend const sc_bit b_xor (const sc_bit & a, char b); 175 friend const sc_bit b_xor (int a, const sc_bit & b); 176 friend const sc_bit b_xor (bool a, const sc_bit & b); 177 friend const sc_bit b_xor (char a, const sc_bit & b); 178 friend void b_xor (sc_bit & r, const sc_bit & a, const sc_bit & b); 179 friend void b_xor (sc_bit & r, const sc_bit & a, int b); 180 friend void b_xor (sc_bit & r, const sc_bit & a, bool b); 181 friend void b_xor (sc_bit & r, const sc_bit & a, char b); 182 friend void b_xor (sc_bit & r, int a, const sc_bit & b); 183 friend void b_xor (sc_bit & r, bool a, const sc_bit & b); 184 friend void b_xor (sc_bit & r, char a, const sc_bit & b); 28 class sc_bit { 29 30 ///////////////////////// 31 ///// SYSTEMCASS SPECIFIC 32 bool val; 33 ///////////////////////// 34 35 public: 36 // constructors & destructor 37 sc_bit() { val = false; } 38 explicit sc_bit(bool a) { val = a; } 39 explicit sc_bit(int a) { val = a > 0; } 40 explicit sc_bit(char a) { val = (a == '1') ? true : false; } 41 explicit sc_bit(const sc_logic & a) { val = a.to_bool(); } 42 ~sc_bit() {} 43 // copy constructor 44 sc_bit(const sc_bit & a) { val = a; } 45 // assignment operators 46 sc_bit & operator = (const sc_bit & b) { val = b.to_bool(); return *this; } 47 sc_bit & operator = (int b) { val = b > 0; return *this; } 48 sc_bit & operator = (bool b) { val = b; return *this; } 49 sc_bit & operator = (char b) { val = (b == '1') ? true : false; return *this; } 50 sc_bit & operator = (const sc_logic & b) { val = b.to_bool(); return *this; } 51 52 // bitwise assignment operators 53 sc_bit & operator &= (const sc_bit & b) { val &= b.to_bool(); return *this; } 54 sc_bit & operator &= (int b) { val &= b > 0; return *this; } 55 sc_bit & operator &= (bool b) { val &= b; return *this; } 56 sc_bit & operator &= (char b) { val &= (b == '1') ? true : false; return *this; } 57 sc_bit & operator |= (const sc_bit & b) { val |= b.val; return *this; } 58 sc_bit & operator |= (int b) { val |= b > 0; return *this; } 59 sc_bit & operator |= (bool b) { val |= b; return *this; } 60 sc_bit & operator |= (char b) { val |= (b == '1') ? true : false; return *this; } 61 sc_bit & operator ^= (const sc_bit & b) { val ^= b.val; return *this; } 62 sc_bit & operator ^= (int b) { val ^= b > 0; return *this; } 63 sc_bit & operator ^= (bool b) { val ^= b; return *this; } 64 sc_bit & operator ^= (char b) { val ^= (b == '1') ? true : false; return *this; } 65 66 // implicit conversion to bool 67 operator bool () const { return val; } 68 bool operator ! () const { return !val; } 69 70 // explicit conversion to character string 71 const sc_string to_string(sc_numrep numrep = SC_DEC ) const { 72 return sc_string ((val) ? "1" : "0"); 73 } 74 const sc_string to_dec() const { return to_string (SC_DEC); } 75 const sc_string to_bin() const { return to_string (SC_BIN); } 76 const sc_string to_oct() const { return to_string (SC_OCT); } 77 const sc_string to_hex() const { return to_string (SC_HEX); } 78 79 // others explicit conversions 80 bool to_bool() const { return val; } 81 char to_char() const { return (val) ? '1' : '0'; } 82 83 // relational operators and functions 84 friend bool operator == (const sc_bit & a, const sc_bit & b) { return a == b; } 85 friend bool operator == (const sc_bit & a, int b); 86 friend bool operator == (const sc_bit & a, bool b); 87 friend bool operator == (const sc_bit & a, char b); 88 friend bool operator == (int a, const sc_bit & b); 89 friend bool operator == (bool a, const sc_bit & b); 90 friend bool operator == (char a, const sc_bit & b); 91 friend bool equal (const sc_bit & a, const sc_bit & b); 92 friend bool equal (const sc_bit & a, int b); 93 friend bool equal (const sc_bit & a, bool b); 94 friend bool equal (const sc_bit & a, char b); 95 friend bool equal (int a, const sc_bit & b); 96 friend bool equal (bool a, const sc_bit & b); 97 friend bool equal (char a, const sc_bit & b); 98 friend bool operator != (const sc_bit & a, const sc_bit & b); 99 friend bool operator != (const sc_bit & a, int b); 100 friend bool operator != (const sc_bit & a, bool b); 101 friend bool operator != (const sc_bit & a, char b); 102 friend bool operator != (int a, const sc_bit & b); 103 friend bool operator != (bool a, const sc_bit & b); 104 friend bool operator != (char a, const sc_bit & b); 105 friend bool not_equal (const sc_bit & a, const sc_bit & b); 106 friend bool not_equal (const sc_bit & a, int b); 107 friend bool not_equal (const sc_bit & a, bool b); 108 friend bool not_equal (const sc_bit & a, char b); 109 friend bool not_equal (int a, const sc_bit & b); 110 friend bool not_equal (bool a, const sc_bit & b); 111 friend bool not_equal (char a, const sc_bit & b); 112 // bitwise complement 113 friend const sc_bit operator ~ (const sc_bit & a); 114 sc_bit & b_not(); 115 friend void b_not (sc_bit & r, const sc_bit & a); 116 friend const sc_bit b_not (const sc_bit & a); 117 // bitwise or 118 friend const sc_bit operator | (const sc_bit & a, const sc_bit & b); 119 friend const sc_bit operator | (const sc_bit & a, int b); 120 friend const sc_bit operator | (const sc_bit & a, bool b); 121 friend const sc_bit operator | (const sc_bit & a, char b); 122 friend const sc_bit operator | (int a, const sc_bit & b); 123 friend const sc_bit operator | (bool a, const sc_bit & b); 124 friend const sc_bit operator | (char a, const sc_bit & b); 125 friend const sc_bit b_or (const sc_bit & a, const sc_bit & b); 126 friend const sc_bit b_or (const sc_bit & a, int b); 127 friend const sc_bit b_or (const sc_bit & a, bool b); 128 friend const sc_bit b_or (const sc_bit & a, char b); 129 friend const sc_bit b_or (int a, const sc_bit & b); 130 friend const sc_bit b_or (bool a, const sc_bit & b); 131 132 friend const sc_bit b_or (char a, const sc_bit & b); 133 friend void b_or (sc_bit & r, const sc_bit & a, const sc_bit & b); 134 friend void b_or (sc_bit & r, const sc_bit & a, int b); 135 friend void b_or (sc_bit & r, const sc_bit & a, bool b); 136 friend void b_or (sc_bit & r, const sc_bit & a, char b); 137 friend void b_or (sc_bit & r, int a, const sc_bit & b); 138 friend void b_or (sc_bit & r, bool a, const sc_bit & b); 139 friend void b_or (sc_bit & r, char a, const sc_bit & b); 140 // bitwise and 141 friend const sc_bit operator & (const sc_bit & a, const sc_bit & b); 142 friend const sc_bit operator & (const sc_bit & a, int b); 143 friend const sc_bit operator & (const sc_bit & a, bool b); 144 friend const sc_bit operator & (const sc_bit & a, char b); 145 friend const sc_bit operator & (int a, const sc_bit & b); 146 friend const sc_bit operator & (bool a, const sc_bit & b); 147 friend const sc_bit operator & (char a, const sc_bit & b); 148 friend const sc_bit b_and (const sc_bit & a, const sc_bit & b); 149 friend const sc_bit b_and (const sc_bit & a, int b); 150 friend const sc_bit b_and (const sc_bit & a, bool b); 151 friend const sc_bit b_and (const sc_bit & a, char b); 152 friend const sc_bit b_and (int a, const sc_bit & b); 153 friend const sc_bit b_and (bool a, const sc_bit & b); 154 friend const sc_bit b_and (char a, const sc_bit & b); 155 friend void b_and (sc_bit & r, const sc_bit & a, const sc_bit & b); 156 friend void b_and (sc_bit & r, const sc_bit & a, int b); 157 friend void b_and (sc_bit & r, const sc_bit & a, bool b); 158 friend void b_and (sc_bit & r, const sc_bit & a, char b); 159 friend void b_and (sc_bit & r, int a, const sc_bit & b); 160 friend void b_and (sc_bit & r, bool a, const sc_bit & b); 161 friend void b_and (sc_bit & r, char a, const sc_bit & b); 162 // bitwise exor 163 friend const sc_bit operator ^ (const sc_bit & a, const sc_bit & b); 164 friend const sc_bit operator ^ (const sc_bit & a, int b); 165 friend const sc_bit operator ^ (const sc_bit & a, bool b); 166 friend const sc_bit operator ^ (const sc_bit & a, char b); 167 friend const sc_bit operator ^ (int a, const sc_bit & b); 168 169 friend const sc_bit operator ^ (bool a, const sc_bit & b); 170 friend const sc_bit operator ^ (char a, const sc_bit & b); 171 friend const sc_bit b_xor (const sc_bit & a, const sc_bit & b); 172 friend const sc_bit b_xor (const sc_bit & a, int b); 173 friend const sc_bit b_xor (const sc_bit & a, bool b); 174 friend const sc_bit b_xor (const sc_bit & a, char b); 175 friend const sc_bit b_xor (int a, const sc_bit & b); 176 friend const sc_bit b_xor (bool a, const sc_bit & b); 177 friend const sc_bit b_xor (char a, const sc_bit & b); 178 friend void b_xor (sc_bit & r, const sc_bit & a, const sc_bit & b); 179 friend void b_xor (sc_bit & r, const sc_bit & a, int b); 180 friend void b_xor (sc_bit & r, const sc_bit & a, bool b); 181 friend void b_xor (sc_bit & r, const sc_bit & a, char b); 182 friend void b_xor (sc_bit & r, int a, const sc_bit & b); 183 friend void b_xor (sc_bit & r, bool a, const sc_bit & b); 184 friend void b_xor (sc_bit & r, char a, const sc_bit & b); 185 186 }; 187 188 } /* end of sc_dt namespace */ 189 190 #endif /* __SC_BIT_H__ */ 191 185 192 /* 186 // other functions 187 void print (std::ostream & os = std::cout) const; 188 void scan (std::istream & = std::cin); 193 # Local Variables: 194 # tab-width: 4; 195 # c-basic-offset: 4; 196 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 197 # indent-tabs-mode: nil; 198 # End: 199 # 200 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 189 201 */ 190 }; 191 192 } /* end of sc_dt namespace */ 193 194 #endif /* __SC_BIT_H__ */ 202 -
sources/src/sc_bv.h
r27 r52 27 27 namespace sc_dt { 28 28 29 class sc_bv_base 30 { 31 public: 32 // constructors 33 /* 34 explicit sc_bv_base (int length_ = sc_length_param ().len ()); 35 explicit sc_bv_base (bool a, int length_ = sc_length_param ().len ()); 36 */ 37 sc_bv_base (const char *a); 38 sc_bv_base (const char *a, int length_); 29 class sc_bv_base { 30 public: 31 // constructors 32 sc_bv_base (const char * a); 33 sc_bv_base (const char * a, int length_); 39 34 template < class X > sc_bv_base (const sc_bv_base & a); 40 35 virtual ~ sc_bv_base (); 41 // assignment operators36 // assignment operators 42 37 template < class X > sc_bv_base & operator = (const sc_bv_base & a); 43 38 sc_bv_base & operator = (const char *a); … … 46 41 sc_bv_base & operator = (const sc_unsigned & a); 47 42 sc_bv_base & operator = (const sc_signed & a); 48 /*49 sc_bv_base & operator = (const sc_uint_base & a);50 sc_bv_base & operator = (const sc_int_base & a);51 */52 43 sc_bv_base & operator = (unsigned long a); 53 44 sc_bv_base & operator = (long a); … … 57 48 sc_bv_base & operator = (int64 a); 58 49 59 // methods60 int length () const;61 bool is_01 () const;50 // methods 51 int length () const; 52 bool is_01 () const; 62 53 }; 63 54 64 55 65 template < int W > class sc_bv:public sc_bv_base66 {67 public:68 // constructors69 sc_bv ();70 explicit sc_bv (bool init_value);71 explicit sc_bv (char init_value);56 template < int W > 57 class sc_bv : public sc_bv_base { 58 public: 59 // constructors 60 sc_bv (); 61 explicit sc_bv (bool init_value); 62 explicit sc_bv (char init_value); 72 63 sc_bv (const char *a); 73 64 sc_bv (const bool * a); … … 75 66 sc_bv (const sc_unsigned & a); 76 67 sc_bv (const sc_signed & a); 77 /*78 sc_bv (const sc_uint_base & a);79 sc_bv (const sc_int_base & a);80 */81 68 sc_bv (unsigned long a); 82 69 sc_bv (long a); … … 86 73 sc_bv (int64 a); 87 74 sc_bv (const sc_bv_base & a); 88 sc_bv (const sc_bv < W > &a); 89 // assignment operators 90 template < class X > sc_bv < W > &operator = (const sc_bv_base & a); 91 sc_bv < W > &operator = (const sc_bv < W > &a); 92 sc_bv < W > &operator = (const char *a); 93 sc_bv < W > &operator = (const bool * a); 94 sc_bv < W > &operator = (const sc_logic * a); 95 sc_bv < W > &operator = (const sc_unsigned & a); 96 sc_bv < W > &operator = (const sc_signed & a); 97 /* 98 sc_bv < W > &operator = (const sc_uint_base & a); 99 sc_bv < W > &operator = (const sc_int_base & a); 100 */ 101 sc_bv < W > &operator = (unsigned long a); 102 sc_bv < W > &operator = (long a); 103 sc_bv < W > &operator = (unsigned int a); 104 sc_bv < W > &operator = (int a); 105 sc_bv < W > &operator = (uint64 a); 106 sc_bv < W > &operator = (int64 a); 75 sc_bv (const sc_bv < W > & a); 76 // assignment operators 77 template < class X > sc_bv < W > & operator = (const sc_bv_base & a); 78 sc_bv < W > & operator = (const sc_bv < W > &a); 79 sc_bv < W > & operator = (const char *a); 80 sc_bv < W > & operator = (const bool * a); 81 sc_bv < W > & operator = (const sc_logic * a); 82 sc_bv < W > & operator = (const sc_unsigned & a); 83 sc_bv < W > & operator = (const sc_signed & a); 84 sc_bv < W > & operator = (unsigned long a); 85 sc_bv < W > & operator = (long a); 86 sc_bv < W > & operator = (unsigned int a); 87 sc_bv < W > & operator = (int a); 88 sc_bv < W > & operator = (uint64 a); 89 sc_bv < W > & operator = (int64 a); 107 90 }; 108 91 … … 110 93 111 94 #endif /* __SC_BV_H__ */ 95 96 /* 97 # Local Variables: 98 # tab-width: 4; 99 # c-basic-offset: 4; 100 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 101 # indent-tabs-mode: nil; 102 # End: 103 # 104 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 105 */ 106 -
sources/src/sc_clock.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : sc_clock.cc |6 | |7 | Author : Buchmann Richard |8 | Taktak Sami |9 | |10 | Date : 09_09_2005 |11 | |12 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : sc_clock.cc | 6 | | 7 | Author : Buchmann Richard | 8 | Taktak Sami | 9 | | 10 | Date : 09_09_2005 | 11 | | 12 \------------------------------------------------------------*/ 13 13 14 14 /* … … 35 35 */ 36 36 37 #include <cassert> 38 37 39 #include "sc_clock.h" 38 #include <cassert> 40 39 41 #ifdef HAVE_CONFIG_H 40 42 #include "config.h" … … 53 55 54 56 55 sc_clock::sc_clock(): base_type() 56 { 57 init (); 58 posedge_first = true; 57 sc_clock::sc_clock(): base_type() { 58 init (); 59 posedge_first = true; 59 60 } 60 61 61 sc_clock::sc_clock(const char *name_): base_type(name_) 62 {63 64 posedge_first = true;62 63 sc_clock::sc_clock(const char * name_): base_type(name_) { 64 init (); 65 posedge_first = true; 65 66 } 66 67 67 sc_clock::sc_clock(const char *name_, 68 const sc_time& period_,69 double duty_cycle_,70 const sc_time& start_time_,71 bool posedge_first_) : base_type(name_) 72 {73 74 assert(period_== 1);75 assert(duty_cycle_ == 0.5);76 assert(start_time_ == SC_ZERO_TIME);77 posedge_first = posedge_first_;68 69 sc_clock::sc_clock(const char * name_, 70 const sc_time & period_, 71 double duty_cycle_, 72 const sc_time & start_time_, 73 bool posedge_first_) : base_type(name_) { 74 init (); 75 assert(period_ == 1); 76 assert(duty_cycle_ == 0.5); 77 assert(start_time_ == SC_ZERO_TIME); 78 posedge_first = posedge_first_; 78 79 } 79 80 80 sc_clock::sc_clock(const char *name_, 81 double period_,82 double duty_cycle_,83 double start_time_,84 bool posedge_first_) : base_type(name_) 85 {86 87 assert(period_== 1);88 assert(duty_cycle_ == 0.5);89 assert(start_time_ == SC_ZERO_TIME);90 posedge_first = posedge_first_;81 82 sc_clock::sc_clock(const char * name_, 83 double period_, 84 double duty_cycle_, 85 double start_time_, 86 bool posedge_first_) : base_type(name_) { 87 init (); 88 assert(period_ == 1); 89 assert(duty_cycle_ == 0.5); 90 assert(start_time_ == SC_ZERO_TIME); 91 posedge_first = posedge_first_; 91 92 } 92 93 93 sc_clock::~sc_clock () 94 { 94 95 sc_clock::~sc_clock() {} 96 97 98 void sc_clock::init () { 99 set_kind(kind_string); 95 100 } 96 101 97 void98 sc_clock::init ()99 {100 set_kind (kind_string);101 }102 102 103 sc_clock::this_type & sc_clock::operator = ( const data_type& value_) {104 write(value_);105 return *this;103 sc_clock::this_type & sc_clock::operator = (const data_type & value_) { 104 write(value_); 105 return *this; 106 106 } 107 107 108 108 } // end of sc_core namespace 109 109 110 /* 111 # Local Variables: 112 # tab-width: 4; 113 # c-basic-offset: 4; 114 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 115 # indent-tabs-mode: nil; 116 # End: 117 # 118 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 119 */ 120 -
sources/src/sc_clock.h
r27 r52 19 19 #endif /* __SC_CLOCK_H__ */ 20 20 21 /* 22 # Local Variables: 23 # tab-width: 4; 24 # c-basic-offset: 4; 25 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 26 # indent-tabs-mode: nil; 27 # End: 28 # 29 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 30 */ 31 -
sources/src/sc_clock_ext.h
r1 r52 47 47 // ---------------------------------------------------------------------------- 48 48 49 class sc_clock : public sc_signal<bool> 50 { 51 ////// 52 // Internal 53 void init (); 54 ////// 55 private: 56 typedef bool data_type; 57 typedef sc_signal<bool> base_type; 58 typedef sc_clock this_type; 49 class sc_clock : public sc_signal<bool> { 50 /////////// 51 // Internal 52 void init (); 53 /////////// 59 54 60 public: 61 sc_clock(); 62 /*virtual */~sc_clock(); 63 // Changes from LRM : 64 // We use "const char *" instead of "sc_module_name" because we don't need 65 // to add a module name in the stack when constructing sc_clock ! 66 explicit sc_clock(const char *name_); 67 sc_clock(const char *name_, 68 const sc_time& period_, 69 double duty_cycle_ = 0.5, 70 const sc_time& start_time_ = SC_ZERO_TIME, 71 bool posedge_first_ = true ); 72 sc_clock(const char *name_, 73 double period_, 74 double duty_cycle_ = 0.5, 75 double start_time_ = 0.0, 76 bool posedge_first_ = true ); 55 private: 56 typedef bool data_type; 57 typedef sc_signal<bool> base_type; 58 typedef sc_clock this_type; 77 59 78 static const char *const kind_string; 79 //virtual const char *kind () const; 80 81 /*inline*/ this_type& operator = ( const data_type& value_); 60 public: 61 sc_clock(); 62 ~sc_clock(); 63 64 // Changes from LRM : 65 // We use "const char *" instead of "sc_module_name" because we don't need 66 // to add a module name in the stack when constructing sc_clock ! 67 68 explicit sc_clock(const char * name_); 69 sc_clock(const char * name_, 70 const sc_time & period_, 71 double duty_cycle_ = 0.5, 72 const sc_time & start_time_ = SC_ZERO_TIME, 73 bool posedge_first_ = true); 82 74 83 bool posedge_first; 75 sc_clock(const char *name_, 76 double period_, 77 double duty_cycle_ = 0.5, 78 double start_time_ = 0.0, 79 bool posedge_first_ = true); 80 81 static const char * const kind_string; 82 83 /*inline*/ this_type & operator = (const data_type & value_); 84 85 bool posedge_first; 84 86 }; 85 87 … … 88 90 #endif /* __SC_CLOCK_EXT_H__ */ 89 91 92 /* 93 # Local Variables: 94 # tab-width: 4; 95 # c-basic-offset: 4; 96 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 97 # indent-tabs-mode: nil; 98 # End: 99 # 100 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 101 */ 102 -
sources/src/sc_event.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : sc_event.cc |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : 09_07_2004 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : sc_event.cc | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 09_07_2004 | 10 | | 11 \------------------------------------------------------------*/ 12 12 13 13 /* … … 36 36 37 37 #include <iostream> 38 38 39 #include "sc_event.h" 39 40 #include "sc_interface.h" 40 41 #include "sc_port_ext.h" 42 41 43 #ifdef HAVE_CONFIG_H 42 44 #include "config.h" … … 52 54 // ---------------------------------------------------------------------------- 53 55 54 ostream& operator << (ostream &o, const sc_event &s) 55 { 56 o << get_name (s.get_interface().get_pointer()) << "."; 57 switch (s.get_flag ()) { 58 case sc_event::VAL: return o << "val()"; 59 case sc_event::NEG: return o << "neg()"; 60 case sc_event::POS: return o << "pos()"; 61 default: 62 cerr << "Internal error : unknown event flag.\n"; 63 exit (13); 64 } 56 ostream & operator << (ostream & o, const sc_event & s) { 57 o << get_name (s.get_interface().get_pointer()) << "."; 58 switch (s.get_flag ()) { 59 case sc_event::VAL: 60 return o << "val()"; 61 case sc_event::NEG: 62 return o << "neg()"; 63 case sc_event::POS: 64 return o << "pos()"; 65 default: 66 cerr << "Internal error : unknown event flag.\n"; 67 exit (13); 68 } 65 69 } 66 70 67 sc_event::sc_event (const sc_interface &inter_, 68 flag_t flag_) 69 : interface (inter_) 70 { 71 flag = flag_; 71 sc_event::sc_event (const sc_interface & inter_, flag_t flag_) : interface (inter_) { 72 flag = flag_; 72 73 } 73 74 74 sc_event::~sc_event () 75 { 76 } 75 sc_event::~sc_event() {} 77 76 78 77 } // end of sc_core namespace 79 78 79 /* 80 # Local Variables: 81 # tab-width: 4; 82 # c-basic-offset: 4; 83 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 84 # indent-tabs-mode: nil; 85 # End: 86 # 87 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 88 */ 89 -
sources/src/sc_event.h
r31 r52 14 14 15 15 #include "sc_fwd.h" 16 16 17 #include <iostream> 17 18 … … 19 20 20 21 class sc_event { 21 public : typedef enum { POS, NEG, VAL } flag_t; 22 private: 23 const sc_interface &interface; 24 flag_t flag; 25 public: 26 bool pos () const; 27 sc_event (const sc_interface &, flag_t); 28 ~sc_event (); 22 public : 23 typedef enum { POS, NEG, VAL } flag_t; 29 24 30 // methods 31 const sc_interface& get_interface() const { return interface;}; // CASC specific 32 flag_t get_flag () const { return flag;}; // CASC specific 33 34 // operators 25 private: 26 const sc_interface & interface; 27 flag_t flag; 35 28 36 friend std::ostream& operator << (std::ostream &, const sc_event &); 37 38 sc_event (); 39 /* 40 // LRM 41 sc_event (); 42 private: 43 // disabled 44 sc_event (const sc_event &); 45 sc_event& operator = (const sc_event&); 46 */ 29 public: 30 bool pos() const; 31 sc_event(const sc_interface &, flag_t); 32 ~sc_event(); 33 34 // methods 35 const sc_interface & get_interface() const { 36 return interface; 37 } // CASC specific 38 flag_t get_flag () const { 39 return flag; 40 } // CASC specific 41 42 // operators 43 44 friend std::ostream & operator << (std::ostream &, const sc_event &); 45 46 sc_event (); 47 47 48 }; 48 49 … … 50 51 51 52 #endif /* __SC_EVENT_H__ */ 53 54 /* 55 # Local Variables: 56 # tab-width: 4; 57 # c-basic-offset: 4; 58 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 59 # indent-tabs-mode: nil; 60 # End: 61 # 62 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 63 */ 64 -
sources/src/sc_event_finder.cc
r27 r52 36 36 37 37 #include "sc_event_finder.h" 38 38 39 #ifdef HAVE_CONFIG_H 39 40 #include "config.h" … … 42 43 namespace sc_core { 43 44 44 sc_event_finder::sc_event_finder (/*const*/ sc_core::sc_port_base &p) 45 : a_port (p) 46 { 47 } 45 sc_event_finder::sc_event_finder (/*const*/sc_core::sc_port_base & p) : a_port (p) {} 48 46 49 sc_event_finder::~sc_event_finder () 50 { 51 } 47 sc_event_finder::~sc_event_finder() {} 52 48 53 /*const*/ sc_core::sc_port_base& 54 sc_event_finder::port () /*const*/ 55 { 49 /*const*/ sc_core::sc_port_base & sc_event_finder::port() /*const*/ { 56 50 return a_port; 57 51 } 58 52 59 53 } 54 55 /* 56 # Local Variables: 57 # tab-width: 4; 58 # c-basic-offset: 4; 59 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 60 # indent-tabs-mode: nil; 61 # End: 62 # 63 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 64 */ 65 -
sources/src/sc_event_finder.h
r27 r52 18 18 19 19 class sc_event_finder { 20 /*const*/sc_core::sc_port_base &a_port; 21 public: 22 sc_event_finder (/*const*/ sc_core::sc_port_base&); 23 virtual ~sc_event_finder (); 20 /*const*/sc_core::sc_port_base & a_port; 24 21 25 // methods 26 /*const*/ sc_core::sc_port_base& port () /*const*/; 27 28 // operators 22 public: 23 sc_event_finder(/*const*/ sc_core::sc_port_base &); 24 virtual ~sc_event_finder(); 29 25 30 private: 31 // disabled 32 sc_event_finder (); 33 sc_event_finder (const sc_event_finder &); 34 sc_event_finder& operator = (const sc_event_finder&); 26 // methods 27 // 28 /*const*/ sc_core::sc_port_base& port () /*const*/; 29 30 // operators 31 32 private: 33 // disabled 34 sc_event_finder(); 35 sc_event_finder(const sc_event_finder &); 36 sc_event_finder & operator = (const sc_event_finder &); 35 37 }; 36 38 … … 38 40 39 41 #endif /* __SC_EVENT_FINDER_H__ */ 42 43 /* 44 # Local Variables: 45 # tab-width: 4; 46 # c-basic-offset: 4; 47 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 48 # indent-tabs-mode: nil; 49 # End: 50 # 51 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 52 */ 53 -
sources/src/sc_fwd.h
r4 r52 20 20 ///////////////////////////////////////////////// 21 21 // kernel 22 // 22 ///////////////////////////////////////////////// 23 23 class method_process_t; 24 24 class sc_port_base; … … 36 36 ///////////////////////////////////////////////// 37 37 // Ports & Signals 38 // 38 ///////////////////////////////////////////////// 39 39 template <class T> class sc_in; 40 40 template <class T> class sc_inout; … … 47 47 ///////////////////////////////////////////////// 48 48 // Tracing 49 // 49 ///////////////////////////////////////////////// 50 50 class sc_trace_file; 51 51 52 52 ///////////////////////////////////////////////// 53 53 // lists 54 // 54 ///////////////////////////////////////////////// 55 55 typedef std::vector<method_process_t *> method_process_list_t; 56 56 57 } 58 57 59 58 60 ///////////////////////////////////////////////// 59 61 // Data Types 60 // 62 ///////////////////////////////////////////////// 61 63 namespace sc_dt { 62 64 63 template <int W> class sc_bigint; 64 template <int W> class sc_biguint; 65 template <int W> class sc_int; 66 template <int W> class sc_uint; 67 template <int W> class sc_bv; 68 template <int W> class sc_lv; 69 class sc_unsigned; 70 class sc_signed; 71 class sc_bit; 72 class sc_logic; 65 template <int W> class sc_bigint; 66 template <int W> class sc_biguint; 67 template <int W> class sc_int; 68 template <int W> class sc_uint; 69 template <int W> class sc_bv; 70 template <int W> class sc_lv; 71 class sc_unsigned; 72 class sc_signed; 73 class sc_bit; 74 class sc_logic; 75 73 76 } 74 77 75 78 #endif 76 79 80 /* 81 # Local Variables: 82 # tab-width: 4; 83 # c-basic-offset: 4; 84 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 85 # indent-tabs-mode: nil; 86 # End: 87 # 88 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 89 */ 90 -
sources/src/sc_int.h
r27 r52 36 36 typedef sc_int<1> sc_int_bit_ref_r; 37 37 38 // 38 39 39 #define MASK32(W) ((~ (const uint32)0) >> (sizeof (uint32) * 8 - W)) 40 40 #define MASK64(W) ((~ (const uint64)0) >> (sizeof (uint64) * 8 - W)) 41 // 42 43 template<int W> struct s_int_type { typedef int64 int_type;}; 41 42 template<int W> struct s_int_type { typedef int64 int_type; }; 43 44 44 #define DECLAR_INT_TYPE(W) template<> struct s_int_type<W> { typedef smallest_int int_type; } // not declared as in8 because << operator threats like a character 45 DECLAR_INT_TYPE( 46 DECLAR_INT_TYPE( 47 DECLAR_INT_TYPE( 48 DECLAR_INT_TYPE( 49 DECLAR_INT_TYPE( 50 DECLAR_INT_TYPE( 51 DECLAR_INT_TYPE( 52 DECLAR_INT_TYPE( 45 DECLAR_INT_TYPE(1); 46 DECLAR_INT_TYPE(2); 47 DECLAR_INT_TYPE(3); 48 DECLAR_INT_TYPE(4); 49 DECLAR_INT_TYPE(5); 50 DECLAR_INT_TYPE(6); 51 DECLAR_INT_TYPE(7); 52 DECLAR_INT_TYPE(8); 53 53 #undef DECLAR_INT_TYPE 54 54 55 #define DECLAR_INT_TYPE(W) template<> struct s_int_type<W> { typedef int16 int_type; } 55 56 DECLAR_INT_TYPE( 9); … … 62 63 DECLAR_INT_TYPE(16); 63 64 #undef DECLAR_INT_TYPE 65 64 66 #define DECLAR_INT_TYPE(W) template<> struct s_int_type<W> { typedef int32 int_type; } 65 67 DECLAR_INT_TYPE(17); … … 86 88 // Used for range, concat functions 87 89 88 class sc_int_subref_r 89 { 90 template <int W> friend class sc_dt::sc_int; 91 int left, right; 92 public : int64 val; 93 sc_int_subref_r (int64 val_, int left_, int right_) 94 { 95 val = val_; left = left_; right = right_; 96 } 97 public: 98 inline int64 read () const { return val; } 99 inline const sc_int_subref_r& operator | (const sc_int_subref_r &v) const 100 { print_warning (); return *this; } 101 102 private :void print_warning () const; 90 class sc_int_subref_r { 91 92 template <int W> friend class sc_dt::sc_int; 93 int left, right; 94 95 public : 96 int64 val; 97 sc_int_subref_r(int64 val_, int left_, int right_) { 98 val = val_; left = left_; right = right_; 99 } 100 101 inline int64 read () const { return val; } 102 inline const sc_int_subref_r& operator | (const sc_int_subref_r &v) const { 103 print_warning (); 104 return *this; 105 } 106 107 private : 108 void print_warning () const; 109 103 110 }; 104 111 … … 110 117 111 118 template< int W /* = SC_INTWIDTH */> 112 class sc_int 113 { 114 /***********************/ 115 /* SYSTEMCASS SPECIFIC */ 116 /***********************/ 117 typedef sc_int<W> this_type; 118 typedef typename s_int_type<W>::int_type data_type; 119 120 typedef data_type sc_int_subref; 121 //typedef data_type sc_int_subref_r; 122 /* removed since "operator ," was going wrong */ 123 124 // internal 125 union { 126 val_field<W,(sizeof (data_type) * 8) - W,data_type> vf; /* To compute */ 127 data_type val; /* To return an int reference (read function) */ 128 // data_type valW:W; /* works with little endianess only */ 129 // bool valB[W]; /* removed since 1 bool takes 1 byte */ 130 }; 131 132 /***********************/ 133 /* L R M */ 134 /***********************/ 135 public: 136 sc_int() { val = 0; } 137 // sc_int(data_type val_) { val = 0; write (val_); } 138 sc_int (const char *a) { val = 0; write (std::atoi (a)); } 139 sc_int (unsigned short a){ val = 0; write (a); } 140 sc_int (short a) { val = 0; write (a); } 141 sc_int (unsigned long a) { val = 0; write (a); } 142 sc_int (long a) { val = 0; write (a); } 143 sc_int (unsigned int a) { val = 0; write (a); } 144 sc_int (int a) { val = 0; write (a); } 145 sc_int (int64 a) { val = 0; write (a); } 146 sc_int (uint64 a) { val = 0; write (a); } 147 sc_int (double a) { val = 0; write (a); } 148 149 template <int W2> sc_int (const sc_int<W2> &val_) { val = 0; write (val_.read());} 150 /* this template doesn't redefine default copy constructor of sc_int. 151 * So, we define by this way 152 */ 153 154 sc_int (const sc_int &val_) { val = val_.val; } 155 sc_int (const sc_int_subref_r &a) { val = 0; write (a); } 119 class sc_int { 120 121 /***********************/ 122 /* SYSTEMCASS SPECIFIC */ 123 /***********************/ 124 typedef sc_int<W> this_type; 125 typedef typename s_int_type<W>::int_type data_type; 126 127 typedef data_type sc_int_subref; 128 129 // internal 130 union { 131 val_field<W, (sizeof (data_type) * 8) - W,data_type> vf; /* To compute */ 132 data_type val; /* To return an int reference (read function) */ 133 }; 134 135 136 /***********************/ 137 /* L R M */ 138 /***********************/ 139 public: 140 sc_int() { val = 0; } 141 sc_int (const char * a) { val = 0; write (std::atoi (a)); } 142 sc_int (unsigned short a) { val = 0; write (a); } 143 sc_int (short a) { val = 0; write (a); } 144 sc_int (unsigned long a) { val = 0; write (a); } 145 sc_int (long a) { val = 0; write (a); } 146 sc_int (unsigned int a) { val = 0; write (a); } 147 sc_int (int a) { val = 0; write (a); } 148 sc_int (int64 a) { val = 0; write (a); } 149 sc_int (uint64 a) { val = 0; write (a); } 150 sc_int (double a) { val = 0; write (a); } 151 152 template <int W2> sc_int (const sc_int<W2> &val_) { val = 0; write (val_.read());} 153 /* this template doesn't redefine default copy constructor of sc_int. 154 * So, we define by this way 155 */ 156 157 sc_int (const sc_int &val_) { val = val_.val; } 158 sc_int (const sc_int_subref_r & a) { val = 0; write (a); } 156 159 /* the user needs to cast explicitly result of range () method. */ 157 160 158 /***********************/ 159 /* SYSTEMCASS SPECIFIC */ 160 /***********************/ 161 162 /***********************/ 163 /* SYSTEMCASS SPECIFIC */ 164 /***********************/ 165 166 // read/write 167 inline const data_type& read() const { return val; } 168 inline void write(data_type val_) { vf.valW = val_; } 169 template <int W2> inline void write (const sc_int<W2> val_) { write (val_.read ()); } 170 inline void write (const sc_int_subref_r& s) { write (s.read()); } 171 172 /***********************/ 173 /* L R M */ 174 /***********************/ 175 176 // operators 177 inline operator const data_type & () const { 178 return read (); 179 } 180 181 template <typename T> inline sc_int& operator = (const T& val_) { 182 write (val_); 183 return *this; 184 } 185 186 inline sc_int & operator = (const sc_int_subref_r& a) { 187 write (a); 188 return *this; 189 } 190 191 // explicit conversions 192 inline uint32 to_uint() const { return val & MASK32(W); } 193 inline int32 to_int() const { return val & MASK32(W); } 194 inline uint64 to_uint64() const { return val & MASK64(W); } 195 inline int64 to_int64() const { return val & MASK64(W); } 196 197 // explicit conversion to character string 198 const sc_string to_string(sc_numrep numrep = SC_DEC) const { 199 return sc_dt::to_string (val, W, numrep); 200 } 201 const sc_string to_dec() const { return to_string (SC_DEC); } 202 const sc_string to_bin() const { return to_string (SC_BIN); } 203 const sc_string to_oct() const { return to_string (SC_OCT); } 204 const sc_string to_hex() const { return to_string (SC_HEX); } 205 206 // arithmetic 207 #define DEFINE_OPERATOR(OPER) \ 208 template <typename T> \ 209 inline sc_int & operator OPER (T v) \ 210 { vf.valW OPER v; return *this; } 211 212 DEFINE_OPERATOR(<<=) 213 DEFINE_OPERATOR(>>=) 214 DEFINE_OPERATOR(+=) 215 DEFINE_OPERATOR(-=) 216 DEFINE_OPERATOR(*=) 217 DEFINE_OPERATOR(/=) 218 DEFINE_OPERATOR(%=) 219 DEFINE_OPERATOR(&=) 220 DEFINE_OPERATOR(|=) 221 DEFINE_OPERATOR(^=) 222 #undef DEFINE_OPERATOR 223 224 inline sc_int_bit_ref & operator [] (int v) { 225 return (vf.valW >> v) & 1; 226 } 227 inline sc_int_bit_ref_r & operator [] (int v) const { 228 return (vf.valW >> v) & 1; 229 } 230 231 template <int W2> 232 inline sc_int<W + W2> operator , (const sc_int<W2> & b) const { 233 sc_int<W + W2> res = read() << W2; res += b.read(); 234 return res; 235 } 236 237 inline sc_int<W + 1> operator , (bool b) const { 238 sc_int<W + 1> res = read(); res <<= 1; res += b; 239 return res; 240 } 241 242 template <int W2> 243 inline sc_int<W2> operator , (const sc_int_subref_r &v) const { 244 std::cerr << "Warning : \n"; 245 return sc_int<W2> (v.read()); 246 } 247 248 inline sc_int_subref range (int left, int right) { 249 return (data_type)((data_type) (((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) & val) >> right; 250 } 251 252 inline sc_int_subref_r range (int left, int right) const { 253 return sc_int_subref_r (((data_type) (((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) & val) >> right, left, right); 254 } 161 255 #if 0 162 bool is_negative () const { 163 return (valW >> (W-1)) == 1; 164 } 256 std::cerr << "range(" << left << "," << right << ")\n"; 257 std::cerr << "val = " << val << "\n"; 258 std::cerr << "~0 >> " << (sizeof (data_type) * 8 - left - 1) << " = " << (data_type) (((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) << "\n"; 259 std::cerr << ((data_type) ((((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) & val) >> right) << "\n"; 260 std::cerr << "data_type = " << sizeof (data_type) << "\n"; 165 261 #endif 166 // read/write167 inline const data_type& read() const { return val; }168 inline void write(data_type val_) { vf.valW = val_; }169 template <int W2> inline void write (const sc_int<W2> val_) { write (val_.read ()); }170 //inline void write (const sc_int<W> val_) { write (val_.read()); };171 inline void write (const sc_int_subref_r& s) { write (s.read()); }172 173 /***********************/174 /* L R M */175 /***********************/176 // operators177 inline operator const data_type& () const { return read (); }178 // inline void write(int64 val_) { val = val_ & MASK64(W); }179 // inline void write(signed int val_) { val = val_ & MASK32(W); }180 template <typename T> inline sc_int& operator = (const T& val_)181 { write (val_); return *this; }182 inline sc_int& operator = (const sc_int_subref_r& a)183 { write (a); return *this; }184 185 // explicit conversions186 inline uint32 to_uint () const {return val & MASK32(W);};187 inline int32 to_int () const {return val & MASK32(W);};188 inline uint64 to_uint64 () const {return val & MASK64(W);};189 inline int64 to_int64 () const {return val & MASK64(W);};190 191 // explicit conversion to character string192 const sc_string to_string ( sc_numrep numrep = SC_DEC ) const193 { return sc_dt::to_string (val, W, numrep); }194 const sc_string to_dec() const { return to_string (SC_DEC); }195 const sc_string to_bin() const { return to_string (SC_BIN); }196 const sc_string to_oct() const { return to_string (SC_OCT); }197 const sc_string to_hex() const { return to_string (SC_HEX); }198 199 // arithmetic200 #define DEFINE_OPERATOR(OPER) \201 template <typename T> \202 inline sc_int& operator OPER (T v) \203 { vf.valW OPER v; return *this; }204 205 DEFINE_OPERATOR(<<=)206 DEFINE_OPERATOR(>>=)207 DEFINE_OPERATOR(+=)208 DEFINE_OPERATOR(-=)209 DEFINE_OPERATOR(*=)210 DEFINE_OPERATOR(/=)211 DEFINE_OPERATOR(%=)212 DEFINE_OPERATOR(&=)213 DEFINE_OPERATOR(|=)214 DEFINE_OPERATOR(^=)215 #undef DEFINE_OPERATOR216 217 inline sc_int_bit_ref& operator [] (int v)218 { return (vf.valW >> v) & 1; }219 inline sc_int_bit_ref_r& operator [] (int v) const220 { return (vf.valW >> v) & 1; }221 222 template <int W2>223 inline sc_int<W+W2> operator , (const sc_int<W2> &b) const224 { sc_int<W+W2> res = read() << W2; res += b.read(); return res; }225 #if 0226 std::cerr << "[" << to_bin() << "," << b.to_bin() << " = " << res.to_bin() << "]\n";227 #endif228 229 inline sc_int<W+1> operator , (bool b) const230 { sc_int<W+1> res = read(); res <<= 1; res += b; return res; }231 #if 0232 std::cerr << "[" << to_bin() << "," << b.to_bin() << " = " << res.to_bin() << "]\n";233 #endif234 235 template <int W2>236 inline sc_int<W2> operator , (const sc_int_subref_r &v) const237 { std::cerr << "Warning : \n"; return sc_int<W2> (v.read()); }238 239 inline sc_int_subref range (int left, int right)240 { return (data_type)((data_type) (((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) & val) >> right; }241 242 inline sc_int_subref_r range (int left, int right) const243 { return sc_int_subref_r (((data_type) (((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) & val) >> right, left, right); }244 #if 0245 std::cerr << "range(" << left << "," << right << ")\n";246 std::cerr << "val = " << val << "\n";247 std::cerr << "~0 >> " << (sizeof (data_type) * 8 - left - 1) << " = " << (data_type) (((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) << "\n";248 std::cerr << ((data_type) ((((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) & val) >> right) << "\n";249 std::cerr << "data_type = " << sizeof (data_type) << "\n";250 #endif251 262 252 263 }; 253 264 254 inline std::ostream& operator << (std::ostream &o, const sc_int_subref_r& s) 255 { return o << s.val; } 265 inline std::ostream & operator << (std::ostream &o, const sc_int_subref_r & s) { 266 return o << s.val; 267 } 268 269 #undef MASK32 270 #undef MASK64 256 271 257 272 } /* end of sc_dt namespace */ … … 259 274 #endif /* __SC_INT_H__ */ 260 275 276 /* 277 # Local Variables: 278 # tab-width: 4; 279 # c-basic-offset: 4; 280 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 281 # indent-tabs-mode: nil; 282 # End: 283 # 284 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 285 */ 286 -
sources/src/sc_interface.cc
r31 r52 34 34 */ 35 35 36 #include <iostream> 37 #include <map> 38 #include <cstdlib> //exit 39 36 40 #include "sc_interface.h" 37 41 #include "sc_event.h" 38 42 #include "assert.h" 39 #include <iostream> 40 #include <map> 43 41 44 #ifdef HAVE_CONFIG_H 42 45 #include "config.h" 43 46 #endif 44 #include <cstdlib> //exit45 47 46 48 using namespace std; 47 49 48 50 namespace sc_core { 51 49 52 struct interface_infos_t { 50 size_t data_size_in_bytes; 51 sc_event default_event; 52 interface_infos_t () 53 { 54 exit(12); 55 } 56 interface_infos_t (size_t s, sc_event e) 57 : data_size_in_bytes(s), default_event (e) 58 { 59 } 53 size_t data_size_in_bytes; 54 sc_event default_event; 55 interface_infos_t() { 56 exit(12); 57 } 58 interface_infos_t (size_t s, sc_event e) : data_size_in_bytes(s), default_event(e) {} 60 59 }; 61 typedef std::map<const sc_interface*,interface_infos_t> interface2infos_t; 60 61 typedef std::map<const sc_interface *,interface_infos_t> interface2infos_t; 62 62 static interface2infos_t interface2infos; 63 63 64 } 64 65 … … 71 72 // ---------------------------------------------------------------------------- 72 73 73 #if 0 74 static 75 ostream& 76 operator << (ostream &o, 77 const sc_interface &i) 78 { 79 return o << hex << &i; 80 } 81 #endif 82 83 /* 84 void 85 sc_interface::register_port (sc_port_base & port_, const char *if_typename_) 86 { 87 } 88 */ 89 90 sc_interface::~sc_interface () 91 {} 74 sc_interface::~sc_interface() {} 92 75 93 76 // constructor 94 sc_interface::sc_interface () 95 { 77 sc_interface::sc_interface() { 96 78 pointer = NULL; // => not assigned 97 79 } 98 80 99 void 100 sc_interface::init (size_t s) const 101 { 102 interface2infos_t::value_type pair (this, 103 interface_infos_t (s,sc_event (*this, sc_event::VAL))); 104 interface2infos.insert (pair); 81 82 void sc_interface::init (size_t s) const { 83 interface2infos_t::value_type pair (this, interface_infos_t(s,sc_event (*this, sc_event::VAL))); 84 interface2infos.insert(pair); 105 85 } 106 86 107 size_t 108 sc_interface::data_size_in_bytes () const 109 { 110 interface2infos_t::iterator i = interface2infos.find (this); 87 size_t sc_interface::data_size_in_bytes () const { 88 interface2infos_t::iterator i = interface2infos.find(this); 111 89 #ifdef CONFIG_DEBUG 112 if (i == interface2infos.end()) {113 114 115 90 if (i == interface2infos.end()) { 91 cerr << "Internal error : can't find data size of " << this << "\n"; 92 exit (90); 93 } 116 94 #endif 117 95 return i->second.data_size_in_bytes; 118 96 } 119 97 120 const sc_event & 121 sc_interface::default_event () const 122 { 123 interface2infos_t::iterator i = interface2infos.find (this); 98 99 const sc_event & sc_interface::default_event () const { 100 interface2infos_t::iterator i = interface2infos.find(this); 124 101 #ifdef CONFIG_DEBUG 125 126 127 128 102 if (i == interface2infos.end ()) { 103 cerr << "Internal error : can't find default event of " << this << "\n"; 104 exit (90); 105 } 129 106 #endif 130 107 return i->second.default_event; 131 108 } 132 109 110 111 /* 112 # Local Variables: 113 # tab-width: 4; 114 # c-basic-offset: 4; 115 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 116 # indent-tabs-mode: nil; 117 # End: 118 # 119 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 120 */ 121 -
sources/src/sc_interface.h
r51 r52 20 20 namespace sc_core { 21 21 22 22 23 // ---------------------------------------------------------------------------- 23 24 // CLASS : sc_interface … … 25 26 // 26 27 // ---------------------------------------------------------------------------- 27 class sc_interface 28 { 29 /////////// 30 // Internal 31 private: tab_t *pointer; // pointeur dans la table de signaux 32 // NULL pour les sc_out/sc_inout 33 public: inline tab_t *get_pointer () const { return pointer; } 34 public: inline void set_pointer (tab_t *i) { pointer = i; } 35 public: size_t data_size_in_bytes () const; /* nb of bytes */ 36 protected:void init (size_t) const; 37 /////////// 38 39 ////// 40 // LRM 41 public: 42 /* 43 virtual void register_port (sc_port_base & port_, const char *if_typename_); 44 */ 45 /*virtual */const sc_event & default_event () const; 46 /*virtual */~ sc_interface (); 47 protected: 48 // constructor 28 29 class sc_interface { 30 /////////// 31 // Internal 32 private: 33 tab_t * pointer; // pointeur dans la table de signaux 34 // NULL pour les sc_out/sc_inout 35 36 public: 37 inline tab_t * get_pointer() const { return pointer; } 38 inline void set_pointer(tab_t * i) { pointer = i; } 39 size_t data_size_in_bytes() const; /* nb of bytes */ 40 41 protected: 42 void init(size_t) const; 43 44 public: 45 const sc_event & default_event() const; 46 ~sc_interface(); 47 48 protected: 49 49 sc_interface (); 50 private: 51 // disabled 52 sc_interface (const sc_interface &); 50 51 private: 52 // disabled 53 // QM: required for compilation... 54 sc_interface(const sc_interface &); 53 55 sc_interface & operator = (const sc_interface &); 54 //////55 56 }; 56 57 … … 58 59 59 60 #endif /* __SC_INTERFACE_H__ */ 61 62 /* 63 # Local Variables: 64 # tab-width: 4; 65 # c-basic-offset: 4; 66 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 67 # indent-tabs-mode: nil; 68 # End: 69 # 70 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 71 */ 72 -
sources/src/sc_localvar.h
r1 r52 20 20 21 21 template <typename T> 22 class sc_localvar : public sc_signal_base 23 { 22 class sc_localvar : public sc_signal_base { 24 23 25 public: sc_localvar (const T& object) 26 { init (object); } 24 public: 25 sc_localvar (const T & object) { 26 init (object); 27 } 27 28 28 private: void init (const T& object) 29 { 30 set_pointer ((tab_t*) &object); 31 set_kind ("sc_localvar"); 32 sc_interface::init (sizeof (object)); 33 bind (*((sc_signal_base*)this)); 34 } 29 private: 30 void init (const T & object) { 31 set_pointer ((tab_t *) &object); 32 set_kind ("sc_localvar"); 33 sc_interface::init (sizeof(object)); 34 bind (*((sc_signal_base *) this)); 35 } 36 35 37 }; 36 38 … … 39 41 #endif 40 42 43 /* 44 # Local Variables: 45 # tab-width: 4; 46 # c-basic-offset: 4; 47 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 48 # indent-tabs-mode: nil; 49 # End: 50 # 51 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 52 */ 53 -
sources/src/sc_logic.cc
r27 r52 40 40 41 41 #include "sc_logic.h" 42 42 43 #ifdef HAVE_CONFIG_H 43 44 #include "config.h" … … 46 47 namespace sc_dt { 47 48 48 const sc_logic SC_LOGIC_0 49 const sc_logic SC_LOGIC_1 50 const sc_logic SC_LOGIC_Z 51 const sc_logic SC_LOGIC_X 49 const sc_logic SC_LOGIC_0(Log_0); 50 const sc_logic SC_LOGIC_1(Log_1); 51 const sc_logic SC_LOGIC_Z(Log_Z); 52 const sc_logic SC_LOGIC_X(Log_X); 52 53 53 54 } /* end of sc_dt namespace */ 54 55 56 /* 57 # Local Variables: 58 # tab-width: 4; 59 # c-basic-offset: 4; 60 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 61 # indent-tabs-mode: nil; 62 # End: 63 # 64 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 65 */ 66 -
sources/src/sc_logic.h
r27 r52 29 29 // ---------------------------------------------------------------------------- 30 30 31 enum sc_logic_value_t 32 { 33 Log_0 = 0, 34 Log_1, 35 Log_Z, 36 Log_X 31 enum sc_logic_value_t { 32 Log_0 = 0, 33 Log_1, 34 Log_Z, 35 Log_X 37 36 }; 38 37 39 class sc_logic 40 { 41 public: 42 // constructors & destructor 43 sc_logic (); 44 sc_logic (const sc_logic & a); 45 sc_logic (sc_logic_value_t v); 46 explicit sc_logic (bool a); 47 explicit sc_logic (char a); 48 explicit sc_logic (int a); 49 explicit sc_logic (const sc_bit & a); 50 ~sc_logic (); 51 // assignment operators 52 sc_logic & operator = (const sc_logic & a); 53 sc_logic & operator = (sc_logic_value_t v); 54 sc_logic & operator = (bool a); 55 sc_logic & operator = (char a); 56 sc_logic & operator = (int a); 57 sc_logic & operator = (const sc_bit & a); 58 // bitwise assignment operators 59 sc_logic & operator &= (const sc_logic & b); 60 sc_logic & operator &= (sc_logic_value_t v); 61 sc_logic & operator &= (bool b); 62 sc_logic & operator &= (char b); 63 sc_logic & operator &= (int b); 64 sc_logic & operator |= (const sc_logic & b); 65 sc_logic & operator |= (sc_logic_value_t v); 66 sc_logic & operator |= (bool b); 67 sc_logic & operator |= (char b); 68 sc_logic & operator |= (int b); 69 sc_logic & operator ^= (const sc_logic & b); 70 sc_logic & operator ^= (sc_logic_value_t v); 71 sc_logic & operator ^= (bool b); 72 sc_logic & operator ^= (char b); 73 sc_logic & operator ^= (int b); 74 // bitwise complement 75 const sc_logic operator ~ () const; 76 sc_logic & b_not (); 77 // bitwise and 78 friend const sc_logic operator & (const sc_logic & a, const sc_logic & b); 79 friend const sc_logic operator & (const sc_logic & a, sc_logic_value_t b); 80 friend const sc_logic operator & (const sc_logic & a, bool b); 81 friend const sc_logic operator & (const sc_logic & a, char b); 82 friend const sc_logic operator & (const sc_logic & a, int b); 83 friend const sc_logic operator & (sc_logic_value_t a, const sc_logic & b); 84 friend const sc_logic operator & (bool a, const sc_logic & b); 85 friend const sc_logic operator & (char a, const sc_logic & b); 86 friend const sc_logic operator & (int a, const sc_logic & b); 87 // bitwise or 88 friend const sc_logic operator | (const sc_logic & a, const sc_logic & b); 89 friend const sc_logic operator | (const sc_logic & a, sc_logic_value_t b); 90 friend const sc_logic operator | (const sc_logic & a, bool b); 91 friend const sc_logic operator | (const sc_logic & a, char b); 92 friend const sc_logic operator | (const sc_logic & a, int b); 93 friend const sc_logic operator | (sc_logic_value_t a, const sc_logic & b); 94 friend const sc_logic operator | (bool a, const sc_logic & b); 95 friend const sc_logic operator | (char a, const sc_logic & b); 96 friend const sc_logic operator | (int a, const sc_logic & b); 97 // bitwise xor 98 friend const sc_logic operator ^ (const sc_logic & a, const sc_logic & b); 99 friend const sc_logic operator ^ (const sc_logic & a, sc_logic_value_t b); 100 friend const sc_logic operator ^ (const sc_logic & a, bool b); 101 friend const sc_logic operator ^ (const sc_logic & a, char b); 102 friend const sc_logic operator ^ (const sc_logic & a, int b); 103 friend const sc_logic operator ^ (sc_logic_value_t a, const sc_logic & b); 104 friend const sc_logic operator ^ (bool a, const sc_logic & b); 105 friend const sc_logic operator ^ (char a, const sc_logic & b); 106 friend const sc_logic operator ^ (int a, const sc_logic & b); 107 // relational operators and functions 108 friend bool operator == (const sc_logic & a, const sc_logic & b); 109 friend bool operator == (const sc_logic & a, 110 sc_logic_value_t b); 111 friend bool operator == (const sc_logic & a, bool b); 112 friend bool operator == (const sc_logic & a, char b); 113 friend bool operator == (const sc_logic & a, int b); 114 friend bool operator == (sc_logic_value_t a, const sc_logic & b); 115 friend bool operator == (bool a, const sc_logic & b); 116 friend bool operator == (char a, const sc_logic & b); 117 friend bool operator == (int a, const sc_logic & b); 118 friend bool operator != (const sc_logic & a, const sc_logic & b); 119 friend bool operator != (const sc_logic & a, sc_logic_value_t b); 120 friend bool operator != (const sc_logic & a, bool b); 121 friend bool operator != (const sc_logic & a, char b); 122 friend bool operator != (const sc_logic & a, int b); 123 friend bool operator != (sc_logic_value_t a, const sc_logic & b); 124 friend bool operator != (bool a, const sc_logic & b); 125 friend bool operator != (char a, const sc_logic & b); 126 friend bool operator != (int a, const sc_logic & b); 127 // explicit conversions 128 sc_logic_value_t value () const; 129 bool is_01 () const; 130 bool to_bool () const; 131 char to_char () const; 132 /* 133 // other methods 134 void print (std::ostream & os = std::cout) const; 135 void scan (std::istream & is = std::cin); 136 */ 137 // memory (de);allocation 138 static void *operator new (size_t, void *p); // placement new 139 static void *operator new (size_t sz); 140 static void operator delete (void *p, size_t sz); 141 static void *operator new[] (size_t sz); 142 static void operator delete[] (void *p, size_t sz); 143 private: 144 // disabled 38 39 class sc_logic { 40 public: 41 // constructors & destructor 42 sc_logic(); 43 sc_logic(const sc_logic & a); 44 sc_logic(sc_logic_value_t v); 45 explicit sc_logic(bool a); 46 explicit sc_logic(char a); 47 explicit sc_logic(int a); 48 explicit sc_logic(const sc_bit & a); 49 ~sc_logic(); 50 // assignment operators 51 sc_logic & operator = (const sc_logic & a); 52 sc_logic & operator = (sc_logic_value_t v); 53 sc_logic & operator = (bool a); 54 sc_logic & operator = (char a); 55 sc_logic & operator = (int a); 56 sc_logic & operator = (const sc_bit & a); 57 // bitwise assignment operators 58 sc_logic & operator &= (const sc_logic & b); 59 sc_logic & operator &= (sc_logic_value_t v); 60 sc_logic & operator &= (bool b); 61 sc_logic & operator &= (char b); 62 sc_logic & operator &= (int b); 63 sc_logic & operator |= (const sc_logic & b); 64 sc_logic & operator |= (sc_logic_value_t v); 65 sc_logic & operator |= (bool b); 66 sc_logic & operator |= (char b); 67 sc_logic & operator |= (int b); 68 sc_logic & operator ^= (const sc_logic & b); 69 sc_logic & operator ^= (sc_logic_value_t v); 70 sc_logic & operator ^= (bool b); 71 sc_logic & operator ^= (char b); 72 sc_logic & operator ^= (int b); 73 // bitwise complement 74 const sc_logic operator ~ () const; 75 sc_logic & b_not(); 76 // bitwise and 77 friend const sc_logic operator & (const sc_logic & a, const sc_logic & b); 78 friend const sc_logic operator & (const sc_logic & a, sc_logic_value_t b); 79 friend const sc_logic operator & (const sc_logic & a, bool b); 80 friend const sc_logic operator & (const sc_logic & a, char b); 81 friend const sc_logic operator & (const sc_logic & a, int b); 82 friend const sc_logic operator & (sc_logic_value_t a, const sc_logic & b); 83 friend const sc_logic operator & (bool a, const sc_logic & b); 84 friend const sc_logic operator & (char a, const sc_logic & b); 85 friend const sc_logic operator & (int a, const sc_logic & b); 86 // bitwise or 87 friend const sc_logic operator | (const sc_logic & a, const sc_logic & b); 88 friend const sc_logic operator | (const sc_logic & a, sc_logic_value_t b); 89 friend const sc_logic operator | (const sc_logic & a, bool b); 90 friend const sc_logic operator | (const sc_logic & a, char b); 91 friend const sc_logic operator | (const sc_logic & a, int b); 92 friend const sc_logic operator | (sc_logic_value_t a, const sc_logic & b); 93 friend const sc_logic operator | (bool a, const sc_logic & b); 94 friend const sc_logic operator | (char a, const sc_logic & b); 95 friend const sc_logic operator | (int a, const sc_logic & b); 96 // bitwise xor 97 friend const sc_logic operator ^ (const sc_logic & a, const sc_logic & b); 98 friend const sc_logic operator ^ (const sc_logic & a, sc_logic_value_t b); 99 friend const sc_logic operator ^ (const sc_logic & a, bool b); 100 friend const sc_logic operator ^ (const sc_logic & a, char b); 101 friend const sc_logic operator ^ (const sc_logic & a, int b); 102 friend const sc_logic operator ^ (sc_logic_value_t a, const sc_logic & b); 103 friend const sc_logic operator ^ (bool a, const sc_logic & b); 104 friend const sc_logic operator ^ (char a, const sc_logic & b); 105 friend const sc_logic operator ^ (int a, const sc_logic & b); 106 // relational operators and functions 107 friend bool operator == (const sc_logic & a, const sc_logic & b); 108 friend bool operator == (const sc_logic & a, sc_logic_value_t b); 109 friend bool operator == (const sc_logic & a, bool b); 110 friend bool operator == (const sc_logic & a, char b); 111 friend bool operator == (const sc_logic & a, int b); 112 friend bool operator == (sc_logic_value_t a, const sc_logic & b); 113 friend bool operator == (bool a, const sc_logic & b); 114 friend bool operator == (char a, const sc_logic & b); 115 friend bool operator == (int a, const sc_logic & b); 116 friend bool operator != (const sc_logic & a, const sc_logic & b); 117 friend bool operator != (const sc_logic & a, sc_logic_value_t b); 118 friend bool operator != (const sc_logic & a, bool b); 119 friend bool operator != (const sc_logic & a, char b); 120 friend bool operator != (const sc_logic & a, int b); 121 friend bool operator != (sc_logic_value_t a, const sc_logic & b); 122 friend bool operator != (bool a, const sc_logic & b); 123 friend bool operator != (char a, const sc_logic & b); 124 friend bool operator != (int a, const sc_logic & b); 125 126 // explicit conversions 127 sc_logic_value_t value() const; 128 bool is_01() const; 129 bool to_bool() const; 130 char to_char() const; 131 132 // memory (de);allocation 133 static void * operator new (size_t, void * p); // placement new 134 static void * operator new (size_t sz); 135 static void operator delete (void * p, size_t sz); 136 static void * operator new [] (size_t sz); 137 static void operator delete [] (void * p, size_t sz); 138 139 private: 140 // disabled 145 141 explicit sc_logic (const char *); 146 142 sc_logic & operator = (const char *); … … 155 151 156 152 #endif /* __SC_LOGIC_H__ */ 153 154 /* 155 # Local Variables: 156 # tab-width: 4; 157 # c-basic-offset: 4; 158 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 159 # indent-tabs-mode: nil; 160 # End: 161 # 162 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 163 */ 164 -
sources/src/sc_lv.h
r27 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __SC_LV_H__ 13 14 #define __SC_LV_H__ … … 28 29 namespace sc_dt { 29 30 30 template<int W> struct s_lv_type { typedef uint64 lv_type;}; 31 template<int W> struct s_lv_type { typedef uint64 lv_type; }; 32 31 33 #define DECLAR_LV_TYPE(W) template<> struct s_lv_type<W> { typedef smallest_uint lv_type; }// not declared as uint16 because << operator threats like a character 32 DECLAR_LV_TYPE( 33 DECLAR_LV_TYPE( 34 DECLAR_LV_TYPE( 35 DECLAR_LV_TYPE( 36 DECLAR_LV_TYPE( 37 DECLAR_LV_TYPE( 38 DECLAR_LV_TYPE( 39 DECLAR_LV_TYPE( 34 DECLAR_LV_TYPE(1); 35 DECLAR_LV_TYPE(2); 36 DECLAR_LV_TYPE(3); 37 DECLAR_LV_TYPE(4); 38 DECLAR_LV_TYPE(5); 39 DECLAR_LV_TYPE(6); 40 DECLAR_LV_TYPE(7); 41 DECLAR_LV_TYPE(8); 40 42 #undef DECLAR_LV_TYPE 43 41 44 #define DECLAR_LV_TYPE(W) template<> struct s_lv_type<W> { typedef uint16 lv_type; } 42 DECLAR_LV_TYPE( 45 DECLAR_LV_TYPE(9); 43 46 DECLAR_LV_TYPE(10); 44 47 DECLAR_LV_TYPE(11); … … 49 52 DECLAR_LV_TYPE(16); 50 53 #undef DECLAR_LV_TYPE 54 51 55 #define DECLAR_LV_TYPE(W) template<> struct s_lv_type<W> { typedef uint32 lv_type; } 52 56 DECLAR_LV_TYPE(17); … … 69 73 70 74 71 class sc_lv_base 72 { 73 public: 74 // constructors 75 /* 76 explicit sc_lv_base (int length_ = sc_length_param ().len ()); 77 explicit sc_lv_base (bool a, int length_ = sc_length_param ().len ()); 78 */ 79 sc_lv_base () { } // SYSTEMCASS SPECIFIC 80 sc_lv_base (const char *a); 81 sc_lv_base (const char *a, int length_); 75 class sc_lv_base { 76 77 public: 78 // constructors 79 sc_lv_base() {} // SYSTEMCASS SPECIFIC 80 sc_lv_base(const char * a); 81 sc_lv_base(const char * a, int length_); 82 82 template < class X > sc_lv_base (const sc_lv_base & a); 83 virtual ~ sc_lv_base() {}84 // assignment operators83 virtual ~sc_lv_base() {} 84 // assignment operators 85 85 template < class X > sc_lv_base & operator = (const sc_lv_base & a); 86 sc_lv_base & operator = (const char * a);86 sc_lv_base & operator = (const char * a); 87 87 sc_lv_base & operator = (const bool * a); 88 88 sc_lv_base & operator = (const sc_logic * a); 89 89 sc_lv_base & operator = (const sc_unsigned & a); 90 90 sc_lv_base & operator = (const sc_signed & a); 91 /*92 sc_lv_base & operator = (const sc_uint_base & a);93 sc_lv_base & operator = (const sc_int_base & a);94 */95 91 sc_lv_base & operator = (unsigned long a); 96 92 sc_lv_base & operator = (long a); … … 100 96 sc_lv_base & operator = (int64 a); 101 97 102 // methods103 int length() const;104 bool is_01() const;98 // methods 99 int length() const; 100 bool is_01() const; 105 101 }; 106 102 107 103 108 template < int W > class sc_lv:public sc_lv_base 109 { 110 /***********************/ 111 /* SYSTEMCASS SPECIFIC */ 112 /***********************/ 113 typedef sc_lv<W> this_type; 114 typedef typename s_lv_type<W>::lv_type data_type; 115 data_type val; 116 public: 117 // constructors 118 sc_lv () { val = 0; } 119 explicit sc_lv (bool init_value) { val = 0; } 120 explicit sc_lv (char init_value) { val = 0; } 121 sc_lv (const char *a) { val = 0; write (atoi (a)); } 122 sc_lv (const bool * a) { val = 0; write (a); } 123 sc_lv (const sc_logic * a) { val = 0; write (a); } 124 sc_lv (const sc_unsigned & a) { val = 0; write (a); } 125 sc_lv (const sc_signed & a) { val = 0; write (a); } 126 /* 127 sc_lv (const sc_uint_base & a); 128 sc_lv (const sc_int_base & a); 129 */ 130 sc_lv (unsigned long a) { val = 0; write (a); } 131 sc_lv (long a) { val = 0; write (a); } 132 sc_lv (unsigned int a) { val = 0; write (a); } 133 sc_lv (int a) { val = 0; write (a); } 134 sc_lv (uint64 a) { val = 0; write (a); } 135 sc_lv (int64 a) { val = 0; write (a); } 136 sc_lv (const sc_lv_base & a) { val = 0; write (a); } 137 sc_lv (const sc_lv < W > &a) { val = 0; write (a); } 138 // assignment operators 104 template < int W > class sc_lv : public sc_lv_base { 105 106 /***********************/ 107 /* SYSTEMCASS SPECIFIC */ 108 /***********************/ 109 110 typedef sc_lv<W> this_type; 111 typedef typename s_lv_type<W>::lv_type data_type; 112 data_type val; 113 114 public: 115 // constructors 116 sc_lv() { val = 0; } 117 explicit sc_lv(bool init_value) { val = 0; } 118 explicit sc_lv (char init_value) { val = 0; } 119 sc_lv(const char * a) { val = 0; write(atoi(a)); } 120 sc_lv(const bool * a) { val = 0; write(a); } 121 sc_lv(const sc_logic * a) { val = 0; write(a); } 122 sc_lv(const sc_unsigned & a) { val = 0; write(a); } 123 sc_lv(const sc_signed & a) { val = 0; write(a); } 124 sc_lv(unsigned long a) { val = 0; write(a); } 125 sc_lv(long a) { val = 0; write(a); } 126 sc_lv(unsigned int a) { val = 0; write(a); } 127 sc_lv(int a) { val = 0; write(a); } 128 sc_lv(uint64 a) { val = 0; write(a); } 129 sc_lv(int64 a) { val = 0; write(a); } 130 sc_lv(const sc_lv_base & a) { val = 0; write(a); } 131 sc_lv(const sc_lv < W > & a) { val = 0; write(a); } 132 133 // assignment operators 139 134 #ifdef LRM 140 template < class X > sc_lv < W > &operator = (const sc_lv_base & a)141 sc_lv < W > &operator = (const sc_lv < W > &a)142 sc_lv < W > &operator = (const char *a)143 sc_lv < W > &operator = (const bool * a)144 sc_lv < W > &operator = (const sc_logic * a)145 sc_lv < W > &operator = (const sc_unsigned & a)146 sc_lv < W > &operator = (const sc_signed & a)135 template < class X > sc_lv < W > & operator = (const sc_lv_base & a); 136 sc_lv < W > & operator = (const sc_lv < W > &a); 137 sc_lv < W > & operator = (const char *a); 138 sc_lv < W > & operator = (const bool * a); 139 sc_lv < W > & operator = (const sc_logic * a); 140 sc_lv < W > & operator = (const sc_unsigned & a); 141 sc_lv < W > & operator = (const sc_signed & a); 147 142 #endif // LRM 148 template <typename T> inline sc_lv& operator = (const T& val_) 149 { write (val_); return *this; } 150 /* 151 sc_lv < W > &operator = (const sc_uint_base & a); 152 sc_lv < W > &operator = (const sc_int_base & a); 153 */ 154 sc_lv < W > &operator = (unsigned long a); 155 sc_lv < W > &operator = (long a); 156 sc_lv < W > &operator = (unsigned int a); 157 sc_lv < W > &operator = (int a) { val = a; return *this; } 158 sc_lv < W > &operator = (uint64 a); 159 sc_lv < W > &operator = (int64 a); 160 /***********************/ 161 /* SYSTEMCASS SPECIFIC */ 162 /***********************/ 163 // read/write 164 inline void write(data_type val_) { val = val_; } 165 template <int W2> inline void write (const sc_lv<W2> val_) { write (val_.read()); } 143 144 template <typename T> inline sc_lv& operator = (const T& val_) { 145 write (val_); 146 return *this; 147 } 148 sc_lv < W > & operator = (unsigned long a); 149 sc_lv < W > & operator = (long a); 150 sc_lv < W > & operator = (unsigned int a); 151 sc_lv < W > & operator = (int a) { val = a; return *this; } 152 sc_lv < W > & operator = (uint64 a); 153 sc_lv < W > & operator = (int64 a); 154 155 156 /***********************/ 157 /* SYSTEMCASS SPECIFIC */ 158 /***********************/ 159 // read/write 160 inline void write(data_type val_) { 161 val = val_; 162 } 163 template <int W2> inline void write (const sc_lv<W2> val_) { 164 write (val_.read()); 165 } 166 166 167 167 }; … … 170 170 171 171 #endif /* __SC_LV_H__ */ 172 173 /* 174 # Local Variables: 175 # tab-width: 4; 176 # c-basic-offset: 4; 177 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 178 # indent-tabs-mode: nil; 179 # End: 180 # 181 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 182 */ 183 -
sources/src/sc_main.cc
r42 r52 54 54 #endif 55 55 56 // 56 57 57 using namespace std; 58 58 using namespace sc_core; 59 // 60 typedef list<sc_module * >module_list_t;61 62 // 59 60 typedef list<sc_module *> module_list_t; 61 62 63 63 namespace sc_core { 64 64 65 bool 65 bool check_port_dependencies = false; 66 66 #ifdef CONFIG_DEFAULT_RUNTIME_COMPILATION 67 bool 67 bool dynamic_link_of_scheduling_code = true; 68 68 #else 69 bool 70 #endif 71 bool dump_netlist_info= false;72 bool dump_funclist_info= false;73 bool dump_stage= false;74 bool dump_all_graph= false;75 const char * dump_module_hierarchy= NULL;76 bool edit_schedule= false;77 bool keep_generated_code= false;78 bool nobanner= false;79 bool noinitialization= false;80 bool nosimulation= false;81 bool notrace= false;82 bool print_schedule= false;83 bool print_user_resources= false;84 char * save_on_exit= NULL;85 int scheduling_method= NO_SCHEDULING;86 bool use_sensitivity_list= false;87 bool use_port_dependency= false;69 bool dynamic_link_of_scheduling_code = false; 70 #endif 71 bool dump_netlist_info = false; 72 bool dump_funclist_info = false; 73 bool dump_stage = false; 74 bool dump_all_graph = false; 75 const char * dump_module_hierarchy = NULL; 76 bool edit_schedule = false; 77 bool keep_generated_code = false; 78 bool nobanner = false; 79 bool noinitialization = false; 80 bool nosimulation = false; 81 bool notrace = false; 82 bool print_schedule = false; 83 bool print_user_resources = false; 84 char * save_on_exit = NULL; 85 int scheduling_method = NO_SCHEDULING; 86 bool use_sensitivity_list = false; 87 bool use_port_dependency = false; 88 88 89 89 #ifdef _OPENMP 90 bool use_openmp= true;90 bool use_openmp = true; 91 91 #else 92 bool use_openmp = false; 93 #endif 94 95 const char *HELP_STRING = \ 92 bool use_openmp = false; 93 #endif 94 95 96 const char * HELP_STRING = \ 96 97 "\n" 97 98 "--a\n" … … 169 170 170 171 171 static 172 void 173 print_splash_screen () 174 { 175 // Display once 176 if (nobanner == false) 177 cerr << get_splash_screen (); 178 nobanner = true; 172 173 static void print_splash_screen() { 174 // Display once 175 if (nobanner == false) { 176 cerr << get_splash_screen (); 177 } 178 nobanner = true; 179 179 } 180 180 181 static 182 void 183 check_parameters () 184 { 185 if (dump_all_graph) { 186 if (use_port_dependency) 187 cerr << "SystemCASS will dump signal dependency graph.\n"; 188 else 189 cerr << "SystemCASS will dump module dependency graph.\n"; 190 } 191 if (!use_port_dependency && check_port_dependencies) 192 cerr << "Warning : unable to check port dependencies.\n"; 193 if (!use_port_dependency) 194 { 195 use_sensitivity_list = true; 196 scheduling_method = CASS_SCHEDULING; 197 } 198 switch (scheduling_method) { 199 case CASS_SCHEDULING : 200 assert(use_port_dependency == false); 201 break; 202 case BUCHMANN_SCHEDULING : 203 case MOUCHARD_SCHEDULING : 181 182 static void check_parameters() { 183 if (dump_all_graph) { 184 if (use_port_dependency) { 185 cerr << "SystemCASS will dump signal dependency graph.\n"; 186 } 187 else { 188 cerr << "SystemCASS will dump module dependency graph.\n"; 189 } 190 } 191 if (!use_port_dependency && check_port_dependencies) { 192 cerr << "Warning : unable to check port dependencies.\n"; 193 } 204 194 if (!use_port_dependency) { 205 cerr << "Error : " 206 "The choosen scheduling needs port dependencies informations\n"; 207 exit (31); 208 } 209 break; 210 default : 211 cerr << "Error : You need to choose one of the available scheduling :\n" 212 << "- Almost static scheduling like CASS (use sensitivity list)\n" 213 << "- Simple static scheduling (use port dependencies)\n" 214 << "- Entirely static scheduling (use port dependencies)\n"; 215 exit (33); 216 } 217 assert(use_port_dependency || use_sensitivity_list); 195 use_sensitivity_list = true; 196 scheduling_method = CASS_SCHEDULING; 197 } 198 switch (scheduling_method) { 199 case CASS_SCHEDULING : 200 assert(use_port_dependency == false); 201 break; 202 case BUCHMANN_SCHEDULING : 203 case MOUCHARD_SCHEDULING : 204 if (!use_port_dependency) { 205 cerr << "Error : " 206 "The choosen scheduling needs port dependencies informations\n"; 207 exit (31); 208 } 209 break; 210 default : 211 cerr << "Error : You need to choose one of the available scheduling :\n" 212 << "- Almost static scheduling like CASS (use sensitivity list)\n" 213 << "- Simple static scheduling (use port dependencies)\n" 214 << "- Entirely static scheduling (use port dependencies)\n"; 215 exit (33); 216 } 217 assert(use_port_dependency || use_sensitivity_list); 218 218 } 219 219 220 void 221 apply_parameters (int &argc, char ** &argv) 222 { 220 221 void apply_parameters(int & argc, char ** &argv) { 223 222 #ifdef KEEP_GENERATED_CODE // supprimer scheduling-XXXXXX.cc 224 keep_generated_code = true;223 keep_generated_code = true; 225 224 #endif 226 225 #ifdef DUMP_NETLIST_INFO 227 dump_netlist_info = true;226 dump_netlist_info = true; 228 227 #endif 229 228 #ifdef DUMP_FUNCLIST_INFO 230 dump_funclist_info = true;229 dump_funclist_info = true; 231 230 #endif 232 231 #ifdef DUMP_STAGE 233 dump_stage = true;232 dump_stage = true; 234 233 #endif 235 234 #ifdef DUMP_COMBINATIONAL_LIST2DOT 236 dump_all_graph = true;235 dump_all_graph = true; 237 236 #endif 238 237 #ifdef PRINT_SCHEDULE 239 print_schedule = true;238 print_schedule = true; 240 239 #endif 241 240 #ifdef USE_PORT_DEPENDENCY 242 use_port_dependency = true; 243 #endif 244 // parse the command line 245 int i; 246 for (i = 1; i < argc; ++i) 247 { 248 if (argv[i][0] == '-') 249 { 250 if (argv[i][1] == '-') 251 { 252 switch (argv[i][2]) 253 { 254 case 'h' : 255 print_splash_screen (); 256 cerr << "Usage : " 257 << argv[0] << " [--c] [--edit] [--d] [--f] [--h] [--i] [--k] [--modules filename] [--nobanner] [--[no]dynamiclink] [--nosim] [--notrace] [--s] [--t] [--tracestart n] [--usage] [--v] [--p|m|a] [others parameters processed by sc_main]\n" 258 << "Thoses options are processed by SystemCASS library. All the remaining options are passed to sc_main.\n" 259 << "sc_main function retrieves last parameters.\n" 260 << HELP_STRING; 261 noinitialization = true; 262 nosimulation = true; 263 continue; 264 case 'v' : 265 print_splash_screen (); 266 cerr << get_used_options () << "\n"; 267 cerr << get_used_env () << "\n"; 268 cerr << sc_version () << "\n\n"; 269 exit (0); 270 case 'u' : 271 if (strcmp (argv[i]+2, "usage") == 0) 272 print_user_resources = true; 273 else 274 break; 275 continue; 276 case 'i' : 277 dump_netlist_info = true; 278 continue; 279 case 'f' : 280 dump_funclist_info = true; 281 continue; 282 case 's' : 283 if (strcmp (argv[i]+2, "save_on_exit") == 0) 284 save_on_exit = argv[++i]; 285 else 286 dump_stage = true; 287 continue; 288 case 'c' : 289 print_schedule = true; 290 continue; 291 case 'd' : 292 if (strcmp (argv[i]+2, "dynamiclink") == 0) 293 dynamic_link_of_scheduling_code = true; 294 else 295 check_port_dependencies = true; 296 continue; 297 case 'e' : 298 if (strcmp (argv[i]+2, "edit") == 0) 299 edit_schedule = true; 300 else 301 break; 302 continue; 303 case 'k' : 304 keep_generated_code = true; 305 continue; 306 case 't' : 307 if (strcmp (argv[i]+2, "tracestart") == 0) { 308 ++i; 309 istringstream iss (argv[i]); 310 iss >> trace_start; 311 trace_start <<= 1; 312 // trace_start = strtoll (argv[i],0,10) << 1; 313 // trace_start = atoll (argv[i]) << 1; 314 } else { 315 dump_all_graph = true; 241 use_port_dependency = true; 242 #endif 243 // parse the command line 244 int i; 245 for (i = 1; i < argc; ++i) { 246 if (argv[i][0] == '-') { 247 if (argv[i][1] == '-') { 248 switch (argv[i][2]) { 249 case 'h' : 250 print_splash_screen(); 251 cerr << "Usage : " 252 << argv[0] << " [--c] [--edit] [--d] [--f] [--h] [--i] [--k] [--modules filename] [--nobanner] [--[no]dynamiclink] [--nosim] [--notrace] [--s] [--t] [--tracestart n] [--usage] [--v] [--p|m|a] [others parameters processed by sc_main]\n" 253 << "Thoses options are processed by SystemCASS library. All the remaining options are passed to sc_main.\n" 254 << "sc_main function retrieves last parameters.\n" 255 << HELP_STRING; 256 noinitialization = true; 257 nosimulation = true; 258 continue; 259 case 'v' : 260 print_splash_screen (); 261 cerr << get_used_options () << "\n"; 262 cerr << get_used_env () << "\n"; 263 cerr << sc_version () << "\n\n"; 264 exit (0); 265 case 'u' : 266 if (strcmp (argv[i] + 2, "usage") == 0) { 267 print_user_resources = true; 268 } 269 else { 270 break; 271 } 272 continue; 273 case 'i' : 274 dump_netlist_info = true; 275 continue; 276 case 'f' : 277 dump_funclist_info = true; 278 continue; 279 case 's' : 280 if (strcmp (argv[i] + 2, "save_on_exit") == 0) { 281 save_on_exit = argv[++i]; 282 } 283 else { 284 dump_stage = true; 285 } 286 287 continue; 288 case 'c' : 289 print_schedule = true; 290 continue; 291 case 'd' : 292 if (strcmp (argv[i] + 2, "dynamiclink") == 0) { 293 dynamic_link_of_scheduling_code = true; 294 } 295 else { 296 check_port_dependencies = true; 297 } 298 continue; 299 case 'e' : 300 if (strcmp (argv[i] + 2, "edit") == 0) { 301 edit_schedule = true; 302 } 303 else { 304 break; 305 } 306 continue; 307 case 'k' : 308 keep_generated_code = true; 309 continue; 310 case 't' : 311 if (strcmp (argv[i] + 2, "tracestart") == 0) { 312 ++i; 313 istringstream iss (argv[i]); 314 iss >> trace_start; 315 trace_start <<= 1; 316 // trace_start = strtoll (argv[i],0,10) << 1; 317 // trace_start = atoll (argv[i]) << 1; 318 } 319 else { 320 dump_all_graph = true; 321 } 322 continue; 323 case 'm' : 324 if (strcmp (argv[i] + 2, "modules") == 0) { 325 ++i; 326 dump_module_hierarchy = argv[i]; 327 continue; 328 } 329 else if (strcmp (argv[i] + 2, "m") == 0) { 330 use_port_dependency = true; 331 scheduling_method = MOUCHARD_SCHEDULING; 332 continue; 333 } 334 break; 335 case 'n' : 336 if (strcmp (argv[i] + 2, "nobanner") == 0) { 337 nobanner = true; 338 } 339 else if (strcmp (argv[i] + 2, "nodynamiclink") == 0) { 340 dynamic_link_of_scheduling_code = false; 341 } 342 else if (strcmp (argv[i] + 2, "nosim") == 0) { 343 nosimulation = true; 344 } 345 else if (strcmp (argv[i] + 2, "notrace") == 0) { 346 notrace = true; 347 } 348 else { 349 break; 350 } 351 continue; 352 case 'a' : 353 use_sensitivity_list = true; 354 scheduling_method = CASS_SCHEDULING; 355 continue; 356 case 'p' : 357 use_port_dependency = true; 358 scheduling_method = BUCHMANN_SCHEDULING; 359 continue; 360 default : 361 break; 362 } 363 break; 316 364 } 317 continue; 318 case 'm' : 319 if (strcmp (argv[i]+2, "modules") == 0) { 320 ++i; 321 dump_module_hierarchy = argv[i]; 322 continue; 323 } else if (strcmp (argv[i]+2, "m") == 0) { 324 use_port_dependency = true; 325 scheduling_method = MOUCHARD_SCHEDULING; 326 continue; 327 } 328 break; 329 case 'n' : 330 if (strcmp (argv[i]+2, "nobanner") == 0) { 331 nobanner = true; 332 } else if (strcmp (argv[i]+2, "nodynamiclink") == 0) { 333 dynamic_link_of_scheduling_code = false; 334 } else if (strcmp (argv[i]+2, "nosim") == 0) { 335 nosimulation = true; 336 } else if (strcmp (argv[i]+2, "notrace") == 0) { 337 notrace = true; 338 } else 339 break; 340 continue; 341 case 'a' : 342 use_sensitivity_list = true; 343 scheduling_method = CASS_SCHEDULING; 344 continue; 345 case 'p' : 346 use_port_dependency = true; 347 scheduling_method = BUCHMANN_SCHEDULING; 348 continue; 349 default : 350 break; 351 } 365 } 352 366 break; 367 } 368 369 // erase SystemCASS options from the command line and give it to the sc_main 370 if (i != 1) { 371 int j = 1; 372 while (i < argc) { 373 argv[j++] = argv[i++]; 353 374 } 354 } 355 break; 356 } 357 358 // erase SystemCASS options from the command line and give it to the sc_main 359 if (i != 1) 360 { 361 int j = 1; 362 while (i < argc) 363 { 364 argv[j++] = argv[i++]; 365 } 366 argc = j; 367 } 368 #if 0 369 cerr << "The user command line length is " << argc << ".\n"; 370 #endif 375 argc = j; 376 } 371 377 } 372 378 … … 374 380 } // end of namespace 375 381 382 376 383 using namespace sc_core; 377 384 378 int 379 main(int argc, 380 char* argv[]) 381 { 382 apply_parameters (argc, argv); 383 print_splash_screen (); 384 check_parameters (); 385 386 if (noinitialization) 387 { 388 return 255; 389 } 390 391 int ret = sc_main(argc, argv); 392 free (pending_write_vector); 393 close_systemcass (); 394 395 if (have_to_stop) 396 { 397 cerr << "'sc_stop' function was called. Exit code : 1\n"; 398 return 1; 399 } 400 401 return ret; 385 int main(int argc, char * argv[]) { 386 apply_parameters(argc, argv); 387 print_splash_screen(); 388 check_parameters(); 389 390 if (noinitialization) { 391 return 255; 392 } 393 394 int ret = sc_main(argc, argv); 395 free(pending_write_vector); 396 close_systemcass(); 397 398 if (have_to_stop) { 399 cerr << "'sc_stop' function was called. Exit code : 1\n"; 400 return 1; 401 } 402 403 return ret; 402 404 } 403 405 406 /* 407 # Local Variables: 408 # tab-width: 4; 409 # c-basic-offset: 4; 410 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 411 # indent-tabs-mode: nil; 412 # End: 413 # 414 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 415 */ 416 -
sources/src/sc_module.cc
r35 r52 49 49 #include "entity.h" 50 50 #include <cassert> 51 51 52 #ifdef HAVE_CONFIG_H 52 53 #include "config.h" … … 62 63 63 64 namespace sc_core { 65 64 66 instances_set_t instances_set; 65 67 instances_list_t temp_list; 66 68 method_process_list_t method_process_list; 67 68 69 module_name_stack_t module_name_stack; 69 70 70 modules_stack_t modules_stack; 71 72 method_process_t *method; 73 74 void 75 declare_method_process (const char * name, 76 SC_ENTRY_FUNC func, 77 sc_module& module) 78 { 79 method = create_method_process (name, func, module); 71 method_process_t * method; 72 73 void declare_method_process(const char * name, SC_ENTRY_FUNC func, sc_module & module) { 74 method = create_method_process(name, func, module); 80 75 method_process_list.push_back(method); 81 76 } 82 77 83 78 84 ostream& 85 operator << (ostream &o, 86 instances_set_t &l) 87 { 79 ostream & operator << (ostream &o, instances_set_t &l) { 88 80 instances_set_t::iterator i; 89 for (i = l.begin (); i != l.end(); ++i) {90 o << (*i)->name 91 } ;81 for (i = l.begin(); i != l.end(); ++i) { 82 o << (*i)->name() << " "; 83 } 92 84 return o << endl; 93 85 } 94 86 87 95 88 template <typename T> 96 static 97 std::ostream& 98 operator << (std::ostream &o, 99 const list<T> &l) 100 { 89 static std::ostream& operator << (std::ostream & o, const list<T> &l) { 101 90 typename list<T>::const_iterator i; 102 for (i = l.begin (); i != l.end(); ++i) {91 for (i = l.begin(); i != l.end(); ++i) { 103 92 o << (*i) << " "; 104 } ;93 } 105 94 return o << endl; 106 95 } 107 96 97 108 98 template <typename T> 109 static 110 std::ostream& 111 operator << (std::ostream &o, 112 const list<T*> &l) 113 { 114 typename list<T*>::const_iterator i; 115 for (i = l.begin (); i != l.end (); ++i) { 99 static std::ostream& operator << (std::ostream &o, const list<T *> &l) { 100 typename list<T *>::const_iterator i; 101 for (i = l.begin(); i != l.end(); ++i) { 116 102 o << (**i) << " "; 117 } ;103 } 118 104 return o << endl; 119 105 } 120 106 121 bool 122 is_clock (const sc_interface &inter) 123 { 124 equi_t &e = get_equi(inter);125 equi_t::iterator i; 126 for (i = e.begin (); i != e.end (); ++i) {127 if (i->kind () == sc_clock::kind_string) 128 return true; 129 130 107 108 bool is_clock (const sc_interface & inter) { 109 equi_t & e = get_equi(inter); 110 equi_t::iterator i; 111 for (i = e.begin(); i != e.end(); ++i) { 112 if (i->kind() == sc_clock::kind_string) { 113 return true; 114 } 115 } 116 return false; 131 117 } 132 118 … … 136 122 // 137 123 // ---------------------------------------------------------------------------- 138 method_process_t::method_process_t(const char* nm, SC_ENTRY_FUNC fn, sc_module& mod) 139 { 124 method_process_t::method_process_t(const char * nm, SC_ENTRY_FUNC fn, sc_module & mod) { 140 125 name = nm; 141 126 func = fn; … … 144 129 } 145 130 146 static 147 bool 148 is_register (const sc_interface &inter) 149 { 150 equi_t &e = get_equi (inter); 151 if (e.size () != 1) 152 return false; 153 sc_object &obj = *(e.begin ()->object); 154 if (obj.kind () != sc_signal_base::kind_string) 155 return false; 156 return true; 157 } 158 159 bool method_process_t::is_combinational(void) 160 { 161 if (sensitivity_list.empty ()) 162 return false; 163 sensitivity_list_t::iterator i; 164 for (i = sensitivity_list.begin (); i != sensitivity_list.end (); ++i) { 131 132 static bool is_register (const sc_interface & inter) { 133 equi_t & e = get_equi(inter); 134 if (e.size() != 1) { 135 return false; 136 } 137 138 sc_object & obj = *(e.begin()->object); 139 if (obj.kind() != sc_signal_base::kind_string) { 140 return false; 141 } 142 return true; 143 } 144 145 146 bool method_process_t::is_combinational(void) { 147 if (sensitivity_list.empty()) { 148 return false; 149 } 150 sensitivity_list_t::iterator i; 151 for (i = sensitivity_list.begin(); i != sensitivity_list.end(); ++i) { 165 152 #if defined(CONFIG_DEBUG) && 0 166 if (i->get_interface() == NULL) 167 { 168 cerr << "'" << i << "' is unbound.\n"; 169 exit (121); 170 } 153 if (i->get_interface() == NULL) { 154 cerr << "'" << i << "' is unbound.\n"; 155 exit(121); 156 } 171 157 #endif 172 if ((i->get_flag() == sc_event::VAL) 173 && (!is_register (i->get_interface()))) 174 return true; 175 } 176 return false; 177 } 178 179 bool method_process_t::is_transition(void) 180 { 181 if (sensitivity_list.empty ()) 182 return false; 183 sensitivity_list_t::iterator i; 184 for (i = sensitivity_list.begin (); i != sensitivity_list.end (); ++i) { 185 if (i->get_flag () != sc_event::POS) 186 return false; 187 // check if the port is a clock 188 if (is_clock (i->get_interface ()) == false) 189 return false; 190 } 191 return true; 192 } 193 194 bool method_process_t::is_genmoore(void) 195 { 196 // sensitivity list of moore functions includes : 197 // - register (signal unconnected) 198 // - negative edge of port which is bound to a clock signal 199 if (sensitivity_list.empty ()) 200 return false; 201 sensitivity_list_t::iterator i; 202 for (i = sensitivity_list.begin (); i != sensitivity_list.end (); ++i) { 203 if ((i->get_flag () == sc_event::VAL) 204 && (is_register(i->get_interface ()))) 205 continue; 206 if ((i->get_flag () == sc_event::NEG) 207 && (is_clock (i->get_interface ()) == true)) 208 continue; 209 return false; 210 } 211 return true; 212 } 213 214 std::ostream& operator << (std::ostream &o, const method_process_t &m) 215 { 216 return o << *(m.module) 217 << "->" 218 << m.name 219 << "() when " 220 << m.sensitivity_list; 221 } 158 if ((i->get_flag() == sc_event::VAL) && (!is_register(i->get_interface()))) { 159 return true; 160 } 161 } 162 return false; 163 } 164 165 166 bool method_process_t::is_transition(void) { 167 if (sensitivity_list.empty()) { 168 return false; 169 } 170 sensitivity_list_t::iterator i; 171 for (i = sensitivity_list.begin(); i != sensitivity_list.end(); ++i) { 172 if (i->get_flag() != sc_event::POS) { 173 return false; 174 } 175 // check if the port is a clock 176 if (is_clock(i->get_interface()) == false) { 177 return false; 178 } 179 } 180 return true; 181 } 182 183 184 bool method_process_t::is_genmoore(void) { 185 // sensitivity list of moore functions includes : 186 // - register (signal unconnected) 187 // - negative edge of port which is bound to a clock signal 188 if (sensitivity_list.empty()) { 189 return false; 190 } 191 sensitivity_list_t::iterator i; 192 for (i = sensitivity_list.begin(); i != sensitivity_list.end(); ++i) { 193 if ((i->get_flag() == sc_event::VAL) && (is_register(i->get_interface()))) { 194 continue; 195 } 196 if ((i->get_flag() == sc_event::NEG) && (is_clock(i->get_interface()) == true)) { 197 continue; 198 } 199 return false; 200 } 201 return true; 202 } 203 204 205 std::ostream & operator << (std::ostream & o, const method_process_t & m) { 206 return o << *(m.module) 207 << "->" 208 << m.name 209 << "() when " 210 << m.sensitivity_list; 211 } 212 222 213 223 214 // ---------------------------------------------------------------------------- … … 227 218 228 219 229 sc_module::sc_module(void) 230 : sc_object (NULL), 231 sensitive (this) 220 sc_module::sc_module(void) : 221 sc_object(NULL), 222 sensitive(this) { 223 init(); 224 } 225 226 sc_module::sc_module(const char * nm) : 227 sc_object(NULL), 228 sensitive(this) { 229 assert(nm != NULL); 230 init(); 231 } 232 233 234 sc_module::sc_module(const sc_module_name & nm) : 235 sc_object(NULL), 236 sensitive(this) { 237 init(); 238 } 239 240 241 void sc_module::init() { 242 instances_set.insert(this); 243 temp_list.push_back(this); 244 modules_stack.top() = this; 245 set_save_handler(*this, NULL); 246 } 247 248 void sc_module::dont_initialize() { 249 sc_core::valid_method_process(); 250 } 251 252 253 void declare_save_handler(const char * name, save_fct_t1 func, sc_module & module) { 254 sc_core::set_save_handler(module, func); 255 } 256 257 typedef std::list<sc_port_base*> port_list_t; 258 259 // Build a port list owned by the module mod 260 static void get_port_list(const sc_module & mod, port_list_t & pl) { 261 port2module_t::iterator i; 262 for (i = port2module.begin(); i != port2module.end(); ++i) { 263 if (i->second == &mod) { 264 pl.push_back((sc_port_base *) (i->first)); 265 } 266 } 267 } 268 269 270 #define BIND(sig) bind(*this, p, port_list, sig) 271 272 static void bind(sc_module & mod, 273 port_list_t::iterator & port_it, 274 port_list_t & port_list, 275 sc_bind_proxy & sig) { 276 if (&sig == &SC_BIND_PROXY_NIL) { 277 return; 278 } 279 if (port_it == port_list.end()) { 280 cerr << "error : binding port in "; 281 cerr << mod.name(); 282 cerr << " module.\n"; 283 exit(7); 284 } 285 bind(**(port_it++), sig); 286 } 287 288 289 void sc_module::operator () ( /* const */ sc_bind_proxy & p001, 290 /* const */ sc_bind_proxy & p002, 291 /* const */ sc_bind_proxy & p003, 292 /* const */ sc_bind_proxy & p004, 293 /* const */ sc_bind_proxy & p005, 294 /* const */ sc_bind_proxy & p006, 295 /* const */ sc_bind_proxy & p007, 296 /* const */ sc_bind_proxy & p008, 297 /* const */ sc_bind_proxy & p009, 298 /* const */ sc_bind_proxy & p010, 299 /* const */ sc_bind_proxy & p011, 300 /* const */ sc_bind_proxy & p012, 301 /* const */ sc_bind_proxy & p013, 302 /* const */ sc_bind_proxy & p014, 303 /* const */ sc_bind_proxy & p015, 304 /* const */ sc_bind_proxy & p016, 305 /* const */ sc_bind_proxy & p017, 306 /* const */ sc_bind_proxy & p018, 307 /* const */ sc_bind_proxy & p019, 308 /* const */ sc_bind_proxy & p020, 309 /* const */ sc_bind_proxy & p021, 310 /* const */ sc_bind_proxy & p022, 311 /* const */ sc_bind_proxy & p023, 312 /* const */ sc_bind_proxy & p024, 313 /* const */ sc_bind_proxy & p025, 314 /* const */ sc_bind_proxy & p026, 315 /* const */ sc_bind_proxy & p027, 316 /* const */ sc_bind_proxy & p028, 317 /* const */ sc_bind_proxy & p029, 318 /* const */ sc_bind_proxy & p030, 319 /* const */ sc_bind_proxy & p031, 320 /* const */ sc_bind_proxy & p032, 321 /* const */ sc_bind_proxy & p033, 322 /* const */ sc_bind_proxy & p034, 323 /* const */ sc_bind_proxy & p035, 324 /* const */ sc_bind_proxy & p036, 325 /* const */ sc_bind_proxy & p037, 326 /* const */ sc_bind_proxy & p038, 327 /* const */ sc_bind_proxy & p039, 328 /* const */ sc_bind_proxy & p040, 329 /* const */ sc_bind_proxy & p041, 330 /* const */ sc_bind_proxy & p042, 331 /* const */ sc_bind_proxy & p043, 332 /* const */ sc_bind_proxy & p044, 333 /* const */ sc_bind_proxy & p045, 334 /* const */ sc_bind_proxy & p046, 335 /* const */ sc_bind_proxy & p047, 336 /* const */ sc_bind_proxy & p048, 337 /* const */ sc_bind_proxy & p049, 338 /* const */ sc_bind_proxy & p050, 339 /* const */ sc_bind_proxy & p051, 340 /* const */ sc_bind_proxy & p052, 341 /* const */ sc_bind_proxy & p053, 342 /* const */ sc_bind_proxy & p054, 343 /* const */ sc_bind_proxy & p055, 344 /* const */ sc_bind_proxy & p056, 345 /* const */ sc_bind_proxy & p057, 346 /* const */ sc_bind_proxy & p058, 347 /* const */ sc_bind_proxy & p059, 348 /* const */ sc_bind_proxy & p060, 349 /* const */ sc_bind_proxy & p061, 350 /* const */ sc_bind_proxy & p062, 351 /* const */ sc_bind_proxy & p063, 352 /* const */ sc_bind_proxy & p064) 232 353 { 233 #if 0 234 cerr << "sc_module constructor with no parameter\n"; 235 #endif 236 init (); 237 } 238 239 sc_module::sc_module(const char* nm) 240 : sc_object (NULL), 241 sensitive (this) 242 { 243 assert(nm != NULL); 244 #if 0 245 cerr << "sc_module constructor with const char * parameter\n"; 246 #endif 247 init (); 248 } 249 250 251 sc_module::sc_module(const sc_module_name &nm) 252 : sc_object (NULL), 253 sensitive (this) 254 { 255 #if 0 256 cerr << "sc_module constructor by copy\n"; 257 #endif 258 init (); 259 } 260 261 void 262 sc_module::init () 263 { 264 instances_set.insert (this); 265 temp_list.push_back (this); 266 modules_stack.top () = this; 267 set_save_handler (*this, NULL); 268 #if 0 269 cout << "sc_module <- " << this->name () << endl; 270 #endif 271 } 272 273 void 274 sc_module::dont_initialize () 275 { 276 sc_core::valid_method_process (); 277 } 278 279 280 void 281 declare_save_handler (const char * name, 282 save_fct_t1 func, 283 sc_module& module) 284 { 285 sc_core::set_save_handler (module, func); 286 } 287 288 typedef std::list<sc_port_base*> port_list_t; 289 290 // Build a port list owned by the module mod 291 static void 292 get_port_list (const sc_module &mod, port_list_t &pl) 293 { 294 port2module_t::iterator i; 295 for (i = port2module.begin (); i != port2module.end (); ++i) { 296 if (i->second == &mod) { 297 pl.push_back ((sc_port_base*)(i->first)); 298 } 299 } 300 } 301 302 303 #define BIND(sig) bind(*this, p, port_list, sig) 304 305 static void 306 bind (sc_module &mod, 307 port_list_t::iterator &port_it, 308 port_list_t &port_list, 309 sc_bind_proxy &sig) 310 { 311 if (&sig == &SC_BIND_PROXY_NIL) { 312 return; 313 }; 314 if (port_it == port_list.end ()) { 315 cerr << "error : binding port in "; 316 cerr << mod.name (); 317 cerr << " module.\n"; 318 exit (7); 319 }; 320 bind (**(port_it++), sig); 321 } 322 323 void 324 sc_module::operator () ( /* const */ sc_bind_proxy& p001, 325 /* const */ sc_bind_proxy& p002, 326 /* const */ sc_bind_proxy& p003, 327 /* const */ sc_bind_proxy& p004, 328 /* const */ sc_bind_proxy& p005, 329 /* const */ sc_bind_proxy& p006, 330 /* const */ sc_bind_proxy& p007, 331 /* const */ sc_bind_proxy& p008, 332 /* const */ sc_bind_proxy& p009, 333 /* const */ sc_bind_proxy& p010, 334 /* const */ sc_bind_proxy& p011, 335 /* const */ sc_bind_proxy& p012, 336 /* const */ sc_bind_proxy& p013, 337 /* const */ sc_bind_proxy& p014, 338 /* const */ sc_bind_proxy& p015, 339 /* const */ sc_bind_proxy& p016, 340 /* const */ sc_bind_proxy& p017, 341 /* const */ sc_bind_proxy& p018, 342 /* const */ sc_bind_proxy& p019, 343 /* const */ sc_bind_proxy& p020, 344 /* const */ sc_bind_proxy& p021, 345 /* const */ sc_bind_proxy& p022, 346 /* const */ sc_bind_proxy& p023, 347 /* const */ sc_bind_proxy& p024, 348 /* const */ sc_bind_proxy& p025, 349 /* const */ sc_bind_proxy& p026, 350 /* const */ sc_bind_proxy& p027, 351 /* const */ sc_bind_proxy& p028, 352 /* const */ sc_bind_proxy& p029, 353 /* const */ sc_bind_proxy& p030, 354 /* const */ sc_bind_proxy& p031, 355 /* const */ sc_bind_proxy& p032, 356 /* const */ sc_bind_proxy& p033, 357 /* const */ sc_bind_proxy& p034, 358 /* const */ sc_bind_proxy& p035, 359 /* const */ sc_bind_proxy& p036, 360 /* const */ sc_bind_proxy& p037, 361 /* const */ sc_bind_proxy& p038, 362 /* const */ sc_bind_proxy& p039, 363 /* const */ sc_bind_proxy& p040, 364 /* const */ sc_bind_proxy& p041, 365 /* const */ sc_bind_proxy& p042, 366 /* const */ sc_bind_proxy& p043, 367 /* const */ sc_bind_proxy& p044, 368 /* const */ sc_bind_proxy& p045, 369 /* const */ sc_bind_proxy& p046, 370 /* const */ sc_bind_proxy& p047, 371 /* const */ sc_bind_proxy& p048, 372 /* const */ sc_bind_proxy& p049, 373 /* const */ sc_bind_proxy& p050, 374 /* const */ sc_bind_proxy& p051, 375 /* const */ sc_bind_proxy& p052, 376 /* const */ sc_bind_proxy& p053, 377 /* const */ sc_bind_proxy& p054, 378 /* const */ sc_bind_proxy& p055, 379 /* const */ sc_bind_proxy& p056, 380 /* const */ sc_bind_proxy& p057, 381 /* const */ sc_bind_proxy& p058, 382 /* const */ sc_bind_proxy& p059, 383 /* const */ sc_bind_proxy& p060, 384 /* const */ sc_bind_proxy& p061, 385 /* const */ sc_bind_proxy& p062, 386 /* const */ sc_bind_proxy& p063, 387 /* const */ sc_bind_proxy& p064 ) 388 { 389 port_list_t port_list; 390 get_port_list (*this,port_list); 391 cerr << "port list : " << port_list << endl; 392 port_list_t::iterator p = port_list.begin (); 393 BIND( p001 ); 394 BIND( p002 ); 395 BIND( p003 ); 396 BIND( p004 ); 397 BIND( p005 ); 398 BIND( p006 ); 399 BIND( p007 ); 400 BIND( p008 ); 401 BIND( p009 ); 402 BIND( p010 ); 403 BIND( p011 ); 404 BIND( p012 ); 405 BIND( p013 ); 406 BIND( p014 ); 407 BIND( p015 ); 408 BIND( p016 ); 409 BIND( p017 ); 410 BIND( p018 ); 411 BIND( p019 ); 412 BIND( p020 ); 413 BIND( p021 ); 414 BIND( p022 ); 415 BIND( p023 ); 416 BIND( p024 ); 417 BIND( p025 ); 418 BIND( p026 ); 419 BIND( p027 ); 420 BIND( p028 ); 421 BIND( p029 ); 422 BIND( p030 ); 423 BIND( p031 ); 424 BIND( p032 ); 425 BIND( p033 ); 426 BIND( p034 ); 427 BIND( p035 ); 428 BIND( p036 ); 429 BIND( p037 ); 430 BIND( p038 ); 431 BIND( p039 ); 432 BIND( p040 ); 433 BIND( p041 ); 434 BIND( p042 ); 435 BIND( p043 ); 436 BIND( p044 ); 437 BIND( p045 ); 438 BIND( p046 ); 439 BIND( p047 ); 440 BIND( p048 ); 441 BIND( p049 ); 442 BIND( p050 ); 443 BIND( p051 ); 444 BIND( p052 ); 445 BIND( p053 ); 446 BIND( p054 ); 447 BIND( p055 ); 448 BIND( p056 ); 449 BIND( p057 ); 450 BIND( p058 ); 451 BIND( p059 ); 452 BIND( p060 ); 453 BIND( p061 ); 454 BIND( p062 ); 455 BIND( p063 ); 456 BIND( p064 ); 457 } 458 459 ostream& operator << (ostream &o, const sc_module &m) 460 { 461 return o << m.name (); 462 } 354 port_list_t port_list; 355 get_port_list(*this, port_list); 356 cerr << "port list : " << port_list << endl; 357 port_list_t::iterator p = port_list.begin(); 358 BIND(p001); 359 BIND(p002); 360 BIND(p003); 361 BIND(p004); 362 BIND(p005); 363 BIND(p006); 364 BIND(p007); 365 BIND(p008); 366 BIND(p009); 367 BIND(p010); 368 BIND(p011); 369 BIND(p012); 370 BIND(p013); 371 BIND(p014); 372 BIND(p015); 373 BIND(p016); 374 BIND(p017); 375 BIND(p018); 376 BIND(p019); 377 BIND(p020); 378 BIND(p021); 379 BIND(p022); 380 BIND(p023); 381 BIND(p024); 382 BIND(p025); 383 BIND(p026); 384 BIND(p027); 385 BIND(p028); 386 BIND(p029); 387 BIND(p030); 388 BIND(p031); 389 BIND(p032); 390 BIND(p033); 391 BIND(p034); 392 BIND(p035); 393 BIND(p036); 394 BIND(p037); 395 BIND(p038); 396 BIND(p039); 397 BIND(p040); 398 BIND(p041); 399 BIND(p042); 400 BIND(p043); 401 BIND(p044); 402 BIND(p045); 403 BIND(p046); 404 BIND(p047); 405 BIND(p048); 406 BIND(p049); 407 BIND(p050); 408 BIND(p051); 409 BIND(p052); 410 BIND(p053); 411 BIND(p054); 412 BIND(p055); 413 BIND(p056); 414 BIND(p057); 415 BIND(p058); 416 BIND(p059); 417 BIND(p060); 418 BIND(p061); 419 BIND(p062); 420 BIND(p063); 421 BIND(p064); 422 } 423 424 425 ostream & operator << (ostream & o, const sc_module & m) { 426 return o << m.name(); 427 } 428 463 429 464 430 // ---------------------------------------------------------------------------- … … 467 433 // ---------------------------------------------------------------------------- 468 434 469 sc_module_name::sc_module_name( const char* name_ ) 470 : m_pushed(true) 471 { 472 #if 0 473 cerr << "sc_module_name constructor with const char * parameter\n"; 435 sc_module_name::sc_module_name(const char * name_) : m_pushed(true) { 436 m_name = name_; 437 init(); 438 } 439 440 441 sc_module_name::sc_module_name(const sc_module_name & module) : m_pushed(false) { 442 m_name = module.m_name; 443 } 444 445 446 void sc_module_name::init() { 447 sc_core::module_name_stack.push_back(m_name); 448 modules_stack.push(NULL); 449 } 450 451 452 sc_module_name::~sc_module_name() { 453 if (m_pushed == false) { 454 return; 455 } 456 assert(sc_core::module_name_stack.empty() == false); 457 sc_core::module_name_stack.pop_back(); 458 modules_stack.pop(); 459 assert(temp_list.empty() == false); 460 sc_module * last1 = temp_list.back(); 461 temp_list.pop_back(); 462 sc_module * last2 = (temp_list.empty()) ? NULL : temp_list.back(); 463 set_parent(*last1, last2); 464 } 465 466 467 std::ostream & operator << (std::ostream & o, const sc_core::sc_module_name & n) { 468 return o << (const char *) n; 469 } 470 471 /////////////////////////////////////////: 472 473 static void check_method_process(const method_process_t & m) { 474 if (m.dont_initialize == false) { 475 assert(m.module != NULL); 476 #ifdef CONFIG_DEBUG 477 std::cerr << "Warning : SystemCASS doesn't perform SC_METHOD(S) initializations.\n" 478 << "Please turn off automatic initialization for '" << m.name 479 << "' method of '" << m.module->name() << "' module" 480 " by calling 'dont_initialize()' function.\n" 481 "Example :\n" 482 " SC_METHOD(transition);\n" 483 " sensitive << clk;\n" 484 " dont_initialize();\n"; 474 485 #endif 475 m_name = name_; 476 init (); 477 } 478 479 sc_module_name::sc_module_name( const sc_module_name &module ) 480 : m_pushed(false) 481 { 482 #if 0 483 cerr << "sc_module_name constructor by copy\n"; 484 #endif 485 m_name = module.m_name; 486 //init (); 487 } 488 489 void 490 sc_module_name::init () 491 { 492 sc_core::module_name_stack.push_back (m_name); 493 modules_stack.push (NULL); 494 #if 0 495 cout << "module_name <- " << m_name << endl; 496 #endif 497 } 498 499 sc_module_name::~sc_module_name () 500 { 501 if (m_pushed == false) 502 return; 503 assert(sc_core::module_name_stack.empty () == false); 504 sc_core::module_name_stack.pop_back (); 505 modules_stack.pop (); 506 #if 0 507 cout << "~sc_module_name <- " << m_name << endl; 508 #endif 509 assert(temp_list.empty () == false); 510 sc_module *last1 = temp_list.back(); 511 temp_list.pop_back(); 512 sc_module *last2 = (temp_list.empty())?NULL:temp_list.back(); 513 set_parent (*last1, last2); 514 } 515 516 std::ostream& 517 operator << (std::ostream& o, 518 const sc_core::sc_module_name &n) 519 { 520 return o << (const char*)n; 521 } 522 523 /////////////////////////////////////////: 524 525 static 526 void 527 check_method_process (const method_process_t &m) 528 { 529 if (m.dont_initialize == false) 530 { 531 assert(m.module != NULL); 532 #ifdef CONFIG_DEBUG 533 std::cerr << "Warning : SystemCASS doesn't perform SC_METHOD(S) initializations.\n" 534 << "Please turn off automatic initialization for '" << m.name 535 << "' method of '" << m.module->name () << "' module" 536 " by calling 'dont_initialize()' function.\n" 537 "Example :\n" 538 " SC_METHOD(transition);\n" 539 " sensitive << clk;\n" 540 " dont_initialize ();\n"; 541 #endif 542 #if 0 543 exit (250405); 544 #endif 545 } 546 } 547 548 void 549 check_all_method_process () 550 { 551 method_process_list_t::const_iterator i; 552 for (i = sc_core::method_process_list.begin(); 553 i != sc_core::method_process_list.end (); 554 ++i) 555 { 556 check_method_process (**i); 557 } 558 } 559 560 void 561 valid_method_process () 562 { 563 method_process_t *m = sc_core::method_process_list.back(); 564 m->dont_initialize = true; 565 } 566 567 method_process_t* 568 create_method_process (const char * name, 569 SC_ENTRY_FUNC func, 570 sc_module& module) 571 { 572 return new method_process_t (name, func, module); 573 } 486 } 487 } 488 489 490 void check_all_method_process() { 491 method_process_list_t::const_iterator i; 492 for (i = sc_core::method_process_list.begin(); i != sc_core::method_process_list.end(); ++i) { 493 check_method_process(**i); 494 } 495 } 496 497 498 void valid_method_process() { 499 method_process_t * m = sc_core::method_process_list.back(); 500 m->dont_initialize = true; 501 } 502 503 504 method_process_t * create_method_process(const char * name, SC_ENTRY_FUNC func, sc_module & module) { 505 return new method_process_t(name, func, module); 506 } 507 574 508 575 509 } // end of sc_core namespace 576 510 511 /* 512 # Local Variables: 513 # tab-width: 4; 514 # c-basic-offset: 4; 515 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 516 # indent-tabs-mode: nil; 517 # End: 518 # 519 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 520 */ 521 -
sources/src/sc_module.h
r35 r52 11 11 | | 12 12 \------------------------------------------------------------*/ 13 13 14 #ifndef __SC_MODULE_H__ 14 15 #define __SC_MODULE_H__ … … 19 20 20 21 #include "internal.h" 21 22 22 #include "sc_fwd.h" 23 23 #include "sc_module_ext.h" … … 34 34 // INTERNAL IMPLEMENTATION 35 35 // 36 typedef std::list<sc_signal_base *> signal_list_t;36 typedef std::list<sc_signal_base *> signal_list_t; 37 37 38 typedef std::list<sc_module *> instances_list_t;39 typedef std::set<sc_module *> instances_set_t;40 extern instances_set_t instances_set; 38 typedef std::list<sc_module *> instances_list_t; 39 typedef std::set<sc_module *> instances_set_t; 40 extern instances_set_t instances_set; // ensemble d'instances 41 41 42 typedef std::stack<const sc_module *> modules_stack_t;42 typedef std::stack<const sc_module *> modules_stack_t; 43 43 extern modules_stack_t modules_stack; 44 extern void check_all_method_process 45 extern void valid_method_process 44 extern void check_all_method_process(); 45 extern void valid_method_process(); 46 46 47 extern std::ostream& operator << (std::ostream &o, instances_set_t&); 47 extern std::ostream & operator << (std::ostream & o, instances_set_t &); 48 48 49 49 50 // ---------------------------------------------------------------------------- … … 52 53 // Method process class. 53 54 // ---------------------------------------------------------------------------- 54 class method_process_t 55 { 56 // for debug 57 public: const char *name; // function name 55 56 class method_process_t { 57 58 59 public: 60 const char * name; // function name 61 58 62 #ifdef DUMP_SCHEDULE_STATS 59 long long int number_of_calls; 60 #endif 61 public: 62 // data 63 sc_module *module; 64 SC_ENTRY_FUNC func; 65 sensitivity_list_t sensitivity_list; 66 bool dont_initialize; 63 long long int number_of_calls; 64 #endif 67 65 68 // constructors 69 method_process_t(const char* nm, SC_ENTRY_FUNC fn, sc_module& mod ); 66 public: 67 // data 68 sc_module * module; 69 SC_ENTRY_FUNC func; 70 sensitivity_list_t sensitivity_list; 71 bool dont_initialize; 70 72 71 // methods 72 friend std::ostream& operator << (std::ostream &, const method_process_t &); 73 74 // accessors 75 bool is_combinational(void); 76 bool is_transition(void); 77 bool is_genmoore(void); 73 // constructors 74 method_process_t(const char * nm, SC_ENTRY_FUNC fn, sc_module & mod); 75 76 // methods 77 friend std::ostream& operator << (std::ostream &, const method_process_t &); 78 79 // accessors 80 bool is_combinational(void); 81 bool is_transition(void); 82 bool is_genmoore(void); 83 78 84 }; 79 85 … … 82 88 83 89 #endif /* __SC_MODULE_H__ */ 90 91 /* 92 # Local Variables: 93 # tab-width: 4; 94 # c-basic-offset: 4; 95 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 96 # indent-tabs-mode: nil; 97 # End: 98 # 99 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 100 */ 101 -
sources/src/sc_module_ext.h
r46 r52 53 53 54 54 typedef void (sc_module::*SC_ENTRY_FUNC)(); 55 //typedef void (*SC_ENTRY_FUNC)(sc_module*); 56 57 extern method_process_t* create_method_process (const char*, SC_ENTRY_FUNC, sc_module&); 55 56 extern method_process_t * create_method_process(const char *, SC_ENTRY_FUNC, sc_module &); 57 58 58 59 59 // ---------------------------------------------------------------------------- … … 62 62 // Module class. 63 63 // ---------------------------------------------------------------------------- 64 64 65 typedef sc_signal_base sc_bind_proxy; 65 66 extern sc_bind_proxy SC_BIND_PROXY_NIL; 66 67 67 struct sc_module : public sc_object 68 { 68 69 struct sc_module : public sc_object { 70 69 71 ////////////////////// 70 72 // SYSTEMCASS SPECIFIC 71 private : void init (); 72 public : 73 // friend std::ostream& operator << (std::ostream &o, const sc_module &m); 74 73 private : 74 void init(); 75 75 ////////////////////// 76 77 76 78 // LRM (?) 77 79 protected: 78 80 sc_module(); 79 sc_module( const char* nm ); 80 // sc_module( const sc_string& nm); 81 sc_module( const sc_module_name &nm); 81 sc_module(const char * nm); 82 sc_module(const sc_module_name & nm); 82 83 83 84 public: 84 85 ~sc_module() {}; 85 86 86 ///////// 87 //// LRM 88 protected: void dont_initialize (); 89 public: void operator () ( /* const */ sc_bind_proxy& p001, 90 /* const */ sc_bind_proxy& p002 = SC_BIND_PROXY_NIL, 91 /* const */ sc_bind_proxy& p003 = SC_BIND_PROXY_NIL, 92 /* const */ sc_bind_proxy& p004 = SC_BIND_PROXY_NIL, 93 /* const */ sc_bind_proxy& p005 = SC_BIND_PROXY_NIL, 94 /* const */ sc_bind_proxy& p006 = SC_BIND_PROXY_NIL, 95 /* const */ sc_bind_proxy& p007 = SC_BIND_PROXY_NIL, 96 /* const */ sc_bind_proxy& p008 = SC_BIND_PROXY_NIL, 97 /* const */ sc_bind_proxy& p009 = SC_BIND_PROXY_NIL, 98 /* const */ sc_bind_proxy& p010 = SC_BIND_PROXY_NIL, 99 /* const */ sc_bind_proxy& p011 = SC_BIND_PROXY_NIL, 100 /* const */ sc_bind_proxy& p012 = SC_BIND_PROXY_NIL, 101 /* const */ sc_bind_proxy& p013 = SC_BIND_PROXY_NIL, 102 /* const */ sc_bind_proxy& p014 = SC_BIND_PROXY_NIL, 103 /* const */ sc_bind_proxy& p015 = SC_BIND_PROXY_NIL, 104 /* const */ sc_bind_proxy& p016 = SC_BIND_PROXY_NIL, 105 /* const */ sc_bind_proxy& p017 = SC_BIND_PROXY_NIL, 106 /* const */ sc_bind_proxy& p018 = SC_BIND_PROXY_NIL, 107 /* const */ sc_bind_proxy& p019 = SC_BIND_PROXY_NIL, 108 /* const */ sc_bind_proxy& p020 = SC_BIND_PROXY_NIL, 109 /* const */ sc_bind_proxy& p021 = SC_BIND_PROXY_NIL, 110 /* const */ sc_bind_proxy& p022 = SC_BIND_PROXY_NIL, 111 /* const */ sc_bind_proxy& p023 = SC_BIND_PROXY_NIL, 112 /* const */ sc_bind_proxy& p024 = SC_BIND_PROXY_NIL, 113 /* const */ sc_bind_proxy& p025 = SC_BIND_PROXY_NIL, 114 /* const */ sc_bind_proxy& p026 = SC_BIND_PROXY_NIL, 115 /* const */ sc_bind_proxy& p027 = SC_BIND_PROXY_NIL, 116 /* const */ sc_bind_proxy& p028 = SC_BIND_PROXY_NIL, 117 /* const */ sc_bind_proxy& p029 = SC_BIND_PROXY_NIL, 118 /* const */ sc_bind_proxy& p030 = SC_BIND_PROXY_NIL, 119 /* const */ sc_bind_proxy& p031 = SC_BIND_PROXY_NIL, 120 /* const */ sc_bind_proxy& p032 = SC_BIND_PROXY_NIL, 121 /* const */ sc_bind_proxy& p033 = SC_BIND_PROXY_NIL, 122 /* const */ sc_bind_proxy& p034 = SC_BIND_PROXY_NIL, 123 /* const */ sc_bind_proxy& p035 = SC_BIND_PROXY_NIL, 124 /* const */ sc_bind_proxy& p036 = SC_BIND_PROXY_NIL, 125 /* const */ sc_bind_proxy& p037 = SC_BIND_PROXY_NIL, 126 /* const */ sc_bind_proxy& p038 = SC_BIND_PROXY_NIL, 127 /* const */ sc_bind_proxy& p039 = SC_BIND_PROXY_NIL, 128 /* const */ sc_bind_proxy& p040 = SC_BIND_PROXY_NIL, 129 /* const */ sc_bind_proxy& p041 = SC_BIND_PROXY_NIL, 130 /* const */ sc_bind_proxy& p042 = SC_BIND_PROXY_NIL, 131 /* const */ sc_bind_proxy& p043 = SC_BIND_PROXY_NIL, 132 /* const */ sc_bind_proxy& p044 = SC_BIND_PROXY_NIL, 133 /* const */ sc_bind_proxy& p045 = SC_BIND_PROXY_NIL, 134 /* const */ sc_bind_proxy& p046 = SC_BIND_PROXY_NIL, 135 /* const */ sc_bind_proxy& p047 = SC_BIND_PROXY_NIL, 136 /* const */ sc_bind_proxy& p048 = SC_BIND_PROXY_NIL, 137 /* const */ sc_bind_proxy& p049 = SC_BIND_PROXY_NIL, 138 /* const */ sc_bind_proxy& p050 = SC_BIND_PROXY_NIL, 139 /* const */ sc_bind_proxy& p051 = SC_BIND_PROXY_NIL, 140 /* const */ sc_bind_proxy& p052 = SC_BIND_PROXY_NIL, 141 /* const */ sc_bind_proxy& p053 = SC_BIND_PROXY_NIL, 142 /* const */ sc_bind_proxy& p054 = SC_BIND_PROXY_NIL, 143 /* const */ sc_bind_proxy& p055 = SC_BIND_PROXY_NIL, 144 /* const */ sc_bind_proxy& p056 = SC_BIND_PROXY_NIL, 145 /* const */ sc_bind_proxy& p057 = SC_BIND_PROXY_NIL, 146 /* const */ sc_bind_proxy& p058 = SC_BIND_PROXY_NIL, 147 /* const */ sc_bind_proxy& p059 = SC_BIND_PROXY_NIL, 148 /* const */ sc_bind_proxy& p060 = SC_BIND_PROXY_NIL, 149 /* const */ sc_bind_proxy& p061 = SC_BIND_PROXY_NIL, 150 /* const */ sc_bind_proxy& p062 = SC_BIND_PROXY_NIL, 151 /* const */ sc_bind_proxy& p063 = SC_BIND_PROXY_NIL, 152 /* const */ sc_bind_proxy& p064 = SC_BIND_PROXY_NIL ); 153 154 ///////// 87 ///////// 88 //// LRM 89 protected: 90 void dont_initialize(); 91 92 public: 93 void operator () ( 94 /* const */ sc_bind_proxy& p001, 95 /* const */ sc_bind_proxy& p002 = SC_BIND_PROXY_NIL, 96 /* const */ sc_bind_proxy& p003 = SC_BIND_PROXY_NIL, 97 /* const */ sc_bind_proxy& p004 = SC_BIND_PROXY_NIL, 98 /* const */ sc_bind_proxy& p005 = SC_BIND_PROXY_NIL, 99 /* const */ sc_bind_proxy& p006 = SC_BIND_PROXY_NIL, 100 /* const */ sc_bind_proxy& p007 = SC_BIND_PROXY_NIL, 101 /* const */ sc_bind_proxy& p008 = SC_BIND_PROXY_NIL, 102 /* const */ sc_bind_proxy& p009 = SC_BIND_PROXY_NIL, 103 /* const */ sc_bind_proxy& p010 = SC_BIND_PROXY_NIL, 104 /* const */ sc_bind_proxy& p011 = SC_BIND_PROXY_NIL, 105 /* const */ sc_bind_proxy& p012 = SC_BIND_PROXY_NIL, 106 /* const */ sc_bind_proxy& p013 = SC_BIND_PROXY_NIL, 107 /* const */ sc_bind_proxy& p014 = SC_BIND_PROXY_NIL, 108 /* const */ sc_bind_proxy& p015 = SC_BIND_PROXY_NIL, 109 /* const */ sc_bind_proxy& p016 = SC_BIND_PROXY_NIL, 110 /* const */ sc_bind_proxy& p017 = SC_BIND_PROXY_NIL, 111 /* const */ sc_bind_proxy& p018 = SC_BIND_PROXY_NIL, 112 /* const */ sc_bind_proxy& p019 = SC_BIND_PROXY_NIL, 113 /* const */ sc_bind_proxy& p020 = SC_BIND_PROXY_NIL, 114 /* const */ sc_bind_proxy& p021 = SC_BIND_PROXY_NIL, 115 /* const */ sc_bind_proxy& p022 = SC_BIND_PROXY_NIL, 116 /* const */ sc_bind_proxy& p023 = SC_BIND_PROXY_NIL, 117 /* const */ sc_bind_proxy& p024 = SC_BIND_PROXY_NIL, 118 /* const */ sc_bind_proxy& p025 = SC_BIND_PROXY_NIL, 119 /* const */ sc_bind_proxy& p026 = SC_BIND_PROXY_NIL, 120 /* const */ sc_bind_proxy& p027 = SC_BIND_PROXY_NIL, 121 /* const */ sc_bind_proxy& p028 = SC_BIND_PROXY_NIL, 122 /* const */ sc_bind_proxy& p029 = SC_BIND_PROXY_NIL, 123 /* const */ sc_bind_proxy& p030 = SC_BIND_PROXY_NIL, 124 /* const */ sc_bind_proxy& p031 = SC_BIND_PROXY_NIL, 125 /* const */ sc_bind_proxy& p032 = SC_BIND_PROXY_NIL, 126 /* const */ sc_bind_proxy& p033 = SC_BIND_PROXY_NIL, 127 /* const */ sc_bind_proxy& p034 = SC_BIND_PROXY_NIL, 128 /* const */ sc_bind_proxy& p035 = SC_BIND_PROXY_NIL, 129 /* const */ sc_bind_proxy& p036 = SC_BIND_PROXY_NIL, 130 /* const */ sc_bind_proxy& p037 = SC_BIND_PROXY_NIL, 131 /* const */ sc_bind_proxy& p038 = SC_BIND_PROXY_NIL, 132 /* const */ sc_bind_proxy& p039 = SC_BIND_PROXY_NIL, 133 /* const */ sc_bind_proxy& p040 = SC_BIND_PROXY_NIL, 134 /* const */ sc_bind_proxy& p041 = SC_BIND_PROXY_NIL, 135 /* const */ sc_bind_proxy& p042 = SC_BIND_PROXY_NIL, 136 /* const */ sc_bind_proxy& p043 = SC_BIND_PROXY_NIL, 137 /* const */ sc_bind_proxy& p044 = SC_BIND_PROXY_NIL, 138 /* const */ sc_bind_proxy& p045 = SC_BIND_PROXY_NIL, 139 /* const */ sc_bind_proxy& p046 = SC_BIND_PROXY_NIL, 140 /* const */ sc_bind_proxy& p047 = SC_BIND_PROXY_NIL, 141 /* const */ sc_bind_proxy& p048 = SC_BIND_PROXY_NIL, 142 /* const */ sc_bind_proxy& p049 = SC_BIND_PROXY_NIL, 143 /* const */ sc_bind_proxy& p050 = SC_BIND_PROXY_NIL, 144 /* const */ sc_bind_proxy& p051 = SC_BIND_PROXY_NIL, 145 /* const */ sc_bind_proxy& p052 = SC_BIND_PROXY_NIL, 146 /* const */ sc_bind_proxy& p053 = SC_BIND_PROXY_NIL, 147 /* const */ sc_bind_proxy& p054 = SC_BIND_PROXY_NIL, 148 /* const */ sc_bind_proxy& p055 = SC_BIND_PROXY_NIL, 149 /* const */ sc_bind_proxy& p056 = SC_BIND_PROXY_NIL, 150 /* const */ sc_bind_proxy& p057 = SC_BIND_PROXY_NIL, 151 /* const */ sc_bind_proxy& p058 = SC_BIND_PROXY_NIL, 152 /* const */ sc_bind_proxy& p059 = SC_BIND_PROXY_NIL, 153 /* const */ sc_bind_proxy& p060 = SC_BIND_PROXY_NIL, 154 /* const */ sc_bind_proxy& p061 = SC_BIND_PROXY_NIL, 155 /* const */ sc_bind_proxy& p062 = SC_BIND_PROXY_NIL, 156 /* const */ sc_bind_proxy& p063 = SC_BIND_PROXY_NIL, 157 /* const */ sc_bind_proxy& p064 = SC_BIND_PROXY_NIL); 158 159 ///////// 155 160 // These are protected so that user derived classes can refer to them. 156 sc_sensitive 161 sc_sensitive sensitive; 157 162 sc_sensitive_pos sensitive_pos; 158 163 sc_sensitive_neg sensitive_neg; 159 164 }; 160 165 166 161 167 #define SC_MODULE(user_module_name) \ 162 168 struct user_module_name : public sc_core::sc_module 163 169 164 170 // the SC_HAS_PROCESS macro call must be followed by a ; 165 #define SC_HAS_PROCESS(user_module_name) 166 typedef user_module_name SC_CURRENT_USER_MODULE167 168 #define SC_CTOR(user_module_name) 169 SC_HAS_PROCESS(user_module_name);\170 user_module_name(sc_core::sc_module_name)171 172 /* Converting `void (module_tag::*)()' to `void (sc_module::*)()' is OK as173 long as the dynamic type is correct. C++ Standard 5.4 "Explicit type174 conversion", clause 7: a pointer to member of derived class type may be175 explicitly converted to a pointer to member of an unambiguous non-virtual176 base class type. */171 #define SC_HAS_PROCESS(user_module_name) \ 172 typedef user_module_name SC_CURRENT_USER_MODULE 173 174 #define SC_CTOR(user_module_name) \ 175 SC_HAS_PROCESS(user_module_name); \ 176 user_module_name(sc_core::sc_module_name) 177 178 /* Converting `void (module_tag::*)()' to `void (sc_module::*)()' is OK as 179 long as the dynamic type is correct. C++ Standard 5.4 "Explicit type 180 conversion", clause 7: a pointer to member of derived class type may be 181 explicitly converted to a pointer to member of an unambiguous non-virtual 182 base class type. */ 177 183 #define SC_MAKE_FUNC_PTR(module_tag, func) \ 178 184 (/*static_cast<*/(sc_core::SC_ENTRY_FUNC)/*>*/ (&module_tag::func)) … … 181 187 182 188 #define DECLARE_METHOD_PROCESS(handle, name, module_tag, func) \ 183 declare_method_process(name, \ 184 SC_MAKE_FUNC_PTR( module_tag, func ), \ 185 *this) 186 187 #define SC_METHOD(func) \ 188 { \ 189 DECLARE_METHOD_PROCESS(func ## _handle, #func, SC_CURRENT_USER_MODULE,func);\ 190 } 189 declare_method_process(name, \ 190 SC_MAKE_FUNC_PTR( module_tag, func ), \ 191 *this) 192 193 194 #define SC_METHOD(func) \ 195 { \ 196 DECLARE_METHOD_PROCESS(func ## _handle, #func, SC_CURRENT_USER_MODULE,func); \ 197 } 191 198 192 199 #define SC_MAKE_SAVE_PTR(module_tag, func) \ … … 194 201 195 202 extern void declare_save_handler(const char*,save_fct_t1,sc_module&); 196 //extern void declare_save_handler(const char*,save_fct_t2,sc_module&); 203 197 204 #define DECLARE_SAVE_HANDLER(handle, name, module_tag, func) \ 198 declare_save_handler (name, \ 199 SC_MAKE_SAVE_PTR( module_tag, func ), \ 200 *this) 201 202 #define SAVE_HANDLER(func) \ 203 { \ 204 DECLARE_SAVE_HANDLER(func ## _handle, #func, SC_CURRENT_USER_MODULE,func);\ 205 } 205 declare_save_handler (name, \ 206 SC_MAKE_SAVE_PTR( module_tag, func ), \ 207 *this) 208 209 210 #define SAVE_HANDLER(func) \ 211 { \ 212 DECLARE_SAVE_HANDLER(func ## _handle, #func, SC_CURRENT_USER_MODULE,func); \ 213 } 214 206 215 } // end of namespace sc_core 207 216 208 217 #endif /* __SC_MODULE_EXT_H__ */ 209 218 219 /* 220 # Local Variables: 221 # tab-width: 4; 222 # c-basic-offset: 4; 223 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 224 # indent-tabs-mode: nil; 225 # End: 226 # 227 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 228 */ 229 -
sources/src/sc_module_name.h
r27 r52 11 11 | | 12 12 \------------------------------------------------------------*/ 13 13 14 #ifndef __SC_MODULE_NAME_H__ 14 15 #define __SC_MODULE_NAME_H__ … … 24 25 // ---------------------------------------------------------------------------- 25 26 26 class sc_module_name 27 { 28 ///////////////////////// 29 // SYSTEMCASS SPECIFIC // 30 void init (); 31 ///////////////////////// 32 33 const char* m_name; 34 bool m_pushed; 35 friend class sc_module; 36 // friend class sc_object_manager; 37 public: 38 sc_module_name( const char* ); 39 sc_module_name( const sc_module_name & ); 40 ~sc_module_name (); 41 operator const char*() const { return m_name; }; 42 private: 43 // disabled 44 sc_module_name (); 27 class sc_module_name { 28 29 ///////////////////////// 30 // SYSTEMCASS SPECIFIC // 31 void init(); 32 ///////////////////////// 33 34 const char * m_name; 35 bool m_pushed; 36 friend class sc_module; 37 38 // friend class sc_object_manager; 39 public: 40 sc_module_name(const char *); 41 sc_module_name(const sc_module_name &); 42 ~sc_module_name(); 43 operator const char * () const { return m_name; }; 44 45 private: 46 // disabled 47 sc_module_name(); 45 48 sc_module_name & operator = (const sc_module_name &); 46 49 }; 47 50 48 //std::ostream& operator << (std::ostream&, const sc_core::sc_module_name &);49 51 50 52 } // end of namespace sc_core … … 52 54 #endif /* __SC_MODULE_NAME__ */ 53 55 56 /* 57 # Local Variables: 58 # tab-width: 4; 59 # c-basic-offset: 4; 60 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 61 # indent-tabs-mode: nil; 62 # End: 63 # 64 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 65 */ 66 -
sources/src/sc_nbdefs.h
r1 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __SC_DEFS_H__ 13 14 #define __SC_DEFS_H__ 14 15 15 16 #ifndef WIN32 16 typedef signed long long 17 typedef signed long long int64; 17 18 typedef unsigned long long uint64; 18 19 #else 19 typedef signed __int64 20 typedef unsigned __int64 20 typedef signed __int64 int64; 21 typedef unsigned __int64 uint64; 21 22 #endif 22 23 23 typedef long int32; 24 typedef long int32; 25 typedef short int16; 26 typedef char int8; 24 27 typedef unsigned long uint32; 25 typedef short int16;26 28 typedef unsigned short uint16; 27 typedef char int8;28 29 typedef unsigned char uint8; 29 30 30 typedef uint16 31 typedef int16 31 typedef uint16 smallest_uint; 32 typedef int16 smallest_int; 32 33 33 34 #endif 35 36 /* 37 # Local Variables: 38 # tab-width: 4; 39 # c-basic-offset: 4; 40 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 41 # indent-tabs-mode: nil; 42 # End: 43 # 44 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 45 */ 46 -
sources/src/sc_numrep.cc
r27 r52 35 35 36 36 #include <string> 37 37 38 #include "sc_numrep.h" 39 38 40 #ifdef HAVE_CONFIG_H 39 41 #include "config.h" … … 43 45 44 46 const std::string numrep_name[] = { 45 "SC_DEC",46 "SC_BIN",47 "SC_BIN_US",48 "SC_BIN_SM",49 "SC_OCT",50 "SC_OCT_US",51 "SC_OCT_SM",52 "SC_HEX",53 "SC_HEX_US",54 "SC_HEX_SM",55 "SC_CSD"47 "SC_DEC", 48 "SC_BIN", 49 "SC_BIN_US", 50 "SC_BIN_SM", 51 "SC_OCT", 52 "SC_OCT_US", 53 "SC_OCT_SM", 54 "SC_HEX", 55 "SC_HEX_US", 56 "SC_HEX_SM", 57 "SC_CSD" 56 58 }; 57 59 58 const std::string 59 to_string (sc_numrep n) 60 { 61 return numrep_name[n]; 60 const std::string to_string (sc_numrep n) { 61 return numrep_name[n]; 62 62 } 63 63 … … 65 65 } // end of sc_dt namespace 66 66 67 /* 68 # Local Variables: 69 # tab-width: 4; 70 # c-basic-offset: 4; 71 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 72 # indent-tabs-mode: nil; 73 # End: 74 # 75 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 76 */ 77 -
sources/src/sc_numrep.h
r33 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __SC_NUMREP_H__ 13 14 #define __SC_NUMREP_H__ … … 15 16 #include <cstdio> 16 17 #include <iostream> 18 17 19 #include "sc_string.h" 18 20 … … 20 22 21 23 typedef enum { 22 SC_NOBASE = 0,23 SC_BIN = 2,// binary24 SC_OCT = 8,// octal, two's complement25 SC_DEC = 10,// decimal26 SC_HEX = 16,// hexadecimal, two's complement27 SC_BIN_US, // binary, unsigned28 SC_BIN_SM, // binary, sign magnitude29 SC_OCT_US,30 SC_OCT_SM,31 SC_HEX_US,32 SC_HEX_SM,33 SC_CSD// canonical signed digit24 SC_NOBASE = 0, 25 SC_BIN = 2, // binary 26 SC_OCT = 8, // octal, two's complement 27 SC_DEC = 10, // decimal 28 SC_HEX = 16, // hexadecimal, two's complement 29 SC_BIN_US, // binary, unsigned 30 SC_BIN_SM, // binary, sign magnitude 31 SC_OCT_US, 32 SC_OCT_SM, 33 SC_HEX_US, 34 SC_HEX_SM, 35 SC_CSD // canonical signed digit 34 36 } sc_numrep; 35 37 36 inline 37 const unsigned int bitstring_to_uint (const char * val) 38 { 39 unsigned int i, res = 0; 40 for (i = 0; val[i] != '\0'; ++i) 41 { 42 res <<= 1; 43 res |= (val[i] == '1')?1:0; 44 } 45 return res; 38 39 inline const unsigned int bitstring_to_uint(const char * val) { 40 unsigned int i, res = 0; 41 for (i = 0; val[i] != '\0'; ++i) { 42 res <<= 1; 43 res |= (val[i] == '1') ? 1 : 0; 44 } 45 return res; 46 46 } 47 47 48 48 49 template <typename T> 49 const sc_string to_string (T val, size_t nbits, sc_numrep n)50 { 51 sc_string s(nbits + 3,'0');52 switch (n) {53 case SC_HEX :{54 char t[64];55 char format[64];56 sprintf (format, "0x0%%0%dx", nbits/4);57 sprintf(t, format, val);58 s = t;59 break;60 }61 case SC_BIN : {62 int i;63 s[1] = 'b';64 for (i = nbits - 1; i >= 0; --i)65 {66 s[i + 3] = (val & 1)?'1':'0';67 val >>= 1;68 }69 break;70 }71 default:72 { std::cerr << "error\n"; return s; }73 }74 #if 0 75 std::cerr << "\"" << s << "\"";76 #endif 77 return s;50 const sc_string to_string(T val, size_t nbits, sc_numrep n) { 51 sc_string s(nbits + 3, '0'); 52 switch (n) { 53 case SC_HEX : 54 { 55 char t[64]; 56 char format[64]; 57 sprintf(format, "0x0%%0%dx", nbits / 4); 58 sprintf(t, format, val); 59 s = t; 60 break; 61 } 62 case SC_BIN : 63 { 64 int i; 65 s[1] = 'b'; 66 for (i = nbits - 1; i >= 0; --i) 67 { 68 s[i + 3] = (val & 1)?'1':'0'; 69 val >>= 1; 70 } 71 break; 72 } 73 default: 74 { 75 std::cerr << "error\n"; return s; 76 } 77 } 78 return s; 78 79 } 79 80 80 const std::string to_string 81 const std::string to_string(sc_numrep); 81 82 82 83 } // end of sc_dt namespace … … 98 99 #endif 99 100 101 /* 102 # Local Variables: 103 # tab-width: 4; 104 # c-basic-offset: 4; 105 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 106 # indent-tabs-mode: nil; 107 # End: 108 # 109 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 110 */ 111 -
sources/src/sc_object.cc
r27 r52 39 39 #include <string> 40 40 #include <map> 41 42 41 #include <cassert> 42 43 43 #include "sc_object.h" 44 //#include "sc_port.h"45 44 #include "internal.h" 46 45 #include "sc_signal.h" 47 46 #include "module_hierarchy.h" 47 48 48 #ifdef HAVE_CONFIG_H 49 49 #include "config.h" 50 50 #endif 51 51 52 52 53 using namespace std; 53 54 54 55 namespace sc_core { 55 56 56 static void 57 gen_name (const char *prefix, string &s) 58 { 59 s = prefix; 60 static int i = 0; 61 char ic[10]; 62 sprintf (ic,"%d",i++); 63 s += ic; 64 } 65 // ---------------------------------------------------------------------------- 66 static void 67 build_complete_name (const char *name, string &out) 68 { 69 out = ""; 70 module_name_stack_t::const_iterator i; 71 for (i = module_name_stack.begin (); i != module_name_stack.end (); ++i) { 72 const string &module_name = *i; 73 out += (module_name + "."); 74 // out += "."; 75 } 76 // assert(name != NULL); 77 if (name) 78 out += name; 79 else 80 out[out.length ()-1] = '\0'; 81 #if 0 82 cerr << "complete_name = " << out << endl; 83 #endif 84 } 85 86 #if 0 87 static 88 void 89 build_full_name_r (string &out, const sc_object *obj) 90 { 91 if (obj == NULL) 92 { 57 static void gen_name (const char *prefix, string &s) { 58 s = prefix; 59 static int i = 0; 60 char ic[10]; 61 sprintf (ic,"%d",i++); 62 s += ic; 63 } 64 65 66 static void build_complete_name (const char *name, string &out) { 93 67 out = ""; 94 } else { 95 const sc_object *parent = obj->get_parent_object (); 96 build_full_name_r (out, parent); 97 out += obj->basename (); 98 out += "."; 99 } 100 } 101 102 static 103 void 104 build_full_name (string &out, const sc_object &obj) 105 { 106 const sc_object *parent = obj.get_parent_object (); 107 build_full_name_r (out, parent); 108 out += obj.basename (); 109 cerr << "build_full_name = " << out << endl; 110 } 111 #endif 112 113 typedef std::map<const sc_object* const,string> object2name_t; 68 module_name_stack_t::const_iterator i; 69 for (i = module_name_stack.begin (); i != module_name_stack.end (); ++i) { 70 const string &module_name = *i; 71 out += (module_name + "."); 72 } 73 if (name) { 74 out += name; 75 } 76 else { 77 out[out.length ()-1] = '\0'; 78 } 79 } 80 81 82 typedef std::map<const sc_object * const, string> object2name_t; 114 83 static object2name_t object2basename; 115 84 static object2name_t object2fullname; 116 85 117 86 struct object_infos_t { 118 const char *kind_string;87 const char * kind_string; 119 88 }; 120 typedef std::map<const sc_object* const,object_infos_t> object2infos_t; 89 90 typedef std::map<const sc_object * const, object_infos_t> object2infos_t; 121 91 static object2infos_t object2infos; 92 122 93 123 94 // We initialize SC_BIND_PROXY_NIL there to make sure object2infos, … … 125 96 // SC_BIND_PROXY_NIL should be declared into sc_module.cc but it prevents us 126 97 // to force the initialization order. 127 const char *SC_BIND_PROXY_NIL_string = "SC_BIND_PROXY_NIL"; 128 sc_bind_proxy SC_BIND_PROXY_NIL (SC_BIND_PROXY_NIL_string,NULL); 98 const char * SC_BIND_PROXY_NIL_string = "SC_BIND_PROXY_NIL"; 99 sc_bind_proxy SC_BIND_PROXY_NIL(SC_BIND_PROXY_NIL_string, NULL); 100 129 101 130 102 // ---------------------------------------------------------------------------- … … 132 104 // 133 105 // ---------------------------------------------------------------------------- 134 135 const char * 136 sc_gen_unique_name (const char *basename_) 137 { 138 string s; 139 gen_name (basename_,s); 140 return strdup (s.c_str ()); 141 } 106 const char * sc_gen_unique_name(const char * basename_) { 107 string s; 108 gen_name(basename_,s); 109 return strdup (s.c_str()); 110 } 111 142 112 143 113 // ---------------------------------------------------------------------------- … … 146 116 // ---------------------------------------------------------------------------- 147 117 148 const char* const sc_object::kind_string = "sc_object"; 149 150 void 151 sc_object::set_kind (const char *k) 152 { 153 object2infos[this].kind_string = k; 154 } 155 156 void 157 sc_object::init () 158 { 159 set_kind ("sc_object"); 160 add_child (*this); 161 } 162 163 sc_object::sc_object() 164 { 165 string noname; 166 gen_name ("noname_",noname); 167 #if 0 168 cerr << "object2basename[this] = " << noname << "\n"; 169 #endif 170 object2basename[this] = noname; 171 build_complete_name (noname.c_str(),object2fullname[this]); 172 init (); 173 } 174 175 sc_object::sc_object(const char *name_) 176 { 177 const char *temp; 178 if (name_ == NULL) { 179 if (module_name_stack.empty()) 180 { 181 cerr << "Internal error : module_name_stack is empty."; 182 exit (21092005); 183 } 184 string &module_name = module_name_stack.back (); 185 temp = module_name.c_str (); 186 } else { 187 temp = name_; 188 } 189 #if 0 190 cerr << "object2basename[this] = " << temp << "\n"; 191 cerr << "name temp = " << temp << endl; 192 #endif 193 object2basename[this] = temp; 194 build_complete_name (name_,object2fullname[this]); 195 init (); 196 } 197 198 const char * 199 sc_object::basename () const 200 { 201 return object2basename[this].c_str (); 202 } 203 204 const char * 205 sc_object::name () const 206 { 207 object2name_t::iterator i = object2fullname.find (this); 118 const char * const sc_object::kind_string = "sc_object"; 119 120 void sc_object::set_kind(const char * k) { 121 object2infos[this].kind_string = k; 122 } 123 124 125 void sc_object::init() { 126 set_kind("sc_object"); 127 add_child(*this); 128 } 129 130 131 sc_object::sc_object() { 132 string noname; 133 gen_name("noname_", noname); 134 object2basename[this] = noname; 135 build_complete_name(noname.c_str(), object2fullname[this]); 136 init(); 137 } 138 139 140 sc_object::sc_object(const char * name_) { 141 const char * temp; 142 if (name_ == NULL) { 208 143 #ifdef CONFIG_DEBUG 209 if (i == object2fullname.end ()) { 210 cerr << "Internal error : can't find name of " << this << "\n"; 211 exit (90); 212 } 213 #endif 214 return i->second.c_str (); 215 } 216 217 void 218 sc_object::rename (const char* newname) const 219 { 144 if (module_name_stack.empty()) { 145 cerr << "Internal error : module_name_stack is empty."; 146 exit(21092005); 147 } 148 #endif 149 string & module_name = module_name_stack.back(); 150 temp = module_name.c_str(); 151 } 152 else { 153 temp = name_; 154 } 155 object2basename[this] = temp; 156 build_complete_name(name_, object2fullname[this]); 157 init(); 158 } 159 160 161 const char * sc_object::basename() const { 162 return object2basename[this].c_str(); 163 } 164 165 166 const char * sc_object::name() const { 167 object2name_t::iterator i = object2fullname.find(this); 168 #ifdef CONFIG_DEBUG 169 if (i == object2fullname.end()) { 170 cerr << "Internal error : can't find name of " << this << "\n"; 171 exit (90); 172 } 173 #endif 174 return i->second.c_str(); 175 } 176 177 178 void sc_object::rename(const char * newname) const { 179 object2basename[this] = newname; 180 build_complete_name (newname,object2fullname[this]); 181 } 182 183 184 const char * sc_object::kind() const { 185 object2infos_t::iterator i = object2infos.find(this); 186 #ifdef CONFIG_DEBUG 187 if (i == object2infos.end()) { 188 cerr << "Internal error : can't find kind of " << this << "\n"; 189 exit(90); 190 } 191 #endif 192 return i->second.kind_string; 193 } 194 195 196 sc_object::~sc_object() { 197 if (save_on_exit) { 198 sc_save_simulation(save_on_exit); 199 save_on_exit = NULL; 200 } 201 object2fullname.erase(this); 202 object2basename.erase(this); 203 object2infos.erase(this); 204 } 205 206 207 std::ostream & operator << (std::ostream & os, const sc_object & obj) { 208 return os << obj.name (); 209 } 210 211 212 /* virtual */ 213 const std::vector<sc_object *> & sc_object::get_child_objects() const { 214 return sc_core::get_child_objects(*this); 215 } 216 217 218 sc_object * sc_object::get_parent_object() const { 219 return sc_core::get_parent_object(*this); 220 } 221 222 223 } // end of sc_core namespace 224 225 220 226 /* 221 object2name_t::iterator i = object2fullname.find (this); 222 #ifdef CONFIG_DEBUG 223 if (i == object2fullname.end ()) { 224 cerr << "Internal error : can't find name of " << this << "\n"; 225 exit (90); 226 } 227 #endif 228 i->second = newname; 229 object2basename[this] = newname; 227 # Local Variables: 228 # tab-width: 4; 229 # c-basic-offset: 4; 230 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 231 # indent-tabs-mode: nil; 232 # End: 233 # 234 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 230 235 */ 231 object2basename[this] = newname; 232 build_complete_name (newname,object2fullname[this]); 233 /* 234 const std::vector<sc_object*>& childs = get_child_objects(); 235 std::vector<sc_object*>::const_iterator it; 236 for (it = childs.begin (); it != childs.end (); ++it) 237 { 238 string out; 239 sc_object* obj = *it; 240 assert(obj != NULL); 241 build_full_name (out, *obj); 242 } 243 */ 244 } 245 const char *sc_object::kind () const 246 { 247 object2infos_t::iterator i = object2infos.find (this); 248 #ifdef CONFIG_DEBUG 249 if (i == object2infos.end ()) { 250 cerr << "Internal error : can't find kind of " << this << "\n"; 251 exit (90); 252 } 253 #endif 254 return i->second.kind_string; 255 } 256 257 sc_object::~sc_object () 258 { 259 if (save_on_exit) 260 { 261 sc_save_simulation (save_on_exit); 262 save_on_exit = NULL; 263 } 264 object2fullname.erase (this); 265 object2basename.erase (this); 266 object2infos.erase (this); 267 } 268 269 std::ostream& 270 operator << (std::ostream& os, const sc_object& obj) 271 { 272 return os << obj.name (); 273 } 274 275 /* virtual */ 276 const std::vector<sc_object*>& 277 sc_object::get_child_objects() const 278 { 279 return sc_core::get_child_objects (*this); 280 } 281 282 sc_object* 283 sc_object::get_parent_object () const 284 { 285 return sc_core::get_parent_object (*this); 286 } 287 288 } // end of sc_core namespace 289 236 -
sources/src/sc_object.h
r1 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __SC_OBJECT_H__ 13 14 #define __SC_OBJECT_H__ … … 23 24 namespace sc_core { 24 25 25 class sc_object 26 { 27 /////////// 26 27 class sc_object { 28 29 /////////// 28 30 // Internal 29 protected: void init (); 30 protected: void set_kind (const char *); 31 /////////// 32 public: 33 static const char* const kind_string; 34 // LRM 35 const char *name () const; 36 const char *basename () const; 37 void rename (const char*) const; 31 // //////// 32 protected: 33 void init(); 34 void set_kind(const char *); 38 35 39 friend std::ostream& operator << (std::ostream& , const sc_object&); 40 /* 41 void print () const; 42 virtual void print (std::ostream & os) const; 43 void dump () const; 44 virtual void dump (std::ostream & os) const; 45 virtual void trace (sc_trace_file *) const; 46 */ 47 /*virtual*/ const char *kind () const; 48 /* 49 sc_simcontext *simcontext () const; 50 bool add_attribute (sc_attr_base &); 51 sc_attr_base *get_attribute (const sc_string &); 52 const sc_attr_base *get_attribute (const sc_string &) const; 53 sc_attr_base *remove_attribute (const sc_string &); 54 void remove_all_attributes (); 55 int num_attributes () const; 56 sc_attr_cltn & attr_cltn (); 57 const sc_attr_cltn & attr_cltn () const; 58 */ 59 /* virtual */ const std::vector<sc_object*>& get_child_objects() const; 60 sc_object* get_parent_object () const; 61 protected: 62 sc_object (); 63 sc_object (const char *); 64 /*virtual */~ sc_object (); 65 36 37 public: 38 static const char * const kind_string; 39 // LRM 40 const char * name() const; 41 const char * basename() const; 42 void rename(const char*) const; 43 44 friend std::ostream & operator << (std::ostream &, const sc_object &); 45 /* virtual */ const char * kind() const; 46 /* virtual */ const std::vector<sc_object *> & get_child_objects() const; 47 sc_object * get_parent_object() const; 48 49 protected: 50 sc_object(); 51 sc_object(const char *); 52 /*virtual */~sc_object(); 53 66 54 }; 67 55 68 const std::vector<sc_object *>& sc_get_top_level_objects();69 const sc_object * sc_find_object (const char*);56 const std::vector<sc_object *> & sc_get_top_level_objects(); 57 const sc_object * sc_find_object(const char *); 70 58 71 59 } // end of sc_core namespace … … 76 64 #endif 77 65 66 /* 67 # Local Variables: 68 # tab-width: 4; 69 # c-basic-offset: 4; 70 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 71 # indent-tabs-mode: nil; 72 # End: 73 # 74 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 75 */ 76 -
sources/src/sc_pat_trace.cc
r27 r52 35 35 */ 36 36 37 #include <ctime> 37 38 38 39 #include "sc_trace.h" … … 41 42 #include "internal.h" // notrace 42 43 43 #include <ctime>44 44 #ifdef HAVE_CONFIG_H 45 45 #include "config.h" … … 48 48 #ifdef CONFIG_PAT_TRACE_FORMAT 49 49 50 //----------------------------------------- 50 51 51 52 52 extern "C" { … … 54 54 } 55 55 56 //#include "malloc.h" // NO LONGER SUPPORTED 56 57 57 #include <cstdlib> 58 58 #include <cstdio> 59 59 60 //-----------------------------------------61 60 62 61 using namespace std; … … 64 63 namespace sc_core { 65 64 66 //*************************************************************************67 65 68 sc_trace_file* 69 sc_create_pat_trace_file(const char * name) 70 { 71 if (notrace) 72 return NULL; 73 //création d'1 instance de la structure Sc_trace_file: 74 sc_trace_file *traceFic=new sc_trace_file(); 75 traceFic->flag = PAT_FORMAT; 76 77 trace_file_list.push_back(traceFic); 78 79 DEF_GENPAT((char *)name); 80 81 return traceFic; 82 //pointeur sur le sc_trace_file dontl'un des elts pointe sur le fichier.pat crée 83 66 sc_trace_file * sc_create_pat_trace_file(const char * name) { 67 if (notrace) { 68 return NULL; 69 } 70 //création d'1 instance de la structure Sc_trace_file: 71 sc_trace_file * traceFic = new sc_trace_file(); 72 traceFic->flag = PAT_FORMAT; 73 74 trace_file_list.push_back(traceFic); 75 76 DEF_GENPAT((char *) name); 77 78 return traceFic; 79 //pointeur sur le sc_trace_file dontl'un des elts pointe sur le fichier.pat crée 84 80 } 81 85 82 86 83 //************************************************************************* 87 84 88 void 89 sc_close_pat_trace_file( sc_trace_file* traceFic ) 90 { 91 if (notrace) 92 return; 85 void sc_close_pat_trace_file(sc_trace_file * traceFic ) { 86 if (notrace) { 87 return; 88 } 93 89 94 trace (*traceFic,false);90 trace(*traceFic, false); 95 91 96 SAV_GENPAT (); 97 98 //libération de l'instance de la structure en mémoire: 99 delete traceFic; 92 SAV_GENPAT(); 100 93 101 vector<sc_trace_file*>::iterator i; 102 for (i = trace_file_list.begin (); i != trace_file_list.end(); ++i) 103 if (*i == traceFic) { 104 trace_file_list.erase(i); 105 break; 106 } 94 //libération de l'instance de la structure en mémoire: 95 delete traceFic; 96 97 vector<sc_trace_file *>::iterator i; 98 for (i = trace_file_list.begin (); i != trace_file_list.end(); ++i) { 99 if (*i == traceFic) { 100 trace_file_list.erase(i); 101 break; 102 } 103 } 107 104 } 108 105 … … 110 107 111 108 #endif 109 110 /* 111 # Local Variables: 112 # tab-width: 4; 113 # c-basic-offset: 4; 114 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 115 # indent-tabs-mode: nil; 116 # End: 117 # 118 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 119 */ 120 -
sources/src/sc_pat_trace.h
r1 r52 11 11 | | 12 12 \------------------------------------------------------------*/ 13 13 14 #ifndef SC_PAT_TRACE_H 14 15 #define SC_PAT_TRACE_H … … 20 21 21 22 // Create PAT file 22 extern sc_trace_file * sc_create_pat_trace_file(const char* name);23 extern sc_trace_file * sc_create_pat_trace_file(const char * name); 23 24 24 25 // Close PAT file … … 32 33 #endif 33 34 35 /* 36 # Local Variables: 37 # tab-width: 4; 38 # c-basic-offset: 4; 39 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 40 # indent-tabs-mode: nil; 41 # End: 42 # 43 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 44 */ 45 -
sources/src/sc_port.cc
r47 r52 51 51 52 52 extern "C" { 53 54 char unstable = 0; // not in sc_core namespace because dynamic link support C linkage only55 int32_t pending_write_vector_nb = 0;53 extern char unstable; 54 char unstable = 0; // not in sc_core namespace because dynamic link support C linkage only 55 int32_t pending_write_vector_nb = 0; 56 56 } 57 57 … … 60 60 namespace sc_core { 61 61 62 const char * const sc_port_base::kind_string = "sc_port";63 const char * const sc_signal_base::kind_string = "sc_signal";62 const char * const sc_port_base::kind_string = "sc_port"; 63 const char * const sc_signal_base::kind_string = "sc_signal"; 64 64 65 65 unsigned int pending_write_vector_capacity = 512; … … 67 67 extern equi_list_t equi_list; 68 68 69 const char* get_module_name (const tab_t *pointer) 70 { 71 const equi_t &eq = get_equi (pointer); 72 return get_module_name (eq); 73 } 74 75 //typedef std::map<const sc_port_base*, const sc_module*> port2module_t; 69 const char * get_module_name (const tab_t * pointer) { 70 const equi_t & eq = get_equi (pointer); 71 return get_module_name (eq); 72 } 73 76 74 port2module_t port2module; 77 75 … … 80 78 const char * const sc_in_string = "sc_in"; 81 79 const char * const sc_out_string = "sc_out"; 80 82 81 83 82 // ---------------------------------------------------------------------------- … … 87 86 // ---------------------------------------------------------------------------- 88 87 89 sc_port_base::sc_port_base() 90 { 88 sc_port_base::sc_port_base() { 91 89 init (); 92 90 } 93 91 94 sc_port_base::sc_port_base(const char* name_) : sc_object(name_) 95 { 96 init (); 97 } 98 99 sc_port_base::sc_port_base(const sc_port_base& parent_) : sc_object (parent_.name ()) 100 { 101 init (); 102 } 103 104 void 105 sc_port_base::init () 106 { 92 93 sc_port_base::sc_port_base(const char * name_) : sc_object(name_) { 94 init (); 95 } 96 97 98 sc_port_base::sc_port_base(const sc_port_base & parent_) : sc_object (parent_.name ()) { 99 init (); 100 } 101 102 103 void sc_port_base::init() { 107 104 #ifdef CONFIG_DEBUG 108 if (modules_stack.empty ()) { 109 cerr << "Internal error : modules stack empty\n"; 110 exit (9); 111 } 112 #endif 113 const sc_module *last_module = sc_core::modules_stack.top (); 114 port2module[this] = last_module; 115 set_kind (kind_string); 116 } 117 118 const sc_module & 119 sc_port_base::get_module () const 120 { 121 port2module_t::iterator i = port2module.find ((sc_port_base*)this); 122 if (i == port2module.end ()) { 123 cerr << "Internal error : Modules contain ports. " 105 if (modules_stack.empty()) { 106 cerr << "Internal error : modules stack empty\n"; 107 exit (9); 108 } 109 #endif 110 const sc_module * last_module = sc_core::modules_stack.top(); 111 port2module[this] = last_module; 112 set_kind(kind_string); 113 } 114 115 116 const sc_module & sc_port_base::get_module() const { 117 port2module_t::iterator i = port2module.find ((sc_port_base *) this); 118 if (i == port2module.end()) { 119 cerr << "Internal error : Modules contain ports. " 124 120 "SystemCASS needs to identify the module that contains the following port : '" 125 << name() 126 << "'\n"; 127 exit (17); 128 } 129 const sc_module *m = i->second; 130 return *m; 131 } 121 << name() 122 << "'\n"; 123 exit (17); 124 } 125 const sc_module * m = i->second; 126 return *m; 127 } 128 132 129 133 130 static bool check_multiwriting2port_error_message = true; 134 void 135 sc_port_base::check_multiwriting2port () const 136 { 137 static std::map<sc_port_base*, double> s; 138 double t = sc_simulation_time (); 139 if (t == 0) 140 return; 141 sc_port_base *port = (sc_port_base*)this; 142 if ((s[port] == t) && (check_multiwriting2port_error_message)) 143 { 144 check_multiwriting2port_error_message = 0; 145 if (use_port_dependency) 146 { 147 std::cerr << "Error at cycle #" << t << " : " 148 "SystemCASS allows only 1 writing for each ports/signals.\n" 131 132 void sc_port_base::check_multiwriting2port() const { 133 static std::map<sc_port_base *, double> s; 134 double t = sc_simulation_time(); 135 if (t == 0) { 136 return; 137 } 138 sc_port_base * port = (sc_port_base *) this; 139 if ((s[port] == t) && (check_multiwriting2port_error_message)) { 140 check_multiwriting2port_error_message = 0; 141 if (use_port_dependency) { 142 std::cerr << "Error at cycle #" << t << " : " 143 "SystemCASS allows only 1 writing for each ports/signals.\n" 149 144 << "Functions write several times into '" << name () << "'.\n"; 150 } else { 151 std::cerr << "Error : " 152 "Multiwriting to port assertion works only " 153 "when SystemCASS uses port dependency information " 154 "(--p parameter).\n"; 155 } 156 sc_core::sc_stop (); 157 exit (31072006); // 6 158 } else 159 s[port] = t; 160 } 161 162 std::ostream& 163 operator << (std::ostream &o, const sc_port_base &p) 164 { 165 return o << p.name (); 166 } 145 } 146 else { 147 std::cerr << "Error : " 148 "Multiwriting to port assertion works only " 149 "when SystemCASS uses port dependency information " 150 "(--p parameter).\n"; 151 } 152 sc_core::sc_stop(); 153 exit (31072006); // 6 154 } 155 else { 156 s[port] = t; 157 } 158 } 159 160 161 std::ostream & operator << (std::ostream & o, const sc_port_base & p) { 162 return o << p.name(); 163 } 164 165 167 166 // ---------------------------------------------------------------------------- 168 167 // CLASS : sc_signal_base … … 170 169 // The sc_signal<T> primitive channel class. 171 170 // ---------------------------------------------------------------------------- 172 173 void 174 sc_signal_base::init () 175 { 176 set_kind (kind_string); 177 bind (*this); 178 } 171 void sc_signal_base::init() { 172 set_kind(kind_string); 173 bind(*this); 174 } 175 179 176 180 177 sc_signal_base::sc_signal_base() { 181 init (); 182 } 183 184 sc_signal_base::sc_signal_base(const char* name_) : sc_object(name_) { 185 init (); 186 } 187 188 sc_signal_base::sc_signal_base(const char* name_, void*) : sc_object(name_) { 189 // this overload is only used for SC_BIND_PROXY_NIL constant. 190 // this signal should not be added to the signal list. 191 } 192 193 sc_signal_base::~sc_signal_base() { 194 } 178 init(); 179 } 180 181 182 sc_signal_base::sc_signal_base(const char * name_) : sc_object(name_) { 183 init (); 184 } 185 186 187 sc_signal_base::sc_signal_base(const char * name_, void *) : sc_object(name_) { 188 // this overload is only used for SC_BIND_PROXY_NIL constant. 189 // this signal should not be added to the signal list. 190 } 191 192 193 sc_signal_base::~sc_signal_base() {} 194 195 195 196 196 /* … … 199 199 200 200 #ifdef DUMP_SIGNAL_STATS 201 typedef map<tab_t *,long long int> counter_t;202 static counter_t 201 typedef map<tab_t *, long long int> counter_t; 202 static counter_t counter; 203 203 long long int unnecessary = 0; 204 204 long long int total_assig = 0; … … 207 207 } // end of sc_core namespace 208 208 209 209 210 extern "C" { 210 void 211 update () 212 { 211 212 void update() { 213 213 #if defined(DUMP_STAGE) 214 cerr << "Updating... "; 215 #endif 216 // stl vectors are too slow 217 // memcopy is not better 218 // signal table sorting doesn't give any better performance 219 #if 0 220 cerr << pending_write_vector_nb << " " << pending_write_vector_capacity << endl; 221 #endif 214 cerr << "Updating... "; 215 #endif 216 // stl vectors are too slow 217 // memcopy is not better 218 // signal table sorting doesn't give any better performance 222 219 #if defined(DUMP_STAGE) 223 cerr << "(" << pending_write_vector_nb 224 << " internal pending writings) "; 225 #endif 226 unsigned int i; 227 for (i = 0; i < pending_write_vector_nb; ++i) { 228 #if 0 229 cerr << "pending_write[" << i << "] : " << pending_write_vector[i]; 230 #endif 220 cerr << "(" << pending_write_vector_nb 221 << " internal pending writings) "; 222 #endif 223 unsigned int i; 224 for (i = 0; i < pending_write_vector_nb; ++i) { 231 225 #define iter (sc_core::pending_write_vector[i]) 232 226 #ifdef CONFIG_DEBUG 233 234 235 236 227 if (iter.pointer == NULL) { 228 cerr << "Internal error : trying to apply a posted write from an unassigned signal/port\n"; 229 exit (8); 230 } 237 231 #endif 238 232 #ifdef DUMP_SIGNAL_STATS 239 if (*(iter.pointer) == iter.value) 240 unnecessary++; 241 counter[iter.pointer]++; 242 #endif 243 *(iter.pointer) = iter.value; 233 if (*(iter.pointer) == iter.value) { 234 unnecessary++; 235 } 236 counter[iter.pointer]++; 237 #endif 238 *(iter.pointer) = iter.value; 244 239 #undef iter 245 }240 } 246 241 #ifdef DUMP_SIGNAL_STATS 247 248 #endif 249 242 total_assig += pending_write_vector_nb; 243 #endif 244 pending_write_vector_nb = 0; 250 245 251 246 #if defined(DUMP_STAGE) 252 cerr << "done.\n";253 #endif 254 }247 cerr << "done.\n"; 248 #endif 249 } 255 250 256 251 } // end of extern "C" … … 258 253 namespace sc_core { 259 254 260 void 261 print_registers_writing_stats (ostream &o) 262 { 255 void print_registers_writing_stats (ostream & o) { 263 256 #ifdef DUMP_SIGNAL_STATS 264 o << "signal index / name / usage (>1%)\n"; 265 o << setprecision (2); 266 double t = sc_simulation_time (); 267 if (t == 0) { 268 o << "Warning : simulation too short.\n"; 269 t = 0.01; 270 } 271 if (total_assig == 0) 272 return; 273 counter_t::iterator k; 274 for (k = counter.begin (); k != counter.end (); ++k) { 275 double usage = k->second / t * 100; 276 if (usage <= 1) 277 continue; 278 o << k->first 279 << " " << get_name (k->first) 280 << " " << usage << "%\n"; 281 } 282 typedef map<string,int> counter_module_t; 283 counter_module_t counter_by_module; 284 for (k = counter.begin (); k != counter.end (); ++k) { 285 string module_name = get_module_name (k->first); 286 counter_by_module[module_name] += k->second; 287 } 288 o << "module name / usage\n"; 289 counter_module_t::iterator i; 290 for (i = counter_by_module.begin (); i != counter_by_module.end (); ++i) { 291 o << i->first 292 << " " << (i->second * 100 / total_assig) << "%\n"; 293 } 294 cerr << "average of assignment number per cycle " << (total_assig / t) << "\n"; 295 cerr << (unnecessary * 100 / total_assig) << "% of assignment are unecessary\n"; 257 o << "signal index / name / usage (>1%)\n"; 258 o << setprecision(2); 259 double t = sc_simulation_time(); 260 if (t == 0) { 261 o << "Warning : simulation too short.\n"; 262 t = 0.01; 263 } 264 if (total_assig == 0) { 265 return; 266 } 267 counter_t::iterator k; 268 for (k = counter.begin(); k != counter.end(); ++k) { 269 double usage = k->second / t * 100; 270 if (usage <= 1) { 271 continue; 272 } 273 o << k->first << " " << get_name (k->first) << " " << usage << "%\n"; 274 } 275 typedef map<string, int> counter_module_t; 276 counter_module_t counter_by_module; 277 for (k = counter.begin(); k != counter.end(); ++k) { 278 string module_name = get_module_name (k->first); 279 counter_by_module[module_name] += k->second; 280 } 281 o << "module name / usage\n"; 282 counter_module_t::iterator i; 283 for (i = counter_by_module.begin(); i != counter_by_module.end(); ++i) { 284 o << i->first << " " << (i->second * 100 / total_assig) << "%\n"; 285 } 286 cerr << "average of assignment number per cycle " << (total_assig / t) << "\n"; 287 cerr << (unnecessary * 100 / total_assig) << "% of assignment are unecessary\n"; 296 288 #else 297 cerr << "Register usage not available.\n"; 298 #endif 299 } 300 301 static 302 bool 303 is_bound (/*const*/ sc_port_base &port) 304 { 305 const tab_t *pointer = port.get_pointer (); 306 //assert(pointer != NULL); 307 if (pointer == NULL) 308 return false; // case : sc_in not bound 309 /* 310 equi_t &e = get_equi (pointer); 311 if (e.size () == 1) 312 return true; // case : sc_out not bound 313 */ 314 return has_equi (port); 315 } 316 317 static 318 void 319 check_port (/*const*/ sc_port_base &port) 320 { 321 if (!is_bound (port)) 322 { 323 cerr << "Error : '" << port.name () << "' port" 289 cerr << "Register usage not available.\n"; 290 #endif 291 } 292 293 static bool is_bound(/*const*/ sc_port_base & port) { 294 const tab_t * pointer = port.get_pointer(); 295 //assert(pointer != NULL); 296 if (pointer == NULL) { 297 return false; // case : sc_in not bound 298 } 299 return has_equi (port); 300 } 301 302 static void check_port(/*const*/ sc_port_base & port) { 303 if (!is_bound (port)) { 304 cerr << "Error : '" << port.name() << "' port" 324 305 " (" << port.kind() << ")" 325 306 " is not bound.\n"; 326 exit (29); 327 } 328 } 329 330 void 331 check_all_ports () 332 { 333 if (dump_stage) 334 cerr << "checking ports..."; 335 port2module_t::/*const_*/iterator i; 336 for (i = port2module.begin (); i != port2module.end (); ++i) 337 { 338 /*const*/ sc_port_base *port = i->first; 339 assert(port != NULL); 340 check_port (*port); 341 } 342 if (dump_stage) 343 cerr << " done."; 344 } 307 exit (29); 308 } 309 } 310 311 312 void check_all_ports() { 313 if (dump_stage) { 314 cerr << "checking ports..."; 315 } 316 port2module_t::/*const_*/iterator i; 317 for (i = port2module.begin(); i != port2module.end(); ++i) { 318 /*const*/ sc_port_base *port = i->first; 319 assert(port != NULL); 320 check_port(*port); 321 } 322 if (dump_stage) { 323 cerr << " done."; 324 } 325 } 326 345 327 346 328 } // end of sc_core namespace 347 329 348 330 331 /* 332 # Local Variables: 333 # tab-width: 4; 334 # c-basic-offset: 4; 335 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 336 # indent-tabs-mode: nil; 337 # End: 338 # 339 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 340 */ 341 -
sources/src/sc_port.h
r27 r52 11 11 | | 12 12 \------------------------------------------------------------*/ 13 13 14 #ifndef __SC_PORT_H__ 14 15 #define __SC_PORT_H__ … … 16 17 #include "sc_port_ext.h" 17 18 #include "sc_fwd.h" 18 //#include "internal_ext.h"19 19 20 20 #include <list> 21 21 22 //23 22 namespace sc_core { 24 // 25 const char * get_module_name (const tab_t *pointer);26 void check_all_ports();23 24 const char * get_module_name(const tab_t * pointer); 25 void check_all_ports(); 27 26 28 27 } // end of sc_core namespace 29 28 30 29 #endif /* __SC_PORT_H__ */ 30 31 /* 32 # Local Variables: 33 # tab-width: 4; 34 # c-basic-offset: 4; 35 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 36 # indent-tabs-mode: nil; 37 # End: 38 # 39 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 40 */ 41 -
sources/src/sc_port_ext.h
r47 r52 11 11 | | 12 12 \------------------------------------------------------------*/ 13 13 14 #ifndef __SC_PORT_EXT_H__ 14 15 #define __SC_PORT_EXT_H__ … … 36 37 // 37 38 #if ((__GNUC__ < 3) || (__GNUC_MINOR__ < 4)) 38 #define INLINE __attribute__((always_inline))39 #define INLINE __attribute__((always_inline)) 39 40 #else 40 /* gcc3.4 doesn't support */41 #define INLINE41 /* gcc3.4 doesn't support */ 42 #define INLINE 42 43 #endif 43 44 44 45 #include <list> 45 46 46 // 47 47 48 namespace sc_core { 48 // 49 50 using namespace sc_dt; 51 52 const char *get_name (const tab_t *pointer); 49 50 using namespace sc_dt; 51 52 const char * get_name(const tab_t * pointer); 53 53 54 54 #define READ_SIGNAL(value_type_,pointer_) \ 55 55 ((value_type_&) (*((value_type_*) (pointer_)))) 56 56 57 57 58 ///////////////////// DEPRECATED 58 59 // C ANSI-only since it is needed to link with extern "C" 59 60 60 extern void bind (sc_port_base&,sc_port_base&); 61 extern void bind (sc_port_base&,sc_signal_base&); 62 extern void bind (sc_signal_base &x); 63 extern void bind (sc_port_base &x); 61 62 extern void bind(sc_port_base &, sc_port_base&); 63 extern void bind(sc_port_base &, sc_signal_base&); 64 extern void bind(sc_signal_base & x); 65 extern void bind(sc_port_base & x); 64 66 65 67 // KIND STRING … … 68 70 extern const char * const sc_out_string; 69 71 70 extern "C" void update (void); 71 72 class sc_port_base : public sc_object, public sc_interface 72 extern "C" void update(void); 73 74 class sc_port_base : public sc_object, public sc_interface { 75 76 protected: 77 typedef sc_port_base base_type; 78 79 public: 80 /////////// 81 // Internal 82 const sc_module & get_module() const; 83 void init(); 84 void check_multiwriting2port() const; 85 /////////// 86 87 friend std::ostream & operator << (std::ostream &, const sc_port_base &); 88 89 90 // LRM 91 static const char * const kind_string; 92 // 93 94 sc_port_base(); 95 sc_port_base(const char * name_); 96 explicit sc_port_base(const sc_port_base & parent_); 97 /*virtual */~sc_port_base() {}; 98 // bind to a handle 99 void operator () (method_process_t & func) const; 100 }; 101 102 103 template < typename T > class sc_port_b : public sc_port_base 73 104 { 74 protected: 75 typedef sc_port_base base_type; 76 public: 105 }; 106 107 108 // ---------------------------------------------------------------------------- 109 // CLASS : sc_in< T > 110 // 111 // ---------------------------------------------------------------------------- 112 113 template < typename T > 114 class sc_in : public sc_port_base { 115 116 private: 117 typedef T data_type; 118 typedef sc_port_base base_type; 119 typedef sc_in<data_type> this_type; 120 typedef sc_signal<data_type> signal_type; 121 122 123 /////////// 124 // Internal 125 void init(); 126 /////////// 127 128 public: 129 // constructors 130 sc_in() : base_type() { init(); } 131 132 explicit sc_in(const char * name_) : base_type(name_) { init(); } 133 134 explicit sc_in(const base_type & parent_) : base_type( parent_ ) { init(); } 135 136 /* 137 // LRM error ! 138 //static const char *const kind_string; this is a template ! 139 */ 140 // virtual const char *kind () const 141 // { return "sc_in"; }; 142 143 sc_event neg() const { return sc_event(*this, sc_event::NEG); }; 144 sc_event pos() const { return sc_event(*this, sc_event::POS); }; 145 146 // read the current value 147 inline const T & read() const INLINE; 148 inline operator const T & () const INLINE; 149 150 // operateur == 151 inline bool operator == (const T & v) INLINE; 152 153 // bind to in interface 154 void operator () (sc_signal<data_type> & s) { 155 sc_core::bind(*this, s); 156 } 157 158 // binding for hierarchical description 159 void operator () (this_type & parent_) { 160 sc_core::bind(*this, parent_); 161 } 162 163 void operator () (sc_out<data_type> & o) { 164 sc_core::bind(*this, o); 165 } 166 167 /*virtual */~sc_in() {}; 168 169 }; 170 171 172 template < typename T > 173 void sc_in< T >::init() { 174 set_kind(sc_in_string); 175 sc_interface::init(sizeof(data_type)); 176 } 177 178 179 // read 180 template < typename T > inline 181 const T & sc_in< T >::read() const { 182 #ifdef DUMP_READ 183 std::cerr << "read " << READ_SIGNAL(const T &, get_pointer()) 184 << " on signal " << name() << "\n"; 185 #endif 186 return READ_SIGNAL(const T, get_pointer()); 187 } 188 189 190 template < typename T > inline 191 sc_in< T >::operator const T & () const { 192 return sc_in< T >::read(); 193 } 194 195 196 template < typename T > inline 197 bool sc_in< T >::operator == (const T & v) { 198 return sc_in< T >::read() == v; 199 } 200 201 202 203 // ---------------------------------------------------------------------------- 204 // CLASS : sc_inout< T > 205 // 206 // ---------------------------------------------------------------------------- 207 208 template < typename T > 209 class sc_inout : public sc_port_base { 210 77 211 /////////// 78 212 // Internal 79 const sc_module &get_module () const; 80 void init (); 81 void check_multiwriting2port () const; 82 /////////// 83 84 friend std::ostream& operator << (std::ostream &, const sc_port_base &); 85 86 // LRM 87 //virtual const sc_event /*&*/ default_event () const; 88 static const char* const kind_string; 89 // virtual const char *kind () const; 90 // 91 sc_port_base(); 92 sc_port_base(const char* name_); 93 explicit sc_port_base(const sc_port_base& parent_); 94 /*virtual */~sc_port_base () {}; 95 // bind to a handle 96 void operator () (method_process_t &func) const; 213 protected: 214 void init(); 215 T val; 216 217 private: 218 typedef T data_type; 219 220 typedef sc_inout<data_type> this_type; 221 typedef sc_signal<data_type> signal_type; 222 223 224 public: 225 // contructeurs 226 sc_inout() : base_type() { init (); }; 227 228 explicit sc_inout(const char * name_) : base_type(name_) { init(); }; 229 230 /* 231 // LRM error ! 232 //static const char *const kind_string; this is a template ! 233 */ 234 235 // read the current value 236 inline const T & read() const INLINE; 237 // write the new value 238 inline void write(const T &) INLINE; 239 template < int W > inline void write(const sc_uint< W > & v) { 240 sc_inout< T >::write(v.read()); 241 } 242 243 inline operator const T & () const INLINE; 244 245 inline sc_inout< T > & operator = (const T & a) INLINE; 246 inline sc_inout< T > & operator = (const sc_signal< T > & a) INLINE; 247 248 // operateur == 249 inline bool operator == (const bool & v) INLINE; 250 251 // bind to in interface 252 void operator () (sc_signal<data_type> & s) { 253 bind(*this); 254 bind(*this, s); 255 } 256 257 void operator () (this_type & parent_) { 258 bind(*this, parent_); 259 } 260 261 /*virtual */~sc_inout() {}; 97 262 }; 98 263 99 template < typename T > class sc_port_b:public sc_port_base 100 { 101 }; 102 103 // ---------------------------------------------------------------------------- 104 // CLASS : sc_in<T> 105 // 106 // ---------------------------------------------------------------------------- 107 108 template <typename T> 109 class sc_in : public sc_port_base 110 { 111 private: 112 typedef T data_type; 113 typedef sc_port_base base_type; 114 typedef sc_in<data_type> this_type; 115 typedef sc_signal<data_type> signal_type; 116 117 /////////// 118 // Internal 119 void init (); 120 /* 121 public: virtual size_t data_size () const 122 { return sizeof (data_type); } 123 */ 124 /////////// 125 public: 126 // constructors 127 sc_in(): base_type() { init (); } 128 129 explicit sc_in(const char* name_): base_type(name_) { init (); } 130 131 explicit sc_in(const base_type& parent_ ): base_type( parent_ ) { init (); } 132 133 /* 134 // LRM error ! 135 //static const char *const kind_string; this is a template ! 136 */ 137 // virtual const char *kind () const 138 // { return "sc_in"; }; 139 140 #if 0 141 // LRM 142 sc_event_finder& neg () const { return *new sc_event_finder (*(sc_port_base*)this);}; 143 sc_event_finder& pos () const { return *new sc_event_finder (*(sc_port_base*)this);}; 144 #endif 145 146 sc_event neg () const { return sc_event (*this, sc_event::NEG);}; 147 sc_event pos () const { return sc_event (*this, sc_event::POS);}; 148 // read the current value 149 inline const T& read() const INLINE; 150 inline operator const T& () const INLINE; 151 152 // operateur == 153 inline bool operator == (const T& v) INLINE; 154 155 // bind to in interface 156 void operator () (sc_signal<data_type> &s) 157 { sc_core::bind (*this,s); } 158 159 // binding for hierarchical description 160 void operator () (this_type &parent_) 161 { sc_core::bind (*this,parent_); } 162 163 void operator () (sc_out<data_type> &o) 164 { sc_core::bind (*this,o); } 165 166 /*virtual */~sc_in() {}; 167 168 }; 169 170 template <typename T> 171 void 172 sc_in<T>::init() 173 { 174 set_kind (sc_in_string); 175 sc_interface::init (sizeof (data_type)); 176 } 177 178 // read 179 template <typename T> inline 180 const T& 181 sc_in<T>::read() const 182 { 183 #ifdef DUMP_READ 184 std::cerr << "read " << READ_SIGNAL(const T&, get_pointer()) 185 << " on signal " << name () << "\n"; 186 #endif 187 return READ_SIGNAL(const T, get_pointer()); 188 } 189 190 template <typename T> inline 191 sc_in<T>::operator const T& () const 192 { return sc_in<T>::read (); } 193 194 template <typename T> inline 195 bool sc_in<T>::operator == (const T& v) { 196 return sc_in<T>::read() == v; 197 } 198 199 // ---------------------------------------------------------------------------- 200 // CLASS : sc_inout<T> 201 // 202 // ---------------------------------------------------------------------------- 203 204 template <typename T> 205 class sc_inout : public sc_port_base 206 { 207 /////////// 208 // Internal 209 protected: 210 void init (); 211 T val; 212 private: 213 typedef T data_type; 214 215 typedef sc_inout<data_type> this_type; 216 typedef sc_signal<data_type> signal_type; 217 218 /* 219 public: virtual size_t data_size () const 220 { return sizeof (data_type); } 221 */ 222 /////////// 223 public: 224 // contructeurs 225 sc_inout(): base_type() { init (); }; 226 227 explicit sc_inout(const char* name_): base_type(name_) { init (); }; 228 229 /* 230 // LRM error ! 231 //static const char *const kind_string; this is a template ! 232 */ 233 //virtual const char *kind () const 234 //{ return "sc_inout"; }; 235 236 // read the current value 237 inline const T& read() const INLINE; 238 // write the new value 239 inline void write( const T& ) INLINE; 240 template <int W> inline void write( const sc_uint<W>& v) 241 { sc_inout<T>::write (v.read()); } 242 243 inline operator const T& () const INLINE; 244 245 inline sc_inout<T>& operator = ( const T& a ) INLINE; 246 247 inline sc_inout<T>& operator = ( const sc_signal<T>& a ) INLINE; 248 249 // inline sc_inout<T>& operator = ( const sc_port_base& a ) INLINE; 250 251 // operateur == 252 inline bool operator == (const bool& v) INLINE; 253 254 // bind to in interface 255 void operator () (sc_signal<data_type> &s) 256 { bind (*this); bind (*this,s); } 257 258 void operator () (this_type &parent_) 259 { bind (*this,parent_); } 260 261 /*virtual */~sc_inout() {}; 262 }; 263 264 template <typename T> 265 void 266 sc_inout<T>::init () 267 { 268 set_pointer ((tab_t*)(void*)&val); 269 sc_object::set_kind (sc_inout_string); 270 sc_interface::init (sizeof (data_type)); 271 /*ref*/ val = (0); 272 //sc_inout::write (0); 264 265 template < typename T > 266 void sc_inout< T >::init() { 267 set_pointer((tab_t *) (void *) &val); 268 sc_object::set_kind(sc_inout_string); 269 sc_interface::init(sizeof(data_type)); 270 /*ref*/ val = (0); 271 //sc_inout::write (0); 273 272 /* Fix : 274 273 * FSM checker generates an error at runtime … … 277 276 } 278 277 278 279 279 // read 280 template <typename T> 281 inline 282 const T& 283 sc_inout<T>::read() const 284 { 280 template < typename T > 281 inline const T & sc_inout< T >::read() const { 285 282 #ifdef DUMP_READ 286 std::cerr << "read " << READ_SIGNAL(const T, get_pointer()) // val 287 << " on signal " << name () << "\n"; 288 #endif 289 // return val; 290 return READ_SIGNAL(const T, get_pointer()); 291 } 283 std::cerr << "read " << READ_SIGNAL(const T, get_pointer()) // val 284 << " on signal " << name () << "\n"; 285 #endif 286 // return val; 287 return READ_SIGNAL(const T, get_pointer()); 288 } 289 292 290 293 291 // write the new value 294 template <typename T> 295 inline 296 void 297 sc_inout<T>::write( const T& value_ ) 298 { 292 template < typename T > 293 inline void sc_inout< T >::write(const T & value_) { 299 294 #ifdef DUMP_WRITE 300 std::cerr << "write " << value_ 301 << " on in/out port (writing into a signal) '" << name () << "'\n"; 302 #endif 303 // T& ref = *(T*)(get_pointer()); 295 std::cerr << "write " << value_ << " on in/out port (writing into a signal) '" << name() << "'\n"; 296 #endif 297 // T& ref = *(T*)(get_pointer()); 304 298 #ifndef USE_PORT_DEPENDENCY 305 unstable |= (value_) != val; //ref; 306 #endif 307 /*ref*/ val = (value_); 308 } 309 310 template <typename T> 311 inline 312 sc_inout<T>::operator const T& () const 313 { return sc_inout<T>::read(); } 314 315 template <typename T> 316 inline sc_inout<T>& sc_inout<T>::operator = ( const T& a ) 317 { sc_inout<T>::write( a ); return *this; } 318 319 template <typename T> 320 inline 321 sc_inout<T>& sc_inout<T>::operator = ( const sc_signal<T>& a ) 322 { sc_inout<T>::write( a.read() ); return *this; } 299 unstable |= (value_) != val; //ref; 300 #endif 301 /*ref*/ val = (value_); 302 } 303 304 305 template < typename T > 306 inline sc_inout< T >::operator const T & () const { 307 return sc_inout< T >::read(); 308 } 309 310 311 template < typename T > 312 inline sc_inout< T > & sc_inout< T >::operator = (const T & a) { 313 sc_inout< T >::write(a); 314 return *this; 315 } 316 317 318 template < typename T > 319 inline sc_inout< T > & sc_inout< T >::operator = (const sc_signal< T > & a) { 320 sc_inout< T >::write(a.read()); 321 return *this; 322 } 323 324 323 325 /* 324 template <typename T> 325 inline 326 sc_inout<T>& sc_inout<T>::operator = ( const sc_port_base& a ) 327 { write( a.read() ); return *this; } 328 */ 329 template <typename T> 330 inline 331 bool sc_inout<T>::operator == (const bool& v) 332 { return sc_inout<T>::read() == v; } 326 template <typename T> 327 inline 328 sc_inout<T>& sc_inout<T>::operator = ( const sc_port_base& a ) 329 { write( a.read() ); return *this; } 330 */ 331 332 333 template < typename T > inline 334 bool sc_inout< T >::operator == (const bool & v) { 335 return sc_inout< T >::read() == v; 336 } 337 333 338 334 339 // ---------------------------------------------------------------------------- … … 340 345 // For debugging reasons, a class is provided instead of a define." 341 346 342 template <typename T> 343 class sc_out : public sc_inout<T> 344 { 345 /////////// 346 // Internal 347 void init (); 348 /////////// 349 public: 350 // typedefs 351 typedef T data_type; 352 typedef sc_inout<T> base_type; 353 typedef sc_out<data_type> this_type; 354 typedef sc_signal<data_type> signal_type; 355 public: 356 // constructors & destructor 357 sc_out(): base_type() { init (); }; 358 explicit sc_out(const char* name_): base_type(name_) { init (); }; 359 sc_out (this_type & parent_); 360 sc_out (const char *name_, this_type & parent_); 361 362 /* 363 // LRM error ! 364 //static const char *const kind_string; this is a template ! 365 */ 366 //virtual const char *kind () const 367 //{ return "sc_out"; }; 368 369 370 inline this_type& operator = ( const data_type& a ) INLINE; 371 inline bool operator == (const bool& v) INLINE; 372 373 // bind to in interface 374 void operator () (sc_signal<data_type> &s) 375 { bind (*this,s); } 347 template < typename T > 348 class sc_out : public sc_inout< T > { 349 350 /////////// 351 // Internal 352 void init(); 353 /////////// 376 354 377 void operator () (this_type &parent_) 378 { bind (*this,parent_); } 379 380 ////////////////////// 381 // Systemcass specific 382 void operator () (sc_port_base &o) 383 { set_port_dependency (&o, (sc_port_base&)(*this)); } 384 /* 385 void operator () () // n'a pas de sens... 386 { set_port_dependency (NULL, (sc_port_base&)(*this)); } 387 */ 388 ////////////////////// 389 390 391 /*virtual */~ sc_out () {}; 392 393 private: 394 // disabled 395 sc_out (const this_type &); 355 public: 356 typedef T data_type; 357 typedef sc_inout< T > base_type; 358 typedef sc_out<data_type> this_type; 359 typedef sc_signal<data_type> signal_type; 360 361 362 // constructors & destructor 363 sc_out() : base_type() { 364 init(); 365 } 366 367 explicit sc_out(const char * name_) : base_type(name_) { 368 init(); 369 } 370 371 sc_out(this_type & parent_); 372 sc_out(const char * name_, this_type & parent_); 373 374 /* 375 // LRM error ! 376 //static const char *const kind_string; this is a template ! 377 */ 378 //virtual const char *kind () const 379 //{ return "sc_out"; }; 380 381 382 inline this_type & operator = (const data_type & a) INLINE; 383 inline bool operator == (const bool & v) INLINE; 384 385 // bind to in interface 386 void operator () (sc_signal<data_type> & s) { 387 bind(*this, s); 388 } 389 390 void operator () (this_type & parent_) { 391 bind(*this, parent_); 392 } 393 394 ////////////////////// 395 // Systemcass specific 396 void operator () (sc_port_base & o) { 397 set_port_dependency(&o, (sc_port_base &) (*this)); 398 } 399 ////////////////////// 400 401 402 /*virtual */~sc_out() {}; 403 404 private: 405 // disabled 406 sc_out(const this_type &); 407 396 408 }; 397 409 398 // 399 template<typename T> 400 void 401 sc_out<T>::init () 402 { 403 sc_inout<T>::init (); 404 // tab_t *t = &(sc_inout<T>::val); 405 // sc_interface::set_pointer (t); 406 sc_object::set_kind (sc_out_string); 407 // sc_interface::init (sizeof (data_type)); 408 // /*ref*/ sc_inout<T>::val = 0; 409 //sc_inout<T>::write (0); 410 411 412 template< typename T > 413 void sc_out< T >::init() { 414 sc_inout< T >::init(); 415 // tab_t *t = &(sc_inout<T>::val); 416 // sc_interface::set_pointer (t); 417 sc_object::set_kind(sc_out_string); 418 // sc_interface::init (sizeof (data_type)); 419 // /*ref*/ sc_inout<T>::val = 0; 420 //sc_inout<T>::write (0); 410 421 /* Fix : 411 422 * FSM checker generates an error at runtime … … 413 424 } 414 425 415 template<typename T> inline 416 sc_out<T>& 417 sc_out<T>::operator = ( const data_type& a ) 418 { sc_out<T>::write( a ); return *this; } 419 420 template<typename T> inline 421 bool 422 sc_out<T>::operator == (const bool& v) 423 { return sc_out<T>::read() == v; } 426 427 template< typename T > 428 inline sc_out< T > & sc_out< T >::operator = (const data_type & a) { 429 sc_out< T >::write(a); 430 return *this; 431 } 432 433 434 template< typename T > 435 inline bool sc_out< T >::operator == (const bool & v) { 436 return sc_out< T >::read() == v; 437 } 438 424 439 425 440 // Dumps 426 template<typename T> inline 427 std::ostream& operator<<( std::ostream& os, const sc_in<T> &r) 428 { return os << r.read (); } 441 template< typename T > 442 inline std::ostream & operator << ( std::ostream & os, const sc_in< T > & r) { 443 return os << r.read(); 444 } 445 429 446 430 447 // Add '&' 431 template<class T> inline 432 std::ostream& operator<<( std::ostream& os, const sc_inout<T> &r) 433 { return os << r.read (); } 434 435 template<class T> inline 436 std::ostream& operator<<( std::ostream& os, const sc_signal<T> &r) 437 { return os << r.read (); } 448 template< class T > 449 inline std::ostream & operator << ( std::ostream & os, const sc_inout< T > & r) { 450 return os << r.read(); 451 } 452 453 454 template< class T > 455 inline std::ostream & operator << ( std::ostream & os, const sc_signal< T > & r) { 456 return os << r.read(); 457 } 458 438 459 439 460 // Declarations … … 449 470 450 471 #endif /* __SC_PORT_EXT_H__ */ 472 473 /* 474 # Local Variables: 475 # tab-width: 4; 476 # c-basic-offset: 4; 477 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 478 # indent-tabs-mode: nil; 479 # End: 480 # 481 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 482 */ 483 -
sources/src/sc_sensitive.cc
r27 r52 41 41 #include "sc_module.h" 42 42 #include "internal.h" 43 43 44 #ifdef HAVE_CONFIG_H 44 45 #include "config.h" … … 48 49 49 50 namespace sc_core { 50 void assert_before_init () 51 { 52 if (sc_core::already_initialized == true) 53 exit (14); 54 } 55 static 56 void add_sensitivity (const sc_event &s) 57 { 58 if (method == NULL) { 59 cerr << "declare a process before declaring " << s << " event\n"; 60 exit (1); 61 } 62 method->sensitivity_list.push_back(s); 63 } 51 52 53 void assert_before_init() { 54 if (sc_core::already_initialized) { 55 exit(14); 56 } 64 57 } 65 58 66 // 59 60 static void add_sensitivity(const sc_event & s) { 61 if (method == NULL) { 62 cerr << "declare a process before declaring " << s << " event\n"; 63 exit(1); 64 } 65 method->sensitivity_list.push_back(s); 66 } 67 68 } 69 70 67 71 using namespace sc_core; 68 72 … … 73 77 // ---------------------------------------------------------------------------- 74 78 75 sc_sensitive& sc_sensitive::operator << (const sc_port_base& port) 76 { 77 sc_event s (port,sc_event::VAL); 78 sc_core::add_sensitivity (s); 79 return *this; 79 sc_sensitive & sc_sensitive::operator << (const sc_port_base & port) { 80 sc_event s(port, sc_event::VAL); 81 sc_core::add_sensitivity(s); 82 return *this; 80 83 } 81 84 82 sc_sensitive& sc_sensitive::operator () (const sc_port_base& port) 83 {84 return *this << port;85 86 sc_sensitive & sc_sensitive::operator () (const sc_port_base & port) { 87 return *this << port; 85 88 } 86 89 87 sc_sensitive& sc_sensitive::operator << (const sc_event &e) 88 {89 sc_core::add_sensitivity(e);90 return *this;90 91 sc_sensitive & sc_sensitive::operator << (const sc_event & e) { 92 sc_core::add_sensitivity(e); 93 return *this; 91 94 } 92 95 93 sc_sensitive& sc_sensitive::operator () (const sc_event& e) 94 {95 return *this << e;96 97 sc_sensitive & sc_sensitive::operator () (const sc_event & e) { 98 return *this << e; 96 99 } 97 100 98 sc_sensitive& sc_sensitive::operator << (sc_event_finder& e) 99 {100 return *this << e.port();101 102 sc_sensitive & sc_sensitive::operator << (sc_event_finder & e) { 103 return *this << e.port(); 101 104 } 102 105 103 sc_sensitive& sc_sensitive::operator () (sc_event_finder& e) 104 {105 return *this << e;106 107 sc_sensitive & sc_sensitive::operator () (sc_event_finder & e) { 108 return *this << e; 106 109 } 107 110 108 sc_sensitive& sc_sensitive::operator << (const sc_interface &e) 109 {110 return *this << e.default_event();111 112 sc_sensitive & sc_sensitive::operator << (const sc_interface & e) { 113 return *this << e.default_event(); 111 114 } 112 115 113 sc_sensitive& sc_sensitive::operator () (const sc_interface &e) 114 {115 return *this << e;116 117 sc_sensitive & sc_sensitive::operator () (const sc_interface & e) { 118 return *this << e; 116 119 } 120 117 121 118 122 … … 124 128 // ---------------------------------------------------------------------------- 125 129 126 sc_sensitive_pos& sc_sensitive_pos::operator << (const sc_port_base& port) 127 {128 sc_event s (port,sc_event::POS);129 sc_core::add_sensitivity(s);130 return *this;130 131 sc_sensitive_pos & sc_sensitive_pos::operator << (const sc_port_base & port) { 132 sc_event s(port, sc_event::POS); 133 sc_core::add_sensitivity(s); 134 return *this; 131 135 } 132 136 133 sc_sensitive_pos& sc_sensitive_pos::operator () (const sc_port_base& port) 134 {135 return *this << port;137 138 sc_sensitive_pos& sc_sensitive_pos::operator () (const sc_port_base & port) { 139 return *this << port; 136 140 } 137 141 138 /*139 sc_sensitive_pos& sc_sensitive_pos::operator << (const sc_interface &e)140 {141 sc_event s (e, sc_event::POS);142 sc_core::add_sensitivity (s);143 return *this;144 };145 142 146 sc_sensitive_pos& sc_sensitive_pos::operator () (const sc_interface &e)147 {148 return *this << e;149 };150 */151 143 152 144 // ---------------------------------------------------------------------------- … … 156 148 // ---------------------------------------------------------------------------- 157 149 158 sc_sensitive_neg& sc_sensitive_neg::operator << (const sc_port_base& port) 159 { 160 sc_event s (port,sc_event::NEG); 161 sc_core::add_sensitivity (s); 162 return *this; 150 sc_sensitive_neg & sc_sensitive_neg::operator << (const sc_port_base & port) { 151 sc_event s(port, sc_event::NEG); 152 sc_core::add_sensitivity(s); 153 return *this; 163 154 } 164 155 165 sc_sensitive_neg& sc_sensitive_neg::operator () (const sc_port_base& port) 166 {167 return *this << port;156 157 sc_sensitive_neg & sc_sensitive_neg::operator () (const sc_port_base & port) { 158 return *this << port; 168 159 } 169 160 170 161 171 162 163 /* 164 # Local Variables: 165 # tab-width: 4; 166 # c-basic-offset: 4; 167 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 168 # indent-tabs-mode: nil; 169 # End: 170 # 171 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 172 */ 173 -
sources/src/sc_sensitive.h
r27 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __SC_SENSITIVE_H__ 13 14 #define __SC_SENSITIVE_H__ 14 15 15 16 #include <list> 17 16 18 #include "sc_fwd.h" 17 19 //#include "sc_event.h" … … 21 23 namespace sc_core { 22 24 23 // ----------------------------------------------------------------------------24 // CLASS : sensitivity_t25 //26 // Static events.27 // ----------------------------------------------------------------------------28 29 /*30 struct sensitivity_t {31 sc_port_base *port;32 typedef enum { POS, NEG, VAL } flag_t;33 public:34 flag_t flag;35 bool pos () const ;36 sensitivity_t (sc_port_base &port_, flag_t flag_);37 friend std::ostream& operator << (std::ostream &, const sensitivity_t &);38 private:39 // disabled40 sensitivity_t ();41 };42 */43 25 44 26 // ---------------------------------------------------------------------------- … … 48 30 // ---------------------------------------------------------------------------- 49 31 50 class sc_sensitive // from SystemC v201 LRM 51 { 52 public: 53 // constructor, destructor 54 explicit sc_sensitive (sc_module *) {}; 55 ~sc_sensitive () {}; 56 public: 57 // specify static sensitivity for processes 58 sc_sensitive & operator () (const sc_event &); 59 sc_sensitive & operator () (const sc_interface &); 60 sc_sensitive & operator () (const sc_port_base &); 61 sc_sensitive & operator () (sc_event_finder &); 62 sc_sensitive & operator << (const sc_event &); 63 sc_sensitive & operator << (const sc_interface &); 64 sc_sensitive & operator << (const sc_port_base &); 65 sc_sensitive & operator << (sc_event_finder &); 66 private: 67 // disabled 68 sc_sensitive (); 69 sc_sensitive (const sc_sensitive &); 32 class sc_sensitive { 33 // from SystemC v201 LRM 34 35 public: 36 // constructor, destructor 37 explicit sc_sensitive (sc_module *) {}; 38 ~sc_sensitive() {}; 39 40 public: 41 // specify static sensitivity for processes 42 sc_sensitive & operator () (const sc_event &); 43 sc_sensitive & operator () (const sc_interface &); 44 sc_sensitive & operator () (const sc_port_base &); 45 sc_sensitive & operator () (sc_event_finder &); 46 sc_sensitive & operator << (const sc_event &); 47 sc_sensitive & operator << (const sc_interface &); 48 sc_sensitive & operator << (const sc_port_base &); 49 sc_sensitive & operator << (sc_event_finder &); 50 51 private: 52 // disabled 53 sc_sensitive (); 54 sc_sensitive (const sc_sensitive &); 70 55 sc_sensitive & operator = (const sc_sensitive &); 71 56 }; … … 77 62 // ---------------------------------------------------------------------------- 78 63 79 class sc_sensitive_pos /* deprecated */ 80 { 81 public: 82 83 sc_sensitive_pos& operator << (const sc_port_base&); 84 sc_sensitive_pos& operator () (const sc_port_base&); 85 sc_sensitive_pos& operator << (const sc_interface &); 86 sc_sensitive_pos& operator () (const sc_interface &); 64 class sc_sensitive_pos { /* deprecated */ 65 66 public: 67 sc_sensitive_pos & operator << (const sc_port_base &); 68 sc_sensitive_pos & operator () (const sc_port_base &); 69 sc_sensitive_pos & operator << (const sc_interface &); 70 sc_sensitive_pos & operator () (const sc_interface &); 87 71 }; 88 72 … … 93 77 // ---------------------------------------------------------------------------- 94 78 95 class sc_sensitive_neg /* deprecated */ 96 { 97 public: 98 99 sc_sensitive_neg& operator << (const sc_port_base&); 100 sc_sensitive_neg& operator () (const sc_port_base&); 101 sc_sensitive_neg& operator << (const sc_interface &); 102 sc_sensitive_neg& operator () (const sc_interface &); 79 class sc_sensitive_neg { /* deprecated */ 80 81 public: 82 sc_sensitive_neg & operator << (const sc_port_base &); 83 sc_sensitive_neg & operator () (const sc_port_base &); 84 sc_sensitive_neg & operator << (const sc_interface &); 85 sc_sensitive_neg & operator () (const sc_interface &); 103 86 }; 87 104 88 105 89 } // end of namespace sc_core 106 90 107 91 #endif /* __SC_SENSITIVE_H__ */ 92 93 /* 94 # Local Variables: 95 # tab-width: 4; 96 # c-basic-offset: 4; 97 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 98 # indent-tabs-mode: nil; 99 # End: 100 # 101 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 102 */ 103 -
sources/src/sc_signal.h
r47 r52 11 11 | | 12 12 \------------------------------------------------------------*/ 13 13 14 #ifndef __SC_SIGNAL_H__ 14 15 #define __SC_SIGNAL_H__ … … 17 18 #include <iostream> 18 19 #include <cstdlib> 20 19 21 #include "sc_fwd.h" 20 22 #include "sc_nbdefs.h" 21 //#include "sc_event_finder.h"22 //#include "sc_event.h"23 23 #include "sc_time.h" // SC_ZERO_TIME 24 24 #include "sc_object.h" … … 30 30 // 31 31 #if ((__GNUC__ < 3) || (__GNUC_MINOR__ < 4)) 32 #define INLINE __attribute__((always_inline))32 #define INLINE __attribute__((always_inline)) 33 33 #else 34 /* gcc3.4 doesn't support */ 35 #define INLINE 36 #endif 34 /* gcc3.4 doesn't support */ 35 #define INLINE 36 #endif 37 37 38 38 39 #define READ_SIGNAL(value_type_,pointer_) \ 39 ((value_type_&) (*((value_type_*) (pointer_))))40 41 40 ((value_type_ &) (*((value_type_ *) (pointer_)))) 41 42 ///////////////////// DEPRECATED 42 43 // C ANSI-only since it is needed to link with extern "C" 43 44 44 extern void bind (sc_port_base&,sc_port_base&); 45 extern void bind (sc_port_base&,sc_signal_base&); 46 extern void bind (sc_signal_base &x); 47 extern void bind (sc_port_base &x); 45 extern void bind(sc_port_base &, sc_port_base &); 46 extern void bind(sc_port_base &, sc_signal_base &); 47 extern void bind(sc_signal_base & x); 48 extern void bind(sc_port_base & x); 49 48 50 typedef tab_t base_type; 51 49 52 struct pending_write_t { 50 base_type *pointer; 51 base_type value; 52 //pending_write_t (base_type *const pointer_, const base_type value_) 53 //{ pointer = pointer_; value = value_; } 54 friend std::ostream& operator << (std::ostream &o, const pending_write_t &p) 55 { return o << "(pointer = " << p.pointer << "; value = " << p.value << ")\n"; } 53 base_type * pointer; 54 base_type value; 55 //pending_write_t(base_type * const pointer_, const base_type value_) { 56 // pointer = pointer_; 57 // value = value_; 58 //} 59 60 friend std::ostream & operator << (std::ostream & o, const pending_write_t & p) { 61 return o << "(pointer = " << p.pointer << "; value = " << p.value << ")\n"; 62 } 56 63 }; 57 64 65 58 66 // Check pending_writing to register 59 extern void pending_writing2register_clear 60 extern void pending_writing2register_record_and_check 67 extern void pending_writing2register_clear(); 68 extern void pending_writing2register_record_and_check(const tab_t *); 61 69 62 70 // Pending write to register (simple stack) 63 typedef pending_write_t * pending_write_vector_t;71 typedef pending_write_t * pending_write_vector_t; 64 72 extern pending_write_vector_t pending_write_vector; 65 73 extern "C" unsigned int pending_write_vector_nb; … … 67 75 68 76 69 template <typename T> 70 inline void post_write (base_type *const pointer_, 71 const T value_) /*INLINE*/; 72 template <typename T> 73 inline void post_multiwrite (base_type *const pointer_, 74 const T value_) 75 { 76 size_t size = (sizeof (T)-1) / sizeof (base_type); 77 size_t i = 0; 78 const base_type *pvalue = (const base_type*)(void*)(&value_); 79 do { 77 template < typename T > 78 inline void post_write(base_type * const pointer_, const T value_) /*INLINE*/; 79 80 template < typename T > 81 inline void post_multiwrite(base_type * const pointer_, const T value_) { 82 size_t size = (sizeof(T) - 1) / sizeof(base_type); 83 size_t i = 0; 84 const base_type * pvalue = (const base_type *) (void *) (& value_); 85 do { 86 post_write(pointer_ + i, pvalue[i]); 87 } while (i++ < size); 88 } 89 90 template < typename T > 91 inline void post_write(base_type * const pointer_, const T value_) { 92 if (sizeof(T) > sizeof(base_type)) { 93 post_multiwrite(pointer_,value_); 94 } 95 else { 96 #if defined(CONFIG_DEBUG) 97 if (pending_write_vector_nb >= pending_write_vector_capacity) { 98 std::cerr << "Error : The array for posted writing on register is too small.\n"; 99 std::cerr << "Up to 1 writing per register is allowed during a cycle.\n"; 100 std::cerr << "Please check the hardware description.\n"; 101 exit(-1); 102 } 103 #endif 104 pending_write_vector[pending_write_vector_nb].pointer = pointer_; 105 // pending_write_vector[pending_write_vector_nb++].value = *(reinterpret_cast<const base_type*const>(&value_)); => bug ! 106 pending_write_vector[pending_write_vector_nb++].value = value_; // => bug avec blues ! 107 108 // -> fix to use user-defined struct in sc_signal/sc_in/sc_out/sc_inout 109 // pending_write_vector[pending_write_vector_nb++].value = *((base_type*)&value_); => bug ! 80 110 #if 0 81 cout << "post_multiwrite 0x" << hex << pvalue[i] << " @" << (pointer_ + i) << "\n"; 82 #endif 83 post_write (pointer_ + i, pvalue[i]); 84 } while (i++ < size); 85 } 86 template <typename T> 87 inline void post_write (base_type *const pointer_, 88 const T value_) 89 { 90 if (sizeof (T) > sizeof (base_type)) { 91 #if 0 92 std::cout << "sizeof (T) = " << sizeof (T) 93 << " (base_type = " << sizeof (base_type) << "\n"; 94 #endif 95 post_multiwrite (pointer_,value_); 96 } else { 97 #if defined(CONFIG_DEBUG) 98 if (pending_write_vector_nb >= pending_write_vector_capacity) { 99 //if (pending_write_vector_nb >= pending_write_vector_capacity * sizeof(pending_write_t)) { 100 std::cerr << "Error : The array for posted writing on register is too small.\n"; 101 std::cerr << "Up to 1 writing per register is allowed during a cycle.\n"; 102 std::cerr << "Please check the hardware description.\n"; 103 exit (-1); 104 } 105 #endif // CONFIG_DEBUG 106 pending_write_vector[pending_write_vector_nb].pointer = pointer_; 107 // pending_write_vector[pending_write_vector_nb++].value = *(reinterpret_cast<const base_type*const>(&value_)); => bug ! 108 pending_write_vector[pending_write_vector_nb++].value = value_; // => bug avec blues ! 109 110 // -> fix to use user-defined struct in sc_signal/sc_in/sc_out/sc_inout 111 // pending_write_vector[pending_write_vector_nb++].value = *((base_type*)&value_); => bug ! 112 #if 0 113 std::cerr << "posted write : ptr = " << pointer_ << ", val = " << value_ << "\n"; 111 std::cerr << "posted write : ptr = " << pointer_ << ", val = " << value_ << "\n"; 114 112 #endif 115 113 #if 0 116 // introduce bug on using trace functions 117 if (value_ == READ_SIGNAL(T,pointer_)) 118 return; 119 #endif 120 }; 121 } 122 123 inline bool is_posted_write () 124 { 125 return pending_write_vector_nb > 0; 126 } 127 128 extern "C" void update (void); 114 // introduce bug on using trace functions 115 if (value_ == READ_SIGNAL(T,pointer_)) { 116 return; 117 } 118 #endif 119 } 120 } 121 122 123 inline bool is_posted_write() { 124 return pending_write_vector_nb > 0; 125 } 126 127 128 extern "C" void update(void); 129 129 130 130 131 // ---------------------------------------------------------------------------- … … 134 135 // ---------------------------------------------------------------------------- 135 136 136 class sc_signal_base : public sc_object, public sc_interface 137 { 138 ////// 139 // Internal 140 friend class sc_clock; 141 friend class sc_port_base; 142 void init (); 143 ////// 144 145 146 public: 147 // LRM (?) 148 //virtual const sc_event /*&*/ default_event () const; 149 static const char* const kind_string; 150 //virtual const char *kind () const; 151 152 // 153 public: 154 sc_signal_base(); 155 sc_signal_base(const char* name_); 156 sc_signal_base(const char* name_, void*); 157 ~sc_signal_base(); 137 class sc_signal_base : public sc_object, public sc_interface { 138 139 ////// 140 // Internal 141 friend class sc_clock; 142 friend class sc_port_base; 143 void init(); 144 ////// 145 146 147 public: 148 // LRM (?) 149 //virtual const sc_event /*&*/ default_event() const; 150 static const char * const kind_string; 151 //virtual const char * kind() const; 152 153 154 155 public: 156 sc_signal_base(); 157 sc_signal_base(const char * name_); 158 sc_signal_base(const char * name_, void *); 159 ~sc_signal_base(); 160 158 161 }; 159 162 160 template <typename T> 161 class sc_signal : public sc_signal_base 162 { 163 private: 164 T val; 165 typedef T data_type; 166 typedef sc_signal < T > this_type; 167 168 /////////// 169 // Internal 170 public: void init (); 171 /////////// 172 173 // virtual void update (); 174 void check_writer (); 175 public: 176 // constructors, destructor 177 sc_signal () 178 { init (); } 179 explicit sc_signal (const char *name_): sc_signal_base(name_) 180 { init (); } 181 /*virtual */~ sc_signal () 182 {} 183 // methods 184 /* 185 virtual void register_port (sc_port_base &, const char *) 186 {} 187 virtual const sc_event & default_event () const 188 {} 189 virtual const sc_event & value_changed_event () const 190 {} 191 */ 192 /*virtual*/ inline const data_type & read () const INLINE; 163 164 template < typename T > 165 class sc_signal : public sc_signal_base { 166 167 private: 168 T val; 169 typedef T data_type; 170 typedef sc_signal < T > this_type; 171 172 173 /////////// 174 // Internal 175 public: 176 void init(); 177 /////////// 178 179 void check_writer(); 180 181 public: 182 // constructors, destructor 183 sc_signal() { 184 init(); 185 } 186 187 explicit sc_signal(const char * name_) : sc_signal_base(name_) { 188 init(); 189 } 190 191 /*virtual*/ ~sc_signal() {} 192 /*virtual*/ inline const data_type & read() const INLINE; 193 /*virtual*/ inline void write(const data_type &) /*INLINE*/; 194 195 inline operator const data_type & () const { return this->read(); } 196 197 inline this_type & operator = (const data_type & a) { 198 sc_signal< T >::write(a); 199 return *this; 200 } 201 202 inline this_type & operator = (const sc_signal < T > & a) { 203 sc_signal< T >::write(a.read()); 204 return *this; 205 } 206 207 inline this_type & operator += (const data_type & a) { 208 sc_signal< T >::write(read() + a); 209 return *this; 210 } 211 212 inline this_type & operator += (const sc_signal < T > & a) { 213 sc_signal< T >::write(read() + a.read()); 214 return *this; 215 } 216 217 const data_type & get_new_value() const; 218 219 // void trace (sc_trace_file * tf) const; 220 /* 221 virtual void print(std::ostream & o) const { o << *this; } 222 virtual void dump(std::ostream & o) const { o << *this; } 223 */ 224 225 private: 226 // disabled 227 sc_signal(const sc_signal < T > &); 228 229 }; 230 231 232 template < typename T > 233 void sc_signal< T >::init() { 234 set_pointer((tab_t *) (void *) &val); 235 set_kind(kind_string); 236 sc_interface::init(sizeof(data_type)); 237 val = 0; /* The simulator initializes the signal/register to 0. */ 238 /* However, hardware initialization still has to be done. */ 239 /* This kind of initialization is for trace diffing. */ 240 } 241 242 243 // read the value 244 template < typename T > 245 /*virtual*/ inline const T & sc_signal< T >::read() const { 246 #ifdef DUMP_READ 247 std::cerr << "read " << READ_SIGNAL(const T, get_pointer()) << " on signal " << name() << "\n"; 248 #endif 249 return READ_SIGNAL(const T, get_pointer()); 250 } 251 252 253 // write the new value 254 template < typename T > 255 inline void sc_signal< T >::write(const data_type & value_) { 256 #ifdef CONFIG_DEBUG 257 if (get_pointer() == NULL) { 258 std::cerr << "Error : Unable to write into '" << name() << "'."; 259 exit(24032005); 260 } 261 #endif 262 #ifdef DUMP_WRITE 263 if (sc_signal< T >::read() == value_) { 264 return; 265 } 266 std::cerr << "write (posted) " << value_ << " on sc_signal (writing into register) '" << name() << "'\n"; 267 #endif 268 post_write(/*(tab_t*)&val*/ get_pointer(), value_); 269 } 270 271 #undef INLINE 272 #undef READ_SIGNAL 273 274 275 } // end of namespace sc_core 276 277 #endif /* __SC_SIGNAL_H__ */ 278 193 279 /* 194 virtual const T & get_data_ref () const 195 {} 196 virtual bool event () const 197 {} 198 */ 199 /*virtual*/ inline void write (const data_type &) /*INLINE*/; 200 inline operator const data_type & () const 201 { return this->read(); } 202 inline this_type& operator = (const data_type & a) 203 { sc_signal<T>::write (a); return *this; } 204 inline this_type& operator = (const sc_signal < T > &a) 205 { sc_signal<T>::write (a.read()); return *this; } 206 inline this_type& operator += (const data_type & a) 207 { sc_signal<T>::write (read() + a); return *this; } 208 inline this_type& operator += (const sc_signal < T > &a) 209 { sc_signal<T>::write (read()+a.read()); return *this; } 210 const data_type & get_new_value () const; 211 // void trace (sc_trace_file * tf) const; 212 /* 213 virtual void print (std::ostream &o) const 214 { o << *this; } 215 virtual void dump (std::ostream &o) const 216 { o << *this; } 217 */ 218 private: 219 // disabled 220 sc_signal (const sc_signal < T > &); 221 222 }; 223 224 template <typename T> 225 void 226 sc_signal<T>::init() 227 { 228 set_pointer ((tab_t*)(void*)&val); 229 set_kind (kind_string); 230 sc_interface::init (sizeof (data_type)); 231 val = 0; /* The simulator initializes the signal/register to 0. */ 232 /* However, hardware initialization still has to be done. */ 233 /* This kind of initialization is for trace diffing. */ 234 } 235 // read the value 236 template <typename T> 237 /*virtual*/ 238 inline 239 const T & 240 sc_signal<T>::read() const 241 { 242 #ifdef DUMP_READ 243 std::cerr << "read " << READ_SIGNAL(const T, get_pointer()) 244 << " on signal " << name () << "\n"; 245 #endif 246 return READ_SIGNAL(const T, get_pointer()); 247 } 248 249 // write the new value 250 template <typename T> 251 inline 252 void 253 sc_signal<T>::write( const data_type& value_ ) 254 { 255 #ifdef CONFIG_DEBUG 256 if (get_pointer() == NULL) 257 { 258 std::cerr << "Error : Unable to write into '" << name () << "'."; 259 exit (24032005); 260 } 261 #endif 262 #ifdef DUMP_WRITE 263 if (sc_signal<T>::read() == value_) 264 return; 265 std::cerr << "write (posted) " << value_ 266 << " on sc_signal (writing into register) '" << name () << "'\n"; 267 #endif 268 post_write (/*(tab_t*)&val*/ get_pointer(), value_); 269 } 270 271 #undef INLINE 272 273 #undef READ_SIGNAL 274 275 } // end of namespace sc_core 276 277 #endif /* __SC_SIGNAL_H__ */ 278 280 # Local Variables: 281 # tab-width: 4; 282 # c-basic-offset: 4; 283 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 284 # indent-tabs-mode: nil; 285 # End: 286 # 287 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 288 */ 289 -
sources/src/sc_signed.h
r1 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __SC_SIGNED_H__ 13 14 #define __SC_SIGNED_H__ … … 23 24 24 25 #endif /* __SC_SIGNED_H__ */ 26 27 /* 28 # Local Variables: 29 # tab-width: 4; 30 # c-basic-offset: 4; 31 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 32 # indent-tabs-mode: nil; 33 # End: 34 # 35 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 36 */ 37 -
sources/src/sc_string.h
r1 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __SC_STRING_H__ 13 14 #define __SC_STRING_H__ … … 19 20 #endif 20 21 22 /* 23 # Local Variables: 24 # tab-width: 4; 25 # c-basic-offset: 4; 26 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 27 # indent-tabs-mode: nil; 28 # End: 29 # 30 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 31 */ 32 -
sources/src/sc_time.cc
r27 r52 35 35 36 36 37 #include "sc_time.h"38 37 #include <ctime> 39 38 #include <sys/time.h> 40 39 #include <string> 41 40 #include <sstream> 41 42 #include "sc_time.h" 43 42 44 #ifdef HAVE_CONFIG_H 43 45 #include "config.h" 44 46 #endif 45 47 48 46 49 namespace sc_core { 47 50 48 static const char *const unit_repr_string[6] = 49 {51 52 static const char *const unit_repr_string[6] = { 50 53 "FS", "PS", "NS", "US", "MS", "SEC" 51 54 }; … … 53 56 uint64_t nb_cycles = 0; 54 57 55 const sc_time SC_ZERO_TIME(0, SC_NS);56 sc_time SC_CURRENT_TIME(0, SC_NS);58 const sc_time SC_ZERO_TIME(0, SC_NS); 59 sc_time SC_CURRENT_TIME(0, SC_NS); 57 60 58 sc_time::sc_time (const sc_time &t)59 {60 *this = t;61 }62 61 63 sc_time::sc_time (double val, sc_time_unit tu) 64 { 65 time = (uint64_t) val; 66 unit = tu; 62 sc_time::sc_time (const sc_time & t) { 63 *this = t; 67 64 } 68 65 69 66 70 sc_time& 71 sc_time::operator = (const sc_time &t) 72 { 73 time = t.time; 74 unit = t.unit; 75 return *this; 67 sc_time::sc_time (double val, sc_time_unit tu) { 68 time = (uint64_t) val; 69 unit = tu; 76 70 } 77 71 78 72 79 const std::string 80 sc_time::to_string () const 81 { 82 std::ostringstream o; 83 o << time << ' ' << unit_repr_string[unit]; 84 return o.str(); 73 sc_time & sc_time::operator = (const sc_time & t) { 74 time = t.time; 75 unit = t.unit; 76 return *this; 85 77 } 78 79 80 const std::string sc_time::to_string() const { 81 std::ostringstream o; 82 o << time << ' ' << unit_repr_string[unit]; 83 return o.str(); 84 } 85 86 86 87 87 } // end of sc_core namespace 88 88 89 /* 90 # Local Variables: 91 # tab-width: 4; 92 # c-basic-offset: 4; 93 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 94 # indent-tabs-mode: nil; 95 # End: 96 # 97 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 98 */ 99 -
sources/src/sc_time.h
r4 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __SC_TIME_H__ 13 14 #define __SC_TIME_H__ … … 18 19 namespace sc_core { 19 20 21 20 22 // ---------------------------------------------------------------------------- 21 23 // ENUM : sc_time_unit … … 24 26 // ---------------------------------------------------------------------------- 25 27 26 enum sc_time_unit 27 { 28 enum sc_time_unit { 28 29 SC_FS = 0, 29 30 SC_PS, … … 34 35 }; 35 36 36 // 37 37 38 class sc_time; 38 39 extern const sc_time SC_ZERO_TIME; … … 41 42 extern uint64_t nb_cycles; 42 43 43 inline double sc_simulation_time() // in default time units44 { 45 return (double)nb_cycles;44 inline double sc_simulation_time() { 45 // in default time units 46 return (double) nb_cycles; 46 47 } 47 48 48 const sc_time& sc_time_stamp ();49 49 50 // 51 class sc_time 52 { 53 friend const sc_time &sc_time_stamp (); 54 uint64_t time; 55 enum sc_time_unit unit; 56 public: 57 sc_time (double val, sc_time_unit tu); 58 sc_time (const sc_time& = SC_ZERO_TIME); 59 60 sc_time& operator= (const sc_time &); 61 62 uint64_t value () const { return time;} 63 inline double to_double () const; 64 inline double to_seconds() const; 65 inline operator double () const { return to_double ();} 66 const std::string to_string () const; 50 const sc_time & sc_time_stamp(); 51 52 53 54 class sc_time { 55 56 friend const sc_time & sc_time_stamp(); 57 uint64_t time; 58 enum sc_time_unit unit; 59 60 public: 61 sc_time(double val, sc_time_unit tu); 62 sc_time(const sc_time & = SC_ZERO_TIME); 63 64 sc_time & operator= (const sc_time &); 65 66 uint64_t value() const { 67 return time; 68 } 69 70 inline double to_double() const; 71 inline double to_seconds() const; 72 inline operator double() const { 73 return to_double(); 74 } 75 76 const std::string to_string() const; 77 67 78 }; 68 79 69 inline const sc_time& sc_time_stamp () // in default time units 70 { 71 SC_CURRENT_TIME.time = nb_cycles; 72 return SC_CURRENT_TIME;// = sc_time (nb_cycles, SC_NS); 80 81 inline const sc_time & sc_time_stamp() { 82 // in default time units 83 SC_CURRENT_TIME.time = nb_cycles; 84 return SC_CURRENT_TIME; // = sc_time (nb_cycles, SC_NS); 73 85 } 74 86 75 double 76 sc_time::to_double () const 77 { 78 double fact = 1; 79 switch(unit) { 80 case SC_FS: fact = 1e-6; break; 81 case SC_PS: fact = 1e-3; break; 82 case SC_NS: fact = 1; break; 83 case SC_US: fact = 1e3; break; 84 case SC_MS: fact = 1e6; break; 85 case SC_SEC: fact = 1e9; break; 86 } 87 return (double)time * fact; 87 88 double sc_time::to_double() const { 89 double fact = 1; 90 switch (unit) { 91 case SC_FS: 92 fact = 1e-6; 93 break; 94 case SC_PS: 95 fact = 1e-3; 96 break; 97 case SC_NS: 98 fact = 1; 99 break; 100 case SC_US: 101 fact = 1e3; 102 break; 103 case SC_MS: 104 fact = 1e6; 105 break; 106 case SC_SEC: 107 fact = 1e9; 108 break; 109 } 110 return (double) time * fact; 88 111 } 89 112 90 double 91 sc_time::to_seconds() const 92 { 93 double fact = 1; 94 switch(unit) { 95 case SC_FS: fact = 1e-15; break; 96 case SC_PS: fact = 1e-12; break; 97 case SC_NS: fact = 1e-9; break; 98 case SC_US: fact = 1e-6; break; 99 case SC_MS: fact = 1e-3; break; 100 case SC_SEC: fact = 1; break; 101 } 102 return (double)time * fact; 113 114 double sc_time::to_seconds() const { 115 double fact = 1; 116 switch (unit) { 117 case SC_FS: 118 fact = 1e-15; 119 break; 120 case SC_PS: 121 fact = 1e-12; 122 break; 123 case SC_NS: 124 fact = 1e-9; 125 break; 126 case SC_US: 127 fact = 1e-6; 128 break; 129 case SC_MS: 130 fact = 1e-3; 131 break; 132 case SC_SEC: 133 fact = 1; 134 break; 135 } 136 return (double) time * fact; 103 137 } 138 104 139 105 140 } // end of namespace sc_core 106 141 142 107 143 #endif /* __SC_TIME_H__ */ 144 145 /* 146 # Local Variables: 147 # tab-width: 4; 148 # c-basic-offset: 4; 149 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 150 # indent-tabs-mode: nil; 151 # End: 152 # 153 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 154 */ 155 -
sources/src/sc_trace.cc
r32 r52 35 35 */ 36 36 37 #include <cassert> 38 #include <list> 39 #include <cstdio> 40 #include <iostream> 41 #include <cstring> //strlen 42 37 43 #include "sc_port.h" 38 44 #include "sc_clock.h" … … 42 48 #include "hex2string.h" 43 49 44 #include <cassert>45 #include <list>46 #include <cstdio>47 #include <iostream>48 #include <cstring> //strlen49 50 50 #ifdef HAVE_CONFIG_H 51 51 #include "config.h" 52 52 #endif 53 53 54 54 55 //----------------------------------------- 55 56 … … 63 64 } 64 65 65 //#include "malloc.h" // NO LONGER SUPPORTED66 66 #include <cstdlib> 67 67 #include <cstdio> … … 70 70 //----------------------------------------- 71 71 72 72 73 namespace sc_core { 73 74 74 75 vector<sc_trace_file *> trace_file_list; 75 uint64 cpt = 0; 76 uint64 trace_start = 0; 77 78 //----------------------------------------- 79 #if 0 80 static ostream& operator << (ostream &, const signal2trace &); 81 #endif 82 83 //----------------------------------------- 84 85 /* 86 typedef list<signal2trace> signal2trace_list; 87 88 template <typename T> 89 static 90 void make_list_from_vector (const vector<T>& v, list<T>& l) 91 { 92 l.clear (); 93 typename vector<T>::const_iterator i; 94 for (i = v.begin (); i != v.end (); ++i) 95 l.push_back (*i); 96 } 97 98 template <typename T> 99 static 100 void make_vector_from_list (const list<T>& l, vector<T>& v) 101 { 102 v.clear (); 103 typename list<T>::const_iterator i; 104 for (i = l.begin (); i != l.end (); ++i) 105 v.push_back (*i); 106 } 107 108 static 109 int operator<(const signal2trace &e1, const signal2trace &e2) 110 { 111 return (e1.bit_size < e2.bit_size); 112 } 113 114 static void 115 init (sc_trace_file *tf) 116 { 117 signal2trace_list lsig; 118 make_list_from_vector (tf->sig_list, lsig); 119 lsig.reverse(); //sort (); 120 make_vector_from_list (lsig, tf->sig_list); 121 } 122 */ 123 124 static 125 void 126 init (sc_trace_file &tf) 127 { 128 if (dump_stage) 129 cerr << "Initializing trace functions : Looking for clocks..."; 130 131 vector<signal2trace>::iterator i; 132 i = (tf.sig_list).begin(); 133 while (i!=(tf.sig_list).end()) { 134 if (is_clock( *(i->inter) ) ) { 135 tf.clk_list.push_back(*i); 136 i = tf.sig_list.erase(i); 137 } 138 else ++i; 139 } 140 if (dump_stage) 141 cerr << "Done\n"; 142 } 143 144 static 145 void 146 vcd_print_cycle_number (FILE *f,long long unsigned int num) 147 { 148 string cycle; 149 150 //------------------------------------------------------------------------------------ 151 // affichage des cycles (#500 ou #2500 etc...) 152 fprintf(f,"\n#%llu00\n", num * 5);//cycle de simulation 153 } 76 uint64 cpt = 0; 77 uint64 trace_start = 0; 78 79 80 static void init(sc_trace_file & tf) { 81 if (dump_stage) { 82 cerr << "Initializing trace functions : Looking for clocks..."; 83 } 84 85 vector<signal2trace>::iterator i; 86 i = (tf.sig_list).begin(); 87 while (i != (tf.sig_list).end()) { 88 if (is_clock(*(i->inter))) { 89 tf.clk_list.push_back(*i); 90 i = tf.sig_list.erase(i); 91 } 92 else { 93 ++i; 94 } 95 } 96 if (dump_stage) { 97 cerr << "Done\n"; 98 } 99 } 100 101 102 static void vcd_print_cycle_number(FILE * f,long long unsigned int num) { 103 string cycle; 104 105 // affichage des cycles (#500 ou #2500 etc...) 106 fprintf(f,"\n#%llu00\n", num * 5);//cycle de simulation 107 } 108 109 154 110 155 111 //-------------------------------------------------------------------------------------- 156 112 // trace function 157 113 // Called each end of cycle to dump in trace files 158 159 void 160 trace_all (bool part) 161 { 162 if (trace_file_list.empty ()) 163 return; 164 165 if (cpt >= trace_start) 166 { 167 vector<sc_trace_file*>::const_iterator ptf; 168 for (ptf = trace_file_list.begin (); ptf != trace_file_list.end(); ++ptf) 169 { 170 sc_trace_file *tf = *ptf; 171 assert(tf != NULL); 172 trace (*tf, part); 173 } 174 } 175 176 cpt++; 177 } 114 void trace_all(bool part) { 115 if (trace_file_list.empty()) { 116 return; 117 } 118 119 if (cpt >= trace_start) { 120 vector<sc_trace_file *>::const_iterator ptf; 121 for (ptf = trace_file_list.begin(); ptf != trace_file_list.end(); ++ptf) { 122 sc_trace_file * tf = *ptf; 123 assert(tf != NULL); 124 trace(*tf, part); 125 } 126 } 127 128 cpt++; 129 } 130 178 131 179 132 #ifdef CONFIG_PAT_TRACE_FORMAT 180 static void 181 pat_set_value (char *buf, const signal2trace &s) 182 { 183 if ( ( s.bit_size % 4 ) == 0 ) 184 { 185 buf[1] = 'x'; 186 hex2string( buf+2, s.inter->get_pointer() , s.bit_size ); 187 } 188 else 189 { 190 buf[1] = 'b'; 191 bit2string( buf+2, s.inter->get_pointer() , s.bit_size ); 192 } 193 } 194 195 inline 196 static 197 void 198 affect (const char *cur, 199 const char *nomSig, 200 const char *buf) 201 { 133 static void pat_set_value(char * buf, const signal2trace & s) { 134 if ((s.bit_size % 4) == 0) { 135 buf[1] = 'x'; 136 hex2string(buf + 2, s.inter->get_pointer(), s.bit_size); 137 } 138 else { 139 buf[1] = 'b'; 140 bit2string(buf + 2, s.inter->get_pointer(), s.bit_size); 141 } 142 } 143 144 145 inline static void affect(const char * cur, const char * nomSig, const char * buf) { 146 AFFECT ((char*)cur, (char*)nomSig, (char*)buf ); 147 } 148 149 150 151 inline static void pat_trace( 152 sc_trace_file & tf, 153 const signal2trace & s2t, 154 const ostringstream & cur1, 155 const ostringstream & cur2) { 156 static char buf[50] = "0\0"; 157 //cout << "Nom du signal: " << s->nomSig; 158 pat_set_value(buf, s2t); 159 affect(cur1.str().c_str(), s2t.nomSig.c_str(), buf); 160 affect(cur2.str().c_str(), s2t.nomSig.c_str(), buf); 161 } 162 163 164 inline static void pat_trace_clocks( 165 sc_trace_file & tf, 166 const ostringstream & cur1, 167 const ostringstream & cur2) { 168 vector<signal2trace>::const_iterator s; 169 for (s = (tf.clk_list).begin(); s != (tf.clk_list).end(); s++) { 170 const signal2trace & s2t = *s; 171 char * name = (char *) ((s2t.nomSig).c_str()); 172 const sc_interface * inter = s2t.inter; 173 const sc_clock * clk = (const sc_clock *) inter; 174 bool posedge_first = clk->posedge_first; 175 char * a, * b; 176 if (posedge_first) { 177 a = "0B1"; 178 b = "0B0"; 179 } 180 else { 181 a = "0B0"; 182 b = "0B1"; 183 } 184 affect(cur1.str().c_str(), name, a); 185 affect(cur2.str().c_str(), name, b); 186 } 187 } 188 189 190 static void pat_trace_init(sc_trace_file & tf) { 191 init(tf); 192 } 193 194 195 static void pat_trace(sc_trace_file & tf, bool part) { 196 if (part) { 197 return; 198 } 199 200 if (cpt == trace_start) { 201 pat_trace_init(tf); 202 } 203 204 // time counters 205 ostringstream cur1, cur2; 206 long long unsigned int buf = cpt * 5; 207 cur1 << buf << "00"; 208 cur2 << buf + 5 << "00"; 209 210 // affect each signal 211 vector<signal2trace>::iterator s; 212 for (s = (tf.sig_list).begin(); s != (tf.sig_list).end(); s++) { 213 pat_trace(tf, *s, cur1, cur2); 214 } 215 pat_trace_clocks(tf, cur1, cur2); 216 } 217 218 #else 219 void pat_trace (sc_trace_file & tf, bool part) {} 220 #endif // CONFIG_PAT_TRACE_FORMAT 221 222 223 static bool is_modified(const signal2trace & s2t) { 224 unsigned int bit_size = s2t.bit_size; 225 if (bit_size > 32) { 226 const uint64 * const pointer_saved = (const uint64 *) s2t.pointer; 227 const uint64 * const pointer_current = (const uint64 *) s2t.inter->get_pointer(); 228 return (*pointer_saved != *pointer_current); 229 } 230 else if (bit_size > 16) { 231 const uint32 * const pointer_saved = (const uint32 *) s2t.pointer; 232 const uint32 * const pointer_current = (const uint32 *) s2t.inter->get_pointer(); 233 return (*pointer_saved != *pointer_current); 234 } 235 else { 236 const uint16 * const pointer_saved = (const uint16 *) s2t.pointer; 237 const uint16 * const pointer_current = (const uint16 *) s2t.inter->get_pointer(); 238 return (*pointer_saved != *pointer_current); 239 } 240 } 241 242 243 static bool save_modification(signal2trace & s2t) { 244 *(s2t.pointer) = *(s2t.inter->get_pointer()); 245 } 246 247 248 static inline void print(sc_trace_file & tf, signal2trace & s2t) { 249 char buf[100]; 250 bit2string(buf + 1, s2t.inter->get_pointer() , s2t.bit_size); 251 252 char * buf2 = strip(buf + 1); 253 int len = strlen(buf2); 254 if (s2t.bit_size != 1) { 255 --buf2; 256 buf2[0] = 'b'; 257 sprintf(buf2 + len + 1, " %s\n", s2t.alias); 258 } 259 else { 260 sprintf(buf2 + len, "%s\n", s2t.alias); 261 } 262 263 // ecriture liste[i] dans le fichier VCD: 264 if ((fprintf(tf.pfic,buf2)) == 0) { 265 cerr << "erreur ecriture du couple Valeur/Nom du signal dans le VCD\n"; 266 exit(16); 267 } 268 } 269 270 271 static inline void vcd_trace(sc_trace_file & tf, signal2trace & s2t, bool skip = true) { 272 if ((skip) && (!is_modified(s2t))) { 273 return; 274 } 275 save_modification(s2t); 276 print(tf, s2t); 277 } 278 279 280 static void vcd_trace_clocks(const sc_trace_file & tf, bool v) { 281 vector<signal2trace>::const_iterator i; 282 for (i = (tf.clk_list).begin(); i != (tf.clk_list).end(); i++) { 283 const signal2trace & s2t = *i; 284 const sc_interface * inter = s2t.inter; 285 const sc_clock * clk = (const sc_clock *) inter; 286 bool posedge_first = clk->posedge_first; 287 fprintf(tf.pfic, "%c%s\n",(v^posedge_first)?'0':'1', i->alias); 288 } 289 } 290 291 292 static tab_t * vcd_signal_table = NULL; 293 294 295 static int vcd_get_size(const signal2trace & s2t) { 202 296 #if 0 203 printf ("AFFECT (\"%s\", \"%s\", \"%s\");\n", 204 cur, 205 nomSig, 206 buf); 297 cerr << "alias : " << s2t.alias << "\n"; 298 cerr << "bit_size : " << s2t.bit_size << "\n"; 299 cerr << "=> #tab_t : " << ((s2t.bit_size - 1) / (sizeof (tab_t)*8)) + 1 << "\n"; 207 300 #endif 208 AFFECT ((char*)cur, (char*)nomSig, (char*)buf ); 209 } 210 211 inline 212 static 213 void 214 pat_trace (sc_trace_file &tf, 215 const signal2trace &s2t, 216 const ostringstream &cur1, 217 const ostringstream &cur2) 218 { 219 static char buf[50] = "0\0"; 220 //cout << "Nom du signal: " << s->nomSig; 221 pat_set_value (buf, s2t); 222 affect (cur1.str().c_str(), s2t.nomSig.c_str(), buf); 223 affect (cur2.str().c_str(), s2t.nomSig.c_str(), buf); 224 } 225 226 inline 227 static 228 void 229 pat_trace_clocks (sc_trace_file &tf, 230 const ostringstream &cur1, 231 const ostringstream &cur2) 232 { 233 vector<signal2trace>::const_iterator s; 234 for(s=(tf.clk_list).begin();s!=(tf.clk_list).end();s++) 235 { 236 const signal2trace &s2t = *s; 237 char *name = (char*)((s2t.nomSig).c_str()); 238 const sc_interface *inter = s2t.inter; 239 const sc_clock *clk = (const sc_clock *) inter; 240 bool posedge_first = clk->posedge_first; 241 char *a, *b; 242 if (posedge_first) 243 { 244 a = "0B1"; b = "0B0"; 245 } else { 246 a = "0B0"; b = "0B1"; 247 } 248 affect (cur1.str().c_str(), name, a); 249 affect (cur2.str().c_str(), name, b); 250 } 251 } 252 253 static 254 void 255 pat_trace_init (sc_trace_file &tf) 256 { 257 init (tf); 258 } 259 260 static 261 void 262 pat_trace (sc_trace_file &tf, 263 bool part) 264 { 265 if (part) 266 return; 267 if (cpt==trace_start) { 268 pat_trace_init (tf); 269 } 270 // time counters 271 ostringstream cur1,cur2; 272 long long unsigned int buf = cpt * 5; 273 cur1 << buf << "00"; 274 cur2 << buf + 5 << "00"; 275 // affect each signal 276 vector<signal2trace>::iterator s; 277 for(s=(tf.sig_list).begin();s!=(tf.sig_list).end();s++) 278 { 279 pat_trace (tf, *s, cur1, cur2); 280 } 281 pat_trace_clocks (tf, cur1, cur2); 282 } 283 #else 284 void 285 pat_trace (sc_trace_file &tf, 286 bool part) 287 { 288 } 301 return ((s2t.bit_size - 1) / (sizeof(tab_t) * 8)) + 1; 302 } 303 304 305 static int vcd_get_signal_table_size(const sc_trace_file & tf) { 306 int total_size = 0; 307 vector<signal2trace>::const_iterator i; 308 for (i = (tf.sig_list).begin(); i != (tf.sig_list).end(); i++) { 309 const signal2trace & s2t = *i; 310 total_size += vcd_get_size(s2t); 311 } 312 return total_size; 313 } 314 315 316 static void vcd_alloc_signal_table(int size) { 317 if (size == 0) { 318 vcd_signal_table = NULL; 319 } 320 else { 321 vcd_signal_table = (tab_t *) malloc(sizeof(tab_t) * size); 322 } 323 #ifdef CONFIG_DEBUG 324 if (vcd_signal_table == NULL) { 325 cerr << "Internal error : Unable to allocate memory for signal table to trace.\n"; 326 exit(24032005); 327 } 328 #endif 329 } 330 331 332 static void vcd_bind_to_signal_table(sc_trace_file & tf) { 333 tab_t * cur = vcd_signal_table; 334 vector<signal2trace>::iterator i; 335 for (i = (tf.sig_list).begin(); i != (tf.sig_list).end(); i++) { 336 signal2trace & s2t = *i; 337 s2t.pointer = cur; 338 cur += vcd_get_size(s2t); 339 #if 0 340 std::cout << s2t 341 << "\nget_pointer () => " << hex << s2t.inter->get_pointer () 342 << "\nvcd pointer () => " << hex << s2t.pointer 343 << "\nvcd_get_size () => " << vcd_get_size (s2t) 344 << "\n"; 345 #endif 346 } 347 } 348 349 350 static void vcd_build_signal_table(sc_trace_file & tf) { 351 int s = vcd_get_signal_table_size(tf); 352 vcd_alloc_signal_table(s); 353 vcd_bind_to_signal_table(tf); 354 } 355 356 357 static void vcd_trace_init(sc_trace_file & tf) { 358 init(tf); 359 fprintf(tf.pfic,"$upscope $end\n$enddefinitions $end\n\n$comment\nAll initial values are dumped below at time 0 sec = 0 timescale units.\n$end\n\n$dumpvars\n"); 360 vcd_build_signal_table(tf); 361 362 // dump all var 363 vector<signal2trace>::iterator i; 364 for(i = (tf.sig_list).begin() ; i != (tf.sig_list).end(); i++) { 365 vcd_trace(tf, *i, false); 366 }//fin de la liste des signal2trace 367 368 // clocks to trace 369 vcd_trace_clocks(tf, true); 370 371 if (cpt == trace_start) { 372 fprintf(tf.pfic, "$end\n"); //fin du $dumpvars 373 } 374 } 375 376 377 static void vcd_trace(sc_trace_file & tf, bool part) { 378 if (sc_core::cpt == sc_core::trace_start) { 379 if (part == false) { 380 vcd_trace_init (tf); 381 } 382 } 383 else { 384 #if defined(CONFIG_DEBUG) 385 if (vcd_signal_table == NULL) { 386 cerr << "Internal Error : VCD signal table is not yet allocated.\n"; 387 exit(1042005); 388 } 389 #endif 390 vcd_print_cycle_number(tf.pfic,sc_core::cpt); 391 // signals to trace 392 if (part == false) { 393 vector<signal2trace>::iterator i; 394 for (i = tf.sig_list.begin(); i != tf.sig_list.end(); i++) { 395 vcd_trace(tf, *i); 396 }//fin de la liste des signal2trace 397 } 398 // clocks to trace 399 vcd_trace_clocks(tf, !part); 400 } 401 } 402 403 404 void trace(sc_trace_file & tf, bool part) { 405 switch (tf.flag) { 406 // fonction trace() pour VCD: 407 case VCD_FORMAT: 408 vcd_trace(tf, part); 409 break; 410 //fin de la fonction trace() pour VCD 411 412 /*------------------------------------------------------------------------------------*/ 413 414 // fonction trace() pour PAT: 415 case PAT_FORMAT: 416 pat_trace(tf, part); 417 break; 418 //fin de la fonction trace() pour PAT 419 } 420 // fin du switch format pour trace() 421 422 } 423 424 425 /*------------------------------------------------------------------------------------*/ 426 427 428 static void vcd_sc_trace(sc_trace_file * tf, const signal2trace & t, const std::string & name) { 429 //déclaration du signal dans l'en-tête du fichier VCD: 430 // exemple de déclarations : 431 // $var wire 1 aaa clk $end 432 // $var wire 1 aab resetn $end 433 // $var wire 1 aac _mips0_IT_5 $end 434 435 std::string declaration; 436 std::ostringstream buf; 437 // begin 438 declaration = "$var wire "; 439 buf.width(4); 440 buf << t.bit_size; 441 declaration += buf.str(); 442 declaration += " "; 443 declaration += t.alias; 444 declaration += " "; 445 declaration += name; 446 // bit range 447 if (t.bit_size != 1) { 448 declaration += " ["; 449 std::ostringstream bit_size; 450 bit_size << t.bit_size - 1; 451 declaration += bit_size.str(); 452 declaration += ":0]"; 453 } 454 // end 455 declaration += " $end\n"; 456 457 if ((fprintf(tf->pfic,declaration.c_str())) == 0) { 458 cerr << "erreur ecriture de declaration du signal sc_signal\n"; 459 exit(3); 460 } 461 } 462 463 464 static void pat_sc_trace(sc_trace_file * tf, const signal2trace & t, const std::string & name) { 465 #ifdef CONFIG_PAT_TRACE_FORMAT 466 //exemple: 467 //DECLAR ("a", ":2", "X", IN, "3 downto 0", "" ); 468 //DECLAR ("b", ":2", "X", IN, "3 downto 0", "" ); 469 //DECLAR ("vdd", ":2", "B", IN, "", "" ); 470 471 std::string downto; 472 const sc_object * obj = (const sc_object *) t.inter; 473 const char * obj_kind = obj->kind(); 474 char * format; 475 char * dir; 476 477 if (strstr(obj_kind, "inout")) 478 dir = OUT; // Direction is OUT instead of INOUT 479 // because port behavior is only seen as an output port. 480 else if (strstr (obj_kind, "in")) { 481 dir = IN; 482 } 483 else if (strstr (obj_kind, "out")) { 484 dir = OUT; 485 } 486 else if (obj_kind == sc_clock::kind_string) { 487 dir = SIGNAL; 488 } 489 else if (obj_kind == sc_signal_base::kind_string) { 490 dir = REGISTER; 491 } 492 // to do : dir = REGISTER; 493 // dir = SIGNAL; 494 495 if (t.bit_size % 4 == 0) { 496 format = "x"; 497 } 498 else { 499 format = "b"; 500 } 501 502 if (t.bit_size == 1) { 503 downto = ""; 504 } 505 else { 506 std::ostringstream nbits; 507 nbits << t.bit_size - 1; 508 downto = nbits.str(); 509 downto += " downto 0"; 510 } 511 512 #if 0 513 printf ("DECLAR (\"%s\", \":1\", \"%s\", %s, \"%s\", \"\" );\n", 514 name.c_str (), 515 format, 516 dir, 517 downto.c_str()); 518 #endif 519 DECLAR ((char *) (name.c_str()), ":1", format, dir, (char *) downto.c_str(), ""); 289 520 #endif // CONFIG_PAT_TRACE_FORMAT 290 291 static 292 bool 293 is_modified (const signal2trace &s2t) 294 { 295 unsigned int bit_size = s2t.bit_size; 296 if (bit_size > 32) 297 { 298 const uint64 *const pointer_saved = (const uint64 *)s2t.pointer; 299 const uint64 *const pointer_current = (const uint64 *)s2t.inter->get_pointer (); 300 return (*pointer_saved != *pointer_current); 301 } else if (bit_size > 16) { 302 const uint32 *const pointer_saved = (const uint32*)s2t.pointer; 303 const uint32 *const pointer_current = (const uint32*)s2t.inter->get_pointer (); 304 return (*pointer_saved != *pointer_current); 305 } else { 306 const uint16 *const pointer_saved = (const uint16 *)s2t.pointer; 307 const uint16 *const pointer_current = (const uint16 *)s2t.inter->get_pointer (); 308 return (*pointer_saved != *pointer_current); 309 } 310 } 311 312 static 313 bool 314 save_modification (signal2trace &s2t) 315 { 316 *(s2t.pointer) = *(s2t.inter->get_pointer ()); 317 } 318 319 static 320 inline 321 void 322 print (sc_trace_file &tf, signal2trace &s2t) 323 { 324 char buf[100]; 325 bit2string( buf+1, s2t.inter->get_pointer() , s2t.bit_size ); 326 327 char *buf2 = strip(buf+1); 328 int len = strlen (buf2); 329 if (s2t.bit_size != 1) 330 { 331 --buf2; 332 buf2[0] = 'b'; 333 sprintf (buf2 + len + 1, " %s\n", s2t.alias); 334 } else { 335 sprintf (buf2 + len, "%s\n", s2t.alias); 336 } 337 /* 338 char *buf2 = strip(buf); 339 char buf3[128]; 340 341 if (s2t.bit_size != 1) 342 sprintf (buf3, "b%s %s\n", buf2, s2t.alias); 343 else 344 sprintf (buf3, "%s%s\n", buf2, s2t.alias); 345 */ 346 // ecriture liste[i] dans le fichier VCD: 347 if ((fprintf(tf.pfic,buf2))==0) 348 { 349 cerr << "erreur ecriture du couple Valeur/Nom du signal dans le VCD\n"; 350 exit(16); 351 } 352 } 353 354 static 355 inline 356 void 357 vcd_trace (sc_trace_file &tf, 358 signal2trace &s2t, 359 bool skip = true) 360 { 361 if ((skip) && (!is_modified (s2t))) 362 return; 363 save_modification (s2t); 364 print (tf, s2t); 365 } 366 367 static 368 void 369 vcd_trace_clocks (const sc_trace_file &tf, 370 bool v) 371 { 372 vector<signal2trace>::const_iterator i; 373 for(i=(tf.clk_list).begin();i!=(tf.clk_list).end();i++) 374 { 375 const signal2trace &s2t = *i; 376 const sc_interface *inter = s2t.inter; 377 const sc_clock *clk = (const sc_clock *) inter; 378 bool posedge_first = clk->posedge_first; 379 fprintf(tf.pfic, "%c%s\n",(v^posedge_first)?'0':'1', i->alias); 380 } 381 } 382 383 static tab_t *vcd_signal_table = NULL; 384 385 386 static 387 int 388 vcd_get_size (const signal2trace &s2t) 389 { 390 #if 0 391 cerr << "alias : " << s2t.alias << "\n"; 392 cerr << "bit_size : " << s2t.bit_size << "\n"; 393 cerr << "=> #tab_t : " << ((s2t.bit_size - 1) / (sizeof (tab_t)*8)) + 1 << "\n"; 394 #endif 395 return ((s2t.bit_size - 1) / (sizeof (tab_t)*8)) + 1; 396 } 397 398 static 399 int 400 vcd_get_signal_table_size (const sc_trace_file &tf) 401 { 402 int total_size = 0; 403 vector<signal2trace>::const_iterator i; 404 for(i=(tf.sig_list).begin();i!=(tf.sig_list).end();i++) 405 { 406 const signal2trace &s2t = *i; 407 total_size += vcd_get_size (s2t); 408 } 409 return total_size; 410 } 411 412 static 413 void 414 vcd_alloc_signal_table (int size) 415 { 416 if (size == 0) 417 vcd_signal_table = NULL; 418 else 419 vcd_signal_table = (tab_t*) malloc (sizeof (tab_t) * size); 420 #ifdef CONFIG_DEBUG 421 if (vcd_signal_table == NULL) 422 { 423 cerr << "Internal error : Unable to allocate memory for signal table to trace.\n"; 424 exit (24032005); 425 } 426 #endif 427 } 428 429 static 430 void 431 vcd_bind_to_signal_table (sc_trace_file &tf) 432 { 433 tab_t *cur = vcd_signal_table; 434 vector<signal2trace>::iterator i; 435 for(i=(tf.sig_list).begin();i!=(tf.sig_list).end();i++) 436 { 437 signal2trace &s2t = *i; 438 s2t.pointer = cur; 439 cur += vcd_get_size (s2t); 440 #if 0 441 std::cout << s2t 442 << "\nget_pointer () => " << hex << s2t.inter->get_pointer () 443 << "\nvcd pointer () => " << hex << s2t.pointer 444 << "\nvcd_get_size () => " << vcd_get_size (s2t) 445 << "\n"; 446 #endif 447 } 448 } 449 450 static 451 void 452 vcd_build_signal_table (sc_trace_file &tf) 453 { 454 int s = vcd_get_signal_table_size (tf); 455 456 vcd_alloc_signal_table (s); 457 458 vcd_bind_to_signal_table (tf); 459 } 460 461 static 462 void 463 vcd_trace_init (sc_trace_file &tf) 464 { 465 init (tf); 466 fprintf (tf.pfic,"$upscope $end\n$enddefinitions $end\n\n$comment\nAll initial values are dumped below at time 0 sec = 0 timescale units.\n$end\n\n$dumpvars\n"); 467 vcd_build_signal_table (tf); 468 469 // dump all var 470 vector<signal2trace>::iterator i; 471 for(i=(tf.sig_list).begin();i!=(tf.sig_list).end();i++) 472 { 473 vcd_trace (tf, *i, false); 474 }//fin de la liste des signal2trace 475 476 // clocks to trace 477 vcd_trace_clocks (tf, true); 478 479 if (cpt==trace_start) 480 fprintf(tf.pfic,"$end\n"); //fin du $dumpvars 481 } 482 483 static 484 void 485 vcd_trace (sc_trace_file &tf, 486 bool part) 487 { 488 if (sc_core::cpt==sc_core::trace_start) { 489 if (part == false) 490 vcd_trace_init (tf); 491 } else { 492 #if defined(CONFIG_DEBUG) 493 if (vcd_signal_table == NULL) 494 { 495 cerr << "Internal Error : VCD signal table is not yet allocated.\n"; 496 exit (1042005); 497 } 498 #endif 499 vcd_print_cycle_number (tf.pfic,sc_core::cpt); 500 // signals to trace 501 if (part == false) 502 { 503 // vector<signal2trace> &sig_list = (part == false)?to_update_on_pos:to_update_on_neg; 504 vector<signal2trace>::iterator i; 505 for(i=tf.sig_list.begin();i!=tf.sig_list.end();i++) 506 { 507 vcd_trace (tf, *i); 508 }//fin de la liste des signal2trace 509 } 510 // clocks to trace 511 vcd_trace_clocks (tf, !part); 512 } 513 } 514 515 void 516 trace (sc_trace_file &tf, bool part) 517 { 518 /*------------------------------------------------------------------------------------*/ 519 520 switch (tf.flag){ 521 522 // fonction trace() pour VCD: 523 case VCD_FORMAT: 524 vcd_trace (tf, part); 525 break;//fin de la fonction trace() pour VCD 526 527 /*------------------------------------------------------------------------------------*/ 528 529 // fonction trace() pour PAT: 530 case PAT_FORMAT : 531 pat_trace (tf, part); 532 break;//fin de la fonction trace() pour PAT 533 }// fin du switch format pour trace() 534 535 } 536 537 /*------------------------------------------------------------------------------------*/ 538 539 static 540 void 541 vcd_sc_trace (sc_trace_file *tf, const signal2trace &t, const std::string 542 &name) 543 { 544 //déclaration du signal dans l'en-tête du fichier VCD: 545 // exemple de déclarations : 546 // $var wire 1 aaa clk $end 547 // $var wire 1 aab resetn $end 548 // $var wire 1 aac _mips0_IT_5 $end 549 550 std::string declaration; 551 std::ostringstream buf; 552 // begin 553 declaration = "$var wire "; 554 buf.width (4); 555 buf << t.bit_size; 556 declaration += buf.str(); 557 declaration += " "; 558 declaration += t.alias; 559 declaration += " "; 560 declaration += name; 561 // bit range 562 if (t.bit_size != 1) 563 { 564 declaration += " ["; 565 std::ostringstream bit_size; 566 bit_size << t.bit_size - 1; 567 declaration += bit_size.str(); 568 declaration += ":0]"; 569 } 570 // end 571 declaration += " $end\n"; 572 //declaration += " $end\n"; 573 574 if ((fprintf(tf->pfic,declaration.c_str()))==0) 575 { 576 cerr << "erreur ecriture de declaration du signal sc_signal\n"; 577 exit(3); 578 } 579 } 580 581 static 582 void 583 pat_sc_trace (sc_trace_file *tf, const signal2trace &t, const std::string 584 &name) 585 { 586 #ifdef CONFIG_PAT_TRACE_FORMAT 587 //exemple: 588 //DECLAR ("a", ":2", "X", IN, "3 downto 0", "" ); 589 //DECLAR ("b", ":2", "X", IN, "3 downto 0", "" ); 590 //DECLAR ("vdd", ":2", "B", IN, "", "" ); 591 592 std::string downto; 593 const sc_object *obj = (const sc_object *) t.inter; 594 const char *obj_kind = obj->kind (); 595 char *format; 596 char *dir; 597 598 if (strstr (obj_kind,"inout")) 599 dir = OUT; // Direction is OUT instead of INOUT 600 // because port behavior is only seen as an output port. 601 else if (strstr (obj_kind,"in")) 602 dir = IN; 603 else if (strstr (obj_kind,"out")) 604 dir = OUT; 605 else if (obj_kind == sc_clock::kind_string) 606 dir = SIGNAL; 607 else if (obj_kind == sc_signal_base::kind_string) 608 dir = REGISTER; 609 // to do : dir = REGISTER; 610 // dir = SIGNAL; 611 612 if ( t.bit_size % 4 == 0) 613 format = "x"; 614 else 615 format = "b"; 616 617 if ( t.bit_size == 1) { 618 downto = ""; 619 } 620 else 621 { 622 std::ostringstream nbits; 623 nbits << t.bit_size-1; 624 downto = nbits.str(); 625 downto += " downto 0"; 626 } 627 628 #if 0 629 printf ("DECLAR (\"%s\", \":1\", \"%s\", %s, \"%s\", \"\" );\n", 630 name.c_str (), 631 format, 632 dir, 633 downto.c_str()); 634 #endif 635 DECLAR ((char*)(name.c_str ()), ":1", format, dir,(char *) downto.c_str(), "" ); 636 #endif // CONFIG_PAT_TRACE_FORMAT 637 } 638 639 void 640 sc_trace( sc_trace_file* tf, const signal2trace &t, const std::string &name ) 641 { 642 if (tf == NULL) 643 return; 644 if (t.bit_size > 64) 645 cerr << "Warning : tracing functions do not support data types larger than 64 bits.\n"; 646 if (already_initialized) 647 cerr << "Warning : please call tracing functions BEFORE sc_initialize.\n"; 648 //ajout du signal dans la liste des signaux à tracer: 649 (tf->sig_list).push_back (t); 650 651 switch (tf->flag) { 652 case VCD_FORMAT : 653 vcd_sc_trace (tf, t, name); 654 break; 655 656 case PAT_FORMAT : 657 pat_sc_trace (tf, t, name); 658 break; 659 default : 660 { 661 cerr << "Unknown trace format.\n"; 662 exit (1); 663 } 664 }// fin switch format pour sc_trace 665 666 } 521 } 522 523 524 void sc_trace(sc_trace_file * tf, const signal2trace & t, const std::string & name) { 525 if (tf == NULL) { 526 return; 527 } 528 if (t.bit_size > 64) { 529 cerr << "Warning : tracing functions do not support data types larger than 64 bits.\n"; 530 } 531 if (already_initialized) { 532 cerr << "Warning : please call tracing functions BEFORE sc_initialize.\n"; 533 } 534 //ajout du signal dans la liste des signaux à tracer: 535 (tf->sig_list).push_back(t); 536 537 switch (tf->flag) { 538 case VCD_FORMAT : 539 vcd_sc_trace(tf, t, name); 540 break; 541 542 case PAT_FORMAT : 543 pat_sc_trace(tf, t, name); 544 break; 545 default : 546 { 547 cerr << "Unknown trace format.\n"; 548 exit(1); 549 } 550 }// fin switch format pour sc_trace 551 552 } 553 554 //---------------------------------------------------------------------------- 555 556 #define DEF_SC_TRACE(T) /*inline \*/ \ 557 void \ 558 sc_trace (sc_trace_file* tf, const T& object, const std::string & name) \ 559 { \ 560 signal2trace t; \ 561 sc_interface * inter = new sc_localvar< T > (object); \ 562 t.inter = inter; \ 563 t.alias = alias(); \ 564 t.bit_size = get_bits_number(object); \ 565 t.nomSig = name; \ 566 sc_trace (tf, t, name); \ 567 } 568 569 570 DEF_SC_TRACE(bool) 571 DEF_SC_TRACE(float) 572 DEF_SC_TRACE(double) 573 DEF_SC_TRACE(unsigned char) 574 DEF_SC_TRACE(unsigned short) 575 DEF_SC_TRACE(unsigned int) 576 DEF_SC_TRACE(unsigned long) 577 DEF_SC_TRACE(char) 578 DEF_SC_TRACE(short) 579 DEF_SC_TRACE(int) 580 DEF_SC_TRACE(long) 581 DEF_SC_TRACE(uint64) 582 DEF_SC_TRACE(int64) 583 584 #undef DEF_SC_TRACE 667 585 668 586 //--------------------------------------------------------------------------- 669 587 670 #if 0671 static672 ostream&673 operator << (ostream &o,674 const signal2trace &s2t)675 {676 o << "signal2trace {"677 << "inter = " << hex << s2t.inter678 << ",alias = '" << s2t.alias << "'"679 << ",bitsize = " << dec << s2t.bit_size680 << ",pointer = " << hex << s2t.pointer681 << ",nomSig = " << s2t.nomSig << "}";682 return o;683 }684 #endif685 686 //----------------------------------------------------------------------------687 688 #define DEF_SC_TRACE(T) /*inline \*/ \689 void \690 sc_trace (sc_trace_file* tf, const T& object, const std::string &name) \691 { \692 signal2trace t; \693 sc_interface *inter = new sc_localvar<T> (object); \694 t.inter = inter; \695 t.alias = alias(); \696 t.bit_size = get_bits_number(object); \697 t.nomSig = name; \698 sc_trace (tf, t, name); \699 } \700 701 DEF_SC_TRACE(bool)702 DEF_SC_TRACE(float)703 DEF_SC_TRACE(double)704 DEF_SC_TRACE(unsigned char)705 DEF_SC_TRACE(unsigned short)706 DEF_SC_TRACE(unsigned int)707 DEF_SC_TRACE(unsigned long)708 DEF_SC_TRACE(char)709 DEF_SC_TRACE(short)710 DEF_SC_TRACE(int)711 DEF_SC_TRACE(long)712 DEF_SC_TRACE(uint64)713 DEF_SC_TRACE(int64)714 715 #undef DEF_SC_TRACE716 717 //---------------------------------------------------------------------------718 588 } // end of sc_core namespace 719 589 590 591 /* 592 # Local Variables: 593 # tab-width: 4; 594 # c-basic-offset: 4; 595 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 596 # indent-tabs-mode: nil; 597 # End: 598 # 599 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 600 */ 601 -
sources/src/sc_trace.h
r1 r52 33 33 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 34 34 */ 35 35 36 #ifndef __SC_TRACE_H__ 36 37 #define __SC_TRACE_H__ 37 38 38 #include "sc_trace_ext.h"39 39 #include <vector> 40 40 41 //--------------------------------------------------------------------------- 41 #include "sc_trace_ext.h" 42 42 43 43 44 namespace sc_core { 44 45 45 //---------------------------------------------------------------------------46 46 47 typedef enum {VCD_FORMAT, PAT_FORMAT} TRACE_FORMAT; 47 typedef enum { 48 VCD_FORMAT, 49 PAT_FORMAT 50 } TRACE_FORMAT; 48 51 49 //---------------------------------------------------------------------------50 52 51 53 extern std::vector<sc_trace_file *> trace_file_list; 52 extern uint64 54 extern uint64 cpt; 53 55 54 extern void trace_all 55 extern void trace (sc_trace_file&, bool part);56 extern void trace_all(bool part); 57 extern void trace(sc_trace_file &, bool part); 56 58 57 //---------------------------------------------------------------------------58 59 59 struct sc_trace_file 60 {61 TRACE_FORMAT 62 FILE *pfic;60 61 struct sc_trace_file { 62 TRACE_FORMAT flag; 63 FILE * pfic; 63 64 std::vector<signal2trace> sig_list; 64 65 std::vector<signal2trace> clk_list; 65 66 }; 66 67 67 //--------------------------------------------------------------------------- 68 68 69 69 70 } // end of sc_core namespace 70 71 71 //----------------------------------------------------------------------------72 72 #endif 73 73 74 /* 75 # Local Variables: 76 # tab-width: 4; 77 # c-basic-offset: 4; 78 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 79 # indent-tabs-mode: nil; 80 # End: 81 # 82 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 83 */ 84 -
sources/src/sc_trace_ext.h
r4 r52 38 38 #define __SC_TRACE_EXT_H__ 39 39 40 #include "sc_fwd.h"41 #include "alias.h"42 40 #include <vector> 43 41 #include <iostream> … … 45 43 #include <sstream> 46 44 45 #include "sc_fwd.h" 46 #include "alias.h" 47 47 #include "sc_module_ext.h" 48 48 #include "sc_localvar.h" 49 49 50 //--------------------------------------------------------------------------- 50 51 51 52 52 namespace sc_core { 53 53 54 using namespace sc_dt; 55 56 //--------------------------------------------------------------------------- 57 58 struct signal2trace 59 { 60 const sc_interface *inter; 61 const char *alias; 62 unsigned int bit_size; 63 tab_t *pointer; 64 std::string nomSig; 54 using namespace sc_dt; 55 56 57 58 struct signal2trace { 59 const sc_interface * inter; 60 const char * alias; 61 unsigned int bit_size; 62 tab_t * pointer; 63 std::string nomSig; 65 64 }; 66 65 67 //--------------------------------------------------------------------------- 68 69 template<typename T> struct bits_number_getter {}; 70 71 #define BITS_NUMBER_GETTER_DEF(newt,typ, expr) \ 72 template<newt> struct bits_number_getter<typ> { \ 73 typedef typ val_t; \ 74 static inline unsigned int get() {return expr;} \ 75 } 76 77 BITS_NUMBER_GETTER_DEF(, bool ,1); 78 BITS_NUMBER_GETTER_DEF(, char ,8*sizeof(val_t)); 79 BITS_NUMBER_GETTER_DEF(, signed char ,8*sizeof(val_t)); 80 BITS_NUMBER_GETTER_DEF(, unsigned char ,8*sizeof(val_t)); 81 BITS_NUMBER_GETTER_DEF(, unsigned short,8*sizeof(val_t)); 82 BITS_NUMBER_GETTER_DEF(, signed short,8*sizeof(val_t)); 83 BITS_NUMBER_GETTER_DEF(, signed int ,8*sizeof(val_t)); 84 BITS_NUMBER_GETTER_DEF(, unsigned int ,8*sizeof(val_t)); 85 BITS_NUMBER_GETTER_DEF(, signed long ,8*sizeof(val_t)); 86 BITS_NUMBER_GETTER_DEF(, unsigned long ,8*sizeof(val_t)); 87 BITS_NUMBER_GETTER_DEF(, float ,8*sizeof(val_t)); 88 BITS_NUMBER_GETTER_DEF(, sc_unsigned ,8*sizeof(unsigned int)); 89 BITS_NUMBER_GETTER_DEF(, sc_signed ,8*sizeof(int)); 90 BITS_NUMBER_GETTER_DEF(, double ,8*sizeof(val_t)); 91 BITS_NUMBER_GETTER_DEF(, uint64 ,8*sizeof(val_t)); 92 BITS_NUMBER_GETTER_DEF(, int64 ,8*sizeof(val_t)); 93 BITS_NUMBER_GETTER_DEF(typename inval_t, sc_in<inval_t> ,bits_number_getter<inval_t>::get()); 94 BITS_NUMBER_GETTER_DEF(typename inval_t, sc_out<inval_t> ,bits_number_getter<inval_t>::get()); 95 BITS_NUMBER_GETTER_DEF(typename inval_t, sc_inout<inval_t> ,bits_number_getter<inval_t>::get()); 96 BITS_NUMBER_GETTER_DEF(typename inval_t, sc_signal<inval_t>,bits_number_getter<inval_t>::get()); 97 BITS_NUMBER_GETTER_DEF(int W, sc_int<W>,W); 98 BITS_NUMBER_GETTER_DEF(int W, sc_uint<W>,W); 99 BITS_NUMBER_GETTER_DEF(int W, sc_bigint<W>,W); 100 BITS_NUMBER_GETTER_DEF(int W, sc_biguint<W>,W); 101 BITS_NUMBER_GETTER_DEF(int W, sc_bv<W>,W); 102 BITS_NUMBER_GETTER_DEF(int W, sc_lv<W>,W); 66 67 68 template< typename T > struct bits_number_getter {}; 69 70 71 #define BITS_NUMBER_GETTER_DEF(newt, typ, expr) \ 72 template<newt> struct bits_number_getter<typ> { \ 73 typedef typ val_t; \ 74 static inline unsigned int get() { return expr; } \ 75 } 76 77 78 BITS_NUMBER_GETTER_DEF(, bool , 1); 79 BITS_NUMBER_GETTER_DEF(, char , 8 * sizeof(val_t)); 80 BITS_NUMBER_GETTER_DEF(, signed char , 8 * sizeof(val_t)); 81 BITS_NUMBER_GETTER_DEF(, unsigned char , 8 * sizeof(val_t)); 82 BITS_NUMBER_GETTER_DEF(, unsigned short, 8 * sizeof(val_t)); 83 BITS_NUMBER_GETTER_DEF(, signed short, 8 * sizeof(val_t)); 84 BITS_NUMBER_GETTER_DEF(, signed int , 8 * sizeof(val_t)); 85 BITS_NUMBER_GETTER_DEF(, unsigned int , 8 * sizeof(val_t)); 86 BITS_NUMBER_GETTER_DEF(, signed long , 8 * sizeof(val_t)); 87 BITS_NUMBER_GETTER_DEF(, unsigned long , 8 * sizeof(val_t)); 88 BITS_NUMBER_GETTER_DEF(, float , 8 * sizeof(val_t)); 89 BITS_NUMBER_GETTER_DEF(, sc_unsigned , 8 * sizeof(unsigned int)); 90 BITS_NUMBER_GETTER_DEF(, sc_signed , 8 * sizeof(int)); 91 BITS_NUMBER_GETTER_DEF(, double , 8 * sizeof(val_t)); 92 BITS_NUMBER_GETTER_DEF(, uint64 , 8 * sizeof(val_t)); 93 BITS_NUMBER_GETTER_DEF(, int64 , 8 * sizeof(val_t)); 94 BITS_NUMBER_GETTER_DEF(typename inval_t, sc_in<inval_t> , bits_number_getter<inval_t>::get()); 95 BITS_NUMBER_GETTER_DEF(typename inval_t, sc_out<inval_t> , bits_number_getter<inval_t>::get()); 96 BITS_NUMBER_GETTER_DEF(typename inval_t, sc_inout<inval_t> , bits_number_getter<inval_t>::get()); 97 BITS_NUMBER_GETTER_DEF(typename inval_t, sc_signal<inval_t>, bits_number_getter<inval_t>::get()); 98 BITS_NUMBER_GETTER_DEF(int W, sc_int<W>, W); 99 BITS_NUMBER_GETTER_DEF(int W, sc_uint<W>, W); 100 BITS_NUMBER_GETTER_DEF(int W, sc_bigint<W>, W); 101 BITS_NUMBER_GETTER_DEF(int W, sc_biguint<W>, W); 102 BITS_NUMBER_GETTER_DEF(int W, sc_bv<W>, W); 103 BITS_NUMBER_GETTER_DEF(int W, sc_lv<W>, W); 103 104 #undef BITS_NUMBER_GETTER_DEF 104 105 template < typename T > inline 106 unsigned int get_bits_number (const T & object) 107 {105 106 107 template < typename T > 108 inline unsigned int get_bits_number (const T & object) { 108 109 return bits_number_getter<T>::get(); 109 110 } 110 111 111 //--------------------------------------------------------------------------- 112 112 113 113 114 struct sc_trace_file; 114 115 115 //--------------------------------------------------------------------------- 116 117 extern void 118 sc_trace( sc_trace_file* tf, const signal2trace &t, const std::string &name ); 116 117 extern void sc_trace(sc_trace_file * tf, const signal2trace & t, const std::string & name); 118 119 120 template < class T > /*inline*/ 121 void sc_trace(sc_trace_file * tf, const sc_in< T > & port, const std::string & name) { 122 signal2trace t; 123 t.inter = (const sc_interface *) &port; 124 t.alias = alias(); 125 t.bit_size = get_bits_number(port); 126 t.nomSig = name; 127 sc_trace (tf, t, name); 128 } 129 130 119 131 120 132 template <class T> /*inline*/ 121 void 122 sc_trace( sc_trace_file* tf, const sc_in<T>& port, const std::string &name ) 123 { 124 signal2trace t; 125 t.inter = (const sc_interface*) &port; 126 t.alias = alias(); 127 t.bit_size = get_bits_number(port); 128 t.nomSig = name; 129 sc_trace (tf, t, name); 130 } 131 132 //---------------------------------------------------------------------------- 133 134 template <class T> /*inline*/ 135 void 136 sc_trace( sc_trace_file* tf, const sc_out<T>& out, const std::string &name ) 137 { 138 signal2trace t; 139 t.inter = (const sc_interface*) &out; 140 t.alias = alias(); 141 t.bit_size = get_bits_number(out); 142 t.nomSig = name; 143 sc_trace (tf, t, name); 144 } 145 146 //---------------------------------------------------------------------------- 133 void sc_trace(sc_trace_file * tf, const sc_out< T > & out, const std::string & name) { 134 signal2trace t; 135 t.inter = (const sc_interface *) &out; 136 t.alias = alias(); 137 t.bit_size = get_bits_number(out); 138 t.nomSig = name; 139 sc_trace (tf, t, name); 140 } 141 142 147 143 148 144 template <typename T> /*inline*/ 149 void 150 sc_trace( sc_trace_file* tf, const sc_inout<T>& inout, const std::string &name ) 151 { 152 signal2trace t; 153 t.inter = (const sc_interface*) &inout; 154 t.alias = alias(); 155 t.bit_size = get_bits_number(inout); 156 t.nomSig = name; 157 sc_trace (tf, t, name); 158 } 159 160 //---------------------------------------------------------------------------- 145 void sc_trace(sc_trace_file * tf, const sc_inout< T > & inout, const std::string & name) { 146 signal2trace t; 147 t.inter = (const sc_interface *) &inout; 148 t.alias = alias(); 149 t.bit_size = get_bits_number(inout); 150 t.nomSig = name; 151 sc_trace (tf, t, name); 152 } 153 154 161 155 162 156 template <typename T> /*inline*/ 163 void 164 sc_trace( sc_trace_file* tf, const sc_signal<T>& signal, const std::string &name ) 165 { 166 signal2trace t; 167 t.inter = (const sc_interface*) &signal; 168 t.alias = alias(); 169 t.bit_size = get_bits_number(signal); 170 t.nomSig = name; 171 sc_trace (tf, t, name); 172 } 173 174 //---------------------------------------------------------------------------- 175 176 #define DEF_SC_TRACE(T) /*inline \*/ \ 177 extern void \ 178 sc_trace (sc_trace_file*, \ 179 const T& object, \ 180 const std::string&); 181 182 DEF_SC_TRACE(bool) 183 DEF_SC_TRACE(float) 184 DEF_SC_TRACE(double) 185 DEF_SC_TRACE(unsigned char) 186 DEF_SC_TRACE(unsigned short) 187 DEF_SC_TRACE(unsigned int) 188 DEF_SC_TRACE(unsigned long) 189 DEF_SC_TRACE(char) 190 DEF_SC_TRACE(short) 191 DEF_SC_TRACE(int) 192 DEF_SC_TRACE(long) 193 DEF_SC_TRACE(uint64) 194 DEF_SC_TRACE(int64) 195 157 void sc_trace( sc_trace_file * tf, const sc_signal< T > & signal, const std::string & name) { 158 signal2trace t; 159 t.inter = (const sc_interface *) &signal; 160 t.alias = alias(); 161 t.bit_size = get_bits_number(signal); 162 t.nomSig = name; 163 sc_trace (tf, t, name); 164 } 165 166 167 168 #define DEF_SC_TRACE(T) /*inline \*/ \ 169 extern void sc_trace (sc_trace_file *, \ 170 const T & object, \ 171 const std::string &); 172 173 DEF_SC_TRACE(bool) 174 DEF_SC_TRACE(float) 175 DEF_SC_TRACE(double) 176 DEF_SC_TRACE(unsigned char) 177 DEF_SC_TRACE(unsigned short) 178 DEF_SC_TRACE(unsigned int) 179 DEF_SC_TRACE(unsigned long) 180 DEF_SC_TRACE(char) 181 DEF_SC_TRACE(short) 182 DEF_SC_TRACE(int) 183 DEF_SC_TRACE(long) 184 DEF_SC_TRACE(uint64) 185 DEF_SC_TRACE(int64) 196 186 #undef DEF_SC_TRACE 197 187 198 188 } // end of sc_core namespace 199 189 200 //---------------------------------------------------------------------------- 190 201 191 #endif 202 192 193 /* 194 # Local Variables: 195 # tab-width: 4; 196 # c-basic-offset: 4; 197 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 198 # indent-tabs-mode: nil; 199 # End: 200 # 201 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 202 */ 203 -
sources/src/sc_uint.h
r27 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __SC_UINT_H__ 13 14 #define __SC_UINT_H__ … … 32 33 typedef sc_uint<1> sc_uint_bit_ref_r; 33 34 35 34 36 // -------------------------------- 35 37 // CLASS : sc_uint_subref_r 36 38 // 37 39 // Used for range, concat functions 38 class sc_uint_subref_r 39 { 40 template <int W> friend class sc_dt::sc_uint; 41 int left, right; 42 public : uint64 val; 43 sc_uint_subref_r (uint64 val_, int left_, int right_) 44 { 45 val = val_; left = left_; right = right_; 46 } 47 public: 48 inline uint64 read () const { return val; } 49 inline const sc_uint_subref_r& operator | (const sc_uint_subref_r &v) const 50 { print_warning (); return *this; } 51 52 private :void print_warning () const; 40 // -------------------------------- 41 42 class sc_uint_subref_r { 43 template <int W> friend class sc_dt::sc_uint; 44 int left, right; 45 public : 46 uint64 val; 47 sc_uint_subref_r(uint64 val_, int left_, int right_) { 48 val = val_; 49 left = left_; 50 right = right_; 51 } 52 53 public: 54 inline uint64 read() const { 55 return val; 56 } 57 58 inline const sc_uint_subref_r & operator | (const sc_uint_subref_r & v) const { 59 print_warning(); 60 return *this; 61 } 62 63 private: 64 void print_warning() const; 65 53 66 }; 54 67 55 // 56 #define MASK32(W) ((~ (const uint32)0) >> (sizeof (uint32) * 8 - W)) 57 #define MASK64(W) ((~ (const uint64)0) >> (sizeof (uint64) * 8 - W)) 58 // 59 60 template<int W> struct s_uint_type { typedef uint64 uint_type;}; 68 69 #define MASK32(W) ((~ (const uint32)0) >> (sizeof(uint32) * 8 - W)) 70 #define MASK64(W) ((~ (const uint64)0) >> (sizeof(uint64) * 8 - W)) 71 72 73 template<int W> struct s_uint_type { 74 typedef uint64 uint_type; 75 }; 76 61 77 #define DECLAR_UINT_TYPE(W) template<> struct s_uint_type<W> { typedef smallest_uint uint_type; }// not declared as uint16 because << operator threats like a character 62 DECLAR_UINT_TYPE( 63 DECLAR_UINT_TYPE( 64 DECLAR_UINT_TYPE( 65 DECLAR_UINT_TYPE( 66 DECLAR_UINT_TYPE( 67 DECLAR_UINT_TYPE( 68 DECLAR_UINT_TYPE( 69 DECLAR_UINT_TYPE( 78 DECLAR_UINT_TYPE(1); 79 DECLAR_UINT_TYPE(2); 80 DECLAR_UINT_TYPE(3); 81 DECLAR_UINT_TYPE(4); 82 DECLAR_UINT_TYPE(5); 83 DECLAR_UINT_TYPE(6); 84 DECLAR_UINT_TYPE(7); 85 DECLAR_UINT_TYPE(8); 70 86 #undef DECLAR_UINT_TYPE 87 71 88 #define DECLAR_UINT_TYPE(W) template<> struct s_uint_type<W> { typedef uint16 uint_type; } 72 DECLAR_UINT_TYPE( 89 DECLAR_UINT_TYPE(9); 73 90 DECLAR_UINT_TYPE(10); 74 91 DECLAR_UINT_TYPE(11); … … 79 96 DECLAR_UINT_TYPE(16); 80 97 #undef DECLAR_UINT_TYPE 98 81 99 #define DECLAR_UINT_TYPE(W) template<> struct s_uint_type<W> { typedef uint32 uint_type; } 82 100 DECLAR_UINT_TYPE(17); … … 98 116 #undef DECLAR_UINT_TYPE 99 117 118 100 119 class sc_uint_subref_r; 101 120 102 template<int W> /* width of data type = SC_INTWIDTH */ 103 class sc_uint 104 { 105 /***********************/ 106 /* SYSTEMCASS SPECIFIC */ 107 /***********************/ 108 typedef sc_uint<W> this_type; 109 typedef typename s_uint_type<W>::uint_type data_type; 110 111 typedef data_type sc_uint_subref; 112 //typedef data_type sc_uint_subref_r; 113 /* removed since "operator ," was going wrong */ 114 115 // internal 116 union { 117 val_field<W,(sizeof (data_type) * 8) - W,data_type> vf; /* To compute */ 118 data_type val; /* To return an int reference (read function) */ 119 // data_type valW:W; /* works with little endianess only */ 120 // bool valB[W]; /* removed since 1 bool takes 1 byte */ 121 }; 122 123 /***********************/ 124 /* L R M */ 125 /***********************/ 126 public: 127 sc_uint () { val = 0; } 128 // sc_uint (data_type val_) { val = 0; write (val_); } 129 sc_uint (const char *a) { val = 0; write (std::atoi (a)); } 130 sc_uint (unsigned short a){ val = 0; write (a); } 131 sc_uint (short a) { val = 0; write (a); } 132 sc_uint (unsigned long a) { val = 0; write (a); } 133 sc_uint (long a) { val = 0; write (a); } 134 sc_uint (unsigned int a) { val = 0; write (a); } 135 sc_uint (int a) { val = 0; write (a); } 136 sc_uint (int64 a) { val = 0; write (a); } 137 sc_uint (uint64 a) { val = 0; write (a); } 138 sc_uint (double a) { val = 0; write (a); } 139 140 template <int W2> sc_uint (const sc_uint<W2> &val_) { val = 0; write (val_.read());} 141 /* this template doesn't redefine default copy constructor of sc_uint. 142 * So, we define by this way 143 */ 144 sc_uint (const sc_uint &val_) { val = 0; write (val_.read()); } 145 sc_uint (const sc_uint_subref_r &val_) { val = 0; write (val_.read()); } 121 122 /* width of data type = SC_INTWIDTH */ 123 template<int W> 124 class sc_uint { 125 126 /***********************/ 127 /* SYSTEMCASS SPECIFIC */ 128 /***********************/ 129 typedef sc_uint<W> this_type; 130 typedef typename s_uint_type<W>::uint_type data_type; 131 typedef data_type sc_uint_subref; 132 //typedef data_type sc_uint_subref_r; /* removed since "operator ," was going wrong */ 133 134 135 // internal 136 union { 137 val_field<W, (sizeof(data_type) * 8) - W, data_type> vf; /* To compute */ 138 data_type val; /* To return an int reference (read function) */ 139 // data_type valW: W; /* works with little endianess only */ 140 // bool valB[W]; /* removed since 1 bool takes 1 byte */ 141 }; 142 143 /***********************/ 144 /* L R M */ 145 /***********************/ 146 public: 147 sc_uint() { val = 0; } 148 // sc_uint(data_type val_) { val = 0; write (val_); } 149 sc_uint(const char * a) { val = 0; write(std::atoi(a)); } 150 sc_uint(unsigned short a) { val = 0; write(a); } 151 sc_uint(short a) { val = 0; write(a); } 152 sc_uint(unsigned long a) { val = 0; write(a); } 153 sc_uint(long a) { val = 0; write(a); } 154 sc_uint(unsigned int a) { val = 0; write(a); } 155 sc_uint(int a) { val = 0; write(a); } 156 sc_uint(int64 a) { val = 0; write(a); } 157 sc_uint(uint64 a) { val = 0; write(a); } 158 sc_uint(double a) { val = 0; write(a); } 159 160 161 template <int W2> sc_uint(const sc_uint<W2> & val_) { 162 val = 0; 163 write(val_.read()); 164 } 165 166 /* this template doesn't redefine default copy constructor of sc_uint. 167 * So, we define by this way 168 */ 169 sc_uint(const sc_uint & val_) { val = 0; write(val_.read()); } 170 sc_uint(const sc_uint_subref_r & val_) { val = 0; write(val_.read()); } 146 171 /* the user needs to cast explicitly result of range () method. */ 147 172 148 /***********************/ 149 /* SYSTEMCASS SPECIFIC */ 150 /***********************/ 151 // read/write 152 inline const data_type& read() const { return val; } 153 inline void write(data_type val_) { vf.valW = val_; } 154 template <int W2> inline void write (const sc_uint<W2> val_) { write (val_.read()); } 155 //inline void write (const sc_uint<W> val_) { write (val_.read()); } 156 inline void write (const sc_uint_subref_r& s) { write (s.read()); } 157 158 /***********************/ 159 /* L R M */ 160 /***********************/ 161 // operators 162 inline operator const data_type& () const { return read (); } 163 // inline void write(uint64 val_) { val = val_ & MASK64(W); } 164 // inline void write(unsigned int val_) { val = val_ & MASK32(W); } 165 template <typename T> inline sc_uint& operator = (const T& val_) 166 { write (val_); return *this; } 167 inline sc_uint& operator = (const sc_uint_subref_r& a) 168 { write (a); return *this; } 169 170 // explicit conversions 171 inline uint32 to_uint () const {return val & MASK32(W);} 172 inline int32 to_int () const {return val & MASK32(W);} 173 inline uint64 to_uint64 () const {return val & MASK64(W);} 174 inline int64 to_int64 () const {return val & MASK64(W);} 175 176 // explicit conversion to character string 177 const sc_string to_string ( sc_numrep numrep = SC_DEC ) const 178 { return sc_dt::to_string (val, W, numrep); } 179 const sc_string to_dec() const { return to_string (SC_DEC); } 180 const sc_string to_bin() const { return to_string (SC_BIN); } 181 const sc_string to_oct() const { return to_string (SC_OCT); } 182 const sc_string to_hex() const { return to_string (SC_HEX); } 183 184 // arithmetic 185 #define DEFINE_OPERATOR(OPER) \ 186 template <typename T> \ 187 inline sc_uint& operator OPER (T v)\ 188 { vf.valW OPER v; return *this; } 189 190 DEFINE_OPERATOR(<<=) 191 DEFINE_OPERATOR(>>=) 192 DEFINE_OPERATOR(+=) 193 DEFINE_OPERATOR(-=) 194 DEFINE_OPERATOR(*=) 195 DEFINE_OPERATOR(/=) 196 DEFINE_OPERATOR(%=) 197 DEFINE_OPERATOR(&=) 198 DEFINE_OPERATOR(|=) 199 DEFINE_OPERATOR(^=) 173 /***********************/ 174 /* SYSTEMCASS SPECIFIC */ 175 /***********************/ 176 // read/write 177 inline const data_type & read() const { 178 return val; 179 } 180 181 inline void write(data_type val_) { 182 vf.valW = val_; 183 } 184 185 template <int W2> inline void write(const sc_uint<W2> val_) { 186 write(val_.read()); 187 } 188 189 // inline void write(const sc_uint<W> val_) { 190 // write(val_.read()); 191 // } 192 193 inline void write(const sc_uint_subref_r & s) { 194 write(s.read()); 195 } 196 197 198 /***********************/ 199 /* L R M */ 200 /***********************/ 201 // operators 202 inline operator const data_type & () const { 203 return read(); 204 } 205 206 // inline void write(uint64 val_) { 207 // val = val_ & MASK64(W); 208 // } 209 // inline void write(unsigned int val_) { 210 // val = val_ & MASK32(W); 211 // } 212 213 template < typename T > inline sc_uint & operator = (const T & val_) { 214 write(val_); 215 return *this; 216 } 217 218 inline sc_uint & operator = (const sc_uint_subref_r & a) { 219 write(a); 220 return *this; 221 } 222 223 // explicit conversions 224 inline uint32 to_uint() const { return val & MASK32(W); } 225 inline int32 to_int() const { return val & MASK32(W); } 226 inline uint64 to_uint64() const { return val & MASK64(W); } 227 inline int64 to_int64() const { return val & MASK64(W); } 228 229 // explicit conversion to character string 230 const sc_string to_string(sc_numrep numrep = SC_DEC) const { 231 return sc_dt::to_string(val, W, numrep); 232 } 233 const sc_string to_dec() const { return to_string(SC_DEC); } 234 const sc_string to_bin() const { return to_string(SC_BIN); } 235 const sc_string to_oct() const { return to_string(SC_OCT); } 236 const sc_string to_hex() const { return to_string(SC_HEX); } 237 238 239 // arithmetic 240 #define DEFINE_OPERATOR(OPER) \ 241 template < typename T > \ 242 inline sc_uint & operator OPER (T v) \ 243 { vf.valW OPER v; return *this; } 244 245 DEFINE_OPERATOR(<<=) 246 DEFINE_OPERATOR(>>=) 247 DEFINE_OPERATOR(+=) 248 DEFINE_OPERATOR(-=) 249 DEFINE_OPERATOR(*=) 250 DEFINE_OPERATOR(/=) 251 DEFINE_OPERATOR(%=) 252 DEFINE_OPERATOR(&=) 253 DEFINE_OPERATOR(|=) 254 DEFINE_OPERATOR(^=) 200 255 #undef DEFINE_OPERATOR 201 256 257 258 inline sc_uint_bit_ref operator [] (int v) { 259 return (vf.valW >> v) & 1; 260 } 261 262 inline sc_uint_bit_ref_r operator [] (int v) const { 263 return (vf.valW >> v) & 1; 264 } 265 266 template <int W2> 267 inline sc_uint<W + W2> operator , (const sc_uint<W2> & b) const { 268 sc_uint<W + W2> res = read() << W2; 269 res += b.read(); 270 return res; 271 } 272 273 inline sc_uint<W + 1> operator , (bool b) const { 274 sc_uint<W + 1> res = read(); 275 res <<= 1; 276 res += b; 277 return res; 278 } 279 280 template <int W2> 281 inline sc_uint<W2> operator , (const sc_uint_subref_r & v) const { 282 std::cerr << "Warning : \n"; // ?? 283 return sc_uint<W2> (v.read()); 284 } 285 286 inline sc_uint_subref range(int left, int right) { 287 return (data_type) ((data_type) (((data_type) ~(0)) >> (sizeof(data_type) * 8 - left - 1)) & val) >> right; 288 } 289 290 inline sc_uint_subref_r range(int left, int right) const { 291 return sc_uint_subref_r (((data_type) (((data_type) ~(0)) >> (sizeof(data_type) * 8 - left - 1)) & val) >> right, left, right); 292 } 293 202 294 #if 0 203 #define DEFINE_OPERATOR(OPER) \ 204 friend bool operator OPER (const data_type& a, const data_type& b); 205 // { return (a.valW) OPER (b.valW); } 206 207 DEFINE_OPERATOR(==) 208 DEFINE_OPERATOR(!=) 209 DEFINE_OPERATOR(>=) 210 DEFINE_OPERATOR(<=) 211 #undef DEFINE_OPERATOR 295 std::cerr << "range(" << left << "," << right << ")\n"; 296 std::cerr << "val = " << val << "\n"; 297 std::cerr << "~0 >> " << (sizeof (data_type) * 8 - left - 1) << " = " << (data_type) (((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) << "\n"; 298 std::cerr << ((data_type) ((((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) & val) >> right) << "\n"; 299 std::cerr << "data_type = " << sizeof (data_type) << "\n"; 212 300 #endif 213 inline sc_uint_bit_ref operator [] (int v) 214 { return (vf.valW >> v) & 1; } 215 inline sc_uint_bit_ref_r operator [] (int v) const 216 { return (vf.valW >> v) & 1; } 217 218 template <int W2> 219 inline sc_uint<W+W2> operator , (const sc_uint<W2> &b) const 220 { sc_uint<W+W2> res = read() << W2; res += b.read(); return res; } 221 #if 0 222 std::cerr << "[" << to_bin() << "," << b.to_bin() << " = " << res.to_bin() << "]\n"; 223 #endif 224 225 inline sc_uint<W+1> operator , (bool b) const 226 { sc_uint<W+1> res = read(); res <<= 1; res += b; return res; } 227 #if 0 228 std::cerr << "[" << to_bin() << "," << b.to_bin() << " = " << res.to_bin() << "]\n"; 229 #endif 230 231 template <int W2> 232 inline sc_uint<W2> operator , (const sc_uint_subref_r &v) const 233 { std::cerr << "Warning : \n"; return sc_uint<W2> (v.read()); } 234 235 inline sc_uint_subref range (int left, int right) 236 { return (data_type)((data_type) (((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) & val) >> right; } 237 238 inline sc_uint_subref_r range (int left, int right) const 239 { return sc_uint_subref_r (((data_type) (((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) & val) >> right, left, right); } 240 #if 0 241 std::cerr << "range(" << left << "," << right << ")\n"; 242 std::cerr << "val = " << val << "\n"; 243 std::cerr << "~0 >> " << (sizeof (data_type) * 8 - left - 1) << " = " << (data_type) (((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) << "\n"; 244 std::cerr << ((data_type) ((((data_type)~(0)) >> (sizeof (data_type) * 8 - left - 1)) & val) >> right) << "\n"; 245 std::cerr << "data_type = " << sizeof (data_type) << "\n"; 246 #endif 301 302 #undef MASK32 303 #undef MASK64 247 304 248 305 }; … … 250 307 // 251 308 // no sign flag to threat 252 // 253 254 inline std::ostream& operator << (std::ostream &o, const sc_uint_subref_r& s) 255 { return o << s.val; } 309 310 inline std::ostream & operator << (std::ostream & o, const sc_uint_subref_r & s) { 311 return o << s.val; 312 } 313 256 314 257 315 } /* end of sc_dt namespace */ … … 259 317 #endif /* __SC_UINT_H__ */ 260 318 319 /* 320 # Local Variables: 321 # tab-width: 4; 322 # c-basic-offset: 4; 323 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 324 # indent-tabs-mode: nil; 325 # End: 326 # 327 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 328 */ 329 -
sources/src/sc_uint_subref_r.cc
r27 r52 35 35 36 36 #include <iostream> 37 37 38 #include "sc_uint.h" 39 38 40 #ifdef HAVE_CONFIG_H 39 41 #include "config.h" … … 42 44 using namespace std; 43 45 44 void 45 sc_dt::sc_uint_subref_r::print_warning () const 46 { 47 cerr << "Warning :\n" 48 " SystemCASS need you to cast explicitly result of range() method.\n"; 49 cerr << " Result Type of range(" << left << "," << right << ")" 50 " shoud be sc_uint<" << left - right + 1 << "> in this case.\n"; 51 exit (23); 46 void sc_dt::sc_uint_subref_r::print_warning() const { 47 cerr << "Warning :\nSystemCASS needs you to cast explicitly the result of range() method.\n"; 48 cerr << " Result Type of range(" << left << "," << right << ")" 49 " shoud be sc_uint<" << left - right + 1 << "> in this case.\n"; 50 exit (23); 52 51 } 53 52 54 53 55 54 55 /* 56 # Local Variables: 57 # tab-width: 4; 58 # c-basic-offset: 4; 59 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 60 # indent-tabs-mode: nil; 61 # End: 62 # 63 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 64 */ 56 65 -
sources/src/sc_unit.h
r1 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __SC_UNIT_H__ 13 14 #define __SC_UNIT_H__ … … 25 26 26 27 #endif /* __SC_UNIT_H__ */ 28 29 /* 30 # Local Variables: 31 # tab-width: 4; 32 # c-basic-offset: 4; 33 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 34 # indent-tabs-mode: nil; 35 # End: 36 # 37 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 38 */ 39 -
sources/src/sc_unsigned.h
r27 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __SC_UNSIGNED_H__ 13 14 #define __SC_UNSIGNED_H__ 15 14 16 15 17 // ---------------------------------------------------------------------------- … … 28 30 29 31 #endif /* __SC_UNSIGNED_H__ */ 32 33 /* 34 # Local Variables: 35 # tab-width: 4; 36 # c-basic-offset: 4; 37 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 38 # indent-tabs-mode: nil; 39 # End: 40 # 41 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 42 */ 43 -
sources/src/sc_vcd_trace.cc
r33 r52 35 35 */ 36 36 37 #include <cstdio> 38 #include <cassert> 39 #include <ctime> 40 #include <string> 37 41 38 42 #include "sc_trace.h" … … 41 45 #include "internal.h" 42 46 43 #include <cstdio>44 #include <cassert>45 #include <ctime>46 #include <string>47 48 47 #ifdef HAVE_CONFIG_H 49 48 #include "config.h" 50 49 #endif 51 50 52 //-----------------------------------------*/53 51 54 52 using namespace std; … … 58 56 //-----------------------------------------*/ 59 57 60 sc_trace_file* 61 sc_create_vcd_trace_file(const char * name) 62 { 63 if (notrace) 64 return NULL; 65 assert(name != NULL); 66 string filename; 67 filename = name; 68 filename += ".vcd"; 69 //char varToday[1024];system(varToday=echo `date`); 70 71 //création d'1 instance de la structure Sc_trace_file: 72 sc_trace_file *traceFic=new sc_trace_file(); 73 traceFic->flag = VCD_FORMAT; 74 75 trace_file_list.push_back(traceFic); 76 77 //en-tête du fichier VCD: 78 char entete[]="$date\n\t%s\n$end\n\n$version\n\t%s\n$end\n\n$timescale\n\t1 ps\n$end\n\n$scope module SystemC $end\n"; 79 80 //ouverture du fichier nommé "*name": 81 traceFic->pfic=fopen(filename.c_str(),"w+");//on a un pointeur sur le fichier 82 if((traceFic->pfic)==NULL) 83 { 84 /* fopen renvoie NULL si erreur */ 85 fprintf(stderr,"\n\terreur ouverture outVcd\n"); 86 exit(15); 87 } 58 sc_trace_file * sc_create_vcd_trace_file(const char * name) { 59 if (notrace) { 60 return NULL; 61 } 62 assert(name != NULL); 63 string filename; 64 filename = name; 65 filename += ".vcd"; 88 66 89 char date[128]; 90 time_t timep = time (NULL); 91 const struct tm *tm = localtime (&timep); 92 strftime (date, 128, "%A %d %B %y %Z - %R:%S -", tm); 67 // Création d'une instance de la structure Sc_trace_file: 68 sc_trace_file * traceFic = new sc_trace_file(); 69 traceFic->flag = VCD_FORMAT; 93 70 94 //écriture de l'en-tête du format VCD: 95 if ((fprintf(traceFic->pfic,entete, date, sc_version ()))==0) 96 { 97 /* fprintf renvoie 0 si erreur */ 98 cerr << "\n\terreur ecriture de l'entete \n"; 99 exit(2); 100 } 101 102 //on retourne un pointeur sur la structure traceFile 103 //dont un des éléments pointe sur notre fichier VCD: 104 return traceFic; 71 trace_file_list.push_back(traceFic); 72 73 //en-tête du fichier VCD: 74 char entete[] = "$date\n\t%s\n$end\n\n$version\n\t%s\n$end\n\n$timescale\n\t1 ps\n$end\n\n$scope module SystemC $end\n"; 75 76 //ouverture du fichier nommé "*name": 77 traceFic->pfic = fopen(filename.c_str(), "w+");//on a un pointeur sur le fichier 78 if ((traceFic->pfic) == NULL) { 79 /* fopen renvoie NULL si erreur */ 80 fprintf(stderr, "\n\terreur ouverture outVcd\n"); 81 exit(15); 82 } 83 84 char date[128]; 85 time_t timep = time(NULL); 86 const struct tm * tm = localtime(&timep); 87 strftime(date, 128, "%A %d %B %y %Z - %R:%S -", tm); 88 89 //écriture de l'en-tête du format VCD: 90 if ((fprintf(traceFic->pfic, entete, date, sc_version())) == 0) { 91 /* fprintf renvoie 0 si erreur */ 92 cerr << "\n\terreur ecriture de l'entete \n"; 93 exit(2); 94 } 95 96 //on retourne un pointeur sur la structure traceFile 97 //dont un des éléments pointe sur notre fichier VCD: 98 return traceFic; 105 99 } 106 100 … … 108 102 //************************************************************************* 109 103 110 void 111 sc_close_vcd_trace_file( sc_trace_file* traceFic ) 112 { 113 if (notrace) 114 return; 115 if (!traceFic) 116 { 117 cerr << "Warning : Unable to close vcd trace file.\n"; 118 return; 119 } 104 void sc_close_vcd_trace_file(sc_trace_file * traceFic) { 105 if (notrace) { 106 return; 107 } 108 if (!traceFic) { 109 cerr << "Warning : Unable to close vcd trace file.\n"; 110 return; 111 } 120 112 121 if (cpt >= trace_start) 122 { 123 trace (*traceFic,false); 124 cpt++; 125 trace (*traceFic,true); 126 } 113 if (cpt >= trace_start) { 114 trace (*traceFic, false); 115 cpt++; 116 trace (*traceFic, true); 117 } 127 118 128 //fermeture fichier VCD 129 if (fclose(traceFic->pfic)) 130 { 131 /* fclose renvoie 0 si OK */ 132 perror("\n\tclosing VCD file."); 133 exit(4); 134 } 119 //fermeture fichier VCD 120 if (fclose(traceFic->pfic)) { 121 /* fclose renvoie 0 si OK */ 122 perror("\n\tclosing VCD file."); 123 exit(4); 124 } 135 125 136 137 126 //libération de l'instance de la structure en mémoire: 127 delete traceFic; 138 128 139 vector<sc_trace_file*>::iterator i; 140 for (i = trace_file_list.begin (); i != trace_file_list.end(); ++i) 141 if (*i == traceFic) { 142 trace_file_list.erase(i); 143 break; 144 } 129 vector<sc_trace_file *>::iterator i; 130 for (i = trace_file_list.begin(); i != trace_file_list.end(); ++i) { 131 if (*i == traceFic) { 132 trace_file_list.erase(i); 133 break; 134 } 135 } 136 } 145 137 146 }147 138 148 139 } // end of sc_core namespace 149 140 141 /* 142 # Local Variables: 143 # tab-width: 4; 144 # c-basic-offset: 4; 145 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 146 # indent-tabs-mode: nil; 147 # End: 148 # 149 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 150 */ 151 -
sources/src/sc_vcd_trace.h
r1 r52 11 11 | | 12 12 \------------------------------------------------------------*/ 13 13 14 #ifndef SC_VCD_TRACE_H 14 15 #define SC_VCD_TRACE_H … … 16 17 #include "sc_fwd.h" 17 18 18 // ----------------------------------------------------------------------------19 19 namespace sc_core { 20 20 21 21 // Create VCD file 22 extern sc_trace_file * sc_create_vcd_trace_file(const char* name);23 extern void sc_close_vcd_trace_file( sc_trace_file* tf);22 extern sc_trace_file * sc_create_vcd_trace_file(const char * name); 23 extern void sc_close_vcd_trace_file(sc_trace_file * tf); 24 24 25 25 } // end of sc_core namespace … … 29 29 30 30 #endif 31 32 /* 33 # Local Variables: 34 # tab-width: 4; 35 # c-basic-offset: 4; 36 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 37 # indent-tabs-mode: nil; 38 # End: 39 # 40 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 41 */ 42 -
sources/src/sc_ver.cc
r40 r52 35 35 */ 36 36 37 #include "sc_ver.h"38 37 #include <iostream> 39 38 #include <cstring> //strcmp 40 39 #include <cstdlib> //exit 40 41 #include "sc_ver.h" 41 42 42 43 #ifdef HAVE_CONFIG_H … … 44 45 #endif 45 46 47 46 48 namespace sc_core { 47 49 48 static 49 const char copyright[] =50 51 static const char copyright[] = 50 52 " Copyright (c) 2003-2009 by all Contributors\n" 51 53 " ALL RIGHTS RESERVED"; 52 54 53 static 54 const char systemc_version[] = 55 static const char systemc_version[] = 55 56 PACKAGE_STRING " --- Compilation date : " __DATE__ " " __TIME__; 56 57 57 static 58 const char splash_screen[] = 59 " ____ _ ____ _ ____ ____ \n" 60 "/ ___| _ _ ___| |_ ___ _ __ ___ / ___| / \\ / ___/ ___| \n" 61 "\\___ \\| | | / __| __/ _ \\ '_ ` _ \\| | / _ \\ \\___ \\___ \\ \n" 62 " ___) | |_| \\__ \\ || __/ | | | | | |___ / ___ \\ ___) |__) |\n" 63 "|____/ \\__, |___/\\__\\___|_| |_| |_|\\____/_/ \\_\\____/____/ \n" 64 " |___/ \n" 65 "\n" 66 " Cycle Accurate System Simulator\n" 58 static const char splash_screen[] = 59 " ____ _ ____ _ ____ ____ \n" 60 "/ ___| _ _ ___| |_ ___ _ __ ___ / ___| / \\ / ___/ ___| \n" 61 "\\___ \\| | | / __| __/ _ \\ '_ ` _ \\| | / _ \\ \\___ \\___ \\ \n" 62 " ___) | |_| \\__ \\ || __/ | | | | | |___ / ___ \\ ___) |__) |\n" 63 "|____/ \\__, |___/\\__\\___|_| |_| |_|\\____/_/ \\_\\____/____/ \n" 64 " |___/ \n" 65 "\n" 66 " Cycle Accurate System Simulator\n" 67 67 #ifdef CONFIG_DEBUG 68 " DEBUG version\n"68 " DEBUG version\n" 69 69 #endif 70 70 #ifdef USE_PORT_DEPENDENCY 71 " using explicit port dependancy\n"71 " using explicit port dependancy\n" 72 72 #endif 73 74 75 76 " Paul-Jerome Kingbo, Frederic Pétrot,\n"77 " Nicolas Pouillon\n"78 79 80 73 " ASIM/LIP6/UPMC\n" 74 " E-mail support: Richard.Buchmann@asim.lip6.fr\n" 75 " Contributors : Richard Buchmann, Sami Taktak,\n" 76 " Paul-Jerome Kingbo, Frederic Pétrot,\n" 77 " Nicolas Pouillon\n" 78 "\n" 79 " Last change : " __DATE__ "\n" 80 "\n"; 81 81 82 const char* 83 sc_copyright() 84 { 82 83 const char * sc_copyright() { 85 84 return copyright; 86 85 } 87 86 88 const char* 89 sc_version() 90 { 87 88 const char * sc_version() { 91 89 return systemc_version; 92 90 } 93 91 94 const char* 95 get_splash_screen() 96 { 92 93 const char * get_splash_screen() { 97 94 return splash_screen; 98 95 } 99 96 97 100 98 } // end of sc_core namespace 101 99 102 bool 103 casc_check_version (const char *runtime_ver) 104 { 105 const char *lib_version = SYSTEMC_VERSION; 106 bool right_version = strcmp (runtime_ver, lib_version) == 0; 107 if (right_version == false) 108 { 109 std::cerr << "Current SystemCASS library version doesn't match.\n"; 110 std::cerr << "SystemCASS linked library is : " << lib_version << "\n"; 111 std::cerr << "SystemCASS environnement variable points to : " << runtime_ver << "\n"; 112 exit(125); 113 } 114 115 return true; 100 101 bool casc_check_version(const char * runtime_ver) { 102 const char * lib_version = SYSTEMC_VERSION; 103 bool right_version = strcmp(runtime_ver, lib_version) == 0; 104 if (right_version == false) { 105 std::cerr << "Current SystemCASS library version doesn't match.\n"; 106 std::cerr << "SystemCASS linked library is : " << lib_version << "\n"; 107 std::cerr << "SystemCASS environnement variable points to : " << runtime_ver << "\n"; 108 exit(125); 109 } 110 111 return true; 116 112 } 117 113 114 115 /* 116 # Local Variables: 117 # tab-width: 4; 118 # c-basic-offset: 4; 119 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 120 # indent-tabs-mode: nil; 121 # End: 122 # 123 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 124 */ 125 -
sources/src/sc_ver.h
r1 r52 11 11 | | 12 12 \------------------------------------------------------------*/ 13 13 14 #ifndef SC_VER_H 14 15 #define SC_VER_H … … 16 17 #include "sc_ver_ext.h" 17 18 19 18 20 namespace sc_core { 19 21 20 extern const char * get_splash_screen();22 extern const char * get_splash_screen(); 21 23 22 24 } // end of sc_core 23 25 24 26 #endif 27 28 /* 29 # Local Variables: 30 # tab-width: 4; 31 # c-basic-offset: 4; 32 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 33 # indent-tabs-mode: nil; 34 # End: 35 # 36 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 37 */ 38 -
sources/src/sc_ver_ext.h
r1 r52 42 42 #include "systemcass_version_ext.h" 43 43 44 44 45 namespace sc_core { 45 46 46 extern const char * sc_copyright();47 extern const char * sc_version();47 extern const char * sc_copyright(); 48 extern const char * sc_version(); 48 49 49 50 } // end of sc_core … … 54 55 #endif 55 56 57 /* 58 # Local Variables: 59 # tab-width: 4; 60 # c-basic-offset: 4; 61 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 62 # indent-tabs-mode: nil; 63 # End: 64 # 65 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 66 */ 67 -
sources/src/schedulers.cc
r38 r52 35 35 */ 36 36 37 #include <cstdio> 38 #include <cassert> 39 #include <iostream> 40 #include <algorithm> //std::sort 41 37 42 #include "sc_module.h" // method_process_t 38 43 #include "gen_code.h" // gen_scheduling_code_for_dynamic_link & gen_scheduling_code_for_static_func … … 43 48 #include "mouchard_scheduling.h" // MakeMouchardScheduling 44 49 #include "graph_signals.h" // makegraph 45 //#include "module_hierarchy2dot.h"46 47 #include <cstdio>48 #include <cassert>49 #include <iostream>50 #include <algorithm> //std::sort51 50 52 51 #ifdef HAVE_CONFIG_H … … 63 62 64 63 template <typename T> 65 ostream& operator << (ostream &o, const vector<T*> &v) 66 { 67 typename vector<T*>::const_iterator i; 68 for (i = v.begin(); i != v.end(); ++i) { 69 o << **i << " "; 70 } 71 return o; 64 ostream & operator << (ostream & o, const vector<T*> & v) { 65 typename vector<T *>::const_iterator i; 66 for (i = v.begin(); i != v.end(); ++i) { 67 o << **i << " "; 68 } 69 return o; 72 70 } 73 71 … … 76 74 /****************/ 77 75 78 //79 76 // sort_functions splits and sorts instances_list into three functions lists : 80 77 method_process_list_t transition_func_list; … … 82 79 method_process_list_t combinational_func_list; 83 80 84 #if 0 85 static 86 bool 87 isCostly (const char *n) 88 { 89 const char *costly[] = {/*"vgmn", */"mips", "cache", NULL}; 90 int i = 0; 91 do { 92 if (strstr (n, costly[i]) != NULL) 93 return true; 94 } while (costly[++i] != NULL); 95 return false; 96 } 97 98 static 99 bool 100 only_sort_by_module_ptr (const method_process_t *a1, 101 const method_process_t *a2) 102 { 103 assert(a1 != NULL); 104 assert(a2 != NULL); 105 sc_module *m1 = a1->module; 106 sc_module *m2 = a2->module; 107 const char* n1 = m1->basename (); 108 const char* n2 = m2->basename (); 109 bool h1 = isCostly (n1); 110 bool h2 = isCostly (n2); 111 if ((h1 ^ h2) == true) 112 return h1 > h2; 113 if (a1->module == a2->module) 114 { 115 union { 116 SC_ENTRY_FUNC func; 117 unsigned long addr_l; 118 unsigned long long addr_ll; 119 } addr1, addr2; 120 addr1.func = a1->func; 121 addr2.func = a2->func; 122 assert(addr1.addr_ll != addr2.addr_ll); 123 if ( sizeof(SC_ENTRY_FUNC) == 4 ) { 124 return (addr1.addr_l < addr2.addr_l); 125 } else { 126 return (addr1.addr_ll < addr2.addr_ll); 127 } 128 } 129 return (a1->module < a2->module); 130 } 131 #endif 132 #if 1 133 static 134 bool 135 sort_by_module_ptr (const method_process_t *a1, 136 const method_process_t *a2) 137 { 138 assert(a1 != NULL); 139 assert(a2 != NULL); 140 return (a1->module < a2->module); 141 } 142 143 static 144 bool 145 sort_by_fct_ptr (const method_process_t *a1, 146 const method_process_t *a2) 147 { 81 82 static bool sort_by_module_ptr (const method_process_t * a1, const method_process_t * a2) { 83 assert(a1 != NULL); 84 assert(a2 != NULL); 85 return (a1->module < a2->module); 86 } 87 88 89 static bool sort_by_fct_ptr (const method_process_t * a1, const method_process_t * a2) { 148 90 assert(a1 != NULL); 149 91 assert(a2 != NULL); … … 153 95 unsigned long long addr_ll; 154 96 } addr1, addr2; 97 155 98 addr1.func = a1->func; 156 99 addr2.func = a2->func; 157 if (a1->func == a2->func) 158 return sort_by_module_ptr (a1,a2); 159 if ( sizeof(SC_ENTRY_FUNC) == 4 ) { 100 101 if (a1->func == a2->func) { 102 return sort_by_module_ptr(a1,a2); 103 } 104 105 if (sizeof(SC_ENTRY_FUNC) == 4 ) { 160 106 return (addr1.addr_l < addr2.addr_l); 161 } else { 107 } 108 else { 162 109 return (addr1.addr_ll < addr2.addr_ll); 163 110 } 164 111 } 165 #endif 166 void 167 sort_functions () 168 { 169 #if 0 170 cerr << method_process_list << endl; 171 #endif 172 method_process_list_t::const_iterator m; 173 for (m = method_process_list.begin(); m != method_process_list.end(); ++m) { 174 if ((*m)->is_combinational()) combinational_func_list.push_back(*m); 175 else if ((*m)->is_transition ()) transition_func_list.push_back(*m); 176 else if ((*m)->is_genmoore ()) moore_func_list.push_back(*m); 177 } 178 #if 1 179 // Sort transition functions by method pointer (1) and by module pointer (2) 180 std::sort (transition_func_list.begin(), transition_func_list.end(), sort_by_fct_ptr); 181 // Sort generation functions by method pointer (1) and by module pointer (2) 182 std::sort (moore_func_list.begin(), moore_func_list.end(), sort_by_fct_ptr); 183 #endif 184 #if 0 185 std::sort (transition_func_list.begin(), transition_func_list.end(), only_sort_by_module_ptr); 186 std::sort (moore_func_list.begin(), moore_func_list.end(), only_sort_by_module_ptr); 187 #endif 112 113 114 115 void sort_functions() { 116 method_process_list_t::const_iterator m; 117 for (m = method_process_list.begin(); m != method_process_list.end(); ++m) { 118 if ((*m)->is_combinational()) { 119 combinational_func_list.push_back(*m); 120 } 121 else if ((*m)->is_transition ()) { 122 transition_func_list.push_back(*m); 123 } 124 else if ((*m)->is_genmoore ()) { 125 moore_func_list.push_back(*m); 126 } 127 } 128 // Sort transition functions by method pointer (1) and by module pointer (2) 129 std::sort (transition_func_list.begin(), transition_func_list.end(), sort_by_fct_ptr); 130 // Sort generation functions by method pointer (1) and by module pointer (2) 131 std::sort (moore_func_list.begin(), moore_func_list.end(), sort_by_fct_ptr); 188 132 } 189 133 … … 192 136 /* ****************** */ 193 137 194 static 195 SignalDependencyGraph* 196 MakeAcyclicSignalDependencyGraph () 197 { 198 if (dump_all_graph) { 199 const PortDependencyGraph &port_graph = get_port_dependency_graph (); 200 PortDependencyGraph2dot ("port_graph", port_graph); 201 } 202 203 SignalDependencyGraph* sig_graph = MakeSignalDependencyGraph (); 204 205 if (dump_all_graph) 206 SignalDependencyGraph2dot ("signal_graph",*sig_graph); 207 208 if (!Check (*sig_graph)) 209 { 210 cerr << "The signal dependency graph is not valid.\n"; 211 exit (29092004); 212 } 213 214 #if 1 215 if (!Check (method_process_list,*sig_graph)) 216 { 217 cerr << "Sensitivity list is not valid.\n"; 218 exit (30092004); 219 } 220 #endif 221 222 // There is a cycle in the signal dependency graph ? 223 Graph *sig_knuth = makegraph (*sig_graph); 224 strong_component_list_t *s = strong_component(sig_knuth); 225 226 if (dump_all_graph) 227 SignalDependencyOrder2txt ("signal_order",*s); 228 229 if (has_cycle (*s)) 230 { 231 cerr << "Error : There is a cycle in the signal dependency graph.\n"; 232 #if 0 233 print_cycle (cerr, get_cycle (*s)); 234 #endif 235 exit (24092004); 236 } 237 return sig_graph; 238 } 239 240 static 241 ProcessDependencyList* 242 MouchardScheduling () 243 { 244 SignalDependencyGraph *sig_graph = MakeAcyclicSignalDependencyGraph (); 245 assert(sig_graph != NULL); 246 // Create the process evaluation list 247 ProcessDependencyList* process_list = MakeMouchardScheduling (*sig_graph); 248 assert(process_list != NULL); 249 250 if (dump_all_graph) 251 ProcessDependencyList2dot ("process_order",*process_list); 252 253 return process_list; 254 } 255 256 static 257 ProcessDependencyList* 258 BuchmannScheduling () 259 { 260 SignalDependencyGraph *sig_graph = MakeAcyclicSignalDependencyGraph (); 261 // Create the process evaluation list 262 ProcessDependencyList* process_list = MakeProcessDependencyList (*sig_graph); 263 264 if (dump_all_graph) 265 ProcessDependencyList2dot ("process_order",*process_list); 266 267 return process_list; 268 } 269 270 string 271 get_scheduling (int scheduling_method) 272 { 273 /* marque les fonctions comme fonction de mealy ou non */ 274 if (dump_funclist_info) 275 cerr << "method process list : " << method_process_list << "\n"; 276 sort_functions (); 277 if (dump_funclist_info) 278 { 279 cerr << "Transition functions : " << transition_func_list << "\n"; 280 cerr << "Moore generation functions : " << moore_func_list << "\n"; 281 cerr << "Mealy generation functions : " << combinational_func_list << "\n"; 282 } 283 284 /* Schedule */ 285 string base_name; 286 switch (scheduling_method) { 287 case BUCHMANN_SCHEDULING : { 288 // Generate the scheduled code, compile and link. 289 // Buchmann's thesis explains this scheduling method. 290 // Uses port dependancies like Dr. Mouchard. 291 ProcessDependencyList* process_list = BuchmannScheduling (); 292 if (dynamic_link_of_scheduling_code) 293 base_name = gen_scheduling_code_for_dynamic_link (transition_func_list, moore_func_list,*process_list); 294 else 295 gen_scheduling_code_for_static_func (transition_func_list, moore_func_list, *process_list); 296 break; 297 } 298 case MOUCHARD_SCHEDULING : { 299 // Generate the scheduled code, compile and link. 300 // Mouchard's thesis explains this scheduling method. 301 // Uses port dependancies like Dr. Mouchard. 302 // CAUTION : unlike FastSysC, this scheduling is totally static 303 // and does not use an event-driven scheduler. 304 ProcessDependencyList* process_list = MouchardScheduling (); 305 if (dynamic_link_of_scheduling_code) 306 base_name = gen_scheduling_code_for_dynamic_link(transition_func_list, moore_func_list,*process_list); 307 else 308 gen_scheduling_code_for_static_func (transition_func_list, moore_func_list, *process_list); 309 break; 310 } 311 case CASS_SCHEDULING : { 312 // Generate the scheduled code, compile and link 313 // Hommais's thesis explains this scheduling method (like CASS strategy) 314 // Doesn't use port dependancies 315 Graph *g = makegraph (&combinational_func_list); 316 if (dump_all_graph && g) 317 graph2dot("module_graph", *g); 318 strong_component_list_t *strong_list = strong_component (g); 319 if (dynamic_link_of_scheduling_code) 320 base_name = gen_scheduling_code_for_dynamic_link(transition_func_list, moore_func_list,*strong_list); 321 else 322 gen_scheduling_code_for_quasistatic_func (transition_func_list, moore_func_list, *strong_list); 323 break; 324 } 325 default : 326 cerr << "Error : Unable to schedule SystemC process." 327 "Please select a scheduling method.\n"; 328 exit (35); 329 } 330 return base_name; 331 } 332 333 bool 334 run_schedule_editor (const char *schedule) 335 { 336 char buf[128]; 337 const char *editor = getenv ("EDITOR"); 338 if (editor == NULL) 339 editor = "vim"; 340 sprintf (buf, "(cd '%s' ; %s '%s')", temporary_dir, editor, schedule); 341 if (dump_stage) 342 cerr << "Executing : " << buf << endl; 343 return (system(buf) == 0); 344 } 345 346 ///////////////////////// 138 static SignalDependencyGraph * MakeAcyclicSignalDependencyGraph() { 139 if (dump_all_graph) { 140 const PortDependencyGraph & port_graph = get_port_dependency_graph (); 141 PortDependencyGraph2dot ("port_graph", port_graph); 142 } 143 144 SignalDependencyGraph * sig_graph = MakeSignalDependencyGraph(); 145 146 if (dump_all_graph) { 147 SignalDependencyGraph2dot ("signal_graph",*sig_graph); 148 } 149 150 if (!Check(*sig_graph)) { 151 cerr << "The signal dependency graph is not valid.\n"; 152 exit (29092004); 153 } 154 155 if (!Check(method_process_list, *sig_graph)) { 156 cerr << "Sensitivity list is not valid.\n"; 157 exit (30092004); 158 } 159 160 // There is a cycle in the signal dependency graph ? 161 Graph * sig_knuth = makegraph(*sig_graph); 162 strong_component_list_t * s = strong_component(sig_knuth); 163 164 if (dump_all_graph) { 165 SignalDependencyOrder2txt("signal_order",*s); 166 } 167 168 if (has_cycle(*s)) { 169 cerr << "Error : There is a cycle in the signal dependency graph.\n"; 170 exit (24092004); 171 } 172 return sig_graph; 173 } 174 175 176 static ProcessDependencyList * MouchardScheduling() { 177 SignalDependencyGraph * sig_graph = MakeAcyclicSignalDependencyGraph(); 178 assert(sig_graph != NULL); 179 // Create the process evaluation list 180 ProcessDependencyList * process_list = MakeMouchardScheduling(*sig_graph); 181 assert(process_list != NULL); 182 183 if (dump_all_graph) { 184 ProcessDependencyList2dot ("process_order", *process_list); 185 } 186 187 return process_list; 188 } 189 190 191 static ProcessDependencyList * BuchmannScheduling() { 192 SignalDependencyGraph * sig_graph = MakeAcyclicSignalDependencyGraph(); 193 // Create the process evaluation list 194 ProcessDependencyList * process_list = MakeProcessDependencyList(*sig_graph); 195 196 if (dump_all_graph) { 197 ProcessDependencyList2dot("process_order", *process_list); 198 } 199 200 return process_list; 201 } 202 203 204 string get_scheduling(int scheduling_method) { 205 /* marque les fonctions comme fonction de mealy ou non */ 206 if (dump_funclist_info) { 207 cerr << "method process list : " << method_process_list << "\n"; 208 } 209 210 sort_functions(); 211 if (dump_funclist_info) { 212 cerr << "Transition functions : " << transition_func_list << "\n"; 213 cerr << "Moore generation functions : " << moore_func_list << "\n"; 214 cerr << "Mealy generation functions : " << combinational_func_list << "\n"; 215 } 216 217 /* Schedule */ 218 string base_name; 219 switch (scheduling_method) { 220 case BUCHMANN_SCHEDULING : 221 { 222 // Generate the scheduled code, compile and link. 223 // Buchmann's thesis explains this scheduling method. 224 // Uses port dependancies like Dr. Mouchard. 225 ProcessDependencyList * process_list = BuchmannScheduling(); 226 if (dynamic_link_of_scheduling_code) { 227 base_name = gen_scheduling_code_for_dynamic_link(transition_func_list, moore_func_list, *process_list); 228 } 229 else { 230 gen_scheduling_code_for_static_func(transition_func_list, moore_func_list, *process_list); 231 } 232 break; 233 } 234 235 case MOUCHARD_SCHEDULING : 236 { 237 // Generate the scheduled code, compile and link. 238 // Mouchard's thesis explains this scheduling method. 239 // Uses port dependancies like Dr. Mouchard. 240 // CAUTION : unlike FastSysC, this scheduling is totally static 241 // and does not use an event-driven scheduler. 242 ProcessDependencyList * process_list = MouchardScheduling(); 243 if (dynamic_link_of_scheduling_code) { 244 base_name = gen_scheduling_code_for_dynamic_link(transition_func_list, moore_func_list, *process_list); 245 } 246 else { 247 gen_scheduling_code_for_static_func (transition_func_list, moore_func_list, *process_list); 248 } 249 break; 250 } 251 252 case CASS_SCHEDULING : 253 { 254 // Generate the scheduled code, compile and link 255 // Hommais's thesis explains this scheduling method (like CASS strategy) 256 // Doesn't use port dependancies 257 Graph * g = makegraph (&combinational_func_list); 258 if (dump_all_graph && g) { 259 graph2dot("module_graph", *g); 260 } 261 strong_component_list_t * strong_list = strong_component(g); 262 if (dynamic_link_of_scheduling_code) { 263 base_name = gen_scheduling_code_for_dynamic_link(transition_func_list, moore_func_list, *strong_list); 264 } 265 else { 266 gen_scheduling_code_for_quasistatic_func (transition_func_list, moore_func_list, *strong_list); 267 } 268 break; 269 } 270 default : 271 cerr << "Error : Unable to schedule SystemC process." 272 "Please select a scheduling method.\n"; 273 exit (35); 274 } 275 return base_name; 276 } 277 278 279 bool run_schedule_editor (const char * schedule) { 280 char buf[128]; 281 const char * editor = getenv("EDITOR"); 282 if (editor == NULL) { 283 editor = "vim"; 284 } 285 sprintf (buf, "(cd '%s' ; %s '%s')", temporary_dir, editor, schedule); 286 if (dump_stage) { 287 cerr << "Executing : " << buf << endl; 288 } 289 return (system(buf) == 0); 290 } 291 347 292 348 293 } // end of sc_core namespace 349 294 295 /* 296 # Local Variables: 297 # tab-width: 4; 298 # c-basic-offset: 4; 299 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 300 # indent-tabs-mode: nil; 301 # End: 302 # 303 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 304 */ 305 -
sources/src/schedulers.h
r27 r52 20 20 ///////////////////////// 21 21 ///// SYSTEMCASS_SPECIFIC 22 extern const char * temporary_dir;23 extern const char * generated_files_dir;24 extern std::string get_scheduling 25 extern bool run_schedule_editor (const char* scheduling);22 extern const char * temporary_dir; 23 extern const char * generated_files_dir; 24 extern std::string get_scheduling(int scheduling_method); 25 extern bool run_schedule_editor(const char * scheduling); 26 26 27 27 ///////////////////////// … … 31 31 #endif 32 32 33 /* 34 # Local Variables: 35 # tab-width: 4; 36 # c-basic-offset: 4; 37 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 38 # indent-tabs-mode: nil; 39 # End: 40 # 41 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 42 */ 43 -
sources/src/serialization.cc
r42 r52 34 34 */ 35 35 36 #include <cassert> 37 #include <map> 38 #include <fstream> 36 39 37 40 #include "internal_ext.h" // tab_t … … 42 45 #include "hex2string.h" 43 46 44 #include <cassert>45 #include <map>46 #include <fstream>47 //#include <vector> // save_module_hierarchy48 49 47 #ifdef HAVE_CONFIG_H 50 48 #include "config.h" … … 54 52 using namespace sc_core; 55 53 54 56 55 namespace sc_core { 57 56 58 #if 0 59 static 60 void 61 save_module_hierarchy (ostream &o, 62 sc_object *obj) 63 { 64 const std::vector<sc_object*> &children = obj->get_child_objects(); 65 for (unsigned i = 0; i < children.size(); i++) 66 { 67 if (children[i]) 68 save_module_hierarchy (o,children[i]); 69 }; 70 // if (obj->kind () != sc_module::kind_string) 71 // o << obj->name () << " " << obj->kind() << endl; 57 58 static void dec2string(char * buf, const tab_t * val, int bit_number) { 59 assert(bit_number <= 64); 60 if (bit_number == 1) { 61 bool v = *((const bool *) val); 62 sprintf(buf, "%d", (v) ? 1 : 0); 63 } 64 else if (bit_number <= 8) { 65 uint8 v = *((const uint8 *) val); 66 int v2 = v; 67 sprintf(buf, "%d", v2); 68 } 69 else if (bit_number <= 16) { 70 uint16 v = *((const uint16 *) val); 71 sprintf(buf, "%u", (uint32) v); 72 } 73 else if (bit_number <= 32) { 74 uint32 v = *((const uint32 *) val); 75 sprintf(buf, "%u", v); 76 } 77 else if (bit_number <= 64) { 78 uint64 v = *((const uint64 *) val); 79 sprintf(buf, "%llu", v); 80 } 72 81 } 73 82 74 static75 void76 save_module_hierarchy (ostream &o,77 const std::vector<sc_object*> &obj_list)78 {79 for (signed int i = obj_list.size(); i >= 0; i--)80 save_module_hierarchy(o, obj_list[i]);81 }82 #endif83 83 84 static 85 void 86 dec2string (char *buf, 87 const tab_t *val, 88 int bit_number) 89 { 90 assert(bit_number <= 64); 91 if (bit_number == 1) { 92 bool v = *((const bool*) val); 93 sprintf (buf, "%d", (v)?1:0); 94 } else if (bit_number <= 8) { 95 uint8 v = *((const uint8*)val); 96 int v2 = v; 97 sprintf (buf, "%d", v2); 98 } else if (bit_number <= 16) { 99 uint16 v = *((const uint16*)val); 100 sprintf (buf, "%u", (uint32) v); 101 } else if (bit_number <= 32) { 102 uint32 v = *((const uint32*)val); 103 sprintf (buf, "%u", v); 104 } else if (bit_number <= 64) { 105 uint64 v = *((const uint64*)val); 106 sprintf (buf, "%llu", v); 107 } 84 static void save_signal_table(ostream & o, int hex = true) { 85 const equi_list_t &eq_l = get_equi_list(); 86 equi_list_t::const_iterator it; 87 for (it = eq_l.begin(); it != eq_l.end(); ++it) { 88 const equi_t & eq = *it; 89 equi_t::const_iterator it2 = eq.begin(); 90 const entity & en = *it2; 91 const sc_interface * f = en.interface; 92 o << dec << get_name(eq) << endl; 93 char buf[128]; 94 if (hex) { 95 buf[0] = '0'; 96 buf[1] = 'x'; 97 hex2string(buf + 2, f->get_pointer(), f->data_size_in_bytes() << 3); 98 } 99 else { 100 dec2string(buf, f->get_pointer(), f->data_size_in_bytes() << 3); 101 } 102 o << buf; 103 o << endl; 104 } 108 105 } 109 106 110 static 111 void 112 save_signal_table (std::ostream &o, 113 int hex = true) 114 { 115 const equi_list_t &eq_l = get_equi_list (); 116 equi_list_t::const_iterator it; 117 for (it = eq_l.begin (); it != eq_l.end (); ++it) 118 { 119 const equi_t &eq = *it; 120 equi_t::const_iterator it2 = eq.begin(); 121 const entity &en = *it2; 122 const sc_interface *f = en.interface; 123 o << dec << get_name (eq) << endl; 124 // print_value (o, *f); 125 char buf[128]; 126 if (hex) 127 { 128 buf[0] = '0'; 129 buf[1] = 'x'; 130 hex2string (buf+2, f->get_pointer (), f->data_size_in_bytes() << 3); 131 } else { 132 dec2string (buf, f->get_pointer (), f->data_size_in_bytes() << 3); 133 } 134 o << buf; 135 o << endl; 136 } 107 108 typedef map<const sc_module *, save_fct_t1> sc_module2save_fct_t1; 109 110 sc_module2save_fct_t1 save_handler_table; 111 112 void set_save_handler(const sc_module & mod, save_fct_t1 fct) { 113 save_handler_table[&mod] = fct; 137 114 } 138 115 139 typedef std::map<const sc_module *, save_fct_t1> sc_module2save_fct_t1;140 sc_module2save_fct_t1 save_handler_table;141 116 142 void 143 set_save_handler (const sc_module &mod, 144 save_fct_t1 fct) 145 { 146 //assert(fct != NULL); 147 //sc_module2save_fct_t1::value_type pair(&mod,fct); 148 //save_handler_table.insert (pair); 149 save_handler_table[&mod] = fct; 117 static void save_modules(FILE * o) { 118 sc_module2save_fct_t1::const_iterator it; 119 for (it = save_handler_table.begin(); it != save_handler_table.end(); ++it) { 120 const sc_module * mod = it->first; 121 save_fct_t1 fct = it->second; 122 assert(mod != NULL); 123 fprintf(o, "module\n%s\n", mod->name()); 124 if (fct != NULL) { 125 (((sc_module *) mod)->*fct)(o); 126 } 127 } 150 128 } 151 129 152 static 153 void 154 //save_modules (ostream &o) 155 save_modules (FILE *o) 156 { 157 sc_module2save_fct_t1::const_iterator it; 158 for (it = save_handler_table.begin(); 159 it != save_handler_table.end(); 160 ++it) 161 { 162 const sc_module *mod = it->first; 163 save_fct_t1 fct = it->second; 164 assert(mod != NULL); 165 // assert(fct != NULL); 166 //o << mod->name () << endl; 167 fprintf (o,"module\n%s\n",mod->name ()); 168 if (fct != NULL) 169 (((sc_module*)mod)->*fct) (o); 170 } 130 131 void sc_save_simulation(const char * filename) { 132 update(); 133 if (dump_stage) { 134 cerr << "Saving simulation into \"" << filename << "\"... "; 135 } 136 137 ofstream file; 138 file.open(filename); 139 file << "CABA Save!" << endl; 140 file << (sc_time_stamp() / 1000) << endl; 141 file << sc_time_stamp().to_string() << endl; 142 save_signal_table(file, true); 143 file.close(); 144 FILE * f = fopen(filename, "a+"); 145 assert(f != NULL); 146 save_modules(f); 147 fclose(f); 148 149 if (dump_stage) { 150 cerr << "done.\n"; 151 } 171 152 } 172 153 173 void174 sc_save_simulation (const char *filename)175 {176 update ();177 if (dump_stage)178 cerr << "Saving simulation into \"" << filename << "\"... ";179 180 ofstream file;181 file.open (filename);182 file << "CABA Save!" << endl;183 file << (sc_time_stamp () / 1000) << endl;184 file << sc_time_stamp ().to_string () << endl;185 //save_module_hierarchy (file,sc_get_top_level_objects ());186 save_signal_table (file, true);187 //save_modules (file);188 //file.close ();189 file.close ();190 FILE *f = fopen (filename, "a+");191 assert(f != NULL);192 save_modules (f);193 fclose (f);194 195 if (dump_stage)196 cerr << "done.\n";197 }198 154 199 155 } // end of sc_core namespace 200 156 201 157 158 /* 159 # Local Variables: 160 # tab-width: 4; 161 # c-basic-offset: 4; 162 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 163 # indent-tabs-mode: nil; 164 # End: 165 # 166 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 167 */ 168 -
sources/src/serialization.h
r27 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __SERIALIZATION_H__ 13 14 #define __SERIALIZATION_H__ … … 17 18 18 19 namespace sc_core { 19 ///////////////////////// 20 20 21 // SYSTEMCASS SPECIFIC // 21 22 extern void set_save_handler (const sc_module &, save_fct_t1); 22 extern void set_save_handler(const sc_module &, save_fct_t1); 23 23 24 24 } // end of sc_core namespace … … 26 26 #endif // __SERIALIZATION_H__ 27 27 28 /* 29 # Local Variables: 30 # tab-width: 4; 31 # c-basic-offset: 4; 32 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 33 # indent-tabs-mode: nil; 34 # End: 35 # 36 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 37 */ 38 -
sources/src/serialization_ext.h
r27 r52 38 38 39 39 #include <iostream> 40 40 41 #include "sc_fwd.h" 41 42 42 43 namespace sc_core { 44 43 45 ///////////////////////// 44 46 // SYSTEMCASS SPECIFIC // 45 47 46 48 // Types 47 //typedef void (sc_core::sc_module::*save_fct_t2) (std::ostream&) const; 48 typedef void (sc_core::sc_module::*save_fct_t1) (FILE*) const; 49 typedef void(sc_core::sc_module::*save_fct_t1) (FILE *) const; 49 50 50 51 // Functions 51 extern void sc_save_simulation (const char *filename = "savedefault");52 extern void sc_save_simulation(const char * filename = "savedefault"); 52 53 53 54 } // end of sc_core namespace … … 59 60 #endif // __SERIALIZATION_EXT_H__ 60 61 62 /* 63 # Local Variables: 64 # tab-width: 4; 65 # c-basic-offset: 4; 66 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 67 # indent-tabs-mode: nil; 68 # End: 69 # 70 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 71 */ 72 -
sources/src/signal_dependency.cc
r27 r52 43 43 #include "sc_module.h" 44 44 #include "sc_ver_ext.h" 45 45 46 #ifdef HAVE_CONFIG_H 46 47 #include "config.h" … … 51 52 namespace sc_core { 52 53 53 bool 54 SignalDependency::operator < (const SignalDependency &b) const 55 { 56 if (source < b.source) 57 return true; 58 if (destination < b.destination) 59 return true; 60 return false; 61 } 62 63 static 64 void 65 txt_write (ofstream &o, const component_list_t &l) 66 { 67 component_list_t::const_iterator it; 68 for (it = l.begin (); it != l.end (); ++it) 69 { 70 o << get_name(*((equi_t*)(*it))) << " "; 71 } 72 } 73 74 static 75 void 76 txt_write (ofstream &o, const strong_component_list_t &l) 77 { 78 strong_component_list_t::const_iterator it; 79 for (it = l.begin (); it != l.end (); ++it) 80 { 81 txt_write (o,**it); 82 o << "\n"; 83 } 84 } 85 86 bool 87 SignalDependencyOrder2txt (const char *name, 88 const strong_component_list_t&l) 89 { 90 if (!name) 91 return false; 92 string filename; 93 filename = name; 94 filename += ".txt"; 95 ofstream o; 96 o.open (filename.c_str(),ios::out | ios::trunc); 97 if (o.is_open () == false) 98 return false; 99 txt_write (o,l); 100 o.close (); 101 return true; 102 103 } 104 105 static 106 void 107 dot_write (ofstream &o, const SignalDependencyGraph &g) 108 { 109 string s; 110 SignalDependencyGraph::const_iterator it; 111 for (it = g.begin (); it != g.end (); ++it) 112 { 113 string name; 114 name = it->method->module->name(); 115 name += "_"; 116 name += it->method->name; 117 o << "edge [label=" 118 << simplify_name(name.c_str(),s) 119 << "];\n"; 120 const equi_t *equi = it->source; 121 name = get_name (*equi); 122 o << simplify_name(name.c_str(),s); 123 o << " -> "; 124 equi = it->destination; 125 name = get_name (*equi); 126 o << simplify_name(name.c_str(),s); 127 o << ";\n"; 128 } 129 } 130 131 bool 132 SignalDependencyGraph2dot (const char *name, 133 const SignalDependencyGraph& g) 134 { 135 if (!name) 136 return false; 137 string filename; 138 filename = name; 139 filename += ".dot"; 140 ofstream o; 141 o.open (filename.c_str(),ios::out | ios::trunc); 142 if (o.is_open () == false) 143 return false; 144 o << "// Signal dependency graph\n" 145 "// Generated by " 146 << sc_version () << "\n"; 147 o << "strict digraph " << name << " {\n"; 148 dot_write (o,g); 149 o << "}\n"; 150 o.close (); 151 if (dump_stage) 152 cerr << "Signal Dependency Graph written into '" 153 << filename << "'.\n"; 154 return true; 155 } 156 157 SignalDependencyGraph* 158 MakeSignalDependencyGraph (const PortDependencyGraph& g) 159 { 160 if (dump_stage) 161 cerr << "Making signal dependency graph...\n"; 162 163 SignalDependencyGraph *sig_g = new SignalDependencyGraph (); 164 PortDependencyGraph::const_iterator it; 165 for (it = g.begin(); it != g.end(); ++it) 166 { 167 SignalDependency s; 168 s.method = it->method; 169 const sc_interface *inter; 170 inter = it->source; 171 if (inter) 172 s.source = &(get_equi (*inter)); 173 else 174 continue; 175 inter = it->destination; 176 s.destination = &(get_equi (*inter)); 177 sig_g->insert(s); 178 } 179 return sig_g; 180 } 181 182 183 static 184 bool 185 is_in (const equi_t &e, const method_process_t &m) 186 { 187 const tab_t *pt = e.begin ()->interface->get_pointer (); 188 const sensitivity_list_t &sens = m.sensitivity_list; 189 sensitivity_list_t::const_iterator it; 190 for (it = sens.begin (); it != sens.end (); ++it) 191 { 192 const sc_event &event = *it; 193 if (pt == event.get_interface().get_pointer ()) 194 return true; 195 } 196 return false; 197 } 198 199 static 200 bool 201 is_valid (const SignalDependency &s) 202 { 203 #if 0 204 cerr << "'" << get_name (*(s.destination)) << "'" 205 << " depends on '" << get_name (*(s.source)) << "'" 206 << " in the module '" << s.method->module->name() << "'\n"; 207 return true; 208 #endif 209 if (is_in (*(s.source), *(s.method))) 210 return true; 211 const char *src = get_name (*(s.source)); 212 cerr << "'" << get_name (*(s.destination)) << "'" 213 << " depends on '" << src << "'" 214 << " in the module '" << s.method->module->name() << "'" 215 << " but '" << src << "' is not in the sensitivity_list.\n"; 216 return false; 217 } 218 219 bool 220 Check (const SignalDependencyGraph &g) 221 { 222 SignalDependencyGraph::const_iterator it; 223 for (it = g.begin(); it != g.end(); ++it) 224 { 225 const SignalDependency &s = (*it); 226 if (!is_valid (s)) 227 return false; 228 } 229 return true; 230 } 231 232 static 233 bool 234 is_in (const equi_t &e, const SignalDependencyGraph &g) 235 { 236 SignalDependencyGraph::const_iterator it; 237 for (it = g.begin (); it != g.end (); ++it) 238 { 239 const SignalDependency &s = *it; 240 if (&e == s.source) 241 return true; 242 } 243 return false; 244 } 245 246 static 247 bool 248 is_in (const sensitivity_list_t &sens, const SignalDependencyGraph &g) 249 { 250 sensitivity_list_t::const_iterator it; 251 for (it = sens.begin (); it != sens.end (); ++it) 252 { 253 const sc_event &event = *it; 254 const sc_interface &i = event.get_interface(); 255 const equi_t &equi = get_equi (i); 256 if (is_clock (i)) 257 continue; 258 if (!is_in (equi, g)) { 259 cerr << "'" << get_name(equi) << "'" 260 << " is in the sensitivity list of "; 261 return false; 262 } 263 } 264 return true; 265 } 266 267 bool 268 Check (const method_process_list_t &ml, 269 const SignalDependencyGraph &g) 270 { 271 method_process_list_t::const_iterator it; 272 for (it = ml.begin(); it != ml.end(); ++it) 273 { 274 const method_process_t &m = *(*it); 275 const sensitivity_list_t &sens = m.sensitivity_list; 276 if (!is_in (sens, g)) 277 { 278 cerr << "'" << m.module->name() << "' module instance " 279 << "but any output port doesn't depend on this input.\n"; 280 return false; 281 } 282 } 283 return true; 284 } 54 bool SignalDependency::operator < (const SignalDependency & b) const { 55 if (source < b.source) { 56 return true; 57 } 58 if (destination < b.destination) { 59 return true; 60 } 61 return false; 62 } 63 64 65 static void txt_write(ofstream & o, const component_list_t & l) { 66 component_list_t::const_iterator it; 67 for (it = l.begin(); it != l.end(); ++it) { 68 o << get_name(*((equi_t *) (*it))) << " "; 69 } 70 } 71 72 73 static void txt_write(ofstream & o, const strong_component_list_t & l) { 74 strong_component_list_t::const_iterator it; 75 for (it = l.begin(); it != l.end(); ++it) { 76 txt_write(o, **it); 77 o << "\n"; 78 } 79 } 80 81 82 bool SignalDependencyOrder2txt(const char * name, const strong_component_list_t & l) { 83 if (!name) { 84 return false; 85 } 86 string filename; 87 filename = name; 88 filename += ".txt"; 89 ofstream o; 90 o.open(filename.c_str(),ios::out | ios::trunc); 91 if (!o.is_open()) { 92 return false; 93 } 94 txt_write(o, l); 95 o.close(); 96 return true; 97 } 98 99 100 static void dot_write(ofstream & o, const SignalDependencyGraph & g) { 101 string s; 102 SignalDependencyGraph::const_iterator it; 103 for (it = g.begin(); it != g.end(); ++it) { 104 string name; 105 name = it->method->module->name(); 106 name += "_"; 107 name += it->method->name; 108 o << "edge [label=" 109 << simplify_name(name.c_str(), s) 110 << "];\n"; 111 const equi_t * equi = it->source; 112 name = get_name(*equi); 113 o << simplify_name(name.c_str(), s); 114 o << " -> "; 115 equi = it->destination; 116 name = get_name(*equi); 117 o << simplify_name(name.c_str(), s); 118 o << ";\n"; 119 } 120 } 121 122 123 bool SignalDependencyGraph2dot(const char * name, const SignalDependencyGraph & g) { 124 if (!name) { 125 return false; 126 } 127 string filename; 128 filename = name; 129 filename += ".dot"; 130 ofstream o; 131 o.open(filename.c_str(),ios::out | ios::trunc); 132 if (!o.is_open()) { 133 return false; 134 } 135 o << "// Signal dependency graph\n" 136 "// Generated by " 137 << sc_version() << "\n"; 138 o << "strict digraph " << name << " {\n"; 139 dot_write(o, g); 140 o << "}\n"; 141 o.close(); 142 if (dump_stage) { 143 cerr << "Signal Dependency Graph written into '" 144 << filename << "'.\n"; 145 } 146 return true; 147 } 148 149 150 SignalDependencyGraph * MakeSignalDependencyGraph(const PortDependencyGraph & g) { 151 if (dump_stage) { 152 cerr << "Making signal dependency graph...\n"; 153 } 154 155 SignalDependencyGraph * sig_g = new SignalDependencyGraph(); 156 PortDependencyGraph::const_iterator it; 157 for (it = g.begin(); it != g.end(); ++it) { 158 SignalDependency s; 159 s.method = it->method; 160 const sc_interface * inter; 161 inter = it->source; 162 if (inter) { 163 s.source = &(get_equi(*inter)); 164 } 165 else { 166 continue; 167 } 168 inter = it->destination; 169 s.destination = &(get_equi(*inter)); 170 sig_g->insert(s); 171 } 172 return sig_g; 173 } 174 175 176 static bool is_in(const equi_t & e, const method_process_t & m) { 177 const tab_t * pt = e.begin()->interface->get_pointer(); 178 const sensitivity_list_t & sens = m.sensitivity_list; 179 sensitivity_list_t::const_iterator it; 180 for (it = sens.begin(); it != sens.end(); ++it) { 181 const sc_event & event = *it; 182 if (pt == event.get_interface().get_pointer()) { 183 return true; 184 } 185 } 186 return false; 187 } 188 189 190 static bool is_valid(const SignalDependency & s) { 191 if (dump_stage) { 192 cerr << "'" << get_name (*(s.destination)) << "'" 193 << " depends on '" << get_name (*(s.source)) << "'" 194 << " in the module '" << s.method->module->name() << "'\n"; 195 } 196 if (is_in(*(s.source), *(s.method))) { 197 return true; 198 } 199 200 const char * src = get_name(*(s.source)); 201 cerr << "'" << get_name(*(s.destination)) << "'" 202 << " depends on '" << src << "'" 203 << " in the module '" << s.method->module->name() << "'" 204 << " but '" << src << "' is not in the sensitivity_list.\n"; 205 return false; 206 } 207 208 209 bool Check(const SignalDependencyGraph & g) { 210 SignalDependencyGraph::const_iterator it; 211 for (it = g.begin(); it != g.end(); ++it) { 212 const SignalDependency &s = (*it); 213 if (!is_valid(s)) { 214 return false; 215 } 216 217 } 218 return true; 219 } 220 221 222 static bool is_in(const equi_t & e, const SignalDependencyGraph & g) { 223 SignalDependencyGraph::const_iterator it; 224 for (it = g.begin(); it != g.end(); ++it) { 225 const SignalDependency & s = *it; 226 if (&e == s.source) { 227 return true; 228 } 229 230 } 231 return false; 232 } 233 234 235 static bool is_in(const sensitivity_list_t & sens, const SignalDependencyGraph & g) { 236 sensitivity_list_t::const_iterator it; 237 for (it = sens.begin(); it != sens.end(); ++it) { 238 const sc_event & event = *it; 239 const sc_interface & i = event.get_interface(); 240 const equi_t & equi = get_equi(i); 241 if (is_clock(i)) { 242 continue; 243 } 244 if (!is_in(equi, g)) { 245 cerr << "'" << get_name(equi) << "' is in the sensitivity list of "; 246 return false; 247 } 248 } 249 return true; 250 } 251 252 253 bool Check(const method_process_list_t & ml, const SignalDependencyGraph & g) { 254 method_process_list_t::const_iterator it; 255 for (it = ml.begin(); it != ml.end(); ++it) { 256 const method_process_t & m = *(*it); 257 const sensitivity_list_t & sens = m.sensitivity_list; 258 if (!is_in(sens, g)) { 259 cerr << "'" << m.module->name() << "' module instance " 260 << "but any output port doesn't depend on this input.\n"; 261 return false; 262 } 263 } 264 return true; 265 } 266 285 267 286 268 } // end of sc_core namespace 287 269 270 /* 271 # Local Variables: 272 # tab-width: 4; 273 # c-basic-offset: 4; 274 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 275 # indent-tabs-mode: nil; 276 # End: 277 # 278 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 279 */ 280 -
sources/src/signal_dependency.h
r35 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef SIGNAL_DEPENDENCY_H 13 14 #define SIGNAL_DEPENDENCY_H 14 15 15 16 #include <set> 17 16 18 #include "sc_fwd.h" 17 19 #include "entity.h" // equi_t 18 20 #include "graph.h" 19 //#include "sc_port.h"20 21 #include "port_dependency.h" 21 22 22 23 namespace sc_core { 23 24 25 24 26 // Signal Dependency Graph 25 27 struct SignalDependency { 26 const method_process_t *method; 27 const equi_t *source; 28 const equi_t *destination; 29 bool operator < (const SignalDependency &a) const; 30 // friend int operator < (const SignalDependency &a, const SignalDependency &b); 28 const method_process_t * method; 29 const equi_t * source; 30 const equi_t * destination; 31 bool operator < (const SignalDependency & a) const; 31 32 }; 33 32 34 33 35 typedef std::set<SignalDependency> SignalDependencyGraph; 34 36 37 35 38 // Convert Port Dependency Graph to Signal Dependency Graph 36 extern SignalDependencyGraph * MakeSignalDependencyGraph (const PortDependencyGraph& = get_port_dependency_graph());39 extern SignalDependencyGraph * MakeSignalDependencyGraph(const PortDependencyGraph & = get_port_dependency_graph()); 37 40 38 41 // Checking 39 extern bool Check (const SignalDependencyGraph&);40 extern bool Check (const method_process_list_t&, const SignalDependencyGraph&);42 extern bool Check(const SignalDependencyGraph &); 43 extern bool Check(const method_process_list_t &, const SignalDependencyGraph &); 41 44 42 45 // Dump 43 extern bool SignalDependencyGraph2dot (const char *name, const SignalDependencyGraph&);44 extern bool SignalDependencyOrder2txt (const char *name, const strong_component_list_t&);46 extern bool SignalDependencyGraph2dot(const char * name, const SignalDependencyGraph &); 47 extern bool SignalDependencyOrder2txt(const char * name, const strong_component_list_t &); 45 48 46 49 } // end of sc_core namespace … … 48 51 #endif 49 52 53 /* 54 # Local Variables: 55 # tab-width: 4; 56 # c-basic-offset: 4; 57 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 58 # indent-tabs-mode: nil; 59 # End: 60 # 61 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 62 */ 63 -
sources/src/simplify_string.cc
r27 r52 35 35 36 36 #include "simplify_string.h" 37 37 38 #ifdef HAVE_CONFIG_H 38 39 #include "config.h" … … 43 44 namespace sc_core { 44 45 46 45 47 // Truncate the name : delete "." 46 string& 47 simplify_name (const char *name, string &newname) 48 { 49 if (!name) { 50 newname = ""; 51 return newname; 52 } 53 newname = name; 54 string::size_type i = 0; 55 do { 56 i = newname.find ('.'); 57 if (i == -1) 58 break; 59 newname[i] = '_'; 60 } while (1); 61 return newname; 48 string & simplify_name (const char * name, string & newname) { 49 if (!name) { 50 newname = ""; 51 return newname; 52 } 53 newname = name; 54 string::size_type i = 0; 55 do { 56 i = newname.find ('.'); 57 if (i == -1) { 58 break; 59 } 60 newname[i] = '_'; 61 } while (1); 62 return newname; 62 63 } 63 64 64 65 } // end of sc_core namespace 65 66 67 /* 68 # Local Variables: 69 # tab-width: 4; 70 # c-basic-offset: 4; 71 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 72 # indent-tabs-mode: nil; 73 # End: 74 # 75 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 76 */ 77 -
sources/src/simplify_string.h
r1 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef SIMPLIFY_STRING_H 13 14 #define SIMPLIFY_STRING_H … … 17 18 // Truncate the name : delete "." 18 19 namespace sc_core { 19 extern std::string& simplify_name (const char *name, std::string &newname); 20 21 extern std::string & simplify_name(const char * name, std::string & newname); 22 20 23 } 21 24 22 25 #endif 23 26 27 /* 28 # Local Variables: 29 # tab-width: 4; 30 # c-basic-offset: 4; 31 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 32 # indent-tabs-mode: nil; 33 # End: 34 # 35 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 36 */ 37 -
sources/src/systemc
r31 r52 31 31 32 32 #endif 33 34 /* 35 # Local Variables: 36 # tab-width: 4; 37 # c-basic-offset: 4; 38 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 39 # indent-tabs-mode: nil; 40 # End: 41 # 42 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 43 */ 44 -
sources/src/systemc.h
r4 r52 52 52 using sc_core::sc_sensitive_pos; 53 53 using sc_core::sc_sensitive_neg; 54 ///////////////////////////////////////////////// 54 55 ///////////////////////////////// 55 56 // Ports & Signals 56 // 57 ///////////////////////////////// 57 58 using sc_core::sc_time; 58 59 using sc_core::sc_simulation_time; … … 89 90 #endif 90 91 92 /* 93 # Local Variables: 94 # tab-width: 4; 95 # c-basic-offset: 4; 96 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 97 # indent-tabs-mode: nil; 98 # End: 99 # 100 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 101 */ 102 -
sources/src/systemcass_version_ext.h
r3 r52 1 1 2 #define SYSTEMC_VERSION "SystemCASS : lundi 10 septembre 2007, 15:" 3 4 /* 5 # Local Variables: 6 # tab-width: 4; 7 # c-basic-offset: 4; 8 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 9 # indent-tabs-mode: nil; 10 # End: 11 # 12 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 13 */ 14 -
sources/src/usage.h
r1 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : usage.h |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : ??_??_2005 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : usage.h | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : ??_??_2005 | 10 | | 11 \------------------------------------------------------------*/ 12 12 13 13 /* … … 33 33 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 34 34 */ 35 35 36 #ifndef __USAGE_H__ 36 37 #define __USAGE_H__ … … 42 43 43 44 struct usage_t { 44 unsigned int elapsed_time; 45 long memory_size; 46 usage_t () 47 { 48 elapsed_time = 0; 49 memory_size = 0; 50 } 51 void start () 52 { 53 struct rusage usage; 54 getrusage(RUSAGE_SELF, &usage); 55 elapsed_time = usage.ru_utime.tv_sec; 56 memory_size = usage.ru_maxrss; 57 } 58 void cont () 59 { 60 struct rusage usage; 61 getrusage(RUSAGE_SELF, &usage); 62 elapsed_time = usage.ru_utime.tv_sec - elapsed_time; 63 memory_size = usage.ru_maxrss; 64 } 65 void stop () 66 { 67 cont (); 68 } 69 operator unsigned int () const 70 { return elapsed_time; } 71 long get_memory_size () const 72 { return memory_size; } 73 friend std::ostream& operator << (std::ostream& o, const usage_t &c) 74 { 75 return o << c.elapsed_time << "seconds"; 76 } 45 unsigned int elapsed_time; 46 long memory_size; 47 usage_t() { 48 elapsed_time = 0; 49 memory_size = 0; 50 } 51 52 void start() { 53 struct rusage usage; 54 getrusage(RUSAGE_SELF, &usage); 55 elapsed_time = usage.ru_utime.tv_sec; 56 memory_size = usage.ru_maxrss; 57 } 58 59 void cont() { 60 struct rusage usage; 61 getrusage(RUSAGE_SELF, &usage); 62 elapsed_time = usage.ru_utime.tv_sec - elapsed_time; 63 memory_size = usage.ru_maxrss; 64 } 65 66 void stop() { 67 cont(); 68 } 69 70 operator unsigned int () const { 71 return elapsed_time; 72 } 73 74 long get_memory_size () const { 75 return memory_size; 76 } 77 78 friend std::ostream & operator << (std::ostream & o, const usage_t & c) { 79 return o << c.elapsed_time << "seconds"; 80 } 81 77 82 }; 78 83 79 84 #endif 80 85 86 /* 87 # Local Variables: 88 # tab-width: 4; 89 # c-basic-offset: 4; 90 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 91 # indent-tabs-mode: nil; 92 # End: 93 # 94 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 95 */ 96 -
sources/src/utils.h
r1 r52 37 37 38 38 #endif /* __UTILS_H__ */ 39
Note: See TracChangeset
for help on using the changeset viewer.