Changeset 188


Ignore:
Timestamp:
May 7, 2019, 6:12:15 PM (6 years ago)
Author:
chronos
Message:
  • Modified: Simplified generated computed goto.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/virtualcpu4/UCompilerPascal.pas

    r187 r188  
    7171    function GetRegister(Index: Byte; BitWidth: TBitWidth): string;
    7272    function GetMemory(Offset: string; BitWidth: TBitWidth): string;
     73    function GetJump(LabelName: string): string;
    7374  public
    7475    Reader: TInstructionReader;
     
    124125procedure TCompilerPascal.InstJump;
    125126begin
    126   AddLine('GotoAddr(@L' + IntToStr(Reader.ReadAddress) + ');');
     127  AddLine(GetJump('L' + IntToStr(Reader.ReadAddress)));
    127128end;
    128129
    129130procedure TCompilerPascal.InstJumpZero;
    130131begin
    131   AddLine('if Zero then GotoAddr(@L' + IntToStr(Reader.ReadAddress) + ');');
     132  AddLine('if Zero then ' + GetJump('L' + IntToStr(Reader.ReadAddress)));
    132133end;
    133134
    134135procedure TCompilerPascal.InstJumpNotZero;
    135136begin
    136   AddLine('if not Zero then GotoAddr(@L' + IntToStr(Reader.ReadAddress) + ');');
     137  AddLine('if not Zero then ' + GetJump('L' + IntToStr(Reader.ReadAddress)));
    137138end;
    138139
     
    142143begin
    143144  Addr := Reader.ReadAddressSigned;
    144   AddLine('GotoAddr(@L' + IntToStr(Reader.IP + Addr) + ');');
     145  AddLine(GetJump('L' + IntToStr(Reader.IP + Addr)));
    145146end;
    146147
     
    150151begin
    151152  Addr := Reader.ReadAddressSigned;
    152   AddLine('if Zero then GotoAddr(@L' + IntToStr(Reader.IP + Addr) + ');');
     153  AddLine('if Zero then ' + GetJump('L' + IntToStr(Reader.IP + Addr)));
    153154end;
    154155
     
    158159begin
    159160  Addr := Reader.ReadAddressSigned;
    160   AddLine('if not Zero then GotoAddr(@L' + IntToStr(Reader.IP + Addr) + ');');
     161  AddLine('if not Zero then ' + GetJump('L' + IntToStr(Reader.IP + Addr)));
    161162end;
    162163
     
    240241  Addr := Reader.ReadAddress;
    241242  AddLine('Dec(SP, ' + IntToStr(BitWidthBytes[Reader.AddrSize]) + ');');
    242   AddLine(GetMemory('SP', Reader.AddrSize) + ' := ' + IntToStr(Reader.IP) + ';');
    243   AddLine('GotoAddr(@L' + IntToStr(Addr) + ');');
     243  AddLine(GetMemory('SP', Reader.AddrSize) + ' := LongWord(@L' + IntToStr(Reader.IP) + ');');
     244  AddLine(GetJump('L' + IntToStr(Addr)));
    244245end;
    245246
     
    248249  AddLine('TempAddr := Pointer(' + GetMemory('SP', Reader.AddrSize) + ');');
    249250  AddLine('Inc(SP, ' + IntToStr(BitWidthBytes[Reader.AddrSize]) + ');');
    250   AddLine('GotoAddr(TempAddr);');
     251  AddLine(GetJump('TempAddr'));
    251252end;
    252253
     
    551552end;
    552553
     554function TCompilerPascal.GetJump(LabelName: string): string;
     555begin
     556  Result := 'asm jmp ' + LabelName + ' end;';
     557end;
     558
    553559procedure TCompilerPascal.Compile;
    554560var
     
    607613  AddLine('  TempAddr: Pointer;');
    608614  AddLine('');
    609   AddLine('procedure GotoAddr(P: Pointer); inline; assembler;');
    610   AddLine('asm');
    611   AddLine('  jmp P;');
    612   AddLine('end;');
    613   AddLine('');
    614615  LabelsText := '';
    615616  for I := 0 to Labels.Count - 1 do begin
Note: See TracChangeset for help on using the changeset viewer.