1 diff -Nur binutils-2.13.90.0.18.orig/gas/Makefile.am binutils-2.13.90.0.18/gas/Makefile.am
2 --- binutils-2.13.90.0.18.orig/gas/Makefile.am Sun Feb 2 03:21:17 2003
3 +++ binutils-2.13.90.0.18/gas/Makefile.am Sun Feb 2 12:25:10 2003
8 -CFILES = $(GAS_CFILES) itbl-ops.c
9 +CFILES = $(GAS_CFILES) gasp.c itbl-ops.c
15 # Note: GASP is now deprecated and has been removed. It is still
16 # available in the CVS archive or older binutils releases if it is needed.
17 -noinst_PROGRAMS = as-new
18 +# ...and it is needed for few packages in distribution.
19 +noinst_PROGRAMS = as-new gasp-new
20 noinst_SCRIPTS = $(GDBINIT)
21 EXTRA_SCRIPTS = .gdbinit
24 as.h asintl.h bignum.h bit_fix.h config.h emul.h expr.h flonum.h \
25 frags.h hash.h listing.h obj.h read.h symbols.h tc.h write.h
27 +gasp_new_SOURCES = gasp.c macro.c sb.c hash.c
28 +gasp_new_LDADD = ../libiberty/libiberty.a $(INTLLIBS)
29 +gasp_new_DEPENDENCIES = ../libiberty/libiberty.a $(INTLDEPS)
31 EXPECT = `if [ -f $${rootme}/../expect/expect ] ; then \
32 echo $${rootme}/../expect/expect ; \
33 else echo expect ; fi`
35 $(INCDIR)/obstack.h subsegs.h struc-symbol.h
36 write.o: write.c $(INCDIR)/symcat.h subsegs.h $(INCDIR)/obstack.h \
37 output-file.h dwarf2dbg.h
38 +gasp.o: gasp.c $(INCDIR)/getopt.h $(INCDIR)/safe-ctype.h \
39 + sb.h macro.h $(INCDIR)/xregex.h $(INCDIR)/xregex2.h
40 itbl-ops.o: itbl-ops.c itbl-ops.h $(INCDIR)/symcat.h
41 e-crisaout.o: $(srcdir)/config/e-crisaout.c $(INCDIR)/symcat.h \
43 --- binutils-2.14.90.0.7/gas/Makefile.in.orig 2003-10-29 18:37:48.000000000 +0100
44 +++ binutils-2.14.90.0.7/gas/Makefile.in 2003-11-04 00:08:05.641363288 +0100
49 -CFILES = $(GAS_CFILES) itbl-ops.c
50 +CFILES = $(GAS_CFILES) gasp.c itbl-ops.c
56 # Note: GASP is now deprecated and has been removed. It is still
57 # available in the CVS archive or older binutils releases if it is needed.
58 -noinst_PROGRAMS = as-new
59 +# ...and it is needed for few packages in distribution.
60 +noinst_PROGRAMS = as-new gasp-new
61 noinst_SCRIPTS = $(GDBINIT)
62 EXTRA_SCRIPTS = .gdbinit
65 $(extra_objects) $(GASLIBS) $(INTLDEPS)
68 +gasp_new_SOURCES = gasp.c macro.c sb.c hash.c
69 +gasp_new_LDADD = ../libiberty/libiberty.a $(INTLLIBS)
70 +gasp_new_DEPENDENCIES = ../libiberty/libiberty.a $(INTLDEPS)
72 EXPECT = `if [ -f $${rootme}/../expect/expect ] ; then \
73 echo $${rootme}/../expect/expect ; \
74 else echo expect ; fi`
76 CONFIG_HEADER = config.h
77 CONFIG_CLEAN_FILES = gdb.ini .gdbinit po/Makefile.in
78 EXTRA_PROGRAMS = itbl-test$(EXEEXT)
79 -noinst_PROGRAMS = as-new$(EXEEXT)
80 +noinst_PROGRAMS = as-new$(EXEEXT) gasp-new$(EXEEXT)
81 PROGRAMS = $(noinst_PROGRAMS)
83 am__objects_1 = app.$(OBJEXT) as.$(OBJEXT) atof-generic.$(OBJEXT) \
84 @@ -2531,6 +2536,10 @@
85 am_as_new_OBJECTS = $(am__objects_1)
86 as_new_OBJECTS = $(am_as_new_OBJECTS)
88 +am_gasp_new_OBJECTS = gasp.$(OBJEXT) macro.$(OBJEXT) sb.$(OBJEXT) \
90 +gasp_new_OBJECTS = $(am_gasp_new_OBJECTS)
92 am_itbl_test_OBJECTS = itbl-parse.$(OBJEXT) itbl-lex.$(OBJEXT)
93 itbl_test_OBJECTS = $(am_itbl_test_OBJECTS)
94 itbl_test_DEPENDENCIES = itbl-tops.o itbl-test.o \
96 install-data-recursive install-exec-recursive \
97 installdirs-recursive install-recursive uninstall-recursive \
98 check-recursive installcheck-recursive
99 -SOURCES = $(as_new_SOURCES) $(EXTRA_as_new_SOURCES) $(itbl_test_SOURCES)
100 +SOURCES = $(as_new_SOURCES) $(EXTRA_as_new_SOURCES) $(itbl_test_SOURCES) $(gasp_new_SOURCES)
103 $(MAKE) $(AM_MAKEFLAGS) all-recursive
104 @@ -2616,6 +2625,9 @@
105 as-new$(EXEEXT): $(as_new_OBJECTS) $(as_new_DEPENDENCIES)
106 @rm -f as-new$(EXEEXT)
107 $(LINK) $(as_new_LDFLAGS) $(as_new_OBJECTS) $(as_new_LDADD) $(LIBS)
108 +gasp-new$(EXEEXT): $(gasp_new_OBJECTS) $(gasp_new_DEPENDENCIES)
109 + @rm -f gasp-new$(EXEEXT)
110 + $(LINK) $(gasp_new_LDFLAGS) $(gasp_new_OBJECTS) $(gasp_new_LDADD) $(LIBS)
111 itbl-test$(EXEEXT): $(itbl_test_OBJECTS) $(itbl_test_DEPENDENCIES)
112 @rm -f itbl-test$(EXEEXT)
113 $(LINK) $(itbl_test_LDFLAGS) $(itbl_test_OBJECTS) $(itbl_test_LDADD) $(LIBS)
114 @@ -3387,6 +3399,8 @@
115 $(INCDIR)/obstack.h subsegs.h struc-symbol.h
116 write.o: write.c $(INCDIR)/symcat.h subsegs.h $(INCDIR)/obstack.h \
117 output-file.h dwarf2dbg.h
118 +gasp.o: gasp.c $(INCDIR)/getopt.h $(INCDIR)/safe-ctype.h \
119 + sb.h macro.h $(INCDIR)/xregex.h $(INCDIR)/xregex2.h
120 itbl-ops.o: itbl-ops.c itbl-ops.h $(INCDIR)/symcat.h
121 e-crisaout.o: $(srcdir)/config/e-crisaout.c $(INCDIR)/symcat.h \
123 diff -Nur binutils-2.13.90.0.18.orig/gas/doc/Makefile.am binutils-2.13.90.0.18/gas/doc/Makefile.am
124 --- binutils-2.13.90.0.18.orig/gas/doc/Makefile.am Sun Feb 2 03:21:17 2003
125 +++ binutils-2.13.90.0.18/gas/doc/Makefile.am Sun Feb 2 12:35:43 2003
130 -info_TEXINFOS = as.texinfo
131 +info_TEXINFOS = as.texinfo gasp.texinfo
133 asconfig.texi: $(CONFIG).texi
135 --- binutils-2.14.90.0.7/gas/doc/Makefile.in.orig 2003-10-29 18:37:48.000000000 +0100
136 +++ binutils-2.14.90.0.7/gas/doc/Makefile.in 2003-11-04 00:08:38.143422224 +0100
141 -info_TEXINFOS = as.texinfo
142 +info_TEXINFOS = as.texinfo gasp.texinfo
146 @@ -236,11 +236,11 @@
148 TEXINFO_TEX = $(top_srcdir)/../texinfo/texinfo.tex
149 am__TEXINFO_TEX_DIR = $(top_srcdir)/../texinfo
151 +INFO_DEPS = as.info gasp.info
155 -TEXINFOS = as.texinfo
156 +TEXINFOS = as.texinfo gasp.texinfo
160 diff -Nur binutils-2.14.90.0.7.orig/gas/doc/gasp.texinfo binutils-2.14.90.0.7/gas/doc/gasp.texinfo
161 --- binutils-2.14.90.0.7.orig/gas/doc/gasp.texinfo Thu Jan 1 01:00:00 1970
162 +++ binutils-2.14.90.0.7/gas/doc/gasp.texinfo Wed Oct 30 05:09:13 2002
164 +\input texinfo @c -*- Texinfo -*-
165 +@setfilename gasp.info
167 +@c This file documents the assembly preprocessor "GASP"
169 +@c Copyright 1994, 1995, 2000, 2002 Free Software Foundation, Inc.
171 +@c Permission is granted to copy, distribute and/or modify this document
172 +@c under the terms of the GNU Free Documentation License, Version 1.1
173 +@c or any later version published by the Free Software Foundation;
174 +@c with no Invariant Sections, with no Front-Cover Texts, and with no
175 +@c Back-Cover Texts. A copy of the license is included in the
176 +@c section entitled "GNU Free Documentation License".
180 +START-INFO-DIR-ENTRY
181 +* gasp: (gasp). The GNU Assembler Preprocessor
190 +@setchapternewpage odd
193 +@c FIXME boring title
194 +@title GASP, an assembly preprocessor
195 +@subtitle for GASP version 1
197 +@subtitle March 1994
198 +@author Roland Pesch
202 +{\parskip=0pt \hfill Cygnus Support\par
206 +@vskip 0pt plus 1filll
207 +Copyright @copyright{} 1994, 1995, 2000, 2002 Free Software Foundation, Inc.
209 + Permission is granted to copy, distribute and/or modify this document
210 + under the terms of the GNU Free Documentation License, Version 1.1
211 + or any later version published by the Free Software Foundation;
212 + with no Invariant Sections, with no Front-Cover Texts, and with no
213 + Back-Cover Texts. A copy of the license is included in the
214 + section entitled "GNU Free Documentation License".
219 +Copyright @copyright{} 1994, 1995, 2000, 2002 Free Software Foundation, Inc.
222 +Permission is granted to process this file through TeX and print the
223 +results, provided the printed document carries a copying permission
224 +notice identical to this one except for the removal of this paragraph
225 +(this paragraph not being relevant to the printed manual).
228 + Permission is granted to copy, distribute and/or modify this document
229 + under the terms of the GNU Free Documentation License, Version 1.1
230 + or any later version published by the Free Software Foundation;
231 + with no Invariant Sections, with no Front-Cover Texts, and with no
232 + Back-Cover Texts. A copy of the license is included in the
233 + section entitled "GNU Free Documentation License".
239 +GASP is a preprocessor for assembly programs.
241 +This file describes version 1 of GASP.
243 +Steve Chamberlain wrote GASP; Roland Pesch wrote this manual.
246 +* Overview:: What is GASP?
247 +* Invoking GASP:: Command line options.
248 +* Commands:: Preprocessor commands.
249 +* GNU Free Documentation License:: GNU Free Documentation License
255 +@chapter What is GASP?
257 +The primary purpose of the @sc{gnu} assembler is to assemble the output of
258 +other programs---notably compilers. When you have to hand-code
259 +specialized routines in assembly, that means the @sc{gnu} assembler is
260 +an unfriendly processor: it has no directives for macros, conditionals,
261 +or many other conveniences that you might expect.
263 +In some cases you can simply use the C preprocessor, or a generalized
264 +preprocessor like @sc{m4}; but this can be awkward, since none of these
265 +things are designed with assembly in mind.
267 +@sc{gasp} fills this need. It is expressly designed to provide the
268 +facilities you need with hand-coded assembly code. Implementing it as a
269 +preprocessor, rather than part of the assembler, allows the maximum
270 +flexibility: you can use it with hand-coded assembly, without paying a
271 +penalty of added complexity in the assembler you use for compiler
274 +@emph{Note} The use of @sc{gasp} has now been deprecated. Anything
275 +that it could do can now be done by the macro facilities built into
276 +@sc{gas} itself. At some point in the future the @sc{gasp} sources will
277 +be removed entirely from the binutils distribution.
279 +Here is a small example to give the flavor of @sc{gasp}. This input to
284 + .MACRO saveregs from=8 to=14
285 +count .ASSIGNA \from
286 + ! save r\from..r\to
287 + .AWHILE \&count LE \to
289 +count .ASSIGNA \&count + 1
295 +bar: mov #H'dead+10,r0
296 +foo .SDATAC "hello"<10>
302 +generates this assembly program:
311 +bar: mov #57005+10,r0
312 +foo: .byte 6,104,101,108,108,111,10
317 +@chapter Command Line Options
319 +@c FIXME! Or is there a simpler way, calling from GAS option?
320 +The simplest way to use @sc{gasp} is to run it as a filter and assemble
321 +its output. In Unix and its ilk, you can do this, for example:
323 +@c FIXME! GASP filename suffix convention?
325 +$ gasp prog.asm | as -o prog.o
328 +Naturally, there are also a few command-line options to allow you to
329 +request variations on this basic theme. Here is the full set of
330 +possibilities for the @sc{gasp} command line.
333 +gasp [ -a | --alternate ]
334 + [ -c @var{char} | --commentchar @var{char} ]
335 + [ -d | --debug ] [ -h | --help ] [ -M | --mri ]
336 + [ -o @var{outfile} | --output @var{outfile} ]
337 + [ -p | --print ] [ -s | --copysource ]
338 + [ -u | --unreasonable ] [ -v | --version ]
339 + @var{infile} @dots{}
343 +@item @var{infile} @dots{}
344 +@c FIXME! Why not stdin as default infile?
345 +The input file names. You must specify at least one input file; if you
346 +specify more, @sc{gasp} preprocesses them all, concatenating the output
347 +in the order you list the @var{infile} arguments.
349 +Mark the end of each input file with the preprocessor command
350 +@code{.END}. @xref{Other Commands,, Miscellaneous commands}.
354 +Use alternative macro syntax. @xref{Alternate,, Alternate macro
355 +syntax}, for a discussion of how this syntax differs from the default
358 +@cindex comment character, changing
359 +@cindex semicolon, as comment
360 +@cindex exclamation mark, as comment
361 +@cindex shriek, as comment
362 +@cindex bang, as comment
363 +@cindex @code{!} default comment char
364 +@cindex @code{;} as comment char
365 +@item -c '@var{char}'
366 +@itemx --commentchar '@var{char}'
367 +Use @var{char} as the comment character. The default comment character
368 +is @samp{!}. For example, to use a semicolon as the comment character,
369 +specify @w{@samp{-c ';'}} on the @sc{gasp} command line. Since
370 +assembler command characters often have special significance to command
371 +shells, it is a good idea to quote or escape @var{char} when you specify
372 +a comment character.
374 +For the sake of simplicity, all examples in this manual use the default
375 +comment character @samp{!}.
379 +Show debugging statistics. In this version of @sc{gasp}, this option
380 +produces statistics about the string buffers that @sc{gasp} allocates
381 +internally. For each defined buffersize @var{s}, @sc{gasp} shows the
382 +number of strings @var{n} that it allocated, with a line like this:
385 +strings size @var{s} : @var{n}
389 +@sc{gasp} displays these statistics on the standard error stream, when
394 +Display a summary of the @sc{gasp} command line options.
398 +Use MRI compatibility mode. Using this option causes @sc{gasp} to
399 +accept the syntax and pseudo-ops used by the Microtec Research
400 +@code{ASM68K} assembler.
402 +@item -o @var{outfile}
403 +@itemx --output @var{outfile}
404 +Write the output in a file called @var{outfile}. If you do not use the
405 +@samp{-o} option, @sc{gasp} writes its output on the standard output
410 +Print line numbers. @sc{gasp} obeys this option @emph{only} if you also
411 +specify @samp{-s} to copy source lines to its output. With @samp{-s
412 +-p}, @sc{gasp} displays the line number of each source line copied
413 +(immediately after the comment character at the beginning of the line).
417 +Copy the source lines to the output file. Use this option
418 +to see the effect of each preprocessor line on the @sc{gasp} output.
419 +@sc{gasp} places a comment character (@samp{!} by default) at
420 +the beginning of each source line it copies, so that you can use this
421 +option and still assemble the result.
424 +@itemx --unreasonable
425 +Bypass ``unreasonable expansion'' limit. Since you can define @sc{gasp}
426 +macros inside other macro definitions, the preprocessor normally
427 +includes a sanity check. If your program requires more than 1,000
428 +nested expansions, @sc{gasp} normally exits with an error message. Use
429 +this option to turn off this check, allowing unlimited nested
434 +Display the @sc{gasp} version number.
438 +@chapter Preprocessor Commands
440 +@sc{gasp} commands have a straightforward syntax that fits in well with
441 +assembly conventions. In general, a command extends for a line, and may
442 +have up to three fields: an optional label, the command itself, and
443 +optional arguments to the command. You can write commands in upper or
444 +lower case, though this manual shows them in upper case. @xref{Syntax
445 +Details,, Details of the GASP syntax}, for more information.
460 +@section Conditional assembly
462 +The conditional-assembly directives allow you to include or exclude
463 +portions of an assembly depending on how a pair of expressions, or a
464 +pair of strings, compare.
466 +The overall structure of conditionals is familiar from many other
467 +contexts. @code{.AIF} marks the start of a conditional, and precedes
468 +assembly for the case when the condition is true. An optional
469 +@code{.AELSE} precedes assembly for the converse case, and an
470 +@code{.AENDI} marks the end of the condition.
472 +@c FIXME! Why doesn't -u turn off this check?
473 +You may nest conditionals up to a depth of 100; @sc{gasp} rejects
474 +nesting beyond that, because it may indicate a bug in your macro
477 +@c FIXME! Why isn't there something like cpp's -D option? Conditionals
478 +@c would be much more useful if there were.
479 +Conditionals are primarily useful inside macro definitions, where you
480 +often need different effects depending on argument values.
481 +@xref{Macros,, Defining your own directives}, for details about defining
485 +@item .AIF @var{expra} @var{cmp} @var{exprb}
486 +@itemx .AIF "@var{stra}" @var{cmp} "@var{strb}"
488 +The governing condition goes on the same line as the @code{.AIF}
489 +preprocessor command. You may compare either two strings, or two
492 +When you compare strings, only two conditional @var{cmp} comparison
493 +operators are available: @samp{EQ} (true if @var{stra} and @var{strb}
494 +are identical), and @samp{NE} (the opposite).
496 +When you compare two expressions, @emph{both expressions must be
497 +absolute} (@pxref{Expressions,, Arithmetic expressions in GASP}). You
498 +can use these @var{cmp} comparison operators with expressions:
502 +Are @var{expra} and @var{exprb} equal? (For strings, are @var{stra} and
503 +@var{strb} identical?)
506 +Are @var{expra} and @var{exprb} different? (For strings, are @var{stra}
507 +and @var{strb} different?
510 +Is @var{expra} less than @var{exprb}? (Not allowed for strings.)
513 +Is @var{expra} less than or equal to @var{exprb}? (Not allowed for strings.)
516 +Is @var{expra} greater than @var{exprb}? (Not allowed for strings.)
519 +Is @var{expra} greater than or equal to @var{exprb}? (Not allowed for
524 +Marks the start of assembly code to be included if the condition fails.
525 +Optional, and only allowed within a conditional (between @code{.AIF} and
529 +Marks the end of a conditional assembly.
533 +@section Repetitive sections of assembly
535 +Two preprocessor directives allow you to repeatedly issue copies of the
536 +same block of assembly code.
539 +@item .AREPEAT @var{aexp}
541 +If you simply need to repeat the same block of assembly over and over a
542 +fixed number of times, sandwich one instance of the repeated block
543 +between @code{.AREPEAT} and @code{.AENDR}. Specify the number of
544 +copies as @var{aexp} (which must be an absolute expression). For
545 +example, this repeats two assembly statements three times in succession:
556 +@item .AWHILE @var{expra} @var{cmp} @var{exprb}
558 +@itemx .AWHILE @var{stra} @var{cmp} @var{strb}
560 +To repeat a block of assembly depending on a conditional test, rather
561 +than repeating it for a specific number of times, use @code{.AWHILE}.
562 +@code{.AENDW} marks the end of the repeated block. The conditional
563 +comparison works exactly the same way as for @code{.AIF}, with the same
564 +comparison operators (@pxref{Conditionals,, Conditional assembly}).
566 +Since the terms of the comparison must be absolute expression,
567 +@code{.AWHILE} is primarily useful within macros. @xref{Macros,,
568 +Defining your own directives}.
571 +@cindex loops, breaking out of
572 +@cindex breaking out of loops
573 +You can use the @code{.EXITM} preprocessor directive to break out of
574 +loops early (as well as to break out of macros). @xref{Macros,,
575 +Defining your own directives}.
578 +@section Preprocessor variables
580 +You can use variables in @sc{gasp} to represent strings, registers, or
581 +the results of expressions.
583 +You must distinguish two kinds of variables:
586 +Variables defined with @code{.EQU} or @code{.ASSIGN}. To evaluate this
587 +kind of variable in your assembly output, simply mention its name. For
588 +example, these two lines define and use a variable @samp{eg}:
598 +@emph{Do not use} this kind of variable in conditional expressions or
599 +while loops; @sc{gasp} only evaluates these variables when writing
603 +Variables for use during preprocessing. You can define these
604 +with @code{.ASSIGNC} or @code{.ASSIGNA}. To evaluate this
605 +kind of variable, write @samp{\&} before the variable name; for example,
611 + .AWHILE \&opcit GT 0
617 +@sc{gasp} treats macro arguments almost the same way, but to evaluate
618 +them you use the prefix @samp{\} rather than @samp{\&}.
619 +@xref{Macros,, Defining your own directives}.
623 +@item @var{pvar} .EQU @var{expr}
624 +@c FIXME! Anything to beware of re GAS directive of same name?
625 +Assign preprocessor variable @var{pvar} the value of the expression
626 +@var{expr}. There are no restrictions on redefinition; use @samp{.EQU}
627 +with the same @var{pvar} as often as you find it convenient.
629 +@item @var{pvar} .ASSIGN @var{expr}
630 +Almost the same as @code{.EQU}, save that you may not redefine
631 +@var{pvar} using @code{.ASSIGN} once it has a value.
632 +@c FIXME!! Supposed to work this way, apparently, but on 9feb94 works
635 +@item @var{pvar} .ASSIGNA @var{aexpr}
636 +Define a variable with a numeric value, for use during preprocessing.
637 +@var{aexpr} must be an absolute expression. You can redefine variables
638 +with @code{.ASSIGNA} at any time.
640 +@item @var{pvar} .ASSIGNC "@var{str}"
641 +Define a variable with a string value, for use during preprocessing.
642 +You can redefine variables with @code{.ASSIGNC} at any time.
644 +@item @var{pvar} .REG (@var{register})
645 +Use @code{.REG} to define a variable that represents a register. In
646 +particular, @var{register} is @emph{not evaluated} as an expression.
647 +You may use @code{.REG} at will to redefine register variables.
650 +All these directives accept the variable name in the ``label'' position,
651 +that is at the left margin. You may specify a colon after the variable
652 +name if you wish; the first example above could have started @samp{eg:}
653 +with the same effect.
655 +@c pagebreak makes for better aesthetics---ensures macro and expansion together
658 +@section Defining your own directives
660 +The commands @code{.MACRO} and @code{.ENDM} allow you to define macros
661 +that generate assembly output. You can use these macros with a syntax
662 +similar to built-in @sc{gasp} or assembler directives. For example,
663 +this definition specifies a macro @code{SUM} that adds together a range of
664 +consecutive registers:
668 + .MACRO SUM FROM=0, TO=9
671 +COUNT .ASSIGNA \FROM+1
672 + .AWHILE \&COUNT LE \TO
674 +COUNT .ASSIGNA \&COUNT+1
681 +With that definition, @samp{SUM 0,5} generates this assembly output:
696 +@item .MACRO @var{macname}
697 +@itemx .MACRO @var{macname} @var{macargs} @dots{}
698 +Begin the definition of a macro called @var{macname}. If your macro
699 +definition requires arguments, specify their names after the macro name,
700 +separated by commas or spaces. You can supply a default value for any
701 +macro argument by following the name with @samp{=@var{deflt}}. For
702 +example, these are all valid @code{.MACRO} statements:
706 +Begin the definition of a macro called @code{COMM}, which takes no
709 +@item .MACRO PLUS1 P, P1
710 +@itemx .MACRO PLUS1 P P1
711 +Either statement begins the definition of a macro called @code{PLUS1},
712 +which takes two arguments; within the macro definition, write
713 +@samp{\P} or @samp{\P1} to evaluate the arguments.
715 +@item .MACRO RESERVE_STR P1=0 P2
716 +Begin the definition of a macro called @code{RESERVE_STR}, with two
717 +arguments. The first argument has a default value, but not the second.
718 +After the definition is complete, you can call the macro either as
719 +@samp{RESERVE_STR @var{a},@var{b}} (with @samp{\P1} evaluating to
720 +@var{a} and @samp{\P2} evaluating to @var{b}), or as @samp{RESERVE_STR
721 +,@var{b}} (with @samp{\P1} evaluating as the default, in this case
722 +@samp{0}, and @samp{\P2} evaluating to @var{b}).
725 +When you call a macro, you can specify the argument values either by
726 +position, or by keyword. For example, @samp{SUM 9,17} is equivalent to
727 +@samp{SUM TO=17, FROM=9}. Macro arguments are preprocessor variables
728 +similar to the variables you define with @samp{.ASSIGNA} or
729 +@samp{.ASSIGNC}; in particular, you can use them in conditionals or for
730 +loop control. (The only difference is the prefix you write to evaluate
731 +the variable: for a macro argument, write @samp{\@var{argname}}, but for
732 +a preprocessor variable, write @samp{\&@var{varname}}.)
734 +@item @var{name} .MACRO
735 +@itemx @var{name} .MACRO ( @var{macargs} @dots{} )
736 +@c FIXME check: I think no error _and_ no args recognized if I use form
737 +@c NAME .MACRO ARG ARG
738 +An alternative form of introducing a macro definition: specify the macro
739 +name in the label position, and the arguments (if any) between
740 +parentheses after the name. Defaulting rules and usage work the same
741 +way as for the other macro definition syntax.
744 +Mark the end of a macro definition.
747 +Exit early from the current macro definition, @code{.AREPEAT} loop, or
748 +@code{.AWHILE} loop.
750 +@cindex number of macros executed
751 +@cindex macros, count executed
753 +@sc{gasp} maintains a counter of how many macros it has
754 +executed in this pseudo-variable; you can copy that number to your
755 +output with @samp{\@@}, but @emph{only within a macro definition}.
757 +@item LOCAL @var{name} [ , @dots{} ]
758 +@emph{Warning: @code{LOCAL} is only available if you select ``alternate
759 +macro syntax'' with @samp{-a} or @samp{--alternate}.} @xref{Alternate,,
760 +Alternate macro syntax}.
762 +Generate a string replacement for each of the @var{name} arguments, and
763 +replace any instances of @var{name} in each macro expansion. The
764 +replacement string is unique in the assembly, and different for each
765 +separate macro expansion. @code{LOCAL} allows you to write macros that
766 +define symbols, without fear of conflict between separate macro expansions.
770 +@section Data output
772 +In assembly code, you often need to specify working areas of memory;
773 +depending on the application, you may want to initialize such memory or
774 +not. @sc{gasp} provides preprocessor directives to help you avoid
775 +repetitive coding for both purposes.
777 +You can use labels as usual to mark the data areas.
785 +@subsection Initialized data
787 +These are the @sc{gasp} directives for initialized data, and the standard
788 +@sc{gnu} assembler directives they expand to:
791 +@item .DATA @var{expr}, @var{expr}, @dots{}
792 +@itemx .DATA.B @var{expr}, @var{expr}, @dots{}
793 +@itemx .DATA.W @var{expr}, @var{expr}, @dots{}
794 +@itemx .DATA.L @var{expr}, @var{expr}, @dots{}
795 +Evaluate arithmetic expressions @var{expr}, and emit the corresponding
796 +@code{as} directive (labelled with @var{lab}). The unqualified
797 +@code{.DATA} emits @samp{.long}; @code{.DATA.B} emits @samp{.byte};
798 +@code{.DATA.W} emits @samp{.short}; and @code{.DATA.L} emits
801 +For example, @samp{foo .DATA 1,2,3} emits @samp{foo: .long 1,2,3}.
803 +@item .DATAB @var{repeat}, @var{expr}
804 +@itemx .DATAB.B @var{repeat}, @var{expr}
805 +@itemx .DATAB.W @var{repeat}, @var{expr}
806 +@itemx .DATAB.L @var{repeat}, @var{expr}
807 +@c FIXME! Looks like gasp accepts and ignores args after 2nd.
808 +Make @code{as} emit @var{repeat} copies of the value of the expression
809 +@var{expr} (using the @code{as} directive @code{.fill}).
810 +@samp{.DATAB.B} repeats one-byte values; @samp{.DATAB.W} repeats
811 +two-byte values; and @samp{.DATAB.L} repeats four-byte values.
812 +@samp{.DATAB} without a suffix repeats four-byte values, just like
815 +@c FIXME! Allowing zero might be useful for edge conditions in macros.
816 +@var{repeat} must be an absolute expression with a positive value.
818 +@item .SDATA "@var{str}" @dots{}
819 +String data. Emits a concatenation of bytes, precisely as you specify
820 +them (in particular, @emph{nothing is added to mark the end} of the
821 +string). @xref{Constants,, String and numeric constants}, for details
822 +about how to write strings. @code{.SDATA} concatenates multiple
823 +arguments, making it easy to switch between string representations. You
824 +can use commas to separate the individual arguments for clarity, if you
827 +@item .SDATAB @var{repeat}, "@var{str}" @dots{}
828 +Repeated string data. The first argument specifies how many copies of
829 +the string to emit; the remaining arguments specify the string, in the
830 +same way as the arguments to @code{.SDATA}.
832 +@item .SDATAZ "@var{str}" @dots{}
833 +Zero-terminated string data. Just like @code{.SDATA}, except that
834 +@code{.SDATAZ} writes a zero byte at the end of the string.
836 +@item .SDATAC "@var{str}" @dots{}
837 +Count-prefixed string data. Just like @code{.SDATA}, except that
838 +@sc{gasp} precedes the string with a leading one-byte count. For
839 +example, @samp{.SDATAC "HI"} generates @samp{.byte 2,72,73}. Since the
840 +count field is only one byte, you can only use @code{.SDATAC} for
841 +strings less than 256 bytes in length.
845 +@subsection Uninitialized data
847 +@c FIXME! .space different on some platforms, notably HPPA. Config?
848 +Use the @code{.RES}, @code{.SRES}, @code{.SRESC}, and @code{.SRESZ}
849 +directives to reserve memory and leave it uninitialized. @sc{gasp}
850 +resolves these directives to appropriate calls of the @sc{gnu}
851 +@code{as} @code{.space} directive.
854 +@item .RES @var{count}
855 +@itemx .RES.B @var{count}
856 +@itemx .RES.W @var{count}
857 +@itemx .RES.L @var{count}
858 +Reserve room for @var{count} uninitialized elements of data. The
859 +suffix specifies the size of each element: @code{.RES.B} reserves
860 +@var{count} bytes, @code{.RES.W} reserves @var{count} pairs of bytes,
861 +and @code{.RES.L} reserves @var{count} quartets. @code{.RES} without a
862 +suffix is equivalent to @code{.RES.L}.
864 +@item .SRES @var{count}
865 +@itemx .SRES.B @var{count}
866 +@itemx .SRES.W @var{count}
867 +@itemx .SRES.L @var{count}
868 +@c FIXME! This is boring. Shouldn't it at least have a different
869 +@c default size? (e.g. the "S" suggests "string", for which .B
870 +@c would be more appropriate)
871 +@code{.SRES} is a synonym for @samp{.RES}.
873 +@item .SRESC @var{count}
874 +@itemx .SRESC.B @var{count}
875 +@itemx .SRESC.W @var{count}
876 +@itemx .SRESC.L @var{count}
877 +Like @code{.SRES}, but reserves space for @code{@var{count}+1} elements.
879 +@item .SRESZ @var{count}
880 +@itemx .SRESZ.B @var{count}
881 +@itemx .SRESZ.W @var{count}
882 +@itemx .SRESZ.L @var{count}
883 +Like @code{.SRES}, but reserves space for @code{@var{count}+1} elements.
887 +@section Assembly listing control
889 +The @sc{gasp} listing-control directives correspond to
890 +related @sc{gnu} @code{as} directives.
894 +@itemx .PRINT NOLIST
895 +Print control. This directive emits the @sc{gnu} @code{as} directive
896 +@code{.list} or @code{.nolist}, according to its argument. @xref{List,,
897 +@code{.list}, as.info, Using as}, for details on how these directives
900 +@item .FORM LIN=@var{ln}
901 +@itemx .FORM COL=@var{cols}
902 +@itemx .FORM LIN=@var{ln} COL=@var{cols}
903 +Specify the page size for assembly listings: @var{ln} represents the
904 +number of lines, and @var{cols} the number of columns. You may specify
905 +either page dimension independently, or both together. If you do not
906 +specify the number of lines, @sc{gasp} assumes 60 lines; if you do not
907 +specify the number of columns, @sc{gasp} assumes 132 columns.
908 +(Any values you may have specified in previous instances of @code{.FORM}
909 +do @emph{not} carry over as defaults.) Emits the @code{.psize}
910 +assembler directive.
912 +@item .HEADING @var{string}
913 +Specify @var{string} as the title of your assembly listings. Emits
914 +@samp{.title "@var{string}"}.
917 +Force a new page in assembly listings. Emits @samp{.eject}.
920 +@node Other Commands
921 +@section Miscellaneous commands
925 +Use the alternate macro syntax henceforth in the assembly.
926 +@xref{Alternate,, Alternate macro syntax}.
929 +@c FIXME! This is very strange, since _GAS_ understands .org
930 +This command is recognized, but not yet implemented. @sc{gasp}
931 +generates an error message for programs that use @code{.ORG}.
933 +@item .RADIX @var{s}
934 +@c FIXME no test cases in testsuite/gasp
935 +@sc{gasp} understands numbers in any of base two, eight, ten, or
936 +sixteen. You can encode the base explicitly in any numeric constant
937 +(@pxref{Constants,, String and numeric constants}). If you write
938 +numbers without an explicit indication of the base, the most recent
939 +@samp{.RADIX @var{s}} command determines how they are interpreted.
940 +@var{s} is a single letter, one of the following:
950 +Base 10. This is the original default radix.
956 +You may specify the argument @var{s} in lower case (any of @samp{bqdh})
957 +with the same effects.
959 +@item .EXPORT @var{name}
960 +@itemx .GLOBAL @var{name}
961 +@c FIXME! No test cases in testsuite/gasp
962 +Declare @var{name} global (emits @samp{.global @var{name}}). The two
963 +directives are synonymous.
966 +No effect: @sc{gasp} accepts this directive, and silently ignores it.
969 +Mark end of each preprocessor file. @sc{gasp} issues a warning if it
970 +reaches end of file without seeing this command.
972 +@item .INCLUDE "@var{str}"
973 +Preprocess the file named by @var{str}, as if its contents appeared
974 +where the @code{.INCLUDE} directive does. @sc{gasp} imposes a maximum
975 +limit of 30 stacked include files, as a sanity check.
976 +@c FIXME! Why is include depth not affected by -u?
978 +@item .ALIGN @var{size}
979 +@c FIXME! Why is this not utterly pointless?
980 +Evaluate the absolute expression @var{size}, and emit the assembly
981 +instruction @samp{.align @var{size}} using the result.
984 +@node Syntax Details
985 +@section Details of the GASP syntax
987 +Since @sc{gasp} is meant to work with assembly code, its statement
988 +syntax has no surprises for the assembly programmer.
991 +@emph{Whitespace} (blanks or tabs; @emph{not} newline) is partially
992 +significant, in that it delimits up to three fields in a line. The
993 +amount of whitespace does not matter; you may line up fields in separate
994 +lines if you wish, but @sc{gasp} does not require that.
996 +@cindex fields of @sc{gasp} source line
998 +The @emph{first field}, an optional @dfn{label}, must be flush left in a
999 +line (with no leading whitespace) if it appears at all. You may use a
1000 +colon after the label if you wish; @sc{gasp} neither requires the colon
1001 +nor objects to it (but will not include it as part of the label name).
1003 +@cindex directive field
1004 +The @emph{second field}, which must appear after some whitespace,
1005 +contains a @sc{gasp} or assembly @dfn{directive}.
1007 +@cindex argument fields
1008 +Any @emph{further fields} on a line are @dfn{arguments} to the
1009 +directive; you can separate them from one another using either commas or
1017 +* String Builtins::
1021 +@subsection Special syntactic markers
1023 +@sc{gasp} recognizes a few special markers: to delimit comments, to
1024 +continue a statement on the next line, to separate symbols from other
1025 +characters, and to copy text to the output literally. (One other
1026 +special marker, @samp{\@@}, works only within macro definitions;
1027 +@pxref{Macros,, Defining your own directives}.)
1030 +The trailing part of any @sc{gasp} source line may be a @dfn{comment}.
1031 +A comment begins with the first unquoted comment character (@samp{!} by
1032 +default), or an escaped or doubled comment character (@samp{\!} or
1033 +@samp{!!} by default), and extends to the end of a line. You can
1034 +specify what comment character to use with the @samp{-c} option
1035 +(@pxref{Invoking GASP,, Command Line Options}). The two kinds of
1036 +comment markers lead to slightly different treatment:
1040 +A single, un-escaped comment character generates an assembly comment in
1041 +the @sc{gasp} output. @sc{gasp} evaluates any preprocessor variables
1042 +(macro arguments, or variables defined with @code{.ASSIGNA} or
1043 +@code{.ASSIGNC}) present. For example, a macro that begins like this
1046 + .MACRO SUM FROM=0, TO=9
1051 +issues as the first line of output a comment that records the
1052 +values you used to call the macro.
1054 +@c comments, preprocessor-only
1055 +@c preprocessor-only comments
1056 +@c GASP-only comments
1059 +Either an escaped comment character, or a double comment character,
1060 +marks a @sc{gasp} source comment. @sc{gasp} does not copy such comments
1061 +to the assembly output.
1064 +@cindex continuation character
1066 +To @emph{continue a statement} on the next line of the file, begin the
1067 +second line with the character @samp{+}.
1069 +@cindex literal copy to output
1070 +@cindex copying literally to output
1071 +@cindex preprocessing, avoiding
1072 +@cindex avoiding preprocessing
1073 +Occasionally you may want to prevent @sc{gasp} from preprocessing some
1074 +particular bit of text. To @emph{copy literally} from the @sc{gasp}
1075 +source to its output, place @samp{\(} before the string to copy, and
1076 +@samp{)} at the end. For example, write @samp{\(\!)} if you need the
1077 +characters @samp{\!} in your assembly output.
1079 +@cindex symbol separator
1080 +@cindex text, separating from symbols
1081 +@cindex symbols, separating from text
1082 +To @emph{separate a preprocessor variable} from text to appear
1083 +immediately after its value, write a single quote (@code{'}). For
1084 +example, @samp{.SDATA "\P'1"} writes a string built by concatenating the
1085 +value of @code{P} and the digit @samp{1}. (You cannot achieve this by
1086 +writing just @samp{\P1}, since @samp{P1} is itself a valid name for a
1087 +preprocessor variable.)
1090 +@subsection String and numeric constants
1092 +There are two ways of writing @dfn{string constants} in @sc{gasp}: as
1093 +literal text, and by numeric byte value. Specify a string literal
1094 +between double quotes (@code{"@var{str}"}). Specify an individual
1095 +numeric byte value as an absolute expression between angle brackets
1096 +(@code{<@var{expr}>}. Directives that output strings allow you to
1097 +specify any number of either kind of value, in whatever order is
1098 +convenient, and concatenate the result. (Alternate syntax mode
1099 +introduces a number of alternative string notations; @pxref{Alternate,,
1100 +Alternate macro syntax}.)
1102 +@c Details of numeric notation, e.g. base prefixes
1103 +You can write @dfn{numeric constants} either in a specific base, or in
1104 +whatever base is currently selected (either 10, or selected by the most
1105 +recent @code{.RADIX}).
1107 +To write a number in a @emph{specific base}, use the pattern
1108 +@code{@var{s}'@var{ddd}}: a base specifier character @var{s}, followed
1109 +by a single quote followed by digits @var{ddd}. The base specifier
1110 +character matches those you can specify with @code{.RADIX}: @samp{B} for
1111 +base 2, @samp{Q} for base 8, @samp{D} for base 10, and @samp{H} for base
1112 +16. (You can write this character in lower case if you prefer.)
1114 +You can write floating point constants using the same syntax recognised
1115 +by GAS @ref{Flonums,,Flonums,as,The GNU Assembler.}. A constraint is
1116 +that these constants will be interpreted as decimal values irrespective
1117 +of the currently selected base.
1119 +@c FIXME! What are rules for recognizing number in deflt base? Whatever
1120 +@c is left over after parsing other things??
1123 +@subsection Symbols
1125 +@sc{gasp} recognizes symbol names that start with any alphabetic character,
1126 +@samp{_}, or @samp{$}, and continue with any of the same characters or
1127 +with digits. Label names follow the same rules.
1130 +@subsection Arithmetic expressions in GASP
1132 +@cindex absolute expressions
1133 +@cindex relocatable expressions
1134 +There are two kinds of expressions, depending on their result:
1135 +@dfn{absolute} expressions, which resolve to a constant (that is, they
1136 +do not involve any values unknown to @sc{gasp}), and @dfn{relocatable}
1137 +expressions, which must reduce to the form
1140 +@var{addsym}+@var{const}-@var{subsym}
1144 +where @var{addsym} and @var{subsym} are assembly symbols of unknown
1145 +value, and @var{const} is a constant.
1147 +Arithmetic for @sc{gasp} expressions follows very similar rules to C.
1148 +You can use parentheses to change precedence; otherwise, arithmetic
1149 +primitives have decreasing precedence in the order of the following
1154 +Single-argument @code{+} (identity), @code{-} (arithmetic opposite), or
1155 +@code{~} (bitwise negation). @emph{The argument must be an absolute
1159 +@code{*} (multiplication) and @code{/} (division). @emph{Both arguments
1160 +must be absolute expressions.}
1163 +@code{+} (addition) and @code{-} (subtraction). @emph{At least one argument
1165 +@c FIXME! Actually, subtraction doesn't check for this.
1168 +@code{&} (bitwise and). @emph{Both arguments must be absolute.}
1171 +@c FIXME! I agree ~ is a better notation than ^ for xor, but is the
1172 +@c improvement worth differing from C?
1173 +@code{|} (bitwise or) and @code{~} (bitwise exclusive or; @code{^} in
1174 +C). @emph{Both arguments must be absolute.}
1177 +@node String Builtins
1178 +@subsection String primitives
1180 +You can use these primitives to manipulate strings (in the argument
1181 +field of @sc{gasp} statements):
1184 +@item .LEN("@var{str}")
1185 +Calculate the length of string @code{"@var{str}"}, as an absolute
1186 +expression. For example, @samp{.RES.B .LEN("sample")} reserves six
1189 +@item .INSTR("@var{string}", "@var{seg}", @var{ix})
1190 +Search for the first occurrence of @var{seg} after position @var{ix} of
1191 +@var{string}. For example, @samp{.INSTR("ABCDEFG", "CDE", 0)} evaluates
1192 +to the absolute result @code{2}.
1194 +The result is @code{-1} if @var{seg} does not occur in @var{string}
1195 +after position @var{ix}.
1197 +@item .SUBSTR("@var{string}",@var{start},@var{len})
1198 +The substring of @var{string} beginning at byte number @var{start} and
1199 +extending for @var{len} bytes.
1203 +@section Alternate macro syntax
1205 +If you specify @samp{-a} or @samp{--alternate} on the @sc{gasp} command
1206 +line, the preprocessor uses somewhat different syntax. This syntax is
1207 +reminiscent of the syntax of Phar Lap macro assembler, but it
1208 +is @emph{not} meant to be a full emulation of Phar Lap or similar
1209 +assemblers. In particular, @sc{gasp} does not support directives such
1210 +as @code{DB} and @code{IRP}, even in alternate syntax mode.
1212 +In particular, @samp{-a} (or @samp{--alternate}) elicits these
1216 +@item Preprocessor directives
1217 +You can use @sc{gasp} preprocessor directives without a leading @samp{.}
1218 +dot. For example, you can write @samp{SDATA} with the same effect as
1222 +One additional directive, @code{LOCAL}, is available. @xref{Macros,,
1223 +Defining your own directives}, for an explanation of how to use
1227 +@item String delimiters
1228 +You can write strings delimited in these other ways besides
1229 +@code{"@var{string}"}:
1232 +@item '@var{string}'
1233 +You can delimit strings with single-quote charaters.
1235 +@item <@var{string}>
1236 +You can delimit strings with matching angle brackets.
1239 +@item single-character string escape
1240 +To include any single character literally in a string (even if the
1241 +character would otherwise have some special meaning), you can prefix the
1242 +character with @samp{!} (an exclamation mark). For example, you can
1243 +write @samp{<4.3 !> 5.4!!>} to get the literal text @samp{4.3 > 5.4!}.
1245 +@item Expression results as strings
1246 +You can write @samp{%@var{expr}} to evaluate the expression @var{expr}
1247 +and use the result as a string.
1250 +@node GNU Free Documentation License
1251 +@chapter GNU Free Documentation License
1253 + GNU Free Documentation License
1255 + Version 1.1, March 2000
1257 + Copyright (C) 2000 Free Software Foundation, Inc.
1258 + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1260 + Everyone is permitted to copy and distribute verbatim copies
1261 + of this license document, but changing it is not allowed.
1266 +The purpose of this License is to make a manual, textbook, or other
1267 +written document "free" in the sense of freedom: to assure everyone
1268 +the effective freedom to copy and redistribute it, with or without
1269 +modifying it, either commercially or noncommercially. Secondarily,
1270 +this License preserves for the author and publisher a way to get
1271 +credit for their work, while not being considered responsible for
1272 +modifications made by others.
1274 +This License is a kind of "copyleft", which means that derivative
1275 +works of the document must themselves be free in the same sense. It
1276 +complements the GNU General Public License, which is a copyleft
1277 +license designed for free software.
1279 +We have designed this License in order to use it for manuals for free
1280 +software, because free software needs free documentation: a free
1281 +program should come with manuals providing the same freedoms that the
1282 +software does. But this License is not limited to software manuals;
1283 +it can be used for any textual work, regardless of subject matter or
1284 +whether it is published as a printed book. We recommend this License
1285 +principally for works whose purpose is instruction or reference.
1288 +1. APPLICABILITY AND DEFINITIONS
1290 +This License applies to any manual or other work that contains a
1291 +notice placed by the copyright holder saying it can be distributed
1292 +under the terms of this License. The "Document", below, refers to any
1293 +such manual or work. Any member of the public is a licensee, and is
1294 +addressed as "you".
1296 +A "Modified Version" of the Document means any work containing the
1297 +Document or a portion of it, either copied verbatim, or with
1298 +modifications and/or translated into another language.
1300 +A "Secondary Section" is a named appendix or a front-matter section of
1301 +the Document that deals exclusively with the relationship of the
1302 +publishers or authors of the Document to the Document's overall subject
1303 +(or to related matters) and contains nothing that could fall directly
1304 +within that overall subject. (For example, if the Document is in part a
1305 +textbook of mathematics, a Secondary Section may not explain any
1306 +mathematics.) The relationship could be a matter of historical
1307 +connection with the subject or with related matters, or of legal,
1308 +commercial, philosophical, ethical or political position regarding
1311 +The "Invariant Sections" are certain Secondary Sections whose titles
1312 +are designated, as being those of Invariant Sections, in the notice
1313 +that says that the Document is released under this License.
1315 +The "Cover Texts" are certain short passages of text that are listed,
1316 +as Front-Cover Texts or Back-Cover Texts, in the notice that says that
1317 +the Document is released under this License.
1319 +A "Transparent" copy of the Document means a machine-readable copy,
1320 +represented in a format whose specification is available to the
1321 +general public, whose contents can be viewed and edited directly and
1322 +straightforwardly with generic text editors or (for images composed of
1323 +pixels) generic paint programs or (for drawings) some widely available
1324 +drawing editor, and that is suitable for input to text formatters or
1325 +for automatic translation to a variety of formats suitable for input
1326 +to text formatters. A copy made in an otherwise Transparent file
1327 +format whose markup has been designed to thwart or discourage
1328 +subsequent modification by readers is not Transparent. A copy that is
1329 +not "Transparent" is called "Opaque".
1331 +Examples of suitable formats for Transparent copies include plain
1332 +ASCII without markup, Texinfo input format, LaTeX input format, SGML
1333 +or XML using a publicly available DTD, and standard-conforming simple
1334 +HTML designed for human modification. Opaque formats include
1335 +PostScript, PDF, proprietary formats that can be read and edited only
1336 +by proprietary word processors, SGML or XML for which the DTD and/or
1337 +processing tools are not generally available, and the
1338 +machine-generated HTML produced by some word processors for output
1341 +The "Title Page" means, for a printed book, the title page itself,
1342 +plus such following pages as are needed to hold, legibly, the material
1343 +this License requires to appear in the title page. For works in
1344 +formats which do not have any title page as such, "Title Page" means
1345 +the text near the most prominent appearance of the work's title,
1346 +preceding the beginning of the body of the text.
1349 +2. VERBATIM COPYING
1351 +You may copy and distribute the Document in any medium, either
1352 +commercially or noncommercially, provided that this License, the
1353 +copyright notices, and the license notice saying this License applies
1354 +to the Document are reproduced in all copies, and that you add no other
1355 +conditions whatsoever to those of this License. You may not use
1356 +technical measures to obstruct or control the reading or further
1357 +copying of the copies you make or distribute. However, you may accept
1358 +compensation in exchange for copies. If you distribute a large enough
1359 +number of copies you must also follow the conditions in section 3.
1361 +You may also lend copies, under the same conditions stated above, and
1362 +you may publicly display copies.
1365 +3. COPYING IN QUANTITY
1367 +If you publish printed copies of the Document numbering more than 100,
1368 +and the Document's license notice requires Cover Texts, you must enclose
1369 +the copies in covers that carry, clearly and legibly, all these Cover
1370 +Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
1371 +the back cover. Both covers must also clearly and legibly identify
1372 +you as the publisher of these copies. The front cover must present
1373 +the full title with all words of the title equally prominent and
1374 +visible. You may add other material on the covers in addition.
1375 +Copying with changes limited to the covers, as long as they preserve
1376 +the title of the Document and satisfy these conditions, can be treated
1377 +as verbatim copying in other respects.
1379 +If the required texts for either cover are too voluminous to fit
1380 +legibly, you should put the first ones listed (as many as fit
1381 +reasonably) on the actual cover, and continue the rest onto adjacent
1384 +If you publish or distribute Opaque copies of the Document numbering
1385 +more than 100, you must either include a machine-readable Transparent
1386 +copy along with each Opaque copy, or state in or with each Opaque copy
1387 +a publicly-accessible computer-network location containing a complete
1388 +Transparent copy of the Document, free of added material, which the
1389 +general network-using public has access to download anonymously at no
1390 +charge using public-standard network protocols. If you use the latter
1391 +option, you must take reasonably prudent steps, when you begin
1392 +distribution of Opaque copies in quantity, to ensure that this
1393 +Transparent copy will remain thus accessible at the stated location
1394 +until at least one year after the last time you distribute an Opaque
1395 +copy (directly or through your agents or retailers) of that edition to
1398 +It is requested, but not required, that you contact the authors of the
1399 +Document well before redistributing any large number of copies, to give
1400 +them a chance to provide you with an updated version of the Document.
1405 +You may copy and distribute a Modified Version of the Document under
1406 +the conditions of sections 2 and 3 above, provided that you release
1407 +the Modified Version under precisely this License, with the Modified
1408 +Version filling the role of the Document, thus licensing distribution
1409 +and modification of the Modified Version to whoever possesses a copy
1410 +of it. In addition, you must do these things in the Modified Version:
1412 +A. Use in the Title Page (and on the covers, if any) a title distinct
1413 + from that of the Document, and from those of previous versions
1414 + (which should, if there were any, be listed in the History section
1415 + of the Document). You may use the same title as a previous version
1416 + if the original publisher of that version gives permission.
1417 +B. List on the Title Page, as authors, one or more persons or entities
1418 + responsible for authorship of the modifications in the Modified
1419 + Version, together with at least five of the principal authors of the
1420 + Document (all of its principal authors, if it has less than five).
1421 +C. State on the Title page the name of the publisher of the
1422 + Modified Version, as the publisher.
1423 +D. Preserve all the copyright notices of the Document.
1424 +E. Add an appropriate copyright notice for your modifications
1425 + adjacent to the other copyright notices.
1426 +F. Include, immediately after the copyright notices, a license notice
1427 + giving the public permission to use the Modified Version under the
1428 + terms of this License, in the form shown in the Addendum below.
1429 +G. Preserve in that license notice the full lists of Invariant Sections
1430 + and required Cover Texts given in the Document's license notice.
1431 +H. Include an unaltered copy of this License.
1432 +I. Preserve the section entitled "History", and its title, and add to
1433 + it an item stating at least the title, year, new authors, and
1434 + publisher of the Modified Version as given on the Title Page. If
1435 + there is no section entitled "History" in the Document, create one
1436 + stating the title, year, authors, and publisher of the Document as
1437 + given on its Title Page, then add an item describing the Modified
1438 + Version as stated in the previous sentence.
1439 +J. Preserve the network location, if any, given in the Document for
1440 + public access to a Transparent copy of the Document, and likewise
1441 + the network locations given in the Document for previous versions
1442 + it was based on. These may be placed in the "History" section.
1443 + You may omit a network location for a work that was published at
1444 + least four years before the Document itself, or if the original
1445 + publisher of the version it refers to gives permission.
1446 +K. In any section entitled "Acknowledgements" or "Dedications",
1447 + preserve the section's title, and preserve in the section all the
1448 + substance and tone of each of the contributor acknowledgements
1449 + and/or dedications given therein.
1450 +L. Preserve all the Invariant Sections of the Document,
1451 + unaltered in their text and in their titles. Section numbers
1452 + or the equivalent are not considered part of the section titles.
1453 +M. Delete any section entitled "Endorsements". Such a section
1454 + may not be included in the Modified Version.
1455 +N. Do not retitle any existing section as "Endorsements"
1456 + or to conflict in title with any Invariant Section.
1458 +If the Modified Version includes new front-matter sections or
1459 +appendices that qualify as Secondary Sections and contain no material
1460 +copied from the Document, you may at your option designate some or all
1461 +of these sections as invariant. To do this, add their titles to the
1462 +list of Invariant Sections in the Modified Version's license notice.
1463 +These titles must be distinct from any other section titles.
1465 +You may add a section entitled "Endorsements", provided it contains
1466 +nothing but endorsements of your Modified Version by various
1467 +parties--for example, statements of peer review or that the text has
1468 +been approved by an organization as the authoritative definition of a
1471 +You may add a passage of up to five words as a Front-Cover Text, and a
1472 +passage of up to 25 words as a Back-Cover Text, to the end of the list
1473 +of Cover Texts in the Modified Version. Only one passage of
1474 +Front-Cover Text and one of Back-Cover Text may be added by (or
1475 +through arrangements made by) any one entity. If the Document already
1476 +includes a cover text for the same cover, previously added by you or
1477 +by arrangement made by the same entity you are acting on behalf of,
1478 +you may not add another; but you may replace the old one, on explicit
1479 +permission from the previous publisher that added the old one.
1481 +The author(s) and publisher(s) of the Document do not by this License
1482 +give permission to use their names for publicity for or to assert or
1483 +imply endorsement of any Modified Version.
1486 +5. COMBINING DOCUMENTS
1488 +You may combine the Document with other documents released under this
1489 +License, under the terms defined in section 4 above for modified
1490 +versions, provided that you include in the combination all of the
1491 +Invariant Sections of all of the original documents, unmodified, and
1492 +list them all as Invariant Sections of your combined work in its
1495 +The combined work need only contain one copy of this License, and
1496 +multiple identical Invariant Sections may be replaced with a single
1497 +copy. If there are multiple Invariant Sections with the same name but
1498 +different contents, make the title of each such section unique by
1499 +adding at the end of it, in parentheses, the name of the original
1500 +author or publisher of that section if known, or else a unique number.
1501 +Make the same adjustment to the section titles in the list of
1502 +Invariant Sections in the license notice of the combined work.
1504 +In the combination, you must combine any sections entitled "History"
1505 +in the various original documents, forming one section entitled
1506 +"History"; likewise combine any sections entitled "Acknowledgements",
1507 +and any sections entitled "Dedications". You must delete all sections
1508 +entitled "Endorsements."
1511 +6. COLLECTIONS OF DOCUMENTS
1513 +You may make a collection consisting of the Document and other documents
1514 +released under this License, and replace the individual copies of this
1515 +License in the various documents with a single copy that is included in
1516 +the collection, provided that you follow the rules of this License for
1517 +verbatim copying of each of the documents in all other respects.
1519 +You may extract a single document from such a collection, and distribute
1520 +it individually under this License, provided you insert a copy of this
1521 +License into the extracted document, and follow this License in all
1522 +other respects regarding verbatim copying of that document.
1525 +7. AGGREGATION WITH INDEPENDENT WORKS
1527 +A compilation of the Document or its derivatives with other separate
1528 +and independent documents or works, in or on a volume of a storage or
1529 +distribution medium, does not as a whole count as a Modified Version
1530 +of the Document, provided no compilation copyright is claimed for the
1531 +compilation. Such a compilation is called an "aggregate", and this
1532 +License does not apply to the other self-contained works thus compiled
1533 +with the Document, on account of their being thus compiled, if they
1534 +are not themselves derivative works of the Document.
1536 +If the Cover Text requirement of section 3 is applicable to these
1537 +copies of the Document, then if the Document is less than one quarter
1538 +of the entire aggregate, the Document's Cover Texts may be placed on
1539 +covers that surround only the Document within the aggregate.
1540 +Otherwise they must appear on covers around the whole aggregate.
1545 +Translation is considered a kind of modification, so you may
1546 +distribute translations of the Document under the terms of section 4.
1547 +Replacing Invariant Sections with translations requires special
1548 +permission from their copyright holders, but you may include
1549 +translations of some or all Invariant Sections in addition to the
1550 +original versions of these Invariant Sections. You may include a
1551 +translation of this License provided that you also include the
1552 +original English version of this License. In case of a disagreement
1553 +between the translation and the original English version of this
1554 +License, the original English version will prevail.
1559 +You may not copy, modify, sublicense, or distribute the Document except
1560 +as expressly provided for under this License. Any other attempt to
1561 +copy, modify, sublicense or distribute the Document is void, and will
1562 +automatically terminate your rights under this License. However,
1563 +parties who have received copies, or rights, from you under this
1564 +License will not have their licenses terminated so long as such
1565 +parties remain in full compliance.
1568 +10. FUTURE REVISIONS OF THIS LICENSE
1570 +The Free Software Foundation may publish new, revised versions
1571 +of the GNU Free Documentation License from time to time. Such new
1572 +versions will be similar in spirit to the present version, but may
1573 +differ in detail to address new problems or concerns. See
1574 +http://www.gnu.org/copyleft/.
1576 +Each version of the License is given a distinguishing version number.
1577 +If the Document specifies that a particular numbered version of this
1578 +License "or any later version" applies to it, you have the option of
1579 +following the terms and conditions either of that specified version or
1580 +of any later version that has been published (not as a draft) by the
1581 +Free Software Foundation. If the Document does not specify a version
1582 +number of this License, you may choose any version ever published (not
1583 +as a draft) by the Free Software Foundation.
1586 +ADDENDUM: How to use this License for your documents
1588 +To use this License in a document you have written, include a copy of
1589 +the License in the document and put the following copyright and
1590 +license notices just after the title page:
1593 + Copyright (c) YEAR YOUR NAME.
1594 + Permission is granted to copy, distribute and/or modify this document
1595 + under the terms of the GNU Free Documentation License, Version 1.1
1596 + or any later version published by the Free Software Foundation;
1597 + with the Invariant Sections being LIST THEIR TITLES, with the
1598 + Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
1599 + A copy of the license is included in the section entitled "GNU
1600 + Free Documentation License".
1603 +If you have no Invariant Sections, write "with no Invariant Sections"
1604 +instead of saying which ones are invariant. If you have no
1605 +Front-Cover Texts, write "no Front-Cover Texts" instead of
1606 +"Front-Cover Texts being LIST"; likewise for Back-Cover Texts.
1608 +If your document contains nontrivial examples of program code, we
1609 +recommend releasing these examples in parallel under your choice of
1610 +free software license, such as the GNU General Public License,
1611 +to permit their use in free software.
1620 diff -Nur binutils-2.13.90.0.18.orig/gas/gasp.c binutils-2.13.90.0.18/gas/gasp.c
1621 --- binutils-2.13.90.0.18.orig/gas/gasp.c Thu Jan 1 01:00:00 1970
1622 +++ binutils-2.13.90.0.18/gas/gasp.c Sun May 26 18:57:12 2002
1624 +/* gasp.c - Gnu assembler preprocessor main program.
1625 + Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
1626 + Free Software Foundation, Inc.
1628 + Written by Steve and Judy Chamberlain of Cygnus Support,
1631 + This file is part of GASP, the GNU Assembler Preprocessor.
1633 + GASP is free software; you can redistribute it and/or modify
1634 + it under the terms of the GNU General Public License as published by
1635 + the Free Software Foundation; either version 2, or (at your option)
1636 + any later version.
1638 + GASP is distributed in the hope that it will be useful,
1639 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1640 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1641 + GNU General Public License for more details.
1643 + You should have received a copy of the GNU General Public License
1644 + along with GASP; see the file COPYING. If not, write to the Free
1645 + Software Foundation, 59 Temple Place - Suite 330, Boston, MA
1646 + 02111-1307, USA. */
1649 +This program translates the input macros and stuff into a form
1650 +suitable for gas to consume.
1652 + gasp [-sdhau] [-c char] [-o <outfile>] <infile>*
1654 + -s copy source to output
1655 + -c <char> comments are started with <char> instead of !
1656 + -u allow unreasonable stuff
1657 + -p print line numbers
1658 + -d print debugging stats
1659 + -s semi colons start comments
1660 + -a use alternate syntax
1661 + Pseudo ops can start with or without a .
1662 + Labels have to be in first column.
1663 + -I specify include dir
1664 + Macro arg parameters subsituted by name, don't need the &.
1665 + String can start with ' too.
1666 + Strings can be surrounded by <..>
1667 + A %<exp> in a string evaluates the expression
1668 + Literal char in a string with !
1671 +#include "config.h"
1672 +#include "bin-bugs.h"
1674 +#include <assert.h>
1676 +#include <string.h>
1677 +#include "getopt.h"
1679 +#ifdef HAVE_STDLIB_H
1680 +#include <stdlib.h>
1683 +#ifdef NEED_MALLOC_DECLARATION
1684 +extern char *malloc ();
1687 +#include "ansidecl.h"
1688 +#include "libiberty.h"
1689 +#include "safe-ctype.h"
1692 +#include "asintl.h"
1693 +#include "xregex.h"
1695 +char *program_version = "1.2";
1697 +/* This is normally declared in as.h, but we don't include that. We
1698 + need the function because other files linked with gasp.c might call
1700 +extern void as_abort PARAMS ((const char *, int, const char *));
1702 +/* The default obstack chunk size. If we set this to zero, the
1703 + obstack code will use whatever will fit in a 4096 byte block. This
1704 + is used by the hash table code used by macro.c. */
1707 +#define MAX_INCLUDES 30 /* Maximum include depth. */
1708 +#define MAX_REASONABLE 1000 /* Maximum number of expansions. */
1710 +int unreasonable; /* -u on command line. */
1711 +int stats; /* -d on command line. */
1712 +int print_line_number; /* -p flag on command line. */
1713 +int copysource; /* -c flag on command line. */
1714 +int warnings; /* Number of WARNINGs generated so far. */
1715 +int errors; /* Number of ERRORs generated so far. */
1716 +int fatals; /* Number of fatal ERRORs generated so far (either 0 or 1). */
1717 +int alternate = 0; /* -a on command line. */
1718 +int mri = 0; /* -M on command line. */
1719 +char comment_char = '!';
1720 +int radix = 10; /* Default radix. */
1722 +int had_end; /* Seen .END. */
1724 +/* The output stream. */
1727 +/* The attributes of each character are stored as a bit pattern
1728 + chartype, which gives us quick tests. */
1734 +#define COMMENTBIT 16
1736 +#define ISCOMMENTCHAR(x) (chartype[(unsigned char)(x)] & COMMENTBIT)
1737 +#define ISFIRSTCHAR(x) (chartype[(unsigned char)(x)] & FIRSTBIT)
1738 +#define ISNEXTCHAR(x) (chartype[(unsigned char)(x)] & NEXTBIT)
1739 +#define ISSEP(x) (chartype[(unsigned char)(x)] & SEPBIT)
1740 +#define ISWHITE(x) (chartype[(unsigned char)(x)] & WHITEBIT)
1741 +#define ISBASE(x) (chartype[(unsigned char)(x)] & BASEBIT)
1742 +static char chartype[256];
1744 +/* Conditional assembly uses the `ifstack'. Each aif pushes another
1745 + entry onto the stack, and sets the on flag if it should. The aelse
1746 + sets hadelse, and toggles on. An aend pops a level. We limit to
1747 + 100 levels of nesting, not because we're facists pigs with read
1748 + only minds, but because more than 100 levels of nesting is probably
1749 + a bug in the user's macro structure. */
1751 +#define IFNESTING 100
1753 + int on; /* Is the level being output. */
1754 + int hadelse; /* Has an aelse been seen. */
1755 +} ifstack[IFNESTING];
1759 +/* The final and intermediate results of expression evaluation are kept in
1760 + exp_t's. Note that a symbol is not an sb, but a pointer into the input
1761 + line. It must be coped somewhere safe before the next line is read in. */
1769 + int value; /* Constant part. */
1770 + symbol add_symbol; /* Name part. */
1771 + symbol sub_symbol; /* Name part. */
1774 +/* Hashing is done in a pretty standard way. A hash_table has a
1775 + pointer to a vector of pointers to hash_entrys, and the size of the
1776 + vector. A hash_entry contains a union of all the info we like to
1777 + store in hash table. If there is a hash collision, hash_entries
1778 + with the same hash are kept in a chain. */
1780 +/* What the data in a hash_entry means. */
1782 + hash_integer, /* Name->integer mapping. */
1783 + hash_string, /* Name->string mapping. */
1784 + hash_macro, /* Name is a macro. */
1785 + hash_formal /* Name is a formal argument. */
1788 +typedef struct hs {
1789 + sb key; /* Symbol name. */
1790 + hash_type type; /* Symbol meaning. */
1794 + struct macro_struct *m;
1795 + struct formal_struct *f;
1797 + struct hs *next; /* Next hash_entry with same hash key. */
1801 + hash_entry **table;
1805 +/* How we nest files and expand macros etc.
1807 + We keep a stack of of include_stack structs. Each include file
1808 + pushes a new level onto the stack. We keep an sb with a pushback
1809 + too. unget chars are pushed onto the pushback sb, getchars first
1810 + checks the pushback sb before reading from the input stream.
1812 + Small things are expanded by adding the text of the item onto the
1813 + pushback sb. Larger items are grown by pushing a new level and
1814 + allocating the entire pushback buf for the item. Each time
1815 + something like a macro is expanded, the stack index is changed. We
1816 + can then perform an exitm by popping all entries off the stack with
1817 + the same stack index. If we're being reasonable, we can detect
1818 + recusive expansion by checking the index is reasonably small. */
1821 + include_file, include_repeat, include_while, include_macro
1824 +struct include_stack {
1825 + sb pushback; /* Current pushback stream. */
1826 + int pushback_index; /* Next char to read from stream. */
1827 + FILE *handle; /* Open file. */
1828 + sb name; /* Name of file. */
1829 + int linecount; /* Number of lines read so far. */
1830 + include_type type;
1831 + int index; /* Index of this layer. */
1832 +} include_stack[MAX_INCLUDES];
1834 +struct include_stack *sp;
1835 +#define isp (sp - include_stack)
1837 +/* Include file list. */
1839 +typedef struct include_path {
1840 + struct include_path *next;
1844 +include_path *paths_head;
1845 +include_path *paths_tail;
1847 +static void quit PARAMS ((void));
1848 +static void hash_new_table PARAMS ((int, hash_table *));
1849 +static int hash PARAMS ((sb *));
1850 +static hash_entry *hash_create PARAMS ((hash_table *, sb *));
1851 +static void hash_add_to_string_table PARAMS ((hash_table *, sb *, sb *, int));
1852 +static void hash_add_to_int_table PARAMS ((hash_table *, sb *, int));
1853 +static hash_entry *hash_lookup PARAMS ((hash_table *, sb *));
1854 +static void checkconst PARAMS ((int, exp_t *));
1855 +static int is_flonum PARAMS ((int, sb *));
1856 +static int chew_flonum PARAMS ((int, sb *, sb *));
1857 +static int sb_strtol PARAMS ((int, sb *, int, int *));
1858 +static int level_0 PARAMS ((int, sb *, exp_t *));
1859 +static int level_1 PARAMS ((int, sb *, exp_t *));
1860 +static int level_2 PARAMS ((int, sb *, exp_t *));
1861 +static int level_3 PARAMS ((int, sb *, exp_t *));
1862 +static int level_4 PARAMS ((int, sb *, exp_t *));
1863 +static int level_5 PARAMS ((int, sb *, exp_t *));
1864 +static int exp_parse PARAMS ((int, sb *, exp_t *));
1865 +static void exp_string PARAMS ((exp_t *, sb *));
1866 +static int exp_get_abs PARAMS ((const char *, int, sb *, int *));
1868 +static void strip_comments PARAMS ((sb *));
1870 +static void unget PARAMS ((int));
1871 +static void include_buf PARAMS ((sb *, sb *, include_type, int));
1872 +static void include_print_where_line PARAMS ((FILE *));
1873 +static void include_print_line PARAMS ((FILE *));
1874 +static int get_line PARAMS ((sb *));
1875 +static int grab_label PARAMS ((sb *, sb *));
1876 +static void change_base PARAMS ((int, sb *, sb *));
1877 +static void do_end PARAMS ((sb *));
1878 +static void do_assign PARAMS ((int, int, sb *));
1879 +static void do_radix PARAMS ((sb *));
1880 +static int get_opsize PARAMS ((int, sb *, int *));
1881 +static int eol PARAMS ((int, sb *));
1882 +static void do_data PARAMS ((int, sb *, int));
1883 +static void do_datab PARAMS ((int, sb *));
1884 +static void do_align PARAMS ((int, sb *));
1885 +static void do_res PARAMS ((int, sb *, int));
1886 +static void do_export PARAMS ((sb *));
1887 +static void do_print PARAMS ((int, sb *));
1888 +static void do_heading PARAMS ((int, sb *));
1889 +static void do_page PARAMS ((void));
1890 +static void do_form PARAMS ((int, sb *));
1891 +static int get_any_string PARAMS ((int, sb *, sb *, int, int));
1892 +static int skip_openp PARAMS ((int, sb *));
1893 +static int skip_closep PARAMS ((int, sb *));
1894 +static int dolen PARAMS ((int, sb *, sb *));
1895 +static int doinstr PARAMS ((int, sb *, sb *));
1896 +static int dosubstr PARAMS ((int, sb *, sb *));
1897 +static void process_assigns PARAMS ((int, sb *, sb *));
1898 +static int get_and_process PARAMS ((int, sb *, sb *));
1899 +static void process_file PARAMS ((void));
1900 +static void free_old_entry PARAMS ((hash_entry *));
1901 +static void do_assigna PARAMS ((int, sb *));
1902 +static void do_assignc PARAMS ((int, sb *));
1903 +static void do_reg PARAMS ((int, sb *));
1904 +static int condass_lookup_name PARAMS ((sb *, int, sb *, int));
1905 +static int whatcond PARAMS ((int, sb *, int *));
1906 +static int istrue PARAMS ((int, sb *));
1907 +static void do_aif PARAMS ((int, sb *));
1908 +static void do_aelse PARAMS ((void));
1909 +static void do_aendi PARAMS ((void));
1910 +static int condass_on PARAMS ((void));
1911 +static void do_if PARAMS ((int, sb *, int));
1912 +static int get_mri_string PARAMS ((int, sb *, sb *, int));
1913 +static void do_ifc PARAMS ((int, sb *, int));
1914 +static void do_aendr PARAMS ((void));
1915 +static void do_awhile PARAMS ((int, sb *));
1916 +static void do_aendw PARAMS ((void));
1917 +static void do_exitm PARAMS ((void));
1918 +static void do_arepeat PARAMS ((int, sb *));
1919 +static void do_endm PARAMS ((void));
1920 +static void do_irp PARAMS ((int, sb *, int));
1921 +static void do_local PARAMS ((int, sb *));
1922 +static void do_macro PARAMS ((int, sb *));
1923 +static int macro_op PARAMS ((int, sb *));
1924 +static int getstring PARAMS ((int, sb *, sb *));
1925 +static void do_sdata PARAMS ((int, sb *, int));
1926 +static void do_sdatab PARAMS ((int, sb *));
1927 +static int new_file PARAMS ((const char *));
1928 +static void do_include PARAMS ((int, sb *));
1929 +static void include_pop PARAMS ((void));
1930 +static int get PARAMS ((void));
1931 +static int linecount PARAMS ((void));
1932 +static int include_next_index PARAMS ((void));
1933 +static void chartype_init PARAMS ((void));
1934 +static int process_pseudo_op PARAMS ((int, sb *, sb *));
1935 +static void add_keyword PARAMS ((const char *, int));
1936 +static void process_init PARAMS ((void));
1937 +static void do_define PARAMS ((const char *));
1938 +static void show_usage PARAMS ((FILE *, int));
1939 +static void show_help PARAMS ((void));
1944 + include_print_where_line (stderr); \
1954 + include_print_where_line (stderr); \
1960 +#define WARNING(x) \
1963 + include_print_where_line (stderr); \
1969 +/* Exit the program and return the right ERROR code. */
1975 + if (fatals + errors)
1983 + for (i = 0; i < sb_max_power_two; i++)
1985 + fprintf (stderr, "strings size %8d : %d\n",
1986 + 1 << i, string_count[i]);
1992 +/* Hash table maintenance. */
1994 +/* Build a new hash table with size buckets
1995 + and fill in the info at ptr. */
1998 +hash_new_table (size, ptr)
2004 + ptr->table = (hash_entry **) xmalloc (size * (sizeof (hash_entry *)));
2005 + /* Fill with null-pointer, not zero-bit-pattern. */
2006 + for (i = 0; i < size; i++)
2007 + ptr->table[i] = 0;
2010 +/* Calculate and return the hash value of the sb at key. */
2018 + char *p = key->ptr;
2019 + for (i = 0; i < key->len; i++)
2021 + k ^= (k << 2) ^ *p;
2024 + return k & 0xf0fff;
2027 +/* Look up key in hash_table tab. If present, then return it,
2028 + otherwise build a new one and fill it with hash_integer. */
2030 +static hash_entry *
2031 +hash_create (tab, key)
2035 + int k = hash (key) % tab->size;
2037 + hash_entry **table = tab->table;
2045 + hash_entry *n = (hash_entry *) xmalloc (sizeof (hash_entry));
2046 + n->next = table[k];
2048 + sb_add_sb (&n->key, key);
2050 + n->type = hash_integer;
2053 + if (strncmp (table[k]->key.ptr, key->ptr, key->len) == 0)
2061 +/* Add sb name with key into hash_table tab.
2062 + If replacing old value and again, then ERROR. */
2065 +hash_add_to_string_table (tab, key, name, again)
2071 + hash_entry *ptr = hash_create (tab, key);
2072 + if (ptr->type == hash_integer)
2074 + sb_new (&ptr->value.s);
2076 + if (ptr->value.s.len)
2079 + ERROR ((stderr, _("redefinition not allowed\n")));
2082 + ptr->type = hash_string;
2083 + sb_reset (&ptr->value.s);
2085 + sb_add_sb (&ptr->value.s, name);
2088 +/* Add integer name to hash_table tab with sb key. */
2091 +hash_add_to_int_table (tab, key, name)
2096 + hash_entry *ptr = hash_create (tab, key);
2097 + ptr->value.i = name;
2100 +/* Look up sb key in hash_table tab.
2101 + If found, return hash_entry result, else 0. */
2103 +static hash_entry *
2104 +hash_lookup (tab, key)
2108 + int k = hash (key) % tab->size;
2109 + hash_entry **table = tab->table;
2110 + hash_entry *p = table[k];
2113 + if (p->key.len == key->len
2114 + && strncmp (p->key.ptr, key->ptr, key->len) == 0)
2123 + are handled in a really simple recursive decent way. each bit of
2124 + the machine takes an index into an sb and a pointer to an exp_t,
2125 + modifies the *exp_t and returns the index of the first character
2126 + past the part of the expression parsed.
2128 + expression precedence:
2137 +/* Make sure that the exp_t at term is constant.
2138 + If not the give the op ERROR. */
2141 +checkconst (op, term)
2145 + if (term->add_symbol.len
2146 + || term->sub_symbol.len)
2148 + ERROR ((stderr, _("the %c operator cannot take non-absolute arguments.\n"), op));
2152 +/* Chew the flonum from the string starting at idx. Adjust idx to
2153 + point to the next character after the flonum. */
2156 +chew_flonum (idx, string, out)
2165 + /* Duplicate and null terminate `string'. */
2167 + sb_add_sb (&buf, string);
2168 + sb_add_char (&buf, '\0');
2170 + if (regcomp (®, "([0-9]*\\.[0-9]+([eE][+-]?[0-9]+)?)", REG_EXTENDED) != 0)
2172 + if (regexec (®, &buf.ptr[idx], 1, &match, 0) != 0)
2175 + /* Copy the match to the output. */
2176 + assert (match.rm_eo >= match.rm_so);
2177 + sb_add_buffer (out, &buf.ptr[idx], match.rm_eo - match.rm_so);
2181 + idx += match.rm_eo;
2186 +is_flonum (idx, string)
2194 + /* Duplicate and null terminate `string'. */
2196 + sb_add_sb (&buf, string);
2197 + sb_add_char (&buf, '\0');
2199 + if (regcomp (®, "^[0-9]*\\.[0-9]+([eE][+-]?[0-9]+)?", REG_EXTENDED) != 0)
2202 + rc = regexec (®, &buf.ptr[idx], 0, NULL, 0);
2208 +/* Turn the number in string at idx into a number of base, fill in
2209 + ptr, and return the index of the first character not in the number. */
2212 +sb_strtol (idx, string, base, ptr)
2219 + idx = sb_skip_white (idx, string);
2221 + while (idx < string->len)
2223 + int ch = string->ptr[idx];
2227 + else if (ch >= 'a' && ch <= 'f')
2228 + dig = ch - 'a' + 10;
2229 + else if (ch >= 'A' && ch <= 'F')
2230 + dig = ch - 'A' + 10;
2237 + value = value * base + dig;
2245 +level_0 (idx, string, lhs)
2250 + lhs->add_symbol.len = 0;
2251 + lhs->add_symbol.name = 0;
2253 + lhs->sub_symbol.len = 0;
2254 + lhs->sub_symbol.name = 0;
2256 + idx = sb_skip_white (idx, string);
2260 + if (ISDIGIT (string->ptr[idx]))
2262 + idx = sb_strtol (idx, string, 10, &lhs->value);
2264 + else if (ISFIRSTCHAR (string->ptr[idx]))
2267 + lhs->add_symbol.name = string->ptr + idx;
2268 + while (idx < string->len && ISNEXTCHAR (string->ptr[idx]))
2273 + lhs->add_symbol.len = len;
2275 + else if (string->ptr[idx] == '"')
2279 + ERROR ((stderr, _("string where expression expected.\n")));
2280 + idx = getstring (idx, string, &acc);
2285 + ERROR ((stderr, _("can't find primary in expression.\n")));
2288 + return sb_skip_white (idx, string);
2292 +level_1 (idx, string, lhs)
2297 + idx = sb_skip_white (idx, string);
2299 + switch (string->ptr[idx])
2302 + idx = level_1 (idx + 1, string, lhs);
2305 + idx = level_1 (idx + 1, string, lhs);
2306 + checkconst ('~', lhs);
2307 + lhs->value = ~lhs->value;
2312 + idx = level_1 (idx + 1, string, lhs);
2313 + lhs->value = -lhs->value;
2314 + t = lhs->add_symbol;
2315 + lhs->add_symbol = lhs->sub_symbol;
2316 + lhs->sub_symbol = t;
2321 + idx = level_5 (sb_skip_white (idx, string), string, lhs);
2322 + if (string->ptr[idx] != ')')
2323 + ERROR ((stderr, _("misplaced closing parens.\n")));
2328 + idx = level_0 (idx, string, lhs);
2331 + return sb_skip_white (idx, string);
2335 +level_2 (idx, string, lhs)
2342 + idx = level_1 (idx, string, lhs);
2344 + while (idx < string->len && (string->ptr[idx] == '*'
2345 + || string->ptr[idx] == '/'))
2347 + char op = string->ptr[idx++];
2348 + idx = level_1 (idx, string, &rhs);
2352 + checkconst ('*', lhs);
2353 + checkconst ('*', &rhs);
2354 + lhs->value *= rhs.value;
2357 + checkconst ('/', lhs);
2358 + checkconst ('/', &rhs);
2359 + if (rhs.value == 0)
2360 + ERROR ((stderr, _("attempt to divide by zero.\n")));
2362 + lhs->value /= rhs.value;
2366 + return sb_skip_white (idx, string);
2370 +level_3 (idx, string, lhs)
2377 + idx = level_2 (idx, string, lhs);
2379 + while (idx < string->len
2380 + && (string->ptr[idx] == '+'
2381 + || string->ptr[idx] == '-'))
2383 + char op = string->ptr[idx++];
2384 + idx = level_2 (idx, string, &rhs);
2388 + lhs->value += rhs.value;
2389 + if (lhs->add_symbol.name && rhs.add_symbol.name)
2391 + ERROR ((stderr, _("can't add two relocatable expressions\n")));
2393 + /* Change nn+symbol to symbol + nn. */
2394 + if (rhs.add_symbol.name)
2396 + lhs->add_symbol = rhs.add_symbol;
2400 + lhs->value -= rhs.value;
2401 + lhs->sub_symbol = rhs.add_symbol;
2405 + return sb_skip_white (idx, string);
2409 +level_4 (idx, string, lhs)
2416 + idx = level_3 (idx, string, lhs);
2418 + while (idx < string->len &&
2419 + string->ptr[idx] == '&')
2421 + char op = string->ptr[idx++];
2422 + idx = level_3 (idx, string, &rhs);
2426 + checkconst ('&', lhs);
2427 + checkconst ('&', &rhs);
2428 + lhs->value &= rhs.value;
2432 + return sb_skip_white (idx, string);
2436 +level_5 (idx, string, lhs)
2443 + idx = level_4 (idx, string, lhs);
2445 + while (idx < string->len
2446 + && (string->ptr[idx] == '|' || string->ptr[idx] == '~'))
2448 + char op = string->ptr[idx++];
2449 + idx = level_4 (idx, string, &rhs);
2453 + checkconst ('|', lhs);
2454 + checkconst ('|', &rhs);
2455 + lhs->value |= rhs.value;
2458 + checkconst ('~', lhs);
2459 + checkconst ('~', &rhs);
2460 + lhs->value ^= rhs.value;
2464 + return sb_skip_white (idx, string);
2467 +/* Parse the expression at offset idx into string, fill up res with
2468 + the result. Return the index of the first char past the
2472 +exp_parse (idx, string, res)
2477 + return level_5 (sb_skip_white (idx, string), string, res);
2480 +/* Turn the expression at exp into text and glue it onto the end of
2484 +exp_string (exp, string)
2490 + sb_reset (string);
2492 + if (exp->add_symbol.len)
2494 + sb_add_buffer (string, exp->add_symbol.name, exp->add_symbol.len);
2502 + sb_add_char (string, '+');
2503 + sprintf (buf, "%d", exp->value);
2504 + sb_add_string (string, buf);
2508 + if (exp->sub_symbol.len)
2510 + sb_add_char (string, '-');
2511 + sb_add_buffer (string, exp->add_symbol.name, exp->add_symbol.len);
2517 + sb_add_char (string, '0');
2520 +/* Parse the expression at offset idx into sb in. Return the value in
2521 + val. If the expression is not constant, give ERROR emsg. Return
2522 + the index of the first character past the end of the expression. */
2525 +exp_get_abs (emsg, idx, in, val)
2532 + idx = exp_parse (idx, in, &res);
2533 + if (res.add_symbol.len || res.sub_symbol.len)
2534 + ERROR ((stderr, "%s", emsg));
2539 +/* Current label parsed from line. */
2542 +/* Hash table for all assigned variables. */
2543 +hash_table assign_hash_table;
2545 +/* Hash table for keyword. */
2546 +hash_table keyword_hash_table;
2548 +/* Hash table for eq variables. */
2551 +#define in_comment ';'
2555 +strip_comments (out)
2558 + char *s = out->ptr;
2560 + for (i = 0; i < out->len; i++)
2562 + if (ISCOMMENTCHAR (s[i]))
2571 +/* Push back character ch so that it can be read again. */
2581 + if (sp->pushback_index)
2582 + sp->pushback_index--;
2584 + sb_add_char (&sp->pushback, ch);
2587 +/* Push the sb ptr onto the include stack, with the given name, type
2591 +include_buf (name, ptr, type, index)
2594 + include_type type;
2598 + if (sp - include_stack >= MAX_INCLUDES)
2599 + FATAL ((stderr, _("unreasonable nesting.\n")));
2600 + sb_new (&sp->name);
2601 + sb_add_sb (&sp->name, name);
2603 + sp->linecount = 1;
2604 + sp->pushback_index = 0;
2606 + sp->index = index;
2607 + sb_new (&sp->pushback);
2608 + sb_add_sb (&sp->pushback, ptr);
2611 +/* Used in ERROR messages, print info on where the include stack is
2615 +include_print_where_line (file)
2618 + struct include_stack *p = include_stack + 1;
2622 + fprintf (file, "%s:%d ", sb_name (&p->name), p->linecount - 1);
2627 +/* Used in listings, print the line number onto file. */
2630 +include_print_line (file)
2634 + struct include_stack *p = include_stack + 1;
2636 + n = fprintf (file, "%4d", p->linecount);
2640 + n += fprintf (file, ".%d", p->linecount);
2645 + fprintf (file, " ");
2650 +/* Read a line from the top of the include stack into sb in. */
2657 + int more = 1, ch = 0;
2661 + putc (comment_char, outfile);
2662 + if (print_line_number)
2663 + include_print_line (outfile);
2670 + while (ch == '\r')
2677 + WARNING ((stderr, _("End of file not at start of line.\n")));
2679 + putc ('\n', outfile);
2689 + putc (ch, outfile);
2698 + /* Continued line. */
2701 + putc (comment_char, outfile);
2702 + putc ('+', outfile);
2715 + sb_add_char (in, ch);
2720 + return more ? ch : 0;
2723 +/* Find a label from sb in and put it in out. */
2726 +grab_label (in, out)
2732 + if (ISFIRSTCHAR (in->ptr[i]) || in->ptr[i] == '\\')
2734 + sb_add_char (out, in->ptr[i]);
2736 + while ((ISNEXTCHAR (in->ptr[i])
2737 + || in->ptr[i] == '\\'
2738 + || in->ptr[i] == '&')
2741 + sb_add_char (out, in->ptr[i]);
2748 +/* Find all strange base stuff and turn into decimal. Also
2749 + find all the other numbers and convert them from the default radix. */
2752 +change_base (idx, in, out)
2759 + while (idx < in->len)
2761 + if (in->ptr[idx] == '\\'
2762 + && idx + 1 < in->len
2763 + && in->ptr[idx + 1] == '(')
2766 + while (idx < in->len
2767 + && in->ptr[idx] != ')')
2769 + sb_add_char (out, in->ptr[idx]);
2772 + if (idx < in->len)
2775 + else if (idx < in->len - 1 && in->ptr[idx + 1] == '\'' && ! mri)
2779 + switch (in->ptr[idx])
2798 + ERROR ((stderr, _("Illegal base character %c.\n"), in->ptr[idx]));
2803 + idx = sb_strtol (idx + 2, in, base, &value);
2804 + sprintf (buffer, "%d", value);
2805 + sb_add_string (out, buffer);
2807 + else if (ISFIRSTCHAR (in->ptr[idx]))
2809 + /* Copy entire names through quickly. */
2810 + sb_add_char (out, in->ptr[idx]);
2812 + while (idx < in->len && ISNEXTCHAR (in->ptr[idx]))
2814 + sb_add_char (out, in->ptr[idx]);
2818 + else if (is_flonum (idx, in))
2820 + idx = chew_flonum (idx, in, out);
2822 + else if (ISDIGIT (in->ptr[idx]))
2825 + /* All numbers must start with a digit, let's chew it and
2826 + spit out decimal. */
2827 + idx = sb_strtol (idx, in, radix, &value);
2828 + sprintf (buffer, "%d", value);
2829 + sb_add_string (out, buffer);
2831 + /* Skip all undigsested letters. */
2832 + while (idx < in->len && ISNEXTCHAR (in->ptr[idx]))
2834 + sb_add_char (out, in->ptr[idx]);
2838 + else if (in->ptr[idx] == '"' || in->ptr[idx] == '\'')
2840 + char tchar = in->ptr[idx];
2841 + /* Copy entire names through quickly. */
2842 + sb_add_char (out, in->ptr[idx]);
2844 + while (idx < in->len && in->ptr[idx] != tchar)
2846 + sb_add_char (out, in->ptr[idx]);
2852 + /* Nothing special, just pass it through. */
2853 + sb_add_char (out, in->ptr[idx]);
2868 + fprintf (outfile, "%s\n", sb_name (in));
2874 +do_assign (again, idx, in)
2879 + /* Stick label in symbol table with following value. */
2884 + idx = exp_parse (idx, in, &e);
2885 + exp_string (&e, &acc);
2886 + hash_add_to_string_table (&assign_hash_table, &label, &acc, again);
2890 +/* .radix [b|q|d|h] */
2896 + int idx = sb_skip_white (0, ptr);
2897 + switch (ptr->ptr[idx])
2916 + ERROR ((stderr, _("radix is %c must be one of b, q, d or h"), radix));
2920 +/* Parse off a .b, .w or .l. */
2923 +get_opsize (idx, in, size)
2929 + if (in->ptr[idx] == '.')
2933 + switch (in->ptr[idx])
2951 + ERROR ((stderr, _("size must be one of b, w or l, is %c.\n"), in->ptr[idx]));
2964 + idx = sb_skip_white (idx, line);
2965 + if (idx < line->len
2966 + && ISCOMMENTCHAR(line->ptr[idx]))
2968 + if (idx >= line->len)
2973 +/* .data [.b|.w|.l] <data>*
2974 + or d[bwl] <data>* */
2977 +do_data (idx, in, size)
2983 + char *opname = ".yikes!";
2989 + idx = get_opsize (idx, in, &opsize);
3001 + opname = ".short";
3008 + fprintf (outfile, "%s\t", opname);
3010 + idx = sb_skip_white (idx, in);
3014 + && in->ptr[idx] == '"')
3017 + idx = getstring (idx, in, &acc);
3018 + for (i = 0; i < acc.len; i++)
3021 + fprintf (outfile, ",");
3022 + fprintf (outfile, "%d", acc.ptr[i]);
3027 + while (!eol (idx, in))
3030 + idx = exp_parse (idx, in, &e);
3031 + exp_string (&e, &acc);
3032 + sb_add_char (&acc, 0);
3033 + fprintf (outfile, "%s", acc.ptr);
3034 + if (idx < in->len && in->ptr[idx] == ',')
3036 + fprintf (outfile, ",");
3042 + sb_print_at (outfile, idx, in);
3043 + fprintf (outfile, "\n");
3046 +/* .datab [.b|.w|.l] <repeat>,<fill> */
3057 + idx = get_opsize (idx, in, &opsize);
3059 + idx = exp_get_abs (_("datab repeat must be constant.\n"), idx, in, &repeat);
3060 + idx = sb_skip_comma (idx, in);
3061 + idx = exp_get_abs (_("datab data must be absolute.\n"), idx, in, &fill);
3063 + fprintf (outfile, ".fill\t%d,%d,%d\n", repeat, opsize, fill);
3066 +/* .align <size> */
3073 + int al, have_fill, fill;
3075 + idx = exp_get_abs (_("align needs absolute expression.\n"), idx, in, &al);
3076 + idx = sb_skip_white (idx, in);
3079 + if (! eol (idx, in))
3081 + idx = sb_skip_comma (idx, in);
3082 + idx = exp_get_abs (_(".align needs absolute fill value.\n"), idx, in,
3087 + fprintf (outfile, ".align %d", al);
3089 + fprintf (outfile, ",%d", fill);
3090 + fprintf (outfile, "\n");
3093 +/* .res[.b|.w|.l] <size> */
3096 +do_res (idx, in, type)
3104 + idx = get_opsize (idx, in, &size);
3105 + while (!eol (idx, in))
3107 + idx = sb_skip_white (idx, in);
3108 + if (in->ptr[idx] == ',')
3110 + idx = exp_get_abs (_("res needs absolute expression for fill count.\n"), idx, in, &count);
3112 + if (type == 'c' || type == 'z')
3115 + fprintf (outfile, ".space %d\n", count * size);
3125 + fprintf (outfile, ".global %s\n", sb_name (in));
3128 +/* .print [list] [nolist] */
3135 + idx = sb_skip_white (idx, in);
3136 + while (idx < in->len)
3138 + if (strncasecmp (in->ptr + idx, "LIST", 4) == 0)
3140 + fprintf (outfile, ".list\n");
3143 + else if (strncasecmp (in->ptr + idx, "NOLIST", 6) == 0)
3145 + fprintf (outfile, ".nolist\n");
3155 +do_heading (idx, in)
3161 + idx = getstring (idx, in, &head);
3162 + fprintf (outfile, ".title \"%s\"\n", sb_name (&head));
3171 + fprintf (outfile, ".eject\n");
3174 +/* .form [lin=<value>] [col=<value>] */
3182 + int columns = 132;
3183 + idx = sb_skip_white (idx, in);
3185 + while (idx < in->len)
3188 + if (strncasecmp (in->ptr + idx, "LIN=", 4) == 0)
3191 + idx = exp_get_abs (_("form LIN= needs absolute expresssion.\n"), idx, in, &lines);
3194 + if (strncasecmp (in->ptr + idx, _("COL="), 4) == 0)
3197 + idx = exp_get_abs (_("form COL= needs absolute expresssion.\n"), idx, in, &columns);
3202 + fprintf (outfile, ".psize %d,%d\n", lines, columns);
3206 +/* Fetch string from the input stream,
3208 + 'Bxyx<whitespace> -> return 'Bxyza
3209 + %<char> -> return string of decimal value of x
3210 + "<string>" -> return string
3211 + xyx<whitespace> -> return xyz
3215 +get_any_string (idx, in, out, expand, pretend_quoted)
3220 + int pretend_quoted;
3223 + idx = sb_skip_white (idx, in);
3225 + if (idx < in->len)
3227 + if (in->len > 2 && in->ptr[idx + 1] == '\'' && ISBASE (in->ptr[idx]))
3229 + while (!ISSEP (in->ptr[idx]))
3230 + sb_add_char (out, in->ptr[idx++]);
3232 + else if (in->ptr[idx] == '%'
3238 + /* Turns the next expression into a string. */
3239 + /* xgettext: no-c-format */
3240 + idx = exp_get_abs (_("% operator needs absolute expression"),
3244 + sprintf (buf, "%d", val);
3245 + sb_add_string (out, buf);
3247 + else if (in->ptr[idx] == '"'
3248 + || in->ptr[idx] == '<'
3249 + || (alternate && in->ptr[idx] == '\''))
3251 + if (alternate && expand)
3253 + /* Keep the quotes. */
3254 + sb_add_char (out, '\"');
3256 + idx = getstring (idx, in, out);
3257 + sb_add_char (out, '\"');
3262 + idx = getstring (idx, in, out);
3267 + while (idx < in->len
3268 + && (in->ptr[idx] == '"'
3269 + || in->ptr[idx] == '\''
3271 + || !ISSEP (in->ptr[idx])))
3273 + if (in->ptr[idx] == '"'
3274 + || in->ptr[idx] == '\'')
3276 + char tchar = in->ptr[idx];
3277 + sb_add_char (out, in->ptr[idx++]);
3278 + while (idx < in->len
3279 + && in->ptr[idx] != tchar)
3280 + sb_add_char (out, in->ptr[idx++]);
3281 + if (idx == in->len)
3284 + sb_add_char (out, in->ptr[idx++]);
3292 +/* Skip along sb in starting at idx, suck off whitespace a ( and more
3293 + whitespace. Return the idx of the next char. */
3296 +skip_openp (idx, in)
3300 + idx = sb_skip_white (idx, in);
3301 + if (in->ptr[idx] != '(')
3302 + ERROR ((stderr, _("misplaced ( .\n")));
3303 + idx = sb_skip_white (idx + 1, in);
3307 +/* Skip along sb in starting at idx, suck off whitespace a ) and more
3308 + whitespace. Return the idx of the next char. */
3311 +skip_closep (idx, in)
3315 + idx = sb_skip_white (idx, in);
3316 + if (in->ptr[idx] != ')')
3317 + ERROR ((stderr, _("misplaced ).\n")));
3318 + idx = sb_skip_white (idx + 1, in);
3325 +dolen (idx, in, out)
3334 + sb_new (&stringout);
3335 + idx = skip_openp (idx, in);
3336 + idx = get_and_process (idx, in, &stringout);
3337 + idx = skip_closep (idx, in);
3338 + sprintf (buffer, "%d", stringout.len);
3339 + sb_add_string (out, buffer);
3341 + sb_kill (&stringout);
3348 +doinstr (idx, in, out)
3362 + idx = skip_openp (idx, in);
3363 + idx = get_and_process (idx, in, &string);
3364 + idx = sb_skip_comma (idx, in);
3365 + idx = get_and_process (idx, in, &search);
3366 + idx = sb_skip_comma (idx, in);
3367 + if (ISDIGIT (in->ptr[idx]))
3369 + idx = exp_get_abs (_(".instr needs absolute expresson.\n"), idx, in, &start);
3375 + idx = skip_closep (idx, in);
3377 + for (i = start; i < string.len; i++)
3379 + if (strncmp (string.ptr + i, search.ptr, search.len) == 0)
3385 + sprintf (buffer, "%d", res);
3386 + sb_add_string (out, buffer);
3387 + sb_kill (&string);
3388 + sb_kill (&search);
3393 +dosubstr (idx, in, out)
3403 + idx = skip_openp (idx, in);
3404 + idx = get_and_process (idx, in, &string);
3405 + idx = sb_skip_comma (idx, in);
3406 + idx = exp_get_abs (_("need absolute position.\n"), idx, in, &pos);
3407 + idx = sb_skip_comma (idx, in);
3408 + idx = exp_get_abs (_("need absolute length.\n"), idx, in, &len);
3409 + idx = skip_closep (idx, in);
3411 + if (len < 0 || pos < 0 ||
3413 + || pos + len > string.len)
3415 + sb_add_string (out, " ");
3419 + sb_add_char (out, '"');
3422 + sb_add_char (out, string.ptr[pos++]);
3425 + sb_add_char (out, '"');
3427 + sb_kill (&string);
3431 +/* Scan line, change tokens in the hash table to their replacements. */
3434 +process_assigns (idx, in, buf)
3439 + while (idx < in->len)
3442 + if (in->ptr[idx] == '\\'
3443 + && idx + 1 < in->len
3444 + && in->ptr[idx + 1] == '(')
3448 + sb_add_char (buf, in->ptr[idx]);
3451 + while (idx < in->len && in->ptr[idx - 1] != ')');
3453 + else if (in->ptr[idx] == '\\'
3454 + && idx + 1 < in->len
3455 + && in->ptr[idx + 1] == '&')
3457 + idx = condass_lookup_name (in, idx + 2, buf, 1);
3459 + else if (in->ptr[idx] == '\\'
3460 + && idx + 1 < in->len
3461 + && in->ptr[idx + 1] == '$')
3463 + idx = condass_lookup_name (in, idx + 2, buf, 0);
3465 + else if (idx + 3 < in->len
3466 + && in->ptr[idx] == '.'
3467 + && TOUPPER (in->ptr[idx + 1]) == 'L'
3468 + && TOUPPER (in->ptr[idx + 2]) == 'E'
3469 + && TOUPPER (in->ptr[idx + 3]) == 'N')
3470 + idx = dolen (idx + 4, in, buf);
3471 + else if (idx + 6 < in->len
3472 + && in->ptr[idx] == '.'
3473 + && TOUPPER (in->ptr[idx + 1]) == 'I'
3474 + && TOUPPER (in->ptr[idx + 2]) == 'N'
3475 + && TOUPPER (in->ptr[idx + 3]) == 'S'
3476 + && TOUPPER (in->ptr[idx + 4]) == 'T'
3477 + && TOUPPER (in->ptr[idx + 5]) == 'R')
3478 + idx = doinstr (idx + 6, in, buf);
3479 + else if (idx + 7 < in->len
3480 + && in->ptr[idx] == '.'
3481 + && TOUPPER (in->ptr[idx + 1]) == 'S'
3482 + && TOUPPER (in->ptr[idx + 2]) == 'U'
3483 + && TOUPPER (in->ptr[idx + 3]) == 'B'
3484 + && TOUPPER (in->ptr[idx + 4]) == 'S'
3485 + && TOUPPER (in->ptr[idx + 5]) == 'T'
3486 + && TOUPPER (in->ptr[idx + 6]) == 'R')
3487 + idx = dosubstr (idx + 7, in, buf);
3488 + else if (ISFIRSTCHAR (in->ptr[idx]))
3490 + /* May be a simple name subsitution, see if we have a word. */
3492 + int cur = idx + 1;
3493 + while (cur < in->len
3494 + && (ISNEXTCHAR (in->ptr[cur])))
3498 + sb_add_buffer (&acc, in->ptr + idx, cur - idx);
3499 + ptr = hash_lookup (&assign_hash_table, &acc);
3502 + /* Found a definition for it. */
3503 + sb_add_sb (buf, &ptr->value.s);
3507 + /* No definition, just copy the word. */
3508 + sb_add_sb (buf, &acc);
3515 + sb_add_char (buf, in->ptr[idx++]);
3521 +get_and_process (idx, in, out)
3528 + idx = get_any_string (idx, in, &t, 1, 0);
3529 + process_assigns (0, &t, out);
3547 + sb_new (&label_in);
3549 + more = get_line (&line);
3552 + /* Find any label and pseudo op that we're intested in. */
3554 + if (line.len == 0)
3556 + if (condass_on ())
3557 + fprintf (outfile, "\n");
3560 + && (line.ptr[0] == '*'
3561 + || line.ptr[0] == '!'))
3563 + /* MRI line comment. */
3564 + fprintf (outfile, "%s", sb_name (&line));
3568 + l = grab_label (&line, &label_in);
3569 + sb_reset (&label);
3571 + if (line.ptr[l] == ':')
3573 + while (ISWHITE (line.ptr[l]) && l < line.len)
3580 + /* Munge the label, unless this is EQU or ASSIGN. */
3583 + && (line.ptr[l] == '.' || alternate || mri))
3587 + if (line.ptr[lx] == '.')
3589 + if (lx + 3 <= line.len
3590 + && strncasecmp ("EQU", line.ptr + lx, 3) == 0
3591 + && (lx + 3 == line.len
3592 + || ! ISFIRSTCHAR (line.ptr[lx + 3])))
3594 + else if (lx + 6 <= line.len
3595 + && strncasecmp ("ASSIGN", line.ptr + lx, 6) == 0
3596 + && (lx + 6 == line.len
3597 + || ! ISFIRSTCHAR (line.ptr[lx + 6])))
3602 + process_assigns (0, &label_in, &label);
3604 + sb_add_sb (&label, &label_in);
3609 + if (process_pseudo_op (l, &line, &acc))
3613 + else if (condass_on ())
3615 + if (macro_op (l, &line))
3624 + fprintf (outfile, "%s:\t", sb_name (&label));
3627 + fprintf (outfile, "\t");
3629 + process_assigns (l, &line, &t1);
3631 + change_base (0, &t1, &t2);
3632 + fprintf (outfile, "%s\n", sb_name (&t2));
3639 + /* Only a label on this line. */
3640 + if (label.len && condass_on ())
3642 + fprintf (outfile, "%s:\n", sb_name (&label));
3650 + more = get_line (&line);
3653 + if (!had_end && !mri)
3654 + WARNING ((stderr, _("END missing from end of file.\n")));
3658 +free_old_entry (ptr)
3663 + if (ptr->type == hash_string)
3664 + sb_kill (&ptr->value.s);
3668 +/* name: .ASSIGNA <value> */
3671 +do_assigna (idx, in)
3679 + process_assigns (idx, in, &tmp);
3680 + idx = exp_get_abs (_(".ASSIGNA needs constant expression argument.\n"), 0, &tmp, &val);
3684 + ERROR ((stderr, _(".ASSIGNA without label.\n")));
3688 + hash_entry *ptr = hash_create (&vars, &label);
3689 + free_old_entry (ptr);
3690 + ptr->type = hash_integer;
3691 + ptr->value.i = val;
3696 +/* name: .ASSIGNC <string> */
3699 +do_assignc (idx, in)
3705 + idx = getstring (idx, in, &acc);
3709 + ERROR ((stderr, _(".ASSIGNS without label.\n")));
3713 + hash_entry *ptr = hash_create (&vars, &label);
3714 + free_old_entry (ptr);
3715 + ptr->type = hash_string;
3716 + sb_new (&ptr->value.s);
3717 + sb_add_sb (&ptr->value.s, &acc);
3722 +/* name: .REG (reg) */
3729 + /* Remove reg stuff from inside parens. */
3732 + idx = skip_openp (idx, in);
3734 + idx = sb_skip_white (idx, in);
3736 + while (idx < in->len
3739 + : in->ptr[idx] != ')'))
3741 + sb_add_char (&what, in->ptr[idx]);
3744 + hash_add_to_string_table (&assign_hash_table, &label, &what, 1);
3749 +condass_lookup_name (inbuf, idx, out, warn)
3757 + sb_new (&condass_acc);
3759 + while (idx < inbuf->len
3760 + && ISNEXTCHAR (inbuf->ptr[idx]))
3762 + sb_add_char (&condass_acc, inbuf->ptr[idx++]);
3765 + if (inbuf->ptr[idx] == '\'')
3767 + ptr = hash_lookup (&vars, &condass_acc);
3773 + WARNING ((stderr, _("Can't find preprocessor variable %s.\n"), sb_name (&condass_acc)));
3777 + sb_add_string (out, "0");
3782 + if (ptr->type == hash_integer)
3785 + sprintf (buffer, "%d", ptr->value.i);
3786 + sb_add_string (out, buffer);
3790 + sb_add_sb (out, &ptr->value.s);
3793 + sb_kill (&condass_acc);
3806 +whatcond (idx, in, val)
3813 + idx = sb_skip_white (idx, in);
3815 + if (idx + 1 < in->len)
3820 + p = in->ptr + idx;
3821 + a = TOUPPER (p[0]);
3822 + b = TOUPPER (p[1]);
3823 + if (a == 'E' && b == 'Q')
3825 + else if (a == 'N' && b == 'E')
3827 + else if (a == 'L' && b == 'T')
3829 + else if (a == 'L' && b == 'E')
3831 + else if (a == 'G' && b == 'T')
3833 + else if (a == 'G' && b == 'E')
3836 + if (cond == NEVER)
3838 + ERROR ((stderr, _("Comparison operator must be one of EQ, NE, LT, LE, GT or GE.\n")));
3841 + idx = sb_skip_white (idx + 2, in);
3858 + idx = sb_skip_white (idx, in);
3860 + if (in->ptr[idx] == '"')
3864 + /* This is a string comparision. */
3865 + idx = getstring (idx, in, &acc_a);
3866 + idx = whatcond (idx, in, &cond);
3867 + idx = getstring (idx, in, &acc_b);
3868 + same = acc_a.len == acc_b.len
3869 + && (strncmp (acc_a.ptr, acc_b.ptr, acc_a.len) == 0);
3871 + if (cond != EQ && cond != NE)
3873 + ERROR ((stderr, _("Comparison operator for strings must be EQ or NE\n")));
3877 + res = (cond != EQ) ^ same;
3880 + /* This is a numeric expression. */
3885 + idx = exp_get_abs (_("Conditional operator must have absolute operands.\n"), idx, in, &vala);
3886 + idx = whatcond (idx, in, &cond);
3887 + idx = sb_skip_white (idx, in);
3888 + if (in->ptr[idx] == '"')
3890 + WARNING ((stderr, _("String compared against expression.\n")));
3895 + idx = exp_get_abs (_("Conditional operator must have absolute operands.\n"), idx, in, &valb);
3902 + res = vala == valb;
3905 + res = vala != valb;
3908 + res = vala < valb;
3911 + res = vala <= valb;
3914 + res = vala > valb;
3917 + res = vala >= valb;
3939 + if (ifi >= IFNESTING)
3941 + FATAL ((stderr, _("AIF nesting unreasonable.\n")));
3944 + ifstack[ifi].on = ifstack[ifi - 1].on ? istrue (idx, in) : 0;
3945 + ifstack[ifi].hadelse = 0;
3953 + ifstack[ifi].on = ifstack[ifi - 1].on ? !ifstack[ifi].on : 0;
3954 + if (ifstack[ifi].hadelse)
3956 + ERROR ((stderr, _("Multiple AELSEs in AIF.\n")));
3958 + ifstack[ifi].hadelse = 1;
3972 + ERROR ((stderr, _("AENDI without AIF.\n")));
3979 + return ifstack[ifi].on;
3982 +/* MRI IFEQ, IFNE, IFLT, IFLE, IFGE, IFGT. */
3985 +do_if (idx, in, cond)
3993 + if (ifi >= IFNESTING)
3995 + FATAL ((stderr, _("IF nesting unreasonable.\n")));
3998 + idx = exp_get_abs (_("Conditional operator must have absolute operands.\n"),
4003 + case EQ: res = val == 0; break;
4004 + case NE: res = val != 0; break;
4005 + case LT: res = val < 0; break;
4006 + case LE: res = val <= 0; break;
4007 + case GE: res = val >= 0; break;
4008 + case GT: res = val > 0; break;
4012 + ifstack[ifi].on = ifstack[ifi - 1].on ? res : 0;
4013 + ifstack[ifi].hadelse = 0;
4016 +/* Get a string for the MRI IFC or IFNC pseudo-ops. */
4019 +get_mri_string (idx, in, val, terminator)
4025 + idx = sb_skip_white (idx, in);
4028 + && in->ptr[idx] == '\'')
4030 + sb_add_char (val, '\'');
4031 + for (++idx; idx < in->len; ++idx)
4033 + sb_add_char (val, in->ptr[idx]);
4034 + if (in->ptr[idx] == '\'')
4037 + if (idx >= in->len
4038 + || in->ptr[idx] != '\'')
4042 + idx = sb_skip_white (idx, in);
4048 + while (idx < in->len
4049 + && in->ptr[idx] != terminator)
4051 + sb_add_char (val, in->ptr[idx]);
4055 + while (i >= 0 && ISWHITE (val->ptr[i]))
4063 +/* MRI IFC, IFNC */
4066 +do_ifc (idx, in, ifnc)
4075 + if (ifi >= IFNESTING)
4077 + FATAL ((stderr, _("IF nesting unreasonable.\n")));
4083 + idx = get_mri_string (idx, in, &first, ',');
4085 + if (idx >= in->len || in->ptr[idx] != ',')
4087 + ERROR ((stderr, _("Bad format for IF or IFNC.\n")));
4091 + idx = get_mri_string (idx + 1, in, &second, ';');
4093 + res = (first.len == second.len
4094 + && strncmp (first.ptr, second.ptr, first.len) == 0);
4098 + ifstack[ifi].on = ifstack[ifi - 1].on ? res : 0;
4099 + ifstack[ifi].hadelse = 0;
4108 + ERROR ((stderr, _("AENDR without a AREPEAT.\n")));
4110 + ERROR ((stderr, _("ENDR without a REPT.\n")));
4116 +do_awhile (idx, in)
4120 + int line = linecount ();
4128 + process_assigns (idx, in, &exp);
4129 + doit = istrue (0, &exp);
4131 + if (! buffer_and_nest ("AWHILE", "AENDW", &sub, get_line))
4132 + FATAL ((stderr, _("AWHILE without a AENDW at %d.\n"), line - 1));
4147 + int index = include_next_index ();
4151 + sb_add_sb (©, &sub);
4152 + sb_add_sb (©, in);
4153 + sb_add_string (©, "\n");
4154 + sb_add_sb (©, &sub);
4155 + sb_add_string (©, "\t.AENDW\n");
4156 + /* Push another WHILE. */
4157 + include_buf (&exp, ©, include_while, index);
4169 + ERROR ((stderr, _("AENDW without a AENDW.\n")));
4174 + Pop things off the include stack until the type and index changes. */
4179 + include_type type = sp->type;
4180 + if (type == include_repeat
4181 + || type == include_while
4182 + || type == include_macro)
4184 + int index = sp->index;
4186 + while (sp->index == index
4187 + && sp->type == type)
4197 +do_arepeat (idx, in)
4201 + int line = linecount ();
4202 + sb exp; /* Buffer with expression in it. */
4203 + sb copy; /* Expanded repeat block. */
4204 + sb sub; /* Contents of AREPEAT. */
4212 + process_assigns (idx, in, &exp);
4213 + idx = exp_get_abs (_("AREPEAT must have absolute operand.\n"), 0, &exp, &rc);
4215 + ret = buffer_and_nest ("AREPEAT", "AENDR", &sub, get_line);
4217 + ret = buffer_and_nest ("REPT", "ENDR", &sub, get_line);
4219 + FATAL ((stderr, _("AREPEAT without a AENDR at %d.\n"), line - 1));
4222 + /* Push back the text following the repeat, and another repeat block
4233 + int index = include_next_index ();
4234 + sb_add_sb (©, &sub);
4238 + sprintf (buffer, "\t.AREPEAT %d\n", rc - 1);
4240 + sprintf (buffer, "\tREPT %d\n", rc - 1);
4241 + sb_add_string (©, buffer);
4242 + sb_add_sb (©, &sub);
4244 + sb_add_string (©, " .AENDR\n");
4246 + sb_add_string (©, " ENDR\n");
4249 + include_buf (&exp, ©, include_repeat, index);
4261 + ERROR ((stderr, _(".ENDM without a matching .MACRO.\n")));
4264 +/* MRI IRP pseudo-op. */
4267 +do_irp (idx, in, irpc)
4277 + err = expand_irp (irpc, idx, in, &out, get_line, comment_char);
4279 + ERROR ((stderr, "%s\n", err));
4281 + fprintf (outfile, "%s", sb_terminate (&out));
4286 +/* Macro processing. */
4288 +/* Parse off LOCAL n1, n2,... Invent a label name for it. */
4291 +do_local (idx, line)
4292 + int idx ATTRIBUTE_UNUSED;
4293 + sb *line ATTRIBUTE_UNUSED;
4295 + ERROR ((stderr, _("LOCAL outside of MACRO")));
4304 + int line = linecount ();
4306 + err = define_macro (idx, in, &label, get_line, (const char **) NULL);
4308 + ERROR ((stderr, _("macro at line %d: %s\n"), line - 1, err));
4320 + if (! macro_defined)
4323 + sb_terminate (in);
4324 + if (! check_macro (in->ptr + idx, &out, comment_char, &err, NULL))
4328 + ERROR ((stderr, "%s\n", err));
4331 + sb_add_string (&name, _("macro expansion"));
4333 + include_buf (&name, &out, include_macro, include_next_index ());
4341 +/* String handling. */
4344 +getstring (idx, in, acc)
4349 + idx = sb_skip_white (idx, in);
4351 + while (idx < in->len
4352 + && (in->ptr[idx] == '"'
4353 + || in->ptr[idx] == '<'
4354 + || (in->ptr[idx] == '\'' && alternate)))
4356 + if (in->ptr[idx] == '<')
4358 + if (alternate || mri)
4362 + while ((in->ptr[idx] != '>' || nest)
4365 + if (in->ptr[idx] == '!')
4368 + sb_add_char (acc, in->ptr[idx++]);
4372 + if (in->ptr[idx] == '>')
4374 + if (in->ptr[idx] == '<')
4376 + sb_add_char (acc, in->ptr[idx++]);
4385 + idx = exp_get_abs (_("Character code in string must be absolute expression.\n"),
4387 + sb_add_char (acc, code);
4389 + if (in->ptr[idx] != '>')
4390 + ERROR ((stderr, _("Missing > for character code.\n")));
4394 + else if (in->ptr[idx] == '"' || in->ptr[idx] == '\'')
4396 + char tchar = in->ptr[idx];
4398 + while (idx < in->len)
4400 + if (alternate && in->ptr[idx] == '!')
4403 + sb_add_char (acc, in->ptr[idx++]);
4407 + if (in->ptr[idx] == tchar)
4410 + if (idx >= in->len || in->ptr[idx] != tchar)
4413 + sb_add_char (acc, in->ptr[idx]);
4423 +/* .SDATA[C|Z] <string> */
4426 +do_sdata (idx, in, type)
4435 + fprintf (outfile, ".byte\t");
4437 + while (!eol (idx, in))
4441 + idx = sb_skip_white (idx, in);
4442 + while (!eol (idx, in))
4444 + pidx = idx = get_any_string (idx, in, &acc, 0, 1);
4447 + if (acc.len > 255)
4449 + ERROR ((stderr, _("string for SDATAC longer than 255 characters (%d).\n"), acc.len));
4451 + fprintf (outfile, "%d", acc.len);
4455 + for (i = 0; i < acc.len; i++)
4459 + fprintf (outfile, ",");
4461 + fprintf (outfile, "%d", acc.ptr[i]);
4468 + fprintf (outfile, ",");
4469 + fprintf (outfile, "0");
4471 + idx = sb_skip_comma (idx, in);
4475 + if (!alternate && in->ptr[idx] != ',' && idx != in->len)
4477 + fprintf (outfile, "\n");
4478 + ERROR ((stderr, _("illegal character in SDATA line (0x%x).\n"),
4485 + fprintf (outfile, "\n");
4488 +/* .SDATAB <count> <string> */
4491 +do_sdatab (idx, in)
4500 + idx = exp_get_abs (_("Must have absolute SDATAB repeat count.\n"), idx, in, &repeat);
4503 + ERROR ((stderr, _("Must have positive SDATAB repeat count (%d).\n"), repeat));
4507 + idx = sb_skip_comma (idx, in);
4508 + idx = getstring (idx, in, &acc);
4510 + for (i = 0; i < repeat; i++)
4513 + fprintf (outfile, "\t");
4514 + fprintf (outfile, ".byte\t");
4515 + sb_print (outfile, &acc);
4516 + fprintf (outfile, "\n");
4526 + FILE *newone = fopen (name, "r");
4530 + if (isp == MAX_INCLUDES)
4531 + FATAL ((stderr, _("Unreasonable include depth (%ld).\n"), (long) isp));
4534 + sp->handle = newone;
4536 + sb_new (&sp->name);
4537 + sb_add_string (&sp->name, name);
4539 + sp->linecount = 1;
4540 + sp->pushback_index = 0;
4541 + sp->type = include_file;
4543 + sb_new (&sp->pushback);
4548 +do_include (idx, in)
4554 + include_path *includes;
4560 + idx = getstring (idx, in, &t);
4563 + idx = sb_skip_white (idx, in);
4564 + while (idx < in->len && ! ISWHITE (in->ptr[idx]))
4566 + sb_add_char (&t, in->ptr[idx]);
4571 + for (includes = paths_head; includes; includes = includes->next)
4574 + sb_add_sb (&cat, &includes->path);
4575 + sb_add_char (&cat, '/');
4576 + sb_add_sb (&cat, &t);
4577 + if (new_file (sb_name (&cat)))
4584 + if (! new_file (sb_name (&t)))
4585 + FATAL ((stderr, _("Can't open include file `%s'.\n"), sb_name (&t)));
4594 + if (sp != include_stack)
4597 + fclose (sp->handle);
4602 +/* Get the next character from the include stack. If there's anything
4603 + in the pushback buffer, take that first. If we're at eof, pop from
4604 + the stack and try again. Keep the linecount up to date. */
4611 + if (sp->pushback.len != sp->pushback_index)
4613 + r = (char) (sp->pushback.ptr[sp->pushback_index++]);
4614 + /* When they've all gone, reset the pointer. */
4615 + if (sp->pushback_index == sp->pushback.len)
4617 + sp->pushback.len = 0;
4618 + sp->pushback_index = 0;
4621 + else if (sp->handle)
4623 + r = getc (sp->handle);
4628 + if (r == EOF && isp)
4632 + while (r == EOF && isp)
4650 + return sp->linecount;
4654 +include_next_index ()
4658 + && index > MAX_REASONABLE)
4659 + FATAL ((stderr, _("Unreasonable expansion (-u turns off check).\n")));
4663 +/* Initialize the chartype vector. */
4669 + for (x = 0; x < 256; x++)
4671 + if (ISALPHA (x) || x == '_' || x == '$')
4672 + chartype[x] |= FIRSTBIT;
4674 + if (mri && x == '.')
4675 + chartype[x] |= FIRSTBIT;
4677 + if (ISDIGIT (x) || ISALPHA (x) || x == '_' || x == '$')
4678 + chartype[x] |= NEXTBIT;
4680 + if (x == ' ' || x == '\t' || x == ',' || x == '"' || x == ';'
4681 + || x == '"' || x == '<' || x == '>' || x == ')' || x == '(')
4682 + chartype[x] |= SEPBIT;
4684 + if (x == 'b' || x == 'B'
4685 + || x == 'q' || x == 'Q'
4686 + || x == 'h' || x == 'H'
4687 + || x == 'd' || x == 'D')
4688 + chartype [x] |= BASEBIT;
4690 + if (x == ' ' || x == '\t')
4691 + chartype[x] |= WHITEBIT;
4693 + if (x == comment_char)
4694 + chartype[x] |= COMMENTBIT;
4698 +/* What to do with all the keywords. */
4699 +#define PROCESS 0x1000 /* Run substitution over the line. */
4700 +#define LAB 0x2000 /* Spit out the label. */
4702 +#define K_EQU (PROCESS|1)
4703 +#define K_ASSIGN (PROCESS|2)
4704 +#define K_REG (PROCESS|3)
4705 +#define K_ORG (PROCESS|4)
4706 +#define K_RADIX (PROCESS|5)
4707 +#define K_DATA (LAB|PROCESS|6)
4708 +#define K_DATAB (LAB|PROCESS|7)
4709 +#define K_SDATA (LAB|PROCESS|8)
4710 +#define K_SDATAB (LAB|PROCESS|9)
4711 +#define K_SDATAC (LAB|PROCESS|10)
4712 +#define K_SDATAZ (LAB|PROCESS|11)
4713 +#define K_RES (LAB|PROCESS|12)
4714 +#define K_SRES (LAB|PROCESS|13)
4715 +#define K_SRESC (LAB|PROCESS|14)
4716 +#define K_SRESZ (LAB|PROCESS|15)
4717 +#define K_EXPORT (LAB|PROCESS|16)
4718 +#define K_GLOBAL (LAB|PROCESS|17)
4719 +#define K_PRINT (LAB|PROCESS|19)
4720 +#define K_FORM (LAB|PROCESS|20)
4721 +#define K_HEADING (LAB|PROCESS|21)
4722 +#define K_PAGE (LAB|PROCESS|22)
4723 +#define K_IMPORT (LAB|PROCESS|23)
4724 +#define K_PROGRAM (LAB|PROCESS|24)
4725 +#define K_END (PROCESS|25)
4726 +#define K_INCLUDE (PROCESS|26)
4727 +#define K_IGNORED (PROCESS|27)
4728 +#define K_ASSIGNA (PROCESS|28)
4729 +#define K_ASSIGNC (29)
4730 +#define K_AIF (PROCESS|30)
4731 +#define K_AELSE (PROCESS|31)
4732 +#define K_AENDI (PROCESS|32)
4733 +#define K_AREPEAT (PROCESS|33)
4734 +#define K_AENDR (PROCESS|34)
4735 +#define K_AWHILE (35)
4736 +#define K_AENDW (PROCESS|36)
4737 +#define K_EXITM (37)
4738 +#define K_MACRO (PROCESS|38)
4739 +#define K_ENDM (39)
4740 +#define K_ALIGN (PROCESS|LAB|40)
4741 +#define K_ALTERNATE (41)
4742 +#define K_DB (LAB|PROCESS|42)
4743 +#define K_DW (LAB|PROCESS|43)
4744 +#define K_DL (LAB|PROCESS|44)
4745 +#define K_LOCAL (45)
4746 +#define K_IFEQ (PROCESS|46)
4747 +#define K_IFNE (PROCESS|47)
4748 +#define K_IFLT (PROCESS|48)
4749 +#define K_IFLE (PROCESS|49)
4750 +#define K_IFGE (PROCESS|50)
4751 +#define K_IFGT (PROCESS|51)
4752 +#define K_IFC (PROCESS|52)
4753 +#define K_IFNC (PROCESS|53)
4754 +#define K_IRP (PROCESS|54)
4755 +#define K_IRPC (PROCESS|55)
4763 +static struct keyword kinfo[] = {
4764 + { "EQU", K_EQU, 0 },
4765 + { "ALTERNATE", K_ALTERNATE, 0 },
4766 + { "ASSIGN", K_ASSIGN, 0 },
4767 + { "REG", K_REG, 0 },
4768 + { "ORG", K_ORG, 0 },
4769 + { "RADIX", K_RADIX, 0 },
4770 + { "DATA", K_DATA, 0 },
4771 + { "DB", K_DB, 0 },
4772 + { "DW", K_DW, 0 },
4773 + { "DL", K_DL, 0 },
4774 + { "DATAB", K_DATAB, 0 },
4775 + { "SDATA", K_SDATA, 0 },
4776 + { "SDATAB", K_SDATAB, 0 },
4777 + { "SDATAZ", K_SDATAZ, 0 },
4778 + { "SDATAC", K_SDATAC, 0 },
4779 + { "RES", K_RES, 0 },
4780 + { "SRES", K_SRES, 0 },
4781 + { "SRESC", K_SRESC, 0 },
4782 + { "SRESZ", K_SRESZ, 0 },
4783 + { "EXPORT", K_EXPORT, 0 },
4784 + { "GLOBAL", K_GLOBAL, 0 },
4785 + { "PRINT", K_PRINT, 0 },
4786 + { "FORM", K_FORM, 0 },
4787 + { "HEADING", K_HEADING, 0 },
4788 + { "PAGE", K_PAGE, 0 },
4789 + { "PROGRAM", K_IGNORED, 0 },
4790 + { "END", K_END, 0 },
4791 + { "INCLUDE", K_INCLUDE, 0 },
4792 + { "ASSIGNA", K_ASSIGNA, 0 },
4793 + { "ASSIGNC", K_ASSIGNC, 0 },
4794 + { "AIF", K_AIF, 0 },
4795 + { "AELSE", K_AELSE, 0 },
4796 + { "AENDI", K_AENDI, 0 },
4797 + { "AREPEAT", K_AREPEAT, 0 },
4798 + { "AENDR", K_AENDR, 0 },
4799 + { "EXITM", K_EXITM, 0 },
4800 + { "MACRO", K_MACRO, 0 },
4801 + { "ENDM", K_ENDM, 0 },
4802 + { "AWHILE", K_AWHILE, 0 },
4803 + { "ALIGN", K_ALIGN, 0 },
4804 + { "AENDW", K_AENDW, 0 },
4805 + { "ALTERNATE", K_ALTERNATE, 0 },
4806 + { "LOCAL", K_LOCAL, 0 },
4810 +/* Although the conditional operators are handled by gas, we need to
4811 + handle them here as well, in case they are used in a recursive
4812 + macro to end the recursion. */
4814 +static struct keyword mrikinfo[] = {
4815 + { "IFEQ", K_IFEQ, 0 },
4816 + { "IFNE", K_IFNE, 0 },
4817 + { "IFLT", K_IFLT, 0 },
4818 + { "IFLE", K_IFLE, 0 },
4819 + { "IFGE", K_IFGE, 0 },
4820 + { "IFGT", K_IFGT, 0 },
4821 + { "IFC", K_IFC, 0 },
4822 + { "IFNC", K_IFNC, 0 },
4823 + { "ELSEC", K_AELSE, 0 },
4824 + { "ENDC", K_AENDI, 0 },
4825 + { "MEXIT", K_EXITM, 0 },
4826 + { "REPT", K_AREPEAT, 0 },
4827 + { "IRP", K_IRP, 0 },
4828 + { "IRPC", K_IRPC, 0 },
4829 + { "ENDR", K_AENDR, 0 },
4833 +/* Look for a pseudo op on the line. If one's there then call
4837 +process_pseudo_op (idx, line, acc)
4844 + if (line->ptr[idx] == '.' || alternate || mri)
4846 + /* Scan forward and find pseudo name. */
4852 + if (line->ptr[idx] == '.')
4854 + in = line->ptr + idx;
4859 + while (idx < line->len && *e && ISFIRSTCHAR (*e))
4861 + sb_add_char (acc, *e);
4866 + ptr = hash_lookup (&keyword_hash_table, acc);
4871 + /* This one causes lots of pain when trying to preprocess
4873 + WARNING ((stderr, _("Unrecognised pseudo op `%s'.\n"),
4878 + if (ptr->value.i & LAB)
4880 + /* Output the label. */
4883 + fprintf (outfile, "%s:\t", sb_name (&label));
4886 + fprintf (outfile, "\t");
4889 + if (mri && ptr->value.i == K_END)
4894 + sb_add_buffer (&t, line->ptr + oidx, idx - oidx);
4895 + fprintf (outfile, "\t%s", sb_name (&t));
4899 + if (ptr->value.i & PROCESS)
4901 + /* Polish the rest of the line before handling the pseudo op. */
4903 + strip_comments (line);
4906 + process_assigns (idx, line, acc);
4908 + change_base (0, acc, line);
4911 + if (!condass_on ())
4913 + switch (ptr->value.i)
4916 + do_aif (idx, line);
4929 + switch (ptr->value.i)
4933 + macro_init (1, mri, 0, exp_get_abs);
4942 + ERROR ((stderr, _("ORG command not allowed.\n")));
4948 + do_data (idx, line, 1);
4951 + do_data (idx, line, 2);
4954 + do_data (idx, line, 4);
4957 + do_data (idx, line, 0);
4960 + do_datab (idx, line);
4963 + do_sdata (idx, line, 0);
4966 + do_sdatab (idx, line);
4969 + do_sdata (idx, line, 'c');
4972 + do_sdata (idx, line, 'z');
4975 + do_assign (0, 0, line);
4978 + do_aif (idx, line);
4981 + do_arepeat (idx, line);
4987 + do_awhile (idx, line);
4993 + do_assign (1, idx, line);
4996 + do_align (idx, line);
4999 + do_res (idx, line, 0);
5002 + do_res (idx, line, 's');
5005 + do_include (idx, line);
5008 + do_local (idx, line);
5011 + do_macro (idx, line);
5017 + do_res (idx, line, 'c');
5020 + do_print (idx, line);
5023 + do_form (idx, line);
5026 + do_heading (idx, line);
5038 + do_res (idx, line, 'z');
5046 + do_assigna (idx, line);
5049 + do_assignc (idx, line);
5055 + do_reg (idx, line);
5058 + do_if (idx, line, EQ);
5061 + do_if (idx, line, NE);
5064 + do_if (idx, line, LT);
5067 + do_if (idx, line, LE);
5070 + do_if (idx, line, GE);
5073 + do_if (idx, line, GT);
5076 + do_ifc (idx, line, 0);
5079 + do_ifc (idx, line, 1);
5082 + do_irp (idx, line, 0);
5085 + do_irp (idx, line, 1);
5093 +/* Add a keyword to the hash table. */
5096 +add_keyword (name, code)
5104 + sb_add_string (&label, name);
5106 + hash_add_to_int_table (&keyword_hash_table, &label, code);
5108 + sb_reset (&label);
5109 + for (j = 0; name[j]; j++)
5110 + sb_add_char (&label, name[j] - 'A' + 'a');
5111 + hash_add_to_int_table (&keyword_hash_table, &label, code);
5116 +/* Build the keyword hash table - put each keyword in the table twice,
5117 + once upper and once lower case. */
5124 + for (i = 0; kinfo[i].name; i++)
5125 + add_keyword (kinfo[i].name, kinfo[i].code);
5129 + for (i = 0; mrikinfo[i].name; i++)
5130 + add_keyword (mrikinfo[i].name, mrikinfo[i].code);
5136 + const char *string;
5145 + if (*string == '=')
5152 + sb_add_char (&value, *string);
5155 + exp_get_abs (_("Invalid expression on command line.\n"),
5160 + sb_add_char (&label, *string);
5165 + ptr = hash_create (&vars, &label);
5166 + free_old_entry (ptr);
5167 + ptr->type = hash_integer;
5168 + ptr->value.i = res;
5172 +char *program_name;
5174 +/* The list of long options. */
5175 +static struct option long_options[] =
5177 + { "alternate", no_argument, 0, 'a' },
5178 + { "include", required_argument, 0, 'I' },
5179 + { "commentchar", required_argument, 0, 'c' },
5180 + { "copysource", no_argument, 0, 's' },
5181 + { "debug", no_argument, 0, 'd' },
5182 + { "help", no_argument, 0, 'h' },
5183 + { "mri", no_argument, 0, 'M' },
5184 + { "output", required_argument, 0, 'o' },
5185 + { "print", no_argument, 0, 'p' },
5186 + { "unreasonable", no_argument, 0, 'u' },
5187 + { "version", no_argument, 0, 'v' },
5188 + { "define", required_argument, 0, 'd' },
5189 + { NULL, no_argument, 0, 0 }
5192 +/* Show a usage message and exit. */
5194 +show_usage (file, status)
5198 + fprintf (file, _("\
5200 + [-a] [--alternate] enter alternate macro mode\n\
5201 + [-c char] [--commentchar char] change the comment character from !\n\
5202 + [-d] [--debug] print some debugging info\n\
5203 + [-h] [--help] print this message\n\
5204 + [-M] [--mri] enter MRI compatibility mode\n\
5205 + [-o out] [--output out] set the output file\n\
5206 + [-p] [--print] print line numbers\n"), program_name);
5207 + fprintf (file, _("\
5208 + [-s] [--copysource] copy source through as comments \n\
5209 + [-u] [--unreasonable] allow unreasonable nesting\n\
5210 + [-v] [--version] print the program version\n\
5211 + [-Dname=value] create preprocessor variable called name, with value\n\
5212 + [-Ipath] add to include path list\n\
5215 + printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
5219 +/* Display a help message and exit. */
5224 + printf (_("%s: Gnu Assembler Macro Preprocessor\n"), program_name);
5225 + show_usage (stdout, 0);
5228 +int main PARAMS ((int, char **));
5236 + char *out_name = 0;
5237 + sp = include_stack;
5239 + ifstack[0].on = 1;
5242 +#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
5243 + setlocale (LC_MESSAGES, "");
5245 +#if defined (HAVE_SETLOCALE)
5246 + setlocale (LC_CTYPE, "");
5248 + bindtextdomain (PACKAGE, LOCALEDIR);
5249 + textdomain (PACKAGE);
5251 + program_name = argv[0];
5252 + xmalloc_set_program_name (program_name);
5254 + hash_new_table (101, &keyword_hash_table);
5255 + hash_new_table (101, &assign_hash_table);
5256 + hash_new_table (101, &vars);
5260 + while ((opt = getopt_long (argc, argv, "I:sdhavc:upo:D:M", long_options,
5267 + out_name = optarg;
5274 + include_path *p = (include_path *) xmalloc (sizeof (include_path));
5276 + sb_new (&p->path);
5277 + sb_add_string (&p->path, optarg);
5279 + paths_tail->next = p;
5286 + print_line_number = 1;
5289 + comment_char = optarg[0];
5301 + do_define (optarg);
5305 + comment_char = ';';
5311 + /* This output is intended to follow the GNU standards document. */
5312 + printf (_("GNU assembler pre-processor %s\n"), program_version);
5313 + printf (_("Copyright 1996 Free Software Foundation, Inc.\n"));
5315 +This program is free software; you may redistribute it under the terms of\n\
5316 +the GNU General Public License. This program has absolutely no warranty.\n"));
5322 + show_usage (stderr, 1);
5329 + macro_init (alternate, mri, 0, exp_get_abs);
5333 + outfile = fopen (out_name, "w");
5336 + fprintf (stderr, _("%s: Can't open output file `%s'.\n"),
5337 + program_name, out_name);
5350 + /* Process all the input files. */
5352 + while (optind < argc)
5354 + if (new_file (argv[optind]))
5360 + fprintf (stderr, _("%s: Can't open input file `%s'.\n"),
5361 + program_name, argv[optind]);
5371 +/* This function is used because an abort in some of the other files
5372 + may be compiled into as_abort because they include as.h. */
5375 +as_abort (file, line, fn)
5376 + const char *file, *fn;
5379 + fprintf (stderr, _("Internal error, aborting at %s line %d"), file, line);
5381 + fprintf (stderr, " in %s", fn);
5382 + fprintf (stderr, _("\nPlease report this bug.\n"));
5385 --- binutils-2.14.90.0.8/gas/macro.c.orig Wed Jan 14 22:07:45 2004
5386 +++ binutils-2.14.90.0.8/gas/macro.c Thu Jan 15 10:46:06 2004
5388 static int get_apost_token (int, sb *, sb *, int);
5389 static int sub_actual (int, sb *, sb *, struct hash_control *, int, sb *, int);
5390 static const char *macro_expand_body
5391 - (sb *, sb *, formal_entry *, struct hash_control *, int);
5392 -static const char *macro_expand (int, sb *, macro_entry *, sb *);
5393 + (sb *, sb *, formal_entry *, struct hash_control *, int, int);
5394 +static const char *macro_expand (int, sb *, macro_entry *, sb *, int);
5396 #define ISWHITE(x) ((x) == ' ' || (x) == '\t')
5401 macro_expand_body (sb *in, sb *out, formal_entry *formals,
5402 - struct hash_control *formal_hash, int locals)
5403 + struct hash_control *formal_hash, int comment_char, int locals)
5407 @@ -649,7 +649,14 @@
5408 else if (in->ptr[src] == '\\')
5411 - if (in->ptr[src] == '(')
5412 + if (in->ptr[src] == comment_char && comment_char != '\0')
5414 + /* This is a comment, just drop the rest of the line. */
5415 + while (src < in->len
5416 + && in->ptr[src] != '\n')
5419 + else if (in->ptr[src] == '(')
5421 /* Sub in till the next ')' literally. */
5426 src = sb_skip_white (src + 5, in);
5427 - while (in->ptr[src] != '\n')
5428 + while (in->ptr[src] != '\n' && in->ptr[src] != comment_char)
5432 @@ -759,6 +766,17 @@
5436 + else if (comment_char != '\0'
5437 + && in->ptr[src] == comment_char
5438 + && src + 1 < in->len
5439 + && in->ptr[src + 1] == comment_char
5442 + /* Two comment chars in a row cause the rest of the line to
5444 + while (src < in->len && in->ptr[src] != '\n')
5447 else if (in->ptr[src] == '"'
5448 || (macro_mri && in->ptr[src] == '\''))
5454 -macro_expand (int idx, sb *in, macro_entry *m, sb *out)
5455 +macro_expand (int idx, sb *in, macro_entry *m, sb *out, int comment_char)
5461 /* Peel off the actuals and store them away in the hash tables' actuals. */
5462 idx = sb_skip_white (idx, in);
5463 - while (idx < in->len)
5464 + while (idx < in->len && in->ptr[idx] != comment_char)
5468 @@ -993,7 +1011,7 @@
5469 sb_add_string (&ptr->actual, buffer);
5472 - err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, 1);
5473 + err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, comment_char, 1);
5477 @@ -1029,7 +1047,7 @@
5478 *EXPAND. Return 1 if a macro is found, 0 otherwise. */
5481 -check_macro (const char *line, sb *expand,
5482 +check_macro (const char *line, sb *expand, int comment_char,
5483 const char **error, macro_entry **info)
5486 @@ -1066,7 +1084,7 @@
5487 sb_add_char (&line_sb, *s++);
5490 - *error = macro_expand (0, &line_sb, macro, expand);
5491 + *error = macro_expand (0, &line_sb, macro, expand, comment_char);
5495 @@ -1090,7 +1108,7 @@
5496 success, or an error message otherwise. */
5499 -expand_irp (int irpc, int idx, sb *in, sb *out, int (*get_line) (sb *))
5500 +expand_irp (int irpc, int idx, sb *in, sb *out, int (*get_line) (sb *), int comment_char)
5504 @@ -1128,10 +1146,10 @@
5507 idx = sb_skip_comma (idx, in);
5508 - if (idx >= in->len)
5509 + if (idx >= in->len || in->ptr[idx] == comment_char)
5511 /* Expand once with a null string. */
5512 - err = macro_expand_body (&sub, out, &f, h, 0);
5513 + err = macro_expand_body (&sub, out, &f, h, comment_char, 0);
5517 @@ -1139,7 +1157,7 @@
5519 if (irpc && in->ptr[idx] == '"')
5521 - while (idx < in->len)
5522 + while (idx < in->len && in->ptr[idx] != comment_char)
5525 idx = get_any_string (idx, in, &f.actual, 1, 0);
5526 @@ -1150,7 +1168,7 @@
5529 nxt = sb_skip_white (idx + 1, in);
5530 - if (nxt >= in->len)
5531 + if (nxt >= in->len || in->ptr[nxt] == comment_char)
5535 @@ -1160,7 +1178,7 @@
5536 sb_add_char (&f.actual, in->ptr[idx]);
5539 - err = macro_expand_body (&sub, out, &f, h, 0);
5540 + err = macro_expand_body (&sub, out, &f, h, comment_char, 0);
5544 --- binutils-2.14.90.0.8/gas/macro.h.orig Wed Jan 14 22:07:45 2004
5545 +++ binutils-2.14.90.0.8/gas/macro.h Thu Jan 15 10:43:32 2004
5547 extern void macro_mri_mode (int);
5548 extern const char *define_macro
5549 (int, sb *, sb *, int (*) (sb *), const char **);
5550 -extern int check_macro (const char *, sb *, const char **, macro_entry **);
5551 +extern int check_macro (const char *, sb *, int, const char **, macro_entry **);
5552 extern void delete_macro (const char *);
5553 -extern const char *expand_irp (int, int, sb *, sb *, int (*) (sb *));
5554 +extern const char *expand_irp (int, int, sb *, sb *, int (*) (sb *), int);
5557 diff -Nur binutils-2.13.90.0.18.orig/gas/read.c binutils-2.13.90.0.18/gas/read.c
5558 --- binutils-2.13.90.0.18.orig/gas/read.c Sun Feb 2 03:21:18 2003
5559 +++ binutils-2.13.90.0.18/gas/read.c Sun Feb 2 15:26:06 2003
5564 - if (check_macro (s, &out, &err, ¯o))
5565 + if (check_macro (s, &out, '\0', &err, ¯o))
5569 @@ -1855,7 +1855,7 @@
5573 - err = expand_irp (irpc, 0, &s, &out, get_line_sb);
5574 + err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
5576 as_bad_where (file, line, "%s", err);