* unless compiled with -dnounsupported, the compiler will now accept not

only JVM constructs that are already implemented, but also ones that
    will be supported in the future but that aren't implemented yet (to
    make it easier to already adapt code to the future changes)

git-svn-id: branches/jvmbackend@18498 -
This commit is contained in:
Jonas Maebe 2011-08-20 08:04:51 +00:00
parent 4491dafd48
commit d1a1d30e04
16 changed files with 259 additions and 6 deletions

View File

@ -85,6 +85,14 @@ interface
case nodetype of case nodetype of
addn: addn:
begin begin
{$ifndef nounsupported}
if not is_wide_or_unicode_string(resultdef) then
begin
result:=left;
left:=nil;
exit;
end;
{$endif nounsupported}
if (left.nodetype=stringconstn) and (tstringconstnode(left).len=0) then if (left.nodetype=stringconstn) and (tstringconstnode(left).len=0) then
begin begin
result:=right; result:=right;
@ -113,6 +121,9 @@ interface
end; end;
ltn,lten,gtn,gten,equaln,unequaln : ltn,lten,gtn,gten,equaln,unequaln :
begin begin
{$ifndef nounsupported}
left.resultdef:=cunicodestringtype;
{$endif nounsupported}
{ call compare routine } { call compare routine }
cmpfuncname := 'fpc_'+tstringdef(left.resultdef).stringtypname+'_compare'; cmpfuncname := 'fpc_'+tstringdef(left.resultdef).stringtypname+'_compare';
{ for equality checks use optimized version } { for equality checks use optimized version }

View File

@ -550,6 +550,20 @@ implementation
result:=true; result:=true;
exit; exit;
end; end;
{$ifndef nounsupported}
if ((left.resultdef.typ=procvardef) and
((resultdef=methodpointertype) or
(resultdef=search_system_type('TMETHOD').typedef))) or
((resultdef.typ=procvardef) and
((left.resultdef=methodpointertype) or
(left.resultdef=search_system_type('TMETHOD').typedef))) then
begin
convtype:=tc_equal;
result:=true;
exit;
end;
{$endif}
end; end;

View File

@ -31,6 +31,10 @@ interface
node,nmem,ncgmem; node,nmem,ncgmem;
type type
tjvmloadparentfpnode = class(tcgloadparentfpnode)
procedure pass_generate_code;override;
end;
tjvmvecnode = class(tcgvecnode) tjvmvecnode = class(tcgvecnode)
function pass_1: tnode; override; function pass_1: tnode; override;
procedure pass_generate_code;override; procedure pass_generate_code;override;
@ -46,6 +50,19 @@ implementation
aasmdata,pass_2, aasmdata,pass_2,
cgutils,hlcgobj,hlcgcpu; cgutils,hlcgobj,hlcgcpu;
{ tjvmloadparentfpnode }
procedure tjvmloadparentfpnode.pass_generate_code;
begin
{$ifndef nounsupported}
location_reset(location,LOC_REGISTER,OS_ADDR);
location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,java_jlobject);
hlcg.a_load_const_reg(current_asmdata.CurrAsmList,java_jlobject,0,location.register);
{$else}
internalerror(2011041301);
{$endif}
end;
{***************************************************************************** {*****************************************************************************
TJVMVECNODE TJVMVECNODE
*****************************************************************************} *****************************************************************************}
@ -77,6 +94,14 @@ implementation
var var
newsize: tcgsize; newsize: tcgsize;
begin begin
{$ifndef nounsupported}
if left.resultdef.typ=stringdef then
begin
location:=left.location;
exit;
end;
{$endif}
{ This routine is not used for Strings, as they are a class type and { This routine is not used for Strings, as they are a class type and
you have to use charAt() there to load a character (and you cannot you have to use charAt() there to load a character (and you cannot
change characters; you have to create a new string in that case) change characters; you have to create a new string in that case)

View File

@ -120,6 +120,15 @@ unit tgcpu;
thlcgjvm(hlcg).a_load_stack_ref(list,java_jlobject,ref,0); thlcgjvm(hlcg).a_load_stack_ref(list,java_jlobject,ref,0);
result:=true; result:=true;
end; end;
setdef:
begin
if is_smallset(def) then
exit;
{$ifndef nounsupported}
gettemp(list,java_jlobject.size,java_jlobject.alignment,temptype,ref);
result:=true;
{$endif}
end;
end; end;
end; end;

View File

@ -91,8 +91,12 @@ implementation
st_unicodestring: st_unicodestring:
encodedstr:=encodedstr+'Ljava/lang/String;'; encodedstr:=encodedstr+'Ljava/lang/String;';
else else
{$ifndef nounsupported}
result:=jvmaddencodedtype(java_jlobject,false,encodedstr,founderror);
{$else}
{ May be handled via wrapping later } { May be handled via wrapping later }
result:=false; result:=false;
{$endif}
end; end;
end; end;
enumdef, enumdef,
@ -127,6 +131,11 @@ implementation
end; end;
pointerdef : pointerdef :
begin begin
{$ifndef nounsupported}
if def=voidpointertype then
result:=jvmaddencodedtype(java_jlobject,false,encodedstr,founderror)
else
{$endif}
{ some may be handled via wrapping later } { some may be handled via wrapping later }
result:=false; result:=false;
end; end;
@ -156,17 +165,25 @@ implementation
end; end;
classrefdef : classrefdef :
begin begin
{$ifndef nounsupported}
result:=jvmaddencodedtype(java_jlobject,false,encodedstr,founderror);
{$else}
{ may be handled via wrapping later } { may be handled via wrapping later }
result:=false; result:=false;
{$endif}
end; end;
setdef : setdef :
begin begin
if is_smallset(def) then if is_smallset(def) then
encodedstr:=encodedstr+'I' encodedstr:=encodedstr+'I'
else else
{ will be hanlded via wrapping later, although wrapping may {$ifndef nounsupported}
happen at higher level } result:=jvmaddencodedtype(java_jlobject,false,encodedstr,founderror);
result:=false; {$else}
{ will be hanlded via wrapping later, although wrapping may
happen at higher level }
result:=false;
{$endif}
end; end;
formaldef : formaldef :
begin begin
@ -175,8 +192,13 @@ implementation
end; end;
arraydef : arraydef :
begin begin
if is_array_of_const(def) or if is_array_of_const(def) then
is_packed_array(def) then {$ifndef nounsupported}
result:=jvmaddencodedtype(java_jlobject,false,encodedstr,founderror)
{$else}
result:=false
{$endif}
else if is_packed_array(def) then
result:=false result:=false
else else
begin begin
@ -191,9 +213,13 @@ implementation
end; end;
procvardef : procvardef :
begin begin
{$ifndef nounsupported}
result:=jvmaddencodedtype(java_jlobject,false,encodedstr,founderror);
{$else}
{ will be hanlded via wrapping later, although wrapping may { will be hanlded via wrapping later, although wrapping may
happen at higher level } happen at higher level }
result:=false; result:=false;
{$endif}
end; end;
objectdef : objectdef :
case tobjectdef(def).objecttype of case tobjectdef(def).objecttype of

View File

@ -2112,6 +2112,12 @@ implementation
newstatement : tstatementnode; newstatement : tstatementnode;
temp : ttempcreatenode; temp : ttempcreatenode;
begin begin
{$ifdef jvm}
{$ifndef nounsupported}
result:=cnothingnode.create;
exit;
{$endif nounsupported}
{$endif}
result:=nil; result:=nil;
case nodetype of case nodetype of
equaln,unequaln,lten,gten: equaln,unequaln,lten,gten:

View File

@ -1628,6 +1628,12 @@ implementation
function tcallnode.gen_procvar_context_tree:tnode; function tcallnode.gen_procvar_context_tree:tnode;
begin begin
{$ifdef jvm}
{$ifndef nounsupported}
result:=cnilnode.create;
exit;
{$endif}
{$endif}
{ Load tmehodpointer(right).self (either self or parentfp) } { Load tmehodpointer(right).self (either self or parentfp) }
result:=genloadfield(ctypeconvnode.create_internal( result:=genloadfield(ctypeconvnode.create_internal(
right.getcopy,methodpointertype), right.getcopy,methodpointertype),

View File

@ -839,6 +839,7 @@ implementation
else else
{ now procedure variable case } { now procedure variable case }
begin begin
{$if defined(nounsupported) or not defined(jvm)}
secondpass(right); secondpass(right);
pvreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR); pvreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
@ -848,6 +849,7 @@ implementation
else else
cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_ADDR,right.location,pvreg); cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_ADDR,right.location,pvreg);
location_freetemp(current_asmdata.CurrAsmList,right.location); location_freetemp(current_asmdata.CurrAsmList,right.location);
{$endif defined(nounsupported) or not defined(jvm)}
{ Load parameters that are in temporary registers in the { Load parameters that are in temporary registers in the
correct parameter register } correct parameter register }
@ -858,6 +860,7 @@ implementation
freeparas; freeparas;
end; end;
{$if defined(nounsupported) or not defined(jvm)}
cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int); cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
if cg.uses_registers(R_FPUREGISTER) then if cg.uses_registers(R_FPUREGISTER) then
cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu); cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
@ -870,6 +873,7 @@ implementation
extra_interrupt_code; extra_interrupt_code;
extra_call_code; extra_call_code;
cg.a_call_reg(current_asmdata.CurrAsmList,pvreg); cg.a_call_reg(current_asmdata.CurrAsmList,pvreg);
{$endif defined(nounsupported) or not defined(jvm)}
extra_post_call_code; extra_post_call_code;
end; end;

View File

@ -360,6 +360,13 @@ interface
procedure tcgtypeconvnode.second_char_to_string; procedure tcgtypeconvnode.second_char_to_string;
begin begin
{$ifdef jvm}
{$ifndef nounsupported}
location_reset_ref(location,LOC_REFERENCE,OS_NO,1);
tg.gethltemp(current_asmdata.CurrAsmList,cshortstringtype,256,tt_normal,location.reference);
exit;
{$endif nounsupported}
{$endif jvm}
location_reset_ref(location,LOC_REFERENCE,OS_NO,2); location_reset_ref(location,LOC_REFERENCE,OS_NO,2);
case tstringdef(resultdef).stringtype of case tstringdef(resultdef).stringtype of
st_shortstring : st_shortstring :
@ -479,6 +486,14 @@ interface
var var
tmpreg: tregister; tmpreg: tregister;
begin begin
{$ifdef jvm}
{$ifndef nounsupported}
location_reset(location,LOC_REGISTER,OS_ADDR);
location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,java_jlobject);
hlcg.a_load_const_reg(current_asmdata.CurrAsmList,java_jlobject,0,location.register);
exit;
{$endif nounsupported}
{$endif jvm}
if tabstractprocdef(resultdef).is_addressonly then if tabstractprocdef(resultdef).is_addressonly then
begin begin
location_reset(location,LOC_REGISTER,OS_ADDR); location_reset(location,LOC_REGISTER,OS_ADDR);
@ -513,6 +528,14 @@ interface
var r:Treference; var r:Treference;
begin begin
{$ifdef jvm}
{$ifndef nounsupported}
tg.gethltemp(current_asmdata.currasmlist,java_jlobject,java_jlobject.size,tt_normal,r);
location_reset_ref(location,LOC_REFERENCE,def_cgsize(resultdef),0);
location.reference:=r;
exit;
{$endif}
{$endif}
tg.gethltemp(current_asmdata.currasmlist,methodpointertype,methodpointertype.size,tt_normal,r); tg.gethltemp(current_asmdata.currasmlist,methodpointertype,methodpointertype.size,tt_normal,r);
location_reset_ref(location,LOC_REFERENCE,def_cgsize(resultdef),0); location_reset_ref(location,LOC_REFERENCE,def_cgsize(resultdef),0);
location.reference:=r; location.reference:=r;

View File

@ -71,7 +71,7 @@ implementation
symconst,symdef,aasmbase,aasmtai,aasmdata,aasmcpu,defutil, symconst,symdef,aasmbase,aasmtai,aasmdata,aasmcpu,defutil,
cpuinfo,cpubase, cpuinfo,cpubase,
cgbase,cgobj,cgutils, cgbase,cgobj,cgutils,
ncgutil, cclasses,asmutils ncgutil, cclasses,asmutils,tgobj
; ;
@ -409,6 +409,13 @@ implementation
i : longint; i : longint;
entry : PHashSetItem; entry : PHashSetItem;
begin begin
{$ifdef jvm}
{$ifndef nounsupported}
location_reset_ref(location,LOC_REFERENCE,OS_ADDR,1);
tg.gethltemp(current_asmdata.CurrAsmList,resultdef,resultdef.size,tt_persistent,location.reference);
exit;
{$endif nounsupported}
{$endif jvm}
location_reset_ref(location,LOC_CREFERENCE,OS_NO,const_align(8)); location_reset_ref(location,LOC_CREFERENCE,OS_NO,const_align(8));
lastlabel:=nil; lastlabel:=nil;
{ const already used ? } { const already used ? }

View File

@ -528,6 +528,9 @@ implementation
var var
setpara, elepara: tnode; setpara, elepara: tnode;
begin begin
{$if defined(jvm) and not defined(nounsupported)}
exit;
{$endif}
{ the set } { the set }
secondpass(tcallparanode(left).left); secondpass(tcallparanode(left).left);
{ the element to set } { the element to set }

View File

@ -412,6 +412,7 @@ implementation
localvarsym : localvarsym :
begin begin
vs:=tabstractnormalvarsym(symtableentry); vs:=tabstractnormalvarsym(symtableentry);
{$if not defined(jvm) or not defined(nounsupported)}
{ Nested variable } { Nested variable }
if assigned(left) then if assigned(left) then
begin begin
@ -423,6 +424,7 @@ implementation
reference_reset_base(location.reference,left.location.register,vs.localloc.reference.offset,vs.localloc.reference.alignment); reference_reset_base(location.reference,left.location.register,vs.localloc.reference.offset,vs.localloc.reference.alignment);
end end
else else
{$endif}
location:=vs.localloc; location:=vs.localloc;
{ handle call by reference variables when they are not { handle call by reference variables when they are not
@ -455,6 +457,14 @@ implementation
end; end;
procsym: procsym:
begin begin
{$ifdef jvm}
{$ifndef nounsupported}
location_reset(location,LOC_REGISTER,OS_ADDR);
location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,java_jlobject);
hlcg.a_load_const_reg(current_asmdata.CurrAsmList,java_jlobject,0,location.register);
exit;
{$endif nounsupported}
{$endif jvm}
if not assigned(procdef) then if not assigned(procdef) then
internalerror(200312011); internalerror(200312011);
if assigned(left) then if assigned(left) then
@ -1095,6 +1105,7 @@ implementation
if dovariant then if dovariant then
begin begin
{$if not defined(jvm) or defined(nounsupported)}
{ find the correct vtype value } { find the correct vtype value }
vtype:=$ff; vtype:=$ff;
vaddr:=false; vaddr:=false;
@ -1214,6 +1225,7 @@ implementation
cg.a_load_const_ref(current_asmdata.CurrAsmList, OS_INT,vtype,href); cg.a_load_const_ref(current_asmdata.CurrAsmList, OS_INT,vtype,href);
{ goto next array element } { goto next array element }
advancearrayoffset(href,sizeof(pint)*2); advancearrayoffset(href,sizeof(pint)*2);
{$endif not jvm or nounsupported}
end end
else else
{ normal array constructor of the same type } { normal array constructor of the same type }

View File

@ -101,6 +101,14 @@ implementation
entry : PHashSetItem; entry : PHashSetItem;
begin begin
{$ifdef jvm}
{$ifndef nounsupported}
location_reset(location,LOC_REGISTER,OS_ADDR);
location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,java_jlobject);
hlcg.a_load_const_reg(current_asmdata.CurrAsmList,java_jlobject,0,location.register);
exit;
{$endif nounsupported}
{$endif jvm}
location_reset(location,LOC_REGISTER,OS_ADDR); location_reset(location,LOC_REGISTER,OS_ADDR);
if (left.nodetype=typen) then if (left.nodetype=typen) then
begin begin
@ -151,6 +159,14 @@ implementation
hsym : tparavarsym; hsym : tparavarsym;
href : treference; href : treference;
begin begin
{$ifdef jvm}
{$ifndef nounsupported}
location_reset(location,LOC_REGISTER,OS_ADDR);
location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,java_jlobject);
hlcg.a_load_const_reg(current_asmdata.CurrAsmList,java_jlobject,0,location.register);
exit;
{$endif nounsupported}
{$endif jvm}
if (current_procinfo.procdef.parast.symtablelevel=parentpd.parast.symtablelevel) then if (current_procinfo.procdef.parast.symtablelevel=parentpd.parast.symtablelevel) then
begin begin
location_reset(location,LOC_REGISTER,OS_ADDR); location_reset(location,LOC_REGISTER,OS_ADDR);
@ -192,6 +208,14 @@ implementation
procedure tcgaddrnode.pass_generate_code; procedure tcgaddrnode.pass_generate_code;
begin begin
{$ifdef jvm}
{$ifndef nounsupported}
location_reset(location,LOC_REGISTER,OS_ADDR);
location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,java_jlobject);
hlcg.a_load_const_reg(current_asmdata.CurrAsmList,java_jlobject,0,location.register);
exit;
{$endif nounsupported}
{$endif jvm}
secondpass(left); secondpass(left);
location_reset(location,LOC_REGISTER,OS_ADDR); location_reset(location,LOC_REGISTER,OS_ADDR);

View File

@ -276,6 +276,17 @@ implementation
if nf_swapped in flags then if nf_swapped in flags then
swapleftright; swapleftright;
{$if defined(jvm) and not defined(nounsupported)}
if not is_smallset(left.resultdef) then
begin
location_reset(location, LOC_REGISTER, uopsize{def_cgsize(resultdef)});
{ allocate a register for the result }
location.register:=cg.getintregister(current_asmdata.CurrAsmList, uopsize);
hlcg.a_load_const_reg(current_asmdata.CurrAsmList,s32inttype,0,location.register);
exit;
end;
{$endif}
setbase:=tsetdef(right.resultdef).setbase; setbase:=tsetdef(right.resultdef).setbase;
if genjumps then if genjumps then
begin begin

View File

@ -401,6 +401,15 @@ implementation
addfield(hrecst,tfieldvarsym.create('$self',vs_value,voidpointertype,[])); addfield(hrecst,tfieldvarsym.create('$self',vs_value,voidpointertype,[]));
methodpointertype:=trecorddef.create('',hrecst); methodpointertype:=trecorddef.create('',hrecst);
addtype('$methodpointer',methodpointertype); addtype('$methodpointer',methodpointertype);
end
else
begin
{$if defined(jvm) and not defined(nounsupported)}
hrecst:=trecordsymtable.create('',1);
addfield(hrecst,tfieldvarsym.create('$proc',vs_value,voidpointertype,[]));
methodpointertype:=trecorddef.create('',hrecst);
addtype('$methodpointer',methodpointertype);
{$endif}
end; end;
symtablestack.pop(systemunit); symtablestack.pop(systemunit);
end; end;
@ -477,7 +486,9 @@ implementation
end; end;
loadtype('variant',cvarianttype); loadtype('variant',cvarianttype);
loadtype('olevariant',colevarianttype); loadtype('olevariant',colevarianttype);
{$if defined(nounsupported) or not defined(jvm)}
if not(target_info.system in systems_managed_vm) then if not(target_info.system in systems_managed_vm) then
{$endif}
loadtype('methodpointer',methodpointertype); loadtype('methodpointer',methodpointertype);
loadtype('HRESULT',hresultdef); loadtype('HRESULT',hresultdef);
{$ifdef cpu64bitaddr} {$ifdef cpu64bitaddr}

View File

@ -124,6 +124,67 @@ type
{$i jrech.inc} {$i jrech.inc}
{$i jdynarrh.inc} {$i jdynarrh.inc}
{$ifndef nounsupported}
type
tmethod = record
code: jlobject;
end;
const
vtInteger = 0;
vtBoolean = 1;
vtChar = 2;
{$ifndef FPUNONE}
vtExtended = 3;
{$endif}
vtString = 4;
vtPointer = 5;
vtPChar = 6;
vtObject = 7;
vtClass = 8;
vtWideChar = 9;
vtPWideChar = 10;
vtAnsiString = 11;
vtCurrency = 12;
vtVariant = 13;
vtInterface = 14;
vtWideString = 15;
vtInt64 = 16;
vtQWord = 17;
vtUnicodeString = 18;
type
TVarRec = record
case VType : sizeint of
{$ifdef ENDIAN_BIG}
vtInteger : ({$IFDEF CPU64}integerdummy1 : Longint;{$ENDIF CPU64}VInteger: Longint);
vtBoolean : ({$IFDEF CPU64}booldummy : Longint;{$ENDIF CPU64}booldummy1,booldummy2,booldummy3: byte; VBoolean: Boolean);
vtChar : ({$IFDEF CPU64}chardummy : Longint;{$ENDIF CPU64}chardummy1,chardummy2,chardummy3: byte; VChar: Char);
vtWideChar : ({$IFDEF CPU64}widechardummy : Longint;{$ENDIF CPU64}wchardummy1,VWideChar: WideChar);
{$else ENDIAN_BIG}
vtInteger : (VInteger: Longint);
vtBoolean : (VBoolean: Boolean);
vtChar : (VChar: Char);
vtWideChar : (VWideChar: WideChar);
{$endif ENDIAN_BIG}
// vtString : (VString: PShortString);
// vtPointer : (VPointer: Pointer);
/// vtPChar : (VPChar: PChar);
vtObject : (VObject: TObject);
// vtClass : (VClass: TClass);
// vtPWideChar : (VPWideChar: PWideChar);
vtAnsiString : (VAnsiString: JLString);
vtCurrency : (VCurrency: Currency);
// vtVariant : (VVariant: PVariant);
vtInterface : (VInterface: JLObject);
vtWideString : (VWideString: JLString);
vtInt64 : (VInt64: Int64);
vtUnicodeString : (VUnicodeString: JLString);
vtQWord : (VQWord: QWord);
end;
{$endif}
Function lo(i : Integer) : byte; [INTERNPROC: fpc_in_lo_Word]; Function lo(i : Integer) : byte; [INTERNPROC: fpc_in_lo_Word];
Function lo(w : Word) : byte; [INTERNPROC: fpc_in_lo_Word]; Function lo(w : Word) : byte; [INTERNPROC: fpc_in_lo_Word];
Function lo(l : Longint) : Word; [INTERNPROC: fpc_in_lo_long]; Function lo(l : Longint) : Word; [INTERNPROC: fpc_in_lo_long];