Page 1 of 1

Error compiling CRC code

Posted: 07 June 2008, 15:28 PM
by Don_Kirby
The code shown below returns the error message
Compiler wrote: CRCError.bas:9: Internal Error: no means to generate code for expression

Code: Select all

Sub Main()
	Dim CRC as UnsignedInteger
	Dim DataCount as Integer
	Dim BufferQ(1 to 100) as Byte
	Dim ReceivedCRC as UnsignedInteger
	DataCount = 10
	CRC = CRC16(BufferQ(1), DataCount, &H8005, &Hffff, zxCRCRefIn Or zxCRCRefOut) 
	'ReceivedCRC = MakeWord(BufferQ(DataCount+1), BufferQ(DataCount + 2))
	If CRC <> ReceivedCRC Then
		'Do some work		
	End If
End Sub
Code details aside, the 'Internal Error' is indicative of a compiler issue.

The three functional bits...

Code: Select all

	CRC = CRC16&#40;BufferQ&#40;1&#41;, DataCount, &H8005, &Hffff, zxCRCRefIn Or zxCRCRefOut&#41; 

Code: Select all

	ReceivedCRC = MakeWord&#40;BufferQ&#40;DataCount+1&#41;, BufferQ&#40;DataCount + 2&#41;&#41;

Code: Select all

	If CRC <> ReceivedCRC Then
		'Do some work		
	End If
...all compile correctly if the other two are commented out.

-Don

Re: Error compiling CRC code

Posted: 07 June 2008, 15:58 PM
by dkinzer
Don_Kirby wrote:The code shown below returns the error message
Thanks for reporting this. We should still have time to figure out the solution and get it in before the final test run for the upcoming release.

Oddly, the error only occurs when compiling for native mode devices. Moreover, it's not related to the functions that you're using; the following simpler test case produces the same result.

Code: Select all

Dim b1 as Byte
Dim b2 as Byte
Sub Main&#40;&#41;
  b1 = Register.PortA
  b2 = Register.PortC
  If &#40;b1 <> b2&#41; Then
  End If
End Sub

Posted: 07 June 2008, 16:48 PM
by dkinzer
The source of the problem has been located and a likely solution identified. You can work around the problem by putting a useful statement inside the If as shown in the test case below or by turning off optimization (use the compiler option optimize=no-optimize). Doing the latter shouldn't have a significant effect, if any, on the code size in native mode since the backend compiler will still be optimizing.

Code: Select all

Sub Main&#40;&#41;
  Dim b1 as Byte
  Dim b2 as Byte
  b1 = Register.PortA
  b2 = Register.PortC
  If &#40;b1 <> b2&#41; Then
    Debug.Print
  End If
End Sub