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

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

Add new component : Read_unit (no tested)
Change functionnal_unit : now use type and operation to execute the good function
Change New_Component's script

File size: 5.3 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
28    if (entity_dest == NULL)
29      throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", try map \""+component_src+"."+port_src+"\" with \""+component_dest+"."+port_dest+"\" but the component \""+component_dest+"\" is unknow."));
30
31    Signal * signal_dest = entity_dest->find_signal (port_dest);
32
33    if (signal_dest == NULL)
34      throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\",try map \""+component_src+"."+port_src+"\" with \""+component_dest+"."+port_dest+"\" but the component \""+component_dest+"\" have not the signal \""+port_dest+"\"."));
35
36    // Second entity
37    Entity * entity_src = find_entity(component_src);
38
39    if (entity_src == NULL)
40      throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", try map \""+component_src+"."+port_src+"\" with \""+component_dest+"."+port_dest+"\" but the component \""+component_src+"\" is unknow."));
41
42    Signal * signal_src = entity_src->find_signal (port_src);
43
44    if (signal_src == NULL)
45      throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", try map \""+component_src+"."+port_src+"\" with \""+component_dest+"."+port_dest+"\" but the component \""+component_src+"\" have not the signal \""+port_src+"\"."));
46
47    // If all is ok, mapping
48    log_printf(TRACE,Behavioural,FUNCTION, "Signal \"%s.%s\"\tlink with \"%s.%s\""
49               ,entity_src ->get_name().c_str()
50               ,signal_src ->get_name().c_str()
51               ,entity_dest->get_name().c_str()
52               ,signal_dest->get_name().c_str());
53
54    // need an internal signal ?
55    bool src_is_port  = entity_src  == _entity;
56    bool dest_is_port = entity_dest == _entity;
57
58    if (src_is_port == true)
59      throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", try map \""+component_src+"."+port_src+"\" with \""+component_dest+"."+port_dest+"\" but the component \""+component_src+" is the Top_level, and we can't be use interface's port of the top level as a source."));
60   
61    // 2 cases :
62    //  a) dest is a top level port -> direct connection
63    //  b) dest is a component port -> need internal signal
64    if (dest_is_port == false)
65      {
66        // 1) find productor of signal
67        //       
68        // Interface      Component
69        //    |          |         
70        //  ----> (IN)     --X-> (IN)
71        //    |          |         
72        //  <-X-- (OUT)    <---- (OUT)
73        //    |              |       
74       
75        Signal * signal_productor;
76        Entity * entity_productor;
77
78        bool     src_is_productor = (signal_src->get_direction() == OUT);
79
80        if (src_is_productor == true)
81          {
82            signal_productor = signal_src;
83            entity_productor = entity_src;
84          }
85        else
86          {
87            signal_productor = signal_dest;
88            entity_productor = entity_dest;
89          }
90
91        signal_dest= signal_internal (entity_productor, signal_productor);
92        signal_dest->set_size_max(signal_src->get_size());
93
94        dest_is_port = false;
95      }
96   
97    try
98      {
99        signal_src->link(signal_dest,
100                         dest_is_port);
101      }
102    catch (morpheo::ErrorMorpheo & error)
103      {
104        throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", try map \""+component_src+"."+port_src+"\" with \""+component_dest+"."+port_dest+"\" but "+error.what ()));
105      }
106    //catch (...)
107    //  {
108    //  }
109
110    log_printf(FUNC,Behavioural,FUNCTION,"End");
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.