|
@@ -30,7 +30,7 @@ interface
|
|
globtype,globals,systems,
|
|
globtype,globals,systems,
|
|
aasmbase,aasmtai,aasmdata,
|
|
aasmbase,aasmtai,aasmdata,
|
|
assemble,
|
|
assemble,
|
|
- aasmllvm;
|
|
|
|
|
|
+ aasmllvm, aasmllvmmetadata;
|
|
|
|
|
|
type
|
|
type
|
|
TLLVMInstrWriter = class;
|
|
TLLVMInstrWriter = class;
|
|
@@ -61,7 +61,7 @@ interface
|
|
procedure WriteDirectiveName(dir: TAsmDirective); virtual;
|
|
procedure WriteDirectiveName(dir: TAsmDirective); virtual;
|
|
procedure WriteRealConst(hp: tai_realconst; do_line: boolean);
|
|
procedure WriteRealConst(hp: tai_realconst; do_line: boolean);
|
|
procedure WriteOrdConst(hp: tai_const);
|
|
procedure WriteOrdConst(hp: tai_const);
|
|
- procedure WriteTai(const replaceforbidden: boolean; const do_line: boolean; var InlineLevel: cardinal; var asmblock: boolean; var hp: tai);
|
|
|
|
|
|
+ procedure WriteTai(const replaceforbidden: boolean; const do_line, inmetadata: boolean; var InlineLevel: cardinal; var asmblock: boolean; var hp: tai);
|
|
public
|
|
public
|
|
constructor CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean); override;
|
|
constructor CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean); override;
|
|
procedure WriteTree(p:TAsmList);override;
|
|
procedure WriteTree(p:TAsmList);override;
|
|
@@ -376,7 +376,7 @@ implementation
|
|
hp:=para^.ai;
|
|
hp:=para^.ai;
|
|
owner.writer.AsmWrite(fstr);
|
|
owner.writer.AsmWrite(fstr);
|
|
fstr:='';
|
|
fstr:='';
|
|
- owner.WriteTai(false,false,tmpinline,tmpasmblock,hp);
|
|
|
|
|
|
+ owner.WriteTai(false,false,para^.def=llvm_metadatatype,tmpinline,tmpasmblock,hp);
|
|
end;
|
|
end;
|
|
{ empty records }
|
|
{ empty records }
|
|
top_undef:
|
|
top_undef:
|
|
@@ -436,7 +436,6 @@ implementation
|
|
|
|
|
|
function TLLVMInstrWriter.getopstr(const o:toper; refwithalign: boolean) : TSymStr;
|
|
function TLLVMInstrWriter.getopstr(const o:toper; refwithalign: boolean) : TSymStr;
|
|
var
|
|
var
|
|
- hs : ansistring;
|
|
|
|
hp: tai;
|
|
hp: tai;
|
|
tmpinline: cardinal;
|
|
tmpinline: cardinal;
|
|
tmpasmblock: boolean;
|
|
tmpasmblock: boolean;
|
|
@@ -499,7 +498,7 @@ implementation
|
|
hp:=o.ai;
|
|
hp:=o.ai;
|
|
owner.writer.AsmWrite(fstr);
|
|
owner.writer.AsmWrite(fstr);
|
|
fstr:='';
|
|
fstr:='';
|
|
- owner.WriteTai(false,false,tmpinline,tmpasmblock,hp);
|
|
|
|
|
|
+ owner.WriteTai(false,false,false,tmpinline,tmpasmblock,hp);
|
|
end;
|
|
end;
|
|
result:='';
|
|
result:='';
|
|
end;
|
|
end;
|
|
@@ -838,7 +837,7 @@ implementation
|
|
WriteSourceLine(hp as tailineinfo);
|
|
WriteSourceLine(hp as tailineinfo);
|
|
end;
|
|
end;
|
|
|
|
|
|
- WriteTai(replaceforbidden, do_line, InlineLevel, asmblock, hp);
|
|
|
|
|
|
+ WriteTai(replaceforbidden, do_line, false, InlineLevel, asmblock, hp);
|
|
hp:=tai(hp.next);
|
|
hp:=tai(hp.next);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -971,7 +970,7 @@ implementation
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure TLLVMAssember.WriteTai(const replaceforbidden: boolean; const do_line: boolean; var InlineLevel: cardinal; var asmblock: boolean; var hp: tai);
|
|
|
|
|
|
+ procedure TLLVMAssember.WriteTai(const replaceforbidden: boolean; const do_line, inmetadata: boolean; var InlineLevel: cardinal; var asmblock: boolean; var hp: tai);
|
|
|
|
|
|
procedure WriteLinkageVibilityFlags(bind: TAsmSymBind);
|
|
procedure WriteLinkageVibilityFlags(bind: TAsmSymBind);
|
|
begin
|
|
begin
|
|
@@ -1021,20 +1020,34 @@ implementation
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure WriteTypedConstData(hp: tai_abstracttypedconst);
|
|
|
|
|
|
+ procedure WriteTypedConstData(hp: tai_abstracttypedconst; metadata: boolean);
|
|
var
|
|
var
|
|
p: tai_abstracttypedconst;
|
|
p: tai_abstracttypedconst;
|
|
pval: tai;
|
|
pval: tai;
|
|
defstr: TSymStr;
|
|
defstr: TSymStr;
|
|
first, gotstring: boolean;
|
|
first, gotstring: boolean;
|
|
begin
|
|
begin
|
|
- defstr:=llvmencodetypename(hp.def);
|
|
|
|
|
|
+ if hp.def<>llvm_metadatatype then
|
|
|
|
+ begin
|
|
|
|
+ defstr:=llvmencodetypename(hp.def)
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ defstr:=''
|
|
|
|
+ end;
|
|
{ write the struct, array or simple type }
|
|
{ write the struct, array or simple type }
|
|
case hp.adetyp of
|
|
case hp.adetyp of
|
|
tck_record:
|
|
tck_record:
|
|
begin
|
|
begin
|
|
- writer.AsmWrite(defstr);
|
|
|
|
- writer.AsmWrite(' <{');
|
|
|
|
|
|
+ if not(metadata) then
|
|
|
|
+ begin
|
|
|
|
+ writer.AsmWrite(defstr);
|
|
|
|
+ writer.AsmWrite(' <{');
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ writer.AsmWrite(' !{');
|
|
|
|
+ end;
|
|
first:=true;
|
|
first:=true;
|
|
for p in tai_aggregatetypedconst(hp) do
|
|
for p in tai_aggregatetypedconst(hp) do
|
|
begin
|
|
begin
|
|
@@ -1042,19 +1055,29 @@ implementation
|
|
writer.AsmWrite(', ')
|
|
writer.AsmWrite(', ')
|
|
else
|
|
else
|
|
first:=false;
|
|
first:=false;
|
|
- WriteTypedConstData(p);
|
|
|
|
|
|
+ WriteTypedConstData(p,metadata);
|
|
|
|
+ end;
|
|
|
|
+ if not(metadata) then
|
|
|
|
+ begin
|
|
|
|
+ writer.AsmWrite('}>');
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ writer.AsmWrite('}');
|
|
end;
|
|
end;
|
|
- writer.AsmWrite('}>');
|
|
|
|
end;
|
|
end;
|
|
tck_array:
|
|
tck_array:
|
|
begin
|
|
begin
|
|
- writer.AsmWrite(defstr);
|
|
|
|
|
|
+ if not(metadata) then
|
|
|
|
+ begin
|
|
|
|
+ writer.AsmWrite(defstr);
|
|
|
|
+ end;
|
|
first:=true;
|
|
first:=true;
|
|
gotstring:=false;
|
|
gotstring:=false;
|
|
for p in tai_aggregatetypedconst(hp) do
|
|
for p in tai_aggregatetypedconst(hp) do
|
|
begin
|
|
begin
|
|
if not first then
|
|
if not first then
|
|
- writer.AsmWrite(',')
|
|
|
|
|
|
+ writer.AsmWrite(', ')
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
writer.AsmWrite(' ');
|
|
writer.AsmWrite(' ');
|
|
@@ -1065,33 +1088,65 @@ implementation
|
|
end
|
|
end
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
- writer.AsmWrite('[');
|
|
|
|
|
|
+ if not metadata then
|
|
|
|
+ begin
|
|
|
|
+ writer.AsmWrite('[');
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ writer.AsmWrite('!{');
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
first:=false;
|
|
first:=false;
|
|
end;
|
|
end;
|
|
{ cannot concat strings and other things }
|
|
{ cannot concat strings and other things }
|
|
if gotstring and
|
|
if gotstring and
|
|
|
|
+ not metadata and
|
|
((tai_abstracttypedconst(p).adetyp<>tck_simple) or
|
|
((tai_abstracttypedconst(p).adetyp<>tck_simple) or
|
|
(tai_simpletypedconst(p).val.typ<>ait_string)) then
|
|
(tai_simpletypedconst(p).val.typ<>ait_string)) then
|
|
internalerror(2014062701);
|
|
internalerror(2014062701);
|
|
- WriteTypedConstData(p);
|
|
|
|
|
|
+ WriteTypedConstData(p,metadata);
|
|
end;
|
|
end;
|
|
if not gotstring then
|
|
if not gotstring then
|
|
- writer.AsmWrite(']');
|
|
|
|
|
|
+ begin
|
|
|
|
+ if not metadata then
|
|
|
|
+ begin
|
|
|
|
+ writer.AsmWrite(']');
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ writer.AsmWrite('}');
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
tck_simple:
|
|
tck_simple:
|
|
begin
|
|
begin
|
|
pval:=tai_simpletypedconst(hp).val;
|
|
pval:=tai_simpletypedconst(hp).val;
|
|
- if pval.typ<>ait_string then
|
|
|
|
|
|
+ if (pval.typ<>ait_string) and
|
|
|
|
+ (defstr<>'') then
|
|
begin
|
|
begin
|
|
writer.AsmWrite(defstr);
|
|
writer.AsmWrite(defstr);
|
|
writer.AsmWrite(' ');
|
|
writer.AsmWrite(' ');
|
|
end;
|
|
end;
|
|
- WriteTai(replaceforbidden,do_line,InlineLevel,asmblock,pval);
|
|
|
|
|
|
+ WriteTai(replaceforbidden,do_line,metadata,InlineLevel,asmblock,pval);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+ procedure WriteLlvmMetadataNode(hp: tai_llvmbasemetadatanode);
|
|
|
|
+ begin
|
|
|
|
+ { must only appear at the top level }
|
|
|
|
+ if fdecllevel<>0 then
|
|
|
|
+ internalerror(2019050111);
|
|
|
|
+ writer.AsmWrite('!');
|
|
|
|
+ writer.AsmWrite(tai_llvmbasemetadatanode(hp).name);
|
|
|
|
+ writer.AsmWrite(' =');
|
|
|
|
+ inc(fdecllevel);
|
|
|
|
+ WriteTypedConstData(hp,true);
|
|
|
|
+ writer.AsmLn;
|
|
|
|
+ dec(fdecllevel);
|
|
|
|
+ end;
|
|
|
|
+
|
|
var
|
|
var
|
|
hp2: tai;
|
|
hp2: tai;
|
|
s: string;
|
|
s: string;
|
|
@@ -1162,7 +1217,10 @@ implementation
|
|
begin
|
|
begin
|
|
if fdecllevel=0 then
|
|
if fdecllevel=0 then
|
|
internalerror(2016120201);
|
|
internalerror(2016120201);
|
|
- writer.AsmWrite('c"');
|
|
|
|
|
|
+ if not inmetadata then
|
|
|
|
+ writer.AsmWrite('c"')
|
|
|
|
+ else
|
|
|
|
+ writer.AsmWrite('!"');
|
|
for i:=1 to tai_string(hp).len do
|
|
for i:=1 to tai_string(hp).len do
|
|
begin
|
|
begin
|
|
ch:=tai_string(hp).str[i-1];
|
|
ch:=tai_string(hp).str[i-1];
|
|
@@ -1278,7 +1336,7 @@ implementation
|
|
hp2:=tai(taillvmdecl(hp).initdata.first);
|
|
hp2:=tai(taillvmdecl(hp).initdata.first);
|
|
while assigned(hp2) do
|
|
while assigned(hp2) do
|
|
begin
|
|
begin
|
|
- WriteTai(replaceforbidden,do_line,InlineLevel,asmblock,hp2);
|
|
|
|
|
|
+ WriteTai(replaceforbidden,do_line,inmetadata,InlineLevel,asmblock,hp2);
|
|
hp2:=tai(hp2.next);
|
|
hp2:=tai(hp2.next);
|
|
end;
|
|
end;
|
|
dec(fdecllevel);
|
|
dec(fdecllevel);
|
|
@@ -1328,6 +1386,28 @@ implementation
|
|
writer.AsmWrite('* ');
|
|
writer.AsmWrite('* ');
|
|
writer.AsmWriteln(LlvmAsmSymName(taillvmalias(hp).oldsym));
|
|
writer.AsmWriteln(LlvmAsmSymName(taillvmalias(hp).oldsym));
|
|
end;
|
|
end;
|
|
|
|
+ ait_llvmmetadatanode:
|
|
|
|
+ begin
|
|
|
|
+ WriteLlvmMetadataNode(tai_llvmbasemetadatanode(hp));
|
|
|
|
+ end;
|
|
|
|
+ ait_llvmmetadatareftypedconst:
|
|
|
|
+ begin
|
|
|
|
+ { must only appear as an element in a typed const }
|
|
|
|
+ if fdecllevel=0 then
|
|
|
|
+ internalerror(2019050110);
|
|
|
|
+ writer.AsmWrite('!');
|
|
|
|
+ writer.AsmWrite(tai_llvmbasemetadatanode(tai_llvmmetadatareftypedconst(hp).val).name);
|
|
|
|
+ end;
|
|
|
|
+ ait_llvmmetadatarefoperand:
|
|
|
|
+ begin
|
|
|
|
+ { must only appear as an operand }
|
|
|
|
+ if fdecllevel=0 then
|
|
|
|
+ internalerror(2019050110);
|
|
|
|
+ writer.AsmWrite('!');
|
|
|
|
+ writer.AsmWrite(tai_llvmmetadatareferenceoperand(hp).id);
|
|
|
|
+ writer.AsmWrite(' !');
|
|
|
|
+ writer.AsmWrite(tai_llvmmetadatareferenceoperand(hp).value.name);
|
|
|
|
+ end;
|
|
ait_symbolpair:
|
|
ait_symbolpair:
|
|
begin
|
|
begin
|
|
{ should be emitted as part of the symbol def }
|
|
{ should be emitted as part of the symbol def }
|
|
@@ -1411,7 +1491,7 @@ implementation
|
|
end;
|
|
end;
|
|
ait_typedconst:
|
|
ait_typedconst:
|
|
begin
|
|
begin
|
|
- WriteTypedConstData(tai_abstracttypedconst(hp));
|
|
|
|
|
|
+ WriteTypedConstData(tai_abstracttypedconst(hp),false);
|
|
end
|
|
end
|
|
else
|
|
else
|
|
internalerror(2019012010);
|
|
internalerror(2019012010);
|
|
@@ -1435,7 +1515,6 @@ implementation
|
|
procedure TLLVMAssember.WriteAsmList;
|
|
procedure TLLVMAssember.WriteAsmList;
|
|
var
|
|
var
|
|
hal : tasmlisttype;
|
|
hal : tasmlisttype;
|
|
- i: longint;
|
|
|
|
a: TExternalAssembler;
|
|
a: TExternalAssembler;
|
|
decorator: TLLVMModuleInlineAssemblyDecorator;
|
|
decorator: TLLVMModuleInlineAssemblyDecorator;
|
|
begin
|
|
begin
|