Commit Graph

38 Commits

Author SHA1 Message Date
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
Jonas Maebe
e8ec2c45af * fixed invokeinterface usage: must also specify the number of stack
slots used by the call

git-svn-id: branches/jvmbackend@18528 -
2011-08-20 08:07:30 +00:00
Jonas Maebe
be1ff9ff92 * fixed handling of OP_SHL,OP_SHR,OP_SAR in op_ref_stack (second operand
is always a 32 bit int)

git-svn-id: branches/jvmbackend@18522 -
2011-08-20 08:06:57 +00:00
Jonas Maebe
f764a72d85 * fixed evaluation stack height count for OP_NEG and non-64 bit opertions
git-svn-id: branches/jvmbackend@18511 -
2011-08-20 08:06:00 +00:00
Jonas Maebe
739c654e3a + support for main programs for the JVM target
o moved several routines from pmodules to ngenutil and overrode them
     in njvmutil (for unit initialisation tables, resource strings, ...)
   o force the evaluation stack size to at least 1 for the main program,
     because the unit initialisation triggers are inserted there afterwards
     and they require one stack slot

git-svn-id: branches/jvmbackend@18507 -
2011-08-20 08:05:38 +00:00
Jonas Maebe
e775e2d9ae * moved gen_entry_code/gen_exit_code from ncgutil to hlcgobj,
and overrode both with empty stubs for the JVM

git-svn-id: branches/jvmbackend@18506 -
2011-08-20 08:05:33 +00:00
Jonas Maebe
f20e347c7e * dummy support for copying arrays of variant/set
git-svn-id: branches/jvmbackend@18505 -
2011-08-20 08:05:28 +00:00
Jonas Maebe
ecba07c6a8 * greatly simplified dynamic array handling by making use of the
java.lang.reflect functionality

git-svn-id: branches/jvmbackend@18503 -
2011-08-20 08:05:17 +00:00
Jonas Maebe
a729201e37 * map normal sets to R_ADDRESSREGISTER
git-svn-id: branches/jvmbackend@18496 -
2011-08-20 08:04:40 +00:00
Jonas Maebe
5b915178fa + support for deep copy of array of strings
git-svn-id: branches/jvmbackend@18477 -
2011-08-20 08:03:09 +00:00
Jonas Maebe
e663f0f31f + support for class constructors for the JVM target
o initialise class vars that need initialisations (records, arrays) in
     class constructors
   o treat class constructors as having a "void" resultdef rather than the
     class type for JVM (maybe has to be done in general?)
   o make it possible to specify pno_noleadingdollar to
     tprocdef.customprocname() so it can be used for class constructors
     (their name is lower cased because it mustn't conflict with other
      identifiers, since their name doesn't matter anyway)
   o added tsk_empty synthetic procdef kind which, as the name implies,
     generates an empty body (for class generated constructors)
  + auto-generate class constructors in case a class has class vars that
    need initialisation

git-svn-id: branches/jvmbackend@18462 -
2011-08-20 08:01:51 +00:00
Jonas Maebe
c264c24fb0 + support for unit initialisation sections for the JVM target,
and initialise global variables that are wrapped (records, arrays)
    in those sections
   o check whether pd.localst is assigned in dbgjasm, because it's
     not for the unit initialisation routine
   o moved insertbssdata() from ncgutil to ngenutil and override it
     njvmutil (it does nothing in the latter, since global variables
     are added as fields to the class representing the unit; the
     initialisation is done in gen_initialize_code() in thlcgjvm)
   o added force_init() and force_final() methods to ngenutil, so
     that targets can force init/final routines separate from the
     regular managed types infrastructure (used by JVM for forcing
     an init section in case of records/arrays)

git-svn-id: branches/jvmbackend@18460 -
2011-08-20 08:01:39 +00:00
Jonas Maebe
cc6a303ee2 * allocate/initialize implicit pointer type fields (arrays, records) in
JVM classes after calling the inherited constructor (before doing
    so, self is not yet valid)

git-svn-id: branches/jvmbackend@18456 -
2011-08-20 08:01:24 +00:00
Jonas Maebe
89e70f347c * do nothing for initialising temps in advance for the JVM target as that
happens automatically when required (for constructing arrays/records;
    reference counted types don't need special treatment since everything
    is garbage collected)

git-svn-id: branches/jvmbackend@18453 -
2011-08-20 08:01:10 +00:00
Jonas Maebe
40e0b4677a + support for (only named, for now) records in the JVM target:
implemented via classes, all descending from system.FpcBaseRecordType
    (records are also considered to be "related" to system.FpcBaseRecordType
     on the JVM target)
  * several routines are auto-generated for all record-classes: apart
    from a default constructor (if there is none), also clone (which
    returns a new instance containing a deep copy of the current
    instance) and deepCopy (which copies all fields of one instance
    into another one)
   o added new field "synthetickind" to tprocdef that indicates what
     kind of synthetically generated method it is (if any), and
     mark such methods also as "synthetic" in the JVM assembler code
   o split off the JVM-specific parser code (e.g., to add default
     constructors) into pjvm.pas

git-svn-id: branches/jvmbackend@18450 -
2011-08-20 08:00:50 +00:00
Jonas Maebe
88df6573a0 * moved de2regtyp() from defutil to hlcgobj, so it can be overridden
(and override for the JVM, making the register type for records
     R_ADDRESSREGISTER instead of R_INTREGISTER there)

git-svn-id: branches/jvmbackend@18448 -
2011-08-20 08:00:31 +00:00
Jonas Maebe
c5b39823e5 + internalerror when passing handling invalid integer size in loadstoreopc()
git-svn-id: branches/jvmbackend@18443 -
2011-08-20 07:59:59 +00:00
Jonas Maebe
5abf6d0aa4 + thlcgobj support of the managed open array initialization fixes of
svn r17068,17071,17081,17136
  * changed all init_paras code in both thlcgobj and ncgutil to use
    location_get_data_ref() instead of direct a_load_loc_reg()/
    ref.base:=reg so it also works with the JVM target
  * changed all init_paras code so it works with targets that do
    not pass an implicit high parameter for open array (and a similar
    fix in ncgcal)
  + added support for initializing array (both regular and open)
    "out" parameters of reference counted types on the JVM target
    (the arrays will be initialised with nil rather than an empty
     array for implementation reasons, see comments in compproc.inc)
  * factored out calling of functions in the system unit directly
    from hlcgobj

git-svn-id: branches/jvmbackend@18421 -
2011-08-20 07:58:14 +00:00
Jonas Maebe
bf0b8503c9 * don't internalerror in decstack() if the evaluation stack becomes corrupted
in case -sr is used (-sr code cannot be compiled, and is only used for
    debugging; with -alr, the stack slot information is printed in the
    assembler file)

git-svn-id: branches/jvmbackend@18410 -
2011-08-20 07:57:22 +00:00
Jonas Maebe
2c313e397e + support for regular arrays and open arrays
o support for copying value parameters at the callee side if they were
     passed by reference in hlcg
   o JVM g_concatcopy() implementation for arrays
   o moved code to get length of an array from njvminl to hlcgcpu so it can
     be reused elsewhere as well
   o export array copy helpers from system unit for use when assigning one
     array to another
   o some generic support for types that are normally not implicit pointers,
     but which are for the JVM target (such as normal arrays)
  * handle assigning nil to a dynamic array by generating a setlength(x,0)
    node instead of by hardcoding a call to fpc_dynarray_clear, so
    target-specific code can handle it if required
  * hook up gethltemp() for JVM ttgjvm so array temps are properly
    allocated

git-svn-id: branches/jvmbackend@18388 -
2011-08-20 07:55:27 +00:00
Jonas Maebe
0a3a62811b + try/except and try/finally support for JVM target:
o always create exceptvarsym entry for on-nodes (on all targets) to remove
     some special cases when an unnamed exception was caught
   o the JVM tryfinally node generates the finally code twice: once for the
     case where no exception occurs, and once when it does occur. The reason
     is that the JVM's static bytecode verification otherwise cannot prove
     that we will only reraise the caught exception when we caught one in
     the first place (the old "jsr" opcode to de-duplicate finally code
     is no longer used in JDK 1.6 because it suffered from the same problem,
     see Sun Java bug
     http://webcache.googleusercontent.com/search?q=cache:ZJFtvxuyhfMJ:bugs.sun.com/bugdatabase/view_bug.do%3Fbug_id%3D6491544 )

git-svn-id: branches/jvmbackend@18387 -
2011-08-20 07:55:21 +00:00
Jonas Maebe
608572c63a * removed unused local variables
* fixed some "uninitialised function result" warnings for dummy routines

git-svn-id: branches/jvmbackend@18381 -
2011-08-20 07:54:37 +00:00
Jonas Maebe
ee8b662fa1 + dynamic array support for the JVM target: setlength(), length(), high():
o since the JVM does not support call-by-reference, setlength() works
     by taking an argument pointing to the old array and one to the new
     array (the latter is always created in advance on the caller side,
     even if not strictly required, because we cannot easily create it
     on the callee side in an efficient way). Then we copy parts of the
     old array to the new array as necessary
   o to represent creating a new dynamic array, the JVM target uses
     an in_new_x tinlinenode
  + tasnode support for the JVM. Special: it can also be used to convert
    java.lang.Object to dynamic arrays, and dynamic arrays of java.lang.Object
    to dynamic arrays with more dimensions (arrays are special JVM objects,
    and such support is required for the setlength support)
  + check whether explicit type conversions are valid, and if so, add the
    necessary conversion code since we cannot simply reinterpret bit patterns
    in most cases in the JVM:
   o in case of class and/or dynamic array types, convert to an as-node
   o in case of int-to-float or float-to-int, use java.lang.Float/Double
     helpers (+ added the definitions of these helpers to the system unit)

git-svn-id: branches/jvmbackend@18378 -
2011-08-20 07:54:17 +00:00
Jonas Maebe
a2a6b2fd1d + "reference" temps that sort of implement pointer-style functionality for
platforms that don't support pointers (by make a copy of all registers
    part of a reference)

git-svn-id: branches/jvmbackend@18377 -
2011-08-20 07:54:10 +00:00
Jonas Maebe
2a6caa539c + support for constant array indices in treference for the JVM target
(art_indexconst)

git-svn-id: branches/jvmbackend@18366 -
2011-08-20 07:52:27 +00:00
Jonas Maebe
5fd205c130 * fixed indentation of thlcgjvm.a_load_loc_stack() implementation
git-svn-id: branches/jvmbackend@18365 -
2011-08-20 07:52:22 +00:00
Jonas Maebe
25f565751a + g_incrrefcount/g_decrrefcount/g_initialize/g_finalize() implementations for
the JVM (only g_initialize does something: set variable to nil)

git-svn-id: branches/jvmbackend@18360 -
2011-08-20 07:51:33 +00:00
Jonas Maebe
e326f46da5 * don't force the constant of a_cmp_const* to be an integer constant,
it can also be null

git-svn-id: branches/jvmbackend@18358 -
2011-08-20 07:51:24 +00:00
Jonas Maebe
9bd753ba7a * don't decrease the evaluation stack counter twice for a_load_*_ref
git-svn-id: branches/jvmbackend@18356 -
2011-08-20 07:51:07 +00:00
Jonas Maebe
71b348757b * reversed expected operand order of tjvmhlcg.a_cmp_*(), because
that's how these operations also work on other architectures
  * fixed tjvmaddnode.second_generic_compare() for this new order

git-svn-id: branches/jvmbackend@18338 -
2011-08-20 07:48:27 +00:00
Jonas Maebe
87925db8fb * fixed 64 bit shl/shr/sar operations: the second argument of the
operation is 32 bit, not 64 bit (both in the compiler and in the
    JVM)
  * request a 64 rather than a 32 bit shift operation from tjvmshlshrnode
    if the result is 64 bit (rather than in case shift value is 64 bit,
    since as described above that never happens)

git-svn-id: branches/jvmbackend@18337 -
2011-08-20 07:48:23 +00:00
Jonas Maebe
e699eb3cc5 + added "list" parameter to thlcgjvm.inc/decstack() methods, and
in case of -ar add to the assembler output the height of the
    evaluation stack every time it's increased or decreased (to
    more easily track missing/wrong inc/decstack() operations)

git-svn-id: branches/jvmbackend@18335 -
2011-08-20 07:48:00 +00:00
Jonas Maebe
dd2862e25a + support for floating point constants
git-svn-id: branches/jvmbackend@18333 -
2011-08-20 07:47:29 +00:00
Jonas Maebe
eb5814a868 * implemented declaring and calling constructors for Java classes
o handle them like for regular classes (return a class instance,
     although this is technically not true since they don't return
     anything; will be changed in the future)
   o because of the previous point, make sure that we handle the
     "function result" properly and don't pop too many values from
     the evaluation stack when calling one constructor from another
   o added "extra_pre_call_code" method used by njvmcal to insert
     the "new" opcode to create the new class instance before
     calling a constructor
   o when a constructor does not call any other constructor (inherited
     or otherwise), automatically insert a call to the inherited
     parameterless constructor as required by the jvm standard)
   TODO: check that *if* an inherited or other constructor is called
     from another constructor, that it does so as the first statement/
     call

git-svn-id: branches/jvmbackend@18328 -
2011-08-20 07:46:37 +00:00
Jonas Maebe
71deda6f50 + added interface to ncgutil.gen_load_loc_cgpara() to hlcgobj + generic
implementation (without loc_©mmregister support)
  * moved ncgutil.gen_load_return_value() to hlcgobj, and factored out
    architecture-specific behaviour to load an uninitialised function result
    into a virtual method (+ JVM-specific implementation of that method),
    gen_load_uninitialized_function_result()
  + added hlcgx86 unit and thlcgx86 type to override the
    thlcgobj.gen_load_uninitialized_function_result() method for x87
    function results; the i386 and x86_64 units now instantiate thlcgx86
    instead of thlcg2ll
  * moved calling of ncgutil.gen_load_loc_cgpara() from ncgcal also to hlcgobj
  -> returning function results works for JVM

git-svn-id: branches/jvmbackend@18317 -
2011-08-20 07:38:16 +00:00
Jonas Maebe
8439e1472e * moved def2regtyp() from jvm/hlcgcpu to defutil, and extended it to
handle vectorfpu (floatdef->MMREG) and softfloat (floatdef->INTREG)
  + thlcg.getregisterfordef(), which uses def2regtyp() to allocate a register
    appropriate to hold values of that tdef type
  + generic thlcg.location_force_reg() implementation. Note that for
    low-level code generator targets it may be slightly less efficient than
    the implementation in hlcg2ll (from ncgutil) because it does not play
    any tricks with the register or location size, or with reference offsets,
    to truncate values

git-svn-id: branches/jvmbackend@18315 -
2011-08-20 07:38:06 +00:00
Jonas Maebe
742f4ee12e + first (partial) implementation of thlcg for the jvm
+ added arrayreftype field to treference for the jvm, because
    array loads have to be performed using special instructions,
    so this information has to be passed on to the code generator.
    This information will have to be added in t(cg)vecnode.
  * moved concatenating the generated code for a procedure to the
    al_procedures list to thlcg.record_generated_code_for_procdef(),
    which is overridden by jvm/hlcgcpu to attach that code to the
    procdef it belongs with. The reason is that a Java class file
    can only contain code for one class, so we have to write out
    the assembler grouped per class instead of in the order the
    routines appear in the source code
  * also committed forgotten changes in psub after moving the
    register allocator initialisation to hlcgobj

git-svn-id: branches/jvmbackend@18308 -
2011-08-20 07:37:26 +00:00