| @@ -64,14 +64,15 @@ typedef union CValue { · 63 unmodified lines |
| 64 | long long ll; | 64 | long long ll; |
| 65 | unsigned long long ull; | 65 | unsigned long long ull; |
| 66 | struct TokenSym *ts; | 66 | struct TokenSym *ts; |
| 67 | int tab[1]; | | |
| 68 | struct Sym *sym; | 67 | struct Sym *sym; |
| | 68 | int tab[1]; |
| 69 | } CValue; | 69 | } CValue; |
| 70 | | 70 | |
| 71 | /* value on stack */ | 71 | /* value on stack */ |
| 72 | typedef struct SValue { | 72 | typedef struct SValue { |
| 73 | int t; | 73 | int t; /* type */ |
| 74 | CValue c; | 74 | int r; /* register + flags */ |
| | 75 | CValue c; /* constant */ |
| 75 | } SValue; | 76 | } SValue; |
| 76 | | 77 | |
| 77 | /* symbol management */ | 78 | /* symbol management */ |
| @@ -360,7 +361,7 @@ int pointed_size(int t); · 282 unmodified lines |
| 360 | int ist(void); | 361 | int ist(void); |
| 361 | int type_decl(int *v, int t, int td); | 362 | int type_decl(int *v, int t, int td); |
| 362 | void error(const char *fmt, ...); | 363 | void error(const char *fmt, ...); |
| 363 | void vset(int t, int v); | 364 | void vset(int t, int r, int v); |
| 364 | | 365 | |
| 365 | /* true if float/double/long double type */ | 366 | /* true if float/double/long double type */ |
| 366 | static inline int is_float(int t) | 367 | static inline int is_float(int t) |
| @@ -485,7 +486,7 @@ void skip(int c) · 118 unmodified lines |
| 485 | | 486 | |
| 486 | void test_lvalue(void) | 487 | void test_lvalue(void) |
| 487 | { | 488 | { |
| 488 | if (!(vtop->t & VT_LVAL)) | 489 | if (!(vtop->r & VT_LVAL)) |
| 489 | expect("lvalue"); | 490 | expect("lvalue"); |
| 490 | } | 491 | } |
| 491 | | 492 | |
| @@ -1874,25 +1875,34 @@ void swap(int *p, int *q) · 1382 unmodified lines |
| 1874 | *q = t; | 1875 | *q = t; |
| 1875 | } | 1876 | } |
| 1876 | | 1877 | |
| 1877 | void vsetc(int t, CValue *vc) | 1878 | void vsetc(int t, int r, CValue *vc) |
| 1878 | { | 1879 | { |
| 1879 | if (vtop >= vstack + VSTACK_SIZE) | 1880 | if (vtop >= vstack + VSTACK_SIZE) |
| 1880 | error("memory full"); | 1881 | error("memory full"); |
| 1881 | /* cannot let cpu flags if other instruction are generated */ | 1882 | /* cannot let cpu flags if other instruction are generated */ |
| 1882 | /* XXX: VT_JMP test too ? */ | 1883 | /* XXX: VT_JMP test too ? */ |
| 1883 | if ((vtop->t & VT_VALMASK) == VT_CMP) | 1884 | if ((vtop->r & VT_VALMASK) == VT_CMP) |
| 1884 | gv(); | 1885 | gv(); |
| 1885 | vtop++; | 1886 | vtop++; |
| 1886 | vtop->t = t; | 1887 | vtop->t = t; |
| | 1888 | vtop->r = r; |
| 1887 | vtop->c = *vc; | 1889 | vtop->c = *vc; |
| 1888 | } | 1890 | } |
| 1889 | | 1891 | |
| 1890 | void vset(int t, int v) | 1892 | /* push integer constant */ |
| | 1893 | void vpushi(int v) |
| | 1894 | { |
| | 1895 | CValue cval; |
| | 1896 | cval.i = v; |
| | 1897 | vsetc(VT_INT, VT_CONST, &cval); |
| | 1898 | } |
| | 1899 | |
| | 1900 | void vset(int t, int r, int v) |
| 1891 | { | 1901 | { |
| 1892 | CValue cval; | 1902 | CValue cval; |
| 1893 | | 1903 | |
| 1894 | cval.i = v; | 1904 | cval.i = v; |
| 1895 | vsetc(t, &cval); | 1905 | vsetc(t, r, &cval); |
| 1896 | } | 1906 | } |
| 1897 | | 1907 | |
| 1898 | void vswap(void) | 1908 | void vswap(void) |
| @@ -1915,22 +1925,25 @@ void vdup(void) · 16 unmodified lines |
| 1915 | int save_reg_forced(int r) | 1925 | int save_reg_forced(int r) |
| 1916 | { | 1926 | { |
| 1917 | int i, l, t; | 1927 | int i, l, t; |
| 1918 | SValue *p; | 1928 | SValue *p, sv; |
| 1919 | | 1929 | |
| 1920 | /* store register */ | 1930 | /* store register */ |
| 1921 | loc = (loc - 4) & -3; | 1931 | loc = (loc - 4) & -3; |
| 1922 | store(r, VT_LOCAL, loc); | 1932 | sv.t = VT_INT; |
| | 1933 | sv.r = VT_LOCAL | VT_LVAL; |
| | 1934 | sv.c.ul = loc; |
| | 1935 | store(r, &sv); |
| 1923 | l = loc; | 1936 | l = loc; |
| 1924 | | 1937 | |
| 1925 | /* modify all stack values */ | 1938 | /* modify all stack values */ |
| 1926 | for(p=vstack;p<=vtop;p++) { | 1939 | for(p=vstack;p<=vtop;p++) { |
| 1927 | i = p->t & VT_VALMASK; | 1940 | i = p->r & VT_VALMASK; |
| 1928 | if (i == r) { | 1941 | if (i == r) { |
| 1929 | if (p->t & VT_LVAL) | 1942 | if (p->r & VT_LVAL) |
| 1930 | t = VT_LLOCAL; | 1943 | t = VT_LLOCAL; |
| 1931 | else | 1944 | else |
| 1932 | t = VT_LOCAL; | 1945 | t = VT_LOCAL; |
| 1933 | p->t = (p->t & VT_TYPE) | VT_LVAL | t; | 1946 | p->r = VT_LVAL | t; |
| 1934 | p->c.ul = l; | 1947 | p->c.ul = l; |
| 1935 | } | 1948 | } |
| 1936 | } | 1949 | } |
| @@ -1945,7 +1958,7 @@ void save_reg(int r) · 8 unmodified lines |
| 1945 | | 1958 | |
| 1946 | /* modify all stack values */ | 1959 | /* modify all stack values */ |
| 1947 | for(p=vstack;p<=vtop;p++) { | 1960 | for(p=vstack;p<=vtop;p++) { |
| 1948 | i = p->t & VT_VALMASK; | 1961 | i = p->r & VT_VALMASK; |
| 1949 | if (i == r) { | 1962 | if (i == r) { |
| 1950 | save_reg_forced(r); | 1963 | save_reg_forced(r); |
| 1951 | break; | 1964 | break; |
| @@ -1963,7 +1976,7 @@ int get_reg(int rc) · 11 unmodified lines |
| 1963 | for(r=0;r<NB_REGS;r++) { | 1976 | for(r=0;r<NB_REGS;r++) { |
| 1964 | if (reg_classes[r] & rc) { | 1977 | if (reg_classes[r] & rc) { |
| 1965 | for(p=vstack;p<=vtop;p++) { | 1978 | for(p=vstack;p<=vtop;p++) { |
| 1966 | i = p->t & VT_VALMASK; | 1979 | i = p->r & VT_VALMASK; |
| 1967 | if (i == r) | 1980 | if (i == r) |
| 1968 | goto notfound; | 1981 | goto notfound; |
| 1969 | } | 1982 | } |
| @@ -1976,7 +1989,7 @@ int get_reg(int rc) · 6 unmodified lines |
| 1976 | important to start from the bottom to ensure that we don't | 1989 | important to start from the bottom to ensure that we don't |
| 1977 | spill registers used in gen_op()) */ | 1990 | spill registers used in gen_op()) */ |
| 1978 | for(p=vstack;p<=vtop;p++) { | 1991 | for(p=vstack;p<=vtop;p++) { |
| 1979 | r = p->t & VT_VALMASK; | 1992 | r = p->r & VT_VALMASK; |
| 1980 | if (r < VT_CONST && (reg_classes[r] & rc)) { | 1993 | if (r < VT_CONST && (reg_classes[r] & rc)) { |
| 1981 | save_reg(r); | 1994 | save_reg(r); |
| 1982 | break; | 1995 | break; |
| @@ -1985,13 +1998,13 @@ int get_reg(int rc) · 2 unmodified lines |
| 1985 | return r; | 1998 | return r; |
| 1986 | } | 1999 | } |
| 1987 | | 2000 | |
| 1988 | void save_regs() | 2001 | void save_regs(void) |
| 1989 | { | 2002 | { |
| 1990 | int r; | 2003 | int r; |
| 1991 | SValue *p; | 2004 | SValue *p; |
| 1992 | | 2005 | |
| 1993 | for(p=vstack;p<=vtop;p++) { | 2006 | for(p=vstack;p<=vtop;p++) { |
| 1994 | r = p->t & VT_VALMASK; | 2007 | r = p->r & VT_VALMASK; |
| 1995 | if (r < VT_CONST) { | 2008 | if (r < VT_CONST) { |
| 1996 | save_reg(r); | 2009 | save_reg(r); |
| 1997 | } | 2010 | } |
| @@ -2002,9 +2015,14 @@ void save_regs() · 4 unmodified lines |
| 2002 | if needed */ | 2015 | if needed */ |
| 2003 | void move_reg(int r, int s) | 2016 | void move_reg(int r, int s) |
| 2004 | { | 2017 | { |
| | 2018 | SValue sv; |
| | 2019 | |
| 2005 | if (r != s) { | 2020 | if (r != s) { |
| 2006 | save_reg(r); | 2021 | save_reg(r); |
| 2007 | load(r, s, 0); | 2022 | sv.t = VT_INT; |
| | 2023 | sv.r = s; |
| | 2024 | sv.c.ul = 0; |
| | 2025 | load(r, &sv); |
| 2008 | } | 2026 | } |
| 2009 | } | 2027 | } |
| 2010 | | 2028 | |
| @@ -2022,14 +2040,15 @@ int gv(void) · 11 unmodified lines |
| 2022 | /* remove bit field info to avoid loops */ | 2040 | /* remove bit field info to avoid loops */ |
| 2023 | vtop->t &= ~(VT_BITFIELD | (-1 << VT_STRUCT_SHIFT)); | 2041 | vtop->t &= ~(VT_BITFIELD | (-1 << VT_STRUCT_SHIFT)); |
| 2024 | /* generate shifts */ | 2042 | /* generate shifts */ |
| 2025 | vset(VT_CONST, 32 - (bit_pos + bit_size)); | 2043 | vpushi(32 - (bit_pos + bit_size)); |
| 2026 | gen_op(TOK_SHL); | 2044 | gen_op(TOK_SHL); |
| 2027 | vset(VT_CONST, 32 - bit_size); | 2045 | vpushi(32 - bit_size); |
| 2028 | /* NOTE: transformed to SHR if unsigned */ | 2046 | /* NOTE: transformed to SHR if unsigned */ |
| 2029 | gen_op(TOK_SAR); | 2047 | gen_op(TOK_SAR); |
| 2030 | r = gv(); | 2048 | r = gv(); |
| 2031 | } else { | 2049 | } else { |
| 2032 | if (is_float(vtop->t) && (vtop->t & (VT_CONST | VT_LVAL)) == VT_CONST) { | 2050 | if (is_float(vtop->t) && |
| | 2051 | (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { |
| 2033 | /* CPUs usually cannot use float constants, so we store them | 2052 | /* CPUs usually cannot use float constants, so we store them |
| 2034 | generically in data segment */ | 2053 | generically in data segment */ |
| 2035 | size = type_size(vtop->t, &align); | 2054 | size = type_size(vtop->t, &align); |
| @@ -2038,20 +2057,20 @@ int gv(void) · 2 unmodified lines |
| 2038 | size = size >> 2; | 2057 | size = size >> 2; |
| 2039 | for(i=0;i<size;i++) | 2058 | for(i=0;i<size;i++) |
| 2040 | ((int *)glo)[i] = vtop->c.tab[i]; | 2059 | ((int *)glo)[i] = vtop->c.tab[i]; |
| 2041 | vtop->t |= VT_LVAL; | 2060 | vtop->r |= VT_LVAL; |
| 2042 | vtop->c.ul = glo; | 2061 | vtop->c.ul = glo; |
| 2043 | glo += size << 2; | 2062 | glo += size << 2; |
| 2044 | } | 2063 | } |
| 2045 | r = vtop->t & VT_VALMASK; | 2064 | r = vtop->r & VT_VALMASK; |
| 2046 | if (r >= VT_CONST || (vtop->t & VT_LVAL)) { | 2065 | if (r >= VT_CONST || (vtop->r & VT_LVAL)) { |
| 2047 | if (is_float(vtop->t)) | 2066 | if (is_float(vtop->t)) |
| 2048 | rc = REG_CLASS_FLOAT; | 2067 | rc = REG_CLASS_FLOAT; |
| 2049 | else | 2068 | else |
| 2050 | rc = REG_CLASS_INT; | 2069 | rc = REG_CLASS_INT; |
| 2051 | r = get_reg(rc); | 2070 | r = get_reg(rc); |
| 2052 | } | 2071 | } |
| 2053 | load(r, vtop->t, vtop->c.ul); | 2072 | load(r, vtop); |
| 2054 | vtop->t = (vtop->t & VT_TYPE) | r; | 2073 | vtop->r = r; |
| 2055 | } | 2074 | } |
| 2056 | return r; | 2075 | return r; |
| 2057 | } | 2076 | } |
| @@ -2065,8 +2084,8 @@ void gen_opc(int op) · 7 unmodified lines |
| 2065 | v1 = vtop - 1; | 2084 | v1 = vtop - 1; |
| 2066 | v2 = vtop; | 2085 | v2 = vtop; |
| 2067 | /* currently, we cannot do computations with forward symbols */ | 2086 | /* currently, we cannot do computations with forward symbols */ |
| 2068 | c1 = (v1->t & (VT_VALMASK | VT_LVAL | VT_FORWARD)) == VT_CONST; | 2087 | c1 = (v1->r & (VT_VALMASK | VT_LVAL | VT_FORWARD)) == VT_CONST; |
| 2069 | c2 = (v2->t & (VT_VALMASK | VT_LVAL | VT_FORWARD)) == VT_CONST; | 2088 | c2 = (v2->r & (VT_VALMASK | VT_LVAL | VT_FORWARD)) == VT_CONST; |
| 2070 | if (c1 && c2) { | 2089 | if (c1 && c2) { |
| 2071 | fc = v2->c.i; | 2090 | fc = v2->c.i; |
| 2072 | switch(op) { | 2091 | switch(op) { |
| @@ -2184,9 +2203,9 @@ void gen_op(int op) · 111 unmodified lines |
| 2184 | gen_opf(op); | 2203 | gen_opf(op); |
| 2185 | if (op >= TOK_EQ && op <= TOK_GT) { | 2204 | if (op >= TOK_EQ && op <= TOK_GT) { |
| 2186 | /* the result is an int */ | 2205 | /* the result is an int */ |
| 2187 | vtop->t = (vtop->t & ~VT_TYPE) | VT_INT; | 2206 | vtop->t = VT_INT; |
| 2188 | } else { | 2207 | } else { |
| 2189 | vtop->t = (vtop->t & ~VT_TYPE) | t; | 2208 | vtop->t = t; |
| 2190 | } | 2209 | } |
| 2191 | } else if (op == '+' || op == '-') { | 2210 | } else if (op == '+' || op == '-') { |
| 2192 | if ((t1 & VT_BTYPE) == VT_PTR && | 2211 | if ((t1 & VT_BTYPE) == VT_PTR && |
| @@ -2197,8 +2216,8 @@ void gen_op(int op) · 4 unmodified lines |
| 2197 | u = pointed_size(t1); | 2216 | u = pointed_size(t1); |
| 2198 | gen_opc(op); | 2217 | gen_opc(op); |
| 2199 | /* set to integer type */ | 2218 | /* set to integer type */ |
| 2200 | vtop->t = (vtop->t & ~VT_TYPE) | VT_INT; | 2219 | vtop->t = VT_INT; |
| 2201 | vset(VT_CONST, u); | 2220 | vpushi(u); |
| 2202 | gen_op(TOK_PDIV); | 2221 | gen_op(TOK_PDIV); |
| 2203 | } else if ((t1 & VT_BTYPE) == VT_PTR || | 2222 | } else if ((t1 & VT_BTYPE) == VT_PTR || |
| 2204 | (t2 & VT_BTYPE) == VT_PTR) { | 2223 | (t2 & VT_BTYPE) == VT_PTR) { |
| @@ -2207,11 +2226,11 @@ void gen_op(int op) · 2 unmodified lines |
| 2207 | swap(&t1, &t2); | 2226 | swap(&t1, &t2); |
| 2208 | } | 2227 | } |
| 2209 | /* stack-4 contains pointer, stack-2 value to add */ | 2228 | /* stack-4 contains pointer, stack-2 value to add */ |
| 2210 | vset(VT_CONST, pointed_size(vtop[-1].t)); | 2229 | vpushi(pointed_size(vtop[-1].t)); |
| 2211 | gen_op('*'); | 2230 | gen_op('*'); |
| 2212 | gen_opc(op); | 2231 | gen_opc(op); |
| 2213 | /* put again type if gen_opc() swaped operands */ | 2232 | /* put again type if gen_opc() swaped operands */ |
| 2214 | vtop->t = (vtop->t & ~VT_TYPE) | (t1 & VT_TYPE); | 2233 | vtop->t = t1; |
| 2215 | } else { | 2234 | } else { |
| 2216 | gen_opc(op); | 2235 | gen_opc(op); |
| 2217 | } | 2236 | } |
| @@ -2242,128 +2261,128 @@ void gen_op(int op) · 24 unmodified lines |
| 2242 | /* cast 'vtop' to 't' type */ | 2261 | /* cast 'vtop' to 't' type */ |
| 2243 | void gen_cast(int t) | 2262 | void gen_cast(int t) |
| 2244 | { | 2263 | { |
| 2245 | int r, bits, sbt, dbt, sf, df, c, st1, dt1; | 2264 | int bits, sbt, dbt, sf, df, c, st1, dt1; |
| 2246 | | 2265 | |
| 2247 | r = vtop->t & VT_VALMASK; | 2266 | /* if not lvalue, then we convert now */ |
| 2248 | if (!(t & VT_LVAL)) { | 2267 | dbt = t & VT_BTYPE; |
| 2249 | /* if not lvalue, then we convert now */ | 2268 | sbt = vtop->t & VT_BTYPE; |
| 2250 | dbt = t & VT_BTYPE; | 2269 | if (sbt != dbt) { |
| 2251 | sbt = vtop->t & VT_BTYPE; | 2270 | sf = is_float(sbt); |
| 2252 | if (sbt != dbt) { | 2271 | df = is_float(dbt); |
| 2253 | sf = is_float(sbt); | 2272 | c = (vtop->r & (VT_VALMASK | VT_LVAL | VT_FORWARD)) == VT_CONST; |
| 2254 | df = is_float(dbt); | 2273 | if (sf && df) { |
| 2255 | c = (vtop->t & (VT_VALMASK | VT_LVAL | VT_FORWARD)) == VT_CONST; | 2274 | /* convert from fp to fp */ |
| 2256 | if (sf && df) { | 2275 | if (c) { |
| 2257 | /* convert from fp to fp */ | 2276 | /* constant case: we can do it now */ |
| 2258 | if (c) { | 2277 | /* XXX: in ISOC, cannot do it if error in convert */ |
| 2259 | /* constant case: we can do it now */ | 2278 | if (dbt == VT_FLOAT && sbt == VT_DOUBLE) |
| 2260 | /* XXX: in ISOC, cannot do it if error in convert */ | 2279 | vtop->c.f = (float)vtop->c.d; |
| 2261 | if (dbt == VT_FLOAT && sbt == VT_DOUBLE) | 2280 | else if (dbt == VT_FLOAT && sbt == VT_LDOUBLE) |
| 2262 | vtop->c.f = (float)vtop->c.d; | 2281 | vtop->c.f = (float)vtop->c.ld; |
| 2263 | else if (dbt == VT_FLOAT && sbt == VT_LDOUBLE) | 2282 | else if (dbt == VT_DOUBLE && sbt == VT_FLOAT) |
| 2264 | vtop->c.f = (float)vtop->c.ld; | 2283 | vtop->c.d = (double)vtop->c.f; |
| 2265 | else if (dbt == VT_DOUBLE && sbt == VT_FLOAT) | 2284 | else if (dbt == VT_DOUBLE && sbt == VT_LDOUBLE) |
| 2266 | vtop->c.d = (double)vtop->c.f; | 2285 | vtop->c.d = (double)vtop->c.ld; |
| 2267 | else if (dbt == VT_DOUBLE && sbt == VT_LDOUBLE) | 2286 | else if (dbt == VT_LDOUBLE && sbt == VT_FLOAT) |
| 2268 | vtop->c.d = (double)vtop->c.ld; | 2287 | vtop->c.ld = (long double)vtop->c.f; |
| 2269 | else if (dbt == VT_LDOUBLE && sbt == VT_FLOAT) | 2288 | else if (dbt == VT_LDOUBLE && sbt == VT_DOUBLE) |
| 2270 | vtop->c.ld = (long double)vtop->c.f; | 2289 | vtop->c.ld = (long double)vtop->c.d; |
| 2271 | else if (dbt == VT_LDOUBLE && sbt == VT_DOUBLE) | 2290 | } else { |
| 2272 | vtop->c.ld = (long double)vtop->c.d; | 2291 | /* non constant case: generate code */ |
| 2273 | } else { | 2292 | gen_cvt_ftof(dbt); |
| 2274 | /* non constant case: generate code */ | 2293 | } |
| 2275 | gen_cvt_ftof(dbt); | 2294 | } else if (df) { |
| 2276 | } | 2295 | /* convert int to fp */ |
| 2277 | } else if (df) { | 2296 | /* XXX: add const cases */ |
| 2278 | /* convert int to fp */ | 2297 | st1 = vtop->t & (VT_BTYPE | VT_UNSIGNED); |
| 2279 | /* XXX: add const cases */ | 2298 | if (c) { |
| 2280 | st1 = vtop->t & (VT_BTYPE | VT_UNSIGNED); | 2299 | switch(st1) { |
| 2281 | if (c) { | 2300 | case VT_LLONG | VT_UNSIGNED: |
| 2282 | switch(st1) { | 2301 | case VT_LLONG: |
| 2283 | case VT_LLONG | VT_UNSIGNED: | 2302 | /* well, currently not needed */ |
| 2284 | case VT_LLONG: | 2303 | goto do_itof; |
| 2285 | /* well, currently not needed */ | 2304 | case VT_INT | VT_UNSIGNED: |
| 2286 | goto do_itof; | 2305 | switch(dbt) { |
| 2287 | case VT_INT | VT_UNSIGNED: | 2306 | case VT_FLOAT: vtop->c.f = (float)vtop->c.ui; break; |
| 2288 | switch(dbt) { | 2307 | case VT_DOUBLE: vtop->c.d = (double)vtop->c.ui; break; |
| 2289 | case VT_FLOAT: vtop->c.f = (float)vtop->c.ui; break; | 2308 | case VT_LDOUBLE: vtop->c.ld = (long double)vtop->c.ui; break; |
| 2290 | case VT_DOUBLE: vtop->c.d = (double)vtop->c.ui; break; | | |
| 2291 | case VT_LDOUBLE: vtop->c.ld = (long double)vtop->c.ui; break; | | |
| 2292 | } | | |
| 2293 | break; | | |
| 2294 | default: | | |
| 2295 | switch(dbt) { | | |
| 2296 | case VT_FLOAT: vtop->c.f = (float)vtop->c.i; break; | | |
| 2297 | case VT_DOUBLE: vtop->c.d = (double)vtop->c.i; break; | | |
| 2298 | case VT_LDOUBLE: vtop->c.ld = (long double)vtop->c.i; break; | | |
| 2299 | } | | |
| 2300 | break; | | |
| 2301 | } | 2309 | } |
| 2302 | } else { | 2310 | break; |
| 2303 | do_itof: | 2311 | default: |
| 2304 | gen_cvt_itof(dbt); | 2312 | switch(dbt) { |
| 2305 | } | 2313 | case VT_FLOAT: vtop->c.f = (float)vtop->c.i; break; |
| 2306 | } else if (sf) { | 2314 | case VT_DOUBLE: vtop->c.d = (double)vtop->c.i; break; |
| 2307 | /* convert fp to int */ | 2315 | case VT_LDOUBLE: vtop->c.ld = (long double)vtop->c.i; break; |
| 2308 | dt1 = t & (VT_BTYPE | VT_UNSIGNED); | | |
| 2309 | /* we handle char/short/etc... with generic code */ | | |
| 2310 | if (dt1 != VT_INT | VT_UNSIGNED && | | |
| 2311 | dt1 != VT_LLONG | VT_UNSIGNED && | | |
| 2312 | dt1 != VT_LLONG) | | |
| 2313 | dt1 = VT_INT; | | |
| 2314 | if (c) { | | |
| 2315 | switch(dt1) { | | |
| 2316 | case VT_LLONG | VT_UNSIGNED: | | |
| 2317 | case VT_LLONG: | | |
| 2318 | /* well, currently not needed */ | | |
| 2319 | goto do_ftoi; | | |
| 2320 | case VT_INT | VT_UNSIGNED: | | |
| 2321 | switch(sbt) { | | |
| 2322 | case VT_FLOAT: vtop->c.ui = (unsigned int)vtop->c.d; break; | | |
| 2323 | case VT_DOUBLE: vtop->c.ui = (unsigned int)vtop->c.d; break; | | |
| 2324 | case VT_LDOUBLE: vtop->c.ui = (unsigned int)vtop->c.d; break; | | |
| 2325 | } | | |
| 2326 | break; | | |
| 2327 | default: | | |
| 2328 | /* int case */ | | |
| 2329 | switch(sbt) { | | |
| 2330 | case VT_FLOAT: vtop->c.i = (int)vtop->c.d; break; | | |
| 2331 | case VT_DOUBLE: vtop->c.i = (int)vtop->c.d; break; | | |
| 2332 | case VT_LDOUBLE: vtop->c.i = (int)vtop->c.d; break; | | |
| 2333 | } | | |
| 2334 | break; | | |
| 2335 | } | 2316 | } |
| 2336 | } else { | 2317 | break; |
| 2337 | do_ftoi: | | |
| 2338 | gen_cvt_ftoi(dt1); | | |
| 2339 | } | | |
| 2340 | if (dt1 == VT_INT && (t & (VT_TYPE | VT_UNSIGNED)) != dt1) { | | |
| 2341 | /* additionnal cast for char/short/bool... */ | | |
| 2342 | vtop->t = (vtop->t & ~VT_TYPE) | dt1; | | |
| 2343 | gen_cast(t); | | |
| 2344 | } | 2318 | } |
| 2345 | } else if (dbt == VT_BOOL) { | 2319 | } else { |
| 2346 | vset(VT_CONST, 0); | 2320 | do_itof: |
| 2347 | gen_op(TOK_NE); | 2321 | gen_cvt_itof(dbt); |
| 2348 | } else if (dbt == VT_BYTE || dbt == VT_SHORT) { | 2322 | } |
| 2349 | if (dbt == VT_BYTE) | 2323 | } else if (sf) { |
| 2350 | bits = 8; | 2324 | /* convert fp to int */ |
| 2351 | else | 2325 | dt1 = t & (VT_BTYPE | VT_UNSIGNED); |
| 2352 | bits = 16; | 2326 | /* we handle char/short/etc... with generic code */ |
| 2353 | if (t & VT_UNSIGNED) { | 2327 | if (dt1 != VT_INT | VT_UNSIGNED && |
| 2354 | vset(VT_CONST, (1 << bits) - 1); | 2328 | dt1 != VT_LLONG | VT_UNSIGNED && |
| 2355 | gen_op('&'); | 2329 | dt1 != VT_LLONG) |
| 2356 | } else { | 2330 | dt1 = VT_INT; |
| 2357 | bits = 32 - bits; | 2331 | if (c) { |
| 2358 | vset(VT_CONST, bits); | 2332 | switch(dt1) { |
| 2359 | gen_op(TOK_SHL); | 2333 | case VT_LLONG | VT_UNSIGNED: |
| 2360 | vset(VT_CONST, bits); | 2334 | case VT_LLONG: |
| 2361 | gen_op(TOK_SAR); | 2335 | /* well, currently not needed */ |
| | 2336 | goto do_ftoi; |
| | 2337 | case VT_INT | VT_UNSIGNED: |
| | 2338 | switch(sbt) { |
| | 2339 | case VT_FLOAT: vtop->c.ui = (unsigned int)vtop->c.d; break; |
| | 2340 | case VT_DOUBLE: vtop->c.ui = (unsigned int)vtop->c.d; break; |
| | 2341 | case VT_LDOUBLE: vtop->c.ui = (unsigned int)vtop->c.d; break; |
| | 2342 | } |
| | 2343 | break; |
| | 2344 | default: |
| | 2345 | /* int case */ |
| | 2346 | switch(sbt) { |
| | 2347 | case VT_FLOAT: vtop->c.i = (int)vtop->c.d; break; |
| | 2348 | case VT_DOUBLE: vtop->c.i = (int)vtop->c.d; break; |
| | 2349 | case VT_LDOUBLE: vtop->c.i = (int)vtop->c.d; break; |
| | 2350 | } |
| | 2351 | break; |
| 2362 | } | 2352 | } |
| | 2353 | } else { |
| | 2354 | do_ftoi: |
| | 2355 | gen_cvt_ftoi(dt1); |
| | 2356 | } |
| | 2357 | if (dt1 == VT_INT && (t & (VT_TYPE | VT_UNSIGNED)) != dt1) { |
| | 2358 | /* additionnal cast for char/short/bool... */ |
| | 2359 | vtop->t = (vtop->t & ~VT_TYPE) | dt1; |
| | 2360 | gen_cast(t); |
| | 2361 | } |
| | 2362 | } else if (dbt == VT_BOOL) { |
| | 2363 | vpushi(0); |
| | 2364 | gen_op(TOK_NE); |
| | 2365 | } else if ((dbt == VT_BYTE || dbt == VT_SHORT) && |
| | 2366 | !(vtop->r & VT_LVAL)) { |
| | 2367 | /* no need to apply if lvalue because we do it while |
| | 2368 | loading the value */ |
| | 2369 | if (dbt == VT_BYTE) |
| | 2370 | bits = 8; |
| | 2371 | else |
| | 2372 | bits = 16; |
| | 2373 | if (t & VT_UNSIGNED) { |
| | 2374 | vpushi((1 << bits) - 1); |
| | 2375 | gen_op('&'); |
| | 2376 | } else { |
| | 2377 | bits = 32 - bits; |
| | 2378 | vpushi(bits); |
| | 2379 | gen_op(TOK_SHL); |
| | 2380 | vpushi(bits); |
| | 2381 | gen_op(TOK_SAR); |
| 2363 | } | 2382 | } |
| 2364 | } | 2383 | } |
| 2365 | } | 2384 | } |
| 2366 | vtop->t = (vtop->t & ~VT_TYPE) | t; | 2385 | vtop->t = t; |
| 2367 | } | 2386 | } |
| 2368 | | 2387 | |
| 2369 | /* return type size. Put alignment at 'a' */ | 2388 | /* return type size. Put alignment at 'a' */ |
| @@ -2599,7 +2618,7 @@ void gen_assign_cast(int dt) · 229 unmodified lines |
| 2599 | /* store vtop in lvalue pushed on stack */ | 2618 | /* store vtop in lvalue pushed on stack */ |
| 2600 | void vstore(void) | 2619 | void vstore(void) |
| 2601 | { | 2620 | { |
| 2602 | int ft, fc, r, t, size, align, bit_size, bit_pos; | 2621 | int ft, r, t, size, align, bit_size, bit_pos; |
| 2603 | GFuncContext gf; | 2622 | GFuncContext gf; |
| 2604 | | 2623 | |
| 2605 | ft = vtop[-1].t; | 2624 | ft = vtop[-1].t; |
| @@ -2614,18 +2633,20 @@ void vstore(void) · 8 unmodified lines |
| 2614 | gfunc_start(&gf); | 2633 | gfunc_start(&gf); |
| 2615 | /* type size */ | 2634 | /* type size */ |
| 2616 | size = type_size(vtop->t, &align); | 2635 | size = type_size(vtop->t, &align); |
| 2617 | vset(VT_CONST, size); | 2636 | vpushi(size); |
| 2618 | gfunc_param(&gf); | 2637 | gfunc_param(&gf); |
| 2619 | /* source */ | 2638 | /* source */ |
| 2620 | vtop->t &= ~VT_LVAL; | 2639 | vtop->t = VT_INT; |
| | 2640 | vtop->r &= ~VT_LVAL; |
| 2621 | gfunc_param(&gf); | 2641 | gfunc_param(&gf); |
| 2622 | /* destination */ | 2642 | /* destination */ |
| 2623 | vswap(); | 2643 | vswap(); |
| 2624 | vtop->t &= ~VT_LVAL; | 2644 | vtop->t = VT_INT; |
| | 2645 | vtop->r &= ~VT_LVAL; |
| 2625 | gfunc_param(&gf); | 2646 | gfunc_param(&gf); |
| 2626 | | 2647 | |
| 2627 | save_regs(); | 2648 | save_regs(); |
| 2628 | vset(VT_CONST, (int)&memcpy); | 2649 | vpushi((int)&memcpy); |
| 2629 | gfunc_call(&gf); | 2650 | gfunc_call(&gf); |
| 2630 | /* leave source on stack */ | 2651 | /* leave source on stack */ |
| 2631 | } else if (ft & VT_BITFIELD) { | 2652 | } else if (ft & VT_BITFIELD) { |
| @@ -2640,30 +2661,32 @@ void vstore(void) · 8 unmodified lines |
| 2640 | vtop[-1] = vtop[-2]; | 2661 | vtop[-1] = vtop[-2]; |
| 2641 | | 2662 | |
| 2642 | /* mask and shift source */ | 2663 | /* mask and shift source */ |
| 2643 | vset(VT_CONST, (1 << bit_size) - 1); | 2664 | vpushi((1 << bit_size) - 1); |
| 2644 | gen_op('&'); | 2665 | gen_op('&'); |
| 2645 | vset(VT_CONST, bit_pos); | 2666 | vpushi(bit_pos); |
| 2646 | gen_op(TOK_SHL); | 2667 | gen_op(TOK_SHL); |
| 2647 | /* load destination, mask and or with source */ | 2668 | /* load destination, mask and or with source */ |
| 2648 | vswap(); | 2669 | vswap(); |
| 2649 | vset(VT_CONST, ~(((1 << bit_size) - 1) << bit_pos)); | 2670 | vpushi(~(((1 << bit_size) - 1) << bit_pos)); |
| 2650 | gen_op('&'); | 2671 | gen_op('&'); |
| 2651 | gen_op('|'); | 2672 | gen_op('|'); |
| 2652 | /* store result */ | 2673 | /* store result */ |
| 2653 | vstore(); | 2674 | vstore(); |
| 2654 | } else { | 2675 | } else { |
| 2655 | r = gv(); /* generate value */ | 2676 | r = gv(); /* generate value */ |
| 2656 | ft = vtop[-1].t; | | |
| 2657 | fc = vtop[-1].c.i; | | |
| 2658 | /* if lvalue was saved on stack, must read it */ | 2677 | /* if lvalue was saved on stack, must read it */ |
| 2659 | if ((ft & VT_VALMASK) == VT_LLOCAL) { | 2678 | if ((vtop[-1].r & VT_VALMASK) == VT_LLOCAL) { |
| | 2679 | SValue sv; |
| 2660 | t = get_reg(REG_CLASS_INT); | 2680 | t = get_reg(REG_CLASS_INT); |
| 2661 | load(t, VT_LOCAL | VT_LVAL, fc); | 2681 | sv.t = VT_INT; |
| 2662 | ft = (ft & ~VT_VALMASK) | t; | 2682 | sv.r = VT_LOCAL | VT_LVAL; |
| | 2683 | sv.c.ul = vtop[-1].c.ul; |
| | 2684 | load(t, &sv); |
| | 2685 | vtop[-1].r = t | VT_LVAL; |
| 2663 | } | 2686 | } |
| 2664 | store(r, ft, fc); | 2687 | store(r, vtop - 1); |
| 2665 | vtop--; | 2688 | vtop--; |
| 2666 | vtop->t = (ft & VT_TYPE) | r; | 2689 | vtop->r = r; |
| 2667 | vtop->c.i = 0; | 2690 | vtop->c.i = 0; |
| 2668 | } | 2691 | } |
| 2669 | } | 2692 | } |
| @@ -2672,6 +2695,7 @@ void vstore(void) · 2 unmodified lines |
| 2672 | void inc(int post, int c) | 2695 | void inc(int post, int c) |
| 2673 | { | 2696 | { |
| 2674 | int r, r1; | 2697 | int r, r1; |
| | 2698 | SValue sv; |
| 2675 | | 2699 | |
| 2676 | test_lvalue(); | 2700 | test_lvalue(); |
| 2677 | if (post) | 2701 | if (post) |
| @@ -2682,13 +2706,16 @@ void inc(int post, int c) · 4 unmodified lines |
| 2682 | /* duplicate value */ | 2706 | /* duplicate value */ |
| 2683 | /* XXX: handle floats */ | 2707 | /* XXX: handle floats */ |
| 2684 | r1 = get_reg(REG_CLASS_INT); | 2708 | r1 = get_reg(REG_CLASS_INT); |
| 2685 | load(r1, r, 0); /* move r to r1 */ | 2709 | sv.t = VT_INT; |
| | 2710 | sv.r = r; |
| | 2711 | sv.c.ul = 0; |
| | 2712 | load(r1, &sv); /* move r to r1 */ |
| 2686 | /* duplicates value */ | 2713 | /* duplicates value */ |
| 2687 | vtop[-2].t = (vtop->t & VT_TYPE) | r1; | 2714 | vtop[-2].r = r1; |
| 2688 | vtop[-2].c.i = 0; | 2715 | vtop[-2].c.i = 0; |
| 2689 | } | 2716 | } |
| 2690 | /* add constant */ | 2717 | /* add constant */ |
| 2691 | vset(VT_CONST, c - TOK_MID); | 2718 | vpushi(c - TOK_MID); |
| 2692 | gen_op('+'); | 2719 | gen_op('+'); |
| 2693 | vstore(); /* store value */ | 2720 | vstore(); /* store value */ |
| 2694 | if (post) | 2721 | if (post) |
| @@ -3107,13 +3134,13 @@ Sym *external_sym(int v, int u) · 412 unmodified lines |
| 3107 | | 3134 | |
| 3108 | void indir(void) | 3135 | void indir(void) |
| 3109 | { | 3136 | { |
| 3110 | if (vtop->t & VT_LVAL) | 3137 | if (vtop->r & VT_LVAL) |
| 3111 | gv(); | 3138 | gv(); |
| 3112 | if ((vtop->t & VT_BTYPE) != VT_PTR) | 3139 | if ((vtop->t & VT_BTYPE) != VT_PTR) |
| 3113 | expect("pointer"); | 3140 | expect("pointer"); |
| 3114 | vtop->t = pointed_type(vtop->t); | 3141 | vtop->t = pointed_type(vtop->t); |
| 3115 | if (!(vtop->t & VT_ARRAY)) /* an array is never an lvalue */ | 3142 | if (!(vtop->t & VT_ARRAY)) /* an array is never an lvalue */ |
| 3116 | vtop->t |= VT_LVAL; | 3143 | vtop->r |= VT_LVAL; |
| 3117 | } | 3144 | } |
| 3118 | | 3145 | |
| 3119 | /* pass a parameter to a function and do type checking and casting */ | 3146 | /* pass a parameter to a function and do type checking and casting */ |
| @@ -3141,21 +3168,21 @@ void unary(void) · 21 unmodified lines |
| 3141 | GFuncContext gf; | 3168 | GFuncContext gf; |
| 3142 | | 3169 | |
| 3143 | if (tok == TOK_NUM || tok == TOK_CCHAR || tok == TOK_LCHAR) { | 3170 | if (tok == TOK_NUM || tok == TOK_CCHAR || tok == TOK_LCHAR) { |
| 3144 | vset(VT_CONST | VT_INT, tokc.i); | 3171 | vpushi(tokc.i); |
| 3145 | next(); | 3172 | next(); |
| 3146 | } else if (tok == TOK_CFLOAT) { | 3173 | } else if (tok == TOK_CFLOAT) { |
| 3147 | vsetc(VT_CONST | VT_FLOAT, &tokc); | 3174 | vsetc(VT_FLOAT, VT_CONST, &tokc); |
| 3148 | next(); | 3175 | next(); |
| 3149 | } else if (tok == TOK_CDOUBLE) { | 3176 | } else if (tok == TOK_CDOUBLE) { |
| 3150 | vsetc(VT_CONST | VT_DOUBLE, &tokc); | 3177 | vsetc(VT_DOUBLE, VT_CONST, &tokc); |
| 3151 | next(); | 3178 | next(); |
| 3152 | } else if (tok == TOK_CLDOUBLE) { | 3179 | } else if (tok == TOK_CLDOUBLE) { |
| 3153 | vsetc(VT_CONST | VT_LDOUBLE, &tokc); | 3180 | vsetc(VT_LDOUBLE, VT_CONST, &tokc); |
| 3154 | next(); | 3181 | next(); |
| 3155 | } else if (tok == TOK___FUNC__) { | 3182 | } else if (tok == TOK___FUNC__) { |
| 3156 | /* special function name identifier */ | 3183 | /* special function name identifier */ |
| 3157 | /* generate (char *) type */ | 3184 | /* generate (char *) type */ |
| 3158 | vset(VT_CONST | mk_pointer(VT_BYTE), glo); | 3185 | vset(mk_pointer(VT_BYTE), VT_CONST, glo); |
| 3159 | strcpy((void *)glo, funcname); | 3186 | strcpy((void *)glo, funcname); |
| 3160 | glo += strlen(funcname) + 1; | 3187 | glo += strlen(funcname) + 1; |
| 3161 | next(); | 3188 | next(); |
| @@ -3174,7 +3201,7 @@ void unary(void) · 12 unmodified lines |
| 3174 | decl_initializer(t, glo, 1, 0); | 3201 | decl_initializer(t, glo, 1, 0); |
| 3175 | glo += type_size(t, &align); | 3202 | glo += type_size(t, &align); |
| 3176 | /* put it as pointer */ | 3203 | /* put it as pointer */ |
| 3177 | vset(t & ~VT_ARRAY, fc); | 3204 | vset(t & ~VT_ARRAY, VT_CONST, fc); |
| 3178 | } else { | 3205 | } else { |
| 3179 | t = tok; | 3206 | t = tok; |
| 3180 | next(); | 3207 | next(); |
| @@ -3194,7 +3221,7 @@ void unary(void) · 13 unmodified lines |
| 3194 | if (!(ft & VT_ARRAY)) | 3221 | if (!(ft & VT_ARRAY)) |
| 3195 | ft |= VT_LVAL; | 3222 | ft |= VT_LVAL; |
| 3196 | fc = decl_initializer_alloc(ft, 1); | 3223 | fc = decl_initializer_alloc(ft, 1); |
| 3197 | vset(ft, fc); | 3224 | vset(ft & VT_TYPE, ft & (VT_VALMASK | VT_LVAL), fc); |
| 3198 | } else { | 3225 | } else { |
| 3199 | unary(); | 3226 | unary(); |
| 3200 | gen_cast(ft); | 3227 | gen_cast(ft); |
| @@ -3214,20 +3241,21 @@ void unary(void) · 13 unmodified lines |
| 3214 | there and in function calls. */ | 3241 | there and in function calls. */ |
| 3215 | if ((vtop->t & VT_BTYPE) != VT_FUNC) | 3242 | if ((vtop->t & VT_BTYPE) != VT_FUNC) |
| 3216 | test_lvalue(); | 3243 | test_lvalue(); |
| 3217 | vtop->t = mk_pointer(vtop->t & VT_LVALN); | 3244 | vtop->t = mk_pointer(vtop->t); |
| | 3245 | vtop->r &= ~VT_LVAL; |
| 3218 | } else | 3246 | } else |
| 3219 | if (t == '!') { | 3247 | if (t == '!') { |
| 3220 | unary(); | 3248 | unary(); |
| 3221 | if ((vtop->t & (VT_VALMASK | VT_LVAL)) == VT_CONST) | 3249 | if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) |
| 3222 | vtop->c.i = !vtop->c.i; | 3250 | vtop->c.i = !vtop->c.i; |
| 3223 | else if ((vtop->t & VT_VALMASK) == VT_CMP) | 3251 | else if ((vtop->r & VT_VALMASK) == VT_CMP) |
| 3224 | vtop->c.i = vtop->c.i ^ 1; | 3252 | vtop->c.i = vtop->c.i ^ 1; |
| 3225 | else | 3253 | else |
| 3226 | vset(VT_JMP, gtst(1, 0)); | 3254 | vset(VT_INT, VT_JMP, gtst(1, 0)); |
| 3227 | } else | 3255 | } else |
| 3228 | if (t == '~') { | 3256 | if (t == '~') { |
| 3229 | unary(); | 3257 | unary(); |
| 3230 | vset(VT_CONST, -1); | 3258 | vpushi(-1); |
| 3231 | gen_op('^'); | 3259 | gen_op('^'); |
| 3232 | } else | 3260 | } else |
| 3233 | if (t == '+') { | 3261 | if (t == '+') { |
| @@ -3251,13 +3279,13 @@ void unary(void) · 17 unmodified lines |
| 3251 | t = vtop->t; | 3279 | t = vtop->t; |
| 3252 | vpop(); | 3280 | vpop(); |
| 3253 | } | 3281 | } |
| 3254 | vset(VT_CONST, type_size(t, &t)); | 3282 | vpushi(type_size(t, &t)); |
| 3255 | } else | 3283 | } else |
| 3256 | if (t == TOK_INC || t == TOK_DEC) { | 3284 | if (t == TOK_INC || t == TOK_DEC) { |
| 3257 | unary(); | 3285 | unary(); |
| 3258 | inc(0, t); | 3286 | inc(0, t); |
| 3259 | } else if (t == '-') { | 3287 | } else if (t == '-') { |
| 3260 | vset(VT_CONST, 0); | 3288 | vpushi(0); |
| 3261 | unary(); | 3289 | unary(); |
| 3262 | gen_op('-'); | 3290 | gen_op('-'); |
| 3263 | } else | 3291 | } else |
| @@ -3273,9 +3301,10 @@ void unary(void) · 9 unmodified lines |
| 3273 | /* int() function */ | 3301 | /* int() function */ |
| 3274 | s = external_sym(t, VT_FUNC | (p << VT_STRUCT_SHIFT)); | 3302 | s = external_sym(t, VT_FUNC | (p << VT_STRUCT_SHIFT)); |
| 3275 | } | 3303 | } |
| 3276 | vset(s->t, s->c); | 3304 | vset(s->t & VT_TYPE, |
| | 3305 | s->t & (VT_VALMASK | VT_LVAL | VT_FORWARD), s->c); |
| 3277 | /* if forward reference, we must point to s */ | 3306 | /* if forward reference, we must point to s */ |
| 3278 | if (vtop->t & VT_FORWARD) | 3307 | if (vtop->r & VT_FORWARD) |
| 3279 | vtop->c.sym = s; | 3308 | vtop->c.sym = s; |
| 3280 | } | 3309 | } |
| 3281 | } | 3310 | } |
| @@ -3290,7 +3319,7 @@ void unary(void) · 8 unmodified lines |
| 3290 | if (tok == TOK_ARROW) | 3319 | if (tok == TOK_ARROW) |
| 3291 | indir(); | 3320 | indir(); |
| 3292 | test_lvalue(); | 3321 | test_lvalue(); |
| 3293 | vtop->t &= VT_LVALN; | 3322 | vtop->r &= ~VT_LVAL; |
| 3294 | next(); | 3323 | next(); |
| 3295 | /* expect pointer on structure */ | 3324 | /* expect pointer on structure */ |
| 3296 | if ((vtop->t & VT_BTYPE) != VT_STRUCT) | 3325 | if ((vtop->t & VT_BTYPE) != VT_STRUCT) |
| @@ -3305,14 +3334,14 @@ void unary(void) · 8 unmodified lines |
| 3305 | if (!s) | 3334 | if (!s) |
| 3306 | error("field not found"); | 3335 | error("field not found"); |
| 3307 | /* add field offset to pointer */ | 3336 | /* add field offset to pointer */ |
| 3308 | vtop->t = (vtop->t & ~VT_TYPE) | VT_INT; /* change type to int */ | 3337 | vtop->t = VT_INT; /* change type to int */ |
| 3309 | vset(VT_CONST, s->c); | 3338 | vpushi(s->c); |
| 3310 | gen_op('+'); | 3339 | gen_op('+'); |
| 3311 | /* change type to field type, and set to lvalue */ | 3340 | /* change type to field type, and set to lvalue */ |
| 3312 | vtop->t = (vtop->t & ~VT_TYPE) | s->t; | 3341 | vtop->t = s->t; |
| 3313 | /* an array is never an lvalue */ | 3342 | /* an array is never an lvalue */ |
| 3314 | if (!(vtop->t & VT_ARRAY)) | 3343 | if (!(vtop->t & VT_ARRAY)) |
| 3315 | vtop->t |= VT_LVAL; | 3344 | vtop->r |= VT_LVAL; |
| 3316 | next(); | 3345 | next(); |
| 3317 | } else if (tok == '[') { | 3346 | } else if (tok == '[') { |
| 3318 | next(); | 3347 | next(); |
| @@ -3321,8 +3350,7 @@ void unary(void) · 2 unmodified lines |
| 3321 | indir(); | 3350 | indir(); |
| 3322 | skip(']'); | 3351 | skip(']'); |
| 3323 | } else if (tok == '(') { | 3352 | } else if (tok == '(') { |
| 3324 | int rett; | 3353 | SValue ret; |
| 3325 | CValue retc; | | |
| 3326 | Sym *sa; | 3354 | Sym *sa; |
| 3327 | | 3355 | |
| 3328 | /* function call */ | 3356 | /* function call */ |
| @@ -3337,7 +3365,7 @@ void unary(void) · 8 unmodified lines |
| 3337 | expect("function pointer"); | 3365 | expect("function pointer"); |
| 3338 | } | 3366 | } |
| 3339 | } else { | 3367 | } else { |
| 3340 | vtop->t &= ~VT_LVAL; /* no lvalue */ | 3368 | vtop->r &= ~VT_LVAL; /* no lvalue */ |
| 3341 | } | 3369 | } |
| 3342 | /* get return type */ | 3370 | /* get return type */ |
| 3343 | s = sym_find((unsigned)vtop->t >> VT_STRUCT_SHIFT); | 3371 | s = sym_find((unsigned)vtop->t >> VT_STRUCT_SHIFT); |
| @@ -3403,15 +3431,17 @@ void unary(void) · 59 unmodified lines |
| 3403 | /* get some space for the returned structure */ | 3431 | /* get some space for the returned structure */ |
| 3404 | size = type_size(s->t, &align); | 3432 | size = type_size(s->t, &align); |
| 3405 | loc = (loc - size) & -align; | 3433 | loc = (loc - size) & -align; |
| 3406 | rett = s->t | VT_LOCAL | VT_LVAL; | 3434 | ret.t = s->t; |
| | 3435 | ret.r = VT_LOCAL | VT_LVAL; |
| 3407 | /* pass it as 'int' to avoid structure arg passing | 3436 | /* pass it as 'int' to avoid structure arg passing |
| 3408 | problems */ | 3437 | problems */ |
| 3409 | vset(VT_INT | VT_LOCAL, loc); | 3438 | vset(VT_INT, VT_LOCAL, loc); |
| 3410 | retc = vtop->c; | 3439 | ret.c = vtop->c; |
| 3411 | gfunc_param(&gf); | 3440 | gfunc_param(&gf); |
| 3412 | } else { | 3441 | } else { |
| 3413 | rett = s->t | FUNC_RET_REG; /* return in register */ | 3442 | ret.t = s->t; |
| 3414 | retc.i = 0; | 3443 | ret.r = FUNC_RET_REG; /* return in register */ |
| | 3444 | ret.c.i = 0; |
| 3415 | } | 3445 | } |
| 3416 | #ifndef INVERT_FUNC_PARAMS | 3446 | #ifndef INVERT_FUNC_PARAMS |
| 3417 | while (tok != ')') { | 3447 | while (tok != ')') { |
| @@ -3428,7 +3458,7 @@ void unary(void) · 10 unmodified lines |
| 3428 | skip(')'); | 3458 | skip(')'); |
| 3429 | gfunc_call(&gf); | 3459 | gfunc_call(&gf); |
| 3430 | /* return value */ | 3460 | /* return value */ |
| 3431 | vsetc(rett, &retc); | 3461 | vsetc(ret.t, ret.r, &ret.c); |
| 3432 | } else { | 3462 | } else { |
| 3433 | break; | 3463 | break; |
| 3434 | } | 3464 | } |
| @@ -3496,7 +3526,7 @@ void eand(void) · 61 unmodified lines |
| 3496 | if (tok != TOK_LAND) { | 3526 | if (tok != TOK_LAND) { |
| 3497 | if (t) { | 3527 | if (t) { |
| 3498 | t = gtst(1, t); | 3528 | t = gtst(1, t); |
| 3499 | vset(VT_JMPI, t); | 3529 | vset(VT_INT, VT_JMPI, t); |
| 3500 | } | 3530 | } |
| 3501 | break; | 3531 | break; |
| 3502 | } | 3532 | } |
| @@ -3516,7 +3546,7 @@ void eor(void) · 13 unmodified lines |
| 3516 | if (tok != TOK_LOR) { | 3546 | if (tok != TOK_LOR) { |
| 3517 | if (t) { | 3547 | if (t) { |
| 3518 | t = gtst(0, t); | 3548 | t = gtst(0, t); |
| 3519 | vset(VT_JMP, t); | 3549 | vset(VT_INT, VT_JMP, t); |
| 3520 | } | 3550 | } |
| 3521 | break; | 3551 | break; |
| 3522 | } | 3552 | } |
| @@ -3561,7 +3591,7 @@ void expr_eq(void) · 38 unmodified lines |
| 3561 | expr_eq(); | 3591 | expr_eq(); |
| 3562 | r2 = gv(); | 3592 | r2 = gv(); |
| 3563 | move_reg(r1, r2); | 3593 | move_reg(r1, r2); |
| 3564 | vtop->t = (vtop->t & VT_TYPE) | r1; | 3594 | vtop->r = r1; |
| 3565 | gsym(u); | 3595 | gsym(u); |
| 3566 | } | 3596 | } |
| 3567 | } | 3597 | } |
| @@ -3585,7 +3615,7 @@ void expr_const1(void) · 17 unmodified lines |
| 3585 | a = const_wanted; | 3615 | a = const_wanted; |
| 3586 | const_wanted = 1; | 3616 | const_wanted = 1; |
| 3587 | expr_eq(); | 3617 | expr_eq(); |
| 3588 | if ((vtop->t & (VT_CONST | VT_LVAL)) != VT_CONST) | 3618 | if ((vtop->r & (VT_VALMASK | VT_LVAL)) != VT_CONST) |
| 3589 | expect("constant"); | 3619 | expect("constant"); |
| 3590 | const_wanted = a; | 3620 | const_wanted = a; |
| 3591 | } | 3621 | } |
| @@ -3680,7 +3710,7 @@ void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg) · 88 unmodified lines |
| 3680 | if ((func_vt & VT_BTYPE) == VT_STRUCT) { | 3710 | if ((func_vt & VT_BTYPE) == VT_STRUCT) { |
| 3681 | /* if returning structure, must copy it to implicit | 3711 | /* if returning structure, must copy it to implicit |
| 3682 | first pointer arg location */ | 3712 | first pointer arg location */ |
| 3683 | vset(mk_pointer(func_vt) | VT_LOCAL | VT_LVAL, func_vc); | 3713 | vset(mk_pointer(func_vt), VT_LOCAL | VT_LVAL, func_vc); |
| 3684 | indir(); | 3714 | indir(); |
| 3685 | vswap(); | 3715 | vswap(); |
| 3686 | /* copy structure value to pointer */ | 3716 | /* copy structure value to pointer */ |
| @@ -3785,8 +3815,8 @@ void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg) · 98 unmodified lines |
| 3785 | /* since a case is like a label, we must skip it with a jmp */ | 3815 | /* since a case is like a label, we must skip it with a jmp */ |
| 3786 | b = gjmp(0); | 3816 | b = gjmp(0); |
| 3787 | gsym(*case_sym); | 3817 | gsym(*case_sym); |
| 3788 | vset(case_reg, 0); | 3818 | vset(VT_INT, case_reg, 0); |
| 3789 | vset(VT_CONST, a); | 3819 | vpushi(a); |
| 3790 | gen_op(TOK_EQ); | 3820 | gen_op(TOK_EQ); |
| 3791 | *case_sym = gtst(1, 0); | 3821 | *case_sym = gtst(1, 0); |
| 3792 | gsym(b); | 3822 | gsym(b); |
| @@ -3936,7 +3966,7 @@ void init_putv(int t, int c, int v, int is_expr) · 143 unmodified lines |
| 3936 | expr_const1(); | 3966 | expr_const1(); |
| 3937 | global_expr = saved_global_expr; | 3967 | global_expr = saved_global_expr; |
| 3938 | } else { | 3968 | } else { |
| 3939 | vset(VT_CONST | VT_INT, v); | 3969 | vpushi(v); |
| 3940 | } | 3970 | } |
| 3941 | /* XXX: do casting */ | 3971 | /* XXX: do casting */ |
| 3942 | /* XXX: not portable */ | 3972 | /* XXX: not portable */ |
| @@ -3965,11 +3995,11 @@ void init_putv(int t, int c, int v, int is_expr) · 22 unmodified lines |
| 3965 | } | 3995 | } |
| 3966 | vpop(); | 3996 | vpop(); |
| 3967 | } else { | 3997 | } else { |
| 3968 | vset(t, c); | 3998 | vset(t & VT_TYPE, t & (VT_VALMASK | VT_LVAL | VT_FORWARD), c); |
| 3969 | if (is_expr) | 3999 | if (is_expr) |
| 3970 | expr_eq(); | 4000 | expr_eq(); |
| 3971 | else | 4001 | else |
| 3972 | vset(VT_CONST | VT_INT, v); | 4002 | vpushi(v); |
| 3973 | vstore(); | 4003 | vstore(); |
| 3974 | vpop(); | 4004 | vpop(); |
| 3975 | } | 4005 | } |
| @@ -3984,13 +4014,13 @@ void init_putz(int t, int c, int size) · 8 unmodified lines |
| 3984 | /* nothing to do because global are already set to zero */ | 4014 | /* nothing to do because global are already set to zero */ |
| 3985 | } else { | 4015 | } else { |
| 3986 | gfunc_start(&gf); | 4016 | gfunc_start(&gf); |
| 3987 | vset(VT_CONST, size); | 4017 | vpushi(size); |
| 3988 | gfunc_param(&gf); | 4018 | gfunc_param(&gf); |
| 3989 | vset(VT_CONST, 0); | 4019 | vpushi(0); |
| 3990 | gfunc_param(&gf); | 4020 | gfunc_param(&gf); |
| 3991 | vset(VT_LOCAL, c); | 4021 | vset(VT_INT, VT_LOCAL, c); |
| 3992 | gfunc_param(&gf); | 4022 | gfunc_param(&gf); |
| 3993 | vset(VT_CONST, (int)&memset); | 4023 | vpushi((int)&memset); |
| 3994 | gfunc_call(&gf); | 4024 | gfunc_call(&gf); |
| 3995 | } | 4025 | } |
| 3996 | } | 4026 | } |