Back to home page

OSCL-LXR

 
 

    


0001 %{
0002 /*
0003  * Sub-parser for macro invocation in the Aic7xxx SCSI
0004  * Host adapter sequencer assembler.
0005  *
0006  * Copyright (c) 2001 Adaptec Inc.
0007  * All rights reserved.
0008  *
0009  * Redistribution and use in source and binary forms, with or without
0010  * modification, are permitted provided that the following conditions
0011  * are met:
0012  * 1. Redistributions of source code must retain the above copyright
0013  *    notice, this list of conditions, and the following disclaimer,
0014  *    without modification.
0015  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
0016  *    substantially similar to the "NO WARRANTY" disclaimer below
0017  *    ("Disclaimer") and any redistribution must be conditioned upon
0018  *    including a substantially similar Disclaimer requirement for further
0019  *    binary redistribution.
0020  * 3. Neither the names of the above-listed copyright holders nor the names
0021  *    of any contributors may be used to endorse or promote products derived
0022  *    from this software without specific prior written permission.
0023  *
0024  * Alternatively, this software may be distributed under the terms of the
0025  * GNU General Public License ("GPL") version 2 as published by the Free
0026  * Software Foundation.
0027  *
0028  * NO WARRANTY
0029  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0030  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0031  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
0032  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0033  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0034  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0035  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0036  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
0037  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
0038  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0039  * POSSIBILITY OF SUCH DAMAGES.
0040  *
0041  * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_macro_gram.y#5 $
0042  *
0043  * $FreeBSD$
0044  */
0045 
0046 #include <sys/types.h>
0047 
0048 #include <inttypes.h>
0049 #include <regex.h>
0050 #include <stdio.h>
0051 #include <stdlib.h>
0052 #include <string.h>
0053 #include <sysexits.h>
0054 
0055 #include "../queue.h"
0056 
0057 #include "aicasm.h"
0058 #include "aicasm_symbol.h"
0059 #include "aicasm_insformat.h"
0060 
0061 static symbol_t *macro_symbol;
0062 
0063 static void add_macro_arg(const char *argtext, int position);
0064 void mmerror(const char *string);
0065 
0066 %}
0067 
0068 %union {
0069         int             value;
0070         char            *str;
0071         symbol_t        *sym;
0072 }
0073 
0074 
0075 %token <str> T_ARG
0076 
0077 %token <sym> T_SYMBOL
0078 
0079 %type <value> macro_arglist
0080 
0081 %%
0082 
0083 macrocall:
0084         T_SYMBOL '('
0085         {
0086                 macro_symbol = $1;
0087         }
0088         macro_arglist ')'
0089         {
0090                 if (macro_symbol->info.macroinfo->narg != $4) {
0091                         printf("Narg == %d", macro_symbol->info.macroinfo->narg);
0092                         stop("Too few arguments for macro invocation",
0093                              EX_DATAERR);
0094                         /* NOTREACHED */
0095                 }
0096                 macro_symbol = NULL;
0097                 YYACCEPT;
0098         }
0099 ;
0100 
0101 macro_arglist:
0102         {
0103                 /* Macros can take 0 arguments */
0104                 $$ = 0;
0105         }
0106 |       T_ARG
0107         {
0108                 $$ = 1;
0109                 add_macro_arg($1, 1);
0110         }
0111 |       macro_arglist ',' T_ARG
0112         {
0113                 if ($1 == 0) {
0114                         stop("Comma without preceding argument in arg list",
0115                              EX_DATAERR);
0116                         /* NOTREACHED */
0117                 }
0118                 $$ = $1 + 1;
0119                 add_macro_arg($3, $$);
0120         }
0121 ;
0122 
0123 %%
0124 
0125 static void
0126 add_macro_arg(const char *argtext, int argnum)
0127 {
0128         struct macro_arg *marg;
0129         int i;
0130 
0131         if (macro_symbol == NULL || macro_symbol->type != MACRO) {
0132                 stop("Invalid current symbol for adding macro arg",
0133                      EX_SOFTWARE);
0134                 /* NOTREACHED */
0135         }
0136         /*
0137          * Macro Invocation.  Find the appropriate argument and fill
0138          * in the replace ment text for this call.
0139          */
0140         i = 0;
0141         STAILQ_FOREACH(marg, &macro_symbol->info.macroinfo->args, links) {
0142                 i++;
0143                 if (i == argnum)
0144                         break;
0145         }
0146         if (marg == NULL) {
0147                 stop("Too many arguments for macro invocation", EX_DATAERR);
0148                 /* NOTREACHED */
0149         }
0150         marg->replacement_text = strdup(argtext);
0151         if (marg->replacement_text == NULL) {
0152                 stop("Unable to replicate replacement text", EX_SOFTWARE);
0153                 /* NOTREACHED */
0154         }
0155 }
0156 
0157 void
0158 mmerror(const char *string)
0159 {
0160         stop(string, EX_DATAERR);
0161 }