sc_port.hh (13273:af60ddcf2a32) | sc_port.hh (13290:1e720f971554) |
---|---|
1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright --- 87 unchanged lines hidden (view full) --- 96 virtual int vbind(sc_interface &) = 0; 97 virtual int vbind(sc_port_base &) = 0; 98 99 virtual void before_end_of_elaboration() = 0; 100 virtual void end_of_elaboration() = 0; 101 virtual void start_of_simulation() = 0; 102 virtual void end_of_simulation() = 0; 103 | 1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright --- 87 unchanged lines hidden (view full) --- 96 virtual int vbind(sc_interface &) = 0; 97 virtual int vbind(sc_port_base &) = 0; 98 99 virtual void before_end_of_elaboration() = 0; 100 virtual void end_of_elaboration() = 0; 101 virtual void start_of_simulation() = 0; 102 virtual void end_of_simulation() = 0; 103 |
104 void report_error(const char *id, const char *add_msg) const; 105 |
|
104 private: 105 friend class ::sc_gem5::Port; 106 friend class ::sc_gem5::Kernel; 107 108 virtual sc_interface *_gem5Interface(int n) const = 0; 109 virtual void _gem5AddInterface(sc_interface *i) = 0; 110 111 ::sc_gem5::Port *_gem5Port; --- 8 unchanged lines hidden (view full) --- 120 void operator () (sc_port_b<IF> &p) { bind(p); } 121 122 virtual void bind(IF &i) { sc_port_base::bind(i); } 123 virtual void bind(sc_port_b<IF> &p) { sc_port_base::bind(p); } 124 125 IF * 126 operator -> () 127 { | 106 private: 107 friend class ::sc_gem5::Port; 108 friend class ::sc_gem5::Kernel; 109 110 virtual sc_interface *_gem5Interface(int n) const = 0; 111 virtual void _gem5AddInterface(sc_interface *i) = 0; 112 113 ::sc_gem5::Port *_gem5Port; --- 8 unchanged lines hidden (view full) --- 122 void operator () (sc_port_b<IF> &p) { bind(p); } 123 124 virtual void bind(IF &i) { sc_port_base::bind(i); } 125 virtual void bind(sc_port_b<IF> &p) { sc_port_base::bind(p); } 126 127 IF * 128 operator -> () 129 { |
128 sc_assert(!_interfaces.empty()); | 130 if (_interfaces.empty()) { 131 report_error("(E112) get interface failed", "port is not bound"); 132 sc_abort(); 133 } |
129 return _interfaces[0]; 130 } 131 const IF * 132 operator -> () const 133 { | 134 return _interfaces[0]; 135 } 136 const IF * 137 operator -> () const 138 { |
134 sc_assert(!_interfaces.empty()); | 139 if (_interfaces.empty()) { 140 report_error("(E112) get interface failed", "port is not bound"); 141 sc_abort(); 142 } |
135 return _interfaces[0]; 136 } 137 138 IF * 139 operator [] (int n) 140 { | 143 return _interfaces[0]; 144 } 145 146 IF * 147 operator [] (int n) 148 { |
141 sc_assert(_interfaces.size() > n); | 149 if (n < 0 || n >= size()) { 150 report_error("(E112) get interface failed", "index out of range"); 151 return NULL; 152 } |
142 return _interfaces[n]; 143 } 144 const IF * 145 operator [] (int n) const 146 { | 153 return _interfaces[n]; 154 } 155 const IF * 156 operator [] (int n) const 157 { |
147 sc_assert(_interfaces.size() > n); | 158 if (n < 0 || n >= size()) { 159 report_error("(E112) get interface failed", "index out of range"); 160 return NULL; 161 } |
148 return _interfaces[n]; 149 } 150 151 sc_interface * 152 get_interface() 153 { | 162 return _interfaces[n]; 163 } 164 165 sc_interface * 166 get_interface() 167 { |
154 sc_assert(!_interfaces.empty()); | 168 if (_interfaces.empty()) 169 return NULL; |
155 return _interfaces[0]; 156 } 157 const sc_interface * 158 get_interface() const 159 { | 170 return _interfaces[0]; 171 } 172 const sc_interface * 173 get_interface() const 174 { |
160 sc_assert(!_interfaces.empty()); | 175 if (_interfaces.empty()) 176 return NULL; |
161 return _interfaces[0]; 162 } 163 164 protected: 165 void before_end_of_elaboration() {} 166 void end_of_elaboration() {} 167 void start_of_simulation() {} 168 void end_of_simulation() {} --- 27 unchanged lines hidden (view full) --- 196 } 197 198 private: 199 std::vector<IF *> _interfaces; 200 201 sc_interface * 202 _gem5Interface(int n) const 203 { | 177 return _interfaces[0]; 178 } 179 180 protected: 181 void before_end_of_elaboration() {} 182 void end_of_elaboration() {} 183 void start_of_simulation() {} 184 void end_of_simulation() {} --- 27 unchanged lines hidden (view full) --- 212 } 213 214 private: 215 std::vector<IF *> _interfaces; 216 217 sc_interface * 218 _gem5Interface(int n) const 219 { |
204 sc_assert(_interfaces.size() > n); | 220 if (n < 0 || n >= size()) { 221 report_error("(E112) get interface failed", "index out of range"); 222 return NULL; 223 } |
205 return _interfaces[n]; 206 } 207 void | 224 return _interfaces[n]; 225 } 226 void |
208 _gem5AddInterface(sc_interface *i) | 227 _gem5AddInterface(sc_interface *iface) |
209 { | 228 { |
210 IF *interface = dynamic_cast | 229 IF *interface = dynamic_cast<IF *>(iface); |
211 sc_assert(interface); | 230 sc_assert(interface); |
231 for (int i = 0; i < _interfaces.size(); i++) { 232 if (interface == _interfaces[i]) { 233 report_error("(E107) bind interface to port failed", 234 "interface already bound to port"); 235 } 236 } |
|
212 _interfaces.push_back(interface); 213 } 214 215 const char *_ifTypeName() const { return typeid(IF).name(); } 216 217 // Disabled 218 sc_port_b() {} 219 sc_port_b(const sc_port_b<IF> &) {} --- 62 unchanged lines hidden --- | 237 _interfaces.push_back(interface); 238 } 239 240 const char *_ifTypeName() const { return typeid(IF).name(); } 241 242 // Disabled 243 sc_port_b() {} 244 sc_port_b(const sc_port_b<IF> &) {} --- 62 unchanged lines hidden --- |