File: asmutils.pas

package info (click to toggle)
fpc 2.6.4%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 178,760 kB
  • ctags: 83,946
  • sloc: pascal: 2,000,374; xml: 138,807; ansic: 9,617; asm: 7,843; yacc: 3,747; php: 3,271; sh: 2,626; makefile: 2,610; lex: 2,537; sql: 267; cpp: 145; sed: 132; perl: 126; csh: 34; tcl: 7
file content (118 lines) | stat: -rw-r--r-- 4,203 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{
    Copyright (c) 1998-2006 by Florian Klaempfl

    This unit contains utility functions for assembler output

    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.

 ****************************************************************************
}
unit asmutils;

interface

{$i fpcdefs.inc}

uses
  aasmbase,
  aasmdata;


    function emit_ansistring_const(list:TAsmList;data:PChar;len:LongInt;NewSection:Boolean=True):TAsmLabel;
    function emit_unicodestring_const(list:TAsmList;data:Pointer;Winlike:Boolean):TAsmLabel;


implementation

uses
  globals,
  globtype,
  systems,
  verbose,
  aasmtai,
  widestr,
  symdef;

    function emit_ansistring_const(list:TAsmList;data:PChar;len:LongInt;NewSection:Boolean): TAsmLabel;
      var
        referencelab: TAsmLabel;
        s: PChar;
      begin
        current_asmdata.getdatalabel(result);
        if NewSection then
          new_section(list,sec_rodata,result.name,const_align(sizeof(pint)));
        referencelab := nil;
        if target_info.system in systems_darwin then
          begin
            current_asmdata.getdatalabel(referencelab);
            list.concat(tai_label.create(referencelab));
          end;
        list.concat(tai_const.create_pint(-1));
        list.concat(tai_const.create_pint(len));
        { make sure the string doesn't get dead stripped if the header is referenced }
        if target_info.system in systems_darwin then
          list.concat(tai_directive.create(asd_reference,result.name));
        list.concat(tai_label.create(result));
        { and vice versa }
        if target_info.system in systems_darwin then
          list.concat(tai_directive.create(asd_reference,referencelab.name));

        getmem(s,len+1);
        move(data^,s^,len);
        s[len]:=#0;
        list.concat(tai_string.create_pchar(s,len+1)); { terminating zero included }
      end;

    function emit_unicodestring_const(list:TAsmList;data:Pointer;Winlike:Boolean):TAsmLabel;
      var
        referencelab: TAsmLabel;
        i, strlength: SizeInt;
      begin
        current_asmdata.getdatalabel(result);
        new_section(list,sec_rodata,result.name,const_align(sizeof(pint)));
        referencelab := nil;
        if target_info.system in systems_darwin then
          begin
            current_asmdata.getdatalabel(referencelab);
            list.concat(tai_label.create(referencelab));
          end;
        strlength := getlengthwidestring(pcompilerwidestring(data));
        if Winlike then
           list.concat(Tai_const.Create_32bit(strlength*cwidechartype.size))
        else
          begin
            list.concat(Tai_const.Create_pint(-1));
            list.concat(Tai_const.Create_pint(strlength*cwidechartype.size));
          end;
        { make sure the string doesn't get dead stripped if the header is referenced }
        if (target_info.system in systems_darwin) then
          list.concat(tai_directive.create(asd_reference,result.name));
        list.concat(Tai_label.Create(result));
        { ... and vice versa }
        if (target_info.system in systems_darwin) then
          list.concat(tai_directive.create(asd_reference,referencelab.name));
        if cwidechartype.size = 2 then
          begin
            for i:=0 to strlength-1 do
              list.concat(Tai_const.Create_16bit(pcompilerwidestring(data)^.data[i]));
            { ending #0 }
            list.concat(Tai_const.Create_16bit(0));
          end
        else
          InternalError(200904271); { codegeneration for other sizes must be written }
      end;


end.