Compiler Issue

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
gerrykurz
XCore Addict
Posts: 204
Joined: Sun Jun 01, 2014 10:25 pm

Compiler Issue

Post by gerrykurz »

Can someone explain why the first bit of code builds without errors and the second bit of code generates this error

mii_filter.xc:102: error: case not terminated with a break or return
Basically the only change to the second bit of code is to remove a lot of the conditional assembly and to change the filter result routine a bit.

Code: Select all


	while (1)
	{
		select
		{
#pragma xta endpoint "rx_packet"
			case (int ifnum=0; ifnum<NUM_ETHERNET_PORTS; ifnum++) c[ifnum] :> buf :
			{
				if (buf)
				{
					int length = mii_packet_get_length(buf);

#if ETHERNET_RX_CRC_ERROR_CHECK
					unsigned poly = 0xEDB88320;
					unsigned crc = mii_packet_get_crc(buf);
					int endbytes;
					int tail;

					tail = mii_packet_get_data(buf,((length & 0xFFFFFFFC)/4)+1);

					endbytes = (length & 3);

					switch (endbytes)
					{
						case 0:
							break;
						case 1:
							tail = crc8shr(crc, tail, poly);
							break;
						case 2:
							tail = crc8shr(crc, tail, poly);
							tail = crc8shr(crc, tail, poly);
							break;
						case 3:
							tail = crc8shr(crc, tail, poly);
							tail = crc8shr(crc, tail, poly);
							tail = crc8shr(crc, tail, poly);
							break;
					}
#endif
					mii_packet_set_src_port(buf,ifnum);

					if (length < 60)
					{
#if ETHERNET_COUNT_PACKETS
						ethernet_filtered_by_length++;
#endif
						mii_packet_set_filter_result(buf, 0);
						mii_packet_set_stage(buf,1);
					}
#if ETHERNET_RX_CRC_ERROR_CHECK
					else if (~crc)
					{
#if ETHERNET_COUNT_PACKETS
						ethernet_filtered_by_bad_crc++;
#endif
						mii_packet_set_filter_result(buf, 0);
						mii_packet_set_stage(buf,1);

					}
#endif
					else
					{
						int broadcast = is_broadcast(buf);
						int unicast = compare_mac(buf,mac);
						int res=0;
#if (NUM_ETHERNET_PORTS > 1) && !defined(DISABLE_ETHERNET_PORT_FORWARDING)
						if (!unicast) {
							res |= MII_FILTER_FORWARD_TO_OTHER_PORTS;
						}
#endif
#ifdef MAC_PROMISCUOUS
						if (1) {
#else
							if (broadcast || unicast) {
#endif
								int filter_result = mac_custom_filter_coerce(buf);
#if ETHERNET_COUNT_PACKETS
								if (filter_result == 0) ethernet_filtered_by_user_filter++;
#endif
								res |= filter_result;
							} else {
#if ETHERNET_COUNT_PACKETS
								ethernet_filtered_by_address++;
#endif
							}
							mii_packet_set_filter_result(buf, res);
							mii_packet_set_stage(buf, 1);
						}
					}
					break;
				} // end if (buf)
			} // end case()
		} // end select
	} // end while (1)



Code: Select all


	while (1)
	{
		select
		{
#pragma xta endpoint "rx_packet"
			case (int ifnum=0; ifnum<NUM_ETHERNET_PORTS; ifnum++) c[ifnum] :> buf :
			{
				if (buf)
				{
					int length = mii_packet_get_length(buf);

					unsigned poly = 0xEDB88320;
					unsigned crc = mii_packet_get_crc(buf);
					int endbytes;
					int tail;

					tail = mii_packet_get_data(buf,((length & 0xFFFFFFFC)/4)+1);

					endbytes = (length & 3);

					switch (endbytes)
					{
						case 0:
							break;
						case 1:
							tail = crc8shr(crc, tail, poly);
							break;
						case 2:
							tail = crc8shr(crc, tail, poly);
							tail = crc8shr(crc, tail, poly);
							break;
						case 3:
							tail = crc8shr(crc, tail, poly);
							tail = crc8shr(crc, tail, poly);
							tail = crc8shr(crc, tail, poly);
							break;
					}
					mii_packet_set_src_port(buf,ifnum);

					if (length < 60)
					{
						ethernet_filtered_by_length++;
						mii_packet_set_filter_result(buf, 0);
						mii_packet_set_stage(buf,1);
					}
					else if (~crc)
					{
						ethernet_filtered_by_bad_crc++;
						mii_packet_set_filter_result(buf, 0);
						mii_packet_set_stage(buf,1);
					}
					else
					{
					    filter_result = 0;
						broadcast = check_for_broadcast(buf);
						our_address = compare_own_mac(buf,own_mac);
						xmos_address = compare_xmos_mac(buf,xmos_mac);

						if (broadcast || our_address)
						{
							filter_result = mac_custom_filter_coerce(buf);
							if (filter_result == 0) ethernet_filtered_by_user_filter++;
						}
						if (broadcast || (xmos_address && !our_address))
						{
						    filter_result |= REPEAT_PACKET_TO_OTHER_PORTS;
						}
						if (!(broadcast || xmos_address))
						{
							ethernet_filtered_by_address++;
						}
						mii_packet_set_filter_result(buf, filter_result);
						mii_packet_set_stage(buf, 1);
					}
		            break;
				} // end if (buf)
			} // end case()
//            break;
		} // end select
	} // end while (1)
}
If I uncomment the second break above, it compiles without error. This seems like a compiler bug to me.....


User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am

Post by mon2 »

break;
} // end if (buf)
} // end case()


Should the break statement above be there ?
User avatar
gerrykurz
XCore Addict
Posts: 204
Joined: Sun Jun 01, 2014 10:25 pm

Post by gerrykurz »

My point is that one compiles and the other does not with the break statement in the same place....
User avatar
davelacey
Experienced Member
Posts: 104
Joined: Fri Dec 11, 2009 8:29 pm

Post by davelacey »

The break is not in the same place. Code snippet 2 has 5 closing braces after the break whereas code snippet 1 has 4 closing braces.

The problem here seems to be in the original ethernet code - the comments on the end braces are incorrect (for example the last closing brace will be for the function - not the while loop). In general, that function is very hard to follow. It looks like that code needs a tidy up to be more readable.
User avatar
davelacey
Experienced Member
Posts: 104
Joined: Fri Dec 11, 2009 8:29 pm

Post by davelacey »

I've created a pull request to tidy up this code:

https://github.com/xcore/sc_ethernet/pull/58
User avatar
gerrykurz
XCore Addict
Posts: 204
Joined: Sun Jun 01, 2014 10:25 pm

Post by gerrykurz »

Thanks, I see the difference now.

A lot of the ethernet code is hard to follow and could use a fair bit of tidying up and better documentation/comments in the source code and header files.

Best regards,

Gerry