Ignore:
Timestamp:
Jul 27, 2007, 12:06:11 AM (17 years ago)
Author:
dai_9181
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler_Common/src/CommonCodeGenerator.cpp

    r239 r241  
    2323        if( (*it) == pPertialSchedule )
    2424        {
     25            long newValue = pNativeCode->GetSize() - (pPertialSchedule->GetCodePos()+pPertialSchedule->GetTypeSize());
     26
     27            extern int obp;
     28            long newValueOld = obp - (pPertialSchedule->GetObpOld()+pPertialSchedule->GetTypeSize());
     29
    2530            if( pPertialSchedule->GetTypeSize() == sizeof(char) )
    2631            {
    27                 pNativeCode->Overwrite( pPertialSchedule->GetCodePos(), (char)( pNativeCode->GetSize() - (pPertialSchedule->GetCodePos()+1) ) );
     32                if( newValue < -128 || 127 < newValue )
     33                {
     34                    // 範囲外
     35                    SetError();
     36                }
     37
     38                pNativeCode->Overwrite( pPertialSchedule->GetCodePos(), (char)newValue );
    2839
    2940                // TODO: 未完成(用が無くなったら消す)
    30                 extern int obp;
    31                 pNativeCode->OverwriteOld( pPertialSchedule->GetObpOld(), (char)( obp - (pPertialSchedule->GetObpOld()+1) ) );
     41                pNativeCode->OverwriteOld( pPertialSchedule->GetObpOld(), (char)newValueOld );
     42            }
     43            else if( pPertialSchedule->GetTypeSize() == sizeof(long) )
     44            {
     45                pNativeCode->Overwrite( pPertialSchedule->GetCodePos(), newValue );
     46
     47                // TODO: 未完成(用が無くなったら消す)
     48                pNativeCode->OverwriteOld( pPertialSchedule->GetObpOld(), newValueOld );
    3249            }
    3350            else
     
    5269    }
    5370}
    54 CodeGenerator::PertialSchedule *CodeGenerator::__jmp_op_format( char opcode, long offset, int op_size, bool isPertialSchedule )
    55 {
    56     pNativeCode->Put( opcode );
     71CodeGenerator::PertialSchedule *CodeGenerator::__jmp_op_format( char opcode, long offset, int op_size, bool isPertialSchedule, bool isSelfOpcodeOffset )
     72{
     73    long beginCodePos = pNativeCode->GetSize();
     74    {
     75        // TODO: 未完成
     76        extern int obp;
     77        beginCodePos = obp;
     78    }
     79
     80    if( opcode == (char)0xEB )
     81    {
     82        // jmp命令のとき
     83        if( op_size == sizeof(char) )
     84        {
     85            pNativeCode->Put( (char)opcode );
     86        }
     87        else if( op_size == sizeof(long) )
     88        {
     89            pNativeCode->Put( (char)0xE9 );
     90        }
     91        else
     92        {
     93            SetError();
     94        }
     95    }
     96    else
     97    {
     98        if( op_size == sizeof(char) )
     99        {
     100            pNativeCode->Put( (char)((char)0x70 | opcode) );
     101        }
     102        else if( op_size == sizeof(long) )
     103        {
     104            pNativeCode->Put( (char)0x0F );
     105            pNativeCode->Put( (char)((char)0x80 | opcode) );
     106        }
     107        else
     108        {
     109            SetError();
     110        }
     111    }
    57112
    58113    PertialSchedule *pPertialSchedule = NULL;
     
    63118    }
    64119
     120    if( isSelfOpcodeOffset )
     121    {
     122        // 自分自身の命令サイズを考慮する場合
     123        //offset += ( pNativeCode->GetSize() - beginCodePos ) + op_size;
     124
     125        // TODO: 未完成
     126        extern int obp;
     127        offset -= ( obp - beginCodePos ) + op_size;
     128    }
     129
    65130    if( op_size == sizeof(char) )
    66131    {
     
    69134    else if( op_size == sizeof(long) )
    70135    {
     136        pNativeCode->Put( offset );
     137    }
     138    else
     139    {
    71140        SetError();
    72         pNativeCode->Put( offset );
    73     }
    74     else
    75     {
    76         SetError();
    77141    }
    78142
     
    81145CodeGenerator::PertialSchedule *CodeGenerator::op_jle( long offset, int op_size, bool isPertialSchedule )
    82146{
    83     return __jmp_op_format( (char)0x7E, offset, op_size, isPertialSchedule );
     147    return __jmp_op_format( (char)0x0E, offset, op_size, isPertialSchedule );
    84148}
    85149CodeGenerator::PertialSchedule *CodeGenerator::op_jbe( long offset, int op_size, bool isPertialSchedule )
    86150{
    87     return __jmp_op_format( (char)0x76, offset, op_size, isPertialSchedule );
     151    return __jmp_op_format( (char)0x06, offset, op_size, isPertialSchedule );
    88152}
    89153CodeGenerator::PertialSchedule *CodeGenerator::op_jge( long offset, int op_size, bool isPertialSchedule )
    90154{
    91     return __jmp_op_format( (char)0x7D, offset, op_size, isPertialSchedule );
     155    return __jmp_op_format( (char)0x0D, offset, op_size, isPertialSchedule );
    92156}
    93157CodeGenerator::PertialSchedule *CodeGenerator::op_jae( long offset, int op_size, bool isPertialSchedule )
    94158{
    95     return __jmp_op_format( (char)0x73, offset, op_size, isPertialSchedule );
     159    return __jmp_op_format( (char)0x03, offset, op_size, isPertialSchedule );
    96160}
    97161CodeGenerator::PertialSchedule *CodeGenerator::op_jl( long offset, int op_size, bool isPertialSchedule )
    98162{
    99     return __jmp_op_format( (char)0x7C, offset, op_size, isPertialSchedule );
     163    return __jmp_op_format( (char)0x0C, offset, op_size, isPertialSchedule );
    100164}
    101165CodeGenerator::PertialSchedule *CodeGenerator::op_jb( long offset, int op_size, bool isPertialSchedule )
    102166{
    103     return __jmp_op_format( (char)0x72, offset, op_size, isPertialSchedule );
     167    return __jmp_op_format( (char)0x02, offset, op_size, isPertialSchedule );
    104168}
    105169CodeGenerator::PertialSchedule *CodeGenerator::op_jg( long offset, int op_size, bool isPertialSchedule )
    106170{
    107     return __jmp_op_format( (char)0x7F, offset, op_size, isPertialSchedule );
     171    return __jmp_op_format( (char)0x0F, offset, op_size, isPertialSchedule );
    108172}
    109173CodeGenerator::PertialSchedule *CodeGenerator::op_ja( long offset, int op_size, bool isPertialSchedule )
    110174{
    111     return __jmp_op_format( (char)0x77, offset, op_size, isPertialSchedule );
     175    return __jmp_op_format( (char)0x07, offset, op_size, isPertialSchedule );
    112176}
    113177CodeGenerator::PertialSchedule *CodeGenerator::op_jne( long offset, int op_size, bool isPertialSchedule )
    114178{
    115     return __jmp_op_format( (char)0x75, offset, op_size, isPertialSchedule );
     179    return __jmp_op_format( (char)0x05, offset, op_size, isPertialSchedule );
    116180}
    117181CodeGenerator::PertialSchedule *CodeGenerator::op_je( long offset, int op_size, bool isPertialSchedule )
    118182{
    119     return __jmp_op_format( (char)0x74, offset, op_size, isPertialSchedule );
    120 }
    121 CodeGenerator::PertialSchedule *CodeGenerator::op_jmp( long offset, int op_size, bool isPertialSchedule )
    122 {
    123     return __jmp_op_format( (char)0xEB, offset, op_size, isPertialSchedule );
    124 }
     183    return __jmp_op_format( (char)0x04, offset, op_size, isPertialSchedule );
     184}
     185CodeGenerator::PertialSchedule *CodeGenerator::op_jmp( long offset, int op_size, bool isPertialSchedule, bool isSelfOpcodeOffset )
     186{
     187    return __jmp_op_format( (char)0xEB, offset, op_size, isPertialSchedule, isSelfOpcodeOffset );
     188}
     189void CodeGenerator::op_jmp_continue()
     190{
     191    //op_jmp( GetContinueCodePos()-(pNativeCode->GetSize()+sizeof(long)), sizeof(long) );
     192
     193    // TODO: 未完成(OpBuffer/obp廃止が整ったら上記のコードを有効にすべし)
     194
     195    if( GetContinueCodePosOld() == -1 )
     196    {
     197        SetError(12,"Continue",cp);
     198        return;
     199    }
     200
     201    extern int obp;
     202    op_jmp( GetContinueCodePosOld()-obp, sizeof(long), false, true );
     203}
Note: See TracChangeset for help on using the changeset viewer.