From f8b1801a8fb7a247ea31be7260c44e333d069a8e Mon Sep 17 00:00:00 2001 From: Sven/Sarah Barth Date: Sun, 6 Feb 2022 13:10:47 +0100 Subject: [PATCH] + implement necessary functionality in tcgprocinfo to initialize and populate the capturer Based on code by Blaise.ru --- compiler/psub.pas | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/compiler/psub.pas b/compiler/psub.pas index 957a0a3008..aa59f28b77 100644 --- a/compiler/psub.pas +++ b/compiler/psub.pas @@ -52,6 +52,7 @@ interface procedure add_entry_exit_code; procedure setup_tempgen; procedure OptimizeNodeTree; + procedure convert_captured_syms; protected procedure generate_code_exceptfilters; public @@ -132,7 +133,7 @@ implementation globtype,tokens,verbose,comphook,constexp, systems,cpubase,aasmbase,aasmtai, { symtable } - symconst,symbase,symsym,symtype,symtable,defutil,defcmp,symcreat, + symconst,symbase,symsym,symtype,symtable,defutil,defcmp,procdefutil,symcreat, paramgr, fmodule, { pass 1 } @@ -621,6 +622,8 @@ implementation end; if m_non_local_goto in current_settings.modeswitches then tsymtable(current_procinfo.procdef.localst).SymList.ForEachCall(@add_label_init,@newstatement); + + initialize_capturer(current_procinfo,newstatement); end; @@ -1733,6 +1736,30 @@ implementation end; + procedure tcgprocinfo.convert_captured_syms; + var + hpi : tcgprocinfo; + old_current_procinfo : tprocinfo; + begin + { do the conversion only if there haven't been any errors so far } + if ErrorCount<>0 then + exit; + old_current_procinfo:=current_procinfo; + current_procinfo:=self; + { process nested procedures } + hpi:=tcgprocinfo(get_first_nestedproc); + while assigned(hpi) do + begin + hpi.convert_captured_syms; + hpi:=tcgprocinfo(hpi.next); + end; + { convert the captured symbols for this routine } + if assigned(code) then + procdefutil.convert_captured_syms(procdef,code); + current_procinfo:=old_current_procinfo; + end; + + procedure TCGProcinfo.CreateInlineInfo; begin new(procdef.inlininginfo); @@ -2480,6 +2507,8 @@ implementation { parse the code ... } code:=block(current_module.islibrary); + postprocess_capturer(self); + if recordtokens then begin { stop token recorder for generic template } @@ -2661,6 +2690,9 @@ implementation { also generate the bodies for all previously done specializations so that we might inline them } generate_specialization_procs; + { convert all load nodes that might have been captured by a + capture object } + tcgprocinfo(current_procinfo).convert_captured_syms; tcgprocinfo(current_procinfo).generate_code_tree; end; end;