Commit Graph

467 Commits

Author SHA1 Message Date
Jonas Maebe
f4c0daddb4 * moved jvm-specific exprasm field from tprocdef to jvm-specific descendant
git-svn-id: trunk@27394 -
2014-03-30 21:04:25 +00:00
Jonas Maebe
11c7d5223c * moved ifdef'd jvm code from tprocvardef to jvm-specific descendant
git-svn-id: trunk@27386 -
2014-03-30 17:15:57 +00:00
Jonas Maebe
721fd887c3 * moved all jvm-specific code from symsym to jvm/symcpu
git-svn-id: trunk@27384 -
2014-03-30 16:55:09 +00:00
Jonas Maebe
b57c95043f + support overriding tdef/tsym methods with target-specific functionality:
o made all (non-abstract) tdef and tsym constructors virtual
   o added c*def/c*sym classref types for every (non-abstract) t*def/t*sym
     class
   o added cpusym unit for every architecture that derives a tcpu*def/tcpu*sym
     class from the base classes, and initialises the c*def/c*sym classes with
     them. This is done so that the llvm target will be able to derive from
     the tcpu*def/sym classes without umpteen ifdefs, and it also means that
     the WPO can devirtualise everything because the c* variables are only
     initialised with one class type
   o replaced all t*def/t*sym constructor calls with c*def/c*sym constructor
     calls

git-svn-id: trunk@27361 -
2014-03-29 22:31:55 +00:00
nickysn
26b53607f8 + 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 -
2014-03-28 00:01:18 +00:00
Jonas Maebe
8d4c372d50 * removed ifdef jvm from ncgvmt
git-svn-id: trunk@27154 -
2014-03-16 11:24:44 +00:00
Jonas Maebe
73a3f5ced4 * moved ncgutil.maybechangeloadnodereg() to hlcg.maybe_change_load_node_reg()
and moved ifdef'd jvm code to overridden method

git-svn-id: trunk@27153 -
2014-03-16 11:24:40 +00:00
Jonas Maebe
d46c353849 * migrated JVM-specific second_nil_to_methodprocvar code to njvmcnv
git-svn-id: trunk@27150 -
2014-03-16 11:24:29 +00:00
Jonas Maebe
84442d05f9 * renamed fobjcforcedprocname to fforcedprocname and also use it for the
JVM target to force virtual method calls to be name-based rather than
    VMT-entry-based

git-svn-id: trunk@27149 -
2014-03-16 11:24:25 +00:00
Jonas Maebe
908bbed312 * moved jvm-specific tarrayreftype from cgutils to jvm/cpubase
git-svn-id: trunk@27148 -
2014-03-16 11:24:21 +00:00
Jonas Maebe
81427523ab * pass a list of (pointers to) the paralocs to hlcgobj.a_call/g_call*, as
required for the LLVM support (LLVM parameter support is not yet
    included)
  * always return the function return loc from a_call*, again as required
    for the LLVM support

git-svn-id: branches/hlcgllvm@26992 -
2014-03-06 21:40:57 +00:00
Jonas Maebe
e9268a0a14 * synchronised with trunk up till r26975
git-svn-id: branches/hlcgllvm@26976 -
2014-03-06 21:36:58 +00:00
Jonas Maebe
98517b9ac9 * set imaginary register start for JVM at register number 2, since there
are only 2 (fake) "real" registers

git-svn-id: trunk@26957 -
2014-03-04 19:42:43 +00:00
Jonas Maebe
8065fc24d9 * fixed indentation of stack slot allocation debug statements
git-svn-id: trunk@26474 -
2014-01-15 20:36:59 +00:00
Jonas Maebe
2518c526c7 * always use a new register for array indices modified by a constant,
improves register/stack allocation

git-svn-id: trunk@26473 -
2014-01-15 20:36:56 +00:00
Jonas Maebe
a5653916e0 * convert array indices always to s32int, because that is the index type used
by java arrays (otherwise we may get unwanted sign extensions after
    performing e.g. an s16bit operation, see the test)

git-svn-id: trunk@26472 -
2014-01-15 20:36:52 +00:00
florian
4d5119bf1c * fixes several issues which cause warnings by the dfa code when using it to detect uninitialized variables
git-svn-id: trunk@26161 -
2013-12-01 17:02:08 +00:00
sergei
d72478eb64 * Function tjvmaddnode.cmpnode2topcmp is, in fact, not specific to any target. Moved it to generic tcgaddnode and reused in tmipsaddnode, where the same functionality was implemented in different way.
git-svn-id: trunk@26151 -
2013-11-28 11:52:47 +00:00
Jonas Maebe
99de108c68 * renamed all paramanagers to tcpuparamanager so the llvm paramanager can
derive from them without ifdefs

git-svn-id: branches/hlcgllvm@26039 -
2013-11-11 11:15:27 +00:00
Jonas Maebe
b47cc22d66 * separated JVM-specific subscripting code in virtual method
git-svn-id: branches/hlcgllvm@26030 -
2013-11-11 11:14:47 +00:00
Jonas Maebe
c693a91e18 * fixed compilation after r25847 (mantis #25237)
git-svn-id: trunk@25870 -
2013-10-27 17:35:04 +00:00
svenbarth
798bb91e90 Extract tdef.is_related plus its overrides in tobjectdef, trecorddef and tstringdef into a new function def_is_related in unit defcmp.
defcmp.pas:
  + add new function "def_is_related" which combines the "is_related" overloads of "tobjectdef", "trecorddef" and "tstringdef" (it returns "false" for other def types which is what "tdef.is_related" did)
  * compare_defs_ext & compatible_childmethod_resultdef: change call from "x.is_related" to "def_is_related(x,...)"
symtype.pas, tdef:
  - remove "is_related" method
symdef.pas:
  - remove "is_related" in "tobjectdef", "trecorddef" and "tstringdef"
  * tobjectdef.needs_inittable: for checking whether a Corba interface somehow inherits from a IInterface don't use "is_related" anymore (we want to avoid the dependency after all), but mimic the necessary functionality of "def_is_related"
htypechk.pas, nadd.pas, ncal.pas, ncnv.pas, ngtcon.pas, nld.pas, optvirt.pas, pdecobj.pas, pdecvar.pas, pexpr.pas, pgenutil.pas:
  * change call from "x.is_related" to "def_is_related(x,...)"
symtable.pas
  + use unit defcmp
  * change call from "x.is_related" to "def_is_related(x,...)"
jvm/njvmcnv.pas, jvm/njvmflw.pas:
  * change call from "x.is_related" to "def_is_related(x,...)"

git-svn-id: trunk@25847 -
2013-10-25 19:44:27 +00:00
svenbarth
c48d572996 Implement support for saving and restoring address registers.
cgobj.pas, tcg:
  * g_save_registers: add the amount of used address registers to size as well
  * g_save_registers: save all used address registers
  * g_restore_registers: restore all stored address registers
m68k/cpubase.pas:
  * rename saved_standard_address_registers to saved_address_registers
all other platform's cpubase.{inc,pas} (except alpha, ia64 and vis which are not up to date):
  * add a saved_address_registers variable with one entry of RS_INVALID

At least a "make fullcycle" did complete.

git-svn-id: trunk@25664 -
2013-10-05 21:43:42 +00:00
Jonas Maebe
20d6db20c8 * fixed compilation of length(unicode/ansistring) on JVM target after r25499
(we previously internally generated assigned(unicode/ansistring) nodes,
     which now cause typecheck errors because there is no special assigned
     handling anymore)

git-svn-id: trunk@25557 -
2013-09-24 23:57:17 +00:00
Jonas Maebe
d2bad665fa * fixed a_op_*_reg() for OP_NOT/OP_NEG (due to the register allocation the
generated code often was still valid though)

git-svn-id: trunk@25415 -
2013-09-04 19:16:59 +00:00
Jonas Maebe
a14ceba791 + -CTinitlocals switch for the JVM that initialises all local variables
that may trigger JVM bytecode verification errors if they are used
    before they are initialised (this includes passing them as a "var"
    parameter) + test
  * sorted -CT parameters alphabetically and alligned them

git-svn-id: trunk@25387 -
2013-08-29 22:21:23 +00:00
Jonas Maebe
1ce93f7430 * when automatically generating an overriding getter/setter method (because
a property in a child class has a higher visibility than the getter/
    setter), ensure that we call the inherited method and not the method
    itself (causing a stack overflow due to infinite recursion)

git-svn-id: trunk@25223 -
2013-08-06 21:50:56 +00:00
pierre
eb1ff90de1 Fix jvm compiler compilation failure after rev 25013
git-svn-id: trunk@25028 -
2013-07-02 12:52:32 +00:00
Jonas Maebe
7566ddcc8f * add a tdef to each parameter location and set it for all target
backends (not yet used, will be used in high level code generator)

git-svn-id: trunk@24761 -
2013-06-02 10:24:02 +00:00
Jonas Maebe
f985149163 * fixed compilation after r24661 (added dummy overloads for newly
implemented LOC_MMREGISTER hlcgobj methods)

git-svn-id: trunk@24731 -
2013-06-01 16:48:11 +00:00
florian
0e41df598e * merge i8086 branch by Nikolay Nikolov
git-svn-id: trunk@24324 -
2013-04-25 20:23:51 +00:00
Jonas Maebe
abc79bc4cf * override tcgraisenode.pass_1 so that the JVM raise support will keep
working after r24288 is merged to trunk

git-svn-id: trunk@24301 -
2013-04-22 14:47:06 +00:00
nickysn
7b8e18ba40 * updated aint to tcgint in jvm/hlcgcpu.pas as well (needed after r23761)
git-svn-id: branches/i8086@24088 -
2013-03-31 12:52:56 +00:00
Jonas Maebe
477eeadaca * made alloctemp more generic
git-svn-id: trunk@24023 -
2013-03-27 17:16:26 +00:00
Jonas Maebe
185f71762f * fixed automatic setter generation if only a setter and no getter prefix
has been specified

git-svn-id: trunk@23561 -
2013-02-02 15:21:58 +00:00
Jonas Maebe
8f96ace589 * fixed -CTauto(g|s)etterprefix automatically generated helpers in case they
have to wrap an existing (g|s)etter that was marked as "abstract" (don't
    mark the helper also as abstract, sicnce it contains code)

git-svn-id: trunk@23545 -
2013-01-30 22:35:59 +00:00
Jonas Maebe
2ed4b295fe * only change the visibility of an existing getter/setter to that of
its property in case the visibility of the property is higher than
    that of the getter/setter (on the JVM target when automatically
    generating getters/setters)

git-svn-id: trunk@23523 -
2013-01-26 16:52:32 +00:00
Jonas Maebe
9cbff6f5a6 + support for record constructors for the JVM target
git-svn-id: trunk@23510 -
2013-01-24 09:45:12 +00:00
Jonas Maebe
3abc7b0d9c * removed superfluous check (a procvardef can never be a constructor) and
typecasts

git-svn-id: trunk@23509 -
2013-01-24 09:45:06 +00:00
paul
51825b6f2e compiler: change ret_in_param to accept tabstractprocdef instead of tproccalloption to allow check more options (required for record constructor implementation)
git-svn-id: trunk@23394 -
2013-01-16 01:14:23 +00:00
Jonas Maebe
69c29a415f * pass the procdef to getintparaloc instead of only the proccalloption, so
that the type of the parameters can be determined automatically
   o added compilerproc declarations for all helpers called in the compiler
     via their assembler name, so we can look up the corresponding procdef

git-svn-id: trunk@23325 -
2013-01-06 15:05:40 +00:00
Jonas Maebe
d9e67fc835 * don't add a separate high parameter for array-of-const parameters on the
JVM target (just like for open array parameters), since the array length
    is already encoded in the array itself there

git-svn-id: trunk@22968 -
2012-11-10 20:26:42 +00:00
Jonas Maebe
4aa05f5133 + support for automatically generating setters/getters for properties on the
JVM target, since Java bytecode itself has no support for properties and
    hence exposing properties to external Java code can only be done through
    getters/setters. Use the new parameters to do so:
      -CTautogetterprefix=XXX
      -CTautosetterprefix=YYY
    The getter/setter will get the same visibility as the property. If a
    getter/setter with the same naming convention was already specified for a
    property and this getter/setter is declared in the same class as the
    property, then the visibility of this existing getter/setter is
    modified and no new routine is generated.

    Newly generated getters/setters are virtual methods, because that is
    the only way in Java bytecode to allow redefining these getters/setters
    in child classes. However, that also means that using these switches can
    change the behvaviour of code, since normally the used property definition
    is only determined by the declared type of its associated class instance,
    and not by the actual instance type. The compiler will therefore warn when
    such an automatically generated getter/setter is overridden by another
    automatically generated getter/setter in a child class.

git-svn-id: trunk@22959 -
2012-11-08 20:18:08 +00:00
Jonas Maebe
29263eb343 + full support for overflow checking on the JVM target (note: significantly
increases code size, because not natively supported by the JVM)

git-svn-id: trunk@22808 -
2012-10-21 17:56:33 +00:00
Jonas Maebe
6abc6106e1 - removed unused local variable
git-svn-id: trunk@22806 -
2012-10-21 17:56:20 +00:00
Jonas Maebe
62c8e47547 + override unnecessary abstract thlcgobj methods with internal errors
git-svn-id: trunk@22281 -
2012-09-02 14:32:31 +00:00
Jonas Maebe
f9c6967c36 * fixed not(pasbool64) (has to be "xor 1" rather than "xor -1")
git-svn-id: trunk@22167 -
2012-08-21 20:04:19 +00:00
Jonas Maebe
b353a2ff27 * fixed writing jvm type for string constants after r22020
git-svn-id: trunk@22123 -
2012-08-19 13:47:50 +00:00
florian
4d86d25c6c * -O4 switch for optimizations which are correct but which might have unexpected effects
like field reordering (possible problems cracker classes) or using ebp as normal register (broken
      stack traces from dump_stack)
    + niln is also valid in a cse domain
    * parameters passed by reference shall have a complexity >1
    * load nodes from outer scopes shall have a complexity >1
    * better cse debugging
    + more node types added to cse
    * consider parameters passed by reference in cse
    * take care of cse in parameters in simple cases

git-svn-id: trunk@22050 -
2012-08-09 18:58:54 +00:00
Jonas Maebe
0a1157da38 * fixed memory leaks in the compiler introduced in r21862 by marking and
releasing temporarily created function result locations

git-svn-id: trunk@21953 -
2012-07-23 13:49:29 +00:00
Jonas Maebe
7717e43929 * moved setting the call result to a separate method, so it can still be
used across multiple levels of inheritance such as on MIPS (and the code
    has to be reusable for a_call_ref/reeg in the future anyway)

git-svn-id: trunk@21906 -
2012-07-12 20:56:25 +00:00
Jonas Maebe
56fcc87cb2 * add get_frame as an internal symbol for the jvm target because that target
defines INTERNAL_BACKTRACE (which assumes get_frame to be internal rather
    than a system unit procedure)
  * changed fpc_assert() declaration for jvm to be the same as for other
    targets, so the same code can be used to call it in ninl now that's
    called from the first pass

git-svn-id: trunk@21903 -
2012-07-12 13:25:02 +00:00
Jonas Maebe
1955255dda * let thlcg.a_call_name() return the tcgpara representing the function
result location (NR_FUNCTION_RESULT_REG is not valid on all platforms)
   o this requires passing the forced function result type (if any) to this
     method
   o a generic, basic thlcg.a_call_name() is now available that sets the
     function result location; can be called by descendants
  * the availability under all circumstances of the correct function return
    type enables g_call_system_proc() on the JVM platform to now determine
    by itself how many stack slots are removed by the call -> do so, instead
    of manually counting them (or forgetting to do so and messing up the
    maximum evaluation stack height calculations)

git-svn-id: trunk@21862 -
2012-07-11 08:25:58 +00:00
Jonas Maebe
882351bb21 * don't insert a conversion to widechar for ansistr[x]:='y' assignments on
the jvm target  (forgot to adapt code after adding ansistring support)

git-svn-id: trunk@21765 -
2012-07-03 21:16:29 +00:00
Jonas Maebe
b0462d27cc * by default, no longer initialize enumeration fields of classes/objects
with the enum instance corresponding to ordinal 0 in JVM constructors,
    because a virtual method called by a parent constructor may already
    have assigned a different value (see tests/test/jvm/tenum2.pp). This
    will result in null pointer exceptions when using such fields without
    first explicitly assigning a value to them though.

    The old behaviour can be restored with the new -CTenumfieldinit command
    line parameter

git-svn-id: trunk@21736 -
2012-06-29 21:24:35 +00:00
Jonas Maebe
7c21cba1e2 * migrated g_copyshortstring, g_incrrefcount and g_array_rtti_helper to thlcg
git-svn-id: trunk@21699 -
2012-06-24 21:36:28 +00:00
Jonas Maebe
7a0ae38700 + also specify the parameter def when allocating a parameter via
getintparaloc + adapted all call sites of getintparaloc. This
    led to a number of additional, related changes:
   o corrected the type information for some getintparaloc parameters
   o don't allocate some intparalocs in cases they aren't used
   o changed "const tvardata" parameter into "constref tvardata" for
     fpc_variant_copy_overwrite to make pass-by-reference semantics
     explicit
   o moved a number of routines that now have to call find_system_type()
     from cgobj to hlcgobj so that cgobj doesn't have to start depending
     on the symtable unit
   o added versions of the cpureg alloc/dealloc methods to hlcgobj that
     call through to their cgobj counter parts, so we can call save/restore
     the cpu registers before/after calling system helpers from hlcgobj
     (not implemented in hlcgobj itself, because all basic register
      allocator functionality is still part of cgobj/cgcpu)

git-svn-id: trunk@21696 -
2012-06-24 15:02:12 +00:00
Jonas Maebe
708a2532fc * consistently define empty saved_mm_registers arrays as containing a single
RS_INVALID superregister (instead of sometimes RS_NO and sometimes
    RS_INVALID)
  * check for RS_INVALID in tcg.g_save_registers() and ignore such entries

git-svn-id: trunk@21622 -
2012-06-15 18:24:25 +00:00
Jonas Maebe
8234a842e6 * fixed conversion of empty ansistring/widestring constants to pchar on
the jvm target + test

git-svn-id: trunk@21391 -
2012-05-26 11:32:20 +00:00
Jonas Maebe
85a3fd3357 + ossinttype/osuinttype defs that correspond to OS_SINT/OS_INT for use in
the high level code generator

git-svn-id: trunk@21279 -
2012-05-12 16:03:15 +00:00
Jonas Maebe
8a7123eed8 * override a_call_reg() with an internalerror rather than a_call_ref(),
since it's the former that is abstract in the base class

git-svn-id: trunk@21126 -
2012-04-29 22:26:51 +00:00
Jonas Maebe
1345b7d107 * changed ref parameter of thlcgobj.a_call_ref() into a const parameter
git-svn-id: trunk@21115 -
2012-04-29 13:13:42 +00:00
Jonas Maebe
4fced5d142 + generic implementation of thlcgobj.a_call_ref()
* override thlcg.a_call_reg() in JVM hlcgcpu with dummy that calls
    internalerror

git-svn-id: trunk@21099 -
2012-04-28 14:27:45 +00:00
Jonas Maebe
e20639732f + cghlcpu unit with thlbasecgcpu class that overrides all abstract tcg
methods that don't have to be implemented by targets using the high
    level code generator, with dummy implementations that raise an internal
    error (to remove warnings about instantiating classes with abstract
    methods)
  * let the JVM tcg descendent derive from this new thlbasecgcpu class

git-svn-id: trunk@21098 -
2012-04-28 14:27:31 +00:00
pierre
857abd87ee + Implement create_varargs_paraloc_info, to allow compilation without warnings
git-svn-id: trunk@21073 -
2012-04-27 08:25:19 +00:00
Jonas Maebe
834026bfb5 * synchronised with trunk up to r21067
git-svn-id: branches/jvmbackend@21068 -
2012-04-26 21:24:20 +00:00
Jonas Maebe
0659058e44 * fixed ansistring -> pchar type conversion on JVM target now that empty
ansistrings are represented by nil
  * fixed type conversion of constant empty ansistring/unicodestring to
    pchar/pwidechar on the JVM target

git-svn-id: branches/jvmbackend@21055 -
2012-04-25 22:29:20 +00:00
Jonas Maebe
aee5380ae0 * merged trunk up to r20882
o support for the new codepage-aware ansistrings in the jvm branch
   o empty ansistrings are now always represented by a nil pointer rather than
     by an empty string, because an empty string also has a code page which
     can confuse code (although this will make ansistrings harder to use
     in Java code)
   o more string helpers code shared between the general and jvm rtl
   o support for indexbyte/word in the jvm rtl (warning: first parameter
     is an open array rather than an untyped parameter there, so
     indexchar(pcharvar^,10,0) will be equivalent to
     indexchar[pcharvar^],10,0) there, which is different from what is
     intended; changing it to an untyped parameter wouldn't help though)
   o default() support is not yet complete
   o calling fpcres is currently broken due to limitations in
     sysutils.executeprocess() regarding handling unix quoting and
     the compiler using the same command lines for scripts and directly
     calling external programs
   o compiling the Java compiler currently requires adding ALLOW_WARNINGS=1
     to the make command line

git-svn-id: branches/jvmbackend@20887 -
2012-04-15 15:54:10 +00:00
Jonas Maebe
622eb4b782 * call getbasedef before getting the classdef of an enum (only the basedef
has an associated class)

git-svn-id: branches/jvmbackend@20870 -
2012-04-14 17:38:02 +00:00
Jonas Maebe
21722802fa * also allow taking the address of a derefence expression on the JVM target
(required for taking the address of threadvars, used by the current RTL)

git-svn-id: branches/jvmbackend@20869 -
2012-04-14 17:37:56 +00:00
Jonas Maebe
94bdf8a086 * adjust integer type information before stores part of a_op_const_ref for
Dalvik type checker

git-svn-id: branches/jvmbackend@20628 -
2012-03-25 14:46:37 +00:00
Jonas Maebe
94b058fe19 * fixed version of r20547: can't check the number of abstract methods of a
class before its VMT has been built, because that's the process that looks
    for inherited abstract methods that are overridden -> instead use a new
    synthetic method kind (tsk_callthrough_nonabstract) that will call
    through to another method (in this case a constructor) if the owning
    class does not contain any abstract methods, and generates an
    empty routine otherwise

git-svn-id: branches/jvmbackend@20589 -
2012-03-23 11:26:30 +00:00
Jonas Maebe
94bffa65e9 * don't create an instance of abstract classes inside their virtual
constructors (simply do nothing), because creating an abstract class
    is not possible in the JVM (and while the JVM only triggers an
    exception when you actually execute code that tries to create an
    abstract class, the Android platform checks this using the bytecode
    verifier at class verification time and therefore stumbled over the
    old code)

git-svn-id: branches/jvmbackend@20547 -
2012-03-20 21:59:57 +00:00
Jonas Maebe
fc6be612fd * also insert an explicit conversion from byte/char/bytebool/... to smallint
on Dalvik, because those values are obtained via an "and 255" operation
    which again turns them into longint values as var as the Dalvik type
    system is concerned

git-svn-id: branches/jvmbackend@20527 -
2012-03-16 20:57:22 +00:00
Jonas Maebe
83235a483b * always return a LOC_JUMP from tjvmnotnode.second_boolean: required both
to correctly handle non-pasbool types (can't just "not" their value),
    and for Dalvik (a "not pasbool" became "xori 1", which turned the value
    from a boolean into an integer as far as the Dalvik type checker was
    concerned)

git-svn-id: branches/jvmbackend@20525 -
2012-03-16 17:23:55 +00:00
Jonas Maebe
0248258670 * always size the value on top of the stack back down to its original size
after an 8/16 bit operation on Dalvik (even if the value cannot have
    become too big), because otherwise its type checker complains

git-svn-id: branches/jvmbackend@20520 -
2012-03-15 17:05:50 +00:00
Jonas Maebe
85ef5e109c + assert() support for the JVM target (currently ignores the Java classloader
assertionStatus setting)

git-svn-id: branches/jvmbackend@20388 -
2012-02-20 11:28:59 +00:00
Jonas Maebe
3916a32f9e * created generic version of thlcgobj.g_reference_loc() and only override
JVM-specific case (needed for future trunk marge to prevent abstract
    method warning)

git-svn-id: branches/jvmbackend@20387 -
2012-02-20 11:28:50 +00:00
Jonas Maebe
0dfdae3132 * always get the basedef for an enum before using its classdef (since only
the basedef has an associated classdef)

git-svn-id: branches/jvmbackend@20142 -
2012-01-21 19:35:58 +00:00
Jonas Maebe
af9934cb6c * make sure that integers converted to widechar are always processed by an
i2c instruction for Dalvik verification purposes

git-svn-id: branches/jvmbackend@19826 -
2011-12-11 17:26:14 +00:00
Jonas Maebe
764502fbe4 * don't "and" loaded unsigned values of 1/2 bytes with 255/65535 in case
their upper bound is lower than 127/32767: not necessary, and in case
    of booleans not even allowed for Dalvik (because the "and" operation
    turns the boolean into an integer as far as Dalvik is concerned)

git-svn-id: branches/jvmbackend@19825 -
2011-12-11 17:25:58 +00:00
Jonas Maebe
c61e9a2f04 * fixed (harmless) invalid typecasts that caused run time errors with -CR
git-svn-id: branches/jvmbackend@19824 -
2011-12-11 17:25:50 +00:00
Jonas Maebe
f4f70f99b2 * call all operators with invokestatic, since they are always
class methods

git-svn-id: branches/jvmbackend@19823 -
2011-12-11 17:25:42 +00:00
Jonas Maebe
21e6401921 * no longer encode all pointers to other pointer types (such as
classes, interfaces, dynamic arrays, ...) as "array of JLObject",
    but instead as an array of the actual pointed-to type. The reason
    for the previous behaviour was mainly that the JVM threadvar
    implementation internally stores all threadvars that are
    such double pointer types into an "array of JLObject". Type casting
    this array to e.g. an "array of array of byte" causes an exception
    even if it only contains "array of byte" instances (since the outer
    array type is different). This is now solved by first taking the
    element of the array and then typecasting it to the destination
    type (so dynarrbyte(arr[0]) instead of pdynarrbyte(arr)^[0]).

    The reason for the new (more accurate) behaviour is because the
    old one caused type errors in case a double pointer field was
    internally created for the nestedfpstruct support (see added
    test)

git-svn-id: branches/jvmbackend@19821 -
2011-12-11 17:25:09 +00:00
Jonas Maebe
bd990d1173 * generate JVM bytecode that passes the stringent requirements of the Dalvik
verifier when -Cpjvmdalvik is used (including debug information). Using
    -Cpjvmdalvik changes the semantics at the language-level in one case:
    boolean(bytevar) will no longer return a boolean that contains the same
    value as bytevar did, but will map the value to 0/1 (that also means that
    such expressions cannot be passed to var-parameters in case of
    -Cpjvmdalvik). Code compiled with -Cpjvmdalvik will also work fine on
    the regular JVM, but it may be somewhat slower (it won't necessarily
    be slower on Dalvik, because the .class -> .dex transformation
    applies many optimizations itself)

git-svn-id: branches/jvmbackend@19743 -
2011-12-04 14:48:54 +00:00
Jonas Maebe
faaa86238c * enable support for creating loadvmtaddr nodes for Java interfaces, because
those are also supported by the Java language (intftype.class) and required
    in equivalent Pascal expressions (such as JLClass(intftype))

git-svn-id: branches/jvmbackend@19742 -
2011-12-04 14:48:48 +00:00
Jonas Maebe
08565ce5be * save/restore the current_except_loc instead of invalidating it after each
use (since try/except statements can be nested)

git-svn-id: branches/jvmbackend@19666 -
2011-11-21 18:48:19 +00:00
Jonas Maebe
4dee36b64b * copy the implicit pointer rather than the contents of var/out/constref
implicit pointer types into the nestedfpstruct, so that the original
    parameter is properly changed when updated from inside nested routines

git-svn-id: branches/jvmbackend@19645 -
2011-11-18 21:09:38 +00:00
Jonas Maebe
74510f9069 + generic infrastructure for target-specific switches
+ -CTcompactintarrayinit command line option to change the code generation
    for typed array of some kind of integer-type initialization so that it
    takes up less space in the bytecode (because the bytecode for all
    routines, including the class initialization code that contains the
    typed constant init code, is limited 64kb, large array or multiple
    array constants could fairly easily bump into that limit)

git-svn-id: branches/jvmbackend@19638 -
2011-11-14 22:57:41 +00:00
Jonas Maebe
1401c4e573 * fixed popping the unused function results of methods returning implicit
function pointer type results (records, shorstrings, ...): always pop a
    single stack slot in that case

git-svn-id: branches/jvmbackend@19598 -
2011-11-06 14:01:12 +00:00
Jonas Maebe
cfca607b9b * in case of an enum without a type name (e.g., "type xx = set of (ea,eb)"),
set the external name of the underlying class type to the internal name
    instead of to an (invalid) empty string

git-svn-id: branches/jvmbackend@19555 -
2011-10-28 21:19:12 +00:00
Jonas Maebe
cf47b8d422 * fixed all known memory leaks in the code added for the JVM port
git-svn-id: branches/jvmbackend@19248 -
2011-09-26 19:31:34 +00:00
Jonas Maebe
26b19274a3 + create an nested interface type called "Callback" inside the classes that
are used to implement procvar types, and add a constructor to the procvar
    types that accept an instance implementing this interface -> much easier
    and more natural to use procvar types from Java code

git-svn-id: branches/jvmbackend@19216 -
2011-09-24 20:32:01 +00:00
Jonas Maebe
5332263d46 * fixed r18981 (conversion of LOC_JUMP to something else must happen before
before the old jump labels are restored)

git-svn-id: branches/jvmbackend@19155 -
2011-09-19 21:22:35 +00:00
Jonas Maebe
583c9a3360 * replace assigned(dynarray) and dynarray=/<>nil with length(dynarray)=/<>0
on the JVM target because empty dynarrays are not always nil there

git-svn-id: branches/jvmbackend@19154 -
2011-09-19 19:59:32 +00:00
Jonas Maebe
f96f5f9e94 + {$VARPARACOPYOUTCHECK+/-} / -Cv switch to enable checking
var-parameters on the JVM target for changes to the value passed
    as var-parameter during the function call (because they are handled
    via copy-in/copy-out, this may indicate unexpected bahviour later on).

    out-parameters are checked in the same way, except if the out-parameter
    is a local variable because then reading it before the call may result
    in a bytecode verification error (since the variable may not yet be
    initialized)

git-svn-id: branches/jvmbackend@19153 -
2011-09-19 19:59:26 +00:00
Jonas Maebe
633de3fe30 * give an error when calling a virtual constructor from another constructor
on the JVM target, because the generated code was invalid and I can't think
    of a generic way to solve it (see added comments in njvmcal.pas)

git-svn-id: branches/jvmbackend@19055 -
2011-09-12 18:08:46 +00:00
Jonas Maebe
125c0cf225 + support for generics on the JVM target:
o don't try to create .class files for generic types
   o still generate all JVM-specific wrappers for generic types even though they
     won't be written out, because when specializing all the defid's have to
     match exactly
   o add synthetic routine implementations after generating the specializations,
     so that the synthetic routines for those specializations are also generated
     (we don't specialize generic versions of the synthetic generic routines
      because it's not easy or even always possible to create valid generic
      versions of synthetic routines)
   o Note: these are Pascal-style generics, not Java-style generics. The generic
     types nor their specializations are usable from Java code (specializations
     may become usable in the future)

git-svn-id: branches/jvmbackend@19047 -
2011-09-11 11:54:37 +00:00
Jonas Maebe
c9ebd433db * fixed array indexing via LOC_JUMP on the JVM target
git-svn-id: branches/jvmbackend@18981 -
2011-09-05 17:41:40 +00:00
Jonas Maebe
1a7c024ad3 * sign extend all byte/ansichar/word parameters before passing them
to and returning them from sub routines, in order to follow the JVM
    specs to the letter (not checked by the JVM bytecode verifiers, but
    checked by the Android DEX verifier)
  * -> also zero-extend them again at the caller side after returning
    from such a function

git-svn-id: branches/jvmbackend@18919 -
2011-08-30 23:34:12 +00:00
Jonas Maebe
f21b34c954 * also resize the value on the stack in a_load_reg_ref() when
required based on the source/destination sizes (like in
    a_load_reg_reg(), a_load_ref_reg() and a_load_ref_ref())

git-svn-id: branches/jvmbackend@18918 -
2011-08-30 23:34:07 +00:00
Jonas Maebe
0e80844e33 * also zero-extend incoming byte/word const-parameters (instead of only
value parameters)
  * fixed upper bound check to determine whether zero-extending is required

git-svn-id: branches/jvmbackend@18917 -
2011-08-30 23:34:02 +00:00
Jonas Maebe
a4cf406189 * use generic string concatentation and comparison infrastructure for the
JVM target (and also the generic routines in case of shortstrings)

git-svn-id: branches/jvmbackend@18910 -
2011-08-29 22:59:25 +00:00
Jonas Maebe
6a7ff1cf75 * use temp-reference nodes rather than addrnodes to create references to
complex parameters passed to inlined routines on the JVM target, because
    it is not possible to take the address of any kind of node on the JVM
    target (temp-reference nodes work for any kind of LOC_(C)REFERENCE, but
    are currently only implemented for the JVM platform)

git-svn-id: branches/jvmbackend@18905 -
2011-08-29 22:58:55 +00:00
Jonas Maebe
7117264f96 * fixed assigning ansi/unicodestrings to shortstrings on the JVM target
(and cleaned up implementing support for special x_to_shortstring
     assignments in the process)

git-svn-id: branches/jvmbackend@18877 -
2011-08-28 19:21:46 +00:00
Jonas Maebe
3bf71d8d04 * fixed unsigned comparisons after r18734 (comparison operator is now
used to determine the signedness of the comparison, not the types
    of the arguments)

git-svn-id: branches/jvmbackend@18833 -
2011-08-24 22:11:22 +00:00
Jonas Maebe
eb268fb2c4 + tcallnode.createinternmethodres() that allows specifying a forced
resultdef for internally generated method calls
  * force the resulttype of methods used to build non-unicode string
    constants on the JVM platform to the stringconstn's resultdef

git-svn-id: branches/jvmbackend@18832 -
2011-08-24 22:11:16 +00:00
Jonas Maebe
bb593346a9 * fixed typecasts between widechars and non-widechars in case an array
element is involved

git-svn-id: branches/jvmbackend@18831 -
2011-08-24 22:11:05 +00:00
Jonas Maebe
f40c893084 * when determining whether taking the address of an array element is
valid, check for the array's actual lower bound instead of always for
    zero

git-svn-id: branches/jvmbackend@18822 -
2011-08-23 20:39:17 +00:00
Jonas Maebe
a2a0436347 + support for threadvars in the JVM based on JLThreadLocal; see
rtl/java/jtvarh.inc for the details

git-svn-id: branches/jvmbackend@18820 -
2011-08-23 17:45:01 +00:00
Jonas Maebe
992cc352c6 * generalized handling of pointers to non-implicit pointer types:
as far as Java is concerned, they're now all arrays of JLObject.
    When loading a value from them, we typecast the loaded value
    to the appropriate type. This allows typecasting one pointer
    type to another without getting verification errors (since an
    "array of JLObject" is not compatible with "array of JLString")
  - no longer allow dereferencing untyped pointers on the JVM
    target, since that always results in invalid bytecode

git-svn-id: branches/jvmbackend@18819 -
2011-08-23 17:44:55 +00:00
Jonas Maebe
0364b7acf9 * also allow taking the address of the first element of an array in
case of non-implicit pointer types

git-svn-id: branches/jvmbackend@18818 -
2011-08-23 17:44:49 +00:00
Jonas Maebe
d063ae10cb * use correct location.size after dereferencing pointers to non-implicit
pointer types instead of hardcoded OS_ADDR

git-svn-id: branches/jvmbackend@18817 -
2011-08-23 16:07:19 +00:00
Jonas Maebe
7010116096 * if a mangledbasename is set for staticvarsyms, also use if when emitting
definitions

git-svn-id: branches/jvmbackend@18814 -
2011-08-23 15:26:06 +00:00
Jonas Maebe
54f9947406 * no need to zero-extend after a load of a widechar
git-svn-id: branches/jvmbackend@18813 -
2011-08-23 15:26:01 +00:00
Jonas Maebe
3a5b3a0cce * don't crash after invalid JVM class definitions while trying to add
a default constructor

git-svn-id: branches/jvmbackend@18807 -
2011-08-23 15:25:11 +00:00
Jonas Maebe
5c832ecbd1 * moved jvm-specific compiler units to the jvm subdirectory
git-svn-id: branches/jvmbackend@18782 -
2011-08-20 08:35:58 +00:00
Jonas Maebe
28c20cfc5e * the default string type for the JVM target is no longer automatically
unicodestring = java.lang.String. The reason this was the default in
    the past is that this was the first string type that was implemented,
    and without it being the default most code involving string operations
    would fail. Now the default strings types are the same as for other
    targets
  + new {$modeswitch unicodestrings} directive, that when activated
    *together* with {$h+},
   1) changes char into an alias for widechar
   2) changes string into an alias for unicodestring
   3) changes the preferred string evaluation type (in case of uncertainty)
      to unicodestring
    {$modeswitch unicodestrings} with {$h-} does not change anything at all
    regarding the string type (it still changes the char type)
  + new uuchar unit that redefines char as widechar, and which is automatically
    included by the compiler if {$modeswitch unicodestrings} is enabled

git-svn-id: branches/jvmbackend@18781 -
2011-08-20 08:35:47 +00:00
Jonas Maebe
c4ffef0a40 * fixed initializing arrays of ansi/unicodestring and of open arrays
removing the array initialization from tgcpu

git-svn-id: branches/jvmbackend@18780 -
2011-08-20 08:35:30 +00:00
Jonas Maebe
67c2c7c166 * renamed cchartype to cansichartype
git-svn-id: branches/jvmbackend@18779 -
2011-08-20 08:35:24 +00:00
Jonas Maebe
26ee54b1a2 * fixed compilation with 2.4.4
git-svn-id: branches/jvmbackend@18778 -
2011-08-20 08:35:19 +00:00
Jonas Maebe
2428ea65c1 * replaced the old hack for non-formal var/out/constref support with
a generalized version of the formal var/out/constref support (this
    also fixes passing string[xyz] expressions to non-formal var/out/constref
    parameters)

git-svn-id: branches/jvmbackend@18774 -
2011-08-20 08:34:46 +00:00
Jonas Maebe
ee77d5a6f2 * some changes to handleformalcopyoutpara() so that in the future it can
also handle non-formal parameters
  * do not copy in the original value in handleformalcopyoutpara() if it's
    an out parameter

git-svn-id: branches/jvmbackend@18772 -
2011-08-20 08:34:36 +00:00
Jonas Maebe
d7cff1cd31 * give an error when trying to typecast a unicodestring into a pwidechar
on the JVM target (we can't access the characters of a JLString as an
    array)

git-svn-id: branches/jvmbackend@18769 -
2011-08-20 08:34:21 +00:00
Jonas Maebe
224aae8993 + support for typecasting ansistrings into pchars on the JVM platform
+ support for indexing pointers as arrays on the JVM platform (with
    JVM-provided range checking, obviously)

git-svn-id: branches/jvmbackend@18768 -
2011-08-20 08:34:16 +00:00
Jonas Maebe
27731e342c + support for array-of-const on the JVM target. Even though the
implementation is a bit different from that on native targets, the
    result is quite compatible

git-svn-id: branches/jvmbackend@18765 -
2011-08-20 08:34:00 +00:00
Jonas Maebe
d0e8cd1637 + support for dereferencing any kind of pointer type
git-svn-id: branches/jvmbackend@18763 -
2011-08-20 08:33:49 +00:00
Jonas Maebe
1a0913c462 * fixed proc_to_procvar() type conversion in case the target procvar
type was generated on-the-fly rather than specified to the
    type conversion node

git-svn-id: branches/jvmbackend@18762 -
2011-08-20 08:33:45 +00:00
Jonas Maebe
687e9fb6dc * fixed fully qualified class names passed to JLClass.forName()
(components must be separated by '.', not '/')

git-svn-id: branches/jvmbackend@18761 -
2011-08-20 08:33:40 +00:00
Jonas Maebe
dd32efa9ff + cstring_to_pchar type conversion support
* fixed AnsiCharArrayClass.CreateFromLiteralStringBytes() declaration
    (no maxlength parameter)

git-svn-id: branches/jvmbackend@18760 -
2011-08-20 08:33:35 +00:00
Jonas Maebe
4647aa3f15 * don't copy back constref parameter values after the call
git-svn-id: branches/jvmbackend@18759 -
2011-08-20 08:33:30 +00:00
Jonas Maebe
76de70e683 * since enums are represented by classes in the JVM, initialize global
variables, class/record fields and arrays with enumtype(0) on
    creation, so that using them without explicitly initializing them
    doesn't cause a null-pointer exception. If enumtype(0) is not a
    valid enum, they are not initialized (and since they wouldn't have
    a valid value on native targets either in that case, an exception
    on use is acceptable)

git-svn-id: branches/jvmbackend@18755 -
2011-08-20 08:33:02 +00:00
Jonas Maebe
d33f71460f * don't initialize static arrays of records twice (g_newarray already
initializes them)

git-svn-id: branches/jvmbackend@18753 -
2011-08-20 08:32:52 +00:00
Jonas Maebe
da5bd3b0bd * use invokespecial for "strict private" (= Java "private") rather than for
plain "private" (~ Java "package") methods

git-svn-id: branches/jvmbackend@18750 -
2011-08-20 08:32:37 +00:00
Jonas Maebe
7f22a2f223 + support for range checking calculations with hlcgobj
* added runerror number to JVM FpcRunTimeError exceptions
  * enabled calling errorproc when a run time error occurs on the
    JVM target

git-svn-id: branches/jvmbackend@18749 -
2011-08-20 08:32:31 +00:00
Jonas Maebe
f4690f90ad * keep maximum used evaluation stack size up-to-date when putting a
default return value on the stack for fpu routines

git-svn-id: branches/jvmbackend@18744 -
2011-08-20 08:31:53 +00:00
Jonas Maebe
fe82e2481b + import java.lang.Math in the system unit
+ include mathh.inc in the system unit, implement most routines based
    on java.lang.Math, and use (an unmodified!) genmath for the rest
  - removed now obsolete jmathh.inc (was partial copy of mathh.inc)
  - removed commented out overrides for several math routines in
    njvminl (doesn't make sense to handle them inline in the compiler)

git-svn-id: branches/jvmbackend@18742 -
2011-08-20 08:31:24 +00:00
Jonas Maebe
af489b99de * fixed handling of currency in int_to_int conversions
git-svn-id: branches/jvmbackend@18741 -
2011-08-20 08:31:12 +00:00
Jonas Maebe
72c81d9eb1 * always create a new call node when replacing virtual class method calls
with wrapper calls, because the parameter nodes are already bound to the
    paravarsyms of the current procdef so simply replacing the procsym and
    procdef is not enough

git-svn-id: branches/jvmbackend@18739 -
2011-08-20 08:30:38 +00:00
Jonas Maebe
c2f2a8c900 * make sure that the expression representing the ansi/unicodestring argument
to length is never evaluated more than once

git-svn-id: branches/jvmbackend@18736 -
2011-08-20 08:30:02 +00:00
Jonas Maebe
707b41b159 + allocate space of local typed consts that are implicit pointer types
in the enclosing class/unit init code

git-svn-id: branches/jvmbackend@18735 -
2011-08-20 08:29:47 +00:00
Jonas Maebe
9253d990d9 * use the signedness of the comparison operation rather than of the
types involved to determine whether or not the comparison is
    unsigned (they don't always match due to bugs in the compiler,
    and the sign of the comparison operation is what's used in
    other code generators too)

git-svn-id: branches/jvmbackend@18734 -
2011-08-20 08:29:36 +00:00
Jonas Maebe
8fcc8f92ca * allow taking the address of var-parameters in normal Pascal code (not just
via internal njvmaddrnodes), because we need it for procvar dispatching

git-svn-id: branches/jvmbackend@18732 -
2011-08-20 08:29:11 +00:00
Jonas Maebe
b3072b3dab * extracted the code to deal with static fields into a routine
(make_field_static() ) and replaced semi-duplicates of that
    code with calls to this routine
  * made the handling of static fields for the JVM target more
    similar to that on the other targets, so that class properties
    now also work there (-> updated JVM-specific code in several
    places to deal with this new handling)

git-svn-id: branches/jvmbackend@18723 -
2011-08-20 08:27:48 +00:00
Jonas Maebe
7419c97e0a * do not call the virtual class method/constructor dispatching lookup
when calling the inherited version, since that one is also known at
    compile time

git-svn-id: branches/jvmbackend@18712 -
2011-08-20 08:26:52 +00:00
Jonas Maebe
1d0388d40a + support for virtual constructors for the JVM platform. We simply
create a virtual class (factory) method that calls the constructor,
    and then let the existing support for virtual class methods handle
    everything

git-svn-id: branches/jvmbackend@18710 -
2011-08-20 08:26:40 +00:00
Jonas Maebe
2a9043f4bc * keep the node flags when replacing a call to a virtual class method with
a call to its wrapper

git-svn-id: branches/jvmbackend@18708 -
2011-08-20 08:26:30 +00:00
Jonas Maebe
7d8cbe80f5 + support for virtual class methods on the JVM platform. The JVM does not
support those natively, so they are emulated via the procvar infrastructure
    (and hence not very fast). Could probably be optimized somewhat by adding
    a cache (hashmap of procvars) to the class hierarchies, maybe in the
    future.

git-svn-id: branches/jvmbackend@18704 -
2011-08-20 08:26:11 +00:00
Jonas Maebe
cd6b8b9dd1 * correctly create procvars for procdefs that have an import_name set
git-svn-id: branches/jvmbackend@18703 -
2011-08-20 08:26:05 +00:00
Jonas Maebe
249b56d742 * fixed calling non-static class methods via procvars: since we can't known
on the caller side whether it's a normal or class method that we are
    calling, add the self-class parameter inside the invoke method if
    necessary (by simply counting the number of parameters and inserting
    it if we're one short)

git-svn-id: branches/jvmbackend@18699 -
2011-08-20 08:25:44 +00:00
Jonas Maebe
d8977b0342 - disabled the set constant caching via static variables for now because
their initialization can cause races between the unit they are declared
    in and the class constructor they are initialized in (even if both
    would be moved to the unit initialization code, a class constructor
    using the set constant could run before the unit initialization code has
    run)

git-svn-id: branches/jvmbackend@18698 -
2011-08-20 08:25:39 +00:00
Jonas Maebe
c8c75d7e1d * convert non-constant enums in in-expressions to longint if we use the
generic jumps code

git-svn-id: branches/jvmbackend@18697 -
2011-08-20 08:25:33 +00:00
Jonas Maebe
4557938e62 - removed no longer needed/used {$ifndef nounsupported} code
git-svn-id: branches/jvmbackend@18692 -
2011-08-20 08:25:08 +00:00
Jonas Maebe
979f55e1db + support for procedural variables for the JVM target
o every porocedural variable type is represented by a class with one
     public "invoke" method whose signature matches the signature of the
     procvar
   o internally, dispatching happens via java.lang.reflect.Method.invoke().
     WARNING: while this allows calling private/protected or other methods
     that are normally not accessible from another context, a security
     manger can override this. If such a security manager is installed,
     most procvars will cause security exceptions
   o such dispatching also requires that all arguments are wrapped, but
     that's done in the compiler-generated body of the invoke method,
     so that procvars can also be called conveniently from Java code
   o typecasting between a procedure of object and tmethod is supported,
     as well as Delphi-style replacing of only the method pointer via
     @procvar1=@procvar2.
   o nested procvars are not yet supported, but most of the basic
     infrastructure for them is already present
  * all units/programs now get an internal __FPC_JVM_Module_Class_Alias$
    type when compiled for the JVM target, which is an "external" class
    that maps to the unit name. This is required to look up the
    JLRMethod instances for regular functions/procedures
  + new tabstractprocdef.copyas() method that allows to create a procvar
    from a procdef and vice versa

git-svn-id: branches/jvmbackend@18690 -
2011-08-20 08:24:58 +00:00
Jonas Maebe
834f8da885 + added extra parameter to jvmgetboxtype() to indicate whether all integer
types should be mapped onto jllong or rather onto the closes matching type

git-svn-id: branches/jvmbackend@18685 -
2011-08-20 08:24:29 +00:00
Jonas Maebe
61fd6ca4ee * zero-extend small unsigned integer parameters on function *entry*, because
the functions may be called from Java code or indirectly and in that case
    there's no way to guarantee that they'll be zero-extended on the caller
    side

git-svn-id: branches/jvmbackend@18684 -
2011-08-20 08:24:24 +00:00
Jonas Maebe
cef61300ff + ttgobj.gethltemptyped() routine for allocating managed types with high level
code generator support
  * refactored some internal temp generator code

git-svn-id: branches/jvmbackend@18681 -
2011-08-20 08:24:07 +00:00
Jonas Maebe
085d0efead * some fixes for fake procvar support
git-svn-id: branches/jvmbackend@18680 -
2011-08-20 08:24:02 +00:00
Jonas Maebe
d6966e545b + support for formal var/out parameters on the JVM target:
o primitive types are first boxed
   o the parameter is passed inside an array of one class instance
   o changing the parameter inside the routine (by assigning a value to it
     like in Delphi.NET and different from regular Pascal code) will replace
     this class instance (again boxing the value if required)
   o on return, the class instance is extracted, unboxed if required, and
     assigned back to the original location
   o formal const parameters are handled without the extra array indirection,
     since they cannot be changed

  TODO: while writing tjvmcallparanode.handleformalcopyoutpara() I forgot that
    calling getcopy on ttemprefnodes whose ttempcreatenode hasn't been copied
    yet works fine, so that code is more complex than needed. Still have to
    fix.

git-svn-id: branches/jvmbackend@18675 -
2011-08-20 08:23:33 +00:00
Jonas Maebe
5bf16214cd * changed initialization of records from constructing a new instance and
copying that over the old one into calling a dedicated fpcInitializeRec()
    method that initializes the required fields. The reason is that this
    initialization is performed for out-parameters, and the fpcDeepCopy()
    method (used to copy one instance over another) has an out-parameter
    -> infinite loop

git-svn-id: branches/jvmbackend@18674 -
2011-08-20 08:23:27 +00:00
Jonas Maebe
40cf2cefa0 * when the user calls initialize(), force initialization to happen on the
JVM platform (normally it's not necessary because all types are
    automatically initialized)

git-svn-id: branches/jvmbackend@18672 -
2011-08-20 08:23:16 +00:00
Jonas Maebe
d0663411a5 * fixed order of operands on the jvm stack in case of a setlength(x,0) call
for a static field

git-svn-id: branches/jvmbackend@18671 -
2011-08-20 08:23:10 +00:00
Jonas Maebe
7286e3b645 * when determining the type to use for checkcast, first always dereference
pointers to implicit pointer types so that afterwards we can set the
    appropriate corresponding class type

git-svn-id: branches/jvmbackend@18668 -
2011-08-20 08:22:52 +00:00
Jonas Maebe
6cced31157 * treat conversions involving arrays of sets also as pointer conversions
git-svn-id: branches/jvmbackend@18667 -
2011-08-20 08:22:47 +00:00
Jonas Maebe
94be1980b4 * fixed type conversions between signed and unsigned ordinals of the same
size when stored in memory

git-svn-id: branches/jvmbackend@18666 -
2011-08-20 08:22:42 +00:00
Jonas Maebe
37aa2d8443 + full support for sets on the JVM target
o sets of enums are handled as JUEnumSet instances, others as JUBitSet
     derivatives (both smallsets and varsets, to make interoperability with
     Java easier)
   o special handling of set constants: these have to be constructed at run
     time. In case of constants in the code, create an internal constsym to
     represent them. These and regular constsyms are then aliased by an
     another internal staticvarsym that is used to initialise them in the
     unit initialisation code.
   o until they are constructed at run time, set constants are encoded as
     constant Java strings (with the characters containing the set bits)
   o hlcgobj conversion of tcginnode.pass_generate_code() for the genjumps
     part (that's the only part of the generic code that's used by the JVM
     target)
   o as far as explicit typecasting support is concerned, currently the
     following ones are supported (both from/to setdefs): ordinal types,
     enums, any other set types (whose size is the same on native targets)
   o enum setdefs also emit signatures
   o overloading routines for different ordinal set types, or for different
     enum set types, is not supported on the JVM target

git-svn-id: branches/jvmbackend@18662 -
2011-08-20 08:22:22 +00:00
Jonas Maebe
67a142c56e * fixed dereferencing pointers to JVM implicit pointer types in case the
pointer was in a register (has to be put into memory, because otherwise
    the compiler thinks that the entire type is stored in a register instead
    of only its address)

git-svn-id: branches/jvmbackend@18659 -
2011-08-20 08:22:05 +00:00
Jonas Maebe
956d63da9e * only treat Java interfaces and classes as equivalent to classdefs rather
than any objectdef

git-svn-id: branches/jvmbackend@18656 -
2011-08-20 08:21:49 +00:00
Jonas Maebe
625f52b7e4 * make sure that int->int conversions are handled by the generic code
* handle class->interface conversions by JVM-specific code

git-svn-id: branches/jvmbackend@18655 -
2011-08-20 08:21:44 +00:00
Jonas Maebe
67ce687683 * don't keep the original location in case of 2->4 byte ordinal type
conversions because the sign may not be correct in case the value comes
    from Java code

git-svn-id: branches/jvmbackend@18654 -
2011-08-20 08:21:39 +00:00
Jonas Maebe
40fdc62e74 + support for automatically converting char/widechar to java.lang.String
git-svn-id: branches/jvmbackend@18653 -
2011-08-20 08:21:34 +00:00
Jonas Maebe
5ad5a6f326 * small optimization for g_getarraylen
git-svn-id: branches/jvmbackend@18648 -
2011-08-20 08:21:10 +00:00
Jonas Maebe
cfe125198c * always return true from tjvmnodeutils.force_init(), because when this
routine is called we don't know yet whether it has to be forced or not
    for the JVM target (staticvarsyms that need initialization may still be
    created during pass1 of the main program/unit code)

git-svn-id: branches/jvmbackend@18646 -
2011-08-20 08:21:01 +00:00
Jonas Maebe
2376003cd0 * wrap the init/finalization code even when it is implicitly generated
* only wrap the init/finalization code after the main program has been
    completely processed (pass1, codegen), because this may influence
    the required wrapping in case of the JVM target
  * replace periods with slashes in the package name when constructing
    the classes corresponding to the units (to execute their initialization
    code) -- didn't notice this was wrong previously because due to the
    incomplete wrapping, they were never being initialized until now

git-svn-id: branches/jvmbackend@18645 -
2011-08-20 08:20:56 +00:00
Jonas Maebe
bc21708967 * again use areturn instead of ireturn for returning enums since they're
classes now

git-svn-id: branches/jvmbackend@18631 -
2011-08-20 08:16:52 +00:00
Jonas Maebe
460c7a519b * also handle tc_int_2_int,tc_int_2_bool,tc_bool_2_int in
target_specific_general_typeconv() for enum type conversions

git-svn-id: branches/jvmbackend@18628 -
2011-08-20 08:16:37 +00:00
Jonas Maebe
6f2b7ca830 * never use the target_specific_explicit_typeconv() code for non-tc_equal
type conversions (those are/can be intercepted in the specific handlers)

git-svn-id: branches/jvmbackend@18623 -
2011-08-20 08:16:09 +00:00
Jonas Maebe
325b5cae6b * fixed int_to_int conversion for larger->smaller types in mem locations
(cannot reuse the memory location on the JVM)
  * optimized int_to_int conversions for certain smaller->larger types
    in mem locations (can reuse the memory location on the JVM, because
    stack locations are always at least 4 bytes)

git-svn-id: branches/jvmbackend@18622 -
2011-08-20 08:16:04 +00:00
Jonas Maebe
bf2854dae5 * when internally taking the address of shortstrings to typecast
them to shortstringclass, make sure the address operator is
    "typed" so that we don't insert useless checkcast instructions

git-svn-id: branches/jvmbackend@18621 -
2011-08-20 08:15:59 +00:00
Jonas Maebe
569228447d * converted all enum handling for the JVM target so that it uses the
JDK class-style enums rather than plain ordinals like in Pascal
   o for Pascal code, nothing changes, except that for the JVM target
     you can always typecast any enum into a class instance (to interface
     with the JDK)
   o to Java programs, FPC enums look exactly like Java enum types

git-svn-id: branches/jvmbackend@18620 -
2011-08-20 08:15:54 +00:00
Jonas Maebe
d64f5d14d6 * fixed compilation with -dnounsupported
git-svn-id: branches/jvmbackend@18619 -
2011-08-20 08:15:48 +00:00
Jonas Maebe
b0d777e16b * keep dynamic array -> open array type conversion nodes for the JVM target,
so that the result type of random dynamic array expressions doesn't suddenly
    get changed into open array (causes internalerror if the size is requested),
    and instead simply change the conversion type to tc_equal

git-svn-id: branches/jvmbackend@18605 -
2011-08-20 08:14:30 +00:00
Jonas Maebe
887248af2d * support var/out managed types on the callee side in location_get_data_ref()
git-svn-id: branches/jvmbackend@18604 -
2011-08-20 08:14:26 +00:00
Jonas Maebe
7e6261ff55 * fixed return opcode for enums and smallsets
git-svn-id: branches/jvmbackend@18603 -
2011-08-20 08:14:21 +00:00
Jonas Maebe
f3f378496f * fixed memory leaks
git-svn-id: branches/jvmbackend@18598 -
2011-08-20 08:13:55 +00:00
Jonas Maebe
ce88df680b + symansistr conditional define that, when activated, makes the symbol/
mangled name handling ansistring rather than pshortstring based (required
    for JVM target; little effect on speed, some extra memory usage)

git-svn-id: branches/jvmbackend@18597 -
2011-08-20 08:13:50 +00:00
Jonas Maebe
d0a3b49e6c * fixed memory leak
git-svn-id: branches/jvmbackend@18595 -
2011-08-20 08:13:36 +00:00
Jonas Maebe
7cf06b9aa6 * fixed accessing var-parameters from nested routines
o support for JVM arrays in JVM addrnodes and derefnodes (so we
     can take the address of var parameters to store them in the
     parentfpstruct and later dereference them)
   o process loadnode.left also in tjvmloadnode.pass_generate_code() when
     handling var-parameters

git-svn-id: branches/jvmbackend@18593 -
2011-08-20 08:13:27 +00:00
Jonas Maebe
23e4405c78 * copyout parameters also have to return "true" for is_addr_param_load()
git-svn-id: branches/jvmbackend@18592 -
2011-08-20 08:13:21 +00:00
Jonas Maebe
4be0ba267a * moved creating block/statement for reference temps into
maybereplacewithtempref() helper

git-svn-id: branches/jvmbackend@18591 -
2011-08-20 08:13:16 +00:00
Jonas Maebe
8fa42c206f + support for nested procedures for the JVM target
o since the JVM target has no stack/framepointer that can be passed
     on to nested routines, all local variables and parameters accessed
     from nested routines are grouped into a local record whose address
     is passed to nested routines. The same technique is also required
     for LLVM in the future

git-svn-id: branches/jvmbackend@18588 -
2011-08-20 08:12:59 +00:00
Jonas Maebe
0fad10179c * fixed some voidpointerdef handling
git-svn-id: branches/jvmbackend@18584 -
2011-08-20 08:12:39 +00:00
Jonas Maebe
528882dc68 * allow typeconversions of formaldef to anything else (make sure to
transform into an as-node when converting into a class/array type)

git-svn-id: branches/jvmbackend@18580 -
2011-08-20 08:12:20 +00:00
Jonas Maebe
c995e56370 * internalerror if constructor not found in record
git-svn-id: branches/jvmbackend@18579 -
2011-08-20 08:12:15 +00:00
Jonas Maebe
8ec21eb426 * fixed flow control handling in case of empty try-blocks and in case of
no default exception catching block

git-svn-id: branches/jvmbackend@18576 -
2011-08-20 08:11:59 +00:00
Jonas Maebe
0706cb5eb6 + support for pointers to types that are implicit pointer types in the JVM
(non-dynamic arrays, records, shortstrings)
  - removed the ability to typecast such types directly into related class
    types, you have to use the @-operator first now to get a pointer to
    the type
   o updated the RTL and internal compiler code to properly use this
     new convention
   o allowed removing several special cases from
     tjvmtypeconvnode.target_specific_general_typeconv(), and that
     method can probably be removed completely over time
  * no longer give compile time errors for pointer-related typecasts that
    will fail at run time, because the checking was too complex and could
    be worked around via actual pointer typecasts anyway
  * removed some unnecessary checkcast operations (for shortstring/
    shortstringclass)

git-svn-id: branches/jvmbackend@18574 -
2011-08-20 08:11:49 +00:00
Jonas Maebe
207a4a32d3 * internalerror in case a stringdef manages to get through to
tjvmvecnode.pass_generate_code() (should be handled earlier)

git-svn-id: branches/jvmbackend@18573 -
2011-08-20 08:11:43 +00:00
Jonas Maebe
6857dde33e + shortstring support for the JVM target (including accessing character 0 as
the "length byte")

git-svn-id: branches/jvmbackend@18570 -
2011-08-20 08:11:28 +00:00
Jonas Maebe
eb40756d35 * zero-extend byte/word field loads (get/putstatic sign-extends)
* move the incstack() from a load before the potential "and" to
    zero-extend, so that the maximum stack height get calculated
    properly

git-svn-id: branches/jvmbackend@18565 -
2011-08-20 08:11:03 +00:00
Jonas Maebe
6374b473ff * convert string constants passed to JLString to unicode
git-svn-id: branches/jvmbackend@18563 -
2011-08-20 08:10:46 +00:00