浏览代码

+ get_threadvar_record() to get a recorddef representing a threadvar (index
and data in case of single threaded)

git-svn-id: trunk@31643 -

Jonas Maebe 10 年之前
父节点
当前提交
83ae160057
共有 2 个文件被更改,包括 32 次插入2 次删除
  1. 4 2
      compiler/symconst.pas
  2. 28 0
      compiler/symdef.pas

+ 4 - 2
compiler/symconst.pas

@@ -658,7 +658,8 @@ type
     itp_rtti_ord_64bit,
     itp_rtti_normal_array,
     itp_rtti_dyn_array,
-    itp_rtti_proc_param
+    itp_rtti_proc_param,
+    itp_threadvar_record
   );
 
   { The order is from low priority to high priority,
@@ -779,7 +780,8 @@ inherited_objectoptions : tobjectoptions = [oo_has_virtual,oo_has_private,oo_has
        '$rtti_ord_64bit$',
        '$rtti_normal_array$',
        '$rtti_dyn_array$',
-       '$rtti_proc_param$'
+       '$rtti_proc_param$',
+       '$threadvar_record$'
      );
 
 

+ 28 - 0
compiler/symdef.pas

@@ -1137,6 +1137,8 @@ interface
     function getansistringdef:tstringdef;
     function getparaencoding(def:tdef):tstringencoding; inline;
 
+    function get_threadvar_record(def: tdef; out index_field, non_mt_data_field: tsym): trecorddef;
+
 implementation
 
     uses
@@ -1211,6 +1213,32 @@ implementation
           result:=0
       end;
 
+
+    function get_threadvar_record(def: tdef; out index_field, non_mt_data_field: tsym): trecorddef;
+      var
+        typ: ttypesym;
+        name: string;
+      begin
+        name:=internaltypeprefixName[itp_threadvar_record]+tostr(def.defid);
+        typ:=try_search_current_module_type(name);
+        if assigned(typ) then
+          begin
+            result:=trecorddef(ttypesym(typ).typedef);
+            index_field:=tsym(result.symtable.symlist[0]);
+            non_mt_data_field:=tsym(result.symtable.symlist[1]);
+            exit;
+          end;
+        { set recordalinmin to sizeof(pint), so the second field gets put at
+          offset = sizeof(pint) as expected }
+        result:=crecorddef.create_global_internal(
+          name,sizeof(pint),sizeof(pint),
+          init_settings.alignment.maxCrecordalign);
+        index_field:=result.add_field_by_def('',u32inttype);
+        non_mt_data_field:=result.add_field_by_def('',def);
+        { no need to add alignment padding, we won't create arrays of these }
+      end;
+
+
     function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
       var
         s,hs,