Browse Source

* factored out emitting a shortstring constant via the typed constant builder

git-svn-id: branches/hlcgllvm@28771 -
Jonas Maebe 10 năm trước cách đây
mục cha
commit
984491e435
2 tập tin đã thay đổi với 20 bổ sung10 xóa
  1. 17 0
      compiler/aasmcnst.pas
  2. 3 10
      compiler/ncgvmt.pas

+ 17 - 0
compiler/aasmcnst.pas

@@ -226,6 +226,8 @@ type
        will be created/destroyed internally by these methods) }
      class function emit_ansistring_const(list: TAsmList; data: pchar; len: asizeint; encoding: tstringencoding; newsection: boolean): tasmlabofs;
      class function emit_unicodestring_const(list: TAsmList; data: pointer; encoding: tstringencoding; winlike: boolean):tasmlabofs;
+     { emit a shortstring constant, and return its def }
+     function emit_shortstring_const(const str: shortstring): tdef;
 
      { begin a potential aggregate type. Must be called for any type
        that consists of multiple tai constant data entries, or that
@@ -1010,6 +1012,21 @@ implementation
      end;
 
 
+   function ttai_typedconstbuilder.emit_shortstring_const(const str: shortstring): tdef;
+     begin
+       { we use an arraydef instead of a shortstringdef, because we don't have
+         functionality in place yet to reuse shortstringdefs of the same length
+         and neither the lowlevel nor the llvm typedconst builder cares about
+         this difference }
+       result:=getarraydef(cansichartype,length(str)+1);
+       maybe_begin_aggregate(result);
+       emit_tai(Tai_const.Create_8bit(length(str)),u8inttype);
+       if str<>'' then
+         emit_tai(Tai_string.Create(str),getarraydef(cansichartype,length(str)));
+       maybe_end_aggregate(result);
+     end;
+
+
    procedure ttai_typedconstbuilder.maybe_begin_aggregate(def: tdef);
      begin
        begin_aggregate_internal(def,false);

+ 3 - 10
compiler/ncgvmt.pas

@@ -515,11 +515,8 @@ implementation
                 current_asmdata.getlabel(l,alt_data);
                 { l: name_of_method }
                 tcb:=ctai_typedconstbuilder.create;
-                namedef:=getarraydef(cansichartype,length(tsym(p).realname)+1);
-                tcb.maybe_begin_aggregate(namedef);
-                tcb.emit_tai(Tai_const.Create_8bit(length(tsym(p).realname)),u8inttype);
-                tcb.emit_tai(Tai_string.Create(tsym(p).realname),getarraydef(cansichartype,length(tsym(p).realname)));
-                tcb.maybe_end_aggregate(namedef);
+
+                namedef:=tcb.emit_shortstring_const(tsym(p).realname);
                 lists^.list.concatList(tcb.get_final_asmlist(l,namedef,sec_rodata_norel,'',sizeof(pint),[tcalo_is_lab]));
                 tcb.free;
                 { the tmethodnamerec }
@@ -992,11 +989,7 @@ implementation
             current_asmdata.getlabel(classnamelabel,alt_data);
             tcb:=ctai_typedconstbuilder.create;
             hs:=_class.RttiName;
-            classnamedef:=cstringdef.createshort(length(hs));
-            tcb.maybe_begin_aggregate(classnamedef);
-            tcb.emit_tai(Tai_const.Create_8bit(length(hs)),u8inttype);
-            tcb.emit_tai(Tai_string.Create(hs),getarraydef(cansichartype,length(hs)));
-            tcb.maybe_end_aggregate(classnamedef);
+            classnamedef:=tcb.emit_shortstring_const(_class.RttiName);
             templist.concatlist(tcb.get_final_asmlist(classnamelabel,classnamedef,sec_rodata_norel,'',sizeof(pint),[tcalo_is_lab]));
             tcb.free;