source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Configuration/src/Instance_fromXMLLight.cpp @ 109

Last change on this file since 109 was 109, checked in by rosiere, 15 years ago

1) Configuration : instance configuration file : regroup similar instance
2) Configuration : timing default = 0
3) Debug/Commit_unit : Add watch dog timer
4) Issue_queue : Test parameters : add test if type is optionnal
5) Cor_glue : Fix insert index
6) Free_list : remove bank_by_pop (else deadlock)
7) Update Free List : add register to source event

  • Property svn:keywords set to Id
File size: 11.5 KB
Line 
1/*
2 * $Id: Instance_fromXMLLight.cpp 109 2009-02-16 20:28:31Z rosiere $
3 *
4 * [ Description ]
5 *
6 */
7
8#include "Behavioural/Configuration/include/Instance.h"
9#include "Common/include/FromString.h"
10#include <fstream>
11
12namespace morpheo {
13namespace behavioural {
14namespace configuration {
15
16  using namespace XMLUtils;
17
18#undef  FUNCTION
19#define FUNCTION "Instance::fromXMLLight"
20  void Instance::fromXMLLight (XML_t * xml,
21                               attribute_t         id,
22                               list_parameters_t * list_parameters,
23                               list_links_t      * list_links,
24                               list_components_t * list_components)
25  {
26
27    XMLLightVector<XML_t> vect = xml->getNodes(); 
28
29    for (uint32_t i=0; i<vect.size(); ++i)
30      {
31        XML_t * child = vect[i];
32
33        std::string child_name = child->getName();
34
35//         log_printf(TRACE,Configuration,FUNCTION,"  * child_name : %s",child_name.c_str());
36
37        //--------------------------------------------
38        // Child : Parameter
39        //--------------------------------------------
40        if (child_name == "parameter")
41          {
42            // Is a parameter
43            testSingleton  (child,true);       
44           
45            attributes_t attributes = child->getAttributes();
46            attribute_t  value_name = getAttribute(child,attributes,"name" );
47            attribute_t  value      = getAttribute(child,attributes,"value");
48
49//             log_printf(TRACE,Configuration,FUNCTION,"    * parameter \"%s\" = %s",value_name.c_str(), value.c_str());
50           
51            testAttributesEmpty(child,attributes);
52
53            // Test the parameter :
54            //   * name is correct
55            //   * value is correct
56            test (value_name, value);
57           
58            // Insert in array
59            Parameter_affectation * param = new Parameter_affectation(value_name, // type
60                                                                      value);
61           
62            // insert parameter
63            (*list_parameters)[param->_name] = param;
64          }
65        //--------------------------------------------
66        // Child : Link
67        //--------------------------------------------
68        else
69        if (child_name == "link")
70          {
71            // Is a parameter
72            testSingleton  (child,true);       
73           
74            attributes_t attributes = child->getAttributes();
75            attribute_t  value_name = getAttribute(child,attributes,"name");
76
77//             log_printf(TRACE,Configuration,FUNCTION,"    * link  \"%s\"",value_name.c_str());
78           
79            // Test, must have src or dest (or twice)
80            bool have_src  = child->containsAttribute("src" );
81            bool have_dest = child->containsAttribute("dest");
82            if (not have_src  and
83                not have_dest)
84              throw ERRORMORPHEO(FUNCTION,toString(_("Syntax error, node \"link\" must have one or twince of this attributes : src, dest\n")));
85           
86            attribute_t  value_src  = (have_src )?getAttribute(child,attributes,"src" ):id;
87            attribute_t  value_dest = (have_dest)?getAttribute(child,attributes,"dest"):id;
88
89
90            testAttributesEmpty(child,attributes);
91           
92            // Test the link :
93            //   * name is correct
94            //   * if not have_src , test if src  is correct
95            //   * if not have_dest, test if dest is correct
96            test (value_name,
97                  xml->getName(),
98                  not have_src,
99                  not have_dest);
100
101            // Create a new link
102            {
103              Link_affectation * link = new Link_affectation(value_name, // type
104                                                             value_src,
105                                                             value_dest);
106             
107              // Test if this id is previously used
108              if (((*list_links)[value_name]).find(value_src) != ((*list_links)[value_name]).end())
109                throw ERRORMORPHEO(FUNCTION,toString(_("A Link \"%s\" with the source \"%s\" is previously declared.\n"),value_name.c_str(),value_src.c_str()));
110             
111              ((*list_links)[value_name])[value_src] = link;
112            }
113          }
114        //--------------------------------------------
115        // Child : Timing
116        //--------------------------------------------
117        else
118        if (child_name == "timing")
119          {
120//             log_printf(TRACE,Configuration,FUNCTION,"    * timing");
121
122            // Notation :
123            //     <timing type="5" operation="8" latence="2"  delay="1" />
124            //
125            // is equivalent at :
126            //     <type id="5" >
127            //       <operation id="8" >
128            //         <parameter  name="delay"   value="1" />
129            //         <parameter  name="latence" value="2" />
130            //       </operation>
131            //     </type>
132
133            // Is a parameter
134            testSingleton  (child,true);       
135           
136            attributes_t attributes      = child->getAttributes();
137            attribute_t  value_type      = getAttribute(child,attributes,"type");
138            bool         have_operation  = (child->containsAttribute("operation"));
139            attribute_t  value_operation ;
140            attribute_t  value_latence   = (child->containsAttribute("latence"  ))?getAttribute(child,attributes,"latence"  ):"1";
141            attribute_t  value_delay     = (child->containsAttribute("delay"    ))?getAttribute(child,attributes,"delay"    ):"1";
142
143            {
144              // Find component "type", if don't exist : create
145              if (((*list_components)["type"]).find(value_type) == ((*list_components)["type"]).end())
146                {
147                  // Create instance
148                  Instance_component * param = new Instance_component("type", // type
149                                                                      value_type);
150                  ((*list_components)["type"])[value_type] = param;
151                }
152
153              list_components_t * list_type = ((*list_components)["type"])[value_type]->_list_components;
154
155              // Find component "operation", if exist : error, else create
156
157              bool         stop            = false;
158              Toperation_t operation       = 0;
159              attribute_t  value_operation = (have_operation)?getAttribute(child,attributes,"operation"):toString(operation);
160
161              while (not stop)
162                {
163                  if (((*list_type)["operation"]).find(value_operation) != ((*list_type)["operation"]).end())
164                    throw ERRORMORPHEO(FUNCTION,toString(_("A Component \"%s\" with id \"%s\" is previously declared.\n"),"operation",value_operation.c_str()));
165                  else
166                    {
167                      // Create instance
168                      Instance_component * param = new Instance_component("operation", // type
169                                                                          value_operation);
170                      ((*list_type)["operation"])[value_operation] = param;
171                    }
172
173                  list_parameters_t * list_operation = ((*list_type)["operation"])[value_operation]->_list_parameters;
174                 
175                  // insert parameter "latence" and "delay"
176                  Parameter_affectation * param_latence = new Parameter_affectation("latence",
177                                                                                    value_latence);
178                  Parameter_affectation * param_delay   = new Parameter_affectation("delay",
179                                                                                    value_delay);           
180                 
181                  (*list_operation)["latence"] = param_latence;
182                  (*list_operation)["delay"  ] = param_delay  ;
183
184                  operation ++;
185                  value_operation = toString(operation);
186                  stop = have_operation or (operation == MAX_OPERATION);
187                };
188             
189            }
190
191            testAttributesEmpty(child,attributes);
192          }
193        //--------------------------------------------
194        // Child : Other (component)
195        //--------------------------------------------
196        else
197          {
198//             log_printf(TRACE,Configuration,FUNCTION,"    * component");
199
200            testSingleton  (child,false);       
201           
202            attributes_t attributes = child->getAttributes();
203            attribute_t  value_ids  = getAttribute(child,attributes,"id");
204            attribute_t  value_type = child->getName();
205
206            testAttributesEmpty(child,attributes);
207
208            // Test if counter is an parameters
209            std::string name_counter = "nb_"+value_type;
210           
211            {
212              if (list_parameters->find(name_counter) == list_parameters->end())
213                {
214                  // Insert in array
215                  Parameter_affectation * param = new Parameter_affectation(name_counter, // type
216                                                                            "0");
217                  // insert parameter
218                  (*list_parameters)[name_counter] = param;
219                }
220            }
221           
222            size_t index_begin = 0;
223            while (index_begin != std::string::npos)
224              {
225                size_t index_end = value_ids.find_first_of(",",index_begin+1);
226               
227                size_t      index_min = (index_begin==0)?index_begin:(index_begin+1);
228                size_t      index_max = index_end-index_min;
229                attribute_t value_id  = value_ids.substr(index_min, index_max);
230
231//                 log_printf(TRACE,Configuration,FUNCTION,"    * component \"%s\" - %s",value_type.c_str(), value_id.c_str());
232
233                index_begin = index_end;
234
235                // Create a new component
236                {
237                  Instance_component * param = new Instance_component(value_type, // type
238                                                                      value_id);
239             
240//                log_printf(TRACE,Configuration,FUNCTION,"%s.%s",value_type.c_str(),value_id.c_str());
241//                log_printf(TRACE,Configuration,FUNCTION,"  * %d",((*list_components)[value_type]).size());
242             
243                  // Test if this id is previously used
244                  if (((*list_components)[value_type]).find(value_id) != ((*list_components)[value_type]).end())
245                    throw ERRORMORPHEO(FUNCTION,toString(_("A Component \"%s\" with id \"%s\" is previously declared.\n"),value_type.c_str(),value_id.c_str()));
246                 
247                  ((*list_components)[value_type])[value_id] = param;
248                }
249
250                // Increase occurence counter
251                {
252                  (*list_parameters)[name_counter]->_value = toString(fromString<uint32_t>((*list_parameters)[name_counter]->_value)+1);
253                }
254               
255                // Recursive function
256                fromXMLLight (child,
257                              ((id=="")?value_id:(id+"."+value_id)), // construction of identificator
258                              ((*list_components)[value_type])[value_id]->_list_parameters,
259//                            ((*list_components)[value_type])[value_id]->_list_links,
260                              list_links,
261                              ((*list_components)[value_type])[value_id]->_list_components);
262              }
263          }
264      }
265  };
266
267}; // end namespace configuration
268}; // end namespace behavioural
269}; // end namespace morpheo             
Note: See TracBrowser for help on using the repository browser.