Commit Graph

86 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
5ad5a6f326 * small optimization for g_getarraylen
git-svn-id: branches/jvmbackend@18648 -
2011-08-20 08:21:10 +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
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
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
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
0fad10179c * fixed some voidpointerdef handling
git-svn-id: branches/jvmbackend@18584 -
2011-08-20 08:12:39 +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
446d91eaab + ansistring support. Items of note:
o support for ansistring constants. It's done via a detour because the
      JVM only supports UTF-16 string constants (no array of byte or anything
      like that): store every ansicharacter in the lower 8 bits of an
      UTF-16 constant string, and at run time copy the characters to an
      ansistring. The alternative is to generate code that stores every
      character separately to an array.
    o the base ansistring support is implemented in a class called
      AnsistringClass, and an ansistring is simply an instance of this
      class under the hood
    o the compiler currently does generate nil pointers as empty
      ansistrings unlike for unicodestrings, where we always
      explicitly generate an empty string. The reason is that
      unicodestrings are the same as JLString and hence common
      for Java interoperation, while ansistrings are unlikely to
      be used in interaction with external Java code

  * fixed indentation

git-svn-id: branches/jvmbackend@18562 -
2011-08-20 08:10:39 +00:00
Jonas Maebe
84640fe7f0 + support for non-static class methods on the JVM target
git-svn-id: branches/jvmbackend@18557 -
2011-08-20 08:10:11 +00:00