* factored out writing of a single tai, so this routine can call itself

recursively when writing out typed constant data
   o basic support for tai_const

git-svn-id: branches/hlcgllvm@28109 -
This commit is contained in:
Jonas Maebe 2014-07-01 16:30:13 +00:00
parent e51b893c9e
commit 1047cdadcb

View File

@ -44,6 +44,8 @@ interface
procedure WriteDirectiveName(dir: TAsmDirective); virtual;
procedure WriteWeakSymbolDef(s: tasmsymbol);
procedure WriteRealConst(hp: tai_realconst; do_line: boolean);
procedure WriteOrdConst(hp: tai_const);
procedure WriteTai(const replaceforbidden: boolean; const do_line: boolean; var InlineLevel: cardinal; var hp: tai);
public
constructor create(smart: boolean); override;
function MakeCmdLine: TCmdStr; override;
@ -432,36 +434,20 @@ implementation
procedure TLLVMAssember.WriteTree(p:TAsmList);
var
ch : char;
lasthp,
hp : tai;
constdef : taiconst_type;
s,t : string;
i,pos,l : longint;
InlineLevel : cardinal;
last_align : longint;
co : comp;
sin : single;
d : double;
{$ifdef cpuextended}
e : extended;
{$endif cpuextended}
do_line : boolean;
sepChar : char;
replaceforbidden: boolean;
begin
if not assigned(p) then
exit;
replaceforbidden:=target_asm.dollarsign<>'$';
last_align := 2;
InlineLevel:=0;
{ lineinfo is only needed for al_procedures (PFV) }
do_line:=(cs_asm_source in current_settings.globalswitches) or
((cs_lineinfo in current_settings.moduleswitches)
and (p=current_asmdata.asmlists[al_procedures]));
lasthp:=nil;
hp:=tai(p.first);
while assigned(hp) do
begin
@ -474,14 +460,133 @@ implementation
WriteSourceLine(hp as tailineinfo);
end;
case hp.typ of
WriteTai(replaceforbidden, do_line, InlineLevel, hp);
hp:=tai(hp.next);
end;
end;
procedure TLLVMAssember.WriteExtraHeader;
begin
AsmWrite('target datalayout = "');
AsmWrite(target_info.llvmdatalayout);
AsmWriteln('"');
AsmWrite('target triple = "');
AsmWrite(llvm_target_name);
AsmWriteln('"');
end;
procedure TLLVMAssember.WriteExtraFooter;
begin
end;
procedure TLLVMAssember.WriteInstruction(hp: tai);
begin
end;
procedure TLLVMAssember.WriteLlvmInstruction(hp: tai);
begin
InstrWriter.WriteInstruction(hp);
end;
procedure TLLVMAssember.WriteWeakSymbolDef(s: tasmsymbol);
begin
AsmWriteLn(#9'.weak '+s.name);
end;
procedure TLLVMAssember.WriteRealConst(hp: tai_realconst; do_line: boolean);
var
pdata: pbyte;
index, step, swapmask, count: longint;
begin
// if do_line then
begin
case tai_realconst(hp).realtyp of
aitrealconst_s32bit:
AsmWriteLn(target_asm.comment+'value: '+single2str(tai_realconst(hp).value.s32val));
aitrealconst_s64bit:
AsmWriteLn(target_asm.comment+'value: '+double2str(tai_realconst(hp).value.s64val));
{$if defined(cpuextended) and defined(FPC_HAS_TYPE_EXTENDED)}
{ can't write full 80 bit floating point constants yet on non-x86 }
aitrealconst_s80bit:
AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_realconst(hp).value.s80val));
{$endif cpuextended}
aitrealconst_s64comp:
AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_realconst(hp).value.s64compval));
else
internalerror(2014050604);
end;
end;
end;
procedure TLLVMAssember.WriteOrdConst(hp: tai_const);
var
consttyp: taiconst_type;
begin
asmwrite(target_asm.comment+' const ');
consttyp:=hp.consttype;
case consttyp of
aitconst_got,
aitconst_gotoff_symbol,
aitconst_uleb128bit,
aitconst_sleb128bit,
aitconst_rva_symbol,
aitconst_secrel32_symbol,
aitconst_darwin_dwarf_delta32,
aitconst_darwin_dwarf_delta64,
aitconst_half16bit:
internalerror(2014052901);
aitconst_128bit,
aitconst_64bit,
aitconst_32bit,
aitconst_16bit,
aitconst_8bit,
aitconst_16bit_unaligned,
aitconst_32bit_unaligned,
aitconst_64bit_unaligned:
begin
{ can't have compile-time differences between symbols; these are
normally for PIC, but llvm takes care of that for us }
if assigned(hp.endsym) then
internalerror(2014052902);
if assigned(hp.sym) then
begin
{ type of struct vs type of field; type of asmsym? }
{ if hp.value<>0 then
xxx }
AsmWrite(hp.sym.name);
if hp.value<>0 then
AsmWrite(tostr_with_plus(hp.value));
end
else
AsmWrite(tostr(hp.value));
AsmLn;
end;
else
internalerror(200704251);
end;
end;
procedure TLLVMAssember.WriteTai(const replaceforbidden: boolean; const do_line: boolean; var InlineLevel: cardinal; var hp: tai);
var
hp2: tai;
s: string;
begin
case hp.typ of
ait_comment :
Begin
begin
AsmWrite(target_asm.comment);
AsmWritePChar(tai_comment(hp).str);
AsmLn;
End;
end;
ait_regalloc :
begin
@ -529,13 +634,12 @@ implementation
ait_const:
begin
AsmWrite(target_asm.comment);
AsmWriteln('const');
WriteOrdConst(tai_const(hp));
end;
ait_realconst :
begin
WriteRealConst(tai_realconst(hp),do_line);
WriteRealConst(tai_realconst(hp), do_line);
end;
ait_string :
@ -553,7 +657,7 @@ implementation
{ should be emitted as part of the variable/function def }
internalerror(2013010703);
end;
if tai_label(hp).labsym.bind in [AB_GLOBAL,AB_PRIVATE_EXTERN] then
if tai_label(hp).labsym.bind in [AB_GLOBAL, AB_PRIVATE_EXTERN] then
begin
{ should be emitted as part of the variable/function def }
//internalerror(2013010704);
@ -578,15 +682,15 @@ implementation
begin
if taillvmdecl(hp).def.typ=procdef then
begin
if taillvmdecl(hp).namesym.bind in [AB_EXTERNAL,AB_WEAK_EXTERNAL] then
if taillvmdecl(hp).namesym.bind in [AB_EXTERNAL, AB_WEAK_EXTERNAL] then
begin
asmwrite('declare');
asmwriteln(llvmencodeproctype(tprocdef(taillvmdecl(hp).def),taillvmdecl(hp).namesym.name,lpd_decl));
asmwriteln(llvmencodeproctype(tprocdef(taillvmdecl(hp).def), taillvmdecl(hp).namesym.name, lpd_decl));
end
else
begin
asmwrite('define');
asmwrite(llvmencodeproctype(tprocdef(taillvmdecl(hp).def),'',lpd_decl));
asmwrite(llvmencodeproctype(tprocdef(taillvmdecl(hp).def), '', lpd_decl));
asmwriteln(' {');
end;
end
@ -610,8 +714,9 @@ implementation
internalerror(2014020104);
end;
asmwrite(llvmencodetype(taillvmdecl(hp).def));
if not(taillvmdecl(hp).namesym.bind in [AB_EXTERNAL,AB_WEAK_EXTERNAL]) then
if not(taillvmdecl(hp).namesym.bind in [AB_EXTERNAL, AB_WEAK_EXTERNAL]) then
asmwrite(' zeroinitializer');
{ alignment }
asmwrite(', align ');
asmwriteln(tostr(taillvmdecl(hp).def.alignment));
end;
@ -622,23 +727,23 @@ implementation
asmwrite(' = alias ');
if taillvmalias(hp).linkage<>lll_default then
begin
str(taillvmalias(hp).linkage,s);
asmwrite(copy(s,length('lll_'),255));
str(taillvmalias(hp).linkage, s);
asmwrite(copy(s, length('lll_'), 255));
asmwrite(' ');
end
else
asmwrite('external ');
if taillvmalias(hp).vis<>llv_default then
begin
str(taillvmalias(hp).vis,s);
asmwrite(copy(s,length('llv_'),255));
str(taillvmalias(hp).vis, s);
asmwrite(copy(s, length('llv_'), 255));
asmwrite(' ');
end;
asmwrite(llvmencodeproctype(tabstractprocdef(taillvmalias(hp).def),'',lpd_alias));
asmwrite(llvmencodeproctype(tabstractprocdef(taillvmalias(hp).def), '', lpd_alias));
asmwrite('* ');
asmwriteln(taillvmalias(hp).oldsym.name);
end;
{$ifdef arm}
{$ifdef arm}
ait_thumb_func:
begin
{ should be emitted as part of the function def }
@ -649,7 +754,7 @@ implementation
{ should be emitted as part of the symbol def }
internalerror(2013010707);
end;
{$endif arm}
{$endif arm}
ait_set:
begin
{ should be emitted as part of the symbol def }
@ -725,69 +830,6 @@ implementation
else
internalerror(2006012201);
end;
lasthp:=hp;
hp:=tai(hp.next);
end;
end;
procedure TLLVMAssember.WriteExtraHeader;
begin
AsmWrite('target datalayout = "');
AsmWrite(target_info.llvmdatalayout);
AsmWriteln('"');
AsmWrite('target triple = "');
AsmWrite(llvm_target_name);
AsmWriteln('"');
end;
procedure TLLVMAssember.WriteExtraFooter;
begin
end;
procedure TLLVMAssember.WriteInstruction(hp: tai);
begin
end;
procedure TLLVMAssember.WriteLlvmInstruction(hp: tai);
begin
InstrWriter.WriteInstruction(hp);
end;
procedure TLLVMAssember.WriteWeakSymbolDef(s: tasmsymbol);
begin
AsmWriteLn(#9'.weak '+s.name);
end;
procedure TLLVMAssember.WriteRealConst(hp: tai_realconst; do_line: boolean);
var
pdata: pbyte;
index, step, swapmask, count: longint;
begin
// if do_line then
begin
case tai_realconst(hp).realtyp of
aitrealconst_s32bit:
AsmWriteLn(target_asm.comment+'value: '+single2str(tai_realconst(hp).value.s32val));
aitrealconst_s64bit:
AsmWriteLn(target_asm.comment+'value: '+double2str(tai_realconst(hp).value.s64val));
{$if defined(cpuextended) and defined(FPC_HAS_TYPE_EXTENDED)}
{ can't write full 80 bit floating point constants yet on non-x86 }
aitrealconst_s80bit:
AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_realconst(hp).value.s80val));
{$endif cpuextended}
aitrealconst_s64comp:
AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_realconst(hp).value.s64compval));
else
internalerror(2014050604);
end;
end;
end;