* separate methods to get the size of the ansistring/unicode header and to

get the offset relative from the returned label from
    emit_(ansi|unicode)_string() to the start of the string data
   o corrected return value for the offset on LLVM: it's always equal to the
     header size, since we can't emit labels in the middle of structured data
     there

git-svn-id: branches/hlcgllvm@28324 -
This commit is contained in:
Jonas Maebe 2014-08-06 18:04:31 +00:00
parent 7a10959aa0
commit c84a8a4bc2
2 changed files with 19 additions and 8 deletions

View File

@ -177,8 +177,12 @@ type
{ returns the offset of the string data relative to ansi/unicode/widestring
constant labels. On most platforms, this is 0 (with the header at a
negative offset), but on some platforms such negative offsets are not
supported this is 0 }
supported this is equal to the header size }
class function get_string_symofs(typ: tstringtype; winlikewidestring: boolean): pint; virtual;
protected
{ this one always return the actual offset, called by the above (and
overridden versions) }
class function get_string_header_size(typ: tstringtype; winlikewidestring: boolean): pint;
end;
ttai_lowleveltypedconstbuilderclass = class of ttai_lowleveltypedconstbuilder;
@ -433,26 +437,33 @@ implementation
class function ttai_lowleveltypedconstbuilder.get_string_symofs(typ: tstringtype; winlikewidestring: boolean): pint;
begin
{ darwin's linker does not support negative offsets }
if not(target_info.system in systems_darwin) then
result:=0
else
result:=get_string_header_size(typ,winlikewidestring);
end;
class function ttai_lowleveltypedconstbuilder.get_string_header_size(typ: tstringtype; winlikewidestring: boolean): pint;
const
ansistring_header_size =
{ encoding }
2 +
{ elesize }
2 +
{$ifdef cpu64bitaddr}
{$ifdef cpu64bitaddr}
{ alignment }
4 +
{$endif cpu64bitaddr}
{$endif cpu64bitaddr}
{ reference count }
sizeof(pint) +
{ length }
sizeof(pint);
unicodestring_header_size = ansistring_header_size;
begin
{ darwin's linker does not support negative offsets }
if not(target_info.system in systems_darwin) then
result:=0
else case typ of
case typ of
st_ansistring:
result:=ansistring_header_size;
st_unicodestring:

View File

@ -431,7 +431,7 @@ implementation
class function tllvmtai_typedconstbuilder.get_string_symofs(typ: tstringtype; winlikewidestring: boolean): pint;
begin
{ LLVM does not support labels in the middle of a declaration }
result:=0;
result:=get_string_header_size(typ,winlikewidestring);
end;