mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-21 11:29:24 +02:00
* cleaner temp get/unget for exceptions
This commit is contained in:
parent
8d078ada18
commit
207e3b1231
@ -98,9 +98,6 @@ implementation
|
||||
{$endif cpu64bit}
|
||||
;
|
||||
|
||||
const
|
||||
EXCEPT_BUF_SIZE = 12;
|
||||
|
||||
{*****************************************************************************
|
||||
Second_While_RepeatN
|
||||
*****************************************************************************}
|
||||
@ -863,25 +860,6 @@ implementation
|
||||
endexceptlabel : tasmlabel;
|
||||
|
||||
|
||||
procedure try_new_exception(list : taasmoutput;var jmpbuf,envbuf, href : treference;
|
||||
a : aword; exceptlabel : tasmlabel);
|
||||
begin
|
||||
tg.GetTemp(list,EXCEPT_BUF_SIZE,tt_persistent,envbuf);
|
||||
tg.GetTemp(list,JMP_BUF_SIZE,tt_persistent,jmpbuf);
|
||||
tg.GetTemp(list,sizeof(aword),tt_persistent,href);
|
||||
new_exception(list, jmpbuf,envbuf, href, a, exceptlabel);
|
||||
end;
|
||||
|
||||
|
||||
procedure try_free_exception(list : taasmoutput;var jmpbuf, envbuf : treference;const href : treference;
|
||||
a : aword ; endexceptlabel : tasmlabel; onlyfree : boolean);
|
||||
begin
|
||||
free_exception(list, jmpbuf, envbuf, href, a, endexceptlabel, onlyfree);
|
||||
tg.Ungettemp(list,jmpbuf);
|
||||
tg.ungettemp(list,envbuf);
|
||||
end;
|
||||
|
||||
|
||||
{ does the necessary things to clean up the object stack }
|
||||
{ in the except block }
|
||||
procedure cleanupobjectstack;
|
||||
@ -919,8 +897,8 @@ implementation
|
||||
oldaktbreaklabel : tasmlabel;
|
||||
oldflowcontrol,tryflowcontrol,
|
||||
exceptflowcontrol : tflowcontrol;
|
||||
tempbuf,tempaddr : treference;
|
||||
href : treference;
|
||||
destroytemps,
|
||||
excepttemps : texceptiontemps;
|
||||
paraloc1 : tparalocation;
|
||||
label
|
||||
errorexit;
|
||||
@ -956,7 +934,8 @@ implementation
|
||||
objectlibrary.getlabel(endexceptlabel);
|
||||
objectlibrary.getlabel(lastonlabel);
|
||||
|
||||
try_new_exception(exprasmlist,tempbuf,tempaddr,href,1,exceptlabel);
|
||||
get_exception_temps(exprasmlist,excepttemps);
|
||||
new_exception(exprasmlist,excepttemps,1,exceptlabel);
|
||||
|
||||
{ try block }
|
||||
{ set control flow labels for the try block }
|
||||
@ -975,7 +954,7 @@ implementation
|
||||
|
||||
cg.a_label(exprasmlist,exceptlabel);
|
||||
|
||||
try_free_exception(exprasmlist,tempbuf,tempaddr,href,0,endexceptlabel,false);
|
||||
free_exception(exprasmlist, excepttemps, 0, endexceptlabel, false);
|
||||
|
||||
cg.a_label(exprasmlist,doexceptlabel);
|
||||
|
||||
@ -1013,7 +992,8 @@ implementation
|
||||
objectlibrary.getlabel(doobjectdestroy);
|
||||
objectlibrary.getlabel(doobjectdestroyandreraise);
|
||||
|
||||
try_new_exception(exprasmlist,tempbuf,tempaddr,href,1,doobjectdestroyandreraise);
|
||||
get_exception_temps(exprasmlist,destroytemps);
|
||||
new_exception(exprasmlist,destroytemps,1,doobjectdestroyandreraise);
|
||||
|
||||
{ here we don't have to reset flowcontrol }
|
||||
{ the default and on flowcontrols are handled equal }
|
||||
@ -1022,7 +1002,7 @@ implementation
|
||||
|
||||
cg.a_label(exprasmlist,doobjectdestroyandreraise);
|
||||
|
||||
try_free_exception(exprasmlist,tempbuf,tempaddr,href,0,doobjectdestroy,false);
|
||||
free_exception(exprasmlist,destroytemps,0,doobjectdestroy,false);
|
||||
|
||||
cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.a_call_name(exprasmlist,'FPC_POPSECONDOBJECTSTACK');
|
||||
@ -1041,6 +1021,7 @@ implementation
|
||||
|
||||
cg.a_label(exprasmlist,doobjectdestroy);
|
||||
cleanupobjectstack;
|
||||
unget_exception_temps(exprasmlist,destroytemps);
|
||||
cg.a_jmp_always(exprasmlist,endexceptlabel);
|
||||
end
|
||||
else
|
||||
@ -1058,7 +1039,7 @@ implementation
|
||||
cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.a_call_name(exprasmlist,'FPC_POPADDRSTACK');
|
||||
cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.g_exception_reason_load(exprasmlist,href);
|
||||
cg.g_exception_reason_load(exprasmlist,excepttemps.reasonbuf);
|
||||
cleanupobjectstack;
|
||||
cg.a_jmp_always(exprasmlist,oldaktexitlabel);
|
||||
end;
|
||||
@ -1071,7 +1052,7 @@ implementation
|
||||
cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.a_call_name(exprasmlist,'FPC_POPADDRSTACK');
|
||||
cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.g_exception_reason_load(exprasmlist,href);
|
||||
cg.g_exception_reason_load(exprasmlist,excepttemps.reasonbuf);
|
||||
cleanupobjectstack;
|
||||
cg.a_jmp_always(exprasmlist,oldaktbreaklabel);
|
||||
end;
|
||||
@ -1084,7 +1065,7 @@ implementation
|
||||
cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.a_call_name(exprasmlist,'FPC_POPADDRSTACK');
|
||||
cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.g_exception_reason_load(exprasmlist,href);
|
||||
cg.g_exception_reason_load(exprasmlist,excepttemps.reasonbuf);
|
||||
cleanupobjectstack;
|
||||
cg.a_jmp_always(exprasmlist,oldaktcontinuelabel);
|
||||
end;
|
||||
@ -1096,7 +1077,7 @@ implementation
|
||||
cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.a_call_name(exprasmlist,'FPC_POPADDRSTACK');
|
||||
cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.g_exception_reason_load(exprasmlist,href);
|
||||
cg.g_exception_reason_load(exprasmlist,excepttemps.reasonbuf);
|
||||
cg.a_jmp_always(exprasmlist,oldaktexitlabel);
|
||||
end;
|
||||
|
||||
@ -1106,7 +1087,7 @@ implementation
|
||||
cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.a_call_name(exprasmlist,'FPC_POPADDRSTACK');
|
||||
cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.g_exception_reason_load(exprasmlist,href);
|
||||
cg.g_exception_reason_load(exprasmlist,excepttemps.reasonbuf);
|
||||
cg.a_jmp_always(exprasmlist,oldaktbreaklabel);
|
||||
end;
|
||||
|
||||
@ -1116,10 +1097,10 @@ implementation
|
||||
cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.a_call_name(exprasmlist,'FPC_POPADDRSTACK');
|
||||
cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.g_exception_reason_load(exprasmlist,href);
|
||||
cg.g_exception_reason_load(exprasmlist,excepttemps.reasonbuf);
|
||||
cg.a_jmp_always(exprasmlist,oldaktcontinuelabel);
|
||||
end;
|
||||
tg.ungettemp(exprasmlist,href);
|
||||
unget_exception_temps(exprasmlist,excepttemps);
|
||||
cg.a_label(exprasmlist,endexceptlabel);
|
||||
|
||||
errorexit:
|
||||
@ -1152,9 +1133,8 @@ implementation
|
||||
doobjectdestroy,
|
||||
oldaktbreaklabel : tasmlabel;
|
||||
oldflowcontrol : tflowcontrol;
|
||||
excepttemps : texceptiontemps;
|
||||
exceptref,
|
||||
tempbuf,tempaddr : treference;
|
||||
href : treference;
|
||||
href2: treference;
|
||||
paraloc1 : tparalocation;
|
||||
begin
|
||||
@ -1183,9 +1163,9 @@ implementation
|
||||
tvarsym(exceptsymtable.symindex.first).localloc.loc:=LOC_REFERENCE;
|
||||
tg.GetLocal(exprasmlist,POINTER_SIZE,voidpointertype.def,
|
||||
tvarsym(exceptsymtable.symindex.first).localloc.reference);
|
||||
reference_reset_base(href,tvarsym(exceptsymtable.symindex.first).localloc.reference.index,
|
||||
reference_reset_base(href2,tvarsym(exceptsymtable.symindex.first).localloc.reference.index,
|
||||
tvarsym(exceptsymtable.symindex.first).localloc.reference.offset);
|
||||
cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,href);
|
||||
cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,href2);
|
||||
end
|
||||
else
|
||||
begin
|
||||
@ -1199,7 +1179,8 @@ implementation
|
||||
objectlibrary.getlabel(doobjectdestroyandreraise);
|
||||
|
||||
{ call setjmp, and jump to finally label on non-zero result }
|
||||
try_new_exception(exprasmlist,tempbuf,tempaddr,href,1,doobjectdestroyandreraise);
|
||||
get_exception_temps(exprasmlist,excepttemps);
|
||||
new_exception(exprasmlist,excepttemps,1,doobjectdestroyandreraise);
|
||||
|
||||
if assigned(right) then
|
||||
begin
|
||||
@ -1221,7 +1202,7 @@ implementation
|
||||
objectlibrary.getlabel(doobjectdestroy);
|
||||
cg.a_label(exprasmlist,doobjectdestroyandreraise);
|
||||
|
||||
try_free_exception(exprasmlist,tempbuf,tempaddr,href,0,doobjectdestroy,false);
|
||||
free_exception(exprasmlist,excepttemps,0,doobjectdestroy,false);
|
||||
|
||||
cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.a_call_name(exprasmlist,'FPC_POPSECONDOBJECTSTACK');
|
||||
@ -1281,6 +1262,7 @@ implementation
|
||||
end;
|
||||
end;
|
||||
|
||||
unget_exception_temps(exprasmlist,excepttemps);
|
||||
cg.a_label(exprasmlist,nextonlabel);
|
||||
flowcontrol:=oldflowcontrol+flowcontrol;
|
||||
{ next on node }
|
||||
@ -1305,9 +1287,7 @@ implementation
|
||||
oldaktbreaklabel : tasmlabel;
|
||||
oldflowcontrol,tryflowcontrol : tflowcontrol;
|
||||
decconst : longint;
|
||||
tempbuf,tempaddr : treference;
|
||||
href : treference;
|
||||
|
||||
excepttemps : texceptiontemps;
|
||||
begin
|
||||
location_reset(location,LOC_VOID,OS_NO);
|
||||
|
||||
@ -1345,7 +1325,8 @@ implementation
|
||||
end;
|
||||
|
||||
{ call setjmp, and jump to finally label on non-zero result }
|
||||
try_new_exception(exprasmlist,tempbuf,tempaddr,href,1,finallylabel);
|
||||
get_exception_temps(exprasmlist,excepttemps);
|
||||
new_exception(exprasmlist,excepttemps,1,finallylabel);
|
||||
|
||||
{ try code }
|
||||
if assigned(left) then
|
||||
@ -1358,7 +1339,7 @@ implementation
|
||||
|
||||
cg.a_label(exprasmlist,finallylabel);
|
||||
{ just free the frame information }
|
||||
try_free_exception(exprasmlist,tempbuf,tempaddr,href,1,finallylabel,true);
|
||||
free_exception(exprasmlist,excepttemps,1,finallylabel,true);
|
||||
|
||||
{ finally code }
|
||||
flowcontrol:=[];
|
||||
@ -1369,7 +1350,7 @@ implementation
|
||||
exit;
|
||||
|
||||
{ the value should now be in the exception handler }
|
||||
cg.g_exception_reason_load(exprasmlist,href);
|
||||
cg.g_exception_reason_load(exprasmlist,excepttemps.reasonbuf);
|
||||
if implicitframe then
|
||||
begin
|
||||
cg.a_cmp_const_reg_label(exprasmlist,OS_INT,OC_EQ,0,NR_FUNCTION_RESULT_REG,endfinallylabel);
|
||||
@ -1414,27 +1395,27 @@ implementation
|
||||
if fc_exit in tryflowcontrol then
|
||||
begin
|
||||
cg.a_label(exprasmlist,exitfinallylabel);
|
||||
cg.g_exception_reason_load(exprasmlist,href);
|
||||
cg.g_exception_reason_save_const(exprasmlist,href,2);
|
||||
cg.g_exception_reason_load(exprasmlist,excepttemps.reasonbuf);
|
||||
cg.g_exception_reason_save_const(exprasmlist,excepttemps.reasonbuf,2);
|
||||
cg.a_jmp_always(exprasmlist,finallylabel);
|
||||
end;
|
||||
if fc_break in tryflowcontrol then
|
||||
begin
|
||||
cg.a_label(exprasmlist,breakfinallylabel);
|
||||
cg.g_exception_reason_load(exprasmlist,href);
|
||||
cg.g_exception_reason_save_const(exprasmlist,href,3);
|
||||
cg.g_exception_reason_load(exprasmlist,excepttemps.reasonbuf);
|
||||
cg.g_exception_reason_save_const(exprasmlist,excepttemps.reasonbuf,3);
|
||||
cg.a_jmp_always(exprasmlist,finallylabel);
|
||||
end;
|
||||
if fc_continue in tryflowcontrol then
|
||||
begin
|
||||
cg.a_label(exprasmlist,continuefinallylabel);
|
||||
cg.g_exception_reason_load(exprasmlist,href);
|
||||
cg.g_exception_reason_save_const(exprasmlist,href,4);
|
||||
cg.g_exception_reason_load(exprasmlist,excepttemps.reasonbuf);
|
||||
cg.g_exception_reason_save_const(exprasmlist,excepttemps.reasonbuf,4);
|
||||
cg.a_jmp_always(exprasmlist,finallylabel);
|
||||
end;
|
||||
end;
|
||||
unget_exception_temps(exprasmlist,excepttemps);
|
||||
cg.a_label(exprasmlist,endfinallylabel);
|
||||
tg.ungettemp(exprasmlist,href);
|
||||
|
||||
current_procinfo.aktexitlabel:=oldaktexitlabel;
|
||||
if assigned(aktbreaklabel) then
|
||||
@ -1462,7 +1443,10 @@ begin
|
||||
end.
|
||||
{
|
||||
$Log$
|
||||
Revision 1.94 2004-03-02 00:36:33 olle
|
||||
Revision 1.95 2004-03-29 14:43:47 peter
|
||||
* cleaner temp get/unget for exceptions
|
||||
|
||||
Revision 1.94 2004/03/02 00:36:33 olle
|
||||
* big transformation of Tai_[const_]Symbol.Create[data]name*
|
||||
|
||||
Revision 1.93 2004/02/27 10:21:05 florian
|
||||
|
@ -84,10 +84,20 @@ interface
|
||||
be modified, all temps should be allocated on the heap instead of the
|
||||
stack.
|
||||
}
|
||||
procedure new_exception(list:TAAsmoutput;const jmpbuf,envbuf, href : treference;
|
||||
a : aword; exceptlabel : tasmlabel);
|
||||
procedure free_exception(list:TAAsmoutput;const jmpbuf, envbuf, href : treference;
|
||||
a : aword ; endexceptlabel : tasmlabel; onlyfree : boolean);
|
||||
|
||||
const
|
||||
EXCEPT_BUF_SIZE = 12;
|
||||
type
|
||||
texceptiontemps=record
|
||||
jmpbuf,
|
||||
envbuf,
|
||||
reasonbuf : treference;
|
||||
end;
|
||||
|
||||
procedure get_exception_temps(list:taasmoutput;var t:texceptiontemps);
|
||||
procedure unget_exception_temps(list:taasmoutput;const t:texceptiontemps);
|
||||
procedure new_exception(list:TAAsmoutput;const t:texceptiontemps;a:aword;exceptlabel:tasmlabel);
|
||||
procedure free_exception(list:TAAsmoutput;const t:texceptiontemps;a:aword;endexceptlabel:tasmlabel;onlyfree:boolean);
|
||||
|
||||
procedure insertconstdata(sym : ttypedconstsym);
|
||||
procedure insertbssdata(sym : tvarsym);
|
||||
@ -268,9 +278,23 @@ implementation
|
||||
EXCEPTION MANAGEMENT
|
||||
*****************************************************************************}
|
||||
|
||||
procedure new_exception(list:TAAsmoutput;const jmpbuf,envbuf, href : treference;
|
||||
a : aword; exceptlabel : tasmlabel);
|
||||
procedure get_exception_temps(list:taasmoutput;var t:texceptiontemps);
|
||||
begin
|
||||
tg.GetTemp(list,EXCEPT_BUF_SIZE,tt_persistent,t.envbuf);
|
||||
tg.GetTemp(list,JMP_BUF_SIZE,tt_persistent,t.jmpbuf);
|
||||
tg.GetTemp(list,sizeof(aword),tt_persistent,t.reasonbuf);
|
||||
end;
|
||||
|
||||
|
||||
procedure unget_exception_temps(list:taasmoutput;const t:texceptiontemps);
|
||||
begin
|
||||
tg.Ungettemp(list,t.jmpbuf);
|
||||
tg.ungettemp(list,t.envbuf);
|
||||
tg.ungettemp(list,t.reasonbuf);
|
||||
end;
|
||||
|
||||
|
||||
procedure new_exception(list:TAAsmoutput;const t:texceptiontemps;a:aword;exceptlabel:tasmlabel);
|
||||
var
|
||||
paraloc1,paraloc2,paraloc3 : tparalocation;
|
||||
begin
|
||||
@ -278,9 +302,9 @@ implementation
|
||||
paraloc2:=paramanager.getintparaloc(pocall_default,2);
|
||||
paraloc3:=paramanager.getintparaloc(pocall_default,3);
|
||||
paramanager.allocparaloc(list,paraloc3);
|
||||
cg.a_paramaddr_ref(list,envbuf,paraloc3);
|
||||
cg.a_paramaddr_ref(list,t.envbuf,paraloc3);
|
||||
paramanager.allocparaloc(list,paraloc2);
|
||||
cg.a_paramaddr_ref(list,jmpbuf,paraloc2);
|
||||
cg.a_paramaddr_ref(list,t.jmpbuf,paraloc2);
|
||||
{ push type of exceptionframe }
|
||||
paramanager.allocparaloc(list,paraloc1);
|
||||
cg.a_param_const(list,OS_S32,1,paraloc1);
|
||||
@ -299,14 +323,12 @@ implementation
|
||||
cg.a_call_name(list,'FPC_SETJMP');
|
||||
cg.deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
|
||||
cg.g_exception_reason_save(list, href);
|
||||
cg.g_exception_reason_save(list, t.reasonbuf);
|
||||
cg.a_cmp_const_reg_label(list,OS_S32,OC_NE,0,cg.makeregsize(NR_FUNCTION_RESULT_REG,OS_S32),exceptlabel);
|
||||
end;
|
||||
|
||||
|
||||
procedure free_exception(list:TAAsmoutput;const jmpbuf, envbuf, href : treference;
|
||||
a : aword ; endexceptlabel : tasmlabel; onlyfree : boolean);
|
||||
|
||||
procedure free_exception(list:TAAsmoutput;const t:texceptiontemps;a:aword;endexceptlabel:tasmlabel;onlyfree:boolean);
|
||||
begin
|
||||
cg.allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
|
||||
cg.a_call_name(list,'FPC_POPADDRSTACK');
|
||||
@ -314,7 +336,7 @@ implementation
|
||||
|
||||
if not onlyfree then
|
||||
begin
|
||||
cg.g_exception_reason_load(list, href);
|
||||
cg.g_exception_reason_load(list, t.reasonbuf);
|
||||
cg.a_cmp_const_reg_label(list,OS_INT,OC_EQ,a,NR_FUNCTION_RESULT_REG,endexceptlabel);
|
||||
end;
|
||||
end;
|
||||
@ -2124,7 +2146,10 @@ implementation
|
||||
end.
|
||||
{
|
||||
$Log$
|
||||
Revision 1.196 2004-03-03 22:02:52 peter
|
||||
Revision 1.197 2004-03-29 14:43:47 peter
|
||||
* cleaner temp get/unget for exceptions
|
||||
|
||||
Revision 1.196 2004/03/03 22:02:52 peter
|
||||
* use loadnode and finalize_data_node for init/final code to support
|
||||
threadvars correctly
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user