github.com/rohankumardubey/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/src/cmd/6c/gc.h (about)

     1  // Inferno utils/6c/gc.h
     2  // http://code.google.com/p/inferno-os/source/browse/utils/6c/gc.h
     3  //
     4  //	Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
     5  //	Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
     6  //	Portions Copyright © 1997-1999 Vita Nuova Limited
     7  //	Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
     8  //	Portions Copyright © 2004,2006 Bruce Ellis
     9  //	Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
    10  //	Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
    11  //	Portions Copyright © 2009 The Go Authors.  All rights reserved.
    12  //
    13  // Permission is hereby granted, free of charge, to any person obtaining a copy
    14  // of this software and associated documentation files (the "Software"), to deal
    15  // in the Software without restriction, including without limitation the rights
    16  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    17  // copies of the Software, and to permit persons to whom the Software is
    18  // furnished to do so, subject to the following conditions:
    19  //
    20  // The above copyright notice and this permission notice shall be included in
    21  // all copies or substantial portions of the Software.
    22  //
    23  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    24  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    25  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    26  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    27  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    28  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    29  // THE SOFTWARE.
    30  
    31  #include	<u.h>
    32  #include	"../cc/cc.h"
    33  #include	"../6l/6.out.h"
    34  
    35  /*
    36   * 6c/amd64
    37   * Intel 386 with AMD64 extensions
    38   */
    39  #define	SZ_CHAR		1
    40  #define	SZ_SHORT	2
    41  #define	SZ_INT		4
    42  #define	SZ_LONG		4
    43  #define	SZ_IND		8
    44  #define	SZ_FLOAT	4
    45  #define	SZ_VLONG	8
    46  #define	SZ_DOUBLE	8
    47  #define	FNX		100
    48  
    49  typedef	struct	Adr	Adr;
    50  typedef	struct	Prog	Prog;
    51  typedef	struct	Case	Case;
    52  typedef	struct	C1	C1;
    53  typedef	struct	Var	Var;
    54  typedef	struct	Reg	Reg;
    55  typedef	struct	Rgn	Rgn;
    56  typedef	struct	Renv	Renv;
    57  
    58  EXTERN	struct
    59  {
    60  	Node*	regtree;
    61  	Node*	basetree;
    62  	short	scale;
    63  	short	reg;
    64  	short	ptr;
    65  } idx;
    66  
    67  struct	Adr
    68  {
    69  	vlong	offset;
    70  	double	dval;
    71  	char	sval[NSNAME];
    72  
    73  	Sym*	sym;
    74  	uchar	type;
    75  	uchar	index;
    76  	uchar	etype;
    77  	uchar	scale;	/* doubles as width in DATA op */
    78  };
    79  #define	A	((Adr*)0)
    80  
    81  #define	INDEXED	9
    82  struct	Prog
    83  {
    84  	Adr	from;
    85  	Adr	to;
    86  	Prog*	link;
    87  	int32	lineno;
    88  	short	as;
    89  };
    90  #define	P	((Prog*)0)
    91  
    92  struct	Case
    93  {
    94  	Case*	link;
    95  	vlong	val;
    96  	int32	label;
    97  	char	def;
    98  	char	isv;
    99  };
   100  #define	C	((Case*)0)
   101  
   102  struct	C1
   103  {
   104  	vlong	val;
   105  	int32	label;
   106  };
   107  
   108  struct	Var
   109  {
   110  	vlong	offset;
   111  	Sym*	sym;
   112  	char	name;
   113  	char	etype;
   114  };
   115  
   116  struct	Reg
   117  {
   118  	int32	pc;
   119  	int32	rpo;		/* reverse post ordering */
   120  
   121  	Bits	set;
   122  	Bits	use1;
   123  	Bits	use2;
   124  
   125  	Bits	refbehind;
   126  	Bits	refahead;
   127  	Bits	calbehind;
   128  	Bits	calahead;
   129  	Bits	regdiff;
   130  	Bits	act;
   131  
   132  	int32	regu;
   133  	int32	loop;		/* could be shorter */
   134  
   135  	Reg*	log5;
   136  	int32	active;
   137  
   138  	Reg*	p1;
   139  	Reg*	p2;
   140  	Reg*	p2link;
   141  	Reg*	s1;
   142  	Reg*	s2;
   143  	Reg*	link;
   144  	Prog*	prog;
   145  };
   146  #define	R	((Reg*)0)
   147  
   148  struct	Renv
   149  {
   150  	int	safe;
   151  	Node	base;
   152  	Node*	saved;
   153  	Node*	scope;
   154  };
   155  
   156  #define	NRGN	600
   157  struct	Rgn
   158  {
   159  	Reg*	enter;
   160  	short	cost;
   161  	short	varno;
   162  	short	regno;
   163  };
   164  
   165  EXTERN	int32	breakpc;
   166  EXTERN	int32	nbreak;
   167  EXTERN	Case*	cases;
   168  EXTERN	Node	constnode;
   169  EXTERN	Node	fconstnode;
   170  EXTERN	Node	vconstnode;
   171  EXTERN	int32	continpc;
   172  EXTERN	int32	curarg;
   173  EXTERN	int32	cursafe;
   174  EXTERN	Prog*	firstp;
   175  EXTERN	Prog*	lastp;
   176  EXTERN	int32	maxargsafe;
   177  EXTERN	int	mnstring;
   178  EXTERN	int	retok;
   179  EXTERN	Node*	nodrat;
   180  EXTERN	Node*	nodret;
   181  EXTERN	Node*	nodsafe;
   182  EXTERN	int32	nrathole;
   183  EXTERN	int32	nstring;
   184  EXTERN	Prog*	p;
   185  EXTERN	int32	pc;
   186  EXTERN	Node	lregnode;
   187  EXTERN	Node	qregnode;
   188  EXTERN	char	string[NSNAME];
   189  EXTERN	Sym*	symrathole;
   190  EXTERN	Node	znode;
   191  EXTERN	Prog	zprog;
   192  EXTERN	int	reg[D_NONE];
   193  EXTERN	int32	exregoffset;
   194  EXTERN	int32	exfregoffset;
   195  EXTERN	uchar	typechlpv[NTYPE];
   196  
   197  #define	BLOAD(r)	band(bnot(r->refbehind), r->refahead)
   198  #define	BSTORE(r)	band(bnot(r->calbehind), r->calahead)
   199  #define	LOAD(r)		(~r->refbehind.b[z] & r->refahead.b[z])
   200  #define	STORE(r)	(~r->calbehind.b[z] & r->calahead.b[z])
   201  
   202  #define	bset(a,n)	((a).b[(n)/32]&(1L<<(n)%32))
   203  
   204  #define	CLOAD	5
   205  #define	CREF	5
   206  #define	CINF	1000
   207  #define	LOOP	3
   208  
   209  EXTERN	Rgn	region[NRGN];
   210  EXTERN	Rgn*	rgp;
   211  EXTERN	int	nregion;
   212  EXTERN	int	nvar;
   213  
   214  EXTERN	Bits	externs;
   215  EXTERN	Bits	params;
   216  EXTERN	Bits	consts;
   217  EXTERN	Bits	addrs;
   218  
   219  EXTERN	int32	regbits;
   220  EXTERN	int32	exregbits;
   221  
   222  EXTERN	int	change;
   223  EXTERN	int	suppress;
   224  
   225  EXTERN	Reg*	firstr;
   226  EXTERN	Reg*	lastr;
   227  EXTERN	Reg	zreg;
   228  EXTERN	Reg*	freer;
   229  EXTERN	Var	var[NVAR];
   230  EXTERN	int32*	idom;
   231  EXTERN	Reg**	rpo2r;
   232  EXTERN	int32	maxnr;
   233  
   234  extern	char*	anames[];
   235  
   236  /*
   237   * sgen.c
   238   */
   239  void	codgen(Node*, Node*);
   240  void	gen(Node*);
   241  void	noretval(int);
   242  void	usedset(Node*, int);
   243  void	xcom(Node*);
   244  void	indx(Node*);
   245  int	bcomplex(Node*, Node*);
   246  Prog*	gtext(Sym*, int32);
   247  vlong	argsize(void);
   248  
   249  /*
   250   * cgen.c
   251   */
   252  void	zeroregm(Node*);
   253  void	cgen(Node*, Node*);
   254  void	reglcgen(Node*, Node*, Node*);
   255  void	lcgen(Node*, Node*);
   256  void	bcgen(Node*, int);
   257  void	boolgen(Node*, int, Node*);
   258  void	sugen(Node*, Node*, int32);
   259  int	needreg(Node*, int);
   260  int	hardconst(Node*);
   261  int	immconst(Node*);
   262  
   263  /*
   264   * txt.c
   265   */
   266  void	ginit(void);
   267  void	gclean(void);
   268  void	nextpc(void);
   269  void	gargs(Node*, Node*, Node*);
   270  void	garg1(Node*, Node*, Node*, int, Node**);
   271  Node*	nodconst(int32);
   272  Node*	nodfconst(double);
   273  Node*	nodgconst(vlong, Type*);
   274  int	nodreg(Node*, Node*, int);
   275  int	isreg(Node*, int);
   276  void	regret(Node*, Node*);
   277  void	regalloc(Node*, Node*, Node*);
   278  void	regfree(Node*);
   279  void	regialloc(Node*, Node*, Node*);
   280  void	regsalloc(Node*, Node*);
   281  void	regaalloc1(Node*, Node*);
   282  void	regaalloc(Node*, Node*);
   283  void	regind(Node*, Node*);
   284  void	gprep(Node*, Node*);
   285  void	naddr(Node*, Adr*);
   286  void	gcmp(int, Node*, vlong);
   287  void	gmove(Node*, Node*);
   288  void	gins(int a, Node*, Node*);
   289  void	gopcode(int, Type*, Node*, Node*);
   290  int	samaddr(Node*, Node*);
   291  void	gbranch(int);
   292  void	patch(Prog*, int32);
   293  int	sconst(Node*);
   294  void	gpseudo(int, Sym*, Node*);
   295  void	gprefetch(Node*);
   296  void	gpcdata(int, int);
   297  
   298  /*
   299   * swt.c
   300   */
   301  int	swcmp(const void*, const void*);
   302  void	doswit(Node*);
   303  void	swit1(C1*, int, int32, Node*);
   304  void	swit2(C1*, int, int32, Node*);
   305  void	newcase(void);
   306  void	bitload(Node*, Node*, Node*, Node*, Node*);
   307  void	bitstore(Node*, Node*, Node*, Node*, Node*);
   308  int32	outstring(char*, int32);
   309  void	nullwarn(Node*, Node*);
   310  void	sextern(Sym*, Node*, int32, int32);
   311  void	gextern(Sym*, Node*, int32, int32);
   312  void	outcode(void);
   313  void	ieeedtod(Ieee*, double);
   314  
   315  /*
   316   * list
   317   */
   318  void	listinit(void);
   319  int	Pconv(Fmt*);
   320  int	Aconv(Fmt*);
   321  int	Dconv(Fmt*);
   322  int	Sconv(Fmt*);
   323  int	Rconv(Fmt*);
   324  int	Xconv(Fmt*);
   325  int	Bconv(Fmt*);
   326  
   327  /*
   328   * reg.c
   329   */
   330  Reg*	rega(void);
   331  int	rcmp(const void*, const void*);
   332  void	regopt(Prog*);
   333  void	addmove(Reg*, int, int, int);
   334  Bits	mkvar(Reg*, Adr*);
   335  void	prop(Reg*, Bits, Bits);
   336  void	loopit(Reg*, int32);
   337  void	synch(Reg*, Bits);
   338  uint32	allreg(uint32, Rgn*);
   339  void	paint1(Reg*, int);
   340  uint32	paint2(Reg*, int);
   341  void	paint3(Reg*, int, int32, int);
   342  void	addreg(Adr*, int);
   343  
   344  /*
   345   * peep.c
   346   */
   347  void	peep(void);
   348  void	excise(Reg*);
   349  Reg*	uniqp(Reg*);
   350  Reg*	uniqs(Reg*);
   351  int	regtyp(Adr*);
   352  int	anyvar(Adr*);
   353  int	subprop(Reg*);
   354  int	copyprop(Reg*);
   355  int	copy1(Adr*, Adr*, Reg*, int);
   356  int	copyu(Prog*, Adr*, Adr*);
   357  
   358  int	copyas(Adr*, Adr*);
   359  int	copyau(Adr*, Adr*);
   360  int	copysub(Adr*, Adr*, Adr*, int);
   361  int	copysub1(Prog*, Adr*, Adr*, int);
   362  
   363  int32	RtoB(int);
   364  int32	FtoB(int);
   365  int	BtoR(int32);
   366  int	BtoF(int32);
   367  
   368  #define	D_HI	D_NONE
   369  #define	D_LO	D_NONE
   370  
   371  /*
   372   * bound
   373   */
   374  void	comtarg(void);
   375  
   376  /*
   377   * com64
   378   */
   379  int	cond(int);
   380  int	com64(Node*);
   381  void	com64init(void);
   382  void	bool64(Node*);
   383  int32	lo64v(Node*);
   384  int32	hi64v(Node*);
   385  Node*	lo64(Node*);
   386  Node*	hi64(Node*);
   387  
   388  /*
   389   * div/mul
   390   */
   391  void	sdivgen(Node*, Node*, Node*, Node*);
   392  void	udivgen(Node*, Node*, Node*, Node*);
   393  void	sdiv2(int32, int, Node*, Node*);
   394  void	smod2(int32, int, Node*, Node*);
   395  void	mulgen(Type*, Node*, Node*);
   396  void	genmuladd(Node*, Node*, int, Node*);
   397  void	shiftit(Type*, Node*, Node*);
   398  
   399  #pragma	varargck	type	"A"	int
   400  #pragma	varargck	type	"B"	Bits
   401  #pragma	varargck	type	"D"	Adr*
   402  #pragma	varargck	type	"lD"	Adr*
   403  #pragma	varargck	type	"P"	Prog*
   404  #pragma	varargck	type	"R"	int
   405  #pragma	varargck	type	"S"	char*
   406  
   407  #define	D_X7	(D_X0+7)
   408  
   409  void	fgopcode(int, Node*, Node*, int, int);