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