[Midnightbsd-cvs] src: pcc/mip: WIP: Update to .99
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Tue Jan 20 16:10:48 EST 2009
Log Message:
-----------
WIP: Update to .99
Added Files:
-----------
src/usr.bin/pcc/ccom:
softfloat.c (r1.1)
src/usr.bin/pcc/i386:
flocal.c (r1.1)
src/usr.bin/pcc/mip:
compat.h (r1.1)
-------------- next part --------------
--- /dev/null
+++ usr.bin/pcc/i386/flocal.c
@@ -0,0 +1,234 @@
+/* $Id: flocal.c,v 1.16 2008/12/19 20:26:50 ragge Exp $ */
+/*
+ * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code and documentation must retain the above
+ * copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditionsand the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed or owned by Caldera
+ * International, Inc.
+ * Neither the name of Caldera International, Inc. nor the names of other
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
+ * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
+ * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <stdio.h>
+
+#include "defines.h"
+#include "defs.h"
+
+void
+prchars(int *s)
+{
+ printf("\t.byte 0%o,0%o\n", s[0], s[1]);
+}
+
+
+void
+setloc(int l)
+{
+ static int lastloc = -1;
+ static char *loctbl[] =
+ { "text", "data", "section .rodata", "section .rodata", "bss" };
+ if (l == lastloc)
+ return;
+ printf("\t.%s\n", loctbl[l]);
+ lastloc = l;
+}
+
+#ifdef FCOM
+
+
+/*
+ PDP11-780/VAX - SPECIFIC PRINTING ROUTINES
+*/
+
+/*
+ * Called just before return from a subroutine.
+ */
+void
+goret(int type)
+{
+}
+
+/*
+ * Print out a label.
+ */
+void
+prlabel(int k)
+{
+ printf(LABFMT ":\n", k);
+}
+
+/*
+ * Print naming for location.
+ * name[0] is location type.
+ */
+void
+prnloc(char *name)
+{
+ if (*name == '0')
+ setloc(DATA);
+ else
+ fatal("unhandled prnloc %c", *name);
+ printf("%s:\n", name+1);
+}
+
+/*
+ * Print integer constant.
+ */
+void
+prconi(FILE *fp, int type, ftnint n)
+{
+ fprintf(fp, "\t%s\t%ld\n", (type==TYSHORT ? ".word" : ".long"), n);
+}
+
+/*
+ * Print address constant, given as a label number.
+ */
+void
+prcona(ftnint a)
+{
+ printf("\t.long\t" LABFMT "\n", (int)a);
+}
+
+/*
+ * Print out a floating constant.
+ */
+void
+prconr(FILE *fp, int type, double x)
+{
+ fprintf(fp, "\t%s\t0f%e\n", (type==TYREAL ? ".float" : ".double"), x);
+}
+
+void
+preven(int k)
+{
+ if (k > 1)
+ printf("\t.align\t%d\n", k);
+}
+
+/*
+ * Convert a tag and offset into the symtab table to a string.
+ * An external string is never longer than XL bytes.
+ */
+char *
+memname(int stg, int mem)
+{
+#define MLEN (XL + 10)
+ char *s = malloc(MLEN);
+
+ switch(stg) {
+ case STGCOMMON:
+ case STGEXT:
+ snprintf(s, MLEN, "%s", varstr(XL, extsymtab[mem].extname));
+ break;
+
+ case STGBSS:
+ case STGINIT:
+ snprintf(s, MLEN, "v.%d", mem);
+ break;
+
+ case STGCONST:
+ snprintf(s, MLEN, ".L%d", mem);
+ break;
+
+ case STGEQUIV:
+ snprintf(s, MLEN, "q.%d", mem);
+ break;
+
+ default:
+ fatal1("memname: invalid vstg %d", stg);
+ }
+ return(s);
+}
+
+void
+prlocvar(char *s, ftnint len)
+{
+ printf("\t.lcomm\t%s,%ld\n", s, len);
+}
+
+
+void
+prext(char *name, ftnint leng, int init)
+{
+ if(leng == 0)
+ printf("\t.globl\t%s\n", name);
+ else
+ printf("\t.comm\t%s,%ld\n", name, leng);
+}
+
+void
+prendproc()
+{
+}
+
+void
+prtail()
+{
+}
+
+void
+prolog(struct entrypoint *ep, struct bigblock *argvec)
+{
+ /* Ignore for now. ENTRY is not supported */
+}
+
+
+
+void
+prdbginfo()
+{
+}
+
+static void
+fcheck(NODE *p, void *arg)
+{
+ NODE *r, *l;
+
+ switch (p->n_op) {
+ case CALL: /* fix arguments */
+ for (r = p->n_right; r->n_op == CM; r = r->n_left) {
+ r->n_right = mkunode(FUNARG, r->n_right, 0,
+ r->n_right->n_type);
+ }
+ l = talloc();
+ *l = *r;
+ r->n_op = FUNARG;
+ r->n_left = l;
+ r->n_type = l->n_type;
+ break;
+ }
+}
+
+/*
+ * Called just before the tree is written out to pass2.
+ */
+void p2tree(NODE *p);
+void
+p2tree(NODE *p)
+{
+ walkf(p, fcheck, 0);
+}
+#endif /* FCOM */
--- /dev/null
+++ usr.bin/pcc/ccom/softfloat.c
@@ -0,0 +1,318 @@
+/* $Id: softfloat.c,v 1.2 2008/09/12 16:27:26 ragge Exp $ */
+
+/*
+ * Copyright (c) 2008 Anders Magnusson. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef SOFTFLOAT
+
+#include "manifest.h"
+#include "pass1.h"
+
+
+/*
+ * Floating point emulation to be used when cross-compiling.
+ * Currently only supports F- and D-float, used in DEC machines.
+ * Should be trivial to add other emulations.
+ *
+ * XXX - assumes that:
+ * - long long is (at least) 64 bits
+ * - int is at least 32 bits.
+ * - short is 16 bits.
+ */
+
+#ifdef FDFLOAT
+
+/*
+ * Useful macros to manipulate the float.
+ */
+#define DSIGN(w) (((w).fd1 >> 15) & 1)
+#define DSIGNSET(w,s) ((w).fd1 = (s << 15) | ((w).fd1 & 077777))
+#define DEXP(w) (((w).fd1 >> 7) & 0377)
+#define DEXPSET(w,e) ((w).fd1 = (((e) & 0377) << 7) | ((w).fd1 & 0100177))
+#define DMANTH(w) ((w).fd1 & 0177)
+#define DMANTHSET(w,m) ((w).fd1 = ((m) & 0177) | ((w).fd1 & 0177600))
+
+typedef unsigned int lword;
+typedef unsigned long long dword;
+
+#define MAXMANT 0x100000000000000LL
+
+/*
+ * Returns a zero dfloat.
+ */
+static SF
+nulldf(void)
+{
+ SF rv;
+
+ rv.fd1 = rv.fd2 = rv.fd3 = rv.fd4 = 0;
+ return rv;
+}
+
+/*
+ * Convert a (u)longlong to dfloat.
+ * XXX - fails on too large (> 55 bits) numbers.
+ */
+SF
+soft_cast(CONSZ ll, TWORD t)
+{
+ int i;
+ SF rv;
+
+ rv = nulldf();
+ if (ll == 0)
+ return rv; /* fp is zero */
+ if (ll < 0)
+ DSIGNSET(rv,1), ll = -ll;
+ for (i = 0; ll > 0; i++, ll <<= 1)
+ ;
+ DEXPSET(rv, 192-i);
+ DMANTHSET(rv, ll >> 56);
+ rv.fd2 = ll >> 40;
+ rv.fd3 = ll >> 24;
+ rv.fd4 = ll >> 8;
+ return rv;
+}
+
+/*
+ * multiply two dfloat. Use chop, not round.
+ */
+SF
+soft_mul(SF p1, SF p2)
+{
+ SF rv;
+ lword a1[2], a2[2], res[4];
+ dword sum;
+
+ res[0] = res[1] = res[2] = res[3] = 0;
+
+ /* move mantissa into lwords */
+ a1[0] = p1.fd4 | (p1.fd3 << 16);
+ a1[1] = p1.fd2 | DMANTH(p1) << 16 | 0x800000;
+
+ a2[0] = p2.fd4 | (p2.fd3 << 16);
+ a2[1] = p2.fd2 | DMANTH(p2) << 16 | 0x800000;
+
+#define MULONE(x,y,r) sum += (dword)a1[x] * (dword)a2[y]; sum += res[r]; \
+ res[r] = sum; sum >>= 32;
+
+ sum = 0;
+ MULONE(0, 0, 0);
+ MULONE(1, 0, 1);
+ res[2] = sum;
+ sum = 0;
+ MULONE(0, 1, 1);
+ MULONE(1, 1, 2);
+ res[3] = sum;
+
+ rv.fd1 = 0;
+ DSIGNSET(rv, DSIGN(p1) ^ DSIGN(p2));
+ DEXPSET(rv, DEXP(p1) + DEXP(p2) - 128);
+ if (res[3] & 0x8000) {
+ res[3] = (res[3] << 8) | (res[2] >> 24);
+ res[2] = (res[2] << 8) | (res[1] >> 24);
+ } else {
+ DEXPSET(rv, DEXP(rv) - 1);
+ res[3] = (res[3] << 9) | (res[2] >> 23);
+ res[2] = (res[2] << 9) | (res[1] >> 23);
+ }
+ DMANTHSET(rv, res[3] >> 16);
+ rv.fd2 = res[3];
+ rv.fd3 = res[2] >> 16;
+ rv.fd4 = res[2];
+ return rv;
+}
+
+SF
+soft_div(SF t, SF n)
+{
+ SF rv;
+ dword T, N, K;
+ int c;
+
+#define SHL(x,b) ((dword)(x) << b)
+ T = SHL(1,55) | SHL(DMANTH(t), 48) |
+ SHL(t.fd2, 32) | SHL(t.fd3, 16) | t.fd4;
+ N = SHL(1,55) | SHL(DMANTH(n), 48) |
+ SHL(n.fd2, 32) | SHL(n.fd3, 16) | n.fd4;
+
+ c = T > N;
+ for (K = 0; (K & 0x80000000000000ULL) == 0; ) {
+ if (T >= N) {
+ T -= N;
+ K |= 1;
+ }
+ T <<= 1;
+ K <<= 1;
+ }
+ rv.fd1 = 0;
+ DSIGNSET(rv, DSIGN(t) ^ DSIGN(n));
+ DEXPSET(rv, DEXP(t) - DEXP(n) + 128 + c);
+ DMANTHSET(rv, K >> 48);
+ rv.fd2 = K >> 32;
+ rv.fd3 = K >> 16;
+ rv.fd4 = K;
+ return rv;
+}
+
+/*
+ * Negate a float number. Easy.
+ */
+SF
+soft_neg(SF sf)
+{
+ int sign = DSIGN(sf) == 0;
+ DSIGNSET(sf, sign);
+ return sf;
+}
+
+/*
+ * Return true if fp number is zero.
+ */
+int
+soft_isz(SF sf)
+{
+ return (DEXP(sf) == 0);
+}
+
+/*
+ * Convert a fp number to a CONSZ.
+ */
+CONSZ
+soft_val(SF sf)
+{
+ CONSZ mant;
+ int exp = DEXP(sf) - 128;
+
+ mant = SHL(1,55) | SHL(DMANTH(sf), 48) |
+ SHL(sf.fd2, 32) | SHL(sf.fd3, 16) | sf.fd4;
+
+ while (exp < 0)
+ mant >>= 1, exp++;
+ while (exp > 0)
+ mant <<= 1, exp--;
+ return mant;
+}
+
+SF
+soft_plus(SF x1, SF x2)
+{
+ cerror("soft_plus");
+ return x1;
+}
+
+SF
+soft_minus(SF x1, SF x2)
+{
+ cerror("soft_minus");
+ return x1;
+}
+
+/*
+ * Convert a hex constant to floating point number.
+ */
+NODE *
+fhexcon(char *s)
+{
+ cerror("fhexcon");
+ return NULL;
+}
+
+/*
+ * Convert a floating-point constant to D-float and store it in a NODE.
+ */
+NODE *
+floatcon(char *s)
+{
+ NODE *p;
+ dword mant;
+ SF fl, flexp, exp5;
+ int exp, negexp, bexp;
+
+ exp = 0;
+ mant = 0;
+#define ADDTO(sum, val) sum = sum * 10 + val - '0'
+ for (; *s >= '0' && *s <= '9'; s++) {
+ if (mant<MAXMANT)
+ ADDTO(mant, *s);
+ else
+ exp++;
+ }
+ if (*s == '.') {
+ for (s++; *s >= '0' && *s <= '9'; s++) {
+ if (mant<MAXMANT) {
+ ADDTO(mant, *s);
+ exp--;
+ }
+ }
+ }
+
+ if ((*s == 'E') || (*s == 'e')) {
+ int eexp = 0, sign = 0;
+ s++;
+ if (*s == '+')
+ p++;
+ else if (*s=='-')
+ sign = 1, s++;
+
+ for (; *s >= '0' && *s <= '9'; s++)
+ ADDTO(eexp, *s);
+ if (sign)
+ eexp = -eexp;
+ exp = exp + eexp;
+ }
+
+ negexp = 1;
+ if (exp<0) {
+ negexp = -1;
+ exp = -exp;
+ }
+
+
+ flexp = soft_cast(1, INT);
+ exp5 = soft_cast(5, INT);
+ bexp = exp;
+ fl = soft_cast(mant, INT);
+
+ for (; exp; exp >>= 1) {
+ if (exp&01)
+ flexp = soft_mul(flexp, exp5);
+ exp5 = soft_mul(exp5, exp5);
+ }
+ if (negexp<0)
+ fl = soft_div(fl, flexp);
+ else
+ fl = soft_mul(fl, flexp);
+
+ DEXPSET(fl, DEXP(fl) + negexp*bexp);
+ p = block(FCON, NIL, NIL, DOUBLE, 0, MKSUE(DOUBLE)); /* XXX type */
+ p->n_dcon = fl;
+ return p;
+}
+#else
+#error missing softfloat definition
+#endif
+#endif
--- /dev/null
+++ usr.bin/pcc/mip/compat.h
@@ -0,0 +1,45 @@
+/*
+ * Just compatibility function prototypes.
+ * Public domain.
+ */
+
+#ifndef COMPAT_H
+#define COMPAT_H
+
+#include <string.h>
+
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char *dst, const char *src, size_t siz);
+#endif
+
+#ifndef HAVE_STRLCAT
+size_t strlcat(char *dst, const char *src, size_t siz);
+#endif
+
+#ifndef HAVE_GETOPT
+extern char *optarg;
+extern int optind;
+int getopt(int, char **, char *);
+#endif
+
+#ifndef HAVE_BASENAME
+char *basename(char *);
+#endif
+
+#ifndef HAVE_MKSTEMP
+int mkstemp(char *);
+#endif
+
+#ifndef HAVE_FFS
+int ffs(int);
+#endif
+
+#ifndef HAVE_SNPRINTF
+int snprintf(char *str, size_t count, const char *fmt, ...);
+#endif
+
+#ifndef HAVE_VSNPRINTF
+int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
+#endif
+
+#endif
More information about the Midnightbsd-cvs
mailing list