TOKEN ChkControl( void ) { int lines_skipped; ppctl_t old_ppctl; if( !CompFlags.doing_macro_expansion ) { if( CompFlags.cpp_output ) { PrintWhiteSpace = FALSE; } } while( CurrChar == '\n' ) { if( TBreak() ) { CErr1( ERR_BREAK_KEY_HIT ); CSuicide(); } lines_skipped = 0; old_ppctl = CompFlags.pre_processing; for( ; CurrChar != EOF_CHAR; ) { if( CompFlags.cpp_output ) { CppPrtChar( '\n' ); } NextChar(); if( CurrChar != PreProcChar ) { SkipAhead(); } if( CurrChar == EOF_CHAR ) break; if( CurrChar == PreProcChar ) { /* start of comp control line */ PPCTL_ENABLE_EOL(); PPCTL_DISABLE_MACROS(); PreProcStmt(); PPFlush2EOL(); CompFlags.pre_processing = old_ppctl; } else if( NestLevel != SkipLevel ) { PPCTL_ENABLE_EOL(); PPCTL_DISABLE_MACROS(); PPNextToken(); /* get into token mode */ PPFlush2EOL(); CompFlags.pre_processing = old_ppctl; } if( NestLevel == SkipLevel ) break; if( CurrChar == '\n' ) { lines_skipped = 1; } } if( CompFlags.cpp_output ) { if( lines_skipped ) { if( SrcFile != NULL ) { /* 14-may-92 */ EmitLine( SrcFile->src_loc.line, SrcFile->src_name ); } } } } // we have already skipped past all white space at the start of the line CurToken = T_WHITE_SPACE; // CurToken = ScanToken(); return( T_WHITE_SPACE ); }
static void GetAsmLine( void ) /****************************/ { unsigned AsmErrLine; TOKEN LastToken; char buf[ MAX_ASM_LINE_LEN + 1 ]; PPCTL_ENABLE_EOL(); AsmErrLine = TokenLoc.line; *buf = '\0'; if( strcmp( Buffer, "_emit" ) == 0 ) { strcpy( buf, AsmSysDefineByte() ); NextToken(); } LastToken = T_DOT; for( ;; ) { if( EndOfAsmStmt() ) break; if(( LastToken != T_DOT ) && ( LastToken != T_BAD_CHAR ) && ( CurToken != T_XOR )) strncat( buf, " ", MAX_ASM_LINE_LEN ); strncat( buf, Buffer, MAX_ASM_LINE_LEN ); LastToken = CurToken; NextToken(); } buf[ MAX_ASM_LINE_LEN ] = '\0'; if( *buf != '\0' ) { TokenLoc.line = AsmErrLine; AsmSysLine( buf ); } PPCTL_DISABLE_EOL(); }
MEPTR DefineCmdLineMacro( // DEFINE A MACRO FROM THE COMMAND LINE // (assumes position is one char after "-D") bool many_tokes ) // - true ==> scan multiple tokens { MEPTR mptr; int (*old_scanner)( void ); ppctl_t old_ppctl; old_scanner = NextChar; old_ppctl = PPControl; NextChar = &SrcFileCmdLnGetChar; PPCTL_ENABLE_EOL(); PPCTL_DISABLE_MACROS(); SrcFileCmdLnDummyOpen(); CurrChar = NextChar(); if( many_tokes ) { mptr = MacroScan( MSCAN_CMDLN_PLUS ); } else { mptr = MacroScan( MSCAN_CMDLN_NORMAL ); } SrcFileCmdLnDummyClose(); NextChar = old_scanner; PPControl = old_ppctl; return( mptr ); }
TOKEN NextTokenSkipEOL( void ) /****************************/ { PPCTL_DISABLE_EOL(); NextToken(); PPCTL_ENABLE_EOL(); return( CurToken ); }
REWRITE *RewritePackageFunction( PTREE multi ) /********************************************/ { ppctl_t old_ppctl; bool skip_first; REWRITE *r; unsigned depth; unsigned asm_depth; TOKEN_LOCN locn; TOKEN_LOCN *plocn; skip_first = FALSE; r = ParseGetRecordingInProgress( &plocn ); if( r == NULL ) { plocn = &locn; r = newREWRITE( T_RIGHT_BRACE, &locn ); } else { skip_first = TRUE; } captureMulti( r, multi, plocn ); old_ppctl = PPControl; asm_depth = 0; depth = 1; /* we've seen one '{' */ while( CurToken != T_EOF ) { DbgAssert( depth != 0 ); switch( CurToken ) { case T_NULL: DbgAssert( asm_depth != 0 ); PPCTL_DISABLE_EOL(); if( depth == asm_depth ) { PPCTL_DISABLE_ASM(); asm_depth = 0; } break; case T___ASM: if( asm_depth == 0 ) { PPCTL_ENABLE_EOL(); PPCTL_ENABLE_ASM(); asm_depth = depth; } break; case T_SEMI_COLON: break; case T_LEFT_BRACE: case T_ALT_LEFT_BRACE: ++depth; break; case T_RIGHT_BRACE: case T_ALT_RIGHT_BRACE: --depth; if( depth == asm_depth ) { PPCTL_DISABLE_EOL(); PPCTL_DISABLE_ASM(); asm_depth = 0; } break; default: break; } if( ! skip_first ) { saveToken( r, plocn ); } skip_first = FALSE; if( depth == 0 ) break; NextToken(); if( PPControl & PPCTL_ASM ) { PPCTL_ENABLE_EOL(); } } PPControl = old_ppctl; return( r ); }
PTREE AsmStmt( void ) /*******************/ { bool uses_auto; AUX_INFO *auxinfo; TOKEN skip_token; TOKEN skip_alt_token; PTREE expr; TYPE fn_type; TYPE ret_type; SYMBOL sym; NAME fn_name; auto VBUF code_buffer; ppctl_t old_ppctl; old_ppctl = PPControl; PPCTL_ENABLE_EOL(); PPCTL_ENABLE_ASM(); VbufInit( &code_buffer ); NextTokenSkipEOL(); AsmSysInit(); if( ( CurToken == T_LEFT_BRACE ) || ( CurToken == T_ALT_LEFT_BRACE ) ) { NextTokenSkipEOL(); for(;;) { getAsmLine( &code_buffer ); if( CurToken == T_RIGHT_BRACE ) break; if( CurToken == T_ALT_RIGHT_BRACE ) break; if( CurToken == T_EOF ) break; NextTokenSkipEOL(); } skip_token = T_RIGHT_BRACE; skip_alt_token = T_ALT_RIGHT_BRACE; } else { getAsmLine( &code_buffer ); skip_token = skip_alt_token = T_NULL; } PPControl = old_ppctl; if( ( CurToken == skip_token ) || ( CurToken == skip_alt_token ) ) { NextToken(); } if( AsmCodeAddress != 0 ) { fn_name = NameDummy(); auxinfo = AsmSysCreateAux( NameStr( fn_name ) ); uses_auto = AsmSysInsertFixups( &code_buffer ); if( uses_auto ) { AsmSysUsesAuto(); } AsmSysDone(); ret_type = GetBasicType( TYP_VOID ); fn_type = MakeModifiableFunction( ret_type, NULL ); fn_type->u.f.pragma = auxinfo; fn_type = CheckDupType( fn_type ); sym = SymCreateFileScope( fn_type, SC_NULL, SF_NULL, fn_name ); LinkageSet( sym, "C" ); expr = genFnCall( fn_name ); } else { expr = NULL; } AsmSysFini(); VbufFree( &code_buffer ); return( expr ); }