source: branches/working-0711/ccl/lisp-kernel/m4macros.m4 @ 9968

Last change on this file since 9968 was 9968, checked in by gb, 11 years ago

Change how line number info is generated, mostly to deal with
macros on Darwin.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
Line 
1changequote([,])
2changecom([/* ],[*/])
3
4
5
6/*   Copyright (C) 1994-2001 Digitool, Inc  */
7/*   This file is part of OpenMCL.    */
8
9/*   OpenMCL is licensed under the terms of the Lisp Lesser GNU Public  */
10/*   License , known as the LLGPL and distributed with OpenMCL as the  */
11/*   file "LICENSE".  The LLGPL consists of a preamble and the LGPL,  */
12/*   which is distributed with OpenMCL as the file "LGPL".  Where these  */
13/*   conflict, the preamble takes precedence.    */
14
15/*   OpenMCL is referenced in the preamble as the "LIBRARY."  */
16
17/*   The LLGPL is also available online at  */
18/*   http://opensource.franz.com/preamble.html  */
19
20
21
22/*  BSD debugging information (line numbers, etc) is a little different  */
23/*  from ELF/SVr4 debugging information.  There are probably lots more  */
24/*  differences, but this helps us to distinguish between what LinuxPPC  */
25/*  (ELF/SVr4) wants and what Darwin(BSD) wants.  */
26
27
28define([BSDstabs],[1])
29define([ELFstabs],[2])
30define([COFFstabs],[3])
31undefine([EABI])
32undefine([POWEROPENABI])
33undefine([rTOC])
34
35
36ifdef([DARWIN],[define([SYSstabs],[BSDstabs])
37                define([DarwinAssembler],[])
38                define([CNamesNeedUnderscores],[])
39                define([LocalLabelPrefix],[L])
40                define([StartTextLabel],[Ltext0])
41                define([EndTextLabel],[Letext])
42                ifdef([PPC],[
43                define([POWEROPENABI],[])])
44                ifdef([X86],[
45                define([SYSCALL_SETS_CARRY_ON_ERROR],[])])
46])
47
48ifdef([LINUX],[define([SYSstabs],[ELFstabs])
49               define([HaveWeakSymbols],[])
50               define([LocalLabelPrefix],[.L])
51               define([StartTextLabel],[.Ltext0])
52               define([EndTextLabel],[.Letext])
53               ifdef([PPC64],[
54               define([POWEROPENABI],[])
55               define([rTOC],[r2])], [
56               define([EABI],[])])])
57
58ifdef([FREEBSD],[define([SYSstabs],[ELFstabs])
59               define([HaveWeakSymbols],[])
60               define([LocalLabelPrefix],[.L])
61               define([StartTextLabel],[.Ltext0])
62               define([EndTextLabel],[.Letext])]
63                ifdef([X86],[
64                define([SYSCALL_SETS_CARRY_ON_ERROR],[])])
65)
66
67ifdef([SOLARIS],[define([SYSstabs],[ELFstabs])
68               define([HaveWeakSymbols],[])
69               define([LocalLabelPrefix],[.L])
70               define([StartTextLabel],[.Ltext0])
71               define([EndTextLabel],[.Letext])])
72
73ifdef([WIN64],[define([SYSstabs],[COFFstabs])
74               define([CNamesNeedUnderscores],[])
75               define([LocalLabelPrefix],[L])])
76
77
78/*  Names exported to (or imported from) C may need leading underscores.  */
79/*  Still.  After all these years.  Why ?  */
80
81define([C],[ifdef([CNamesNeedUnderscores],[[_]$1],[$1])])
82
83define([_linecounter_],0)
84
85define([_emit_BSD_source_line_stab],[
86ifdef([X86],[
87# __line__ "__file__" 1],[
88        .stabd 68,0,$1
89])])
90
91
92/*  We don't really do "weak importing" of symbols from a separate  */
93/*  subprims library anymore; if we ever do and the OS supports it,  */
94/*  here's how to say that we want it ...  */
95
96define([WEAK],[ifdef([HaveWeakSymbols],[
97        .weak $1
98],[
99        .globl $1
100])])
101
102define([_emit_ELF_source_line_stab],[
103  define([_linecounter_],incr(_linecounter_))
104        .stabn 68,0,$1,[.LM]_linecounter_[-]__func_name
105[.LM]_linecounter_:
106])
107
108define([_emit_COFF_source_line_stab],[
109        .loc 1 $1 0
110])
111
112
113define([emit_source_line_stab],[
114        ifelse(eval(SYSstabs),
115             eval(BSDstabs),
116              [_emit_BSD_source_line_stab($1)],
117              eval(SYSstabs),
118              eval(ELFstabs),
119              [_emit_ELF_source_line_stab($1)],
120              [_emit_COFF_source_line_stab($1)])])
121
122
123
124
125
126
127/*  Assemble a reference to the high half of a 32-bit constant,  */
128/*  possibly adjusted for sign-extension of thw low half.  */
129
130
131define([HA],[ifdef([DARWIN],[ha16($1)],[$1@ha])])
132
133 
134/*  Likewise for the low half, and for the high half without  */
135/*  concern for sign-extension of the low half.  */
136
137define([LO],[ifdef([DARWIN],[lo16($1)],[$1@l])])
138define([HI],[ifdef([DARWIN],[hi16($1)],[$1@hi])])
139
140/*  Note that m4 macros that could be expanded in the .text segment  */
141/*  need to advertise the current line number after they have finished  */
142/*  expanding.  That shouldn't be too onerous, if only because there  */
143/*  should not be too many of them.  */
144
145
146define([N_FUN],36)
147define([N_SO],100)
148
149/*    I wish that there was a less-dumb way of doing this.  */
150
151define([pwd0],esyscmd([/bin/pwd]))
152define([__pwd__],substr(pwd0,0,decr(len(pwd0)))[/])
153
154/*   _beginfile() -- gets line/file in synch, generates N_SO for file,  */
155/*   starts .text section  */
156
157
158define([_beginfile],[ifdef([WIN64],[
159        .file 1 "__file__"
160        .text
161],[
162        .stabs "__pwd__",N_SO,0,0,StartTextLabel()
163        .stabs "__file__",N_SO,0,0,StartTextLabel()
164ifdef([PPC64],[
165ifdef([DARWIN],[
166        .machine ppc64
167])])
168        .text
169StartTextLabel():
170# __line__ "__file__"
171])])
172
173define([_endfile],[
174ifdef([WIN64],[
175],[
176        .stabs "",N_SO,0,0,EndTextLabel()
177EndTextLabel():
178# __line__
179])
180])
181
182define([_startfn],[define([__func_name],$1)
183# __line__
184        ifelse(eval(SYSstabs),eval(ELFstabs),[
185        .type $1,@function
186])
187$1:
188ifdef([WIN64],[
189        .def    $1;     .scl    2;      .type   32;     .endef
190],[
191        .stabd 68,0,__line__
192        .stabs "$1:F1",36,0,__line__,$1
193])
194        .set func_start,$1
195# __line__ "__file__" 1 ])
196
197
198
199define([_exportfn],[
200        .globl $1
201        _startfn($1)
202ifdef([PPC64],[
203ifdef([LINUX],[
204        .global [.]$1
205[.]$1:
206])])
207# __line__
208])
209
210
211define([_endfn],[
212LocalLabelPrefix[]__func_name[999]:
213ifdef([WIN64],[
214],[
215        .stabs "",36,0,0,LocalLabelPrefix[]__func_name[999]-__func_name
216        .line __line__
217        ifelse(eval(SYSstabs),eval(ELFstabs),[
218        .size __func_name,LocalLabelPrefix[]__func_name[999]-__func_name
219])
220])
221        undefine([__func_name])
222])
223
224
225/* _struct(name,start_offset)  */
226/*   This just generates a bunch of assembler equates; m4  */
227/*   doesn't remember much of it ..  */
228
229define([_struct], [define([__struct_name],$1)
230 define([_struct_org_name], _$1_org)
231 define([_struct_base_name], _$1_base)
232        .set _struct_org_name,$2
233        .set _struct_base_name,_struct_org_name
234 ifelse($3,[],[
235  undefine([_struct_fixed_size_name])
236  ],[
237  define([_struct_fixed_size_name], _$1_fixed_size)
238        .set _struct_fixed_size_name,$3
239  ])
240])
241
242define([_struct_pad],[
243        .set _struct_org_name,_struct_org_name + $1
244])
245 
246define([_struct_label],[
247        .set __struct_name[.]$1, _struct_org_name
248])
249
250/*  _field(name,size)   */
251define([_field],[_struct_label($1) _struct_pad($2)])
252
253define([_halfword], [_field($1, 2)])
254define([_word], [_field($1, 4)])
255define([_dword],[_field($1, 8)])
256define([_node], [_field($1, node_size)])
257
258define([_ends],[ifdef([_struct_fixed_size_name],[
259        .set  __struct_name[.size],_struct_fixed_size_name
260        ],[
261        .set  __struct_name[.size], _struct_org_name-_struct_base_name
262        ])
263])
264
265
266/*   Lisp fixed-size objects always have a 1-word header  */
267/*   and are always accessed from a "fulltag_misc"-tagged pointer.  */
268/*   We also want to define STRUCT_NAME.element_count for each  */
269/*   such object.  */
270
271
272define([_structf],[
273        _struct($1,ifelse($2,[],-misc_bias,$2))
274        _node(header)
275])
276
277define([_endstructf],[
278        .set __struct_name.[element_count],((_struct_org_name-node_size)-_struct_base_name)/node_size
279        _ends
280])
281
282
283define([__],[emit_source_line_stab(__line__)
284        $@
285        ])
286
287define([__local_label_counter__],0)
288define([__macro_label_counter__],0)
289
290define([new_local_labels],
291  [define([__local_label_counter__],incr(__local_label_counter__))])
292
293define([new_macro_labels],
294  [define([__macro_label_counter__],incr(__macro_label_counter__))])
295
296define([_local_label],[LocalLabelPrefix()[]$1])
297
298define([local_label],[_local_label($1[]__local_label_counter__)])
299
300define([macro_label],[_local_label($1[]__macro_label_counter__)])
301
302
303/* The Darwin assembler doesn't seem to support .ifdef/.ifndef, but  */
304/* does understand .if.    */
305/* Note that using M4's own ifdef is certainly possible, but it's  */
306/* hard to generate source line information when doing so.  */
307
308 
309define([__ifdef],[ifdef([$1],[.if 1],[.if 0])])
310define([__ifndef],[ifdef([$1],[.if 0],[.if 1])])
311define([__else],[.else])
312define([__endif],[.endif])
313define([__if],[.if $1])
314
315define([equate_if_defined],[ifdef($1,[
316[$1] = 1
317],[
318[$1] = 0
319])])
320
321equate_if_defined([DARWIN])
322equate_if_defined([LINUX])
323equate_if_defined([FREEBSD])
324equate_if_defined([SOLARIS])
325equate_if_defined([WIN64])
326equate_if_defined([PPC64])
327equate_if_defined([X8664])
328
329equate_if_defined([HAVE_TLS])
330/* DARWIN_GS_HACK is hopefully short-lived */
331equate_if_defined([DARWIN_GS_HACK])
332
333equate_if_defined([SYSCALL_SETS_CARRY_ON_ERROR])
334
335
336
337/* We use (more-or-less) a PowerOpen C frame, except on LinuxPPC32  */
338
339define([USE_POWEROPEN_C_FRAME],[])
340undefine([USE_EABI_C_FRAME])
341
342ifdef([LINUX],[
343ifdef([PPC64],[],[
344define([USE_EABI_C_FRAME],[])
345undefine([USE_POWEROPEN_C_FRAME])
346])])
347
348
349
350
Note: See TracBrowser for help on using the repository browser.