source: trunk/IPs/systemC/processor/Morpheo/Behavioural/src/Component_port_map.cpp @ 75

Last change on this file since 75 was 75, checked in by rosiere, 16 years ago

Update all component (except front_end) to :

  • new statistics model
  • no namespace std
File size: 4.9 KB
Line 
1/*
2 * $Id$
3 *
4 * [ Description ]
5 *
6 */
7
8#include "Behavioural/include/Component.h"
9
10namespace morpheo              {
11namespace behavioural          {
12
13#undef  FUNCTION
14#define FUNCTION "Component::port_map"
15  void Component::port_map (std::string component_src ,
16                            std::string port_src      ,
17                            std::string component_dest,
18                            std::string port_dest     )
19  {
20    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
21
22    std::string name_entity = _entity->get_name();
23
24    // First entity
25    Entity * entity_dest = find_entity(component_dest);
26
27    if (entity_dest == NULL)
28      throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", port map with unknow component \""+component_dest+"\"."));
29
30    Signal * signal_dest = entity_dest->find_signal (port_dest);
31
32    if (signal_dest == NULL)
33      throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", port map with component \""+component_dest+"\" and a unknow signal \""+port_dest+"\"."));
34
35    // Second entity
36    Entity * entity_src = find_entity(component_src);
37
38    if (entity_src == NULL)
39      throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", port map with unknow component \""+component_src+"\"."));
40
41    Signal * signal_src = entity_src->find_signal (port_src);
42
43    if (signal_src == NULL)
44      throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", port map with component \""+component_src+"\" and a unknow signal \""+port_src+"\"."));
45
46    // If all is ok, mapping
47    log_printf(TRACE,Behavioural,FUNCTION, "Signal \"%s.%s\"\tlink with \"%s.%s\""
48               ,entity_src ->get_name().c_str()
49               ,signal_src ->get_name().c_str()
50               ,entity_dest->get_name().c_str()
51               ,signal_dest->get_name().c_str());
52
53    // need an internal signal ?
54    bool src_is_port  = entity_src  == _entity;
55    bool dest_is_port = entity_dest == _entity;
56
57    if (src_is_port == true)
58      throw (ErrorMorpheo ("<Component::port_map> src can't be an interface's port of the top level."));
59   
60    // 2 cases :
61    //  a) dest is a top level port -> direct connection
62    //  b) dest is a component port -> need internal signal
63    if (dest_is_port == false)
64      {
65        // 1) find productor of signal
66        //       
67        // Interface      Component
68        //    |          |         
69        //  ----> (IN)     --X-> (IN)
70        //    |          |         
71        //  <-X-- (OUT)    <---- (OUT)
72        //    |              |       
73       
74        Signal * signal_productor;
75        Entity * entity_productor;
76
77        bool     src_is_productor = (signal_src->get_direction() == OUT);
78
79        if (src_is_productor == true)
80          {
81            signal_productor = signal_src;
82            entity_productor = entity_src;
83          }
84        else
85          {
86            signal_productor = signal_dest;
87            entity_productor = entity_dest;
88          }
89
90        signal_dest= signal_internal (entity_productor, signal_productor);
91        signal_dest->set_size_max(signal_src->get_size());
92
93        dest_is_port = false;
94      }
95   
96    try
97      {
98        signal_src->link(signal_dest,
99                         dest_is_port);
100      }
101    catch (morpheo::ErrorMorpheo & error)
102      {
103        throw (ErrorMorpheo ("<Component::port_map> Error in mapping between "+entity_src ->get_name()+"."+signal_src ->get_name()+" and "+entity_dest->get_name()+"."+signal_dest->get_name()+" :\n"+error.what ()));
104      }
105    //catch (...)
106    //  {
107    //  }
108
109    log_printf(FUNC,Behavioural,FUNCTION,"End");
110  };
111
112
113  void Component::port_map (std::string component_src ,
114                            std::string port_src      )
115  {
116    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
117   
118    Entity * entity_src = find_entity(component_src);
119   
120    if (entity_src == NULL)
121      throw (ErrorMorpheo ("<Component::port_map> in component \""+_entity->get_name()+"\", port map with unknow component \""+component_src+"\"."));
122   
123    Signal * signal_src = entity_src->find_signal (port_src);
124   
125    if (signal_src == NULL)
126      throw (ErrorMorpheo ("<Component::port_map> in component \""+_entity->get_name()+"\", port map with component \""+component_src+"\" and a unknow signal \""+port_src+"\"."));
127   
128    // need an internal signal ?
129   
130    if (entity_src == _entity)
131      throw (ErrorMorpheo ("<Component::port_map> src can't be an interface's port of the top level."));
132   
133    if (signal_src->get_direction() != OUT)
134      throw (ErrorMorpheo ("<Component::port_map> the direction of the signal '"+signal_src->get_name()+"' must be OUT."));
135
136    Signal * signal_dest;
137
138    signal_dest= signal_internal (entity_src, signal_src);
139    signal_dest->set_size_max(signal_src->get_size());
140   
141    try
142      {
143        signal_src->link(signal_dest,
144                         false);
145      }
146    catch (morpheo::ErrorMorpheo & error)
147      {
148        throw (ErrorMorpheo ("<Component::port_map> Error in mapping "+entity_src ->get_name()+"."+signal_src ->get_name()+" :\n"+error.what ()));
149      }
150    //catch (...)
151    //  {
152    //  }
153
154    log_printf(FUNC,Behavioural,FUNCTION,"End");
155  };
156
157}; // end namespace behavioural         
158}; // end namespace morpheo             
159
Note: See TracBrowser for help on using the repository browser.