/* ccg.c -- preprocessor for dynamic assemblers * * Copyright (C) 1999, 2000 Ian Piumarta * * This file is part of CCG. * * CCG is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * CCG is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. * * See the file COPYING for more details. * * Last edited: Thu Jan 13 12:02:56 2000 by piumarta (Ian Piumarta) on pingu */ #include #include #include #include #include #ifdef __STRICT_ANSI__ /* a BSD function not declared in ANSI string.h */ extern int strcasecmp(); #endif #if defined(sun) && defined(__sparc__) # include # if !defined(ECHRNG) /* Poor old SunOS needs a little coaxing along */ extern int vfprintf(); extern int bcopy(); extern int strcasecmp(); # define memmove(d,s,l) bcopy(s,d,l) # endif #endif #define REWRITE_PSEUDO_ARGS #define HEADER_PREFIX "ccg/asm-" #define LABEL_CHARS "_A-Za-z0-9" #define ASM_1_OPEN "#[" #define ASM_1_CLOSE "]#" #define ASM_2_OPEN "#{" #define ASM_2_CLOSE "}#" #define REG_OPEN "#(" #define REG_CLOSE ")#" char commentChar= '#'; char escapeChar= '!'; #define ASM_1_BEGIN "_ASM_APP_1" #define ASM_1_END "_ASM_NOAPP_1" #define ASM_2_BEGIN "_ASM_APP_2" #define ASM_2_END "_ASM_NOAPP_2" #define ASM_ORG "_ASM_ORG" #define ASM_LBL "_ASM_LBL" #define ASM_DEF "_ASM_DEF" char *fileName= 0; int lineNo= 0; char line[256]; int quiet= 0; int dodot= 1; int check_insns= 1; int asmFwdWarned= 0; char **insn_tab= 0; typedef char *(*rewriter)(int code); extern rewriter rewrite; void warning(char *fmt, ...) { if (!quiet) { va_list ap; if (fileName) fprintf(stderr, "%s:%d: warning: ", fileName, lineNo); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); if (fileName) fprintf(stderr, "%s:%d: %s\n", fileName, lineNo, line); } } void error(char *fmt, ...) { va_list ap; if (fileName) fprintf(stderr, "%s:%d: error: ", fileName, lineNo); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); if (fileName) fprintf(stderr, "%s:%d: %s\n", fileName, lineNo, line); exit(1); } void usage(char *progName) { fprintf(stderr, CCGVERSION" Copyright (C) 1999, 2000 Ian Piumarta \n" "Usage: %s [