mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-14 07:59:27 +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}
|
||||
private
|
||||
setcount: longint;
|
||||
procedure WriteDecodedSleb128(a: int64);
|
||||
procedure WriteDecodedUleb128(a: qword);
|
||||
procedure WriteCFI(hp: tai_cfi_base);
|
||||
function NextSetLabel: string;
|
||||
protected
|
||||
@ -660,21 +658,6 @@ implementation
|
||||
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);
|
||||
begin
|
||||
writer.AsmWrite(cfi2str[hp.cfityp]);
|
||||
@ -708,21 +691,6 @@ implementation
|
||||
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}
|
||||
procedure TGNUAssembler.WriteFuncType(functype: TWasmFuncType);
|
||||
var
|
||||
@ -1194,9 +1162,9 @@ implementation
|
||||
writer.AsmWrite(ait_const2str[aitconst_8bit]);
|
||||
case tai_const(hp).consttype of
|
||||
aitconst_uleb128bit:
|
||||
WriteDecodedUleb128(qword(tai_const(hp).value));
|
||||
writer.AsmWrite(uleb128tostr(qword(tai_const(hp).value)));
|
||||
aitconst_sleb128bit:
|
||||
WriteDecodedSleb128(int64(tai_const(hp).value));
|
||||
writer.AsmWrite(sleb128tostr(tai_const(hp).value));
|
||||
else
|
||||
;
|
||||
end
|
||||
|
@ -157,6 +157,8 @@ interface
|
||||
function single2str(d : single) : string; virtual;
|
||||
function double2str(d : double) : string; virtual;
|
||||
function extended2str(e : extended) : string; virtual;
|
||||
function sleb128tostr(a : int64) : string;
|
||||
function uleb128tostr(a : qword) : string;
|
||||
Function DoPipe:boolean; virtual;
|
||||
|
||||
function CreateNewAsmWriter: TExternalAssemblerOutputFile; virtual;
|
||||
@ -744,6 +746,36 @@ Implementation
|
||||
extended2str:='0d'+hs
|
||||
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;
|
||||
begin
|
||||
|
@ -800,13 +800,13 @@ interface
|
||||
begin
|
||||
consttype:=tai_const(hp).consttype;
|
||||
case consttype of
|
||||
aitconst_uleb128bit,
|
||||
aitconst_sleb128bit,
|
||||
aitconst_uleb128bit:
|
||||
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:
|
||||
begin
|
||||
writer.AsmWriteLn(asminfo^.comment+'Unsupported const type '+
|
||||
ait_const2str[consttype]);
|
||||
end;
|
||||
writer.AsmWriteLn(asminfo^.comment+'Unsupported const type '+
|
||||
ait_const2str[consttype]);
|
||||
{$ifdef i8086}
|
||||
aitconst_farptr:
|
||||
begin
|
||||
|
@ -41,8 +41,6 @@ unit agsdasz80;
|
||||
|
||||
TSdccSdasZ80Assembler=class(TExternalAssembler)
|
||||
private
|
||||
procedure WriteDecodedSleb128(a: int64);
|
||||
procedure WriteDecodedUleb128(a: qword);
|
||||
procedure WriteRealConstAsBytes(hp: tai_realconst; const dbdir: string; do_line: boolean);
|
||||
function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
|
||||
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
|
||||
);
|
||||
|
||||
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);
|
||||
var
|
||||
pdata: pbyte;
|
||||
@ -652,9 +618,9 @@ unit agsdasz80;
|
||||
consttype:=tai_const(hp).consttype;
|
||||
case consttype of
|
||||
aitconst_uleb128bit:
|
||||
WriteDecodedUleb128(qword(tai_const(hp).value));
|
||||
writer.AsmWriteLn(ait_const2str[aitconst_8bit]+uleb128tostr(qword(tai_const(hp).value)));
|
||||
aitconst_sleb128bit:
|
||||
WriteDecodedSleb128(int64(tai_const(hp).value));
|
||||
writer.AsmWriteLn(ait_const2str[aitconst_8bit]+sleb128tostr(tai_const(hp).value));
|
||||
aitconst_64bit,
|
||||
aitconst_64bit_unaligned,
|
||||
aitconst_32bit,
|
||||
|
@ -41,8 +41,6 @@ unit agz80vasm;
|
||||
|
||||
TZ80Vasm=class(TExternalAssembler)
|
||||
private
|
||||
procedure WriteDecodedSleb128(a: int64);
|
||||
procedure WriteDecodedUleb128(a: qword);
|
||||
procedure WriteRealConstAsBytes(hp: tai_realconst; const dbdir: string; do_line: boolean);
|
||||
function sectionattrs(atype:TAsmSectiontype):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
|
||||
);
|
||||
|
||||
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);
|
||||
var
|
||||
pdata: pbyte;
|
||||
@ -683,9 +649,9 @@ unit agz80vasm;
|
||||
consttype:=tai_const(hp).consttype;
|
||||
case consttype of
|
||||
aitconst_uleb128bit:
|
||||
WriteDecodedUleb128(qword(tai_const(hp).value));
|
||||
writer.AsmWriteLn(ait_const2str[aitconst_8bit]+uleb128tostr(qword(tai_const(hp).value)));
|
||||
aitconst_sleb128bit:
|
||||
WriteDecodedSleb128(int64(tai_const(hp).value));
|
||||
writer.AsmWriteLn(ait_const2str[aitconst_8bit]+sleb128tostr(tai_const(hp).value));
|
||||
aitconst_64bit,
|
||||
aitconst_64bit_unaligned,
|
||||
aitconst_32bit,
|
||||
|
Loading…
Reference in New Issue
Block a user