mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-04 04:50:30 +02:00
* Support for sleb128 and uleb128 constants in the NASM writer.
* Added sleb128tostr() and uleb128tostr() methods to TExternalAssembler. * Use these methods in assembler writers instead of code duplication.
This commit is contained in:
parent
5479663e56
commit
122ed4b76a
@ -74,8 +74,6 @@ interface
|
|||||||
{$endif WASM}
|
{$endif WASM}
|
||||||
private
|
private
|
||||||
setcount: longint;
|
setcount: longint;
|
||||||
procedure WriteDecodedSleb128(a: int64);
|
|
||||||
procedure WriteDecodedUleb128(a: qword);
|
|
||||||
procedure WriteCFI(hp: tai_cfi_base);
|
procedure WriteCFI(hp: tai_cfi_base);
|
||||||
function NextSetLabel: string;
|
function NextSetLabel: string;
|
||||||
protected
|
protected
|
||||||
@ -660,21 +658,6 @@ implementation
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TGNUAssembler.WriteDecodedUleb128(a: qword);
|
|
||||||
var
|
|
||||||
i,len : longint;
|
|
||||||
buf : array[0..63] of byte;
|
|
||||||
begin
|
|
||||||
len:=EncodeUleb128(a,buf,0);
|
|
||||||
for i:=0 to len-1 do
|
|
||||||
begin
|
|
||||||
if (i > 0) then
|
|
||||||
writer.AsmWrite(',');
|
|
||||||
writer.AsmWrite(tostr(buf[i]));
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure TGNUAssembler.WriteCFI(hp: tai_cfi_base);
|
procedure TGNUAssembler.WriteCFI(hp: tai_cfi_base);
|
||||||
begin
|
begin
|
||||||
writer.AsmWrite(cfi2str[hp.cfityp]);
|
writer.AsmWrite(cfi2str[hp.cfityp]);
|
||||||
@ -708,21 +691,6 @@ implementation
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TGNUAssembler.WriteDecodedSleb128(a: int64);
|
|
||||||
var
|
|
||||||
i,len : longint;
|
|
||||||
buf : array[0..255] of byte;
|
|
||||||
begin
|
|
||||||
len:=EncodeSleb128(a,buf,0);
|
|
||||||
for i:=0 to len-1 do
|
|
||||||
begin
|
|
||||||
if (i > 0) then
|
|
||||||
writer.AsmWrite(',');
|
|
||||||
writer.AsmWrite(tostr(buf[i]));
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
{$ifdef WASM}
|
{$ifdef WASM}
|
||||||
procedure TGNUAssembler.WriteFuncType(functype: TWasmFuncType);
|
procedure TGNUAssembler.WriteFuncType(functype: TWasmFuncType);
|
||||||
var
|
var
|
||||||
@ -1194,9 +1162,9 @@ implementation
|
|||||||
writer.AsmWrite(ait_const2str[aitconst_8bit]);
|
writer.AsmWrite(ait_const2str[aitconst_8bit]);
|
||||||
case tai_const(hp).consttype of
|
case tai_const(hp).consttype of
|
||||||
aitconst_uleb128bit:
|
aitconst_uleb128bit:
|
||||||
WriteDecodedUleb128(qword(tai_const(hp).value));
|
writer.AsmWrite(uleb128tostr(qword(tai_const(hp).value)));
|
||||||
aitconst_sleb128bit:
|
aitconst_sleb128bit:
|
||||||
WriteDecodedSleb128(int64(tai_const(hp).value));
|
writer.AsmWrite(sleb128tostr(tai_const(hp).value));
|
||||||
else
|
else
|
||||||
;
|
;
|
||||||
end
|
end
|
||||||
|
@ -157,6 +157,8 @@ interface
|
|||||||
function single2str(d : single) : string; virtual;
|
function single2str(d : single) : string; virtual;
|
||||||
function double2str(d : double) : string; virtual;
|
function double2str(d : double) : string; virtual;
|
||||||
function extended2str(e : extended) : string; virtual;
|
function extended2str(e : extended) : string; virtual;
|
||||||
|
function sleb128tostr(a : int64) : string;
|
||||||
|
function uleb128tostr(a : qword) : string;
|
||||||
Function DoPipe:boolean; virtual;
|
Function DoPipe:boolean; virtual;
|
||||||
|
|
||||||
function CreateNewAsmWriter: TExternalAssemblerOutputFile; virtual;
|
function CreateNewAsmWriter: TExternalAssemblerOutputFile; virtual;
|
||||||
@ -744,6 +746,36 @@ Implementation
|
|||||||
extended2str:='0d'+hs
|
extended2str:='0d'+hs
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TExternalAssembler.sleb128tostr(a: int64): string;
|
||||||
|
var
|
||||||
|
i,len : longint;
|
||||||
|
buf : array[0..31] of byte;
|
||||||
|
begin
|
||||||
|
result:='';
|
||||||
|
len:=EncodeSleb128(a,buf,0);
|
||||||
|
for i:=0 to len-1 do
|
||||||
|
begin
|
||||||
|
if (i > 0) then
|
||||||
|
result:=result+',';
|
||||||
|
result:=result+tostr(buf[i]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TExternalAssembler.uleb128tostr(a: qword): string;
|
||||||
|
var
|
||||||
|
i,len : longint;
|
||||||
|
buf : array[0..31] of byte;
|
||||||
|
begin
|
||||||
|
result:='';
|
||||||
|
len:=EncodeUleb128(a,buf,0);
|
||||||
|
for i:=0 to len-1 do
|
||||||
|
begin
|
||||||
|
if (i > 0) then
|
||||||
|
result:=result+',';
|
||||||
|
result:=result+tostr(buf[i]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function TExternalAssembler.DoPipe:boolean;
|
Function TExternalAssembler.DoPipe:boolean;
|
||||||
begin
|
begin
|
||||||
|
@ -800,13 +800,13 @@ interface
|
|||||||
begin
|
begin
|
||||||
consttype:=tai_const(hp).consttype;
|
consttype:=tai_const(hp).consttype;
|
||||||
case consttype of
|
case consttype of
|
||||||
aitconst_uleb128bit,
|
aitconst_uleb128bit:
|
||||||
aitconst_sleb128bit,
|
writer.AsmWriteLn(ait_const2str[aitconst_8bit]+uleb128tostr(qword(tai_const(hp).value)));
|
||||||
|
aitconst_sleb128bit:
|
||||||
|
writer.AsmWriteLn(ait_const2str[aitconst_8bit]+sleb128tostr(tai_const(hp).value));
|
||||||
aitconst_128bit:
|
aitconst_128bit:
|
||||||
begin
|
writer.AsmWriteLn(asminfo^.comment+'Unsupported const type '+
|
||||||
writer.AsmWriteLn(asminfo^.comment+'Unsupported const type '+
|
ait_const2str[consttype]);
|
||||||
ait_const2str[consttype]);
|
|
||||||
end;
|
|
||||||
{$ifdef i8086}
|
{$ifdef i8086}
|
||||||
aitconst_farptr:
|
aitconst_farptr:
|
||||||
begin
|
begin
|
||||||
|
@ -41,8 +41,6 @@ unit agsdasz80;
|
|||||||
|
|
||||||
TSdccSdasZ80Assembler=class(TExternalAssembler)
|
TSdccSdasZ80Assembler=class(TExternalAssembler)
|
||||||
private
|
private
|
||||||
procedure WriteDecodedSleb128(a: int64);
|
|
||||||
procedure WriteDecodedUleb128(a: qword);
|
|
||||||
procedure WriteRealConstAsBytes(hp: tai_realconst; const dbdir: string; do_line: boolean);
|
procedure WriteRealConstAsBytes(hp: tai_realconst; const dbdir: string; do_line: boolean);
|
||||||
function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
|
function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
|
||||||
procedure WriteSection(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder;secalign:longint;
|
procedure WriteSection(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder;secalign:longint;
|
||||||
@ -79,38 +77,6 @@ unit agsdasz80;
|
|||||||
#9'.dw'#9,#9'FIXMEDD'#9,#9'FIXMEDQ'#9
|
#9'.dw'#9,#9'FIXMEDD'#9,#9'FIXMEDQ'#9
|
||||||
);
|
);
|
||||||
|
|
||||||
procedure TSdccSdasZ80Assembler.WriteDecodedSleb128(a: int64);
|
|
||||||
var
|
|
||||||
i,len : longint;
|
|
||||||
buf : array[0..255] of byte;
|
|
||||||
begin
|
|
||||||
writer.AsmWrite(#9'.db'#9);
|
|
||||||
len:=EncodeSleb128(a,buf,0);
|
|
||||||
for i:=0 to len-1 do
|
|
||||||
begin
|
|
||||||
if (i > 0) then
|
|
||||||
writer.AsmWrite(',');
|
|
||||||
writer.AsmWrite(tostr(buf[i]));
|
|
||||||
end;
|
|
||||||
writer.AsmWriteLn(#9'; sleb '+tostr(a));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TSdccSdasZ80Assembler.WriteDecodedUleb128(a: qword);
|
|
||||||
var
|
|
||||||
i,len : longint;
|
|
||||||
buf : array[0..63] of byte;
|
|
||||||
begin
|
|
||||||
writer.AsmWrite(#9'.db'#9);
|
|
||||||
len:=EncodeUleb128(a,buf,0);
|
|
||||||
for i:=0 to len-1 do
|
|
||||||
begin
|
|
||||||
if (i > 0) then
|
|
||||||
writer.AsmWrite(',');
|
|
||||||
writer.AsmWrite(tostr(buf[i]));
|
|
||||||
end;
|
|
||||||
writer.AsmWriteLn(#9'; uleb '+tostr(a));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TSdccSdasZ80Assembler.WriteRealConstAsBytes(hp: tai_realconst; const dbdir: string; do_line: boolean);
|
procedure TSdccSdasZ80Assembler.WriteRealConstAsBytes(hp: tai_realconst; const dbdir: string; do_line: boolean);
|
||||||
var
|
var
|
||||||
pdata: pbyte;
|
pdata: pbyte;
|
||||||
@ -652,9 +618,9 @@ unit agsdasz80;
|
|||||||
consttype:=tai_const(hp).consttype;
|
consttype:=tai_const(hp).consttype;
|
||||||
case consttype of
|
case consttype of
|
||||||
aitconst_uleb128bit:
|
aitconst_uleb128bit:
|
||||||
WriteDecodedUleb128(qword(tai_const(hp).value));
|
writer.AsmWriteLn(ait_const2str[aitconst_8bit]+uleb128tostr(qword(tai_const(hp).value)));
|
||||||
aitconst_sleb128bit:
|
aitconst_sleb128bit:
|
||||||
WriteDecodedSleb128(int64(tai_const(hp).value));
|
writer.AsmWriteLn(ait_const2str[aitconst_8bit]+sleb128tostr(tai_const(hp).value));
|
||||||
aitconst_64bit,
|
aitconst_64bit,
|
||||||
aitconst_64bit_unaligned,
|
aitconst_64bit_unaligned,
|
||||||
aitconst_32bit,
|
aitconst_32bit,
|
||||||
|
@ -41,8 +41,6 @@ unit agz80vasm;
|
|||||||
|
|
||||||
TZ80Vasm=class(TExternalAssembler)
|
TZ80Vasm=class(TExternalAssembler)
|
||||||
private
|
private
|
||||||
procedure WriteDecodedSleb128(a: int64);
|
|
||||||
procedure WriteDecodedUleb128(a: qword);
|
|
||||||
procedure WriteRealConstAsBytes(hp: tai_realconst; const dbdir: string; do_line: boolean);
|
procedure WriteRealConstAsBytes(hp: tai_realconst; const dbdir: string; do_line: boolean);
|
||||||
function sectionattrs(atype:TAsmSectiontype):string;
|
function sectionattrs(atype:TAsmSectiontype):string;
|
||||||
function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
|
function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
|
||||||
@ -80,38 +78,6 @@ unit agz80vasm;
|
|||||||
#9'.uahalf'#9,#9'FIXMEDD'#9,#9'FIXMEDQ'#9
|
#9'.uahalf'#9,#9'FIXMEDD'#9,#9'FIXMEDQ'#9
|
||||||
);
|
);
|
||||||
|
|
||||||
procedure TZ80vasm.WriteDecodedSleb128(a: int64);
|
|
||||||
var
|
|
||||||
i,len : longint;
|
|
||||||
buf : array[0..255] of byte;
|
|
||||||
begin
|
|
||||||
writer.AsmWrite(#9'.byte'#9);
|
|
||||||
len:=EncodeSleb128(a,buf,0);
|
|
||||||
for i:=0 to len-1 do
|
|
||||||
begin
|
|
||||||
if (i > 0) then
|
|
||||||
writer.AsmWrite(',');
|
|
||||||
writer.AsmWrite(tostr(buf[i]));
|
|
||||||
end;
|
|
||||||
writer.AsmWriteLn(#9'; sleb '+tostr(a));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TZ80vasm.WriteDecodedUleb128(a: qword);
|
|
||||||
var
|
|
||||||
i,len : longint;
|
|
||||||
buf : array[0..63] of byte;
|
|
||||||
begin
|
|
||||||
writer.AsmWrite(#9'.byte'#9);
|
|
||||||
len:=EncodeUleb128(a,buf,0);
|
|
||||||
for i:=0 to len-1 do
|
|
||||||
begin
|
|
||||||
if (i > 0) then
|
|
||||||
writer.AsmWrite(',');
|
|
||||||
writer.AsmWrite(tostr(buf[i]));
|
|
||||||
end;
|
|
||||||
writer.AsmWriteLn(#9'; uleb '+tostr(a));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TZ80vasm.WriteRealConstAsBytes(hp: tai_realconst; const dbdir: string; do_line: boolean);
|
procedure TZ80vasm.WriteRealConstAsBytes(hp: tai_realconst; const dbdir: string; do_line: boolean);
|
||||||
var
|
var
|
||||||
pdata: pbyte;
|
pdata: pbyte;
|
||||||
@ -683,9 +649,9 @@ unit agz80vasm;
|
|||||||
consttype:=tai_const(hp).consttype;
|
consttype:=tai_const(hp).consttype;
|
||||||
case consttype of
|
case consttype of
|
||||||
aitconst_uleb128bit:
|
aitconst_uleb128bit:
|
||||||
WriteDecodedUleb128(qword(tai_const(hp).value));
|
writer.AsmWriteLn(ait_const2str[aitconst_8bit]+uleb128tostr(qword(tai_const(hp).value)));
|
||||||
aitconst_sleb128bit:
|
aitconst_sleb128bit:
|
||||||
WriteDecodedSleb128(int64(tai_const(hp).value));
|
writer.AsmWriteLn(ait_const2str[aitconst_8bit]+sleb128tostr(tai_const(hp).value));
|
||||||
aitconst_64bit,
|
aitconst_64bit,
|
||||||
aitconst_64bit_unaligned,
|
aitconst_64bit_unaligned,
|
||||||
aitconst_32bit,
|
aitconst_32bit,
|
||||||
|
Loading…
Reference in New Issue
Block a user