Commit ebce7944 authored by Russ Cox's avatar Russ Cox

build: annotations and modifications for c2go

The main changes fall into a few patterns:

1. Replace #define with enum.

2. Add /*c2go */ comment giving effect of #define.
This is necessary for function-like #defines and
non-enum-able #defined constants.
(Not all compilers handle negative or large enums.)

3. Add extra braces in struct initializer.
(c2go does not implement the full rules.)

This is enough to let c2go typecheck the source tree.
There may be more changes once it is doing
other semantic analyses.

LGTM=minux, iant
R=minux, dave, iant
CC=golang-codereviews
https://golang.org/cl/106860045
parent 4fedb59a
...@@ -129,6 +129,14 @@ int Bungetc(Biobuf*); ...@@ -129,6 +129,14 @@ int Bungetc(Biobuf*);
int Bungetrune(Biobuf*); int Bungetrune(Biobuf*);
long Bwrite(Biobuf*, void*, long); long Bwrite(Biobuf*, void*, long);
int Bvprint(Biobuf*, char*, va_list); int Bvprint(Biobuf*, char*, va_list);
/*c2go
int BGETC(Biobuf*);
int BGETLE2(Biobuf*);
int BGETLE4(Biobuf*);
int BPUTC(Biobuf*, int);
int BPUTLE2(Biobuf*, int);
int BPUTLE4(Biobuf*, int);
*/
#if defined(__cplusplus) #if defined(__cplusplus)
} }
......
...@@ -112,6 +112,8 @@ struct Prog ...@@ -112,6 +112,8 @@ struct Prog
char width; /* fake for DATA */ char width; /* fake for DATA */
char mode; /* 16, 32, or 64 in 6l, 8l; internal use in 5g, 6g, 8g */ char mode; /* 16, 32, or 64 in 6l, 8l; internal use in 5g, 6g, 8g */
/*c2go uchar TEXTFLAG; */
}; };
// prevent incompatible type signatures between liblink and 8l on Plan 9 // prevent incompatible type signatures between liblink and 8l on Plan 9
...@@ -167,7 +169,7 @@ struct LSym ...@@ -167,7 +169,7 @@ struct LSym
// SDATA, SBSS // SDATA, SBSS
uchar* p; uchar* p;
int32 np; int np;
int32 maxp; int32 maxp;
Reloc* r; Reloc* r;
int32 nr; int32 nr;
......
...@@ -23,10 +23,10 @@ vlong MAXWIDTH = (1LL<<32) - 1; ...@@ -23,10 +23,10 @@ vlong MAXWIDTH = (1LL<<32) - 1;
*/ */
Typedef typedefs[] = Typedef typedefs[] =
{ {
"int", TINT, TINT32, {"int", TINT, TINT32},
"uint", TUINT, TUINT32, {"uint", TUINT, TUINT32},
"uintptr", TUINTPTR, TUINT32, {"uintptr", TUINTPTR, TUINT32},
0 {0}
}; };
void void
......
...@@ -11,10 +11,13 @@ ...@@ -11,10 +11,13 @@
#define TEXTFLAG reg #define TEXTFLAG reg
#define REGALLOC_R0 0 enum
#define REGALLOC_RMAX REGEXT {
#define REGALLOC_F0 NREG REGALLOC_R0 = 0,
#define REGALLOC_FMAX (REGALLOC_F0 + FREGEXT) REGALLOC_RMAX = REGEXT,
REGALLOC_F0 = NREG,
REGALLOC_FMAX = REGALLOC_F0 + FREGEXT,
};
EXTERN int32 dynloc; EXTERN int32 dynloc;
EXTERN uchar reg[REGALLOC_FMAX+1]; EXTERN uchar reg[REGALLOC_FMAX+1];
......
...@@ -636,6 +636,7 @@ splitclean(void) ...@@ -636,6 +636,7 @@ splitclean(void)
} }
#define CASE(a,b) (((a)<<16)|((b)<<0)) #define CASE(a,b) (((a)<<16)|((b)<<0))
/*c2go int CASE(int, int); */
void void
gmove(Node *f, Node *t) gmove(Node *f, Node *t)
......
...@@ -49,6 +49,24 @@ ...@@ -49,6 +49,24 @@
typedef struct Reg Reg; typedef struct Reg Reg;
typedef struct Rgn Rgn; typedef struct Rgn Rgn;
/*c2go
extern Node *Z;
enum
{
D_HI = D_NONE,
D_LO = D_NONE,
CLOAD = 5,
CREF = 5,
CINF = 1000,
LOOP = 3,
};
uint32 BLOAD(Reg*);
uint32 BSTORE(Reg*);
uint32 LOAD(Reg*);
uint32 STORE(Reg*);
*/
// A Reg is a wrapper around a single Prog (one instruction) that holds // A Reg is a wrapper around a single Prog (one instruction) that holds
// register optimization information while the optimizer runs. // register optimization information while the optimizer runs.
// r->prog is the instruction. // r->prog is the instruction.
...@@ -71,8 +89,10 @@ struct Reg ...@@ -71,8 +89,10 @@ struct Reg
int32 regu; // register used bitmap int32 regu; // register used bitmap
}; };
#define R ((Reg*)0) #define R ((Reg*)0)
/*c2go extern Reg *R; */
#define NRGN 600 #define NRGN 600
/*c2go enum { NRGN = 600 }; */
struct Rgn struct Rgn
{ {
Reg* enter; Reg* enter;
......
...@@ -564,6 +564,8 @@ gotit: ...@@ -564,6 +564,8 @@ gotit:
* .. * ..
*/ */
#define FAIL(msg) { if(debug['P']) print("\t%s; FAILURE\n", msg); return 0; } #define FAIL(msg) { if(debug['P']) print("\t%s; FAILURE\n", msg); return 0; }
/*c2go void FAIL(char*); */
int int
shiftprop(Flow *r) shiftprop(Flow *r)
{ {
......
...@@ -36,6 +36,11 @@ ...@@ -36,6 +36,11 @@
#define NREGVAR 32 #define NREGVAR 32
#define REGBITS ((uint32)0xffffffff) #define REGBITS ((uint32)0xffffffff)
/*c2go enum {
NREGVAR = 32,
REGBITS = 0xffffffff,
};
*/
void addsplits(void); void addsplits(void);
static Reg* firstr; static Reg* firstr;
......
...@@ -28,34 +28,43 @@ ...@@ -28,34 +28,43 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#define NSNAME 8 enum
#define NSYM 50 {
#define NREG 16 NSNAME = 8,
NSYM = 50,
NREG = 16,
};
#include "../ld/textflag.h" #include "../ld/textflag.h"
#define REGRET 0
/* -1 disables use of REGARG */ /* -1 disables use of REGARG */
#define REGARG -1 #define REGARG -1
/* compiler allocates R1 up as temps */ /*c2go enum { REGARG = -1 }; */
/* compiler allocates register variables R3 up */
#define REGEXT 10 enum
/* these two registers are declared in runtime.h */ {
#define REGG (REGEXT-0) REGRET = 0,
#define REGM (REGEXT-1) /* compiler allocates R1 up as temps */
/* compiler allocates external registers R10 down */ /* compiler allocates register variables R3 up */
#define REGTMP 11 /* compiler allocates external registers R10 down */
#define REGSP 13 REGEXT = 10,
#define REGLINK 14 /* these two registers are declared in runtime.h */
#define REGPC 15 REGG = REGEXT-0,
REGM = REGEXT-1,
#define NFREG 16
#define FREGRET 0 REGTMP = 11,
#define FREGEXT 7 REGSP = 13,
#define FREGTMP 15 REGLINK = 14,
REGPC = 15,
NFREG = 16,
FREGRET = 0,
FREGEXT = 7,
FREGTMP = 15,
};
/* compiler allocates register variables F0 up */ /* compiler allocates register variables F0 up */
/* compiler allocates external registers F7 down */ /* compiler allocates external registers F7 down */
enum as enum
{ {
AXXX, AXXX,
...@@ -209,35 +218,38 @@ enum as ...@@ -209,35 +218,38 @@ enum as
}; };
/* scond byte */ /* scond byte */
#define C_SCOND ((1<<4)-1) enum
#define C_SBIT (1<<4) {
#define C_PBIT (1<<5) C_SCOND = (1<<4)-1,
#define C_WBIT (1<<6) C_SBIT = 1<<4,
#define C_FBIT (1<<7) /* psr flags-only */ C_PBIT = 1<<5,
#define C_UBIT (1<<7) /* up bit, unsigned bit */ C_WBIT = 1<<6,
C_FBIT = 1<<7, /* psr flags-only */
#define C_SCOND_EQ 0 C_UBIT = 1<<7, /* up bit, unsigned bit */
#define C_SCOND_NE 1
#define C_SCOND_HS 2 C_SCOND_EQ = 0,
#define C_SCOND_LO 3 C_SCOND_NE = 1,
#define C_SCOND_MI 4 C_SCOND_HS = 2,
#define C_SCOND_PL 5 C_SCOND_LO = 3,
#define C_SCOND_VS 6 C_SCOND_MI = 4,
#define C_SCOND_VC 7 C_SCOND_PL = 5,
#define C_SCOND_HI 8 C_SCOND_VS = 6,
#define C_SCOND_LS 9 C_SCOND_VC = 7,
#define C_SCOND_GE 10 C_SCOND_HI = 8,
#define C_SCOND_LT 11 C_SCOND_LS = 9,
#define C_SCOND_GT 12 C_SCOND_GE = 10,
#define C_SCOND_LE 13 C_SCOND_LT = 11,
#define C_SCOND_NONE 14 C_SCOND_GT = 12,
#define C_SCOND_NV 15 C_SCOND_LE = 13,
C_SCOND_NONE = 14,
/* D_SHIFT type */ C_SCOND_NV = 15,
#define SHIFT_LL 0<<5
#define SHIFT_LR 1<<5 /* D_SHIFT type */
#define SHIFT_AR 2<<5 SHIFT_LL = 0<<5,
#define SHIFT_RR 3<<5 SHIFT_LR = 1<<5,
SHIFT_AR = 2<<5,
SHIFT_RR = 3<<5,
};
enum enum
{ {
...@@ -279,3 +291,4 @@ enum ...@@ -279,3 +291,4 @@ enum
* this is the ranlib header * this is the ranlib header
*/ */
#define SYMDEF "__.GOSYMDEF" #define SYMDEF "__.GOSYMDEF"
/*c2go extern char SYMDEF[]; */
...@@ -30,10 +30,10 @@ int cmpptr = ACMPQ; ...@@ -30,10 +30,10 @@ int cmpptr = ACMPQ;
*/ */
Typedef typedefs[] = Typedef typedefs[] =
{ {
"int", TINT, TINT64, {"int", TINT, TINT64},
"uint", TUINT, TUINT64, {"uint", TUINT, TUINT64},
"uintptr", TUINTPTR, TUINT64, {"uintptr", TUINTPTR, TUINT64},
0 {0}
}; };
void void
......
...@@ -584,6 +584,7 @@ ginscon(int as, vlong c, Node *n2) ...@@ -584,6 +584,7 @@ ginscon(int as, vlong c, Node *n2)
} }
#define CASE(a,b) (((a)<<16)|((b)<<0)) #define CASE(a,b) (((a)<<16)|((b)<<0))
/*c2go int CASE(int, int); */
/* /*
* Is this node a memory operand? * Is this node a memory operand?
......
...@@ -49,6 +49,24 @@ ...@@ -49,6 +49,24 @@
typedef struct Reg Reg; typedef struct Reg Reg;
typedef struct Rgn Rgn; typedef struct Rgn Rgn;
/*c2go
extern Node *Z;
enum
{
D_HI = D_NONE,
D_LO = D_NONE,
CLOAD = 5,
CREF = 5,
CINF = 1000,
LOOP = 3,
};
uint32 BLOAD(Reg*);
uint32 BSTORE(Reg*);
uint32 LOAD(Reg*);
uint32 STORE(Reg*);
*/
// A Reg is a wrapper around a single Prog (one instruction) that holds // A Reg is a wrapper around a single Prog (one instruction) that holds
// register optimization information while the optimizer runs. // register optimization information while the optimizer runs.
// r->prog is the instruction. // r->prog is the instruction.
...@@ -71,8 +89,10 @@ struct Reg ...@@ -71,8 +89,10 @@ struct Reg
int32 regu; // register used bitmap int32 regu; // register used bitmap
}; };
#define R ((Reg*)0) #define R ((Reg*)0)
/*c2go extern Reg *R; */
#define NRGN 600 #define NRGN 600
/*c2go enum { NRGN = 600 }; */
struct Rgn struct Rgn
{ {
Reg* enter; Reg* enter;
......
...@@ -35,6 +35,11 @@ ...@@ -35,6 +35,11 @@
#define NREGVAR 32 /* 16 general + 16 floating */ #define NREGVAR 32 /* 16 general + 16 floating */
#define REGBITS ((uint32)0xffffffff) #define REGBITS ((uint32)0xffffffff)
/*c2go enum {
NREGVAR = 32,
REGBITS = 0xffffffff,
};
*/
static Reg* firstr; static Reg* firstr;
static int first = 1; static int first = 1;
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
* amd64 * amd64
*/ */
enum as enum
{ {
AXXX, AXXX,
AAAA, AAAA,
......
...@@ -23,10 +23,10 @@ vlong MAXWIDTH = (1LL<<32) - 1; ...@@ -23,10 +23,10 @@ vlong MAXWIDTH = (1LL<<32) - 1;
*/ */
Typedef typedefs[] = Typedef typedefs[] =
{ {
"int", TINT, TINT32, {"int", TINT, TINT32},
"uint", TUINT, TUINT32, {"uint", TUINT, TUINT32},
"uintptr", TUINTPTR, TUINT32, {"uintptr", TUINTPTR, TUINT32},
0 {0}
}; };
void void
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
uint32 unmappedzero = 4096; uint32 unmappedzero = 4096;
#define CASE(a,b) (((a)<<16)|((b)<<0)) #define CASE(a,b) (((a)<<16)|((b)<<0))
/*c2go int CASE(int, int);*/
void void
clearp(Prog *p) clearp(Prog *p)
...@@ -697,6 +698,7 @@ optoas(int op, Type *t) ...@@ -697,6 +698,7 @@ optoas(int op, Type *t)
} }
#define FCASE(a, b, c) (((a)<<16)|((b)<<8)|(c)) #define FCASE(a, b, c) (((a)<<16)|((b)<<8)|(c))
/*c2go int FCASE(int, int, int); */
int int
foptoas(int op, Type *t, int flg) foptoas(int op, Type *t, int flg)
{ {
......
...@@ -49,6 +49,24 @@ ...@@ -49,6 +49,24 @@
typedef struct Reg Reg; typedef struct Reg Reg;
typedef struct Rgn Rgn; typedef struct Rgn Rgn;
/*c2go
extern Node *Z;
enum
{
D_HI = D_NONE,
D_LO = D_NONE,
CLOAD = 5,
CREF = 5,
CINF = 1000,
LOOP = 3,
};
uint32 BLOAD(Reg*);
uint32 BSTORE(Reg*);
uint32 LOAD(Reg*);
uint32 STORE(Reg*);
*/
// A Reg is a wrapper around a single Prog (one instruction) that holds // A Reg is a wrapper around a single Prog (one instruction) that holds
// register optimization information while the optimizer runs. // register optimization information while the optimizer runs.
// r->prog is the instruction. // r->prog is the instruction.
...@@ -84,8 +102,10 @@ struct Reg ...@@ -84,8 +102,10 @@ struct Reg
Prog* prog; // actual instruction Prog* prog; // actual instruction
}; };
#define R ((Reg*)0) #define R ((Reg*)0)
/*c2go extern Reg *R; */
#define NRGN 600 #define NRGN 600
/*c2go enum { NRGN = 600 }; */
struct Rgn struct Rgn
{ {
Reg* enter; Reg* enter;
......
...@@ -33,7 +33,9 @@ ...@@ -33,7 +33,9 @@
#include "gg.h" #include "gg.h"
#include "opt.h" #include "opt.h"
#define REGEXT 0 enum {
REGEXT = 0,
};
static void conprop(Flow *r); static void conprop(Flow *r);
static void elimshortmov(Graph*); static void elimshortmov(Graph*);
......
...@@ -35,6 +35,11 @@ ...@@ -35,6 +35,11 @@
#define NREGVAR 16 /* 8 integer + 8 floating */ #define NREGVAR 16 /* 8 integer + 8 floating */
#define REGBITS ((uint32)0xffff) #define REGBITS ((uint32)0xffff)
/*c2go enum {
NREGVAR = 16,
REGBITS = (1<<NREGVAR) - 1,
};
*/
static Reg* firstr; static Reg* firstr;
static int first = 1; static int first = 1;
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#define NSNAME 8 #define NSNAME 8
#include "../ld/textflag.h" #include "../ld/textflag.h"
enum as enum
{ {
AXXX, AXXX,
AAAA, AAAA,
......
...@@ -82,7 +82,16 @@ mkanames(char *dir, char *file) ...@@ -82,7 +82,16 @@ mkanames(char *dir, char *file)
bprintf(&b, "%s/../cmd/%cl/%c.out.h", dir, ch, ch); bprintf(&b, "%s/../cmd/%cl/%c.out.h", dir, ch, ch);
readfile(&in, bstr(&b)); readfile(&in, bstr(&b));
splitlines(&lines, bstr(&in)); splitlines(&lines, bstr(&in));
bprintf(&out, "char* anames%c[] = {\n", ch);
// Include link.h so that the extern declaration there is
// checked against the non-extern declaration we are generating.
bwritestr(&out, bprintf(&b, "#include <u.h>\n"));
bwritestr(&out, bprintf(&b, "#include <libc.h>\n"));
bwritestr(&out, bprintf(&b, "#include <bio.h>\n"));
bwritestr(&out, bprintf(&b, "#include <link.h>\n"));
bwritestr(&out, bprintf(&b, "\n"));
bwritestr(&out, bprintf(&b, "char* anames%c[] = {\n", ch));
for(i=0; i<lines.len; i++) { for(i=0; i<lines.len; i++) {
if(hasprefix(lines.p[i], "\tA")) { if(hasprefix(lines.p[i], "\tA")) {
p = xstrstr(lines.p[i], ","); p = xstrstr(lines.p[i], ",");
......
...@@ -22,6 +22,7 @@ BEGIN{ ...@@ -22,6 +22,7 @@ BEGIN{
bison = 1 bison = 1
grammar = 0 grammar = 0
states = 0 states = 0
open = 0
} }
# In Grammar section of y.output, # In Grammar section of y.output,
...@@ -130,11 +131,26 @@ $1 == "%" { ...@@ -130,11 +131,26 @@ $1 == "%" {
continue continue
# No shift or reduce applied - found the error. # No shift or reduce applied - found the error.
printf("\t%s, %s,\n", state, tok); printf("\t{%s, %s,\n", state, tok);
open = 1;
break break
} }
next next
} }
# Print other lines verbatim. # Print other lines verbatim.
open && /,$/ {
s = $0;
sub(",", "},", s)
print s
open = 0
next
}
open && /"$/ {
print $0 "}"
open = 0
next
}
{print} {print}
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <libc.h> #include <libc.h>
#include "go.h" #include "go.h"
#define TUP(x,y) (((x)<<16)|(y)) #define TUP(x,y) (((x)<<16)|(y))
/*c2go int TUP(int, int); */
static Val tocplx(Val); static Val tocplx(Val);
static Val toflt(Val); static Val toflt(Val);
......
...@@ -1110,6 +1110,7 @@ escflood(EscState *e, Node *dst) ...@@ -1110,6 +1110,7 @@ escflood(EscState *e, Node *dst)
// pass all the tests we have written so far, which we assume matches // pass all the tests we have written so far, which we assume matches
// the level of complexity we want the escape analysis code to handle. // the level of complexity we want the escape analysis code to handle.
#define MinLevel (-2) #define MinLevel (-2)
/*c2go enum { MinLevel = -2 };*/
static void static void
escwalk(EscState *e, int level, Node *dst, Node *src) escwalk(EscState *e, int level, Node *dst, Node *src)
......
...@@ -139,6 +139,8 @@ yy_isalnum(int c) ...@@ -139,6 +139,8 @@ yy_isalnum(int c)
#define isalnum use_yy_isalnum_instead_of_isalnum #define isalnum use_yy_isalnum_instead_of_isalnum
#define DBG if(!debug['x']){}else print #define DBG if(!debug['x']){}else print
/*c2go void DBG(char*, ...); */
enum enum
{ {
EOF = -1, EOF = -1,
...@@ -516,24 +518,18 @@ saveerrors(void) ...@@ -516,24 +518,18 @@ saveerrors(void)
nerrors = 0; nerrors = 0;
} }
/*
* macro to portably read/write archive header.
* 'cmd' is read/write/Bread/Bwrite, etc.
*/
#define HEADER_IO(cmd, f, h) cmd(f, h.name, sizeof(h.name)) != sizeof(h.name)\
|| cmd(f, h.date, sizeof(h.date)) != sizeof(h.date)\
|| cmd(f, h.uid, sizeof(h.uid)) != sizeof(h.uid)\
|| cmd(f, h.gid, sizeof(h.gid)) != sizeof(h.gid)\
|| cmd(f, h.mode, sizeof(h.mode)) != sizeof(h.mode)\
|| cmd(f, h.size, sizeof(h.size)) != sizeof(h.size)\
|| cmd(f, h.fmag, sizeof(h.fmag)) != sizeof(h.fmag)
static int static int
arsize(Biobuf *b, char *name) arsize(Biobuf *b, char *name)
{ {
struct ar_hdr a; struct ar_hdr a;
if (HEADER_IO(Bread, b, a)) if(Bread(b, a.name, sizeof(a.name)) != sizeof(a.name) ||
Bread(b, a.date, sizeof(a.date)) != sizeof(a.date) ||
Bread(b, a.uid, sizeof(a.uid)) != sizeof(a.uid) ||
Bread(b, a.gid, sizeof(a.gid)) != sizeof(a.gid) ||
Bread(b, a.mode, sizeof(a.mode)) != sizeof(a.mode) ||
Bread(b, a.size, sizeof(a.size)) != sizeof(a.size) ||
Bread(b, a.fmag, sizeof(a.fmag)) != sizeof(a.fmag))
return -1; return -1;
if(strncmp(a.name, name, strlen(name)) != 0) if(strncmp(a.name, name, strlen(name)) != 0)
...@@ -1858,74 +1854,74 @@ static struct ...@@ -1858,74 +1854,74 @@ static struct
/* name lexical etype op /* name lexical etype op
*/ */
/* basic types */ /* basic types */
"int8", LNAME, TINT8, OXXX, {"int8", LNAME, TINT8, OXXX},
"int16", LNAME, TINT16, OXXX, {"int16", LNAME, TINT16, OXXX},
"int32", LNAME, TINT32, OXXX, {"int32", LNAME, TINT32, OXXX},
"int64", LNAME, TINT64, OXXX, {"int64", LNAME, TINT64, OXXX},
"uint8", LNAME, TUINT8, OXXX, {"uint8", LNAME, TUINT8, OXXX},
"uint16", LNAME, TUINT16, OXXX, {"uint16", LNAME, TUINT16, OXXX},
"uint32", LNAME, TUINT32, OXXX, {"uint32", LNAME, TUINT32, OXXX},
"uint64", LNAME, TUINT64, OXXX, {"uint64", LNAME, TUINT64, OXXX},
"float32", LNAME, TFLOAT32, OXXX, {"float32", LNAME, TFLOAT32, OXXX},
"float64", LNAME, TFLOAT64, OXXX, {"float64", LNAME, TFLOAT64, OXXX},
"complex64", LNAME, TCOMPLEX64, OXXX, {"complex64", LNAME, TCOMPLEX64, OXXX},
"complex128", LNAME, TCOMPLEX128, OXXX, {"complex128", LNAME, TCOMPLEX128, OXXX},
"bool", LNAME, TBOOL, OXXX, {"bool", LNAME, TBOOL, OXXX},
"string", LNAME, TSTRING, OXXX, {"string", LNAME, TSTRING, OXXX},
"any", LNAME, TANY, OXXX, {"any", LNAME, TANY, OXXX},
"break", LBREAK, Txxx, OXXX, {"break", LBREAK, Txxx, OXXX},
"case", LCASE, Txxx, OXXX, {"case", LCASE, Txxx, OXXX},
"chan", LCHAN, Txxx, OXXX, {"chan", LCHAN, Txxx, OXXX},
"const", LCONST, Txxx, OXXX, {"const", LCONST, Txxx, OXXX},
"continue", LCONTINUE, Txxx, OXXX, {"continue", LCONTINUE, Txxx, OXXX},
"default", LDEFAULT, Txxx, OXXX, {"default", LDEFAULT, Txxx, OXXX},
"else", LELSE, Txxx, OXXX, {"else", LELSE, Txxx, OXXX},
"defer", LDEFER, Txxx, OXXX, {"defer", LDEFER, Txxx, OXXX},
"fallthrough", LFALL, Txxx, OXXX, {"fallthrough", LFALL, Txxx, OXXX},
"for", LFOR, Txxx, OXXX, {"for", LFOR, Txxx, OXXX},
"func", LFUNC, Txxx, OXXX, {"func", LFUNC, Txxx, OXXX},
"go", LGO, Txxx, OXXX, {"go", LGO, Txxx, OXXX},
"goto", LGOTO, Txxx, OXXX, {"goto", LGOTO, Txxx, OXXX},
"if", LIF, Txxx, OXXX, {"if", LIF, Txxx, OXXX},
"import", LIMPORT, Txxx, OXXX, {"import", LIMPORT, Txxx, OXXX},
"interface", LINTERFACE, Txxx, OXXX, {"interface", LINTERFACE, Txxx, OXXX},
"map", LMAP, Txxx, OXXX, {"map", LMAP, Txxx, OXXX},
"package", LPACKAGE, Txxx, OXXX, {"package", LPACKAGE, Txxx, OXXX},
"range", LRANGE, Txxx, OXXX, {"range", LRANGE, Txxx, OXXX},
"return", LRETURN, Txxx, OXXX, {"return", LRETURN, Txxx, OXXX},
"select", LSELECT, Txxx, OXXX, {"select", LSELECT, Txxx, OXXX},
"struct", LSTRUCT, Txxx, OXXX, {"struct", LSTRUCT, Txxx, OXXX},
"switch", LSWITCH, Txxx, OXXX, {"switch", LSWITCH, Txxx, OXXX},
"type", LTYPE, Txxx, OXXX, {"type", LTYPE, Txxx, OXXX},
"var", LVAR, Txxx, OXXX, {"var", LVAR, Txxx, OXXX},
"append", LNAME, Txxx, OAPPEND, {"append", LNAME, Txxx, OAPPEND},
"cap", LNAME, Txxx, OCAP, {"cap", LNAME, Txxx, OCAP},
"close", LNAME, Txxx, OCLOSE, {"close", LNAME, Txxx, OCLOSE},
"complex", LNAME, Txxx, OCOMPLEX, {"complex", LNAME, Txxx, OCOMPLEX},
"copy", LNAME, Txxx, OCOPY, {"copy", LNAME, Txxx, OCOPY},
"delete", LNAME, Txxx, ODELETE, {"delete", LNAME, Txxx, ODELETE},
"imag", LNAME, Txxx, OIMAG, {"imag", LNAME, Txxx, OIMAG},
"len", LNAME, Txxx, OLEN, {"len", LNAME, Txxx, OLEN},
"make", LNAME, Txxx, OMAKE, {"make", LNAME, Txxx, OMAKE},
"new", LNAME, Txxx, ONEW, {"new", LNAME, Txxx, ONEW},
"panic", LNAME, Txxx, OPANIC, {"panic", LNAME, Txxx, OPANIC},
"print", LNAME, Txxx, OPRINT, {"print", LNAME, Txxx, OPRINT},
"println", LNAME, Txxx, OPRINTN, {"println", LNAME, Txxx, OPRINTN},
"real", LNAME, Txxx, OREAL, {"real", LNAME, Txxx, OREAL},
"recover", LNAME, Txxx, ORECOVER, {"recover", LNAME, Txxx, ORECOVER},
"notwithstanding", LIGNORE, Txxx, OXXX, {"notwithstanding", LIGNORE, Txxx, OXXX},
"thetruthofthematter", LIGNORE, Txxx, OXXX, {"thetruthofthematter", LIGNORE, Txxx, OXXX},
"despiteallobjections", LIGNORE, Txxx, OXXX, {"despiteallobjections", LIGNORE, Txxx, OXXX},
"whereas", LIGNORE, Txxx, OXXX, {"whereas", LIGNORE, Txxx, OXXX},
"insofaras", LIGNORE, Txxx, OXXX, {"insofaras", LIGNORE, Txxx, OXXX},
}; };
static void static void
...@@ -2175,50 +2171,50 @@ struct ...@@ -2175,50 +2171,50 @@ struct
char* name; char* name;
} lexn[] = } lexn[] =
{ {
LANDAND, "ANDAND", {LANDAND, "ANDAND"},
LANDNOT, "ANDNOT", {LANDNOT, "ANDNOT"},
LASOP, "ASOP", {LASOP, "ASOP"},
LBREAK, "BREAK", {LBREAK, "BREAK"},
LCASE, "CASE", {LCASE, "CASE"},
LCHAN, "CHAN", {LCHAN, "CHAN"},
LCOLAS, "COLAS", {LCOLAS, "COLAS"},
LCOMM, "<-", {LCOMM, "<-"},
LCONST, "CONST", {LCONST, "CONST"},
LCONTINUE, "CONTINUE", {LCONTINUE, "CONTINUE"},
LDDD, "...", {LDDD, "..."},
LDEC, "DEC", {LDEC, "DEC"},
LDEFAULT, "DEFAULT", {LDEFAULT, "DEFAULT"},
LDEFER, "DEFER", {LDEFER, "DEFER"},
LELSE, "ELSE", {LELSE, "ELSE"},
LEQ, "EQ", {LEQ, "EQ"},
LFALL, "FALL", {LFALL, "FALL"},
LFOR, "FOR", {LFOR, "FOR"},
LFUNC, "FUNC", {LFUNC, "FUNC"},
LGE, "GE", {LGE, "GE"},
LGO, "GO", {LGO, "GO"},
LGOTO, "GOTO", {LGOTO, "GOTO"},
LGT, "GT", {LGT, "GT"},
LIF, "IF", {LIF, "IF"},
LIMPORT, "IMPORT", {LIMPORT, "IMPORT"},
LINC, "INC", {LINC, "INC"},
LINTERFACE, "INTERFACE", {LINTERFACE, "INTERFACE"},
LLE, "LE", {LLE, "LE"},
LLITERAL, "LITERAL", {LLITERAL, "LITERAL"},
LLSH, "LSH", {LLSH, "LSH"},
LLT, "LT", {LLT, "LT"},
LMAP, "MAP", {LMAP, "MAP"},
LNAME, "NAME", {LNAME, "NAME"},
LNE, "NE", {LNE, "NE"},
LOROR, "OROR", {LOROR, "OROR"},
LPACKAGE, "PACKAGE", {LPACKAGE, "PACKAGE"},
LRANGE, "RANGE", {LRANGE, "RANGE"},
LRETURN, "RETURN", {LRETURN, "RETURN"},
LRSH, "RSH", {LRSH, "RSH"},
LSELECT, "SELECT", {LSELECT, "SELECT"},
LSTRUCT, "STRUCT", {LSTRUCT, "STRUCT"},
LSWITCH, "SWITCH", {LSWITCH, "SWITCH"},
LTYPE, "TYPE", {LTYPE, "TYPE"},
LVAR, "VAR", {LVAR, "VAR"},
}; };
char* char*
...@@ -2240,56 +2236,56 @@ struct ...@@ -2240,56 +2236,56 @@ struct
char *want; char *want;
} yytfix[] = } yytfix[] =
{ {
"$end", "EOF", {"$end", "EOF"},
"LLITERAL", "literal", {"LLITERAL", "literal"},
"LASOP", "op=", {"LASOP", "op="},
"LBREAK", "break", {"LBREAK", "break"},
"LCASE", "case", {"LCASE", "case"},
"LCHAN", "chan", {"LCHAN", "chan"},
"LCOLAS", ":=", {"LCOLAS", ":="},
"LCONST", "const", {"LCONST", "const"},
"LCONTINUE", "continue", {"LCONTINUE", "continue"},
"LDDD", "...", {"LDDD", "..."},
"LDEFAULT", "default", {"LDEFAULT", "default"},
"LDEFER", "defer", {"LDEFER", "defer"},
"LELSE", "else", {"LELSE", "else"},
"LFALL", "fallthrough", {"LFALL", "fallthrough"},
"LFOR", "for", {"LFOR", "for"},
"LFUNC", "func", {"LFUNC", "func"},
"LGO", "go", {"LGO", "go"},
"LGOTO", "goto", {"LGOTO", "goto"},
"LIF", "if", {"LIF", "if"},
"LIMPORT", "import", {"LIMPORT", "import"},
"LINTERFACE", "interface", {"LINTERFACE", "interface"},
"LMAP", "map", {"LMAP", "map"},
"LNAME", "name", {"LNAME", "name"},
"LPACKAGE", "package", {"LPACKAGE", "package"},
"LRANGE", "range", {"LRANGE", "range"},
"LRETURN", "return", {"LRETURN", "return"},
"LSELECT", "select", {"LSELECT", "select"},
"LSTRUCT", "struct", {"LSTRUCT", "struct"},
"LSWITCH", "switch", {"LSWITCH", "switch"},
"LTYPE", "type", {"LTYPE", "type"},
"LVAR", "var", {"LVAR", "var"},
"LANDAND", "&&", {"LANDAND", "&&"},
"LANDNOT", "&^", {"LANDNOT", "&^"},
"LBODY", "{", {"LBODY", "{"},
"LCOMM", "<-", {"LCOMM", "<-"},
"LDEC", "--", {"LDEC", "--"},
"LINC", "++", {"LINC", "++"},
"LEQ", "==", {"LEQ", "=="},
"LGE", ">=", {"LGE", ">="},
"LGT", ">", {"LGT", ">"},
"LLE", "<=", {"LLE", "<="},
"LLT", "<", {"LLT", "<"},
"LLSH", "<<", {"LLSH", "<<"},
"LRSH", ">>", {"LRSH", ">>"},
"LOROR", "||", {"LOROR", "||"},
"LNE", "!=", {"LNE", "!="},
// spell out to avoid confusion with punctuation in error messages // spell out to avoid confusion with punctuation in error messages
"';'", "semicolon or newline", {"';'", "semicolon or newline"},
"','", "comma", {"','", "comma"},
}; };
static void static void
......
...@@ -20,7 +20,15 @@ enum { ...@@ -20,7 +20,15 @@ enum {
#define _Init1 0xEFCDAB89 #define _Init1 0xEFCDAB89
#define _Init2 0x98BADCFE #define _Init2 0x98BADCFE
#define _Init3 0x10325476 #define _Init3 0x10325476
/*c2go
enum {
_Init0 = 0x67452301,
_Init1 = 0xEFCDAB89,
_Init2 = 0x98BADCFE,
_Init3 = 0x10325476
};
*/
void void
md5reset(MD5 *d) md5reset(MD5 *d)
{ {
......
...@@ -657,8 +657,8 @@ static void ...@@ -657,8 +657,8 @@ static void
progeffects(Prog *prog, Array *vars, Bvec *uevar, Bvec *varkill, Bvec *avarinit) progeffects(Prog *prog, Array *vars, Bvec *uevar, Bvec *varkill, Bvec *avarinit)
{ {
ProgInfo info; ProgInfo info;
Adr *from; Addr *from;
Adr *to; Addr *to;
Node *node; Node *node;
int32 i; int32 i;
int32 pos; int32 pos;
...@@ -1663,6 +1663,13 @@ livenessepilogue(Liveness *lv) ...@@ -1663,6 +1663,13 @@ livenessepilogue(Liveness *lv)
// FNV-1 hash function constants. // FNV-1 hash function constants.
#define H0 2166136261UL #define H0 2166136261UL
#define Hp 16777619UL #define Hp 16777619UL
/*c2go
enum
{
H0 = 2166136261,
Hp = 16777619,
};
*/
static uint32 static uint32
hashbitmap(uint32 h, Bvec *bv) hashbitmap(uint32 h, Bvec *bv)
......
...@@ -98,6 +98,10 @@ chasejmp(Prog *p, int *jmploop) ...@@ -98,6 +98,10 @@ chasejmp(Prog *p, int *jmploop)
*/ */
#define alive ((void*)0) #define alive ((void*)0)
#define dead ((void*)1) #define dead ((void*)1)
/*c2go
extern void *alive;
extern void *dead;
*/
/* mark all code reachable from firstp as alive */ /* mark all code reachable from firstp as alive */
static void static void
......
...@@ -3445,7 +3445,7 @@ smagic(Magic *m) ...@@ -3445,7 +3445,7 @@ smagic(Magic *m)
mask = 0xffffffffLL; mask = 0xffffffffLL;
break; break;
case 64: case 64:
mask = 0xffffffffffffffffLL; mask = 0xffffffffffffffffULL;
break; break;
} }
two31 = mask ^ (mask>>1); two31 = mask ^ (mask>>1);
...@@ -3543,7 +3543,7 @@ umagic(Magic *m) ...@@ -3543,7 +3543,7 @@ umagic(Magic *m)
mask = 0xffffffffLL; mask = 0xffffffffLL;
break; break;
case 64: case 64:
mask = 0xffffffffffffffffLL; mask = 0xffffffffffffffffULL;
break; break;
} }
two31 = mask ^ (mask>>1); two31 = mask ^ (mask>>1);
......
...@@ -34,6 +34,7 @@ struct Case ...@@ -34,6 +34,7 @@ struct Case
Case* link; // linked list to link Case* link; // linked list to link
}; };
#define C ((Case*)nil) #define C ((Case*)nil)
/*c2go Case *C; */
void void
dumpcase(Case *c0) dumpcase(Case *c0)
......
...@@ -14,66 +14,66 @@ static struct { ...@@ -14,66 +14,66 @@ static struct {
// is converted by bisonerrors into the yystate and yychar caused // is converted by bisonerrors into the yystate and yychar caused
// by that token list. // by that token list.
222, ',', {222, ',',
"unexpected comma during import block", "unexpected comma during import block"},
32, ';', {32, ';',
"missing import path; require quoted string", "missing import path; require quoted string"},
378, ';', {378, ';',
"missing { after if clause", "missing { after if clause"},
399, ';', {399, ';',
"missing { after switch clause", "missing { after switch clause"},
238, ';', {238, ';',
"missing { after for clause", "missing { after for clause"},
476, LBODY, {476, LBODY,
"missing { after for clause", "missing { after for clause"},
22, '{', {22, '{',
"unexpected semicolon or newline before {", "unexpected semicolon or newline before {"},
145, ';', {145, ';',
"unexpected semicolon or newline in type declaration", "unexpected semicolon or newline in type declaration"},
37, '}', {37, '}',
"unexpected } in channel type", "unexpected } in channel type"},
37, ')', {37, ')',
"unexpected ) in channel type", "unexpected ) in channel type"},
37, ',', {37, ',',
"unexpected comma in channel type", "unexpected comma in channel type"},
439, LELSE, {439, LELSE,
"unexpected semicolon or newline before else", "unexpected semicolon or newline before else"},
258, ',', {258, ',',
"name list not allowed in interface type", "name list not allowed in interface type"},
238, LVAR, {238, LVAR,
"var declaration not allowed in for initializer", "var declaration not allowed in for initializer"},
65, '{', {65, '{',
"unexpected { at end of statement", "unexpected { at end of statement"},
377, '{', {377, '{',
"unexpected { at end of statement", "unexpected { at end of statement"},
126, ';', {126, ';',
"argument to go/defer must be function call", "argument to go/defer must be function call"},
426, ';', {426, ';',
"need trailing comma before newline in composite literal", "need trailing comma before newline in composite literal"},
437, ';', {437, ';',
"need trailing comma before newline in composite literal", "need trailing comma before newline in composite literal"},
113, LNAME, {113, LNAME,
"nested func not allowed", "nested func not allowed"},
645, ';', {645, ';',
"else must be followed by if or statement block" "else must be followed by if or statement block"}
}; };
...@@ -21,3 +21,16 @@ ...@@ -21,3 +21,16 @@
#define WRAPPER 32 #define WRAPPER 32
// This function uses its incoming context register. // This function uses its incoming context register.
#define NEEDCTXT 64 #define NEEDCTXT 64
/*c2go
enum
{
NOPROF = 1,
DUPOK = 2,
NOSPLIT = 4,
RODATA = 8,
NOPTR = 16,
WRAPPER = 32,
NEEDCTXT = 64,
};
*/
...@@ -43,7 +43,7 @@ typedef uchar Opcross[32][2][32]; ...@@ -43,7 +43,7 @@ typedef uchar Opcross[32][2][32];
struct Optab struct Optab
{ {
char as; uchar as;
uchar a1; uchar a1;
char a2; char a2;
uchar a3; uchar a3;
...@@ -2038,64 +2038,6 @@ if(0 /*debug['G']*/) print("%ux: %s: arm %d\n", (uint32)(p->pc), p->from.sym->na ...@@ -2038,64 +2038,6 @@ if(0 /*debug['G']*/) print("%ux: %s: arm %d\n", (uint32)(p->pc), p->from.sym->na
out[4] = o5; out[4] = o5;
out[5] = o6; out[5] = o6;
return; return;
#ifdef NOTDEF
v = p->pc;
switch(o->size) {
default:
if(debug['a'])
Bprint(&bso, " %.8ux:\t\t%P\n", v, p);
break;
case 4:
if(debug['a'])
Bprint(&bso, " %.8ux: %.8ux\t%P\n", v, o1, p);
lputl(o1);
break;
case 8:
if(debug['a'])
Bprint(&bso, " %.8ux: %.8ux %.8ux%P\n", v, o1, o2, p);
lputl(o1);
lputl(o2);
break;
case 12:
if(debug['a'])
Bprint(&bso, " %.8ux: %.8ux %.8ux %.8ux%P\n", v, o1, o2, o3, p);
lputl(o1);
lputl(o2);
lputl(o3);
break;
case 16:
if(debug['a'])
Bprint(&bso, " %.8ux: %.8ux %.8ux %.8ux %.8ux%P\n",
v, o1, o2, o3, o4, p);
lputl(o1);
lputl(o2);
lputl(o3);
lputl(o4);
break;
case 20:
if(debug['a'])
Bprint(&bso, " %.8ux: %.8ux %.8ux %.8ux %.8ux %.8ux%P\n",
v, o1, o2, o3, o4, o5, p);
lputl(o1);
lputl(o2);
lputl(o3);
lputl(o4);
lputl(o5);
break;
case 24:
if(debug['a'])
Bprint(&bso, " %.8ux: %.8ux %.8ux %.8ux %.8ux %.8ux %.8ux%P\n",
v, o1, o2, o3, o4, o5, o6, p);
lputl(o1);
lputl(o2);
lputl(o3);
lputl(o4);
lputl(o5);
lputl(o6);
break;
}
#endif
} }
static int32 static int32
......
This diff is collapsed.
This diff is collapsed.
...@@ -161,7 +161,10 @@ uchar inuxi2[2]; ...@@ -161,7 +161,10 @@ uchar inuxi2[2];
uchar inuxi4[4]; uchar inuxi4[4];
uchar inuxi8[8]; uchar inuxi8[8];
#define LOG 5 enum
{
LOG = 5,
};
void void
mkfwd(LSym *sym) mkfwd(LSym *sym)
{ {
......
...@@ -958,7 +958,7 @@ xfol(Link *ctxt, Prog *p, Prog **last) ...@@ -958,7 +958,7 @@ xfol(Link *ctxt, Prog *p, Prog **last)
{ {
Prog *q; Prog *q;
int i; int i;
enum as a; int a;
loop: loop:
if(p == nil) if(p == nil)
......
...@@ -697,7 +697,7 @@ xfol(Link *ctxt, Prog *p, Prog **last) ...@@ -697,7 +697,7 @@ xfol(Link *ctxt, Prog *p, Prog **last)
{ {
Prog *q; Prog *q;
int i; int i;
enum as a; int a;
loop: loop:
if(p == nil) if(p == nil)
......
...@@ -44,20 +44,20 @@ static struct { ...@@ -44,20 +44,20 @@ static struct {
char *name; char *name;
int val; int val;
} headers[] = { } headers[] = {
"darwin", Hdarwin, {"android", Hlinux},
"dragonfly", Hdragonfly, {"darwin", Hdarwin},
"elf", Helf, {"dragonfly", Hdragonfly},
"freebsd", Hfreebsd, {"elf", Helf},
"linux", Hlinux, {"freebsd", Hfreebsd},
"android", Hlinux, {"linux", Hlinux},
"nacl", Hnacl, {"nacl", Hnacl},
"netbsd", Hnetbsd, {"netbsd", Hnetbsd},
"openbsd", Hopenbsd, {"openbsd", Hopenbsd},
"plan9", Hplan9, {"plan9", Hplan9},
"solaris", Hsolaris, {"solaris", Hsolaris},
"windows", Hwindows, {"windows", Hwindows},
"windowsgui", Hwindows, {"windowsgui", Hwindows},
0, 0 {0, 0},
}; };
int int
......
...@@ -22,3 +22,14 @@ ...@@ -22,3 +22,14 @@
// assembly code without an explicit specification). // assembly code without an explicit specification).
// This value is generated by the compiler, assembler, or linker. // This value is generated by the compiler, assembler, or linker.
#define ArgsSizeUnknown 0x80000000 #define ArgsSizeUnknown 0x80000000
/*c2go
enum {
PCDATA_ArgSize = 0,
PCDATA_StackMapIndex = 1,
FUNCDATA_ArgsPointerMaps = 2,
FUNCDATA_LocalsPointerMaps = 3,
FUNCDATA_DeadValueMaps = 4,
ArgsSizeUnknown = 0x80000000,
};
*/
...@@ -111,3 +111,9 @@ enum { ...@@ -111,3 +111,9 @@ enum {
// Must be greater than any real sp. // Must be greater than any real sp.
// 0xfffffade in hex. // 0xfffffade in hex.
#define StackPreempt ((uint64)-1314) #define StackPreempt ((uint64)-1314)
/*c2go
enum
{
StackPreempt = -1314,
};
*/
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