github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/cmd/8c/gc.h (about)

     1  // Inferno utils/8c/gc.h
     2  // http://code.google.com/p/inferno-os/source/browse/utils/8c/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	"../8l/8.out.h"
    34  
    35  /*
    36   * 8c/386
    37   * Intel 386
    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		4
    44  #define	SZ_FLOAT	4
    45  #define	SZ_VLONG	8
    46  #define	SZ_DOUBLE	8
    47  #define	FNX		100
    48  
    49  typedef	struct	Case	Case;
    50  typedef	struct	C1	C1;
    51  typedef	struct	Reg	Reg;
    52  typedef	struct	Rgn	Rgn;
    53  typedef	struct	Renv	Renv;
    54  
    55  EXTERN	struct
    56  {
    57  	Node*	regtree;
    58  	Node*	basetree;
    59  	short	scale;
    60  	short	reg;
    61  	short	ptr;
    62  } idx;
    63  
    64  #define	A	((Addr*)0)
    65  
    66  #define	INDEXED	9
    67  
    68  #define	P	((Prog*)0)
    69  
    70  struct	Case
    71  {
    72  	Case*	link;
    73  	int32	val;
    74  	int32	label;
    75  	char	def;
    76  	char	isv;
    77  };
    78  #define	C	((Case*)0)
    79  
    80  struct	C1
    81  {
    82  	int32	val;
    83  	int32	label;
    84  };
    85  
    86  struct	Reg
    87  {
    88  	int32	pc;
    89  	int32	rpo;		/* reverse post ordering */
    90  
    91  	Bits	set;
    92  	Bits	use1;
    93  	Bits	use2;
    94  
    95  	Bits	refbehind;
    96  	Bits	refahead;
    97  	Bits	calbehind;
    98  	Bits	calahead;
    99  	Bits	regdiff;
   100  	Bits	act;
   101  
   102  	int32	regu;
   103  	int32	loop;		/* could be shorter */
   104  
   105  	Reg*	log5;
   106  	int32	active;
   107  
   108  	Reg*	p1;
   109  	Reg*	p2;
   110  	Reg*	p2link;
   111  	Reg*	s1;
   112  	Reg*	s2;
   113  	Reg*	link;
   114  	Prog*	prog;
   115  };
   116  #define	R	((Reg*)0)
   117  
   118  struct	Renv
   119  {
   120  	int	safe;
   121  	Node	base;
   122  	Node*	saved;
   123  	Node*	scope;
   124  };
   125  
   126  #define	NRGN	600
   127  struct	Rgn
   128  {
   129  	Reg*	enter;
   130  	short	cost;
   131  	short	varno;
   132  	short	regno;
   133  };
   134  
   135  EXTERN	int32	breakpc;
   136  EXTERN	int32	nbreak;
   137  EXTERN	Case*	cases;
   138  EXTERN	Node	constnode;
   139  EXTERN	Node	fconstnode;
   140  EXTERN	int32	continpc;
   141  EXTERN	int32	curarg;
   142  EXTERN	int32	cursafe;
   143  EXTERN	Prog*	lastp;
   144  EXTERN	int32	maxargsafe;
   145  EXTERN	int	mnstring;
   146  EXTERN	Node*	nodrat;
   147  EXTERN	Node*	nodret;
   148  EXTERN	Node*	nodsafe;
   149  EXTERN	int32	nrathole;
   150  EXTERN	int32	nstring;
   151  EXTERN	Prog*	p;
   152  EXTERN	int32	pc;
   153  EXTERN	Node	regnode;
   154  EXTERN	Node	fregnode0;
   155  EXTERN	Node	fregnode1;
   156  EXTERN	char	string[NSNAME];
   157  EXTERN	Sym*	symrathole;
   158  EXTERN	Node	znode;
   159  EXTERN	Prog	zprog;
   160  EXTERN	int	reg[D_NONE];
   161  EXTERN	int32	exregoffset;
   162  EXTERN	int32	exfregoffset;
   163  
   164  #define	BLOAD(r)	band(bnot(r->refbehind), r->refahead)
   165  #define	BSTORE(r)	band(bnot(r->calbehind), r->calahead)
   166  #define	LOAD(r)		(~r->refbehind.b[z] & r->refahead.b[z])
   167  #define	STORE(r)	(~r->calbehind.b[z] & r->calahead.b[z])
   168  
   169  #define	bset(a,n)	((a).b[(n)/32]&(1L<<(n)%32))
   170  
   171  #define	CLOAD	5
   172  #define	CREF	5
   173  #define	CINF	1000
   174  #define	LOOP	3
   175  
   176  EXTERN	Rgn	region[NRGN];
   177  EXTERN	Rgn*	rgp;
   178  EXTERN	int	nregion;
   179  EXTERN	int	nvar;
   180  
   181  EXTERN	Bits	externs;
   182  EXTERN	Bits	params;
   183  EXTERN	Bits	consts;
   184  EXTERN	Bits	addrs;
   185  
   186  EXTERN	int32	regbits;
   187  EXTERN	int32	exregbits;
   188  
   189  EXTERN	int	change;
   190  EXTERN	int	suppress;
   191  
   192  EXTERN	Reg*	firstr;
   193  EXTERN	Reg*	lastr;
   194  EXTERN	Reg	zreg;
   195  EXTERN	Reg*	freer;
   196  EXTERN	int32*	idom;
   197  EXTERN	Reg**	rpo2r;
   198  EXTERN	int32	maxnr;
   199  
   200  extern	char*	anames[];
   201  
   202  /*
   203   * sgen.c
   204   */
   205  void	codgen(Node*, Node*);
   206  void	gen(Node*);
   207  void	noretval(int);
   208  void	usedset(Node*, int);
   209  void	xcom(Node*);
   210  void	indx(Node*);
   211  int	bcomplex(Node*, Node*);
   212  Prog*	gtext(Sym*, int32);
   213  vlong	argsize(int);
   214  
   215  /*
   216   * cgen.c
   217   */
   218  void	zeroregm(Node*);
   219  void	cgen(Node*, Node*);
   220  void	reglcgen(Node*, Node*, Node*);
   221  void	lcgen(Node*, Node*);
   222  void	bcgen(Node*, int);
   223  void	boolgen(Node*, int, Node*);
   224  void	sugen(Node*, Node*, int32);
   225  int	needreg(Node*, int);
   226  
   227  /*
   228   * cgen64.c
   229   */
   230  int	vaddr(Node*, int);
   231  void	loadpair(Node*, Node*);
   232  int	cgen64(Node*, Node*);
   233  void	testv(Node*, int);
   234  
   235  /*
   236   * txt.c
   237   */
   238  void	ginit(void);
   239  void	gclean(void);
   240  void	nextpc(void);
   241  void	gargs(Node*, Node*, Node*);
   242  void	garg1(Node*, Node*, Node*, int, Node**);
   243  Node*	nodconst(int32);
   244  Node*	nodfconst(double);
   245  int	nodreg(Node*, Node*, int);
   246  int	isreg(Node*, int);
   247  void	regret(Node*, Node*, Type*, int);
   248  void	regalloc(Node*, Node*, Node*);
   249  void	regfree(Node*);
   250  void	regialloc(Node*, Node*, Node*);
   251  void	regsalloc(Node*, Node*);
   252  void	regaalloc1(Node*, Node*);
   253  void	regaalloc(Node*, Node*);
   254  void	regind(Node*, Node*);
   255  void	gprep(Node*, Node*);
   256  void	naddr(Node*, Addr*);
   257  void	gmove(Node*, Node*);
   258  void	gins(int a, Node*, Node*);
   259  void	fgopcode(int, Node*, Node*, int, int);
   260  void	gopcode(int, Type*, Node*, Node*);
   261  int	samaddr(Node*, Node*);
   262  void	gbranch(int);
   263  void	patch(Prog*, int32);
   264  int	sconst(Node*);
   265  void	gpseudo(int, Sym*, Node*);
   266  void	gprefetch(Node*);
   267  void	gpcdata(int, int);
   268  
   269  /*
   270   * swt.c
   271   */
   272  int	swcmp(const void*, const void*);
   273  void	doswit(Node*);
   274  void	swit1(C1*, int, int32, Node*);
   275  void	swit2(C1*, int, int32, Node*);
   276  void	newcase(void);
   277  void	bitload(Node*, Node*, Node*, Node*, Node*);
   278  void	bitstore(Node*, Node*, Node*, Node*, Node*);
   279  int32	outstring(char*, int32);
   280  void	nullwarn(Node*, Node*);
   281  void	sextern(Sym*, Node*, int32, int32);
   282  void	gextern(Sym*, Node*, int32, int32);
   283  void	outcode(void);
   284  
   285  /*
   286   * list
   287   */
   288  void	listinit(void);
   289  
   290  /*
   291   * reg.c
   292   */
   293  Reg*	rega(void);
   294  int	rcmp(const void*, const void*);
   295  void	regopt(Prog*);
   296  void	addmove(Reg*, int, int, int);
   297  Bits	mkvar(Reg*, Addr*);
   298  void	prop(Reg*, Bits, Bits);
   299  void	loopit(Reg*, int32);
   300  void	synch(Reg*, Bits);
   301  uint32	allreg(uint32, Rgn*);
   302  void	paint1(Reg*, int);
   303  uint32	paint2(Reg*, int);
   304  void	paint3(Reg*, int, int32, int);
   305  void	addreg(Addr*, int);
   306  
   307  /*
   308   * peep.c
   309   */
   310  void	peep(void);
   311  void	excise(Reg*);
   312  Reg*	uniqp(Reg*);
   313  Reg*	uniqs(Reg*);
   314  int	regtyp(Addr*);
   315  int	anyvar(Addr*);
   316  int	subprop(Reg*);
   317  int	copyprop(Reg*);
   318  int	copy1(Addr*, Addr*, Reg*, int);
   319  int	copyu(Prog*, Addr*, Addr*);
   320  
   321  int	copyas(Addr*, Addr*);
   322  int	copyau(Addr*, Addr*);
   323  int	copysub(Addr*, Addr*, Addr*, int);
   324  int	copysub1(Prog*, Addr*, Addr*, int);
   325  
   326  int32	RtoB(int);
   327  int32	FtoB(int);
   328  int	BtoR(int32);
   329  int	BtoF(int32);
   330  
   331  #define	D_HI	D_NONE
   332  #define	D_LO	D_NONE
   333  
   334  /*
   335   * bound
   336   */
   337  void	comtarg(void);
   338  
   339  /*
   340   * com64
   341   */
   342  int	cond(int);
   343  int	com64(Node*);
   344  void	com64init(void);
   345  void	bool64(Node*);
   346  int32	lo64v(Node*);
   347  int32	hi64v(Node*);
   348  Node*	lo64(Node*);
   349  Node*	hi64(Node*);
   350  
   351  /*
   352   * div/mul
   353   */
   354  void	sdivgen(Node*, Node*, Node*, Node*);
   355  void	udivgen(Node*, Node*, Node*, Node*);
   356  void	sdiv2(int32, int, Node*, Node*);
   357  void	smod2(int32, int, Node*, Node*);
   358  void	mulgen(Type*, Node*, Node*);
   359  void	genmuladd(Node*, Node*, int, Node*);
   360  void	shiftit(Type*, Node*, Node*);
   361  
   362  /* wrecklessly steal a field */
   363  
   364  #define	rplink	label