[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" |
---|
[42] | 15 | void Component::port_map (string component_src , |
---|
| 16 | string port_src , |
---|
| 17 | string component_dest, |
---|
| 18 | string port_dest ) |
---|
[31] | 19 | { |
---|
[43] | 20 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
| 21 | |
---|
[42] | 22 | string name_entity = _entity->get_name(); |
---|
[31] | 23 | |
---|
[42] | 24 | // First entity |
---|
| 25 | Entity * entity_dest = find_entity(component_dest); |
---|
[31] | 26 | |
---|
[42] | 27 | if (entity_dest == NULL) |
---|
[43] | 28 | throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", port map with unknow component \""+component_dest+"\".")); |
---|
[31] | 29 | |
---|
[42] | 30 | Signal * signal_dest = entity_dest->find_signal (port_dest); |
---|
[31] | 31 | |
---|
[42] | 32 | if (signal_dest == NULL) |
---|
[43] | 33 | throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", port map with component \""+component_dest+"\" and a unknow signal \""+port_dest+"\".")); |
---|
[31] | 34 | |
---|
[42] | 35 | // Second entity |
---|
| 36 | Entity * entity_src = find_entity(component_src); |
---|
[31] | 37 | |
---|
[42] | 38 | if (entity_src == NULL) |
---|
[43] | 39 | throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", port map with unknow component \""+component_src+"\".")); |
---|
[31] | 40 | |
---|
[42] | 41 | Signal * signal_src = entity_src->find_signal (port_src); |
---|
[31] | 42 | |
---|
[42] | 43 | if (signal_src == NULL) |
---|
[43] | 44 | throw (ErrorMorpheo ("<Component::port_map> in component \""+name_entity+"\", port map with component \""+component_src+"\" and a unknow signal \""+port_src+"\".")); |
---|
[31] | 45 | |
---|
[42] | 46 | // If all is ok, mapping |
---|
[44] | 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()); |
---|
[43] | 52 | |
---|
[62] | 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.")); |
---|
[43] | 59 | |
---|
[62] | 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 | dest_is_port = false; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | try |
---|
| 95 | { |
---|
| 96 | signal_src->link(signal_dest, |
---|
| 97 | dest_is_port); |
---|
| 98 | } |
---|
| 99 | catch (morpheo::ErrorMorpheo & error) |
---|
| 100 | { |
---|
| 101 | 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 ())); |
---|
| 102 | } |
---|
| 103 | //catch (...) |
---|
| 104 | // { |
---|
| 105 | // } |
---|
| 106 | |
---|
[43] | 107 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
[31] | 108 | }; |
---|
| 109 | |
---|
[62] | 110 | |
---|
| 111 | void Component::port_map (string component_src , |
---|
| 112 | string port_src ) |
---|
| 113 | { |
---|
| 114 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
| 115 | |
---|
| 116 | Entity * entity_src = find_entity(component_src); |
---|
| 117 | |
---|
| 118 | if (entity_src == NULL) |
---|
| 119 | throw (ErrorMorpheo ("<Component::port_map> in component \""+_entity->get_name()+"\", port map with unknow component \""+component_src+"\".")); |
---|
| 120 | |
---|
| 121 | Signal * signal_src = entity_src->find_signal (port_src); |
---|
| 122 | |
---|
| 123 | if (signal_src == NULL) |
---|
| 124 | throw (ErrorMorpheo ("<Component::port_map> in component \""+_entity->get_name()+"\", port map with component \""+component_src+"\" and a unknow signal \""+port_src+"\".")); |
---|
| 125 | |
---|
| 126 | // need an internal signal ? |
---|
| 127 | |
---|
| 128 | if (entity_src == _entity) |
---|
| 129 | throw (ErrorMorpheo ("<Component::port_map> src can't be an interface's port of the top level.")); |
---|
| 130 | |
---|
| 131 | if (signal_src->get_direction() != OUT) |
---|
| 132 | throw (ErrorMorpheo ("<Component::port_map> the direction of the signal '"+signal_src->get_name()+"' must be OUT.")); |
---|
| 133 | |
---|
| 134 | try |
---|
| 135 | { |
---|
| 136 | signal_src->link(signal_internal (entity_src, signal_src), |
---|
| 137 | false); |
---|
| 138 | } |
---|
| 139 | catch (morpheo::ErrorMorpheo & error) |
---|
| 140 | { |
---|
| 141 | throw (ErrorMorpheo ("<Component::port_map> Error in mapping "+entity_src ->get_name()+"."+signal_src ->get_name()+" :\n"+error.what ())); |
---|
| 142 | } |
---|
| 143 | //catch (...) |
---|
| 144 | // { |
---|
| 145 | // } |
---|
| 146 | |
---|
| 147 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
| 148 | }; |
---|
| 149 | |
---|
[31] | 150 | }; // end namespace behavioural |
---|
| 151 | }; // end namespace morpheo |
---|
[62] | 152 | |
---|