浏览代码

* 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 -

Jonas Maebe 11 年之前
父节点
当前提交
c84a8a4bc2
共有 2 个文件被更改,包括 19 次插入8 次删除
  1. 18 7
      compiler/aasmcnst.pas
  2. 1 1
      compiler/llvm/nllvmtcon.pas

+ 18 - 7
compiler/aasmcnst.pas

@@ -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:

+ 1 - 1
compiler/llvm/nllvmtcon.pas

@@ -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;