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 --- 19 unchanged lines hidden (view full) --- 28 */ 29 30#ifndef __SYSTEMC_EXT_CORE_SC_PORT_HH__ 31#define __SYSTEMC_EXT_CORE_SC_PORT_HH__ 32 33#include <typeinfo> 34#include <vector> 35 |
36#include "../channel/messages.hh" |
37#include "../utils/sc_report_handler.hh" 38#include "sc_module.hh" // for sc_gen_unique_name 39#include "sc_object.hh" 40 41namespace sc_gem5 42{ 43 44class Port; --- 80 unchanged lines hidden (view full) --- 125 126 virtual void bind(IF &i) { sc_port_base::bind(i); } 127 virtual void bind(sc_port_b<IF> &p) { sc_port_base::bind(p); } 128 129 IF * 130 operator -> () 131 { 132 if (_interfaces.empty()) { |
133 report_error(SC_ID_GET_IF_, "port is not bound"); |
134 sc_abort(); 135 } 136 return _interfaces[0]; 137 } 138 const IF * 139 operator -> () const 140 { 141 if (_interfaces.empty()) { |
142 report_error(SC_ID_GET_IF_, "port is not bound"); |
143 sc_abort(); 144 } 145 return _interfaces[0]; 146 } 147 148 IF * 149 operator [] (int n) 150 { 151 if (n < 0 || n >= size()) { |
152 report_error(SC_ID_GET_IF_, "index out of range"); |
153 return NULL; 154 } 155 return _interfaces[n]; 156 } 157 const IF * 158 operator [] (int n) const 159 { 160 if (n < 0 || n >= size()) { |
161 report_error(SC_ID_GET_IF_, "index out of range"); |
162 return NULL; 163 } 164 return _interfaces[n]; 165 } 166 167 sc_interface * 168 get_interface() 169 { --- 45 unchanged lines hidden (view full) --- 215 216 private: 217 std::vector<IF *> _interfaces; 218 219 sc_interface * 220 _gem5Interface(int n) const 221 { 222 if (n < 0 || n >= size()) { |
223 report_error(SC_ID_GET_IF_, "index out of range"); |
224 return NULL; 225 } 226 return _interfaces[n]; 227 } 228 void 229 _gem5AddInterface(sc_interface *iface) 230 { 231 IF *interface = dynamic_cast<IF *>(iface); 232 sc_assert(interface); 233 for (int i = 0; i < _interfaces.size(); i++) { 234 if (interface == _interfaces[i]) { |
235 report_error(SC_ID_BIND_IF_TO_PORT_, |
236 "interface already bound to port"); 237 } 238 } 239 _interfaces.push_back(interface); 240 } 241 242 const char *_ifTypeName() const { return typeid(IF).name(); } 243 --- 67 unchanged lines hidden --- |