2
0
Эх сурвалжийг харах

Add section directive for subroutines for embedded and freertos systems.

ccrause 3 жил өмнө
parent
commit
738a0a35de

+ 21 - 0
compiler/aasmtai.pas

@@ -680,6 +680,7 @@ interface
           { this constructor is made private on purpose }
           { because sections should be created via new_section() }
           constructor Create(Asectype:TAsmSectiontype;const Aname:string;Aalign:longint;Asecorder:TasmSectionorder=secorder_default);
+          constructor Create_proc(Asectype:TAsmSectiontype;const Aname:string;Aalign:longint;Asecorder:TasmSectionorder=secorder_default);
 {$pop}
        end;
 
@@ -1060,6 +1061,7 @@ interface
 
     procedure maybe_new_object_file(list:TAsmList);
     function new_section(list:TAsmList;Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default) : tai_section;
+    function new_proc_section(list:TAsmList;Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default) : tai_section;
 
     function ppuloadai(ppufile:tcompilerppufile):tai;
     procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
@@ -1099,6 +1101,16 @@ implementation
       end;
 
 
+    function new_proc_section(list:TAsmList;Asectype:TAsmSectiontype;
+      const Aname:string;Aalign:byte;Asecorder:TasmSectionorder):tai_section;
+      begin
+        Result:=tai_section.Create_proc(Asectype,Aname,Aalign,Asecorder);
+        list.concat(Result);
+        inc(list.section_count);
+        list.concat(cai_align.create(Aalign));
+      end;
+
+
     function ppuloadai(ppufile:tcompilerppufile):tai;
       var
         b : byte;
@@ -1318,6 +1330,15 @@ implementation
         sec:=nil;
       end;
 
+    constructor tai_section.Create_proc(Asectype:TAsmSectiontype;
+      const Aname:string;Aalign:longint;Asecorder:TasmSectionorder);
+      begin
+        Create(Asectype,Aname,Aalign,Asecorder);
+        secprogbits:=SPB_PROGBITS;
+        exclude(secflags,SF_W);
+        include(secflags,SF_X);
+      end;
+
 
     constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
       begin

+ 4 - 1
compiler/hlcgobj.pas

@@ -5497,7 +5497,10 @@ implementation
         alt:=al_pure_assembler;
       { add the procedure to the al_procedures }
       maybe_new_object_file(current_asmdata.asmlists[alt]);
-      new_section(current_asmdata.asmlists[alt],sec_code,lower(pd.mangledname),getprocalign);
+      if pd.section<>'' then
+        new_proc_section(current_asmdata.asmlists[alt],sec_user,lower(pd.section),getprocalign)
+      else
+        new_section(current_asmdata.asmlists[alt],sec_code,lower(pd.mangledname),getprocalign);
       current_asmdata.asmlists[alt].concatlist(code);
       { save local data (casetable) also in the same file }
       if assigned(data) and

+ 19 - 1
compiler/pdecsub.pas

@@ -2416,6 +2416,15 @@ begin
     message(parser_e_cannot_use_hardfloat_in_a_softfloat_environment);
 end;
 
+procedure pd_section(pd:tabstractprocdef);
+begin
+  if pd.typ<>procdef then
+    internalerror(2021032801);
+  if not (target_info.system in systems_allow_section) then
+    Comment(V_Error,'Directive section not allowed for this target.');
+  tprocdef(pd).section:=get_stringconst;
+end;
+
 type
    pd_handler=procedure(pd:tabstractprocdef);
    proc_dir_rec=record
@@ -2430,7 +2439,7 @@ type
    end;
 const
   {Should contain the number of procedure directives we support.}
-  num_proc_directives=53;
+  num_proc_directives=54;
   proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
    (
     (
@@ -2754,6 +2763,15 @@ const
       mutexclpocall : [];
       mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
       mutexclpo     : [po_external]
+    ),(
+      idtok:_SECTION;
+      pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
+      handler  : @pd_section;
+      pocall   : pocall_none;
+      pooption : [po_public,po_global];
+      mutexclpocall : [pocall_internproc];
+      mutexclpotype : [];
+      mutexclpo     : [po_external,po_inline,po_interrupt]
     ),(
       idtok:_SOFTFLOAT;
       pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];

+ 1 - 0
compiler/symdef.pas

@@ -695,6 +695,7 @@ interface
           { number of user visible parameters }
           maxparacount,
           minparacount    : byte;
+          section : ansistring;
           constructor create(dt:tdeftyp;level:byte;doregister:boolean);
           constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
           destructor destroy;override;

+ 1 - 1
compiler/systems.pas

@@ -318,7 +318,7 @@ interface
        systems_freertos = [system_xtensa_freertos,system_arm_freertos];
 
        { all systems that allow section directive }
-       systems_allow_section = systems_embedded;
+       systems_allow_section = systems_embedded+systems_freertos;
 
        { systems that uses dotted function names as descriptors }
        systems_dotted_function_names = [system_powerpc64_linux]+systems_aix;