Commit Graph

184 Commits

Author SHA1 Message Date
Jonas Maebe
a637fbe596 * moved all g_exception_*() methods to hlcgobj and cleaned them up (no more
hardcoded registers for the most part)
  + added extra g_exception_discard_reason() that can be called when we only
    want to get rid of the currently pushed exception reason, and don't have
    to load it (so it can do nothing on platforms that don't use push/pop)

git-svn-id: branches/hlcgllvm@28481 -
2014-08-19 20:22:24 +00:00
Jonas Maebe
bacd303208 * synchronized with trunk up to r27758
git-svn-id: branches/hlcgllvm@27779 -
2014-05-12 16:12:34 +00:00
nickysn
a79a891940 * handle the result of FPC_CATCHES via the high level code generator (which makes it i8086 far pointer safe)
git-svn-id: trunk@27451 -
2014-04-02 14:25:19 +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
sergei
e26ce9e442 * Fix code generation of for-loops. Keeping a copy of to-value in register during pass 2 is basically a hack, because register may be destroyed if an exception is raised and handled in loop body. This went unnoticed because generic setjmp-based exception handling is restoring registers to the state at entry to try block, and Win64 SEH also has some register-preserving features. However, for Win32 SEH it is not true.
Instead, to-value is now copied to a temp during pass 1, and this temp is forced into memory if loop body contains try..finally or try..except block.

git-svn-id: trunk@26192 -
2013-12-07 09:18:18 +00:00
sergei
563b74b16a * Cleanup code generation for try..finally nodes.
git-svn-id: trunk@26191 -
2013-12-07 07:31:59 +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
nickysn
bf07fc077b * specify AT_DATA in all references to the tobjectdef.vmt_mangledname symbol.
This fixes a lot of bugs, related to objects and classes in the i8086 medium
  memory model

git-svn-id: trunk@25794 -
2013-10-15 18:56:27 +00:00
sergei
4a9fe5d07d * Fixed register live range in for-loops:
o Loop counter node is "left", not "right",
  o End-value register needs explicit sync.

Without these changes, allocating registers in hlcg.a_cmp_reg_loc_label (at the end of loop) could reuse counter or end-value register, resulting in invalid code.

git-svn-id: trunk@24924 -
2013-06-21 15:26:14 +00:00
florian
a07af824ea * properly fix raise node handling on x86-64 after r24288
git-svn-id: trunk@24334 -
2013-04-26 20:17:54 +00:00
pierre
4f8fcb7f15 Revert commit 24324 for ncgflow.pas unit to fix win64 cycle
git-svn-id: trunk@24328 -
2013-04-26 09:38:57 +00:00
florian
709ba5e053 + introduce cnf_call_never_returns to signal the dfa if a call node never returns
* get rid of  tcgraisenode.pass_generate_code, it is replaced by compiler proc. call nodes generated in pass_1

git-svn-id: branches/i8086@24288 -
2013-04-21 16:53:25 +00:00
nickysn
a5c5b05362 * initial support for system procs that use calling conventions that push left to right on i8086 or i386
git-svn-id: branches/i8086@24282 -
2013-04-21 13:26:12 +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
18698bc93d Fix safecall for cpus for which NR_FUNCTION_RESULT_REG is different from NR_FUNCTION_RETURN_REG
git-svn-id: trunk@22489 -
2012-09-27 15:59:31 +00:00
florian
ca5fabda6d * cleanup some unused units from uses clauses
git-svn-id: trunk@22433 -
2012-09-21 18:53:46 +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
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
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
fa98e0523d * Safecall handling: forgot to free cgpara before doing the call, fixed.
git-svn-id: trunk@19976 -
2012-01-05 19:12:56 +00:00
sergei
f6761d7939 * Handle safecall exceptions entirely in tcgtryfinallynode pass2. This simplifies things and removes the need in hidden safe_result variable.
git-svn-id: trunk@19950 -
2012-01-02 14:23:31 +00:00
sergei
8c9ad67682 + tcgexitnode,tcgbreaknode,tcgcontinuenode: added possibility to generate specialized code for leaving unwind-protected regions.
git-svn-id: trunk@19636 -
2011-11-14 22:47:37 +00:00
sergei
e2d43fcb30 - tcgonnode: don't store exception object in temp if it is not used.
- tcgtryexceptnode: don't generate code to decrease/compare exception reason if not necessary.

git-svn-id: trunk@19517 -
2011-10-19 20:28:41 +00:00
sergei
a32fdc3ae6 + Added a simple helper tcg.g_call, intended to replace allocallcpuregisters+a_call_name+deallocallcpuregisters sequence which is used all over the place.
* Refactored code generation for tcgonnonde and tcgtryexceptnode, simplifying both compiler and generated code. Merged compilerprocs called in sequence into larger ones (fpc_popobjectstack+fpc_destroyexception -> fpc_doneexception, fpc_popsecondobjectstack+fpc_destroyexception+fpc_reraise -> fpc_raise_nested).

git-svn-id: trunk@19506 -
2011-10-18 15:46:15 +00:00
sergei
9ed2fa6f7b - Exception handling: calling FPC_CATCHES(-1) is obsolete, it does not change any state and its return value is not used. Removed.
- Don't generate guard frame around 'except' block if it contains no code (tryexceptnode.t1 is an empty blocknode in this case).

git-svn-id: trunk@19415 -
2011-10-08 12:57:58 +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
e9f1856a61 * converted non-exception-related nodes to thlcgobj
git-svn-id: branches/jvmbackend@18330 -
2011-08-20 07:46:46 +00:00
florian
d9ed5adb21 * set line info markers properly, resolves #17803
git-svn-id: trunk@17476 -
2011-05-16 15:15:35 +00:00
joost
65ab1e820b * Safecall on linux/i386 now behaves like cdecl plus hidden exception support.
* Adapted tests because safecall on linux/i386 now does not include high() 
   support anymore

git-svn-id: trunk@15913 -
2010-08-27 19:07:22 +00:00
florian
ad23569cf1 * renamed pi_has_goto into pi_has_label because the problematic thing is if a procedure has a label as target and not if it has some goto
* moved inclusion of pi_has_label to tlabelnode.pass_1

git-svn-id: trunk@15712 -
2010-08-05 19:22:12 +00:00
Jonas Maebe
283018a3bf * changed tprocdef.funcretloc[] from a tlocation into a tcgpara so it can
represent complex locations (required for full x86-64 ABI support,
    which is not yet implemented) -> lots of special result handling
    code has been removed and replaced by the parameter handling
    routines
  + added support for composite parameters (and hence function
    results) to tcg.a_load_ref_cgpara() (so it can be used for
    handling, e.g., 64 bit parameters on 32 bit platforms)
  * the above fixed writing past the end of allocated memory when
    handling records returned in registers on x86-64 whose size is
    not a multiple of 8 bytes (mantis #16357)
  - removed the x86-64 and PPC specific versions of a_load_ref_cgpara(),
    as they are now handled correctly by the generic version
  * moved the responsibility of allocating tcgpara cpu registers
    (using paramanager.allocparaloc()) from the callers of
    cg.a_load*_cgpara() to the cg.a_load*_cgpara() methods
    themselves (so the register allocation can be done efficiently
    when dealing with function results)
  * for the above, renamed paramanager.alloc/freeparaloc() to
    paramanager.alloc/freecgpara(), and use paramanager.allocparaloc()
    to allocate individual pcgparalocations instead
  * fixed the register size of SSE2 function result registers for
    x86-64 (when used for floating point), which results in removing
    a few superfluous "movs? %xmm0,%xmm0" instructions
  * fixed compilation of paramanagers of avr, m68k and mips after r13695
    and also updated them for these new changes

git-svn-id: trunk@15350 -
2010-05-30 21:12:57 +00:00
Jonas Maebe
9bc15a5f61 * renamed a_param_* to a_load_*_cgpara
git-svn-id: trunk@15305 -
2010-05-22 09:07:21 +00:00
Jonas Maebe
d8a902b4c4 * fixed internalerror in case the from-value of a for-loop has loc_jump
(mantis #15750)

git-svn-id: trunk@15071 -
2010-03-26 22:26:25 +00:00
paul
e2fdfc426f compiler: fix safecall result handling if it is placed to a register
git-svn-id: trunk@14952 -
2010-02-28 10:50:40 +00:00
paul
b884d568e1 compiler: fix 64bit safecall handling
git-svn-id: trunk@14949 -
2010-02-27 16:15:03 +00:00
paul
cf0a1b1af9 compiler: safecall exception handling:
- move safecall exception handling from codegenerator to generate_except_block method (which generates nodes)
  - call SafeCallException for safecall methods which raises an exception

git-svn-id: trunk@14940 -
2010-02-26 10:17:24 +00:00
florian
c1f3d8dcaa * unified names of system_*/systems_* sets
git-svn-id: trunk@14566 -
2010-01-07 18:16:20 +00:00
Jonas Maebe
4838ebe73b * renamed mark_InlineStart/mark_InlineEnd to mark_NoLineinfoStart/
mark_NoLineinfoEnd
  * add "no line info" markers for try/except and try/finally internal cleanup
    code, so the debugger doesn't jump back and forth between the end and start
    of exception blocks when you arrive at the end
  * honour "no line info" markers in dbgdwarf.pas

git-svn-id: trunk@14327 -
2009-12-04 19:37:22 +00:00
Jonas Maebe
d644fc87a1 * handle loc_jump/loc_flags in for-loop upper bound (mantis #15169)
git-svn-id: trunk@14261 -
2009-11-23 21:11:16 +00:00
Jonas Maebe
1f6ec379de * moved field definitions before method/property definitions (see mantis
#13971)

git-svn-id: trunk@13330 -
2009-06-27 11:27:31 +00:00
Jonas Maebe
c1e327c8c4 * insert register allocation/deallocation information for the exception
handling code (g_exception_reason_load() now automatically allocates
    the cpu register that it loads). This fixes the bug reported in
    http://lists.freepascal.org/lists/fpc-devel/2009-May/016773.html
    on i386 with -O2)

git-svn-id: trunk@13105 -
2009-05-06 19:11:54 +00:00
Jonas Maebe
7d459cf12a * the compiler now explicitly keeps track of the minimally guaranteed
alignment for each memory reference (mantis #12137, and
    test/packages/fcl-registry/tregistry1.pp on sparc). This also
    enables better code generation for packed records in many cases.
  o several changes were made to the compiler to minimise the chances
    of accidentally forgetting to set the alignment of memory references
    in the future:
    - reference_reset*() now has an extra alignment parameter
    - location_reset() can now only be used for non LOC_(C)REFERENCE,
      use location_reset_ref() for those (split the tloc enum so the
      compiler can catch errors using range checking)

git-svn-id: trunk@12719 -
2009-02-08 13:00:24 +00:00
Jonas Maebe
718694d1d6 * always specify an explicit alignment for tgobj.gettemp (so e.g.
shortstring temps don't get maximum alignment)
  * changed some gettemptyed() calls into gettemp() calls (gettemptyped
    means that this temp can only be used for temps of that type,
    which is necessary for refcounted types but not for floats)

git-svn-id: trunk@12036 -
2008-11-08 22:20:47 +00:00
Jonas Maebe
a23630260b + "weakexternal" support for imported procedures and variables.
the syntax is exactly the same as for "external", except for
    the keyword. It is currently only active for Darwin targets.
    It should also work at least for Linux targets, but only with
    the GNU assembler (which is why it is not activated there)
  + test for this functionality

git-svn-id: trunk@12009 -
2008-11-01 18:38:32 +00:00
Jonas Maebe
c65f8e7652 * safecall is only supposed to do anything for Windows targets. Removed
partial implementation for other targets and run test only for Windows

git-svn-id: trunk@11593 -
2008-08-16 14:46:20 +00:00
florian
050627ea1d * allow goto inside finally blocks
git-svn-id: trunk@11392 -
2008-07-17 19:49:38 +00:00
Jonas Maebe
2348c7ea00 * allow ssa to happen for outer for-loop control variables
git-svn-id: trunk@11320 -
2008-07-03 19:39:23 +00:00
Jonas Maebe
f36e5411af * split cpu64bit compiler define into
a) cpu64bitaddr, which means that we are generating a compiler which
       will generate code for targets with a 64 bit address space/abi
    b) cpu64bitalu, which means that we are generating a compiler which
       will generate code for a cpu with support for 64 bit integer
       operations (possibly running in a 32 bit address space, depending
       on the cpu64bitaddr define)
   All cpus which had cpu64bit set now have both the above defines set,
   and none of the 32 bit cpus have cpu64bitalu set (and none will
   compile with it currently)
  + pint and puint types, similar to aint/aword (not pword because that
    that conflicts with pword=^word)
  * several changes from aint/aword to pint/pword
  * some changes of tcgsize2size[OS_INT] to sizeof(pint)

git-svn-id: trunk@10320 -
2008-02-13 20:44:00 +00:00
Jonas Maebe
1f1a43d7f0 * fixed crash when compiling inlined procedures containing labels
git-svn-id: trunk@9804 -
2008-01-20 10:29:04 +00:00
daniel
4ca3a590e8 * Labels that are defined or referenced in a different lexical level
than their declaration need to be code generated as global asmlabels.

git-svn-id: trunk@9791 -
2008-01-19 13:50:58 +00:00