[31] | 1 | /* |
---|
| 2 | * $Id$ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
[42] | 8 | #include "Behavioural/include/Component.h" |
---|
[31] | 9 | |
---|
| 10 | namespace morpheo { |
---|
| 11 | namespace behavioural { |
---|
| 12 | |
---|
[43] | 13 | #undef FUNCTION |
---|
| 14 | #define FUNCTION "Component::port_map" |
---|
[75] | 15 | void Component::port_map (std::string component_src , |
---|
| 16 | std::string port_src , |
---|
| 17 | std::string component_dest, |
---|
| 18 | std::string port_dest ) |
---|
[31] | 19 | { |
---|
[43] | 20 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
| 21 | |
---|
[75] | 22 | std::string name_entity = _entity->get_name(); |
---|
[31] | 23 | |
---|
[42] | 24 | // First entity |
---|
| 25 | Entity * entity_dest = find_entity(component_dest); |
---|
[31] | 26 | |
---|
[76] | 27 | |
---|
[42] | 28 | if (entity_dest == NULL) |
---|
[76] | 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.")); |
---|
[31] | 30 | |
---|
[42] | 31 | Signal * signal_dest = entity_dest->find_signal (port_dest); |
---|
[31] | 32 | |
---|
[42] | 33 | if (signal_dest == NULL) |
---|
[76] | 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+"\".")); |
---|
[31] | 35 | |
---|
[42] | 36 | // Second entity |
---|
| 37 | Entity * entity_src = find_entity(component_src); |
---|
[31] | 38 | |
---|
[42] | 39 | if (entity_src == NULL) |
---|
[76] | 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.")); |
---|
[31] | 41 | |
---|
[42] | 42 | Signal * signal_src = entity_src->find_signal (port_src); |
---|
[31] | 43 | |
---|
[42] | 44 | if (signal_src == NULL) |
---|
[76] | 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+"\".")); |
---|
[31] | 46 | |
---|
[42] | 47 | // If all is ok, mapping |
---|
[44] | 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()); |
---|
[43] | 53 | |
---|
[62] | 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) |
---|
[76] | 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.")); |
---|
[43] | 60 | |
---|
[62] | 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 | |
---|
[65] | 91 | signal_dest= signal_internal (entity_productor, signal_productor); |
---|
| 92 | signal_dest->set_size_max(signal_src->get_size()); |
---|
| 93 | |
---|
[62] | 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 | { |
---|
[76] | 104 | throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", try map \""+component_src+"."+port_src+"\" with \""+component_dest+"."+port_dest+"\" but "+error.what ())); |
---|
[62] | 105 | } |
---|
| 106 | //catch (...) |
---|
| 107 | // { |
---|
| 108 | // } |
---|
| 109 | |
---|
[43] | 110 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
[31] | 111 | }; |
---|
| 112 | |
---|
[75] | 113 | void Component::port_map (std::string component_src , |
---|
| 114 | std::string port_src ) |
---|
[62] | 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.")); |
---|
[65] | 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()); |
---|
[62] | 140 | |
---|
| 141 | try |
---|
| 142 | { |
---|
[65] | 143 | signal_src->link(signal_dest, |
---|
[62] | 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 | |
---|
[31] | 157 | }; // end namespace behavioural |
---|
| 158 | }; // end namespace morpheo |
---|
[62] | 159 | |
---|