+ added method reference_reset_base with support for different pointer types to

the high level code generator. All hlcg code, except for the jvm code
  generator, updated to use the new method. I didn't update jvm (it still uses
  the method from cgutils), because I'm not familiar with that platform, so I
  might get the types wrong.

git-svn-id: trunk@27309 -
This commit is contained in:
nickysn 2014-03-28 00:01:18 +00:00
parent 7f88dc9d95
commit 26b53607f8
4 changed files with 65 additions and 27 deletions

View File

@ -107,6 +107,21 @@ unit hlcgobj;
result loading, this is the register type used } result loading, this is the register type used }
function def2regtyp(def: tdef): tregistertype; virtual; function def2regtyp(def: tdef): tregistertype; virtual;
{# Returns a reference with its base address set from a pointer that
has been loaded in a register.
A generic version is provided. This routine should be overridden
on platforms which support pointers with different sizes (for
example i8086 near and far pointers) or require some other sort of
special consideration when converting a pointer in a register to a
reference.
@param(ref where the result is returned)
@param(regsize the type of the pointer, contained in the reg parameter)
@param(reg register containing the value of a pointer)
}
procedure reference_reset_base(var ref: treference; regsize: tdef; reg: tregister; offset, alignment: longint); virtual;
{# Emit a label to the instruction stream. } {# Emit a label to the instruction stream. }
procedure a_label(list : TAsmList;l : tasmlabel); inline; procedure a_label(list : TAsmList;l : tasmlabel); inline;
@ -727,6 +742,14 @@ implementation
end; end;
end; end;
procedure thlcgobj.reference_reset_base(var ref: treference; regsize: tdef;
reg: tregister; offset, alignment: longint);
begin
reference_reset(ref,alignment);
ref.base:=reg;
ref.offset:=offset;
end;
procedure thlcgobj.a_label(list: TAsmList; l: tasmlabel); inline; procedure thlcgobj.a_label(list: TAsmList; l: tasmlabel); inline;
begin begin
cg.a_label(list,l); cg.a_label(list,l);
@ -765,7 +788,7 @@ implementation
a_load_reg_reg(list,size,cgpara.location^.def,r,cgpara.location^.register); a_load_reg_reg(list,size,cgpara.location^.def,r,cgpara.location^.register);
LOC_REFERENCE,LOC_CREFERENCE: LOC_REFERENCE,LOC_CREFERENCE:
begin begin
reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment); reference_reset_base(ref,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
a_load_reg_ref(list,size,cgpara.location^.def,r,ref); a_load_reg_ref(list,size,cgpara.location^.def,r,ref);
end; end;
LOC_MMREGISTER,LOC_CMMREGISTER: LOC_MMREGISTER,LOC_CMMREGISTER:
@ -795,7 +818,7 @@ implementation
a_load_const_reg(list,cgpara.location^.def,a,cgpara.location^.register); a_load_const_reg(list,cgpara.location^.def,a,cgpara.location^.register);
LOC_REFERENCE,LOC_CREFERENCE: LOC_REFERENCE,LOC_CREFERENCE:
begin begin
reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment); reference_reset_base(ref,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
a_load_const_ref(list,cgpara.location^.def,a,ref); a_load_const_ref(list,cgpara.location^.def,a,ref);
end end
else else
@ -926,7 +949,7 @@ implementation
begin begin
if assigned(location^.next) then if assigned(location^.next) then
internalerror(2010052906); internalerror(2010052906);
reference_reset_base(ref,location^.reference.index,location^.reference.offset,newalignment(cgpara.alignment,cgpara.intsize-sizeleft)); reference_reset_base(ref,voidstackpointertype,location^.reference.index,location^.reference.offset,newalignment(cgpara.alignment,cgpara.intsize-sizeleft));
if (def_cgsize(size)<>OS_NO) and if (def_cgsize(size)<>OS_NO) and
(size.size=sizeleft) and (size.size=sizeleft) and
(sizeleft<=sizeof(aint)) then (sizeleft<=sizeof(aint)) then
@ -2365,7 +2388,7 @@ implementation
LOC_REFERENCE,LOC_CREFERENCE: LOC_REFERENCE,LOC_CREFERENCE:
begin begin
cgpara.check_simple_location; cgpara.check_simple_location;
reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment); reference_reset_base(ref,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
a_loadfpu_reg_ref(list,fromsize,cgpara.def,r,ref); a_loadfpu_reg_ref(list,fromsize,cgpara.def,r,ref);
end; end;
LOC_REGISTER,LOC_CREGISTER: LOC_REGISTER,LOC_CREGISTER:
@ -2396,7 +2419,7 @@ implementation
LOC_REFERENCE,LOC_CREFERENCE: LOC_REFERENCE,LOC_CREFERENCE:
begin begin
cgpara.check_simple_location; cgpara.check_simple_location;
reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment); reference_reset_base(href,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
{ concatcopy should choose the best way to copy the data } { concatcopy should choose the best way to copy the data }
g_concatcopy(list,fromsize,ref,href); g_concatcopy(list,fromsize,ref,href);
end; end;
@ -2476,7 +2499,7 @@ implementation
a_loadmm_reg_reg(list,fromsize,cgpara.def,reg,cgpara.location^.register,shuffle); a_loadmm_reg_reg(list,fromsize,cgpara.def,reg,cgpara.location^.register,shuffle);
LOC_REFERENCE,LOC_CREFERENCE: LOC_REFERENCE,LOC_CREFERENCE:
begin begin
reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment); reference_reset_base(href,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
a_loadmm_reg_ref(list,fromsize,cgpara.def,reg,href,shuffle); a_loadmm_reg_ref(list,fromsize,cgpara.def,reg,href,shuffle);
end; end;
LOC_REGISTER,LOC_CREGISTER: LOC_REGISTER,LOC_CREGISTER:
@ -3805,14 +3828,14 @@ implementation
begin begin
if not loadref then if not loadref then
internalerror(200410231); internalerror(200410231);
reference_reset_base(ref,l.register,0,alignment); reference_reset_base(ref,voidpointertype,l.register,0,alignment);
end; end;
LOC_REFERENCE, LOC_REFERENCE,
LOC_CREFERENCE : LOC_CREFERENCE :
begin begin
if loadref then if loadref then
begin begin
reference_reset_base(ref,getaddressregister(list,voidpointertype),0,alignment); reference_reset_base(ref,voidpointertype,getaddressregister(list,voidpointertype),0,alignment);
{ it's a pointer to def } { it's a pointer to def }
a_load_ref_reg(list,voidpointertype,voidpointertype,l.reference,ref.base); a_load_ref_reg(list,voidpointertype,voidpointertype,l.reference,ref.base);
end end
@ -4305,7 +4328,7 @@ implementation
if assigned(hp^.def) and if assigned(hp^.def) and
is_managed_type(hp^.def) then is_managed_type(hp^.def) then
begin begin
reference_reset_base(href,current_procinfo.framepointer,hp^.pos,sizeof(pint)); reference_reset_base(href,voidstackpointertype,current_procinfo.framepointer,hp^.pos,voidstackpointertype.size);
g_initialize(list,hp^.def,href); g_initialize(list,hp^.def,href);
end; end;
hp:=hp^.next; hp:=hp^.next;
@ -4353,7 +4376,7 @@ implementation
is_managed_type(hp^.def) then is_managed_type(hp^.def) then
begin begin
include(current_procinfo.flags,pi_needs_implicit_finally); include(current_procinfo.flags,pi_needs_implicit_finally);
reference_reset_base(href,current_procinfo.framepointer,hp^.pos,sizeof(pint)); reference_reset_base(href,voidstackpointertype,current_procinfo.framepointer,hp^.pos,voidstackpointertype.size);
g_finalize(list,hp^.def,href); g_finalize(list,hp^.def,href);
end; end;
hp:=hp^.next; hp:=hp^.next;
@ -4853,7 +4876,7 @@ implementation
case para.location^.loc of case para.location^.loc of
LOC_REFERENCE,LOC_CREFERENCE: LOC_REFERENCE,LOC_CREFERENCE:
begin begin
reference_reset_base(href,para.location^.reference.index,para.location^.reference.offset,para.alignment); reference_reset_base(href,voidstackpointertype,para.location^.reference.index,para.location^.reference.offset,para.alignment);
a_load_ref_ref(list,para.def,para.def,href,destloc.reference); a_load_ref_ref(list,para.def,para.def,href,destloc.reference);
end; end;
else else

View File

@ -78,10 +78,10 @@ implementation
(cgpara.location^.reference.index=NR_STACK_POINTER_REG) then (cgpara.location^.reference.index=NR_STACK_POINTER_REG) then
begin begin
cg.g_stackpointer_alloc(list,stacksize); cg.g_stackpointer_alloc(list,stacksize);
reference_reset_base(href,NR_STACK_POINTER_REG,0,sizeof(pint)); reference_reset_base(href,voidstackpointertype,NR_STACK_POINTER_REG,0,voidstackpointertype.size);
end end
else else
reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment); reference_reset_base(href,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
cg.a_loadfpu_reg_ref(list,locsize,locsize,l.register,href); cg.a_loadfpu_reg_ref(list,locsize,locsize,l.register,href);
end; end;
LOC_FPUREGISTER: LOC_FPUREGISTER:
@ -123,10 +123,10 @@ implementation
(cgpara.location^.reference.index=NR_STACK_POINTER_REG) then (cgpara.location^.reference.index=NR_STACK_POINTER_REG) then
begin begin
cg.g_stackpointer_alloc(list,stacksize); cg.g_stackpointer_alloc(list,stacksize);
reference_reset_base(href,NR_STACK_POINTER_REG,0,sizeof(pint)); reference_reset_base(href,voidstackpointertype,NR_STACK_POINTER_REG,0,voidstackpointertype.size);
end end
else else
reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment); reference_reset_base(href,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
cg.a_loadmm_reg_ref(list,locsize,locsize,l.register,href,mms_movescalar); cg.a_loadmm_reg_ref(list,locsize,locsize,l.register,href,mms_movescalar);
end; end;
LOC_FPUREGISTER: LOC_FPUREGISTER:
@ -152,7 +152,7 @@ implementation
cg.a_load_ref_cgpara(list,locsize,l.reference,cgpara) cg.a_load_ref_cgpara(list,locsize,l.reference,cgpara)
else else
begin begin
reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment); reference_reset_base(href,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
cg.g_concatcopy(list,l.reference,href,stacksize); cg.g_concatcopy(list,l.reference,href,stacksize);
end; end;
end; end;

View File

@ -37,12 +37,17 @@ interface
type type
{ thlcgcpu }
thlcgcpu = class(thlcgx86) thlcgcpu = class(thlcgx86)
protected protected
procedure gen_loadfpu_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation; const cgpara: tcgpara; locintsize: longint); override; procedure gen_loadfpu_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation; const cgpara: tcgpara; locintsize: longint); override;
public public
function getaddressregister(list:TAsmList;size:tdef):Tregister;override; function getaddressregister(list:TAsmList;size:tdef):Tregister;override;
procedure reference_reset_base(var ref: treference; regsize: tdef; reg: tregister; offset, alignment: longint); override;
procedure g_copyvaluepara_openarray(list: TAsmList; const ref: treference; const lenloc: tlocation; arrdef: tarraydef; destreg: tregister); override; procedure g_copyvaluepara_openarray(list: TAsmList; const ref: treference; const lenloc: tlocation; arrdef: tarraydef; destreg: tregister); override;
procedure g_releasevaluepara_openarray(list: TAsmList; arrdef: tarraydef; const l: tlocation); override; procedure g_releasevaluepara_openarray(list: TAsmList; arrdef: tarraydef; const l: tlocation); override;
@ -58,7 +63,8 @@ implementation
paramgr, paramgr,
cpubase,cpuinfo,tgobj,cgobj,cgcpu, cpubase,cpuinfo,tgobj,cgobj,cgcpu,
defutil, defutil,
symconst; symconst,
procinfo;
{ thlcgcpu } { thlcgcpu }
@ -85,10 +91,10 @@ implementation
(cgpara.location^.reference.index=NR_STACK_POINTER_REG) then (cgpara.location^.reference.index=NR_STACK_POINTER_REG) then
begin begin
cg.g_stackpointer_alloc(list,stacksize); cg.g_stackpointer_alloc(list,stacksize);
reference_reset_base(href,NR_STACK_POINTER_REG,0,sizeof(pint)); reference_reset_base(href,voidstackpointertype,NR_STACK_POINTER_REG,0,voidstackpointertype.size);
end end
else else
reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment); reference_reset_base(href,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
cg.a_loadfpu_reg_ref(list,locsize,locsize,l.register,href); cg.a_loadfpu_reg_ref(list,locsize,locsize,l.register,href);
end; end;
LOC_FPUREGISTER: LOC_FPUREGISTER:
@ -130,10 +136,10 @@ implementation
(cgpara.location^.reference.index=NR_STACK_POINTER_REG) then (cgpara.location^.reference.index=NR_STACK_POINTER_REG) then
begin begin
cg.g_stackpointer_alloc(list,stacksize); cg.g_stackpointer_alloc(list,stacksize);
reference_reset_base(href,NR_STACK_POINTER_REG,0,sizeof(pint)); reference_reset_base(href,voidstackpointertype,NR_STACK_POINTER_REG,0,voidstackpointertype.size);
end end
else else
reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment); reference_reset_base(href,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
cg.a_loadmm_reg_ref(list,locsize,locsize,l.register,href,mms_movescalar); cg.a_loadmm_reg_ref(list,locsize,locsize,l.register,href,mms_movescalar);
end; end;
LOC_FPUREGISTER: LOC_FPUREGISTER:
@ -159,7 +165,7 @@ implementation
cg.a_load_ref_cgpara(list,locsize,l.reference,cgpara) cg.a_load_ref_cgpara(list,locsize,l.reference,cgpara)
else else
begin begin
reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment); reference_reset_base(href,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
cg.g_concatcopy(list,l.reference,href,stacksize); cg.g_concatcopy(list,l.reference,href,stacksize);
end; end;
end; end;
@ -186,6 +192,15 @@ implementation
end; end;
procedure thlcgcpu.reference_reset_base(var ref: treference; regsize: tdef;
reg: tregister; offset, alignment: longint);
begin
inherited reference_reset_base(ref, regsize, reg, offset, alignment);
if is_farpointer(regsize) or is_hugepointer(regsize) then
ref.segment:=GetNextReg(reg);
end;
procedure thlcgcpu.g_copyvaluepara_openarray(list: TAsmList; const ref: treference; const lenloc: tlocation; arrdef: tarraydef; destreg: tregister); procedure thlcgcpu.g_copyvaluepara_openarray(list: TAsmList; const ref: treference; const lenloc: tlocation; arrdef: tarraydef; destreg: tregister);
begin begin
if paramanager.use_fixed_stack then if paramanager.use_fixed_stack then

View File

@ -1031,7 +1031,7 @@ implementation
end; end;
art_indexref: art_indexref:
begin begin
reference_reset_base(href,ref.indexbase,ref.indexoffset,4); cgutils.reference_reset_base(href,ref.indexbase,ref.indexoffset,4);
href.symbol:=ref.indexsymbol; href.symbol:=ref.indexsymbol;
a_load_ref_stack(list,s32inttype,href,prepare_stack_for_ref(list,href,false)); a_load_ref_stack(list,s32inttype,href,prepare_stack_for_ref(list,href,false));
end; end;
@ -1789,7 +1789,7 @@ implementation
{ passed by reference in array of single element; l contains the { passed by reference in array of single element; l contains the
base address of the array } base address of the array }
location_reset_ref(tmploc,LOC_REFERENCE,OS_ADDR,4); location_reset_ref(tmploc,LOC_REFERENCE,OS_ADDR,4);
reference_reset_base(tmploc.reference,getaddressregister(list,java_jlobject),0,4); cgutils.reference_reset_base(tmploc.reference,getaddressregister(list,java_jlobject),0,4);
tmploc.reference.arrayreftype:=art_indexconst; tmploc.reference.arrayreftype:=art_indexconst;
tmploc.reference.indexoffset:=0; tmploc.reference.indexoffset:=0;
a_load_loc_reg(list,java_jlobject,java_jlobject,l,tmploc.reference.base); a_load_loc_reg(list,java_jlobject,java_jlobject,l,tmploc.reference.base);
@ -1856,7 +1856,7 @@ implementation
case current_procinfo.procdef.proctypeoption of case current_procinfo.procdef.proctypeoption of
potype_unitinit: potype_unitinit:
begin begin
reference_reset_base(ref,NR_NO,0,1); cgutils.reference_reset_base(ref,NR_NO,0,1);
if assigned(current_module.globalsymtable) then if assigned(current_module.globalsymtable) then
allocate_implicit_structs_for_st_with_base_ref(list,current_module.globalsymtable,ref,staticvarsym); allocate_implicit_structs_for_st_with_base_ref(list,current_module.globalsymtable,ref,staticvarsym);
allocate_implicit_structs_for_st_with_base_ref(list,current_module.localsymtable,ref,staticvarsym); allocate_implicit_structs_for_st_with_base_ref(list,current_module.localsymtable,ref,staticvarsym);
@ -1866,7 +1866,7 @@ implementation
{ also initialise local variables, if any } { also initialise local variables, if any }
inherited; inherited;
{ initialise class fields } { initialise class fields }
reference_reset_base(ref,NR_NO,0,1); cgutils.reference_reset_base(ref,NR_NO,0,1);
allocate_implicit_structs_for_st_with_base_ref(list,tabstractrecorddef(current_procinfo.procdef.owner.defowner).symtable,ref,staticvarsym); allocate_implicit_structs_for_st_with_base_ref(list,tabstractrecorddef(current_procinfo.procdef.owner.defowner).symtable,ref,staticvarsym);
end end
else else
@ -2415,7 +2415,7 @@ implementation
internalerror(2011033001); internalerror(2011033001);
selfreg:=getaddressregister(list,selfpara.vardef); selfreg:=getaddressregister(list,selfpara.vardef);
a_load_loc_reg(list,obj,obj,selfpara.localloc,selfreg); a_load_loc_reg(list,obj,obj,selfpara.localloc,selfreg);
reference_reset_base(ref,selfreg,0,1); cgutils.reference_reset_base(ref,selfreg,0,1);
allocate_implicit_structs_for_st_with_base_ref(list,obj.symtable,ref,fieldvarsym); allocate_implicit_structs_for_st_with_base_ref(list,obj.symtable,ref,fieldvarsym);
end; end;