Changeset 225 in dev for trunk/abdev/BasicCompiler_Common


Ignore:
Timestamp:
Jul 21, 2007, 11:47:40 PM (17 years ago)
Author:
dai_9181
Message:

CodeGeneratorクラスのベースを実装

Location:
trunk/abdev/BasicCompiler_Common
Files:
6 edited

Legend:

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

    r223 r225  
    11#include "stdafx.h"
    22
    3 #include "common.h"
     3#include <Compiler.h>
    44
    55#ifdef _AMD64_
     
    2525
    2626    //mov rax,rsp
    27     op_mov_RR(REG_RAX,REG_RSP);
     27    compiler.codeGenerator.op_mov_RR(REG_RAX,REG_RSP);
    2828
    2929    //mov ptr[offset],rax/eax
    30     op_mov_MR(PTR_SIZE,REG_RAX,0,(int)RelativeVar.offset,MOD_DISP32);
     30    compiler.codeGenerator.op_mov_MR(PTR_SIZE,REG_RAX,0,(int)RelativeVar.offset,MOD_DISP32);
    3131    obp-=sizeof(long);
    3232    pobj_GlobalVarSchedule->add();
  • trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h

    r224 r225  
    11#pragma once
    22
     3#include <NativeCode.h>
     4
     5#ifdef _AMD64_
     6#include "../../BasicCompiler64/MachineFixed.h"
     7#else
     8#include "../../BasicCompiler32/MachineFixed.h"
     9#endif
     10
     11
    312void ReallocNativeCodeBuffer();
     13
     14class CodeGenerator
     15{
     16    NativeCode *pNativeCode;
     17
     18    // XMLシリアライズ用
     19private:
     20    friend class boost::serialization::access;
     21    template<class Archive> void serialize(Archive& ar, const unsigned int version)
     22    {
     23        ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( NativeCode );
     24    }
     25
     26public:
     27
     28    void Select( NativeCode &nativeCode )
     29    {
     30        pNativeCode = &nativeCode;
     31    }
     32
     33#ifdef _AMD64_
     34#else
     35private:
     36    void set_mod_rm_sib_disp(char mod,int reg,int scale,int index_reg,int base_reg,long disp);
     37    void __op_format(char op_prefix,char opcode,int reg);
     38    void __op_format(char op_prefix,char opcode1,char opcode2,int reg,int base_reg,int offset,char mod);
     39public:
     40    void op_mov_RV          (int reg,long offset);
     41    void op_mov_RV          (int op_size,int reg,int offset);
     42    void op_mov_RR          (int reg1,int reg2);
     43    void op_mov_RM          (int op_size,int reg,int base_reg,int offset,char mod);
     44    void op_mov_RM_ex       (int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset);
     45    void op_mov_MR          (int op_size,int reg,int base_reg,int offset,char mod);
     46    void op_mov_MR_ex       (int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset);
     47    void op_movsx_R32R16    (int reg32,int reg16 = REG_NON);
     48    void op_movsx_R32R8     (int reg32,int reg8 = REG_NON);
     49    void op_movsx_R16R8     (int reg16,int reg8 = REG_NON);
     50    void op_inc             (int reg);
     51    void op_dec             (int reg);
     52    void op_add_RV8         (int reg,char cValue);
     53    void op_add_RR          ( int reg1, int reg2 );
     54    void op_add_RM          (int op_size,int reg,int base_reg,int offset,char mod);
     55    void op_adc_RV8         (int reg,char cValue);
     56    void op_adc_RR          ( int reg1, int reg2 );
     57    void op_sub_RV8         (int reg,char cValue);
     58    void op_sub_RR          ( int reg1, int reg2 );
     59    void op_sbb_RV8         (int reg,char cValue);
     60    void op_sbb_RR          ( int reg1, int reg2 );
     61    void op_imul_RR         (int reg1,int reg2);
     62    void op_imul_RV         (int reg,long i32data);
     63    void op_imul_RV8        (int reg,char cValue);
     64    void op_div_R           ( int reg );
     65    void op_idiv_R          ( int reg );
     66    void op_and_RV          (int reg,long value);
     67    void op_and_RR          ( int reg1, int reg2 );
     68    void op_or_RR           ( int op_size, int reg1, int reg2 );
     69    void op_xor_RR          ( int reg1, int reg2 = REG_NON );
     70    void op_neg             ( int reg );
     71    void op_cdq             ();
     72
     73    void op_rep_movs        (int op_size);
     74
     75    void op_push(int reg);
     76    void op_push_V(long data);
     77    void op_push_M( int base_reg );
     78    void op_pop(int reg = REG_NON);
     79    void op_add_esp(long num);
     80    void op_sub_esp(long num);
     81    void op_cmp_RR( int reg1, int reg2 );
     82    void op_cmp_value(int op_size,int reg,char byte_data);
     83    void op_setne( int reg );
     84    void op_test(int reg1,int reg2);
     85    void op_test_ah( char cValue );
     86    void op_fld_ptr_esp(int type);
     87    void op_fld_basereg         (int type,int base_reg);
     88    void op_fld_base_offset     (int type,int base_reg,long offset);
     89    void op_fld_base_offset_ex  (int type,int base_reg1,int base_reg2,long offset,BOOL bUseOffset);
     90    void op_fstp_basereg        (int type,int base_reg);
     91    void op_fstp_base_offset    (int type,int base_reg,long offset);
     92    void op_fstp_base_offset_ex (int type,int base_reg1,int base_reg2,long offset,BOOL bUseOffset);
     93    void op_fistp_ptr_esp       ( int typeSize );
     94    void op_fstp_push           ( Type &type );
     95    void op_fcompp();
     96    void op_fnstsw_ax();
     97    void op_zero_reg(int reg);
     98    void fpu_cast();
     99    void fpu_cast_end();
     100
     101    void op_call(const UserProc *pUserProc);
     102    void op_ret();
     103#endif
     104
     105
     106
     107
     108    void PutOld( char c1, char c2 )
     109    {
     110        pNativeCode->Put( c1 );
     111        pNativeCode->Put( c2 );
     112    }
     113    void PutOld( char c1, char c2, char c3 )
     114    {
     115        pNativeCode->Put( c1 );
     116        pNativeCode->Put( c2 );
     117        pNativeCode->Put( c3 );
     118    }
     119    void PutOld( char c1, char c2, char c3, char c4 )
     120    {
     121        pNativeCode->Put( c1 );
     122        pNativeCode->Put( c2 );
     123        pNativeCode->Put( c3 );
     124        pNativeCode->Put( c4 );
     125    }
     126    void PutOld( char c1, char c2, char c3, char c4, char c5 )
     127    {
     128        pNativeCode->Put( c1 );
     129        pNativeCode->Put( c2 );
     130        pNativeCode->Put( c3 );
     131        pNativeCode->Put( c4 );
     132        pNativeCode->Put( c5 );
     133    }
     134    void PutOld( char c1, char c2, char c3, char c4, char c5, char c6 )
     135    {
     136        pNativeCode->Put( c1 );
     137        pNativeCode->Put( c2 );
     138        pNativeCode->Put( c3 );
     139        pNativeCode->Put( c4 );
     140        pNativeCode->Put( c5 );
     141        pNativeCode->Put( c6 );
     142    }
     143};
  • trunk/abdev/BasicCompiler_Common/include/Compiler.h

    r224 r225  
    55#include <MetaImpl.h>
    66#include <DataTable.h>
     7#include <CodeGenerator.h>
    78
    89class Compiler
     
    3435    }
    3536
     37    // グローバル領域のネイティブコード
     38    NativeCode globalNativeCode;
     39
     40    // コード生成機構
     41    CodeGenerator codeGenerator;
     42
    3643    static bool StringToType( const std::string &typeName, Type &type );
    3744    static const std::string TypeToString( const Type &type );
  • trunk/abdev/BasicCompiler_Common/include/NativeCode.h

    r224 r225  
    22
    33#include <vector>
     4
     5#include <BoostSerializationSupport.h>
    46
    57class Schedule
     
    911    {
    1012        None,
     13        GlobalVar,      // グローバル変数スケジュール
     14        LocalVar,       // ローカル変数スケジュール
     15        Relocation,     // リロケーション情報スケジュール
    1116    };
    1217
     
    123128        memcpy( this->codeBuffer + this->size, codeBuffer, size );
    124129        this->size += size;
     130
     131        // 未完成
     132        extern char *OpBuffer;
     133        extern int obp;
     134        memcpy( OpBuffer, codeBuffer, size );
     135        obp += size;
    125136    }
    126137    void Put( const NativeCode &nativeCode )
     
    132143        codeBuffer[size++] = c;
    133144        Realloc();
     145
     146
     147
     148        // 未完成
     149        extern char *OpBuffer;
     150        extern int obp;
     151        OpBuffer[obp++]=c;
    134152    }
    135153    void Put( long l, Schedule::Type scheduleType = Schedule::None )
     
    142160        *((long *)(codeBuffer+size))=l;
    143161        size += sizeof(long);
     162
     163
     164
     165        // 未完成
     166        extern char *OpBuffer;
     167        extern int obp;
     168        *((long *)(OpBuffer+obp))=l;
     169        obp+=sizeof(long);
    144170    }
    145171};
  • trunk/abdev/BasicCompiler_Common/include/Procedure.h

    r224 r225  
    1111#include <Parameter.h>
    1212#include <Variable.h>
    13 #include <NativeCode.h>
     13#include <CodeGenerator.h>
    1414
    1515class CClass;
     
    314314    }
    315315
     316    NativeCode &GetNativeCode()
     317    {
     318        return nativeCode;
     319    }
     320
    316321    std::string GetFullName() const;
    317322
  • trunk/abdev/BasicCompiler_Common/src/LexicalScopingImpl.cpp

    r206 r225  
    108108
    109109            //mov ecx,dword ptr[ebp+offset]
    110             op_mov_RM(sizeof(long),REG_ECX,REG_EBP,-pVar->GetOffsetAddress(),MOD_BASE_DISP32);
     110            compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_EBP,-pVar->GetOffsetAddress(),MOD_BASE_DISP32);
    111111            obp-=sizeof(long);
    112112            AddLocalVarAddrSchedule();
     
    114114
    115115            //push ecx
    116             op_push(REG_ECX);
     116            compiler.codeGenerator.op_push(REG_ECX);
    117117#endif
    118118
    119119            //call free
    120120            extern const UserProc *pSub_free;
    121             op_call(pSub_free);
     121            compiler.codeGenerator.op_call(pSub_free);
    122122
    123123
Note: See TracChangeset for help on using the changeset viewer.