Commit Graph

353 Commits

Author SHA1 Message Date
Jonas Maebe
146e3bcb9e * synchronised with trunk till r29513
git-svn-id: branches/blocks@29516 -
2015-01-21 23:28:34 +00:00
Jonas Maebe
e97f31541e - reverted partial commit of merge
git-svn-id: branches/blocks@29515 -
2015-01-21 23:24:37 +00:00
Jonas Maebe
a76bbf363d * synchronised with trunk r29513
git-svn-id: branches/blocks@29514 -
2015-01-21 23:18:29 +00:00
florian
1178fdc98f * force objects and records only into memory if their address is passed, hint from Jonas, improves code after r29139
git-svn-id: trunk@29344 -
2014-12-27 16:42:34 +00:00
florian
854fa1d4b9 * force advanced records into memory when they are used as self, resolves #26075
git-svn-id: trunk@29139 -
2014-11-23 22:05:40 +00:00
sergei
bb1cec2474 * tcgcallparanode.secondcallparan: factored a complex condition into variable.
* tcgcallnode.pass_generate_code: call reorder_parameters also for procedure variable case, as it is done in two other control branches.

git-svn-id: trunk@28959 -
2014-11-01 15:07:28 +00:00
nickysn
0f9e8f84bb * tcgcallnode.pass_generate_code: pass the correct vmt pointer type parameter to
location_force_reg when generating code for a call to a virtual class method,
  called through a class reference var. This bug went unnoticed so far, because
  on all platforms, except i8086 medium and compact memory models, the size of
  a vmt pointer is the same as the size of a procvar. Even in the i8086 medium
  and compact memory models, the previous code would generate correct code,
  because thlcg2ll.a_load_loc_reg uses loc.size (which was correct) in the case
  when fromsize=tosize (both of which were wrong, but equal), due to the check
  in hlcg2ll.pas:555. Thanks to Jonas for finding this bug!

git-svn-id: trunk@28512 -
2014-08-22 23:17:46 +00:00
Jonas Maebe
bd09b88a5b + support for http://en.wikipedia.org/wiki/Blocks_(C_language_extension)
o blocks are implemented as a variation of procedure variables
   o declaration of a block variable: "test: procedure(c: char) is block;"
     (C equivalent: (void)(^test)(char c) )
   o the compiler automatically converts procedures/functions whose address
     is passed to a block parameter or assigned to a block variable into
     a "block". This consists of
    1) generating a block descriptor (containing the size of the "block
       literal" (see below) and the signature of the invocation function
       encoded as an Objective-C selector)
    2) generating a wrapper function around the original funcion (with C
       calling convention), that has an extra first hidden parameter
       (marked as vo_is_parentfp in the compiler) whose type is a pointer
       to the describing "block literal"
    3) generating the "block literal", which contains a pointer to an
       external variable indicating whether this block captures context or
       not, some flags (see compiler/blockutl.get_block_literal_flags for
       info), a pointer to the wrapper function and a pointer to the
       descriptor. In the future, it will also contain captured variables.
   o right now, only global procedures/functions can be converted to blocks
     (because they don't require state capturing). The next steps are (Object
     Pascal) methods (not Objective-C methods, because Objective-C method
     procvars don't exist) and finally nested functions
   o on Mac OS X, the functionality will only work on Mac OS X 10.7 and later,
     because we have to use the so-called "ABI.2010.3.16" to ensure that
     our blocks aren't called as variadic functions by the runtime (which
     came out after the Mac OS X 10.6 release)
   o while the currently implemented functionality does not require any
     library support at all, there's no use enabling it on other platforms
     because unless it has been confirmed to work with a blocks runtime,
     there's no point in using blocks (they're just somewhat bulky procvars
     right now). Enabling it on other platforms (in combination with the
     GNUStep Objective-C run time), should simply be a matter of adding
     the right {$linklib xxx} statement to rtl/inc/blockrtl.pp file, adding
     that file to Makefile.fpc for that platform and adding that platform
     to the compiler/systems.systems_blocks_supported set

git-svn-id: branches/blocks@28232 -
2014-07-18 09:15:22 +00:00
Jonas Maebe
5fa09fa2f4 * changed tcallnode.fforcedprocname from shortstring into tsymstr,
so it doesn't truncate mangled names for the JVM target (it's
    used there since r27149)
   o adapted a number of WPO helpers to use tsymstr instead of
     shortstring, but the WPO devirtualization functionality is
     still limited to shortstrings internally

git-svn-id: trunk@27741 -
2014-05-10 12:47:25 +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
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
sergei
9c1f917e3a * a_call_ref functionality cannot be implemented efficiently at code generator level, because references need specific preparations at earlier points. Moved this support to tcgcallnode and its x86 descendants, and got rid of all ifdef's around.
+ x86 targets now directly call procedure variables located in references.
- a_call_ref method removed from tcg and thlcgobj.

git-svn-id: trunk@26666 -
2014-02-03 13:28:56 +00:00
sergei
7104157a57 * Changed tabstractprocdef.address_size to return the def, which can be used to get other properties like size and alignment. Removes one of i8086 ifdef's.
git-svn-id: trunk@26664 -
2014-02-03 10:47:54 +00:00
sergei
e0082262cc * Don't generate VMT checking code twice (gen_load_vmt_register generates it already).
git-svn-id: trunk@26657 -
2014-02-03 00:27:05 +00:00
sergei
ff3fe06af9 * Changed condition around declaration of 'cgpara' to be the same as around its usage.
- Removed one of $ifdef's.

git-svn-id: trunk@26595 -
2014-01-27 01:41:51 +00:00
svenbarth
235c06ab34 Implement volatile address registers. Fixes quite some tests, but also breaks others... (overall more are fixed than are broken :) )
paramgr.pas, tparamanager:
  + add virtual get_volatile_registers_address method which by default returns an empty set
cgobj.pas, tcg:
  * allocallcpuregisters: also allocate address registers if needed
  * deallocallcpuregisters: also deallocate address registers if needed
ncgcal.pas, tcgcallnode.pass_generate_code:
  * (de)allocate address registers
  * keep result from being deallocated if it should be an address register (currently by no architecture...)
m68k/cpupara.pas, tm68kparamanager:
  + get_volatile_registers_address: return a0 and a1 as volatile registers
m68k/n68kmat.pas, tm68kmoddivnode.call_rtl_divmod_reg_reg:
  * (de)allocate address registers

git-svn-id: trunk@25633 -
2013-10-03 20:33:11 +00:00
nickysn
1029636dfe * far proc fixes in tcgcallnode.pass_generate_code
git-svn-id: trunk@24837 -
2013-06-09 14:21:03 +00:00
nickysn
ed92dee3fb * fixed the calling of virtual methods on i8086
git-svn-id: trunk@24646 -
2013-05-30 16:23:29 +00:00
Jonas Maebe
8b8a786823 * moved ARM/x86 ifdef'ed code from ncgcal to virtual methods
git-svn-id: trunk@24179 -
2013-04-07 13:42:06 +00:00
Jonas Maebe
4daa40f480 * reorder register parameters to minimise the number of register conflicts,
which usually (but not always) results in better register allocation

git-svn-id: trunk@24038 -
2013-03-28 18:44:57 +00:00
svenbarth
344571cb4e Added support for type helpers. In non Delphi modes they use "type helper" and in mode Delphi they use "record helper". They can also be used on constants.
symconst.pas:
  + extend "thelpertype" by "ht_type" which tells the code in "pdecobj.parse_extended_type" that a type helper declaration has been parsed
node.pas:
  + add a constant which identifies all constant node types
ptype.pas:
  + read_named_type: add a parameter "hadtypetoken" to tell the code whether a "type" token had been parsed before
  + read_named_type: if an identifier "helper" is parsed we need to check whether "hadtypetoken" is true and the modeswitch "m_class" is set, but the "m_delphi" one is not; in that case we have a "type helper" declaration
pgenutil.pas, generate_specialization:
  * adjust call to read_named_type
pdecl.pas, types_dec:
  * adjust call to read_named_type

pdecobj.pas:
  * parse_extended_type: extend for correct handling of primitive types (includes Delphi compatible handling as well) and reject types that are explicitly not allowed
  * method_dec: require "static" for class methods in type helpers
  * method_doc: allow constructors for type helpers as well
paramgr.pas, tparamanager:
  * set_common_funcretloc_info: handle type helper constructors like record constructors
  * handle_common_ret_in_param: the "self" value of a type helper constructor is also returned in a parameter
pexpr.pas:
  + add a function to postfixoperators which tries to find and apply a type helper for a given type
  * postfixoperators: try to apply type helpers for ordinal constants
  * postfixoperators: use the correct string type for string constants
  * postfixoperators: try to apply type helpers for enum constants
  * postfixoperators: try to apply type helpers for arrays
  * postfixoperators: try to apply type helpers for Variant
  * postfixoperators: try to apply type helpers for pointer types
  * postfixoperators: try to apply type helpers for other types
  * factor: check postfixoperators after _REALNUMBER, _CCHAR, _CWCHAR, _TRUE and _FALSE
  * factor: also check postfixoperators if a _POINT follows a _NIL

symdef.pas, tdefawaresymtablestack.addhelpers:
  * use "generate_objectpascal_helper_key" to generate the key
symtable.pas:
  + add function to generate the key value for the map of extended types using the extended def
  * adjust "search_last_objectpascal_helper" and "search_objectpascal_helper" to handle primitive types as well
  * use the new "generate_objectpascal_helper_key" function to generate the key

pparautl.pas:
  * insert_self_and_vmt_para: don't insert the $vmt symbol for record or type helpers (ToDo: check whether class helpers really need the symbol as well)
  * insert_self_and_vmt_para: pass "self" as var parameter for type helpers as well
psub.pas, generate_bodyentry_block: 
  * also allow type helpers for constructor methods
ncal.pas, tcallnode.gen_self_tree:
  * also use a temp variable for type helper constructors
ncgcal.pas, tcgcallnode.secondcallparan:
  * allow Pointers to be passed as address param if it is the Self value of a type helper extending a pointer type
  * correctly handle the location in case of type helper constructors

+ add tests

git-svn-id: trunk@23580 -
2013-02-06 09:49:35 +00:00
svenbarth
7bad1763b8 Decrease amount of code duplication regarding handling of safecall and record constructors.
paramgr.pas, tparamanager:
    + add new method "handle_common_ret_in_param"
    * extract common code (safecall + record constructor handling) from "ret_in_param" to "handle_common_ret_in_param" and call the latter in "ret_in_param"
[aarch64,arm,avr,i386,x86_64]/cpupara.pas, tCPUparamanager.ret_in_param:
    * call "handle_common_ret_in_param" instead of implementing the same check again and again
ncgcal.pas, tcgcallnode.handle_return_value:
    * move the check for (record) constructors to "tparamanager.handle_common_ret_in_param"

git-svn-id: trunk@23520 -
2013-01-25 20:39:28 +00:00
Jonas Maebe
10e3cab1b1 * fixed formatting
git-svn-id: trunk@23508 -
2013-01-24 09:44:59 +00:00
paul
5d74e0578a compiler: remove unused variables and unneeded assignments
git-svn-id: trunk@23467 -
2013-01-21 01:24:36 +00:00
paul
b2a613c17f compiler: implement record constructors + tests
git-svn-id: trunk@23395 -
2013-01-16 02:07:42 +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
pierre
7ea11f0171 Use SUPPORT_SAFECALL conditional
git-svn-id: trunk@22490 -
2012-09-27 15:59:57 +00:00
florian
67744ef46e * fix methodpointers in registers on big endian targets
git-svn-id: trunk@22362 -
2012-09-09 17:54:35 +00:00
florian
4514a55ec6 * call method pointers located in registers correctly
git-svn-id: trunk@22343 -
2012-09-06 15:12:06 +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
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
276a0918f5 * fixed (harmless) class cast error
git-svn-id: trunk@21860 -
2012-07-11 08:25:42 +00:00
pierre
3f6c3cbb87 * Call hlcg.a_call_ref and a_call_reg instead of cg methods (needed for MIPS cpu)
git-svn-id: trunk@21855 -
2012-07-10 21:34:03 +00:00
florian
7df1403849 * fix releasing of shortstring temps. in arrayconstructor nodes
git-svn-id: trunk@21753 -
2012-07-01 18:46:54 +00:00
Jonas Maebe
571b3feab1 * fixed internalerror on win64 after r21696 (source register size depends on
the platform, mantis #22316)

git-svn-id: trunk@21715 -
2012-06-26 17:01:34 +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
325c60866f * use tcgpara.def instead of extra size parameters
git-svn-id: trunk@21694 -
2012-06-24 15:01:59 +00:00
Jonas Maebe
9bfb8b5d48 * fixed (currently harmless) error in r21287 that specified that the full
contents of a procvar had to be loaded in case of a procedure of object
    or nested procvar rather than only the code address (harmless, because
    this code is only active for low level targets currently and since
    r21330 the location's size was used because the source and destination
    types were the same)

git-svn-id: trunk@21352 -
2012-05-20 21:11:45 +00:00
Jonas Maebe
edd42aa42a * moved subsetref/reg and bit_set/test support from cgobj to hlcgobj for
future use by high level code generator targets
   o this in turn required that all a_load*_loc* methods are called via
     hlcg rather than via cg, since a location can be a subsetref/reg and
     and those are no longer handled in tcg
   o that then required moving several force_location_* routines into
     thlcg because they use a_load_loc*, but did not take tdef size
     parameters (which are required by the thlcg a_load_loc* routines)
   o the only practical consequence is that from now on, you have to
     use hlcg.location_force_mem/reg() (fpureg not yet) and
     hlcg.gen_load_loc_cgpara() instead of the removed versions from ncgutil,
     and hlcg.a_load*loc*() instead of cg.a_load*loc* if a subsetref/reg
     might be involved

git-svn-id: trunk@21287 -
2012-05-13 12:33:10 +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
sergei
13e513fdf7 * Pass NR_FUNCTION_RESULT_REG to FPC_SAFECALLCHECK in target-independent way.
* Added missing call to paramanager.freecgpara.
* Handle safecall stuff after deallocating registers of the main call in order to keep allocations balanced.

git-svn-id: trunk@21021 -
2012-04-24 14:50:56 +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
sergei
06192a8137 Values of managed variables are never ever used after decrementing reference on the variable, so there is no point of having a 'decrement reference' as a separate operation. We can always do 'finalize', i.e. clear the contents after decref.
* Modified fpc_ansistr_decr_ref and fpc_widestr_decr_ref so they always zero the pointer passed by reference. Other _decr_ref helpers already do it.
- Removed tcg.g_decrrefcount, calling cg.g_finalize instead.
- finalize_data_node and tcg.g_finalize: removed code generation for zeroing locations, because it is now done by RTL helpers. This further reduces code size.

As a total result of this change and r20118, the size of Lazarus executable is reduced by about 12%.

git-svn-id: trunk@20119 -
2012-01-19 23:11:09 +00:00
sergei
b1cbf30a94 * Managed types passed to out formal parameters must be completely cleaned (decrementing refcount is not enough) at caller side, because callee side doesn't know their actual type and cannot initialize them. Resolves #20962.
git-svn-id: trunk@19956 -
2012-01-03 09:07:08 +00:00
sergei
3a579ced7b * Fixed IE201103063 when <dynamic array of unmanaged type> is being passed to <out open array> parameter.
git-svn-id: trunk@19684 -
2011-11-25 14:43:17 +00:00
pierre
b6de7f0d6b * Suppress Comaprison might be always false if first_mm_imreg is zero
git-svn-id: trunk@19584 -
2011-11-03 10:13:26 +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
1a23a7cd27 * removed all remaining nounsupported ifdefs (except for the one about
variants)

git-svn-id: branches/jvmbackend@18770 -
2011-08-20 08:34:26 +00:00