mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-13 09:19:32 +02:00

+ darwin/ppc64 support + val/str/read(ln)/write(ln) support for enums + simple cse at the node tree level + if-node simplify support + simple ssa support for memory locations + support for optional overflow/rangecheck boolean parameters for operators * a lot of unification of the ppc32/ppc64 code generators ........ r6380 | jonas | 2007-02-08 21:25:36 +0100 (Thu, 08 Feb 2007) | 4 lines Changed paths: M /branches/fpc_2_3/compiler/ncgld.pas M /branches/fpc_2_3/compiler/tgobj.pas A /branches/fpc_2_3/tests/webtbs/tw8283.pp + support for replacing the memory location of a temp (including local variables) with that of another temp to avoid unnecessary copies (mantis #8283) ........ r6381 | jonas | 2007-02-08 22:53:36 +0100 (Thu, 08 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/nflw.pas A /branches/fpc_2_3/tests/webtbs/tw8282.pp + simplify support for ifn (based on patch by Florian) ........ r6386 | peter | 2007-02-09 13:48:53 +0100 (Fri, 09 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/htypechk.pas M /branches/fpc_2_3/compiler/ncal.pas M /branches/fpc_2_3/compiler/symconst.pas * overflow,rangecheck optional parameters for operators, patch from 8281 ........ r6391 | jonas | 2007-02-09 23:52:13 +0100 (Fri, 09 Feb 2007) | 4 lines Changed paths: M /branches/fpc_2_3/compiler/powerpc/agppcgas.pas M /branches/fpc_2_3/compiler/powerpc64/cpunode.pas D /branches/fpc_2_3/compiler/powerpc64/nppcinl.pas M /branches/fpc_2_3/compiler/ppcgen/ngppcinl.pas * merged fsqrt(s) support to common powerpc unit, activate for ppc32 if -Op970 is used (still default for ppc64, since default cpu there is already ppc970) ........ r6394 | jonas | 2007-02-10 18:58:47 +0100 (Sat, 10 Feb 2007) | 4 lines Changed paths: M /branches/fpc_2_3/compiler/powerpc/cgcpu.pas M /branches/fpc_2_3/compiler/powerpc64/cgcpu.pas M /branches/fpc_2_3/compiler/ppcgen/cgppc.pas * adapted a_jmp_name for darwin/ppc64 * merged g_intf_wrapper for ppc32 and ppc64, and added darwin/ppc64 support to it ........ r6396 | jonas | 2007-02-10 20:16:06 +0100 (Sat, 10 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/cgobj.pas + darwin/ppc64 support for g_indirect_sym_load ........ r6397 | jonas | 2007-02-10 20:22:49 +0100 (Sat, 10 Feb 2007) | 4 lines Changed paths: M /branches/fpc_2_3/compiler/powerpc/cgcpu.pas M /branches/fpc_2_3/compiler/powerpc64/cgcpu.pas M /branches/fpc_2_3/compiler/ppcgen/cgppc.pas + darwin/ppc64 support to ppc64's fixref * moved ppc32 a_load_store to cgppc and use it for darwin/ppc64 as well (its relocatable symbols are only 32 bits large) ........ r6399 | jonas | 2007-02-10 22:02:37 +0100 (Sat, 10 Feb 2007) | 4 lines Changed paths: M /branches/fpc_2_3/compiler/systems.pas + system_x86_64_darwin identifier + set default source system for system_x86_64_darwin and system_powerpc64_darwin ........ r6404 | jonas | 2007-02-10 23:01:23 +0100 (Sat, 10 Feb 2007) | 5 lines Changed paths: M /branches/fpc_2_3/compiler/aasmdata.pas M /branches/fpc_2_3/compiler/aggas.pas M /branches/fpc_2_3/compiler/cgobj.pas M /branches/fpc_2_3/compiler/cgutils.pas M /branches/fpc_2_3/compiler/cresstr.pas M /branches/fpc_2_3/compiler/dbgdwarf.pas M /branches/fpc_2_3/compiler/dbgstabs.pas M /branches/fpc_2_3/compiler/ncgutil.pas M /branches/fpc_2_3/compiler/ogelf.pas M /branches/fpc_2_3/compiler/pdecvar.pas M /branches/fpc_2_3/compiler/pmodules.pas M /branches/fpc_2_3/compiler/symdef.pas M /branches/fpc_2_3/compiler/systems.pas + system_x86_64_darwin identifier + systems_darwin set which collects all darwin variants + added support for darwin/ppc64 and darwin/x86_64 where needed in the generic code ........ r6406 | jonas | 2007-02-10 23:24:32 +0100 (Sat, 10 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/cgobj.pas * ifdef cpu64 -> ifdef cpu64bit ........ r6409 | jonas | 2007-02-11 00:34:04 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/pdecvar.pas * fixed ppc64 compilation ........ r6413 | jonas | 2007-02-11 12:41:27 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/rtl/bsd/system.pp M /branches/fpc_2_3/rtl/darwin/powerpc/sig_cpu.inc M /branches/fpc_2_3/rtl/darwin/signal.inc + darwin/ppc64 support for signal routines ........ r6415 | jonas | 2007-02-11 13:54:53 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/systems/i_linux.pas * set abi of linux/ppc64 to abi_powerpc_sysv ........ r6416 | jonas | 2007-02-11 13:55:51 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/powerpc64/cputarg.pas M /branches/fpc_2_3/compiler/systems/i_bsd.pas M /branches/fpc_2_3/compiler/systems/t_bsd.pas + darwin/ppc64 source and target information ........ r6418 | jonas | 2007-02-11 14:19:55 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/rtl/powerpc64/math.inc * darwin/ppc64 compilation fixes ........ r6419 | jonas | 2007-02-11 14:22:22 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/powerpc/cgcpu.pas M /branches/fpc_2_3/compiler/powerpc64/cgcpu.pas M /branches/fpc_2_3/compiler/ppcgen/cgppc.pas * darwin/ppc64 needs the 32 bit version of a_loadaddr_ref_reg ........ r6420 | jonas | 2007-02-11 14:22:55 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/utils/fpcm/fpcmmain.pp + darwin/ppc64 support ........ r6426 | jonas | 2007-02-11 16:13:19 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/powerpc64/rappcgas.pas * fixed refaddr parsing for darwin/ppc64 ........ r6427 | jonas | 2007-02-11 16:14:21 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/powerpc/agppcgas.pas M /branches/fpc_2_3/compiler/powerpc64/agppcgas.pas A /branches/fpc_2_3/compiler/ppcgen/agppcutl.pas * moved ppc32/ppc64 assembler writer helpers to a common unit ........ r6430 | jonas | 2007-02-11 17:53:23 +0100 (Sun, 11 Feb 2007) | 4 lines Changed paths: D /branches/fpc_2_3/rtl/darwin/powerpc/sig_cpu.inc D /branches/fpc_2_3/rtl/darwin/powerpc/sighnd.inc A /branches/fpc_2_3/rtl/darwin/powerpc64 A /branches/fpc_2_3/rtl/darwin/powerpc64/sig_cpu.inc A /branches/fpc_2_3/rtl/darwin/powerpc64/sighnd.inc A /branches/fpc_2_3/rtl/darwin/ppcgen A /branches/fpc_2_3/rtl/darwin/ppcgen/ppchnd.inc (from /branches/fpc_2_3/rtl/darwin/powerpc/sighnd.inc:6422) A /branches/fpc_2_3/rtl/darwin/ppcgen/sig_ppc.inc (from /branches/fpc_2_3/rtl/darwin/powerpc/sig_cpu.inc:6422) M /branches/fpc_2_3/rtl/darwin/signal.inc * fixed ppc/ppc64 signal include handling (both real files are in ppcgen, dummies in powerpc and powerpc64 which include those files) (1st step because pre-commit filter can't handle replaced files) ........ r6431 | jonas | 2007-02-11 17:53:47 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: A /branches/fpc_2_3/rtl/darwin/powerpc/sig_cpu.inc A /branches/fpc_2_3/rtl/darwin/powerpc/sighnd.inc * second step of signal include patch ........ r6432 | jonas | 2007-02-11 19:00:12 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/systems/t_bsd.pas * changed darwin checks to use systems_darwin constant ........ r6433 | jonas | 2007-02-11 19:05:38 +0100 (Sun, 11 Feb 2007) | 3 lines Changed paths: M /branches/fpc_2_3/compiler/powerpc64/cgcpu.pas * handle non-multiple-of-4 offsets with 64 bit loads/stores for darwin/ppc64 ........ r6434 | jonas | 2007-02-11 19:05:56 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: D /branches/fpc_2_3/compiler/powerpc/agppcgas.pas D /branches/fpc_2_3/compiler/powerpc64/agppcgas.pas A /branches/fpc_2_3/compiler/ppcgen/agppcgas.pas (from /branches/fpc_2_3/compiler/ppcgen/agppcutl.pas:6427) D /branches/fpc_2_3/compiler/ppcgen/agppcutl.pas * completely merged ppc assembler writers ........ r6435 | jonas | 2007-02-11 19:06:40 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/rtl/darwin/console.pp M /branches/fpc_2_3/rtl/darwin/termiosproc.inc * fixed 64 bit compilation ........ r6436 | jonas | 2007-02-11 19:09:28 +0100 (Sun, 11 Feb 2007) | 3 lines Changed paths: M /branches/fpc_2_3/packages/extra/Makefile.fpc * universal interfaces aren't 64 bit ready yet -> only compile for darwin/ppc and darwin/i386 ........ r6438 | jonas | 2007-02-11 19:22:34 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: A /branches/fpc_2_3/tests/test/cg/obj/darwin/powerpc64 A /branches/fpc_2_3/tests/test/cg/obj/darwin/powerpc64/ctest.o A /branches/fpc_2_3/tests/test/cg/obj/darwin/powerpc64/tcext3.o A /branches/fpc_2_3/tests/test/cg/obj/darwin/powerpc64/tcext4.o A /branches/fpc_2_3/tests/test/cg/obj/darwin/powerpc64/tcext5.o + compiled for darwin/ppc64 ........ r6439 | jonas | 2007-02-11 20:24:42 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/ppcgen/cgppc.pas * patch from Thomas to fix linux/ppc64 ........ r6440 | jonas | 2007-02-11 20:25:15 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/systems.pas * fixed setting source OS for darwin/ppc64 ........ r6444 | florian | 2007-02-11 22:24:20 +0100 (Sun, 11 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/globtype.pas M /branches/fpc_2_3/compiler/nopt.pas M /branches/fpc_2_3/compiler/nutils.pas M /branches/fpc_2_3/compiler/optcse.pas M /branches/fpc_2_3/compiler/psub.pas + first node cse implementation ........ r6445 | jonas | 2007-02-11 22:30:07 +0100 (Sun, 11 Feb 2007) | 6 lines Changed paths: M /branches/fpc_2_3/compiler/cresstr.pas * hack to work around strange darwin/ppc64 linker bug: it seems to have problems if you put a global symbol at the end of a section without any data following (at least in case of the resource strings section) -> add dummy byte at the end for darwin/ppc64 (otherwise it messes up the address of the first symbol stub entry) ........ r6449 | jonas | 2007-02-11 23:23:44 +0100 (Sun, 11 Feb 2007) | 4 lines Changed paths: M /branches/fpc_2_3/compiler/systems/i_bsd.pas * cpupowerpc is defined for both ppc32 and ppc64 -> changed to cpupowerpc32 to avoid defining source wrongly on ppc64 ........ r6450 | jonas | 2007-02-11 23:26:34 +0100 (Sun, 11 Feb 2007) | 3 lines Changed paths: M /branches/fpc_2_3/compiler/ppcgen/ngppcset.pas * disable jump tables for darwin/ppc64 for now, don't work yet for some reason ........ r6451 | florian | 2007-02-11 23:54:37 +0100 (Sun, 11 Feb 2007) | 3 lines Changed paths: M /branches/fpc_2_3/compiler/ncal.pas M /branches/fpc_2_3/compiler/nutils.pas M /branches/fpc_2_3/compiler/optcse.pas * improved cse * better complexity calculation for subscript nodes with classes or interfaces ........ r6456 | jonas | 2007-02-12 19:33:22 +0100 (Mon, 12 Feb 2007) | 4 lines Changed paths: M /branches/fpc_2_3/compiler/nutils.pas + support for notn,shln,shrn,equaln,unequaln,gtn,gten,ltn,lten in node_cplexity() * mark muln,divn,modn as more complex ........ r6469 | jonas | 2007-02-13 15:56:01 +0100 (Tue, 13 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/optcse.pas * fixed when cross-compiling a 64 bit compiler from a 32 bit platform ........ r6471 | jonas | 2007-02-13 16:17:16 +0100 (Tue, 13 Feb 2007) | 3 lines Changed paths: M /branches/fpc_2_3/compiler/powerpc64/cputarg.pas * include stabs support (can work on darwin/ppc64, but doesn't work yet) ........ r6473 | jonas | 2007-02-13 16:45:48 +0100 (Tue, 13 Feb 2007) | 3 lines Changed paths: M /branches/fpc_2_3/compiler/powerpc64/cgcpu.pas M /branches/fpc_2_3/compiler/powerpc64/cpupara.pas * R2 is a volatile and usable register under darwin/ppc64 * R13 is a reserved non-volatile register under darwin/ppc64 (tls) ........ r6479 | jonas | 2007-02-13 20:40:50 +0100 (Tue, 13 Feb 2007) | 3 lines Changed paths: M /branches/fpc_2_3/compiler/systems/i_bsd.pas * maxCrecordalign seems to have to be 8 rather 4, in spite of what the ABI docs say (although they are contradictory to some extent) ........ r6487 | jonas | 2007-02-14 15:57:40 +0100 (Wed, 14 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/tests/webtbs/tw8153a.pp * fixed for darwin/ppc64 ........ r6488 | jonas | 2007-02-14 15:58:56 +0100 (Wed, 14 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/tests/webtbs/tw7851a.pp * fixed for darwin/ppc64 ........ r6494 | jonas | 2007-02-15 19:36:55 +0100 (Thu, 15 Feb 2007) | 3 lines Changed paths: M /branches/fpc_2_3/compiler/systems/i_bsd.pas * set default debug info for darwin/ppc64 to dwarf2 since it works better than stabs currently ........ r6500 | jonas | 2007-02-15 21:38:16 +0100 (Thu, 15 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/version.pas * updated version to 2.3.0 ........ r6505 | jonas | 2007-02-15 22:39:28 +0100 (Thu, 15 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/version.pas * changed version to 2.3.1 ........ r6511 | jonas | 2007-02-16 15:17:24 +0100 (Fri, 16 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/powerpc64/itcpugas.pas * system_powerpc_darwin -> system_powerpc64_darwin ........ r6546 | daniel | 2007-02-18 15:48:54 +0100 (Sun, 18 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/ncginl.pas M /branches/fpc_2_3/compiler/ncgld.pas M /branches/fpc_2_3/compiler/ncgrtti.pas M /branches/fpc_2_3/compiler/ncnv.pas M /branches/fpc_2_3/compiler/ninl.pas M /branches/fpc_2_3/compiler/nld.pas M /branches/fpc_2_3/compiler/nutils.pas M /branches/fpc_2_3/compiler/pinline.pas M /branches/fpc_2_3/rtl/inc/astrings.inc M /branches/fpc_2_3/rtl/inc/compproc.inc M /branches/fpc_2_3/rtl/inc/sstrings.inc M /branches/fpc_2_3/rtl/inc/text.inc M /branches/fpc_2_3/rtl/inc/wstrings.inc + Val/str/read/write support for enumeration types. ........ r6547 | daniel | 2007-02-18 17:01:20 +0100 (Sun, 18 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/rtl/inc/sstrings.inc * Fix val code that I broke. ........ r6571 | daniel | 2007-02-20 09:27:44 +0100 (Tue, 20 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/rtl/inc/astrings.inc M /branches/fpc_2_3/rtl/inc/sstrings.inc M /branches/fpc_2_3/rtl/inc/text.inc M /branches/fpc_2_3/rtl/inc/wstrings.inc * o2s -> ord2str, s2o -> str2ord ........ r6572 | daniel | 2007-02-20 09:33:30 +0100 (Tue, 20 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/ncgld.pas M /branches/fpc_2_3/compiler/ncgrtti.pas M /branches/fpc_2_3/compiler/ninl.pas M /branches/fpc_2_3/compiler/nld.pas * o2s -> ord2str, s2o -> str2ord ........ r6574 | daniel | 2007-02-20 12:07:58 +0100 (Tue, 20 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/rtl/inc/compproc.inc * o2s -> ord2str, s2o -> str2ord ........ r6578 | daniel | 2007-02-20 22:18:49 +0100 (Tue, 20 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/rtl/inc/text.inc * Change longint to valsint. ........ r6579 | daniel | 2007-02-20 22:29:09 +0100 (Tue, 20 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/ninl.pas * Handle ordinal currency types. ........ r6580 | jonas | 2007-02-20 22:29:11 +0100 (Tue, 20 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/ncgrtti.pas * fixed compilation for cpurequiresproperalignment ........ r6581 | jonas | 2007-02-20 22:30:21 +0100 (Tue, 20 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/ninl.pas * fixed typo ........ r6582 | daniel | 2007-02-20 22:36:19 +0100 (Tue, 20 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/ninl.pas * Set is_real to true. ........ r6590 | jonas | 2007-02-21 20:23:54 +0100 (Wed, 21 Feb 2007) | 2 lines Changed paths: M /branches/fpc_2_3/compiler/systems/i_bsd.pas * set tf_dwarf_only_local_labels for darwin/ppc64 git-svn-id: trunk@6720 -
1155 lines
39 KiB
ObjectPascal
1155 lines
39 KiB
ObjectPascal
{
|
|
Copyright (c) 1998-2006 by the Free Pascal team
|
|
|
|
This unit implements the generic part of the GNU assembler
|
|
(v2.8 or later) writer
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
****************************************************************************
|
|
}
|
|
{ Base unit for writing GNU assembler output.
|
|
}
|
|
unit aggas;
|
|
|
|
{$i fpcdefs.inc}
|
|
|
|
interface
|
|
|
|
uses
|
|
cclasses,
|
|
globtype,globals,
|
|
aasmbase,aasmtai,aasmdata,aasmcpu,
|
|
assemble;
|
|
|
|
|
|
type
|
|
TCPUInstrWriter = class;
|
|
{# This is a derived class which is used to write
|
|
GAS styled assembler.
|
|
}
|
|
TGNUAssembler=class(texternalassembler)
|
|
protected
|
|
function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;virtual;
|
|
procedure WriteSection(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder);
|
|
procedure WriteExtraHeader;virtual;
|
|
procedure WriteInstruction(hp: tai);
|
|
public
|
|
function MakeCmdLine: TCmdStr; override;
|
|
procedure WriteTree(p:TAsmList);override;
|
|
procedure WriteAsmList;override;
|
|
destructor destroy; override;
|
|
private
|
|
setcount: longint;
|
|
procedure WriteDecodedSleb128(a: int64);
|
|
procedure WriteDecodedUleb128(a: qword);
|
|
function NextSetLabel: string;
|
|
protected
|
|
InstrWriter: TCPUInstrWriter;
|
|
end;
|
|
|
|
|
|
{# This is the base class for writing instructions.
|
|
|
|
The WriteInstruction() method must be overriden
|
|
to write a single instruction to the assembler
|
|
file.
|
|
}
|
|
TCPUInstrWriter = class
|
|
constructor create(_owner: TGNUAssembler);
|
|
procedure WriteInstruction(hp : tai); virtual; abstract;
|
|
protected
|
|
owner: TGNUAssembler;
|
|
end;
|
|
|
|
|
|
TAppleGNUAssembler=class(TGNUAssembler)
|
|
function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;override;
|
|
private
|
|
debugframecount: aint;
|
|
end;
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
|
SysUtils,
|
|
cutils,cfileutils,systems,
|
|
fmodule,finput,verbose,
|
|
itcpugas,cpubase
|
|
;
|
|
|
|
const
|
|
line_length = 70;
|
|
|
|
var
|
|
CurrSecType : TAsmSectiontype; { last section type written }
|
|
lastfileinfo : tfileposinfo;
|
|
infile,
|
|
lastinfile : tinputfile;
|
|
symendcount : longint;
|
|
|
|
type
|
|
{$ifdef cpuextended}
|
|
t80bitarray = array[0..9] of byte;
|
|
{$endif cpuextended}
|
|
t64bitarray = array[0..7] of byte;
|
|
t32bitarray = array[0..3] of byte;
|
|
|
|
{****************************************************************************}
|
|
{ Support routines }
|
|
{****************************************************************************}
|
|
|
|
function fixline(s:string):string;
|
|
{
|
|
return s with all leading and ending spaces and tabs removed
|
|
}
|
|
var
|
|
i,j,k : integer;
|
|
begin
|
|
i:=length(s);
|
|
while (i>0) and (s[i] in [#9,' ']) do
|
|
dec(i);
|
|
j:=1;
|
|
while (j<i) and (s[j] in [#9,' ']) do
|
|
inc(j);
|
|
for k:=j to i do
|
|
if s[k] in [#0..#31,#127..#255] then
|
|
s[k]:='.';
|
|
fixline:=Copy(s,j,i-j+1);
|
|
end;
|
|
|
|
function single2str(d : single) : string;
|
|
var
|
|
hs : string;
|
|
begin
|
|
str(d,hs);
|
|
{ replace space with + }
|
|
if hs[1]=' ' then
|
|
hs[1]:='+';
|
|
single2str:='0d'+hs
|
|
end;
|
|
|
|
function double2str(d : double) : string;
|
|
var
|
|
hs : string;
|
|
begin
|
|
str(d,hs);
|
|
{ replace space with + }
|
|
if hs[1]=' ' then
|
|
hs[1]:='+';
|
|
double2str:='0d'+hs
|
|
end;
|
|
|
|
function extended2str(e : extended) : string;
|
|
var
|
|
hs : string;
|
|
begin
|
|
str(e,hs);
|
|
{ replace space with + }
|
|
if hs[1]=' ' then
|
|
hs[1]:='+';
|
|
extended2str:='0d'+hs
|
|
end;
|
|
|
|
|
|
{ convert floating point values }
|
|
{ to correct endian }
|
|
procedure swap64bitarray(var t: t64bitarray);
|
|
var
|
|
b: byte;
|
|
begin
|
|
b:= t[7];
|
|
t[7] := t[0];
|
|
t[0] := b;
|
|
|
|
b := t[6];
|
|
t[6] := t[1];
|
|
t[1] := b;
|
|
|
|
b:= t[5];
|
|
t[5] := t[2];
|
|
t[2] := b;
|
|
|
|
b:= t[4];
|
|
t[4] := t[3];
|
|
t[3] := b;
|
|
end;
|
|
|
|
|
|
procedure swap32bitarray(var t: t32bitarray);
|
|
var
|
|
b: byte;
|
|
begin
|
|
b:= t[1];
|
|
t[1]:= t[2];
|
|
t[2]:= b;
|
|
|
|
b:= t[0];
|
|
t[0]:= t[3];
|
|
t[3]:= b;
|
|
end;
|
|
|
|
|
|
const
|
|
ait_const2str : array[aitconst_128bit..aitconst_indirect_symbol] of string[20]=(
|
|
#9'.fixme128'#9,#9'.quad'#9,#9'.long'#9,#9'.short'#9,#9'.byte'#9,
|
|
#9'.sleb128'#9,#9'.uleb128'#9,
|
|
#9'.rva'#9,#9'.indirect_symbol'#9
|
|
);
|
|
|
|
{****************************************************************************}
|
|
{ GNU Assembler writer }
|
|
{****************************************************************************}
|
|
|
|
destructor TGNUAssembler.Destroy;
|
|
begin
|
|
InstrWriter.free;
|
|
inherited destroy;
|
|
end;
|
|
|
|
|
|
function TGNUAssembler.MakeCmdLine: TCmdStr;
|
|
begin
|
|
result := inherited MakeCmdLine;
|
|
// MWE: disabled again. It generates dwarf info for the generated .s
|
|
// files as well. This conflicts with the info we generate
|
|
// if target_dbg.id = dbg_dwarf then
|
|
// result := result + ' --gdwarf-2';
|
|
end;
|
|
|
|
|
|
function TGNUAssembler.NextSetLabel: string;
|
|
begin
|
|
inc(setcount);
|
|
result := target_asm.labelprefix+'$set$'+tostr(setcount);
|
|
end;
|
|
|
|
function TGNUAssembler.sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
|
|
const
|
|
secnames : array[TAsmSectiontype] of string[17] = ('',
|
|
'.text',
|
|
'.data',
|
|
{ why doesn't .rodata work? (FK) }
|
|
{$warning TODO .rodata not yet working}
|
|
{$if defined(arm) or defined(powerpc)}
|
|
'.rodata',
|
|
{$else arm}
|
|
'.data',
|
|
{$endif arm}
|
|
'.bss',
|
|
'.threadvar',
|
|
'.pdata',
|
|
'', { stubs }
|
|
'.stab',
|
|
'.stabstr',
|
|
'.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
|
|
'.eh_frame',
|
|
'.debug_frame','.debug_info','.debug_line','.debug_abbrev',
|
|
'.fpc',
|
|
'.toc',
|
|
'.init'
|
|
);
|
|
secnames_pic : array[TAsmSectiontype] of string[17] = ('',
|
|
'.text',
|
|
'.data.rel',
|
|
'.data.rel',
|
|
'.bss',
|
|
'.threadvar',
|
|
'.pdata',
|
|
'', { stubs }
|
|
'.stab',
|
|
'.stabstr',
|
|
'.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
|
|
'.eh_frame',
|
|
'.debug_frame','.debug_info','.debug_line','.debug_abbrev',
|
|
'.fpc',
|
|
'.toc',
|
|
'.init'
|
|
);
|
|
var
|
|
sep : string[3];
|
|
secname : string;
|
|
begin
|
|
if (cs_create_pic in current_settings.moduleswitches) and
|
|
not(target_info.system in systems_darwin) then
|
|
secname:=secnames_pic[atype]
|
|
else
|
|
secname:=secnames[atype];
|
|
{$ifdef m68k}
|
|
{ old Amiga GNU AS doesn't support .section .fpc }
|
|
if (atype=sec_fpc) and (target_info.system = system_m68k_amiga) then
|
|
secname:=secnames[sec_data];
|
|
{$endif}
|
|
if (atype=sec_fpc) and (Copy(aname,1,3)='res') then
|
|
begin
|
|
result:=secname+'.'+aname;
|
|
exit;
|
|
end;
|
|
|
|
if (atype=sec_threadvar) and
|
|
(target_info.system=system_i386_win32) then
|
|
secname:='.tls';
|
|
|
|
{ For bss we need to set some flags that are target dependent,
|
|
it is easier to disable it for smartlinking. It doesn't take up
|
|
filespace }
|
|
if not(target_info.system in systems_darwin) and
|
|
use_smartlink_section and
|
|
(aname<>'') and
|
|
(atype <> sec_toc) and
|
|
(atype<>sec_bss) then
|
|
begin
|
|
case aorder of
|
|
secorder_begin :
|
|
sep:='.b_';
|
|
secorder_end :
|
|
sep:='.z_';
|
|
else
|
|
sep:='.n_';
|
|
end;
|
|
result:=secname+sep+aname
|
|
end
|
|
else
|
|
result:=secname;
|
|
end;
|
|
|
|
|
|
procedure TGNUAssembler.WriteSection(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder);
|
|
var
|
|
s : string;
|
|
begin
|
|
AsmLn;
|
|
case target_info.system of
|
|
system_i386_OS2,
|
|
system_i386_EMX,
|
|
system_m68k_amiga, { amiga has old GNU AS (2.14), which blews up from .section (KB) }
|
|
system_m68k_linux: ;
|
|
system_powerpc_darwin,
|
|
system_i386_darwin,
|
|
system_powerpc64_darwin,
|
|
system_x86_64_darwin:
|
|
begin
|
|
if (atype = sec_stub) then
|
|
AsmWrite('.section ');
|
|
end
|
|
else
|
|
AsmWrite('.section ');
|
|
end;
|
|
s:=sectionname(atype,aname,aorder);
|
|
AsmWrite(s);
|
|
case atype of
|
|
sec_fpc :
|
|
if aname = 'resptrs' then
|
|
AsmWrite(', "a", @progbits');
|
|
sec_stub :
|
|
begin
|
|
case target_info.system of
|
|
{ there are processor-independent shortcuts available }
|
|
{ for this, namely .symbol_stub and .picsymbol_stub, but }
|
|
{ they don't work and gcc doesn't use them either... }
|
|
system_powerpc_darwin,
|
|
system_powerpc64_darwin:
|
|
AsmWriteln('__TEXT,__symbol_stub1,symbol_stubs,pure_instructions,16');
|
|
system_i386_darwin:
|
|
AsmWriteln('__IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5');
|
|
{ darwin/x86-64 uses RIP-based GOT addressing }
|
|
else
|
|
internalerror(2006031101);
|
|
end;
|
|
end;
|
|
end;
|
|
AsmLn;
|
|
CurrSecType:=atype;
|
|
end;
|
|
|
|
|
|
procedure TGNUAssembler.WriteDecodedUleb128(a: qword);
|
|
var
|
|
i,len : longint;
|
|
buf : array[0..63] of byte;
|
|
begin
|
|
len:=EncodeUleb128(a,buf);
|
|
for i:=0 to len-1 do
|
|
begin
|
|
if (i > 0) then
|
|
AsmWrite(',');
|
|
AsmWrite(tostr(buf[i]));
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TGNUAssembler.WriteDecodedSleb128(a: int64);
|
|
var
|
|
i,len : longint;
|
|
buf : array[0..255] of byte;
|
|
begin
|
|
len:=EncodeSleb128(a,buf);
|
|
for i:=0 to len-1 do
|
|
begin
|
|
if (i > 0) then
|
|
AsmWrite(',');
|
|
AsmWrite(tostr(buf[i]));
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TGNUAssembler.WriteTree(p:TAsmList);
|
|
|
|
function needsObject(hp : tai_symbol) : boolean;
|
|
begin
|
|
needsObject :=
|
|
(
|
|
assigned(hp.next) and
|
|
(tai(hp.next).typ in [ait_const,ait_datablock,
|
|
ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit])
|
|
) or
|
|
(hp.sym.typ=AT_DATA);
|
|
|
|
end;
|
|
|
|
var
|
|
ch : char;
|
|
hp : tai;
|
|
hp1 : tailineinfo;
|
|
constdef : taiconst_type;
|
|
s,t : string;
|
|
i,pos,l : longint;
|
|
InlineLevel : longint;
|
|
last_align : longint;
|
|
co : comp;
|
|
sin : single;
|
|
d : double;
|
|
{$ifdef cpuextended}
|
|
e : extended;
|
|
{$endif cpuextended}
|
|
do_line : boolean;
|
|
|
|
sepChar : char;
|
|
nextdwarffileidx : longint;
|
|
begin
|
|
if not assigned(p) then
|
|
exit;
|
|
|
|
nextdwarffileidx:=1;
|
|
|
|
last_align := 2;
|
|
InlineLevel:=0;
|
|
{ lineinfo is only needed for al_procedures (PFV) }
|
|
do_line:=(cs_asm_source in current_settings.globalswitches) or
|
|
((cs_lineinfo in current_settings.moduleswitches)
|
|
and (p=current_asmdata.asmlists[al_procedures]));
|
|
hp:=tai(p.first);
|
|
while assigned(hp) do
|
|
begin
|
|
if not(hp.typ in SkipLineInfo) then
|
|
begin
|
|
hp1 := hp as tailineinfo;
|
|
current_filepos:=hp1.fileinfo;
|
|
{ no line info for inlined code }
|
|
if do_line and (inlinelevel=0) then
|
|
begin
|
|
{ load infile }
|
|
if lastfileinfo.fileindex<>hp1.fileinfo.fileindex then
|
|
begin
|
|
infile:=current_module.sourcefiles.get_file(hp1.fileinfo.fileindex);
|
|
if assigned(infile) then
|
|
begin
|
|
{ open only if needed !! }
|
|
if (cs_asm_source in current_settings.globalswitches) then
|
|
infile.open;
|
|
end;
|
|
{ avoid unnecessary reopens of the same file !! }
|
|
lastfileinfo.fileindex:=hp1.fileinfo.fileindex;
|
|
{ be sure to change line !! }
|
|
lastfileinfo.line:=-1;
|
|
end;
|
|
{ write source }
|
|
if (cs_asm_source in current_settings.globalswitches) and
|
|
assigned(infile) then
|
|
begin
|
|
if (infile<>lastinfile) then
|
|
begin
|
|
AsmWriteLn(target_asm.comment+'['+infile.name^+']');
|
|
if assigned(lastinfile) then
|
|
lastinfile.close;
|
|
end;
|
|
if (hp1.fileinfo.line<>lastfileinfo.line) and
|
|
((hp1.fileinfo.line<infile.maxlinebuf) or (InlineLevel>0)) then
|
|
begin
|
|
if (hp1.fileinfo.line<>0) and
|
|
((infile.linebuf^[hp1.fileinfo.line]>=0) or (InlineLevel>0)) then
|
|
AsmWriteLn(target_asm.comment+'['+tostr(hp1.fileinfo.line)+'] '+
|
|
fixline(infile.GetLineStr(hp1.fileinfo.line)));
|
|
{ set it to a negative value !
|
|
to make that is has been read already !! PM }
|
|
if (infile.linebuf^[hp1.fileinfo.line]>=0) then
|
|
infile.linebuf^[hp1.fileinfo.line]:=-infile.linebuf^[hp1.fileinfo.line]-1;
|
|
end;
|
|
end;
|
|
lastfileinfo:=hp1.fileinfo;
|
|
lastinfile:=infile;
|
|
end;
|
|
end;
|
|
|
|
case hp.typ of
|
|
|
|
ait_comment :
|
|
Begin
|
|
AsmWrite(target_asm.comment);
|
|
AsmWritePChar(tai_comment(hp).str);
|
|
AsmLn;
|
|
End;
|
|
|
|
ait_regalloc :
|
|
begin
|
|
if (cs_asm_regalloc in current_settings.globalswitches) then
|
|
begin
|
|
AsmWrite(#9+target_asm.comment+'Register ');
|
|
repeat
|
|
AsmWrite(std_regname(Tai_regalloc(hp).reg));
|
|
if (hp.next=nil) or
|
|
(tai(hp.next).typ<>ait_regalloc) or
|
|
(tai_regalloc(hp.next).ratype<>tai_regalloc(hp).ratype) then
|
|
break;
|
|
hp:=tai(hp.next);
|
|
AsmWrite(',');
|
|
until false;
|
|
AsmWrite(' ');
|
|
AsmWriteLn(regallocstr[tai_regalloc(hp).ratype]);
|
|
end;
|
|
end;
|
|
|
|
ait_tempalloc :
|
|
begin
|
|
if (cs_asm_tempalloc in current_settings.globalswitches) then
|
|
begin
|
|
{$ifdef EXTDEBUG}
|
|
if assigned(tai_tempalloc(hp).problem) then
|
|
AsmWriteLn(target_asm.comment+'Temp '+tostr(tai_tempalloc(hp).temppos)+','+
|
|
tostr(tai_tempalloc(hp).tempsize)+' '+tai_tempalloc(hp).problem^)
|
|
else
|
|
{$endif EXTDEBUG}
|
|
AsmWriteLn(target_asm.comment+'Temp '+tostr(tai_tempalloc(hp).temppos)+','+
|
|
tostr(tai_tempalloc(hp).tempsize)+' '+tempallocstr[tai_tempalloc(hp).allocation]);
|
|
end;
|
|
end;
|
|
|
|
ait_align :
|
|
begin
|
|
if tai_align_abstract(hp).aligntype>1 then
|
|
begin
|
|
if not(target_info.system in systems_darwin) then
|
|
begin
|
|
AsmWrite(#9'.balign '+tostr(tai_align_abstract(hp).aligntype));
|
|
if tai_align_abstract(hp).use_op then
|
|
AsmWrite(','+tostr(tai_align_abstract(hp).fillop))
|
|
{$ifdef x86}
|
|
{ force NOP as alignment op code }
|
|
else if CurrSecType=sec_code then
|
|
AsmWrite(',0x90');
|
|
{$endif x86}
|
|
end
|
|
else
|
|
begin
|
|
{ darwin as only supports .align }
|
|
if not ispowerof2(tai_align_abstract(hp).aligntype,i) then
|
|
internalerror(2003010305);
|
|
AsmWrite(#9'.align '+tostr(i));
|
|
last_align := i;
|
|
end;
|
|
AsmLn;
|
|
end;
|
|
end;
|
|
|
|
ait_section :
|
|
begin
|
|
if tai_section(hp).sectype<>sec_none then
|
|
WriteSection(tai_section(hp).sectype,tai_section(hp).name^,tai_section(hp).secorder)
|
|
else
|
|
begin
|
|
{$ifdef EXTDEBUG}
|
|
AsmWrite(target_asm.comment);
|
|
AsmWriteln(' sec_none');
|
|
{$endif EXTDEBUG}
|
|
end;
|
|
end;
|
|
|
|
ait_datablock :
|
|
begin
|
|
if (target_info.system in systems_darwin) then
|
|
begin
|
|
{On Mac OS X you can't have common symbols in a shared
|
|
library, since those are in the TEXT section and the text section is
|
|
read-only in shared libraries (so it can be shared among different
|
|
processes). The alternate code creates some kind of common symbols in
|
|
the data segment. The generic code no longer uses common symbols, but
|
|
this doesn't work on Mac OS X as well.}
|
|
if tai_datablock(hp).is_global then
|
|
begin
|
|
asmwrite('.globl ');
|
|
asmwriteln(tai_datablock(hp).sym.name);
|
|
asmwriteln('.data');
|
|
asmwrite('.zerofill __DATA, __common, ');
|
|
asmwrite(tai_datablock(hp).sym.name);
|
|
asmwriteln(', '+tostr(tai_datablock(hp).size)+','+tostr(last_align));
|
|
if not(CurrSecType in [sec_data,sec_none]) then
|
|
writesection(CurrSecType,'',secorder_default);
|
|
end
|
|
else
|
|
begin
|
|
asmwrite(#9'.lcomm'#9);
|
|
asmwrite(tai_datablock(hp).sym.name);
|
|
asmwrite(','+tostr(tai_datablock(hp).size));
|
|
asmwrite(','+tostr(last_align));
|
|
asmln;
|
|
end
|
|
end
|
|
else
|
|
begin
|
|
{ The .comm is required for COMMON symbols. These are used
|
|
in the shared library loading. All the symbols declared in
|
|
the .so file need to resolve to the data allocated in the main
|
|
program (PFV) }
|
|
if Tai_datablock(hp).is_global then
|
|
begin
|
|
asmwrite(#9'.comm'#9);
|
|
asmwrite(tai_datablock(hp).sym.name);
|
|
asmwrite(','+tostr(tai_datablock(hp).size));
|
|
asmln;
|
|
end
|
|
else
|
|
begin
|
|
asmwrite(#9'.lcomm'#9);
|
|
asmwrite(tai_datablock(hp).sym.name);
|
|
asmwrite(','+tostr(tai_datablock(hp).size));
|
|
asmln;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
ait_const:
|
|
begin
|
|
constdef:=tai_const(hp).consttype;
|
|
case constdef of
|
|
{$ifndef cpu64bit}
|
|
aitconst_128bit :
|
|
begin
|
|
internalerror(200404291);
|
|
end;
|
|
|
|
aitconst_64bit :
|
|
begin
|
|
if assigned(tai_const(hp).sym) then
|
|
internalerror(200404292);
|
|
AsmWrite(ait_const2str[aitconst_32bit]);
|
|
if target_info.endian = endian_little then
|
|
begin
|
|
AsmWrite(tostr(longint(lo(tai_const(hp).value))));
|
|
AsmWrite(',');
|
|
AsmWrite(tostr(longint(hi(tai_const(hp).value))));
|
|
end
|
|
else
|
|
begin
|
|
AsmWrite(tostr(longint(hi(tai_const(hp).value))));
|
|
AsmWrite(',');
|
|
AsmWrite(tostr(longint(lo(tai_const(hp).value))));
|
|
end;
|
|
AsmLn;
|
|
end;
|
|
{$endif cpu64bit}
|
|
aitconst_uleb128bit,
|
|
aitconst_sleb128bit,
|
|
{$ifdef cpu64bit}
|
|
aitconst_128bit,
|
|
aitconst_64bit,
|
|
{$endif cpu64bit}
|
|
aitconst_32bit,
|
|
aitconst_16bit,
|
|
aitconst_8bit,
|
|
aitconst_rva_symbol,
|
|
aitconst_indirect_symbol :
|
|
begin
|
|
if (target_info.system in systems_darwin) and
|
|
(tai_const(hp).consttype in [aitconst_uleb128bit,aitconst_sleb128bit]) then
|
|
begin
|
|
AsmWrite(ait_const2str[aitconst_8bit]);
|
|
case tai_const(hp).consttype of
|
|
aitconst_uleb128bit:
|
|
WriteDecodedUleb128(qword(tai_const(hp).value));
|
|
aitconst_sleb128bit:
|
|
WriteDecodedSleb128(int64(tai_const(hp).value));
|
|
end
|
|
end
|
|
else
|
|
begin
|
|
AsmWrite(ait_const2str[tai_const(hp).consttype]);
|
|
l:=0;
|
|
t := '';
|
|
repeat
|
|
if assigned(tai_const(hp).sym) then
|
|
begin
|
|
if assigned(tai_const(hp).endsym) then
|
|
begin
|
|
if (target_info.system in systems_darwin) then
|
|
begin
|
|
s := NextSetLabel;
|
|
t := #9'.set '+s+','+tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name;
|
|
end
|
|
else
|
|
s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
|
|
end
|
|
else
|
|
s:=tai_const(hp).sym.name;
|
|
if tai_const(hp).value<>0 then
|
|
s:=s+tostr_with_plus(tai_const(hp).value);
|
|
end
|
|
else
|
|
s:=tostr(tai_const(hp).value);
|
|
AsmWrite(s);
|
|
inc(l,length(s));
|
|
{ Values with symbols are written on a single line to improve
|
|
reading of the .s file (PFV) }
|
|
if assigned(tai_const(hp).sym) or
|
|
not(CurrSecType in [sec_data,sec_rodata]) or
|
|
(l>line_length) or
|
|
(hp.next=nil) or
|
|
(tai(hp.next).typ<>ait_const) or
|
|
(tai_const(hp.next).consttype<>constdef) or
|
|
assigned(tai_const(hp.next).sym) then
|
|
break;
|
|
hp:=tai(hp.next);
|
|
AsmWrite(',');
|
|
until false;
|
|
if (t <> '') then
|
|
begin
|
|
AsmLn;
|
|
AsmWrite(t);
|
|
end;
|
|
end;
|
|
AsmLn;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
{ the "and defined(FPC_HAS_TYPE_EXTENDED)" isn't optimal but currently the only solution
|
|
it prevents proper cross compilation to i386 though
|
|
}
|
|
{$if defined(cpuextended) and defined(FPC_HAS_TYPE_EXTENDED)}
|
|
ait_real_80bit :
|
|
begin
|
|
if do_line then
|
|
AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_real_80bit(hp).value));
|
|
{ Make sure e is a extended type, bestreal could be
|
|
a different type (bestreal) !! (PFV) }
|
|
e:=tai_real_80bit(hp).value;
|
|
AsmWrite(#9'.byte'#9);
|
|
for i:=0 to 9 do
|
|
begin
|
|
if i<>0 then
|
|
AsmWrite(',');
|
|
AsmWrite(tostr(t80bitarray(e)[i]));
|
|
end;
|
|
AsmLn;
|
|
end;
|
|
{$endif cpuextended}
|
|
|
|
ait_real_64bit :
|
|
begin
|
|
if do_line then
|
|
AsmWriteLn(target_asm.comment+'value: '+double2str(tai_real_64bit(hp).value));
|
|
d:=tai_real_64bit(hp).value;
|
|
{ swap the values to correct endian if required }
|
|
if source_info.endian <> target_info.endian then
|
|
swap64bitarray(t64bitarray(d));
|
|
AsmWrite(#9'.byte'#9);
|
|
{$ifdef arm}
|
|
{ on a real arm cpu, it's already hi/lo swapped }
|
|
{$ifndef cpuarm}
|
|
if tai_real_64bit(hp).formatoptions=fo_hiloswapped then
|
|
begin
|
|
for i:=4 to 7 do
|
|
begin
|
|
if i<>4 then
|
|
AsmWrite(',');
|
|
AsmWrite(tostr(t64bitarray(d)[i]));
|
|
end;
|
|
for i:=0 to 3 do
|
|
begin
|
|
AsmWrite(',');
|
|
AsmWrite(tostr(t64bitarray(d)[i]));
|
|
end;
|
|
end
|
|
else
|
|
{$endif cpuarm}
|
|
{$endif arm}
|
|
begin
|
|
for i:=0 to 7 do
|
|
begin
|
|
if i<>0 then
|
|
AsmWrite(',');
|
|
AsmWrite(tostr(t64bitarray(d)[i]));
|
|
end;
|
|
end;
|
|
AsmLn;
|
|
end;
|
|
|
|
ait_real_32bit :
|
|
begin
|
|
if do_line then
|
|
AsmWriteLn(target_asm.comment+'value: '+single2str(tai_real_32bit(hp).value));
|
|
sin:=tai_real_32bit(hp).value;
|
|
{ swap the values to correct endian if required }
|
|
if source_info.endian <> target_info.endian then
|
|
swap32bitarray(t32bitarray(sin));
|
|
AsmWrite(#9'.byte'#9);
|
|
for i:=0 to 3 do
|
|
begin
|
|
if i<>0 then
|
|
AsmWrite(',');
|
|
AsmWrite(tostr(t32bitarray(sin)[i]));
|
|
end;
|
|
AsmLn;
|
|
end;
|
|
|
|
ait_comp_64bit :
|
|
begin
|
|
if do_line then
|
|
AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_comp_64bit(hp).value));
|
|
AsmWrite(#9'.byte'#9);
|
|
co:=comp(tai_comp_64bit(hp).value);
|
|
{ swap the values to correct endian if required }
|
|
if source_info.endian <> target_info.endian then
|
|
swap64bitarray(t64bitarray(co));
|
|
for i:=0 to 7 do
|
|
begin
|
|
if i<>0 then
|
|
AsmWrite(',');
|
|
AsmWrite(tostr(t64bitarray(co)[i]));
|
|
end;
|
|
AsmLn;
|
|
end;
|
|
|
|
ait_string :
|
|
begin
|
|
pos:=0;
|
|
for i:=1 to tai_string(hp).len do
|
|
begin
|
|
if pos=0 then
|
|
begin
|
|
AsmWrite(#9'.ascii'#9'"');
|
|
pos:=20;
|
|
end;
|
|
ch:=tai_string(hp).str[i-1];
|
|
case ch of
|
|
#0, {This can't be done by range, because a bug in FPC}
|
|
#1..#31,
|
|
#128..#255 : s:='\'+tostr(ord(ch) shr 6)+tostr((ord(ch) and 63) shr 3)+tostr(ord(ch) and 7);
|
|
'"' : s:='\"';
|
|
'\' : s:='\\';
|
|
else
|
|
s:=ch;
|
|
end;
|
|
AsmWrite(s);
|
|
inc(pos,length(s));
|
|
if (pos>line_length) or (i=tai_string(hp).len) then
|
|
begin
|
|
AsmWriteLn('"');
|
|
pos:=0;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
ait_label :
|
|
begin
|
|
if (tai_label(hp).labsym.is_used) then
|
|
begin
|
|
if tai_label(hp).labsym.bind=AB_GLOBAL then
|
|
begin
|
|
AsmWrite('.globl'#9);
|
|
AsmWriteLn(tai_label(hp).labsym.name);
|
|
end;
|
|
AsmWrite(tai_label(hp).labsym.name);
|
|
AsmWriteLn(':');
|
|
end;
|
|
end;
|
|
|
|
ait_symbol :
|
|
begin
|
|
if (target_info.system = system_powerpc64_linux) and
|
|
(tai_symbol(hp).sym.typ = AT_FUNCTION) and (cs_profile in current_settings.moduleswitches) then
|
|
begin
|
|
AsmWriteLn('.globl _mcount');
|
|
end;
|
|
if tai_symbol(hp).is_global then
|
|
begin
|
|
AsmWrite('.globl'#9);
|
|
AsmWriteLn(tai_symbol(hp).sym.name);
|
|
end;
|
|
if (target_info.system = system_powerpc64_linux) and
|
|
(tai_symbol(hp).sym.typ = AT_FUNCTION) then
|
|
begin
|
|
AsmWriteLn('.section "opd", "aw"');
|
|
AsmWriteLn('.align 3');
|
|
AsmWriteLn(tai_symbol(hp).sym.name + ':');
|
|
AsmWriteLn('.quad .' + tai_symbol(hp).sym.name + ', .TOC.@tocbase, 0');
|
|
AsmWriteLn('.previous');
|
|
AsmWriteLn('.size ' + tai_symbol(hp).sym.name + ', 24');
|
|
if (tai_symbol(hp).is_global) then
|
|
AsmWriteLn('.globl .' + tai_symbol(hp).sym.name);
|
|
AsmWriteLn('.type .' + tai_symbol(hp).sym.name + ', @function');
|
|
{ the dotted name is the name of the actual function entry }
|
|
AsmWrite('.');
|
|
end
|
|
else
|
|
begin
|
|
if (target_info.system <> system_arm_linux) then
|
|
sepChar := '@'
|
|
else
|
|
sepChar := '#';
|
|
if (tf_needs_symbol_type in target_info.flags) then
|
|
begin
|
|
AsmWrite(#9'.type'#9 + tai_symbol(hp).sym.name);
|
|
if (needsObject(tai_symbol(hp))) then
|
|
AsmWriteLn(',' + sepChar + 'object')
|
|
else
|
|
AsmWriteLn(',' + sepChar + 'function');
|
|
end;
|
|
end;
|
|
AsmWriteLn(tai_symbol(hp).sym.name + ':');
|
|
end;
|
|
|
|
ait_symbol_end :
|
|
begin
|
|
if tf_needs_symbol_size in target_info.flags then
|
|
begin
|
|
s:=target_asm.labelprefix+'e'+tostr(symendcount);
|
|
inc(symendcount);
|
|
AsmWriteLn(s+':');
|
|
AsmWrite(#9'.size'#9);
|
|
if (target_info.system = system_powerpc64_linux) and (tai_symbol_end(hp).sym.typ = AT_FUNCTION) then
|
|
AsmWrite('.');
|
|
AsmWrite(tai_symbol_end(hp).sym.name);
|
|
AsmWrite(', '+s+' - ');
|
|
if (target_info.system = system_powerpc64_linux) and (tai_symbol_end(hp).sym.typ = AT_FUNCTION) then
|
|
AsmWrite('.');
|
|
AsmWriteLn(tai_symbol_end(hp).sym.name);
|
|
end;
|
|
end;
|
|
|
|
ait_instruction :
|
|
begin
|
|
WriteInstruction(hp);
|
|
end;
|
|
|
|
ait_stab :
|
|
begin
|
|
if assigned(tai_stab(hp).str) then
|
|
begin
|
|
AsmWrite(#9'.'+stabtypestr[tai_stab(hp).stabtype]+' ');
|
|
AsmWritePChar(tai_stab(hp).str);
|
|
AsmLn;
|
|
end;
|
|
end;
|
|
|
|
ait_file :
|
|
begin
|
|
tai_file(hp).idx:=nextdwarffileidx;
|
|
inc(nextdwarffileidx);
|
|
AsmWrite(#9'.file '+tostr(tai_file(hp).idx)+' "');
|
|
|
|
AsmWritePChar(tai_file(hp).str);
|
|
AsmWrite('"');
|
|
AsmLn;
|
|
end;
|
|
|
|
ait_loc :
|
|
begin
|
|
AsmWrite(#9'.loc '+tostr(tai_loc(hp).fileentry.idx)+' '+tostr(tai_loc(hp).line)+' '+tostr(tai_loc(hp).column));
|
|
AsmLn;
|
|
end;
|
|
|
|
ait_force_line,
|
|
ait_function_name : ;
|
|
|
|
ait_cutobject :
|
|
begin
|
|
if SmartAsm then
|
|
begin
|
|
{ only reset buffer if nothing has changed }
|
|
if AsmSize=AsmStartSize then
|
|
AsmClear
|
|
else
|
|
begin
|
|
AsmClose;
|
|
DoAssemble;
|
|
AsmCreate(tai_cutobject(hp).place);
|
|
end;
|
|
{ avoid empty files }
|
|
while assigned(hp.next) and (tai(hp.next).typ in [ait_cutobject,ait_section,ait_comment]) do
|
|
begin
|
|
if tai(hp.next).typ=ait_section then
|
|
CurrSecType:=tai_section(hp.next).sectype;
|
|
hp:=tai(hp.next);
|
|
end;
|
|
if CurrSecType<>sec_none then
|
|
WriteSection(CurrSecType,'',secorder_default);
|
|
AsmStartSize:=AsmSize;
|
|
|
|
{ reset dwarf file index }
|
|
nextdwarffileidx:=1;
|
|
end;
|
|
end;
|
|
|
|
ait_marker :
|
|
if tai_marker(hp).kind=mark_InlineStart then
|
|
inc(InlineLevel)
|
|
else if tai_marker(hp).kind=mark_InlineEnd then
|
|
dec(InlineLevel);
|
|
|
|
ait_directive :
|
|
begin
|
|
AsmWrite('.'+directivestr[tai_directive(hp).directive]+' ');
|
|
if assigned(tai_directive(hp).name) then
|
|
AsmWrite(tai_directive(hp).name^);
|
|
AsmLn;
|
|
end;
|
|
|
|
else
|
|
internalerror(2006012201);
|
|
end;
|
|
hp:=tai(hp.next);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TGNUAssembler.WriteExtraHeader;
|
|
begin
|
|
end;
|
|
|
|
|
|
procedure TGNUAssembler.WriteInstruction(hp: tai);
|
|
begin
|
|
InstrWriter.WriteInstruction(hp);
|
|
end;
|
|
|
|
|
|
procedure TGNUAssembler.WriteAsmList;
|
|
var
|
|
n : string;
|
|
hal : tasmlisttype;
|
|
begin
|
|
{$ifdef EXTDEBUG}
|
|
if assigned(current_module.mainsource) then
|
|
Comment(V_Debug,'Start writing gas-styled assembler output for '+current_module.mainsource^);
|
|
{$endif}
|
|
|
|
CurrSecType:=sec_none;
|
|
FillChar(lastfileinfo,sizeof(lastfileinfo),0);
|
|
LastInfile:=nil;
|
|
|
|
if assigned(current_module.mainsource) then
|
|
n:=ExtractFileName(current_module.mainsource^)
|
|
else
|
|
n:=InputFileName;
|
|
AsmWriteLn(#9'.file "'+FixFileName(n)+'"');
|
|
WriteExtraHeader;
|
|
AsmStartSize:=AsmSize;
|
|
symendcount:=0;
|
|
|
|
for hal:=low(TasmlistType) to high(TasmlistType) do
|
|
begin
|
|
AsmWriteLn(target_asm.comment+'Begin asmlist '+AsmlistTypeStr[hal]);
|
|
writetree(current_asmdata.asmlists[hal]);
|
|
AsmWriteLn(target_asm.comment+'End asmlist '+AsmlistTypeStr[hal]);
|
|
end;
|
|
|
|
{
|
|
Result doesn't work properly yet due to a bug in Apple's linker
|
|
|
|
if (cs_create_smart in current_settings.moduleswitches) and
|
|
(target_info.system in systems_darwin) then
|
|
AsmWriteLn(#9'.subsections_via_symbols');
|
|
}
|
|
|
|
AsmLn;
|
|
{$ifdef EXTDEBUG}
|
|
if assigned(current_module.mainsource) then
|
|
Comment(V_Debug,'Done writing gas-styled assembler output for '+current_module.mainsource^);
|
|
{$endif EXTDEBUG}
|
|
end;
|
|
|
|
|
|
{****************************************************************************}
|
|
{ Apple/GNU Assembler writer }
|
|
{****************************************************************************}
|
|
|
|
function TAppleGNUAssembler.sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
|
|
begin
|
|
if (target_info.system in systems_darwin) then
|
|
case atype of
|
|
sec_bss:
|
|
{ all bss (lcomm) symbols are automatically put in the right }
|
|
{ place by using the lcomm assembler directive }
|
|
atype := sec_none;
|
|
sec_debug_frame,
|
|
sec_eh_frame:
|
|
begin
|
|
result := '.section __DWARFA,__debug_frame,coalesced,no_toc+strip_static_syms'#10'EH_frame'+tostr(debugframecount)+':';
|
|
inc(debugframecount);
|
|
exit;
|
|
end;
|
|
sec_debug_line:
|
|
begin
|
|
result := '.section __DWARF,__debug_line,regular,debug';
|
|
exit;
|
|
end;
|
|
sec_debug_info:
|
|
begin
|
|
result := '.section __DWARF,__debug_info,regular,debug';
|
|
exit;
|
|
end;
|
|
sec_debug_abbrev:
|
|
begin
|
|
result := '.section __DWARF,__debug_abbrev,regular,debug';
|
|
exit;
|
|
end;
|
|
sec_rodata:
|
|
begin
|
|
result := '.const';
|
|
exit;
|
|
end;
|
|
sec_fpc:
|
|
begin
|
|
result := '.section __TEXT, .fpc, regular, no_dead_strip';
|
|
exit;
|
|
end;
|
|
end;
|
|
result := inherited sectionname(atype,aname,aorder);
|
|
end;
|
|
|
|
|
|
{****************************************************************************}
|
|
{ Abstract Instruction Writer }
|
|
{****************************************************************************}
|
|
|
|
constructor TCPUInstrWriter.create(_owner: TGNUAssembler);
|
|
begin
|
|
inherited create;
|
|
owner := _owner;
|
|
end;
|
|
|
|
end.
|