Verify that IFs, REPTs and MACROs are terminated

Ensure that IF constructs, REPT blocks, and MACRO defintions are terminated with ENDC, ENDR, or ENDM respectively. If they are not, print an error and stop assembly.

As well as aiding a forgetful programmer, this reduces the risk of memory problems if the file ends less than four bytes after the block starts.
This commit is contained in:
Ben10do
2017-02-02 16:27:53 +00:00
parent 547abfefc1
commit 38372c59ed

View File

@@ -182,6 +182,10 @@ void copyrept( void )
} }
} }
if (level != 0) {
fatalerror("Unterminated REPT block");
}
len=src-pCurrentBuffer->pBuffer-4; len=src-pCurrentBuffer->pBuffer-4;
src=pCurrentBuffer->pBuffer; src=pCurrentBuffer->pBuffer;
@@ -257,6 +261,10 @@ void copymacro( void )
} }
} }
if (level != 0) {
fatalerror("Unterminated MACRO definition");
}
len=src-pCurrentBuffer->pBuffer-4; len=src-pCurrentBuffer->pBuffer-4;
src=pCurrentBuffer->pBuffer; src=pCurrentBuffer->pBuffer;
@@ -348,6 +356,10 @@ void if_skip_to_else( void )
} }
} }
if (level != 0) {
fatalerror("Unterminated IF construct");
}
len=src-pCurrentBuffer->pBuffer; len=src-pCurrentBuffer->pBuffer;
yyskipbytes( len ); yyskipbytes( len );
@@ -403,6 +415,10 @@ void if_skip_to_endc( void )
} }
} }
if (level != 0) {
fatalerror("Unterminated IF construct");
}
len=src-pCurrentBuffer->pBuffer; len=src-pCurrentBuffer->pBuffer;
yyskipbytes( len ); yyskipbytes( len );