Changeset 241 in dev for trunk/abdev/BasicCompiler_Common


Ignore:
Timestamp:
Jul 27, 2007, 12:06:11 AM (17 years ago)
Author:
dai_9181
Message:
 
Location:
trunk/abdev/BasicCompiler_Common
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler_Common/Compile.cpp

    r232 r241  
    2323LABEL *pLabelNames;
    2424int MaxLabelNum;
    25 
    26 //Continueアドレス
    27 DWORD dwContinueAddress;
    2825
    2926//Caseスケジュール
  • trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h

    r240 r241  
    5252
    5353private:
     54
     55    // 部分スケジュールの管理
    5456    typedef std::vector<PertialSchedule *> PertialSchedules;
    5557    PertialSchedules pertialSchedules;
    5658
     59    // Continue用のコード位置情報の管理
     60    std::vector<long> continueCodePositions;
     61    std::vector<long> _continueCodePositions_ObpOld;
     62
    5763public:
    5864
     
    7884    }
    7985
     86    long GetContinueCodePos() const
     87    {
     88        if( continueCodePositions.size() == 0 )
     89        {
     90            return -1;
     91        }
     92        return continueCodePositions[continueCodePositions.size()-1];
     93    }
     94    void ClearContinueArea()
     95    {
     96        continueCodePositions.clear();
     97        _continueCodePositions_ObpOld.clear();
     98    }
     99    void ContinueAreaBegin()
     100    {
     101        continueCodePositions.push_back( pNativeCode->GetSize() );
     102
     103        extern int obp;
     104        _continueCodePositions_ObpOld.push_back( obp );
     105    }
     106    void ContinueAreaEnd()
     107    {
     108        continueCodePositions.pop_back();
     109        _continueCodePositions_ObpOld.pop_back();
     110    }
     111    long GetContinueCodePosOld() const
     112    {
     113        if( _continueCodePositions_ObpOld.size() == 0 )
     114        {
     115            return -1;
     116        }
     117        return _continueCodePositions_ObpOld[_continueCodePositions_ObpOld.size()-1];
     118    }
     119
    80120    void CheckUnresolveSchedule();
    81121
     
    88128
    89129private:
    90     PertialSchedule *__jmp_op_format( char opcode, long offset, int op_size, bool isPertialSchedule = false );
     130    PertialSchedule *__jmp_op_format( char opcode, long offset, int op_size, bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
    91131public:
    92132    PertialSchedule *op_jle( long offset, int op_size = sizeof(char), bool isPertialSchedule = false );
     
    100140    PertialSchedule *op_jne( long offset, int op_size = sizeof(char), bool isPertialSchedule = false );
    101141    PertialSchedule *op_je( long offset, int op_size = sizeof(char), bool isPertialSchedule = false );
    102     PertialSchedule *op_jmp( long offset, int op_size = sizeof(char), bool isPertialSchedule = false );
     142    PertialSchedule *op_jmp( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
     143    void op_jmp_continue();
    103144
    104145
  • trunk/abdev/BasicCompiler_Common/include/NativeCode.h

    r237 r241  
    141141        // 未完成
    142142        extern char *OpBuffer;
    143         extern int obp;
    144143        OpBuffer[_obpOld] = c;
     144    }
     145    void Overwrite( int codePos, long newLongValue )
     146    {
     147        *(long *)(this->codeBuffer+codePos) = newLongValue;
     148    }
     149    void OverwriteOld( int _obpOld, long newLongValue )
     150    {
     151        // 未完成
     152        extern char *OpBuffer;
     153        *(long *)(OpBuffer+_obpOld) = newLongValue;
    145154    }
    146155
  • 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.