Commit 781b2a25 authored by Anthony Martin's avatar Anthony Martin

cmd/cc: support 21-bit runes in wide string constants

Changeset 7557a627e9b5 added a temporary stop-gap to silence
a print format warning for %S. This has been reverted.

None of this code is original. It was copied from the latest
Plan 9 compilers.

R=golang-dev, r, rsc
CC=golang-dev
https://golang.org/cl/8630044
parent acd887ba
......@@ -55,6 +55,8 @@ typedef struct Bits Bits;
typedef struct Dynimp Dynimp;
typedef struct Dynexp Dynexp;
typedef Rune TRune; /* target system type */
#define BUFSIZ 8192
#define NSYMB 500
#define NHASH 1024
......@@ -85,7 +87,7 @@ struct Node
double fconst; /* fp constant */
vlong vconst; /* non fp const */
char* cstring; /* character string */
ushort* rstring; /* rune string */
TRune* rstring; /* rune string */
Sym* sym;
Type* type;
......@@ -367,6 +369,9 @@ enum
TFILE,
TOLD,
NALLTYPES,
/* adapt size of Rune to target system's size */
TRUNE = sizeof(TRune)==4? TUINT: TUSHORT,
};
enum
{
......@@ -766,7 +771,7 @@ void gclean(void);
void gextern(Sym*, Node*, int32, int32);
void ginit(void);
int32 outstring(char*, int32);
int32 outlstring(ushort*, int32);
int32 outlstring(TRune*, int32);
void sextern(Sym*, Node*, int32, int32);
void xcom(Node*);
int32 exreg(Type*);
......@@ -800,7 +805,6 @@ int machcap(Node*);
#pragma varargck type "Q" int32
#pragma varargck type "O" int
#pragma varargck type "O" uint
#pragma varargck type "S" ushort*
#pragma varargck type "T" Type*
#pragma varargck type "U" char*
#pragma varargck type "|" int
......
......@@ -891,9 +891,9 @@ lstring:
LLSTRING
{
$$ = new(OLSTRING, Z, Z);
$$->type = typ(TARRAY, types[TUSHORT]);
$$->type->width = $1.l + sizeof(ushort);
$$->rstring = (ushort*)$1.s;
$$->type = typ(TARRAY, types[TRUNE]);
$$->type->width = $1.l + sizeof(TRune);
$$->rstring = (TRune*)$1.s;
$$->sym = symstring;
$$->etype = TARRAY;
$$->class = CSTATIC;
......@@ -903,16 +903,16 @@ lstring:
char *s;
int n;
n = $1->type->width - sizeof(ushort);
n = $1->type->width - sizeof(TRune);
s = alloc(n+$2.l+MAXALIGN);
memcpy(s, $1->rstring, n);
memcpy(s+n, $2.s, $2.l);
*(ushort*)(s+n+$2.l) = 0;
*(TRune*)(s+n+$2.l) = 0;
$$ = $1;
$$->type->width += $2.l;
$$->rstring = (ushort*)s;
$$->rstring = (TRune*)s;
}
zelist:
......
......@@ -87,6 +87,7 @@ tcomo(Node *n, int f)
Node *l, *r;
Type *t;
int o;
static TRune zer;
if(n == Z) {
diag(Z, "Z in tcom");
......@@ -651,12 +652,10 @@ tcomo(Node *n, int f)
break;
case OLSTRING:
if(n->type->link != types[TUSHORT]) {
if(n->type->link != types[TRUNE]) {
o = outstring(0, 0);
while(o & 3) {
ushort a[1];
a[0] = 0;
outlstring(a, sizeof(ushort));
outlstring(&zer, sizeof(TRune));
o = outlstring(0, 0);
}
}
......
......@@ -268,7 +268,7 @@ nextinit(void)
a->cstring++;
}
if(a->op == OLSTRING) {
b->vconst = convvtox(*a->rstring, TUSHORT);
b->vconst = convvtox(*a->rstring, TRUNE);
a->rstring++;
}
a->type->width -= b->type->width;
......
......@@ -533,7 +533,7 @@ l1:
yyerror("missing '");
peekc = c1;
}
yylval.vval = convvtox(c, TUSHORT);
yylval.vval = convvtox(c, TRUNE);
return LUCONST;
}
if(c == '"') {
......@@ -607,15 +607,15 @@ l1:
c = escchar('"', 1, 0);
if(c == EOF)
break;
cp = allocn(cp, c1, sizeof(ushort));
*(ushort*)(cp + c1) = c;
c1 += sizeof(ushort);
cp = allocn(cp, c1, sizeof(TRune));
*(TRune*)(cp + c1) = c;
c1 += sizeof(TRune);
}
yylval.sval.l = c1;
do {
cp = allocn(cp, c1, sizeof(ushort));
*(ushort*)(cp + c1) = 0;
c1 += sizeof(ushort);
cp = allocn(cp, c1, sizeof(TRune));
*(TRune*)(cp + c1) = 0;
c1 += sizeof(TRune);
} while(c1 & MAXALIGN);
yylval.sval.s = cp;
return LLSTRING;
......@@ -1093,7 +1093,7 @@ getnsc(void)
} else
c = GETC();
for(;;) {
if(!isspace(c))
if(c >= Runeself || !isspace(c))
return c;
if(c == '\n') {
lineno++;
......@@ -1137,7 +1137,7 @@ loop:
*/
i = 2;
if(longflg)
i = 4;
i = 6;
l = 0;
for(; i>0; i--) {
c = getc();
......@@ -1167,7 +1167,7 @@ loop:
*/
i = 2;
if(longflg)
i = 5;
i = 8;
l = c - '0';
for(; i>0; i--) {
c = getc();
......
......@@ -102,28 +102,29 @@ newcase(void)
}
int32
outlstring(ushort *s, int32 n)
outlstring(TRune *s, int32 n)
{
char buf[2];
int c;
char buf[sizeof(TRune)];
uint c;
int i;
int32 r;
if(suppress)
return nstring;
while(nstring & 1)
while(nstring & (sizeof(TRune)-1))
outstring("", 1);
r = nstring;
while(n > 0) {
c = *s++;
if(align(0, types[TCHAR], Aarg1, nil)) {
buf[0] = c>>8;
buf[1] = c;
for(i = 0; i < sizeof(TRune); i++)
buf[i] = c>>(8*(sizeof(TRune) - i - 1));
} else {
buf[0] = c;
buf[1] = c>>8;
for(i = 0; i < sizeof(TRune); i++)
buf[i] = c>>(8*i);
}
outstring(buf, 2);
n -= sizeof(ushort);
outstring(buf, sizeof(TRune));
n -= sizeof(TRune);
}
return r;
}
......
......@@ -116,7 +116,10 @@ prtree1(Node *n, int d, int f)
break;
case OLSTRING:
print(" \"%S\"", n->rstring);
if(sizeof(TRune) == sizeof(Rune))
print(" \"%S\"", (Rune*)n->rstring);
else
print(" \"...\"");
i = 0;
break;
......
This diff is collapsed.
/* A Bison parser, made by GNU Bison 2.3. */
/* A Bison parser, made by GNU Bison 2.7.12-4996. */
/* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
This program 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, or (at your option)
any later version.
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
......@@ -29,10 +26,20 @@
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_YY_Y_TAB_H_INCLUDED
# define YY_YY_Y_TAB_H_INCLUDED
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
......@@ -189,11 +196,12 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
#line 36 "cc.y"
{
/* Line 2053 of yacc.c */
#line 36 "cc.y"
Node* node;
Sym* sym;
Type* type;
......@@ -217,14 +225,30 @@ typedef union YYSTYPE
int32 lval;
double dval;
vlong vval;
}
/* Line 1529 of yacc.c. */
#line 223 "y.tab.h"
YYSTYPE;
/* Line 2053 of yacc.c */
#line 232 "y.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif
extern YYSTYPE yylval;
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int yyparse (void *YYPARSE_PARAM);
#else
int yyparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int yyparse (void);
#else
int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */
#endif /* !YY_YY_Y_TAB_H_INCLUDED */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment