Exemplo n.º 1
0
void HllCheckOpen( void )
/***********************/
{
    if ( HllStack ) {
        AsmErr( BLOCK_NESTING_ERROR, ".if-.repeat-.while" );
    }
}
Exemplo n.º 2
0
void IfCondFini( void )
/*********************/
{
    if( NestLevel > 0 ) {
        AsmErr( UNCLOSED_CONDITIONALS, NestLevel );
    }
}
Exemplo n.º 3
0
int conditional_error_directive( int i )
/**************************************/
{
    uint_16         direct;

    direct = AsmBuffer[i]->u.value;

    /* expand any constants if necessary */
    switch( direct ) {
    case T_DOT_ERRE:
    case T_DOT_ERRNZ:
    case T_DOT_ERRDIF:
    case T_DOT_ERRDIFI:
    case T_DOT_ERRIDN:
    case T_DOT_ERRIDNI:
    case T_ERRIFE:
    case T_ERRIFDIF:
    case T_ERRIFDIFI:
    case T_ERRIFIDN:
    case T_ERRIFIDNI:
        ExpandTheWorld( i+1, FALSE, TRUE );
    }

    switch( direct ) {
    case T_DOT_ERR:
    case T_ERR:
        AsmErr( FORCED );
        return( ERROR );
    case T_DOT_ERRNZ:
        if( AsmBuffer[i+1]->token == T_NUM && AsmBuffer[i+1]->u.value ) {
            AsmErr( FORCED_NOT_ZERO, AsmBuffer[i+1]->u.value );
            return( ERROR );
        }
        break;
    case T_DOT_ERRE:
    case T_ERRIFE:
        if( AsmBuffer[i+1]->token == T_NUM && !AsmBuffer[i+1]->u.value ) {
            AsmErr( FORCED_EQUAL, AsmBuffer[i+1]->u.value );
            return( ERROR );
        }
        break;
    case T_DOT_ERRDEF:
    case T_ERRIFDEF:
        if( check_defd( AsmBuffer[i+1]->string_ptr ) ) {
            AsmErr( FORCED_DEF, AsmBuffer[i+1]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRNDEF:
    case T_ERRIFNDEF:
        if( !check_defd( AsmBuffer[i+1]->string_ptr ) ) {
            AsmErr( FORCED_NOT_DEF, AsmBuffer[i+1]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRB:
    case T_ERRIFB:
        if( AsmBuffer[i+1]->token == T_STRING &&
                check_blank( AsmBuffer[i+1]->string_ptr ) ) {
            AsmErr( FORCED_BLANK, AsmBuffer[i+1]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRNB:
    case T_ERRIFNB:
        if( AsmBuffer[i+1]->token != T_STRING ||
                !check_blank( AsmBuffer[i+1]->string_ptr ) ) {
            AsmErr( FORCED_NOT_BLANK, AsmBuffer[i+1]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRDIF:
    case T_ERRIFDIF:
        if( check_dif( TRUE, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr ) ) {
            AsmErr( FORCED_DIF, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRDIFI:
    case T_ERRIFDIFI:
        if( check_dif( FALSE, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr ) ) {
            AsmErr( FORCED_DIF, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRIDN:
    case T_ERRIFIDN:
        if( !check_dif( TRUE, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr ) ) {
            AsmErr( FORCED_IDN, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRIDNI:
    case T_ERRIFIDNI:
        if( !check_dif( FALSE, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr ) ) {
            AsmErr( FORCED_IDN, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr );
            return( ERROR );
        }
        break;
    }
    return( NOT_ERROR );
}
Exemplo n.º 4
0
void AsmError( int msgnum )
/*************************/
{
    AsmErr( msgnum );
}
Exemplo n.º 5
0
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 );
}
Exemplo n.º 6
0
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 );
}
Exemplo n.º 7
0
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 );
}