Added the optional C keyword "volatile" to the __asm__ statement grammar.

It prevents the statement's Assembly code from being optimized (e.g., moved or removed).  Optimization is disabled for that statement's entire function (other functions aren't affected).
This commit is contained in:
Greg King
2016-04-22 11:33:52 -04:00
parent 62c2177599
commit 2c7ccca210
2 changed files with 68 additions and 50 deletions

View File

@@ -41,12 +41,14 @@
/* cc65 */
#include "asmlabel.h"
#include "codegen.h"
#include "codeseg.h"
#include "datatype.h"
#include "error.h"
#include "expr.h"
#include "function.h"
#include "litpool.h"
#include "scanner.h"
#include "segments.h"
#include "stackptr.h"
#include "symtab.h"
#include "asmstmt.h"
@@ -422,6 +424,15 @@ void AsmStatement (void)
/* Skip the ASM */
NextToken ();
/* An optional volatile qualifier disables optimization for
** the entire function [same as #pragma optimize(push, off)].
*/
if (CurTok.Tok == TOK_VOLATILE) {
/* Don't optimize the Current code Segment */
CS->Code->Optimize = 0;
NextToken ();
}
/* Need left parenthesis */
if (!ConsumeLParen ()) {
return;