// #pragma alias(id1/"name1", id2/"name2") // // Causes linker to replace references to id1/name1 with references // to id2/name2. Both the alias and the substituted symbol may be defined // either as a string name or an id of existing symbol. // static void PragAlias( void ) /***************************/ { SYM_HANDLE alias_sym; SYM_HANDLE subst_sym; const char *alias_name; const char *subst_name; alias_list **alias; alias_list *new_alias; alias_name = subst_name = NULL; alias_sym = subst_sym = NULL; if( ExpectingToken( T_LEFT_PAREN ) ) { PPCTL_ENABLE_MACROS(); PPNextToken(); if( CurToken == T_ID ) { alias_sym = SymLook( HashValue, Buffer ); if( alias_sym == 0 ) { CErr2p( ERR_UNDECLARED_SYM, Buffer ); } } else if( CurToken == T_STRING ) { alias_name = CStrSave( Buffer ); } PPNextToken(); MustRecog( T_COMMA ); if( CurToken == T_ID ) { subst_sym = SymLook( HashValue, Buffer ); if( subst_sym == 0 ) { CErr2p( ERR_UNDECLARED_SYM, Buffer ); } } else if( CurToken == T_STRING ) { subst_name = CStrSave( Buffer ); } PPNextToken(); PPCTL_DISABLE_MACROS(); MustRecog( T_RIGHT_PAREN ); } /* Add a new alias record - if it's valid - to the list */ if( ( alias_name != NULL || alias_sym != NULL ) && ( subst_name != NULL || subst_sym != NULL ) ) { for( alias = &AliasHead; *alias != NULL; alias = &(*alias)->next ) ; /* nothing to do */ new_alias = (void *)CMemAlloc( sizeof( alias_list ) ); new_alias->next = NULL; if( alias_name ) { new_alias->name = alias_name; } else { new_alias->a_sym = alias_sym; } if( subst_name ) { new_alias->subst = subst_name; } else { new_alias->s_sym = subst_sym; } *alias = new_alias; } }
static user_seg *AllocUserSeg( const char *segname, const char *class_name, seg_type segtype ) { user_seg *useg; useg = CMemAlloc( sizeof( user_seg ) ); useg->next = NULL; useg->name = CStrSave( segname ); useg->class_name = NULL; useg->segtype = segtype; if( class_name != NULL ) { useg->class_name = CStrSave( class_name ); } useg->segid = userSegment++; return( useg ); }
static struct user_seg *AllocUserSeg( char *segname, char *class_name, seg_type segtype ) { struct user_seg *useg; useg = CMemAlloc( sizeof( struct user_seg ) ); useg->next = NULL; useg->name = CStrSave( segname ); useg->class_name = NULL; useg->segtype = segtype; if( class_name != NULL ) { useg->class_name = CStrSave( class_name ); } useg->segment = UserSegment; ++UserSegment; return( useg ); }
static void PragDataSeg( void ) /* 22-oct-92 */ /*****************************/ { char *segname; segment_id segment; if( CurToken == T_LEFT_PAREN ) { PPCTL_ENABLE_MACROS(); segment = 0; NextToken(); if( ( CurToken == T_STRING ) || ( CurToken == T_ID ) ) { segname = CStrSave( Buffer ); NextToken(); if( CurToken == T_COMMA ) { NextToken(); if( ( CurToken == T_STRING ) || ( CurToken == T_ID ) ) { segment = AddSegName( segname, Buffer, SEGTYPE_DATA ); NextToken(); } else { segment = AddSegName( segname, NULL, SEGTYPE_DATA ); } } else { segment = AddSegName( segname, NULL, SEGTYPE_DATA ); } CMemFree( segname ); } PPCTL_DISABLE_MACROS(); MustRecog( T_RIGHT_PAREN ); DefDataSegment = segment; } }
void InitModInfo( void ) { GenSwitches = 0; TargetSwitches = 0; Toggles = TOGGLE_CHECK_STACK | TOGGLE_UNREFERENCED | TOGGLE_REUSE_DUPLICATE_STRINGS; DataThreshold = 32767; OptSize = 50; UndefNames = NULL; WholeFName = NULL; ObjectFileName = NULL; ErrorFileName = CStrSave( "*" ); DependFileName = NULL; DependForceSlash = 0; ModuleName = NULL; ErrLimit = 20; WngLevel = 1; #if _CPU == 8086 PackAmount = TARGET_INT; /* pack structs on word boundaries */ #elif _CPU == 386 PackAmount = 8; #else CompFlags.make_enums_an_int = 1; // make enums ints CompFlags.original_enum_setting = 1; PackAmount = 8; #endif PreProcChar = '#'; CompFlags.check_syntax = 0; CompFlags.signed_char = 0; CompFlags.use_full_codegen_od = 0; CompFlags.inline_functions = 0; CompFlags.dump_prototypes = 0; CompFlags.generate_prototypes = 0; CompFlags.bss_segment_used = 0; CompFlags.undefine_all_macros = 0; CompFlags.extensions_enabled = 1; CompFlags.oldmacros_enabled = 1; CompFlags.unix_ext = 0; CompFlags.slack_byte_warning = 0; CompFlags.errfile_written = 0; CompFlags.zu_switch_used = 0; CompFlags.register_conventions = 0; CompFlags.pragma_library = 0; CompFlags.emit_all_default_libs = 0; CompFlags.emit_library_names = 1; CompFlags.emit_dependencies = 1; CompFlags.emit_targimp_symbols = 1; CompFlags.use_unicode = 1; CompFlags.no_debug_type_names = 0; CompFlags.auto_agg_inits = 0; CompFlags.no_check_inits = 0; CompFlags.no_check_qualifiers = 0; CompFlags.ignore_default_dirs = 0; CompFlags.use_stdcall_at_number = 1; CompFlags.rent = 0; SetAuxWatcallInfo(); }
void PragObjNameInfo( char **objname ) /************************************/ { if( CurToken == T_STRING ) { *objname = CStrSave( Buffer ); NextToken(); } }
local void CopyExceptRtn( void ) /******************************/ { if( CurrInfo->except_rtn == NULL ) return; if( CurrInfo->except_rtn != CurrAlias->except_rtn ) return; CurrInfo->except_rtn = CStrSave( CurrInfo->except_rtn ); }
local void CopyObjName( void ) /****************************/ { if( CurrInfo->objname == NULL ) return; if( CurrInfo->objname != CurrAlias->objname ) return; CurrInfo->objname = CStrSave( CurrInfo->objname ); }
void LookAhead( void ) { SavedId = CStrSave( Buffer ); /* save current id */ SavedHash = HashValue; /* and its hash value */ SavedTokenLoc = TokenLoc; /* save linenum and fno 09-jul-95 */ NextToken(); /* get next token */ LAToken = CurToken; /* save it in look ahead */ CurToken = T_SAVED_ID; /* go back to saved id */ }
// forms: (1) #pragma include_alias( "alias_name", "real_name" ) // (2) #pragma include_alias( <alias_name>, <real_name> ) // // causes include directives referencing alias_name to be refer // to real_name instead // static void PragIncludeAlias( void ) /**********************************/ { if( ExpectingToken( T_LEFT_PAREN ) ) { PPCTL_ENABLE_MACROS(); NextToken(); if( CurToken == T_STRING ) { char *alias_name; alias_name = CStrSave( Buffer ); NextToken(); MustRecog( T_COMMA ); if( CurToken == T_STRING ) { SrcFileIncludeAlias( alias_name, Buffer, FALSE ); NextToken(); } CMemFree( alias_name ); } else if( CurToken == T_LT ) { char a_buf[ 82 ]; /* same size as CInclude() in cmac2.c */ char r_buf[ 82 ]; a_buf[ 0 ] = '\0'; for( ;; ) { NextToken(); if( CurToken == T_GT ) { NextToken(); break; } if( CurToken == T_NULL ) { break; } strncat( a_buf, Buffer, sizeof( a_buf ) - 2 ); } MustRecog( T_COMMA ); if( CurToken == T_LT ) { r_buf[ 0 ] = '\0'; for( ;; ) { NextToken(); if( CurToken == T_GT ) { NextToken(); break; } if( CurToken == T_NULL ) { break; } strncat( r_buf, Buffer, sizeof( r_buf ) - 2 ); } SrcFileIncludeAlias( a_buf, r_buf, TRUE ); } } PPCTL_DISABLE_MACROS(); MustRecog( T_RIGHT_PAREN ); } }
static char *ChunkToStr( STRCHUNK *pch ) { char *ret; /* remove spaces from end of string */ while( pch->cursize > 0 && pch->data[pch->cursize - 1] == ' ' ) { pch->data[--pch->cursize] = '\0'; } ret = pch->data; if( ret == NULL ) { ret = CStrSave( "" ); } return( ret ); }
static void PragCodeSeg( void ) /* 22-oct-92 */ /*****************************/ { textsegment *seg; char *segname; char *classname; if( CurToken == T_LEFT_PAREN ) { PPCTL_ENABLE_MACROS(); seg = NULL; NextToken(); if( ( CurToken == T_STRING ) || ( CurToken == T_ID ) ) { segname = CStrSave( Buffer ); classname = CStrSave( "" ); NextToken(); if( CurToken == T_COMMA ) { NextToken(); if( ( CurToken == T_STRING ) || ( CurToken == T_ID ) ) { CMemFree( classname ); classname = CStrSave( Buffer ); // CodeClassName = CStrSave( Buffer ); /* 13-apr-93 */ NextToken(); } } seg = LkSegName( segname, classname ); CMemFree( segname ); CMemFree( classname ); } PPCTL_DISABLE_MACROS(); MustRecog( T_RIGHT_PAREN ); DefCodeSegment = seg; #if _CPU == 8086 || _CPU == 386 CompFlags.multiple_code_segments = 1; #endif } }
void AsmSysMakeInlineAsmFunc( int code_ovrflw ) /*********************************************/ { int code_length; SYM_HANDLE sym_handle; TREEPTR tree; int uses_auto; char name[8]; code_length = AsmCodeAddress; if( code_length != 0 ) { sprintf( name, "F.%d", AsmFuncNum ); ++AsmFuncNum; CreateAux( name ); CurrInfo = (struct aux_info *)CMemAlloc( sizeof( struct aux_info ) ); *CurrInfo = WatcallInfo; CurrInfo->use = 1; CurrInfo->save = AsmRegsSaved; // indicate no registers saved uses_auto = InsertFixups( AsmCodeBuffer, code_length, &CurrInfo->code ); if( uses_auto ) { /* We want to force the calling routine to set up a [E]BP frame for the use of this pragma. This is done by saying the pragma modifies the [E]SP register. A kludge, but it works. */ HW_CTurnOff( CurrInfo->save, HW_SP ); } CurrEntry->info = CurrInfo; CurrEntry->next = AuxList; AuxList = CurrEntry; CurrEntry = NULL; sym_handle = MakeFunction( CStrSave( name ), FuncNode( GetType( TYPE_VOID ), 0, NULL ) ); tree = LeafNode( OPR_FUNCNAME ); tree->op.sym_handle = sym_handle; tree = ExprNode( tree, OPR_CALL, NULL ); tree->expr_type = GetType( TYPE_VOID ); AddStmt( tree ); } }
local void CDefine( void ) { struct macro_parm *mp, *prev_mp, *formal_parms; int parm_cnt, parm_end = 0; int ppscan_mode; char *token_buf; source_loc macro_loc; PPNextToken(); if( CurToken != T_ID ) { ExpectIdentifier(); return; } if( strcmp( Buffer, "defined" ) == 0 ) { CErr1( ERR_CANT_DEFINE_DEFINED ); return; } token_buf = CStrSave( Buffer ); formal_parms = NULL; macro_loc = SrcFileLoc; parm_cnt = -1; /* -1 ==> no () following */ if( CurrChar == '(' ) { /* parms present */ PPNextToken(); /* grab the '(' */ PPNextToken(); parm_cnt = 0; /* 0 ==> () following */ parm_end = 0; prev_mp = NULL; for( ;; ) { if( CurToken == T_RIGHT_PAREN ) break; if( parm_end ) { ExpectingAfter( T_RIGHT_PAREN, T_DOT_DOT_DOT ); return; } if( CurToken != T_DOT_DOT_DOT && !ExpectingToken( T_ID ) ) { return; } ++parm_cnt; if( CurToken == T_DOT_DOT_DOT ) { parm_end = 1; /* can have no more parms after this. */ } mp = (struct macro_parm *)CMemAlloc( sizeof( struct macro_parm ) ); if( formal_parms == NULL ) { formal_parms = mp; } else { if( FormalParm( formal_parms ) ) { CErr2p( ERR_DUPLICATE_MACRO_PARM, Buffer ); } prev_mp->next_macro_parm = mp; } if( CurToken == T_DOT_DOT_DOT ) mp->parm = CStrSave( "__VA_ARGS__" ); else mp->parm = CStrSave( Buffer ); prev_mp = mp; PPNextToken(); if( CurToken == T_RIGHT_PAREN ) break; if( CurToken == T_NULL ) { CErr1( ERR_INVALID_MACRO_DEFN ); break; } if( parm_end ) { ExpectingAfter( T_RIGHT_PAREN, T_DOT_DOT_DOT ); return; } MustRecog( T_COMMA ); if( CurToken != T_DOT_DOT_DOT && !ExpectingToken( T_ID ) ) { return; } } } /* grab replacement tokens */ ppscan_mode = InitPPScan(); // enable T_PPNUMBER tokens GrabTokens( parm_end ? -(parm_cnt + 1) : (parm_cnt + 1), formal_parms, token_buf, ¯o_loc ); FiniPPScan( ppscan_mode ); // disable T_PPNUMBER tokens for( ; (mp = formal_parms) != NULL; ) { formal_parms = mp->next_macro_parm; CMemFree( mp->parm ); CMemFree( mp ); } CMemFree( token_buf ); }
local int GetByteSeq( byte_seq **code ) /*************************************/ { unsigned char buff[MAXIMUM_BYTESEQ + 32]; char *name; unsigned long offset; fix_words fixword; int uses_auto; char too_many_bytes; #if _CPU == 8086 bool use_fpu_emu = FALSE; #endif AsmSysInit( buff ); CompFlags.pre_processing = 1; /* enable macros */ NextToken(); too_many_bytes = 0; uses_auto = 0; offset = 0; name = NULL; for( ;; ) { if( CurToken == T_STRING ) { /* 06-sep-91 */ #if _CPU == 8086 AsmLine( Buffer, GET_FPU_EMU( ProcRevision ) ); use_fpu_emu = FALSE; #else AsmLine( Buffer, FALSE ); #endif NextToken(); if( CurToken == T_COMMA ) { NextToken(); } } else if( CurToken == T_CONSTANT ) { #if _CPU == 8086 if( use_fpu_emu ) { AddAFix( AsmCodeAddress, NULL, FIX_SEG, 0 ); use_fpu_emu = FALSE; } #endif AsmCodeBuffer[AsmCodeAddress++] = Constant; NextToken(); } else { #if _CPU == 8086 use_fpu_emu = FALSE; #endif fixword = FixupKeyword(); if( fixword == FIXWORD_NONE ) break; if( fixword == FIXWORD_FLOAT ) { #if _CPU == 8086 if( GET_FPU_EMU( ProcRevision ) ) { use_fpu_emu = TRUE; } #endif } else { /* seg or offset */ if( CurToken != T_ID ) { CErr1( ERR_EXPECTING_ID ); } else { name = CStrSave( Buffer ); NextToken(); if( CurToken == T_PLUS ) { NextToken(); if( CurToken == T_CONSTANT ) { offset = Constant; NextToken(); } } else if( CurToken == T_MINUS ) { NextToken(); if( CurToken == T_CONSTANT ) { offset = -Constant; NextToken(); } } } switch( fixword ) { case FIXWORD_RELOFF: #if _CPU == 8086 AddAFix( AsmCodeAddress, name, FIX_RELOFF16, offset ); AsmCodeAddress += 2; #else AddAFix( AsmCodeAddress, name, FIX_RELOFF32, offset ); AsmCodeAddress += 4; #endif break; case FIXWORD_OFFSET: #if _CPU == 8086 AddAFix( AsmCodeAddress, name, FIX_OFF16, offset ); AsmCodeAddress += 2; #else AddAFix( AsmCodeAddress, name, FIX_OFF32, offset ); AsmCodeAddress += 4; #endif break; case FIXWORD_SEGMENT: AddAFix( AsmCodeAddress, name, FIX_SEG, 0 ); AsmCodeAddress += 2; break; } } } if( AsmCodeAddress > MAXIMUM_BYTESEQ ) { if( ! too_many_bytes ) { CErr1( ERR_TOO_MANY_BYTES_IN_PRAGMA ); too_many_bytes = 1; } AsmCodeAddress = 0; // reset index to we don't overrun buffer } } if( too_many_bytes ) { FreeAsmFixups(); uses_auto = 0; } else { uses_auto = InsertFixups( buff, AsmCodeAddress, code ); } CompFlags.pre_processing = 2; AsmSysFini(); return( uses_auto ); }
static void CDefine( void ) { MPPTR mp; MPPTR prev_mp; MPPTR formal_parms; mac_parm_count parm_count; macro_flags mflags; bool ppscan_mode; char *token_buf; source_loc macro_loc; PPNextToken(); if( CurToken != T_ID ) { ExpectIdentifier(); return; } if( CMPLIT( Buffer, "defined" ) == 0 ) { CErr1( ERR_CANT_DEFINE_DEFINED ); return; } token_buf = CStrSave( Buffer ); formal_parms = NULL; macro_loc = SrcFileLoc; parm_count = 0; /* 0 ==> no () following */ mflags = MFLAG_USER_DEFINED; if( CurrChar == '(' ) { /* parms present */ PPNextToken(); /* grab the '(' */ PPNextToken(); parm_count = 1; /* 1 ==> () following */ prev_mp = NULL; for( ; CurToken != T_RIGHT_PAREN; ) { if( mflags & MFLAG_VAR_ARGS ) { ExpectingAfter( T_RIGHT_PAREN, T_DOT_DOT_DOT ); return; } if( CurToken != T_DOT_DOT_DOT && !ExpectingToken( T_ID ) ) { return; } ++parm_count; if( CurToken == T_DOT_DOT_DOT ) { mflags |= MFLAG_VAR_ARGS; /* can have no more parms after this. */ } mp = (MPPTR)CMemAlloc( sizeof( MPDEFN ) ); if( formal_parms == NULL ) { formal_parms = mp; } else { if( FormalParm( formal_parms ) ) { CErr2p( ERR_DUPLICATE_MACRO_PARM, Buffer ); } prev_mp->next = mp; } if( CurToken == T_DOT_DOT_DOT ) { mp->parm = CStrSave( "__VA_ARGS__" ); } else { mp->parm = CStrSave( Buffer ); } prev_mp = mp; PPNextToken(); if( CurToken == T_RIGHT_PAREN ) break; if( CurToken == T_NULL ) { CErr1( ERR_INVALID_MACRO_DEFN ); break; } if( mflags & MFLAG_VAR_ARGS ) { ExpectingAfter( T_RIGHT_PAREN, T_DOT_DOT_DOT ); return; } MustRecog( T_COMMA ); if( CurToken != T_DOT_DOT_DOT && !ExpectingToken( T_ID ) ) { return; } } } /* grab replacement tokens */ ppscan_mode = InitPPScan(); // enable T_PPNUMBER tokens GrabTokens( parm_count, mflags, formal_parms, token_buf, ¯o_loc ); FiniPPScan( ppscan_mode ); // disable T_PPNUMBER tokens for( ; (mp = formal_parms) != NULL; ) { formal_parms = mp->next; CMemFree( mp->parm ); CMemFree( mp ); } CMemFree( token_buf ); }
static bool GetByteSeq( byte_seq **code ) /**************************************/ { unsigned char buff[MAXIMUM_BYTESEQ + 32]; char *name; unsigned offset; fix_words fixword; bool uses_auto; bool too_many_bytes; #if _CPU == 8086 bool use_fpu_emu = false; #endif AsmSysInit( buff ); PPCTL_ENABLE_MACROS(); NextToken(); too_many_bytes = false; uses_auto = false; offset = 0; name = NULL; for( ;; ) { if( CurToken == T_STRING ) { #if _CPU == 8086 AsmLine( Buffer, use_fpu_emu ); use_fpu_emu = false; #else AsmLine( Buffer, false ); #endif NextToken(); if( CurToken == T_COMMA ) { NextToken(); } } else if( CurToken == T_CONSTANT ) { #if _CPU == 8086 if( use_fpu_emu ) { AddAFix( AsmCodeAddress, NULL, FIX_SEG, 0 ); use_fpu_emu = false; } #endif AsmCodeBuffer[AsmCodeAddress++] = (unsigned char)Constant; NextToken(); } else { #if _CPU == 8086 use_fpu_emu = false; #endif fixword = FixupKeyword(); if( fixword == FIXWORD_NONE ) break; if( fixword == FIXWORD_FLOAT ) { #if _CPU == 8086 if( GET_FPU_EMU( ProcRevision ) ) { use_fpu_emu = true; } #endif } else { /* seg or offset */ if( !IS_ID_OR_KEYWORD( CurToken ) ) { CErr1( ERR_EXPECTING_ID ); } else { name = CStrSave( Buffer ); NextToken(); if( CurToken == T_PLUS ) { NextToken(); if( CurToken == T_CONSTANT ) { offset = Constant; NextToken(); } } else if( CurToken == T_MINUS ) { NextToken(); if( CurToken == T_CONSTANT ) { offset = -(int)Constant; NextToken(); } } } switch( fixword ) { case FIXWORD_RELOFF: #if _CPU == 8086 AddAFix( AsmCodeAddress, name, FIX_RELOFF16, offset ); AsmCodeAddress += 2; #else AddAFix( AsmCodeAddress, name, FIX_RELOFF32, offset ); AsmCodeAddress += 4; #endif break; case FIXWORD_OFFSET: #if _CPU == 8086 AddAFix( AsmCodeAddress, name, FIX_OFF16, offset ); AsmCodeAddress += 2; #else AddAFix( AsmCodeAddress, name, FIX_OFF32, offset ); AsmCodeAddress += 4; #endif break; case FIXWORD_SEGMENT: AddAFix( AsmCodeAddress, name, FIX_SEG, 0 ); AsmCodeAddress += 2; break; } } } if( AsmCodeAddress > MAXIMUM_BYTESEQ ) { if( !too_many_bytes ) { CErr1( ERR_TOO_MANY_BYTES_IN_PRAGMA ); too_many_bytes = true; } AsmCodeAddress = 0; // reset index to we don't overrun buffer } } PPCTL_DISABLE_MACROS(); if( too_many_bytes ) { uses_auto = false; } else { uses_auto = InsertFixups( buff, AsmCodeAddress, code ); } FreeAsmFixups(); AsmSysFini(); return( uses_auto ); }