181a182,196
> # determine the port->msg buffer mappings
> def getBufferMaps(self, ident):
> msg_bufs = []
> port_to_buf_map = {}
> in_msg_bufs = {}
> for port in self.in_ports:
> buf_name = "m_%s_ptr" % port.buffer_expr.name
> msg_bufs.append(buf_name)
> port_to_buf_map[port] = msg_bufs.index(buf_name)
> if buf_name not in in_msg_bufs:
> in_msg_bufs[buf_name] = [port]
> else:
> in_msg_bufs[buf_name].append(port)
> return port_to_buf_map, in_msg_bufs, msg_bufs
>
425a441
> #include <typeinfo>
938c954,960
< ${{action["c_code"]}}
---
> try {
> ${{action["c_code"]}}
> } catch (const RejectException & e) {
> fatal("Error in action ${{ident}}:${{action.ident}}: "
> "executed a peek statement with the wrong message "
> "type specified. ");
> }
1030a1053
> #include <typeinfo>
1053a1077,1078
> port_to_buf_map, in_msg_bufs, msg_bufs = self.getBufferMaps(ident)
>
1062a1088,1089
> unsigned char rejected[${{len(msg_bufs)}}];
> memset(rejected, 0, sizeof(unsigned char)*${{len(msg_bufs)}});
1086a1114,1116
> if port in port_to_buf_map:
> code('try {')
> code.indent()
1088d1117
< code.dedent()
1089a1119,1126
> if port in port_to_buf_map:
> code.dedent()
> code('''
> } catch (const RejectException & e) {
> rejected[${{port_to_buf_map[port]}}]++;
> }
> ''')
> code.dedent()
1095c1132,1150
< break; // If we got this far, we have nothing left todo
---
> // If we got this far, we have nothing left todo or something went
> // wrong''')
> for buf_name, ports in in_msg_bufs.items():
> if len(ports) > 1:
> # only produce checks when a buffer is shared by multiple ports
> code('''
> if (${{buf_name}}->isReady() && rejected[${{port_to_buf_map[ports[0]]}}] == ${{len(ports)}})
> {
> // no port claimed the message on the top of this buffer
> panic("Runtime Error at Ruby Time: %d. "
> "All ports rejected a message. "
> "You are probably sending a message type to this controller "
> "over a virtual network that do not define an in_port for "
> "the incoming message type.\\n",
> Cycles(1));
> }
> ''')
> code('''
> break;
1172a1228,1229
> port_to_buf_map, in_msg_bufs, msg_bufs = self.getBufferMaps(ident)
>