static void do_init_stuff( char **cmdline ) /*****************************************/ { char *env; char buff[80]; if( !MsgInit() ) exit(1); AsmInit( -1, -1, -1, -1 ); // initialize hash table strcpy( buff, "__WASM__=" BANSTR( _BANVER ) ); add_constant( buff ); ForceInclude = getenv( "FORCE" ); do_envvar_cmdline( "WASM" ); parse_cmdline( cmdline ); set_build_target(); get_os_include(); env = getenv( "INCLUDE" ); if( env != NULL ) AddStringToIncludePath( env ); if( !Options.quiet && !Options.banner_printed ) { Options.banner_printed = TRUE; trademark(); } open_files(); PushLineQueue(); AsmLookup( "$" ); // create "$" symbol for current segment counter }
static void do_init_stuff( char **cmdline ) /*****************************************/ { char *env; if( !MsgInit() ) exit(1); add_constant( "WASM=" BANSTR( _BANVER ), true ); ForceInclude = AsmStrDup( getenv( "FORCE" ) ); do_envvar_cmdline( "WASM" ); parse_cmdline( cmdline ); set_build_target(); set_cpu_mode(); set_fpu_mode(); get_os_include(); env = getenv( "INCLUDE" ); if( env != NULL ) AddItemToIncludePath( env, NULL ); PrintBanner(); open_files(); PushLineQueue(); }
ret_code HllEndDef( int i ) /*************************/ { //struct asm_sym *sym; struct hll_list *hll; int cmd = AsmBuffer[i]->value; char buffer[MAX_ID_LEN+1+64]; DebugMsg(("HllEndDef(%s) enter\n", AsmBuffer[i]->string_ptr )); if ( HllStack == NULL ) { DebugMsg(("HllEndDef: hll stack is empty\n")); AsmError( DIRECTIVE_MUST_BE_IN_CONTROL_BLOCK ); return( ERROR ); } hll = HllStack; HllStack = hll->next; PushLineQueue(); switch (cmd) { case T_DOT_ENDIF: if ( hll->cmd != HLL_IF ) { DebugMsg(("HllEndDef no .IF on the hll stack\n")); AsmErr( BLOCK_NESTING_ERROR, AsmBuffer[i]->string_ptr ); return( ERROR ); } /* if a test label isn't created yet, create it */ if ( hll->symtest ) { MakeLabel( buffer, hll->symtest ); AddLineQueue( buffer ); } /* create the exit label if it exists */ if ( hll->symexit ) { MakeLabel( buffer, hll->symexit ); AddLineQueue( buffer ); } i++; break; case T_DOT_ENDW: if ( hll->cmd != HLL_WHILE ) { DebugMsg(("HllEndDef no .WHILE on the hll stack\n")); AsmErr( BLOCK_NESTING_ERROR, AsmBuffer[i]->string_ptr ); return( ERROR ); } /* create test label */ if ( hll->symtest ) { MakeLabel( buffer, hll->symtest ); DebugMsg(("HllEndDef: created: %s\n", buffer)); AddLineQueue( buffer ); } HllPushTestLines( hll ); MakeLabel( buffer, hll->symexit ); AddLineQueue( buffer ); i++; break; case T_DOT_UNTILCXZ: if ( hll->cmd != HLL_REPEAT ) { DebugMsg(("HllEndDef no .REPEAT on the hll stack\n")); AsmErr( BLOCK_NESTING_ERROR, AsmBuffer[i]->string_ptr ); return( ERROR ); } MakeLabel( buffer, hll->symtest ); AddLineQueue( buffer ); i++; /* read in optional (simple) expression */ if ( AsmBuffer[i]->token != T_FINAL ) { if ( ERROR == EvaluateHllExpression( hll, &i, LABELFIRST, FALSE ) ) { return( ERROR ); } if ( HllCheckTestLines(hll) == ERROR ) { AsmError( EXPR_TOO_COMPLEX_FOR_UNTILCXZ ); return( ERROR ); } /* write condition lines */ HllPushTestLines( hll ); } else { sprintf( buffer, " loop %s", hll->symfirst ); AddLineQueue( buffer ); } MakeLabel( buffer, hll->symexit ); AddLineQueue( buffer ); break; case T_DOT_UNTIL: if ( hll->cmd != HLL_REPEAT ) { DebugMsg(("HllEndDef no .REPEAT on the hll stack\n")); AsmErr( BLOCK_NESTING_ERROR, AsmBuffer[i]->string_ptr ); return( ERROR ); } MakeLabel( buffer, hll->symtest ); AddLineQueue( buffer ); i++; /* read in (optional) expression */ /* if expression is missing, just generate nothing */ if ( AsmBuffer[i]->token != T_FINAL ) { if ( ERROR == EvaluateHllExpression( hll, &i, LABELFIRST, FALSE ) ) { return( ERROR ); } /* write condition lines */ HllPushTestLines( hll ); } #if 0 sprintf( buffer, " jmp %s", hll->symfirst ); AddLineQueue( buffer ); #endif MakeLabel( buffer, hll->symexit ); AddLineQueue( buffer ); break; } AsmFree( hll->symfirst ); AsmFree( hll->symtest ); AsmFree( hll->symexit ); AsmFree( hll->condlines ); AsmFree( hll ); if ( AsmBuffer[i]->token != T_FINAL ) { AsmErr( SYNTAX_ERROR_EX, AsmBuffer[i]->string_ptr ); return( ERROR ); } if ( ModuleInfo.list ) LstWrite( LSTTYPE_DIRECTIVE, GetCurrOffset(), NULL ); if ( line_queue ) RunLineQueue(); return( NOT_ERROR ); }
ret_code HllStartDef( int i ) /***************************/ { struct hll_list *hll; int cmd = AsmBuffer[i]->value; char buffer[MAX_ID_LEN+1+64]; DebugMsg(("HllStartDef(%u [=%s]) enter\n", i, AsmBuffer[i]->string_ptr )); #if FASTPASS /* make sure the directive is stored */ if ( StoreState == FALSE && Parse_Pass == PASS_1 ) { SaveState(); } #endif switch (cmd) { case T_DOT_REPEAT: if ( AsmBuffer[i+1]->token != T_FINAL ) { DebugMsg(("HllStartDef: unexpected tokens behind .REPEAT\n" )); AsmError( SYNTAX_ERROR ); return( ERROR ); } break; case T_DOT_IF: case T_DOT_WHILE: #if 0 /* Masm allows a missing expression! */ if ( AsmBuffer[i+1]->token == T_FINAL ) { AsmError( SYNTAX_ERROR ); return( ERROR ); } #endif break; } hll = AsmAlloc( sizeof(hll_list) ); hll->cmd = HLL_UNDEF; /* create labels which are always needed */ /* for .IF -.ENDIF without .ELSE no symexit label is needed. */ hll->symfirst = NULL; hll->symexit = NULL; hll->symtest = MakeAnonymousLabel(); hll->condlines = NULL; // structure for .IF .ELSE .ENDIF // cond jump to symtest // ... // jmp symexit // symtest: // ... // symexit: // structure for .IF .ELSEIF // cond jump to symtest // ... // jmp symexit // symtest: // cond jump to (new) symtest // ... // jmp symexit // symtest: // ... // structure for .WHILE and .REPEAT: // jmp symtest (for .WHILE only) // symfirst: // ... // symtest: (jumped to by .continue) // test end condition, cond jump to symfirst // symexit: (jumped to by .break) PushLineQueue(); switch (cmd) { case T_DOT_IF: hll->cmd = HLL_IF; /* get the C-style expression, convert to ASM code lines */ i++; if ( ERROR == EvaluateHllExpression( hll, &i, LABELTEST, FALSE ) ) { return( ERROR ); } HllPushTestLines( hll ); #if 1 /* if no lines have been created, the symtest label isn't needed */ if ( line_queue == NULL ) { AsmFree( hll->symtest ); hll->symtest = NULL; } #endif break; case T_DOT_WHILE: case T_DOT_REPEAT: /* create the label to loop start */ hll->symfirst = MakeAnonymousLabel(); hll->symexit = MakeAnonymousLabel(); if ( cmd == T_DOT_WHILE ) { i++; hll->cmd = HLL_WHILE; if ( AsmBuffer[i]->token != T_FINAL ) { if ( ERROR == EvaluateHllExpression( hll, &i, LABELFIRST, TRUE ) ) { return( ERROR ); } } else hll->condlines = ""; /* create a jump to second label */ /* optimisation: if second label is just a jump, dont jump! */ if ( hll->condlines && _memicmp(hll->condlines, "jmp", 3) ) { sprintf( buffer, " jmp %s", hll->symtest ); AddLineQueue( buffer ); } else { AsmFree( hll->symtest ); hll->symtest = NULL; } } else { i++; hll->cmd = HLL_REPEAT; } MakeLabel( buffer, hll->symfirst ); AddLineQueue( buffer ); break; } if ( AsmBuffer[i]->token != T_FINAL ) { DebugMsg(("HllStartDef: unexpected token %u [%s]\n", AsmBuffer[i]->token, AsmBuffer[i]->string_ptr )); AsmErr( SYNTAX_ERROR_EX, AsmBuffer[i]->string_ptr ); return( ERROR ); } hll->next = HllStack; HllStack = hll; if ( ModuleInfo.list ) LstWrite( LSTTYPE_DIRECTIVE, GetCurrOffset(), NULL ); if ( line_queue ) /* might be NULL! (".if 1") */ RunLineQueue(); return( NOT_ERROR ); }
ret_code HllExitDef( int i ) /**************************/ { //int level; //struct asm_sym *sym; struct hll_list *hll; char *savedlines; hll_cmd savedcmd; int cmd = AsmBuffer[i]->value; char buffer[MAX_ID_LEN+1+64]; DebugMsg(("HllExitDef(%s) enter\n", AsmBuffer[i]->string_ptr )); hll = HllStack; if ( hll == NULL ) { DebugMsg(("HllExitDef stack error\n")); AsmError( DIRECTIVE_MUST_BE_IN_CONTROL_BLOCK ); return( ERROR ); } PushLineQueue(); switch (cmd) { case T_DOT_ELSE: case T_DOT_ELSEIF: if ( hll->cmd != HLL_IF ) { DebugMsg(("HllExitDef(%s): symtest=%X\n", AsmBuffer[i]->string_ptr, hll->symtest)); AsmErr( BLOCK_NESTING_ERROR, AsmBuffer[i]->string_ptr ); return( ERROR ); } /* the "symexit" label is only needed if an .ELSE branch exists. That's why it is created delayed. */ if ( hll->symexit == NULL) hll->symexit = MakeAnonymousLabel(); sprintf( buffer," jmp %s", hll->symexit ); AddLineQueue( buffer ); if ( hll->symtest ) { MakeLabel( buffer, hll->symtest ); AddLineQueue( buffer ); AsmFree( hll->symtest ); hll->symtest = NULL; } i++; if (cmd == T_DOT_ELSEIF) { /* create new symtest label */ hll->symtest = MakeAnonymousLabel(); if ( ERROR == EvaluateHllExpression( hll, &i, LABELTEST, FALSE ) ) { return( ERROR ); } HllPushTestLines( hll ); } break; case T_DOT_BREAK: case T_DOT_CONTINUE: for ( ; hll && hll->cmd == HLL_IF; hll = hll->next ); if ( hll == NULL ) { AsmError( DIRECTIVE_MUST_BE_IN_CONTROL_BLOCK ); return( ERROR ); } /* .BREAK .IF ... or .CONTINUE .IF ? */ i++; if ( AsmBuffer[i]->token != T_FINAL ) { if ( AsmBuffer[i]->token == T_DIRECTIVE && AsmBuffer[i]->value == T_DOT_IF ) { savedlines = hll->condlines; savedcmd = hll->cmd; hll->condlines = NULL; hll->cmd = HLL_BREAK; i++; if ( cmd == T_DOT_BREAK ) { if ( ERROR == EvaluateHllExpression( hll, &i, LABELEXIT, TRUE ) ) { return( ERROR ); } } else { /* T_DOT_CONTINUE */ if ( ERROR == EvaluateHllExpression( hll, &i, LABELTEST, TRUE ) ) { return( ERROR ); } } HllPushTestLines( hll ); AsmFree( hll->condlines ); hll->condlines = savedlines; hll->cmd = savedcmd; } } else { if ( cmd == T_DOT_BREAK ) { sprintf( buffer," jmp %s", hll->symexit ); } else { if ( hll->symtest ) sprintf( buffer," jmp %s", hll->symtest ); else sprintf( buffer," jmp %s", hll->symfirst ); } AddLineQueue( buffer ); } break; } if ( AsmBuffer[i]->token != T_FINAL ) { AsmErr( SYNTAX_ERROR_EX, AsmBuffer[i]->string_ptr ); return( ERROR ); } if ( ModuleInfo.list ) LstWrite( LSTTYPE_DIRECTIVE, GetCurrOffset(), NULL ); RunLineQueue(); return( NOT_ERROR ); }