static void FreeFiles( void ) /***************************/ { #if FASTMEM==0 int i; /* remove the main src item from src stack */ src_stack->next = SrcFree; SrcFree = src_stack; #endif /* v2.03: set src_stack=NULL to ensure that GetCurrSrcPos() * won't find something when called from main(). */ src_stack = NULL; #if FASTMEM==0 /* free the "free src_items"-heap */ while ( SrcFree ) { struct src_item *next; next = SrcFree->next; LclFree( SrcFree ); SrcFree = next; }; for ( i = 0; i < ModuleInfo.g.cnt_fnames; i++ ) { LclFree( ModuleInfo.g.FNames[i].fname ); //LclFree( ModuleInfo.g.FNames[i].fullname ); } #endif if ( ModuleInfo.g.FNames ) { MemFree( ModuleInfo.g.FNames ); ModuleInfo.g.FNames = NULL; } return; }
void DeleteGroup( struct dsym *dir ) /**********************************/ { struct seg_item *curr; struct seg_item *next; for( curr = dir->e.grpinfo->seglist; curr; curr = next ) { next = curr->next; DebugMsg(("DeleteGroup(%s): free seg_item=%p\n", dir->sym.name, curr )); LclFree( curr ); } DebugMsg(("DeleteGroup(%s): extension %p will be freed\n", dir->sym.name, dir->e.grpinfo )); LclFree( dir->e.grpinfo ); return; }
void FreePubQueue( void ) /***********************/ { #if FASTMEM==0 struct qnode *curr; struct qnode *next; for( curr = ModuleInfo.g.PubQueue.head; curr; curr = next ) { next = curr->next; LclFree( curr ); } #endif ModuleInfo.g.PubQueue.head = NULL; }
void QueueDeleteLinnum( struct qdesc *queue ) /*******************************************/ { struct line_num_info *curr; struct line_num_info *next; if ( queue == NULL ) return; curr = queue->head; for( ; curr ; curr = next ) { next = curr->next; LclFree( curr ); } return; }
void FreeLnameQueue( void ) /*************************/ { struct asym *sym; struct qnode *curr; struct qnode *next; DebugMsg(("FreeLnameQueue enter\n" )); for( curr = ModuleInfo.g.LnameQueue.head; curr; curr = next ) { next = curr->next; sym = (struct asym *)curr->elmt; /* the class name symbols are not part of the * symbol table and hence must be freed now. */ if( sym->state == SYM_CLASS_LNAME ) { SymFree( sym ); } LclFree( curr ); } }
void InputFini( void ) /********************/ { #ifdef DEBUG_OUT int i; /* for the main source file, lines usually isn't filled yet */ if ( ModuleInfo.g.FNames ) ModuleInfo.g.FNames[ModuleInfo.srcfile].lines = src_stack->line_num; for( i = 0; i < ModuleInfo.g.cnt_fnames; i++ ) { if ( Options.log_all_files ) { if ( ModuleInfo.g.FNames[i].included > 1 ) printf("%2u: %5u *%2u %s\n", i+1, ModuleInfo.g.FNames[i].lines, ModuleInfo.g.FNames[i].included, ModuleInfo.g.FNames[i].fname ); else printf("%2u: %5u %s\n", i+1, ModuleInfo.g.FNames[i].lines, ModuleInfo.g.FNames[i].fname ); } DebugMsg(( "InputFini: idx=%u name=%s\n", i, ModuleInfo.g.FNames[i].fname )); } #endif if ( ModuleInfo.g.IncludePath ) MemFree( ModuleInfo.g.IncludePath ); /* free items in ModuleInfo.g.FNames ( and FreeFile, if FASTMEM==0 ) */ FreeFiles(); #ifdef DEBUG_OUT if ( Options.quiet == FALSE ) { printf("lines read(files)/processed in pass one: %" I32_SPEC "u / %" I32_SPEC "u\n", cntflines, cntlines ); printf("invokations: PreprocessLine=%" I32_SPEC "u/%" I32_SPEC "u/%" I32_SPEC "u, Tokenize=%" I32_SPEC "u/%" I32_SPEC "u\n", cntppl0, cntppl1, cntppl2, cnttok0, cnttok1 ); } #endif ModuleInfo.tokenarray = NULL; #ifdef DEBUG_OUT token_stringbuf = NULL; StringBufferEnd = NULL; commentbuffer = NULL; CurrSource = NULL; #endif LclFree( srclinebuffer ); }
void SegmentFini( void ) /**********************/ { #if FASTPASS #if FASTMEM==0 struct dsym *curr; /* this is debugging code only. Usually FASTPASS and FASTMEM * are both either TRUE or FALSE. * It's active if both DEBUG and TRMEM is set in Makefile. */ DebugMsg(("SegmentFini() enter\n")); for( curr = SymTables[TAB_SEG].head; curr; curr = curr->next ) { struct fixup *fix; DebugMsg(("SegmentFini(): segment %s\n", curr->sym.name )); for ( fix = curr->e.seginfo->FixupListHead; fix ; ) { struct fixup *next = fix->nextrlc; LclFree( fix ); fix = next; } } DebugMsg(("SegmentFini() exit\n")); #endif #endif }
ret_code CatStrDir( int i, struct asm_tok tokenarray[] ) /******************************************************/ { struct asym *sym; int count; char *p; /* struct expr opndx; */ DebugMsg1(("CatStrDir(%u) enter\n", i )); DebugCmd( catstrcnt++ ); #if 0 /* can't happen */ /* syntax must be <id> CATSTR textitem[,textitem,...] */ if ( i != 1 ) { return( EmitErr( SYNTAX_ERROR_EX, tokenarray[i].string_ptr ) ); } if ( tokenarray[0].token != T_ID ) { return( EmitErr( SYNTAX_ERROR_EX, tokenarray[0].string_ptr ) ); } #endif i++; /* go past CATSTR/TEXTEQU */ /* v2.08: don't copy to temp buffer */ //*StringBufferEnd = NULLC; /* check correct syntax and length of items */ for ( count = 0; i < Token_Count; ) { DebugMsg1(("CatStrDir(%s): item[%u]=%s delim=0x%x\n", tokenarray[0].string_ptr, i, tokenarray[i].string_ptr, tokenarray[i].string_delim )); if ( tokenarray[i].token != T_STRING || tokenarray[i].string_delim != '<' ) { DebugMsg(("CatStrDir: error, not a <>-literal: %s\n", tokenarray[i].tokpos )); return( TextItemError( &tokenarray[i] ) ); } /* v2.08: using tokenarray.stringlen is not quite correct, since some chars * are stored in 2 bytes (!) */ if ( ( count + tokenarray[i].stringlen ) >= MAX_LINE_LEN ) { DebugMsg(("CatStrDir: error, literal too long: %u + %u >= %u\n", count, tokenarray[i].stringlen, MAX_LINE_LEN )); return( EmitError( STRING_OR_TEXT_LITERAL_TOO_LONG ) ); } /* v2.08: don't copy to temp buffer */ //strcpy( StringBufferEnd + count, tokenarray[i].string_ptr ); count = count + tokenarray[i].stringlen; i++; if ( ( tokenarray[i].token != T_COMMA ) && ( tokenarray[i].token != T_FINAL ) ) { return( EmitErr( SYNTAX_ERROR_EX, tokenarray[i].string_ptr ) ); } i++; } sym = SymSearch( tokenarray[0].string_ptr ); if ( sym == NULL ) { sym = SymCreate( tokenarray[0].string_ptr ); DebugMsg1(( "CatStrDir: new symbol %s created\n", sym->name)); } else if( sym->state == SYM_UNDEFINED ) { /* v2.01: symbol has been used already. Using * a textmacro before it has been defined is * somewhat problematic. */ sym_remove_table( &SymTables[TAB_UNDEF], (struct dsym *)sym ); #if FASTPASS SkipSavedState(); /* further passes must be FULL! */ #endif EmitWarn( 2, TEXT_MACRO_USED_PRIOR_TO_DEFINITION, sym->name ); } else if( sym->state != SYM_TMACRO ) { /* it is defined as something else, get out */ DebugMsg(( "CatStrDir(%s) exit, symbol redefinition\n", sym->name)); return( EmitErr( SYMBOL_REDEFINITION, sym->name ) ); } sym->state = SYM_TMACRO; sym->isdefined = TRUE; #if FASTMEM==0 if ( sym->string_ptr ) LclFree( sym->string_ptr ); sym->string_ptr = (char *)LclAlloc( count + 1 ); #else /* v2.08: reuse string space if fastmem is on */ if ( sym->total_size < ( count+1 ) ) { LclFree( sym->string_ptr ); /* is a noop if fastmem is on */ sym->string_ptr = (char *)LclAlloc( count + 1 ); sym->total_size = count + 1; } #endif /* v2.08: don't use temp buffer */ //memcpy( sym->string_ptr, StringBufferEnd, count + 1 ); for ( i = 2, p = sym->string_ptr; i < Token_Count; i += 2 ) { memcpy( p, tokenarray[i].string_ptr, tokenarray[i].stringlen ); p += tokenarray[i].stringlen; } *p = NULLC; DebugMsg1(("CatStrDir(%s) (new) value: >%s<\n", sym->name, sym->string_ptr )); if ( ModuleInfo.list ) LstWrite( LSTTYPE_TMACRO, 0, sym ); return( NOT_ERROR ); }
/* SubStr() * defines a text equate. * syntax: name SUBSTR <string>, pos [, size] */ ret_code SubStrDir( int i, struct asm_tok tokenarray[] ) /******************************************************/ { struct asym *sym; char *name; char *p; //char *newvalue; int pos; int size; int cnt; bool chksize; struct expr opndx; DebugMsg1(("SubStrDir enter\n")); DebugCmd( substrcnt++ ); /* at least 5 items are needed * 0 1 2 3 4 5 6 * ID SUBSTR SRC_ID , POS [, LENGTH] */ #if 0 /* can't happen */ if ( i != 1 ) { return( EmitErr( SYNTAX_ERROR_EX, tokenarray[i].string_ptr ) ); } if ( tokenarray[0].token != T_ID ) { return( EmitErr( SYNTAX_ERROR_EX, tokenarray[0].string_ptr ) ); } #endif name = tokenarray[0].string_ptr; i++; /* go past SUBSTR */ /* third item must be a string */ if ( tokenarray[i].token != T_STRING || tokenarray[i].string_delim != '<' ) { DebugMsg(("SubStrDir: error, no text item\n")); return( TextItemError( &tokenarray[i] ) ); } p = tokenarray[i].string_ptr; cnt = tokenarray[i].stringlen; i++; DebugMsg1(("SubStrDir(%s): src=>%s<\n", name, p)); if ( tokenarray[i].token != T_COMMA ) { return( EmitErr( EXPECTING_COMMA, tokenarray[i].tokpos ) ); } i++; /* get pos, must be a numeric value and > 0 */ /* v2.11: flag NOUNDEF added - no forward ref possible */ if ( EvalOperand( &i, tokenarray, Token_Count, &opndx, EXPF_NOUNDEF ) == ERROR ) { DebugMsg(("SubStrDir(%s): invalid pos value\n", name)); return( ERROR ); } /* v2.04: "string" constant allowed as second argument */ //if ( opndx.kind != EXPR_CONST || opndx.string != NULL ) { if ( opndx.kind != EXPR_CONST ) { DebugMsg(("SubStrDir(%s): pos value is not a constant\n", name)); return( EmitError( CONSTANT_EXPECTED ) ); } /* pos is expected to be 1-based */ pos = opndx.value; if ( pos <= 0 ) { return( EmitError( POSITIVE_VALUE_EXPECTED ) ); } if ( tokenarray[i].token != T_FINAL ) { if ( tokenarray[i].token != T_COMMA ) { return( EmitErr( EXPECTING_COMMA, tokenarray[i].tokpos ) ); } i++; /* get size, must be a constant */ /* v2.11: flag NOUNDEF added - no forward ref possible */ if ( EvalOperand( &i, tokenarray, Token_Count, &opndx, EXPF_NOUNDEF ) == ERROR ) { DebugMsg(("SubStrDir(%s): invalid size value\n", name)); return( ERROR ); } /* v2.04: string constant ok */ //if ( opndx.kind != EXPR_CONST || opndx.string != NULL ) { if ( opndx.kind != EXPR_CONST ) { DebugMsg(("SubStrDir(%s): size value is not a constant\n", name)); return( EmitError( CONSTANT_EXPECTED ) ); } size = opndx.value; if ( tokenarray[i].token != T_FINAL ) { DebugMsg(("SubStrDir(%s): additional items found\n", name)); return( EmitErr( SYNTAX_ERROR_EX, tokenarray[i].string_ptr ) ); } if ( size < 0 ) { return( EmitError( COUNT_MUST_BE_POSITIVE_OR_ZERO ) ); } chksize = TRUE; } else { size = -1; chksize = FALSE; } #if 0 cnt = pos; /* position p to start of substring */ for ( pos--; pos > 0 && *p ; pos--, p++ ) if ( *p == '!' && *(p+1) != NULLC ) p++; if ( *p == NULLC ) { return( EmitErr( INDEX_VALUE_PAST_END_OF_STRING, cnt ) ); } if ( *p == '!' && *(p+1) != NULLC ) p++; for ( newvalue = p, cnt = size; *p && cnt; cnt--, p++ ) if ( *p == '!' && *(p+1) != NULLC ) p++; /* v2.04: check added */ if ( chksize && cnt ) { return( EmitError( COUNT_VALUE_TOO_LARGE ) ); } size = p - newvalue; p = newvalue; #else if ( pos > cnt ) { return( EmitErr( INDEX_VALUE_PAST_END_OF_STRING, pos ) ); } if ( chksize && (pos+size-1) > cnt ) { return( EmitError( COUNT_VALUE_TOO_LARGE ) ); } p += pos - 1; if ( size == -1 ) size = cnt - pos + 1; #endif sym = SymSearch( name ); /* if we've never seen it before, put it in */ if( sym == NULL ) { sym = SymCreate( name ); } else if( sym->state == SYM_UNDEFINED ) { /* it was referenced before being defined. This is * a bad idea for preprocessor text items, because it * will require a full second pass! */ sym_remove_table( &SymTables[TAB_UNDEF], (struct dsym *)sym ); #if FASTPASS SkipSavedState(); EmitWarn( 2, TEXT_MACRO_USED_PRIOR_TO_DEFINITION, sym->name ); #endif } else if( sym->state != SYM_TMACRO ) { /* it is defined as something incompatible, get out */ DebugMsg(( "SubStrDir(%s) error, incompatible type\n", sym->name)); return( EmitErr( SYMBOL_REDEFINITION, sym->name ) ); } sym->state = SYM_TMACRO; sym->isdefined = TRUE; #if FASTMEM==0 if ( sym->string_ptr ) LclFree( sym->string_ptr ); sym->string_ptr = (char *)LclAlloc( size + 1 ); #else if ( sym->total_size < ( size + 1 ) ) { LclFree( sym->string_ptr ); sym->string_ptr = LclAlloc ( size + 1 ); sym->total_size = size + 1; } #endif memcpy( sym->string_ptr, p, size ); *(sym->string_ptr + size) = NULLC; DebugMsg1(("SubStrDir(%s): result=>%s<\n", sym->name, sym->string_ptr )); LstWrite( LSTTYPE_TMACRO, 0, sym ); return( NOT_ERROR ); }
/* * used by EQU if the value to be assigned to a symbol is text. * - sym: text macro name, may be NULL * - name: identifer ( if sym == NULL ) * - value: value of text macro ( original line, BEFORE expansion ) */ struct asym *SetTextMacro( struct asm_tok tokenarray[], struct asym *sym, const char *name, const char *value ) /*************************************************************************************************************/ { int count; //char *p; DebugCmd( equcnt++ ); if ( sym == NULL ) sym = SymCreate( name ); else if ( sym->state == SYM_UNDEFINED ) { sym_remove_table( &SymTables[TAB_UNDEF], (struct dsym *)sym ); #if FASTPASS /* the text macro was referenced before being defined. * this is valid usage, but it requires a full second pass. * just simply deactivate the fastpass feature for this module! */ SkipSavedState(); #endif EmitWarn( 2, TEXT_MACRO_USED_PRIOR_TO_DEFINITION, sym->name ); } else if ( sym->state != SYM_TMACRO ) { EmitErr( SYMBOL_REDEFINITION, name ); return( NULL ); } sym->state = SYM_TMACRO; sym->isdefined = TRUE; if ( tokenarray[2].token == T_STRING && tokenarray[2].string_delim == '<' ) { /* the simplest case: value is a literal. define a text macro! */ /* just ONE literal is allowed */ if ( tokenarray[3].token != T_FINAL ) { EmitErr( SYNTAX_ERROR_EX, tokenarray[3].tokpos ); return( NULL ); } value = tokenarray[2].string_ptr; count = tokenarray[2].stringlen; } else { /* * the original source is used, since the tokenizer has * deleted some information. */ //while ( isspace( *value ) ) value++; /* probably obsolete */ count = strlen( value ); /* skip trailing spaces */ for ( ; count; count-- ) if ( isspace( *( value + count - 1 ) ) == FALSE ) break; } #if FASTMEM==0 if ( sym->string_ptr ) LclFree( sym->string_ptr ); sym->string_ptr = (char *)LclAlloc( count + 1 ); #else if ( sym->total_size < ( count + 1 ) ) { LclFree( sym->string_ptr ); /* is a noop if fastmem is on */ sym->string_ptr = (char *)LclAlloc( count + 1 ); sym->total_size = count + 1; } #endif memcpy( sym->string_ptr, value, count ); *(sym->string_ptr + count) = NULLC; DebugMsg1(( "SetTextMacro(%s): value is >%s<, exit\n", sym->name, sym->string_ptr )); return( sym ); }