Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.276
 
1.277
 
MAIN:ragge:20100411150104
 
pftn.c
_>6565 
 6666 # include "pass1.h"
 6767 
<>68 -#include <string.h> /* XXX - for strcmp */
 69 -
7068 #include "cgram.h"
 7169 
 7270 struct symtab *cftnsp;
     
 !
20652063         return r;
 20662064 }
 20672065 
<>2068 -#ifndef NO_C_BUILTINS
 2069 -/*
 2070 - * replace an alloca function with direct allocation on stack.
 2071 - * return a destination temp node.
 2072 - */
 2073 -static NODE *
 2074 -builtin_alloca(NODE *f, NODE *a)
 2075 -{
 2076 -        struct symtab *sp;
 2077 -        NODE *t, *u;
 2078 -
 2079 -#ifdef notyet
 2080 -        if (xnobuiltins)
 2081 -                return NULL;
 2082 -#endif
 2083 -        sp = f->n_sp;
 2084 -
 2085 -        if (a == NULL || a->n_op == CM) {
 2086 -                uerror("wrong arg count for alloca");
 2087 -                return bcon(0);
 2088 -        }
 2089 -        t = tempnode(0, VOID|PTR, 0, MKSUE(INT) /* XXX */);
 2090 -        u = tempnode(regno(t), VOID|PTR, 0, MKSUE(INT) /* XXX */);
 2091 -        spalloc(t, a, SZCHAR);
 2092 -        tfree(f);
 2093 -        return u;
 2094 -}
 2095 -
 2096 -/*
 2097 - * See if there is a goto in the tree.
 2098 - * XXX this function is a hack for a flaw in handling of
 2099 - * compound expressions and inline functions and should not be
 2100 - * needed.
 2101 - */
 2102 -static int
 2103 -hasgoto(NODE *p)
 2104 -{
 2105 -        int o = coptype(p->n_op);
 2106 -
 2107 -        if (o == LTYPE)
 2108 -                return 0;
 2109 -        if (p->n_op == GOTO)
 2110 -                return 1;
 2111 -        if (o == UTYPE)
 2112 -                return hasgoto(p->n_left);
 2113 -        if (hasgoto(p->n_left))
 2114 -                return 1;
 2115 -        return hasgoto(p->n_right);
 2116 -}
 2117 -
 2118 -/*
 2119 - * Determine if a value is known to be constant at compile-time and
 2120 - * hence that PCC can perform constant-folding on expressions involving
 2121 - * that value.
 2122 - */
 2123 -static NODE *
 2124 -builtin_constant_p(NODE *f, NODE *a)
 2125 -{
 2126 -        int isconst = (a != NULL && a->n_op == ICON);
 2127 -
 2128 -        tfree(f);
 2129 -        if (a && hasgoto(a)) {
 2130 -                a = buildtree(COMOP, a, bcon(0));
 2131 -        } else {
 2132 -                tfree(a);
 2133 -                a = bcon(isconst);
 2134 -        }
 2135 -
 2136 -        return a;
 2137 -}
 2138 -
 2139 -/*
 2140 - * Hint to the compiler whether this expression will evaluate true or false.
 2141 - * Just ignored for now.
 2142 - */
 2143 -static NODE *
 2144 -builtin_expect(NODE *f, NODE *a)
 2145 -{
 2146 -
 2147 -        tfree(f);
 2148 -        if (a && a->n_op == CM) {
 2149 -                tfree(a->n_right);
 2150 -                f = a->n_left;
 2151 -                nfree(a);
 2152 -                a = f;
 2153 -        }
 2154 -
 2155 -        return a;
 2156 -}
 2157 -
 2158 -/*
 2159 - * Just invoke memcpy(3).
 2160 - */
 2161 -static NODE *
 2162 -builtin_memcpy(NODE *f, NODE *a)
 2163 -{
 2164 -        if (a == NULL)
 2165 -                goto bad;
 2166 -
 2167 -        f->n_sp = lookup("memcpy", SNORMAL);
 2168 -        return buildtree(CALL, f, a);
 2169 -
 2170 -bad:
 2171 -        uerror("bad argument to __builtin_memcpy");
 2172 -        return bcon(0);
 2173 -}
 2174 -
 2175 -/*
 2176 - * Just invoke memset(3).
 2177 - */
 2178 -static NODE *
 2179 -builtin_memset(NODE *f, NODE *a)
 2180 -{
 2181 -
 2182 -        if (a == NULL)
 2183 -                goto bad;
 2184 -
 2185 -        f->n_sp = lookup("memset", SNORMAL);
 2186 -        return buildtree(CALL, f, a);
 2187 -
 2188 -bad:
 2189 -        uerror("bad argument to __builtin_memset");
 2190 -        return bcon(0);
 2191 -}
 2192 -
 2193 -/*
 2194 - * Take integer absolute value.
 2195 - * Simply does: ((((x)>>(8*sizeof(x)-1))^(x))-((x)>>(8*sizeof(x)-1)))
 2196 - */
 2197 -static NODE *
 2198 -builtin_abs(NODE *f, NODE *a)
 2199 -{
 2200 -        NODE *p, *q, *r, *t, *t2, *t3;
 2201 -        int tmp1, tmp2, shift;
 2202 -
 2203 -        if (a == NULL)
 2204 -                goto bad;
 2205 -
 2206 -        if (a->n_type == FLOAT || a->n_type == DOUBLE || a->n_type == LDOUBLE)
 2207 -                goto bad;
 2208 -
 2209 -        tfree(f);
 2210 -
 2211 -        if (a->n_op == ICON) {
 2212 -                if (a->n_lval < 0)
 2213 -                        a->n_lval = -a->n_lval;
 2214 -                p = a;
 2215 -        } else {
 2216 -                t = tempnode(0, a->n_type, a->n_df, a->n_sue);
 2217 -                tmp1 = regno(t);
 2218 -                p = buildtree(ASSIGN, t, a);
 2219 -
 2220 -                t = tempnode(tmp1, a->n_type, a->n_df, a->n_sue);
 2221 -                shift = (int)tsize(a->n_type, a->n_df, a->n_sue) - 1;
 2222 -                q = buildtree(RS, t, bcon(shift));
 2223 -
 2224 -                t2 = tempnode(0, a->n_type, a->n_df, a->n_sue);
 2225 -                tmp2 = regno(t2);
 2226 -                q = buildtree(ASSIGN, t2, q);
 2227 -
 2228 -                t = tempnode(tmp1, a->n_type, a->n_df, a->n_sue);
 2229 -                t2 = tempnode(tmp2, a->n_type, a->n_df, a->n_sue);
 2230 -                t3 = tempnode(tmp2, a->n_type, a->n_df, a->n_sue);
 2231 -                r = buildtree(MINUS, buildtree(ER, t, t2), t3);
 2232 -
 2233 -                p = buildtree(COMOP, p, buildtree(COMOP, q, r));
 2234 -        }
 2235 -
 2236 -        return p;
 2237 -
 2238 -bad:
 2239 -        uerror("bad argument to __builtin_abs");
 2240 -        return bcon(0);
 2241 -}
 2242 -
 2243 -#ifndef TARGET_STDARGS
 2244 -static NODE *
 2245 -builtin_stdarg_start(NODE *f, NODE *a)
 2246 -{
 2247 -        NODE *p, *q;
 2248 -        int sz;
 2249 -
 2250 -        /* check num args and type */
 2251 -        if (a == NULL || a->n_op != CM || a->n_left->n_op == CM ||
 2252 -            !ISPTR(a->n_left->n_type))
 2253 -                goto bad;
 2254 -
 2255 -        /* must first deal with argument size; use int size */
 2256 -        p = a->n_right;
 2257 -        if (p->n_type < INT) {
 2258 -                sz = (int)(SZINT/tsize(p->n_type, p->n_df, p->n_sue));
 2259 -        } else
 2260 -                sz = 1;
 2261 -
 2262 -        /* do the real job */
 2263 -        p = buildtree(ADDROF, p, NIL); /* address of last arg */
 2264 -#ifdef BACKAUTO
 2265 -        p = optim(buildtree(PLUS, p, bcon(sz))); /* add one to it (next arg) */
 2266 -#else
 2267 -        p = optim(buildtree(MINUS, p, bcon(sz))); /* add one to it (next arg) */
 2268 -#endif
 2269 -        q = block(NAME, NIL, NIL, PTR+VOID, 0, 0); /* create cast node */
 2270 -        q = buildtree(CAST, q, p); /* cast to void * (for assignment) */
 2271 -        p = q->n_right;
 2272 -        nfree(q->n_left);
 2273 -        nfree(q);
 2274 -        p = buildtree(ASSIGN, a->n_left, p); /* assign to ap */
 2275 -        tfree(f);
 2276 -        nfree(a);
 2277 -        return p;
 2278 -bad:
 2279 -        uerror("bad argument to __builtin_stdarg_start");
 2280 -        return bcon(0);
 2281 -}
 2282 -
 2283 -static NODE *
 2284 -builtin_va_arg(NODE *f, NODE *a)
 2285 -{
 2286 -        NODE *p, *q, *r, *rv;
 2287 -        int sz, nodnum;
 2288 -
 2289 -        /* check num args and type */
 2290 -        if (a == NULL || a->n_op != CM || a->n_left->n_op == CM ||
 2291 -            !ISPTR(a->n_left->n_type) || a->n_right->n_op != TYPE)
 2292 -                goto bad;
 2293 -
 2294 -        /* create a copy to a temp node of current ap */
 2295 -        p = ccopy(a->n_left);
 2296 -        q = tempnode(0, p->n_type, p->n_df, p->n_sue);
 2297 -        nodnum = regno(q);
 2298 -        rv = buildtree(ASSIGN, q, p);
 2299 -
 2300 -        r = a->n_right;
 2301 -        sz = (int)tsize(r->n_type, r->n_df, r->n_sue)/SZCHAR;
 2302 -        /* add one to ap */
 2303 -#ifdef BACKAUTO
 2304 -        rv = buildtree(COMOP, rv , buildtree(PLUSEQ, a->n_left, bcon(sz)));
 2305 -#else
 2306 -#error fix wrong eval order in builtin_va_arg
 2307 -        ecomp(buildtree(MINUSEQ, a->n_left, bcon(sz)));
 2308 -#endif
 2309 -
 2310 -        nfree(a->n_right);
 2311 -        nfree(a);
 2312 -        nfree(f);
 2313 -        r = tempnode(nodnum, INCREF(r->n_type), r->n_df, r->n_sue);
 2314 -        return buildtree(COMOP, rv, buildtree(UMUL, r, NIL));
 2315 -bad:
 2316 -        uerror("bad argument to __builtin_va_arg");
 2317 -        return bcon(0);
 2318 -
 2319 -}
 2320 -
 2321 -static NODE *
 2322 -builtin_va_end(NODE *f, NODE *a)
 2323 -{
 2324 -        tfree(f);
 2325 -        tfree(a);
 2326 -        return bcon(0); /* nothing */
 2327 -}
 2328 -
 2329 -static NODE *
 2330 -builtin_va_copy(NODE *f, NODE *a)
 2331 -{
 2332 -        if (a == NULL || a->n_op != CM || a->n_left->n_op == CM)
 2333 -                goto bad;
 2334 -        tfree(f);
 2335 -        f = buildtree(ASSIGN, a->n_left, a->n_right);
 2336 -        nfree(a);
 2337 -        return f;
 2338 -
 2339 -bad:
 2340 -        uerror("bad argument to __builtin_va_copy");
 2341 -        return bcon(0);
 2342 -}
 2343 -#endif /* TARGET_STDARGS */
 2344 -
 2345 -static struct bitable {
 2346 -        char *name;
 2347 -        NODE *(*fun)(NODE *f, NODE *a);
 2348 -} bitable[] = {
 2349 -        { "__builtin_alloca", builtin_alloca },
 2350 -        { "__builtin_constant_p", builtin_constant_p },
 2351 -        { "__builtin_abs", builtin_abs },
 2352 -        { "__builtin_expect", builtin_expect },
 2353 -        { "__builtin_memcpy", builtin_memcpy },
 2354 -        { "__builtin_memset", builtin_memset },
 2355 -#ifndef TARGET_STDARGS
 2356 -        { "__builtin_stdarg_start", builtin_stdarg_start },
 2357 -        { "__builtin_va_start", builtin_stdarg_start },
 2358 -        { "__builtin_va_arg", builtin_va_arg },
 2359 -        { "__builtin_va_end", builtin_va_end },
 2360 -        { "__builtin_va_copy", builtin_va_copy },
 2361 -#endif
 2362 -#ifdef TARGET_BUILTINS
 2363 -        TARGET_BUILTINS
 2364 -#endif
 2365 -};
 2366 -#endif
 2367 -
23682066 #ifdef PCC_DEBUG
 23692067 /*
 23702068  * Print a prototype.
     
 !
24412139 #ifndef NO_C_BUILTINS
 24422140         /* check for builtins. function pointers are not allowed */
 24432141         if (f->n_op == NAME &&
<>2444 -            f->n_sp->sname[0] == '_' && f->n_sp->sname[1] == '_') {
 2445 -                int i;
 2446 -
 2447 -                for (i = 0; i < (int)(sizeof(bitable)/sizeof(bitable[0])); i++) {
 2448 -                        if (strcmp(bitable[i].name, f->n_sp->sname) == 0)
 2449 -                                return (*bitable[i].fun)(f, a);
 2450 -                }
 2451 -        }
  2142+            f->n_sp->sname[0] == '_' && f->n_sp->sname[1] == '_')
  2143+                if ((w = builtin_check(f, a)) != NIL)
  2144+                        return w;
<_24522145 #endif
 24532146 
 24542147         /* Check for undefined or late defined enums */
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-08-20 14:42 +0200