github.com/ccccaoqing/test@v0.0.0-20220510085219-3985d23445c0/src/cmd/gc/go.h (about)

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include	<bio.h>
     6  #include	<link.h>
     7  
     8  #undef OAPPEND
     9  
    10  // avoid <ctype.h>
    11  #undef isblank
    12  #define isblank goisblank
    13  
    14  #ifndef	EXTERN
    15  #define	EXTERN	extern
    16  #endif
    17  
    18  #undef	BUFSIZ
    19  
    20  // The parser's maximum stack size.
    21  // We have to use a #define macro here since yacc
    22  // or bison will check for its definition and use
    23  // a potentially smaller value if it is undefined.
    24  #define YYMAXDEPTH 500
    25  
    26  enum
    27  {
    28  	NHUNK		= 50000,
    29  	BUFSIZ		= 8192,
    30  	NSYMB		= 500,
    31  	NHASH		= 1024,
    32  	STRINGSZ	= 200,
    33  	MAXALIGN	= 7,
    34  	UINF		= 100,
    35  
    36  	PRIME1		= 3,
    37  
    38  	AUNK		= 100,
    39  
    40  	// These values are known by runtime.
    41  	// The MEMx and NOEQx values must run in parallel.  See algtype.
    42  	AMEM		= 0,
    43  	AMEM0,
    44  	AMEM8,
    45  	AMEM16,
    46  	AMEM32,
    47  	AMEM64,
    48  	AMEM128,
    49  	ANOEQ,
    50  	ANOEQ0,
    51  	ANOEQ8,
    52  	ANOEQ16,
    53  	ANOEQ32,
    54  	ANOEQ64,
    55  	ANOEQ128,
    56  	ASTRING,
    57  	AINTER,
    58  	ANILINTER,
    59  	ASLICE,
    60  	AFLOAT32,
    61  	AFLOAT64,
    62  	ACPLX64,
    63  	ACPLX128,
    64  
    65  	BADWIDTH	= -1000000000,
    66  	
    67  	MaxStackVarSize = 10*1024*1024,
    68  };
    69  
    70  extern vlong	MAXWIDTH;
    71  
    72  /*
    73   * note this is the representation
    74   * of the compilers string literals,
    75   * it is not the runtime representation
    76   */
    77  typedef	struct	Strlit	Strlit;
    78  struct	Strlit
    79  {
    80  	int32	len;
    81  	char	s[1]; // variable
    82  };
    83  
    84  enum
    85  {
    86  	Mpscale	= 29,		// safely smaller than bits in a long
    87  	Mpprec	= 16,		// Mpscale*Mpprec is max number of bits
    88  	Mpnorm	= Mpprec - 1,	// significant words in a normalized float
    89  	Mpbase	= 1L << Mpscale,
    90  	Mpsign	= Mpbase >> 1,
    91  	Mpmask	= Mpbase - 1,
    92  	Mpdebug	= 0,
    93  };
    94  
    95  typedef	struct	Mpint	Mpint;
    96  struct	Mpint
    97  {
    98  	long	a[Mpprec];
    99  	uchar	neg;
   100  	uchar	ovf;
   101  };
   102  
   103  typedef	struct	Mpflt	Mpflt;
   104  struct	Mpflt
   105  {
   106  	Mpint	val;
   107  	short	exp;
   108  };
   109  
   110  typedef	struct	Mpcplx	Mpcplx;
   111  struct	Mpcplx
   112  {
   113  	Mpflt	real;
   114  	Mpflt	imag;
   115  };
   116  
   117  typedef	struct	Val	Val;
   118  struct	Val
   119  {
   120  	short	ctype;
   121  	union
   122  	{
   123  		short	reg;		// OREGISTER
   124  		short	bval;		// bool value CTBOOL
   125  		Mpint*	xval;		// int CTINT, rune CTRUNE
   126  		Mpflt*	fval;		// float CTFLT
   127  		Mpcplx*	cval;		// float CTCPLX
   128  		Strlit*	sval;		// string CTSTR
   129  	} u;
   130  };
   131  
   132  // prevent incompatible type signatures between libgc and 8g on Plan 9
   133  #pragma incomplete struct Array
   134  
   135  typedef	struct	Array	Array;
   136  typedef	struct	Bvec	Bvec;
   137  typedef	struct	Pkg Pkg;
   138  typedef	struct	Sym	Sym;
   139  typedef	struct	Node	Node;
   140  typedef	struct	NodeList	NodeList;
   141  typedef	struct	Type	Type;
   142  typedef	struct	Label	Label;
   143  
   144  struct	Type
   145  {
   146  	uchar	etype;
   147  	uchar	nointerface;
   148  	uchar	noalg;
   149  	uchar	chan;
   150  	uchar	trecur;		// to detect loops
   151  	uchar	printed;
   152  	uchar	embedded;	// TFIELD embedded type
   153  	uchar	siggen;
   154  	uchar	funarg;		// on TSTRUCT and TFIELD
   155  	uchar	copyany;
   156  	uchar	local;		// created in this file
   157  	uchar	deferwidth;
   158  	uchar	broke;  	// broken type definition.
   159  	uchar	isddd;		// TFIELD is ... argument
   160  	uchar	align;
   161  	uchar	haspointers;	// 0 unknown, 1 no, 2 yes
   162  
   163  	Node*	nod;		// canonical OTYPE node
   164  	Type*	orig;		// original type (type literal or predefined type)
   165  	int		lineno;
   166  
   167  	// TFUNC
   168  	int	thistuple;
   169  	int	outtuple;
   170  	int	intuple;
   171  	uchar	outnamed;
   172  
   173  	Type*	method;
   174  	Type*	xmethod;
   175  
   176  	Sym*	sym;
   177  	int32	vargen;		// unique name for OTYPE/ONAME
   178  
   179  	Node*	nname;
   180  	vlong	argwid;
   181  
   182  	// most nodes
   183  	Type*	type;   	// actual type for TFIELD, element type for TARRAY, TCHAN, TMAP, TPTRxx
   184  	vlong	width;  	// offset in TFIELD, width in all others
   185  
   186  	// TFIELD
   187  	Type*	down;		// next struct field, also key type in TMAP
   188  	Type*	outer;		// outer struct
   189  	Strlit*	note;		// literal string annotation
   190  
   191  	// TARRAY
   192  	vlong	bound;		// negative is dynamic array
   193  
   194  	// TMAP
   195  	Type*	bucket;		// internal type representing a hash bucket
   196  	Type*	hmap;		// internal type representing a Hmap (map header object)
   197  	Type*	hiter;		// internal type representing hash iterator state
   198  	Type*	map;		// link from the above 3 internal types back to the map type.
   199  
   200  	int32	maplineno;	// first use of TFORW as map key
   201  	int32	embedlineno;	// first use of TFORW as embedded type
   202  	
   203  	// for TFORW, where to copy the eventual value to
   204  	NodeList	*copyto;
   205  	
   206  	Node	*lastfn;	// for usefield
   207  };
   208  #define	T	((Type*)0)
   209  
   210  typedef struct InitEntry InitEntry;
   211  typedef struct InitPlan InitPlan;
   212  
   213  struct InitEntry
   214  {
   215  	vlong xoffset;  // struct, array only
   216  	Node *key;  // map only
   217  	Node *expr;
   218  };
   219  
   220  struct InitPlan
   221  {
   222  	vlong lit;  // bytes of initialized non-zero literals
   223  	vlong zero;  // bytes of zeros
   224  	vlong expr;  // bytes of run-time computed expressions
   225  
   226  	InitEntry *e;
   227  	int len;
   228  	int cap;
   229  };
   230  
   231  enum
   232  {
   233  	EscUnknown,
   234  	EscHeap,
   235  	EscScope,
   236  	EscNone,
   237  	EscReturn,
   238  	EscNever,
   239  	EscBits = 3,
   240  	EscMask = (1<<EscBits) - 1,
   241  	EscContentEscapes = 1<<EscBits, // value obtained by indirect of parameter escapes to some returned result
   242  	EscReturnBits = EscBits+1,
   243  };
   244  
   245  struct	Node
   246  {
   247  	// Tree structure.
   248  	// Generic recursive walks should follow these fields.
   249  	Node*	left;
   250  	Node*	right;
   251  	Node*	ntest;
   252  	Node*	nincr;
   253  	NodeList*	ninit;
   254  	NodeList*	nbody;
   255  	NodeList*	nelse;
   256  	NodeList*	list;
   257  	NodeList*	rlist;
   258  
   259  	uchar	op;
   260  	uchar	nointerface;
   261  	uchar	ullman;		// sethi/ullman number
   262  	uchar	addable;	// type of addressability - 0 is not addressable
   263  	uchar	trecur;		// to detect loops
   264  	uchar	etype;		// op for OASOP, etype for OTYPE, exclam for export
   265  	uchar	bounded;	// bounds check unnecessary
   266  	uchar	class;		// PPARAM, PAUTO, PEXTERN, etc
   267  	uchar	method;		// OCALLMETH name
   268  	uchar	embedded;	// ODCLFIELD embedded type
   269  	uchar	colas;		// OAS resulting from :=
   270  	uchar	diag;		// already printed error about this
   271  	uchar	noescape;	// func arguments do not escape
   272  	uchar	nosplit;	// func should not execute on separate stack
   273  	uchar	builtin;	// built-in name, like len or close
   274  	uchar	walkdef;
   275  	uchar	typecheck;
   276  	uchar	local;
   277  	uchar	dodata;
   278  	uchar	initorder;
   279  	uchar	used;
   280  	uchar	isddd;
   281  	uchar	readonly;
   282  	uchar	implicit;
   283  	uchar	addrtaken;	// address taken, even if not moved to heap
   284  	uchar	dupok;	// duplicate definitions ok (for func)
   285  	uchar	wrapper;	// is method wrapper (for func)
   286  	uchar	reslice;	// this is a reslice x = x[0:y] or x = append(x, ...)
   287  	schar	likely; // likeliness of if statement
   288  	uchar	hasbreak;	// has break statement
   289  	uchar	needzero; // if it contains pointers, needs to be zeroed on function entry
   290  	uchar	needctxt;	// function uses context register (has closure variables)
   291  	uint	esc;		// EscXXX
   292  	int	funcdepth;
   293  
   294  	// most nodes
   295  	Type*	type;
   296  	Node*	orig;		// original form, for printing, and tracking copies of ONAMEs
   297  
   298  	// func
   299  	Node*	nname;
   300  	Node*	shortname;
   301  	NodeList*	enter;
   302  	NodeList*	exit;
   303  	NodeList*	cvars;	// closure params
   304  	NodeList*	dcl;	// autodcl for this func/closure
   305  	NodeList*	inl;	// copy of the body for use in inlining
   306  	NodeList*	inldcl;	// copy of dcl for use in inlining
   307  
   308  	// OLITERAL/OREGISTER
   309  	Val	val;
   310  
   311  	// ONAME
   312  	Node*	ntype;
   313  	Node*	defn;	// ONAME: initializing assignment; OLABEL: labeled statement
   314  	Node*	pack;	// real package for import . names
   315  	Node*	curfn;	// function for local variables
   316  	Type*	paramfld; // TFIELD for this PPARAM; also for ODOT, curfn
   317  
   318  	// ONAME func param with PHEAP
   319  	Node*	heapaddr;	// temp holding heap address of param
   320  	Node*	stackparam;	// OPARAM node referring to stack copy of param
   321  	Node*	alloc;	// allocation call
   322  
   323  	// ONAME closure param with PPARAMREF
   324  	Node*	outer;	// outer PPARAMREF in nested closure
   325  	Node*	closure;	// ONAME/PHEAP <-> ONAME/PPARAMREF
   326  
   327  	// ONAME substitute while inlining
   328  	Node* inlvar;
   329  
   330  	// OPACK
   331  	Pkg*	pkg;
   332  	
   333  	// OARRAYLIT, OMAPLIT, OSTRUCTLIT.
   334  	InitPlan*	initplan;
   335  
   336  	// Escape analysis.
   337  	NodeList* escflowsrc;	// flow(this, src)
   338  	NodeList* escretval;	// on OCALLxxx, list of dummy return values
   339  	int	escloopdepth;	// -1: global, 0: return variables, 1:function top level, increased inside function for every loop or label to mark scopes
   340  
   341  	Sym*	sym;		// various
   342  	int32	vargen;		// unique name for OTYPE/ONAME
   343  	int32	lineno;
   344  	int32	endlineno;
   345  	vlong	xoffset;
   346  	vlong	stkdelta;	// offset added by stack frame compaction phase.
   347  	int32	ostk;
   348  	int32	iota;
   349  	uint32	walkgen;
   350  	int32	esclevel;
   351  	void*	opt;	// for optimization passes
   352  };
   353  #define	N	((Node*)0)
   354  
   355  /*
   356   * Every node has a walkgen field.
   357   * If you want to do a traversal of a node graph that
   358   * might contain duplicates and want to avoid
   359   * visiting the same nodes twice, increment walkgen
   360   * before starting.  Then before processing a node, do
   361   *
   362   *	if(n->walkgen == walkgen)
   363   *		return;
   364   *	n->walkgen = walkgen;
   365   *
   366   * Such a walk cannot call another such walk recursively,
   367   * because of the use of the global walkgen.
   368   */
   369  EXTERN	uint32	walkgen;
   370  
   371  struct	NodeList
   372  {
   373  	Node*	n;
   374  	NodeList*	next;
   375  	NodeList*	end;
   376  };
   377  
   378  enum
   379  {
   380  	SymExport	= 1<<0,	// to be exported
   381  	SymPackage	= 1<<1,
   382  	SymExported	= 1<<2,	// already written out by export
   383  	SymUniq		= 1<<3,
   384  	SymSiggen	= 1<<4,
   385  };
   386  
   387  struct	Sym
   388  {
   389  	ushort	lexical;
   390  	uchar	flags;
   391  	uchar	sym;		// huffman encoding in object file
   392  	Sym*	link;
   393  	int32	npkg;	// number of imported packages with this name
   394  	uint32	uniqgen;
   395  	Pkg*	importdef;	// where imported definition was found
   396  
   397  	// saved and restored by dcopy
   398  	Pkg*	pkg;
   399  	char*	name;		// variable name
   400  	Node*	def;		// definition: ONAME OTYPE OPACK or OLITERAL
   401  	Label*	label;	// corresponding label (ephemeral)
   402  	int32	block;		// blocknumber to catch redeclaration
   403  	int32	lastlineno;	// last declaration for diagnostic
   404  	Pkg*	origpkg;	// original package for . import
   405  	LSym*	lsym;
   406  };
   407  #define	S	((Sym*)0)
   408  
   409  EXTERN	Sym*	dclstack;
   410  
   411  struct	Pkg
   412  {
   413  	char*	name;		// package name
   414  	Strlit*	path;		// string literal used in import statement
   415  	Sym*	pathsym;
   416  	char*	prefix;		// escaped path for use in symbol table
   417  	Pkg*	link;
   418  	uchar	imported;	// export data of this package was parsed
   419  	char	exported;	// import line written in export data
   420  	char	direct;	// imported directly
   421  	char	safe;	// whether the package is marked as safe
   422  };
   423  
   424  typedef	struct	Iter	Iter;
   425  struct	Iter
   426  {
   427  	int	done;
   428  	Type*	tfunc;
   429  	Type*	t;
   430  	Node**	an;
   431  	Node*	n;
   432  };
   433  
   434  // Node ops.
   435  enum
   436  {
   437  	OXXX,
   438  
   439  	// names
   440  	ONAME,	// var, const or func name
   441  	ONONAME,	// unnamed arg or return value: f(int, string) (int, error) { etc }
   442  	OTYPE,	// type name
   443  	OPACK,	// import
   444  	OLITERAL, // literal
   445  
   446  	// expressions
   447  	OADD,	// x + y
   448  	OSUB,	// x - y
   449  	OOR,	// x | y
   450  	OXOR,	// x ^ y
   451  	OADDSTR,	// s + "foo"
   452  	OADDR,	// &x
   453  	OANDAND,	// b0 && b1
   454  	OAPPEND,	// append
   455  	OARRAYBYTESTR,	// string(bytes)
   456  	OARRAYBYTESTRTMP, // string(bytes) ephemeral
   457  	OARRAYRUNESTR,	// string(runes)
   458  	OSTRARRAYBYTE,	// []byte(s)
   459  	OSTRARRAYRUNE,	// []rune(s)
   460  	OAS,	// x = y or x := y
   461  	OAS2,	// x, y, z = xx, yy, zz
   462  	OAS2FUNC,	// x, y = f()
   463  	OAS2RECV,	// x, ok = <-c
   464  	OAS2MAPR,	// x, ok = m["foo"]
   465  	OAS2DOTTYPE,	// x, ok = I.(int)
   466  	OASOP,	// x += y
   467  	OCALL,	// function call, method call or type conversion, possibly preceded by defer or go.
   468  	OCALLFUNC,	// f()
   469  	OCALLMETH,	// t.Method()
   470  	OCALLINTER,	// err.Error()
   471  	OCALLPART,	// t.Method (without ())
   472  	OCAP,	// cap
   473  	OCLOSE,	// close
   474  	OCLOSURE,	// f = func() { etc }
   475  	OCMPIFACE,	// err1 == err2
   476  	OCMPSTR,	// s1 == s2
   477  	OCOMPLIT,	// composite literal, typechecking may convert to a more specific OXXXLIT.
   478  	OMAPLIT,	// M{"foo":3, "bar":4}
   479  	OSTRUCTLIT,	// T{x:3, y:4}
   480  	OARRAYLIT,	// [2]int{3, 4}
   481  	OPTRLIT,	// &T{x:3, y:4}
   482  	OCONV,	// var i int; var u uint; i = int(u)
   483  	OCONVIFACE,	// I(t)
   484  	OCONVNOP,	// type Int int; var i int; var j Int; i = int(j)
   485  	OCOPY,	// copy
   486  	ODCL,	// var x int
   487  	ODCLFUNC,	// func f() or func (r) f()
   488  	ODCLFIELD,	// struct field, interface field, or func/method argument/return value.
   489  	ODCLCONST,	// const pi = 3.14
   490  	ODCLTYPE,	// type Int int
   491  	ODELETE,	// delete
   492  	ODOT,	// t.x
   493  	ODOTPTR,	// p.x that is implicitly (*p).x
   494  	ODOTMETH,	// t.Method
   495  	ODOTINTER,	// err.Error
   496  	OXDOT,	// t.x, typechecking may convert to a more specific ODOTXXX.
   497  	ODOTTYPE,	// e = err.(MyErr)
   498  	ODOTTYPE2,	// e, ok = err.(MyErr)
   499  	OEQ,	// x == y
   500  	ONE,	// x != y
   501  	OLT,	// x < y
   502  	OLE,	// x <= y
   503  	OGE,	// x >= y
   504  	OGT,	// x > y
   505  	OIND,	// *p
   506  	OINDEX,	// a[i]
   507  	OINDEXMAP,	// m[s]
   508  	OKEY,	// The x:3 in t{x:3, y:4}, the 1:2 in a[1:2], the 2:20 in [3]int{2:20}, etc.
   509  	OPARAM,	// The on-stack copy of a parameter or return value that escapes.
   510  	OLEN,	// len
   511  	OMAKE,	// make, typechecking may convert to a more specific OMAKEXXX.
   512  	OMAKECHAN,	// make(chan int)
   513  	OMAKEMAP,	// make(map[string]int)
   514  	OMAKESLICE,	// make([]int, 0)
   515  	OMUL,	// x * y
   516  	ODIV,	// x / y
   517  	OMOD,	// x % y
   518  	OLSH,	// x << u
   519  	ORSH,	// x >> u
   520  	OAND,	// x & y
   521  	OANDNOT,	// x &^ y
   522  	ONEW,	// new
   523  	ONOT,	// !b
   524  	OCOM,	// ^x
   525  	OPLUS,	// +x
   526  	OMINUS,	// -y
   527  	OOROR,	// b1 || b2
   528  	OPANIC,	// panic
   529  	OPRINT,	// print
   530  	OPRINTN,	// println
   531  	OPAREN,	// (x)
   532  	OSEND,	// c <- x
   533  	OSLICE,	// v[1:2], typechecking may convert to a more specific OSLICEXXX.
   534  	OSLICEARR,	// a[1:2]
   535  	OSLICESTR,	// s[1:2]
   536  	OSLICE3,	// v[1:2:3], typechecking may convert to OSLICE3ARR.
   537  	OSLICE3ARR,	// a[1:2:3]
   538  	ORECOVER,	// recover
   539  	ORECV,	// <-c
   540  	ORUNESTR,	// string(i)
   541  	OSELRECV,	// case x = <-c:
   542  	OSELRECV2,	// case x, ok = <-c:
   543  	OIOTA,	// iota
   544  	OREAL,	// real
   545  	OIMAG,	// imag
   546  	OCOMPLEX,	// complex
   547  
   548  	// statements
   549  	OBLOCK,	// block of code
   550  	OBREAK,	// break
   551  	OCASE,	// case, after being verified by swt.c's casebody.
   552  	OXCASE,	// case, before verification.
   553  	OCONTINUE,	// continue
   554  	ODEFER,	// defer
   555  	OEMPTY,	// no-op
   556  	OFALL,	// fallthrough, after being verified by swt.c's casebody.
   557  	OXFALL,	// fallthrough, before verification.
   558  	OFOR,	// for
   559  	OGOTO,	// goto
   560  	OIF,	// if
   561  	OLABEL,	// label:
   562  	OPROC,	// go
   563  	ORANGE,	// range
   564  	ORETURN,	// return
   565  	OSELECT,	// select
   566  	OSWITCH,	// switch x
   567  	OTYPESW,	// switch err.(type)
   568  
   569  	// types
   570  	OTCHAN,	// chan int
   571  	OTMAP,	// map[string]int
   572  	OTSTRUCT,	// struct{}
   573  	OTINTER,	// interface{}
   574  	OTFUNC,	// func()
   575  	OTARRAY,	// []int, [8]int, [N]int or [...]int
   576  
   577  	// misc
   578  	ODDD,	// func f(args ...int) or f(l...) or var a = [...]int{0, 1, 2}.
   579  	ODDDARG,	// func f(args ...int), introduced by escape analysis.
   580  	OINLCALL,	// intermediary representation of an inlined call.
   581  	OEFACE,	// itable and data words of an empty-interface value.
   582  	OITAB,	// itable word of an interface value.
   583  	OSPTR,  // base pointer of a slice or string.
   584  	OCLOSUREVAR, // variable reference at beginning of closure function
   585  	OCFUNC,	// reference to c function pointer (not go func value)
   586  	OCHECKNIL, // emit code to ensure pointer/interface not nil
   587  	OVARKILL, // variable is dead
   588  
   589  	// arch-specific registers
   590  	OREGISTER,	// a register, such as AX.
   591  	OINDREG,	// offset plus indirect of a register, such as 8(SP).
   592  
   593  	// 386/amd64-specific opcodes
   594  	OCMP,	// compare: ACMP.
   595  	ODEC,	// decrement: ADEC.
   596  	OINC,	// increment: AINC.
   597  	OEXTEND,	// extend: ACWD/ACDQ/ACQO.
   598  	OHMUL, // high mul: AMUL/AIMUL for unsigned/signed (OMUL uses AIMUL for both).
   599  	OLROT,	// left rotate: AROL.
   600  	ORROTC, // right rotate-carry: ARCR.
   601  	ORETJMP,	// return to other function
   602  
   603  	OEND,
   604  };
   605  
   606  enum
   607  {
   608  	Txxx,			// 0
   609  
   610  	TINT8,	TUINT8,		// 1
   611  	TINT16,	TUINT16,
   612  	TINT32,	TUINT32,
   613  	TINT64,	TUINT64,
   614  	TINT, TUINT, TUINTPTR,
   615  
   616  	TCOMPLEX64,		// 12
   617  	TCOMPLEX128,
   618  
   619  	TFLOAT32,		// 14
   620  	TFLOAT64,
   621  
   622  	TBOOL,			// 16
   623  
   624  	TPTR32, TPTR64,		// 17
   625  
   626  	TFUNC,			// 19
   627  	TARRAY,
   628  	T_old_DARRAY,
   629  	TSTRUCT,		// 22
   630  	TCHAN,
   631  	TMAP,
   632  	TINTER,			// 25
   633  	TFORW,
   634  	TFIELD,
   635  	TANY,
   636  	TSTRING,
   637  	TUNSAFEPTR,
   638  
   639  	// pseudo-types for literals
   640  	TIDEAL,			// 31
   641  	TNIL,
   642  	TBLANK,
   643  
   644  	// pseudo-type for frame layout
   645  	TFUNCARGS,
   646  	TCHANARGS,
   647  	TINTERMETH,
   648  
   649  	NTYPE,
   650  };
   651  
   652  enum
   653  {
   654  	CTxxx,
   655  
   656  	CTINT,
   657  	CTRUNE,
   658  	CTFLT,
   659  	CTCPLX,
   660  	CTSTR,
   661  	CTBOOL,
   662  	CTNIL,
   663  };
   664  
   665  enum
   666  {
   667  	/* types of channel */
   668  	/* must match ../../pkg/nreflect/type.go:/Chandir */
   669  	Cxxx,
   670  	Crecv = 1<<0,
   671  	Csend = 1<<1,
   672  	Cboth = Crecv | Csend,
   673  };
   674  
   675  // declaration context
   676  enum
   677  {
   678  	Pxxx,
   679  
   680  	PEXTERN,	// global variable
   681  	PAUTO,		// local variables
   682  	PPARAM,		// input arguments
   683  	PPARAMOUT,	// output results
   684  	PPARAMREF,	// closure variable reference
   685  	PFUNC,		// global function
   686  
   687  	PDISCARD,	// discard during parse of duplicate import
   688  
   689  	PHEAP = 1<<7,	// an extra bit to identify an escaped variable
   690  };
   691  
   692  enum
   693  {
   694  	Etop = 1<<1,		// evaluated at statement level
   695  	Erv = 1<<2,		// evaluated in value context
   696  	Etype = 1<<3,
   697  	Ecall = 1<<4,		// call-only expressions are ok
   698  	Efnstruct = 1<<5,	// multivalue function returns are ok
   699  	Eiota = 1<<6,		// iota is ok
   700  	Easgn = 1<<7,		// assigning to expression
   701  	Eindir = 1<<8,		// indirecting through expression
   702  	Eaddr = 1<<9,		// taking address of expression
   703  	Eproc = 1<<10,		// inside a go statement
   704  	Ecomplit = 1<<11,	// type in composite literal
   705  };
   706  
   707  #define	BITS	5
   708  #define	NVAR	(BITS*sizeof(uint32)*8)
   709  
   710  typedef	struct	Bits	Bits;
   711  struct	Bits
   712  {
   713  	uint32	b[BITS];
   714  };
   715  
   716  EXTERN	Bits	zbits;
   717  
   718  struct Bvec
   719  {
   720  	int32	n;	// number of bits
   721  	uint32	b[];
   722  };
   723  
   724  typedef	struct	Var	Var;
   725  struct	Var
   726  {
   727  	vlong	offset;
   728  	Node*	node;
   729  	Var*	nextinnode;
   730  	int	width;
   731  	char	name;
   732  	char	etype;
   733  	char	addr;
   734  };
   735  
   736  EXTERN	Var	var[NVAR];
   737  
   738  typedef	struct	Typedef	Typedef;
   739  struct	Typedef
   740  {
   741  	char*	name;
   742  	int	etype;
   743  	int	sameas;
   744  };
   745  
   746  extern	Typedef	typedefs[];
   747  
   748  typedef	struct	Sig	Sig;
   749  struct	Sig
   750  {
   751  	char*	name;
   752  	Pkg*	pkg;
   753  	Sym*	isym;
   754  	Sym*	tsym;
   755  	Type*	type;
   756  	Type*	mtype;
   757  	int32	offset;
   758  	Sig*	link;
   759  };
   760  
   761  typedef	struct	Io	Io;
   762  struct	Io
   763  {
   764  	char*	infile;
   765  	Biobuf*	bin;
   766  	int32	ilineno;
   767  	int	nlsemi;
   768  	int	eofnl;
   769  	int	last;
   770  	int	peekc;
   771  	int	peekc1;	// second peekc for ...
   772  	char*	cp;	// used for content when bin==nil
   773  	int	importsafe;
   774  };
   775  
   776  typedef	struct	Dlist	Dlist;
   777  struct	Dlist
   778  {
   779  	Type*	field;
   780  };
   781  
   782  typedef	struct	Idir	Idir;
   783  struct Idir
   784  {
   785  	Idir*	link;
   786  	char*	dir;
   787  };
   788  
   789  /*
   790   * argument passing to/from
   791   * smagic and umagic
   792   */
   793  typedef	struct	Magic Magic;
   794  struct	Magic
   795  {
   796  	int	w;	// input for both - width
   797  	int	s;	// output for both - shift
   798  	int	bad;	// output for both - unexpected failure
   799  
   800  	// magic multiplier for signed literal divisors
   801  	int64	sd;	// input - literal divisor
   802  	int64	sm;	// output - multiplier
   803  
   804  	// magic multiplier for unsigned literal divisors
   805  	uint64	ud;	// input - literal divisor
   806  	uint64	um;	// output - multiplier
   807  	int	ua;	// output - adder
   808  };
   809  
   810  struct	Label
   811  {
   812  	uchar	used;
   813  	Sym*	sym;
   814  	Node*	def;
   815  	NodeList*	use;
   816  	Label*	link;
   817  	
   818  	// for use during gen
   819  	Prog*	gotopc;	// pointer to unresolved gotos
   820  	Prog*	labelpc;	// pointer to code
   821  	Prog*	breakpc;	// pointer to code
   822  	Prog*	continpc;	// pointer to code
   823  };
   824  #define	L	((Label*)0)
   825  
   826  /*
   827   * note this is the runtime representation
   828   * of the compilers arrays.
   829   *
   830   * typedef	struct
   831   * {				// must not move anything
   832   *	uchar	array[8];	// pointer to data
   833   *	uchar	nel[4];		// number of elements
   834   *	uchar	cap[4];		// allocated number of elements
   835   * } Array;
   836   */
   837  EXTERN	int	Array_array;	// runtime offsetof(Array,array) - same for String
   838  EXTERN	int	Array_nel;	// runtime offsetof(Array,nel) - same for String
   839  EXTERN	int	Array_cap;	// runtime offsetof(Array,cap)
   840  EXTERN	int	sizeof_Array;	// runtime sizeof(Array)
   841  
   842  
   843  /*
   844   * note this is the runtime representation
   845   * of the compilers strings.
   846   *
   847   * typedef	struct
   848   * {				// must not move anything
   849   *	uchar	array[8];	// pointer to data
   850   *	uchar	nel[4];		// number of elements
   851   * } String;
   852   */
   853  EXTERN	int	sizeof_String;	// runtime sizeof(String)
   854  
   855  EXTERN	Dlist	dotlist[10];	// size is max depth of embeddeds
   856  
   857  EXTERN	Io	curio;
   858  EXTERN	Io	pushedio;
   859  EXTERN	int32	lexlineno;
   860  EXTERN	int32	lineno;
   861  EXTERN	int32	prevlineno;
   862  
   863  EXTERN	char*	infile;
   864  EXTERN	char*	outfile;
   865  EXTERN	Biobuf*	bout;
   866  EXTERN	int	nerrors;
   867  EXTERN	int	nsavederrors;
   868  EXTERN	int	nsyntaxerrors;
   869  EXTERN	int	safemode;
   870  EXTERN	int	nolocalimports;
   871  EXTERN	char	namebuf[NSYMB];
   872  EXTERN	char	lexbuf[NSYMB];
   873  EXTERN	char	litbuf[NSYMB];
   874  EXTERN	int	debug[256];
   875  EXTERN	char*	debugstr;
   876  EXTERN	int	debug_checknil;
   877  EXTERN	Sym*	hash[NHASH];
   878  EXTERN	Sym*	importmyname;	// my name for package
   879  EXTERN	Pkg*	localpkg;	// package being compiled
   880  EXTERN	Pkg*	importpkg;	// package being imported
   881  EXTERN	Pkg*	structpkg;	// package that declared struct, during import
   882  EXTERN	Pkg*	builtinpkg;	// fake package for builtins
   883  EXTERN	Pkg*	gostringpkg;	// fake pkg for Go strings
   884  EXTERN	Pkg*	itabpkg;	// fake pkg for itab cache
   885  EXTERN	Pkg*	runtimepkg;	// package runtime
   886  EXTERN	Pkg*	racepkg;	// package runtime/race
   887  EXTERN	Pkg*	stringpkg;	// fake package for C strings
   888  EXTERN	Pkg*	typepkg;	// fake package for runtime type info (headers)
   889  EXTERN	Pkg*	typelinkpkg;	// fake package for runtime type info (data)
   890  EXTERN	Pkg*	weaktypepkg;	// weak references to runtime type info
   891  EXTERN	Pkg*	unsafepkg;	// package unsafe
   892  EXTERN	Pkg*	trackpkg;	// fake package for field tracking
   893  EXTERN	Pkg*	phash[128];
   894  EXTERN	int	tptr;		// either TPTR32 or TPTR64
   895  extern	char*	runtimeimport;
   896  extern	char*	unsafeimport;
   897  EXTERN	char*	myimportpath;
   898  EXTERN	Idir*	idirs;
   899  EXTERN	char*	localimport;
   900  
   901  EXTERN	Type*	types[NTYPE];
   902  EXTERN	Type*	idealstring;
   903  EXTERN	Type*	idealbool;
   904  EXTERN	Type*	bytetype;
   905  EXTERN	Type*	runetype;
   906  EXTERN	Type*	errortype;
   907  EXTERN	uchar	simtype[NTYPE];
   908  EXTERN	uchar	isptr[NTYPE];
   909  EXTERN	uchar	isforw[NTYPE];
   910  EXTERN	uchar	isint[NTYPE];
   911  EXTERN	uchar	isfloat[NTYPE];
   912  EXTERN	uchar	iscomplex[NTYPE];
   913  EXTERN	uchar	issigned[NTYPE];
   914  EXTERN	uchar	issimple[NTYPE];
   915  
   916  EXTERN	uchar	okforeq[NTYPE];
   917  EXTERN	uchar	okforadd[NTYPE];
   918  EXTERN	uchar	okforand[NTYPE];
   919  EXTERN	uchar	okfornone[NTYPE];
   920  EXTERN	uchar	okforcmp[NTYPE];
   921  EXTERN	uchar	okforbool[NTYPE];
   922  EXTERN	uchar	okforcap[NTYPE];
   923  EXTERN	uchar	okforlen[NTYPE];
   924  EXTERN	uchar	okforarith[NTYPE];
   925  EXTERN	uchar	okforconst[NTYPE];
   926  EXTERN	uchar*	okfor[OEND];
   927  EXTERN	uchar	iscmp[OEND];
   928  
   929  EXTERN	Mpint*	minintval[NTYPE];
   930  EXTERN	Mpint*	maxintval[NTYPE];
   931  EXTERN	Mpflt*	minfltval[NTYPE];
   932  EXTERN	Mpflt*	maxfltval[NTYPE];
   933  
   934  EXTERN	NodeList*	xtop;
   935  EXTERN	NodeList*	externdcl;
   936  EXTERN	NodeList*	closures;
   937  EXTERN	NodeList*	exportlist;
   938  EXTERN	NodeList*	importlist;	// imported functions and methods with inlinable bodies
   939  EXTERN	NodeList*	funcsyms;
   940  EXTERN	int	dclcontext;		// PEXTERN/PAUTO
   941  EXTERN	int	incannedimport;
   942  EXTERN	int	statuniqgen;		// name generator for static temps
   943  EXTERN	int	loophack;
   944  
   945  EXTERN	int32	iota;
   946  EXTERN	NodeList*	lastconst;
   947  EXTERN	Node*	lasttype;
   948  EXTERN	vlong	maxarg;
   949  EXTERN	vlong	stksize;		// stack size for current frame
   950  EXTERN	vlong	stkptrsize;		// prefix of stack containing pointers
   951  EXTERN	int32	blockgen;		// max block number
   952  EXTERN	int32	block;			// current block number
   953  EXTERN	int	hasdefer;		// flag that curfn has defer statetment
   954  
   955  EXTERN	Node*	curfn;
   956  
   957  EXTERN	int	widthptr;
   958  EXTERN	int	widthint;
   959  EXTERN	int	widthreg;
   960  
   961  EXTERN	Node*	typesw;
   962  EXTERN	Node*	nblank;
   963  
   964  extern	int	thechar;
   965  extern	char*	thestring;
   966  extern	LinkArch*	thelinkarch;
   967  EXTERN	int  	use_sse;
   968  
   969  EXTERN	char*	hunk;
   970  EXTERN	int32	nhunk;
   971  EXTERN	int32	thunk;
   972  
   973  EXTERN	int	funcdepth;
   974  EXTERN	int	typecheckok;
   975  EXTERN	int	compiling_runtime;
   976  EXTERN	int	compiling_wrappers;
   977  EXTERN	int	inl_nonlocal;
   978  EXTERN	int	use_writebarrier;
   979  EXTERN	int	pure_go;
   980  EXTERN	char*	flag_installsuffix;
   981  EXTERN	int	flag_race;
   982  EXTERN	int	flag_largemodel;
   983  EXTERN	int	noescape;
   984  EXTERN	int	nosplit;
   985  EXTERN	int	debuglive;
   986  EXTERN	Link*	ctxt;
   987  
   988  EXTERN	int	nointerface;
   989  EXTERN	int	fieldtrack_enabled;
   990  EXTERN	int	precisestack_enabled;
   991  EXTERN	int	writearchive;
   992  
   993  EXTERN	Biobuf	bstdout;
   994  
   995  EXTERN	int	nacl;
   996  
   997  /*
   998   *	y.tab.c
   999   */
  1000  int	yyparse(void);
  1001  
  1002  /*
  1003   *	align.c
  1004   */
  1005  int	argsize(Type *t);
  1006  void	checkwidth(Type *t);
  1007  void	defercheckwidth(void);
  1008  void	dowidth(Type *t);
  1009  void	resumecheckwidth(void);
  1010  vlong	rnd(vlong o, vlong r);
  1011  void	typeinit(void);
  1012  
  1013  /*
  1014   *	array.c
  1015   */
  1016  Array*	arraynew(int32 capacity, int32 size);
  1017  void	arrayfree(Array *array);
  1018  int32	arraylength(Array *array);
  1019  void*	arrayget(Array *array, int32 index);
  1020  void	arrayset(Array *array, int32 index, void *element);
  1021  void	arrayadd(Array *array, void *element);
  1022  void	arraysort(Array* array, int (*cmp)(const void*, const void*));
  1023  
  1024  /*
  1025   *	bits.c
  1026   */
  1027  int	Qconv(Fmt *fp);
  1028  Bits	band(Bits a, Bits b);
  1029  int	bany(Bits *a);
  1030  int	beq(Bits a, Bits b);
  1031  int	bitno(int32 b);
  1032  Bits	blsh(uint n);
  1033  Bits	bnot(Bits a);
  1034  int	bnum(Bits a);
  1035  Bits	bor(Bits a, Bits b);
  1036  int	bset(Bits a, uint n);
  1037  
  1038  /*
  1039   *	bv.c
  1040   */
  1041  Bvec*	bvalloc(int32 n);
  1042  void	bvandnot(Bvec *dst, Bvec *src1, Bvec *src2);
  1043  int	bvcmp(Bvec *bv1, Bvec *bv2);
  1044  void	bvcopy(Bvec *dst, Bvec *src);
  1045  Bvec*	bvconcat(Bvec *src1, Bvec *src2);
  1046  int	bvget(Bvec *bv, int32 i);
  1047  int32	bvnext(Bvec *bv, int32 i);
  1048  int	bvisempty(Bvec *bv);
  1049  void	bvnot(Bvec *bv);
  1050  void	bvor(Bvec *dst, Bvec *src1, Bvec *src2);
  1051  void	bvand(Bvec *dst, Bvec *src1, Bvec *src2);
  1052  void	bvprint(Bvec *bv);
  1053  void	bvreset(Bvec *bv, int32 i);
  1054  void	bvresetall(Bvec *bv);
  1055  void	bvset(Bvec *bv, int32 i);
  1056  
  1057  /*
  1058   *	closure.c
  1059   */
  1060  Node*	closurebody(NodeList *body);
  1061  void	closurehdr(Node *ntype);
  1062  void	typecheckclosure(Node *func, int top);
  1063  Node*	walkclosure(Node *func, NodeList **init);
  1064  void	typecheckpartialcall(Node*, Node*);
  1065  Node*	walkpartialcall(Node*, NodeList**);
  1066  
  1067  /*
  1068   *	const.c
  1069   */
  1070  int	cmpslit(Node *l, Node *r);
  1071  int	consttype(Node *n);
  1072  void	convconst(Node *con, Type *t, Val *val);
  1073  void	convlit(Node **np, Type *t);
  1074  void	convlit1(Node **np, Type *t, int explicit);
  1075  void	defaultlit(Node **np, Type *t);
  1076  void	defaultlit2(Node **lp, Node **rp, int force);
  1077  void	evconst(Node *n);
  1078  int	isconst(Node *n, int ct);
  1079  int	isgoconst(Node *n);
  1080  Node*	nodcplxlit(Val r, Val i);
  1081  Node*	nodlit(Val v);
  1082  long	nonnegconst(Node *n);
  1083  int	doesoverflow(Val v, Type *t);
  1084  void	overflow(Val v, Type *t);
  1085  int	smallintconst(Node *n);
  1086  Val	toint(Val v);
  1087  Mpflt*	truncfltlit(Mpflt *oldv, Type *t);
  1088  
  1089  /*
  1090   *	cplx.c
  1091   */
  1092  void	complexadd(int op, Node *nl, Node *nr, Node *res);
  1093  void	complexbool(int op, Node *nl, Node *nr, int true, int likely, Prog *to);
  1094  void	complexgen(Node *n, Node *res);
  1095  void	complexminus(Node *nl, Node *res);
  1096  void	complexmove(Node *f, Node *t);
  1097  void	complexmul(Node *nl, Node *nr, Node *res);
  1098  int	complexop(Node *n, Node *res);
  1099  void	nodfconst(Node *n, Type *t, Mpflt* fval);
  1100  
  1101  /*
  1102   *	dcl.c
  1103   */
  1104  void	addmethod(Sym *sf, Type *t, int local, int nointerface);
  1105  void	addvar(Node *n, Type *t, int ctxt);
  1106  NodeList*	checkarglist(NodeList *all, int input);
  1107  Node*	colas(NodeList *left, NodeList *right, int32 lno);
  1108  void	colasdefn(NodeList *left, Node *defn);
  1109  NodeList*	constiter(NodeList *vl, Node *t, NodeList *cl);
  1110  Node*	dclname(Sym *s);
  1111  void	declare(Node *n, int ctxt);
  1112  void	dumpdcl(char *st);
  1113  Node*	embedded(Sym *s, Pkg *pkg);
  1114  Node*	fakethis(void);
  1115  void	funcbody(Node *n);
  1116  void	funccompile(Node *n, int isclosure);
  1117  void	funchdr(Node *n);
  1118  Type*	functype(Node *this, NodeList *in, NodeList *out);
  1119  void	ifacedcl(Node *n);
  1120  int	isifacemethod(Type *f);
  1121  void	markdcl(void);
  1122  Node*	methodname(Node *n, Type *t);
  1123  Node*	methodname1(Node *n, Node *t);
  1124  Sym*	methodsym(Sym *nsym, Type *t0, int iface);
  1125  Node*	newname(Sym *s);
  1126  Node*	oldname(Sym *s);
  1127  void	popdcl(void);
  1128  void	poptodcl(void);
  1129  void	redeclare(Sym *s, char *where);
  1130  void	testdclstack(void);
  1131  Type*	tointerface(NodeList *l);
  1132  Type*	tostruct(NodeList *l);
  1133  Node*	typedcl0(Sym *s);
  1134  Node*	typedcl1(Node *n, Node *t, int local);
  1135  Node*	typenod(Type *t);
  1136  NodeList*	variter(NodeList *vl, Node *t, NodeList *el);
  1137  Sym*	funcsym(Sym*);
  1138  
  1139  /*
  1140   *	esc.c
  1141   */
  1142  void	escapes(NodeList*);
  1143  
  1144  /*
  1145   *	export.c
  1146   */
  1147  void	autoexport(Node *n, int ctxt);
  1148  void	dumpexport(void);
  1149  int	exportname(char *s);
  1150  void	exportsym(Node *n);
  1151  void    importconst(Sym *s, Type *t, Node *n);
  1152  void	importimport(Sym *s, Strlit *z);
  1153  Sym*    importsym(Sym *s, int op);
  1154  void    importtype(Type *pt, Type *t);
  1155  void    importvar(Sym *s, Type *t);
  1156  Type*	pkgtype(Sym *s);
  1157  
  1158  /*
  1159   *	fmt.c
  1160   */
  1161  void	fmtinstallgo(void);
  1162  void	dump(char *s, Node *n);
  1163  void	dumplist(char *s, NodeList *l);
  1164  
  1165  /*
  1166   *	gen.c
  1167   */
  1168  void	addrescapes(Node *n);
  1169  void	cgen_as(Node *nl, Node *nr);
  1170  void	cgen_callmeth(Node *n, int proc);
  1171  void	cgen_eface(Node* n, Node* res);
  1172  void	cgen_slice(Node* n, Node* res);
  1173  void	clearlabels(void);
  1174  void	clearslim(Node*);
  1175  void	checklabels(void);
  1176  int	dotoffset(Node *n, int64 *oary, Node **nn);
  1177  void	gen(Node *n);
  1178  void	genlist(NodeList *l);
  1179  Node*	sysfunc(char *name);
  1180  void	tempname(Node *n, Type *t);
  1181  Node*	temp(Type*);
  1182  
  1183  /*
  1184   *	init.c
  1185   */
  1186  void	fninit(NodeList *n);
  1187  Sym*	renameinit(void);
  1188  
  1189  /*
  1190   *	inl.c
  1191   */
  1192  void	caninl(Node *fn);
  1193  void	inlcalls(Node *fn);
  1194  void	typecheckinl(Node *fn);
  1195  
  1196  /*
  1197   *	lex.c
  1198   */
  1199  void	cannedimports(char *file, char *cp);
  1200  void	importfile(Val *f, int line);
  1201  char*	lexname(int lex);
  1202  char*	expstring(void);
  1203  void	mkpackage(char* pkgname);
  1204  void	unimportfile(void);
  1205  int32	yylex(void);
  1206  extern	int	yylast;
  1207  extern	int	yyprev;
  1208  
  1209  /*
  1210   *	mparith1.c
  1211   */
  1212  int	Bconv(Fmt *fp);
  1213  int	Fconv(Fmt *fp);
  1214  void	mpaddcfix(Mpint *a, vlong c);
  1215  void	mpaddcflt(Mpflt *a, double c);
  1216  void	mpatofix(Mpint *a, char *as);
  1217  void	mpatoflt(Mpflt *a, char *as);
  1218  int	mpcmpfixc(Mpint *b, vlong c);
  1219  int	mpcmpfixfix(Mpint *a, Mpint *b);
  1220  int	mpcmpfixflt(Mpint *a, Mpflt *b);
  1221  int	mpcmpfltc(Mpflt *b, double c);
  1222  int	mpcmpfltfix(Mpflt *a, Mpint *b);
  1223  int	mpcmpfltflt(Mpflt *a, Mpflt *b);
  1224  void	mpcomfix(Mpint *a);
  1225  void	mpdivfixfix(Mpint *a, Mpint *b);
  1226  void	mpmodfixfix(Mpint *a, Mpint *b);
  1227  void	mpmovefixfix(Mpint *a, Mpint *b);
  1228  void	mpmovefixflt(Mpflt *a, Mpint *b);
  1229  int	mpmovefltfix(Mpint *a, Mpflt *b);
  1230  void	mpmovefltflt(Mpflt *a, Mpflt *b);
  1231  void	mpmulcfix(Mpint *a, vlong c);
  1232  void	mpmulcflt(Mpflt *a, double c);
  1233  void	mpsubfixfix(Mpint *a, Mpint *b);
  1234  void	mpsubfltflt(Mpflt *a, Mpflt *b);
  1235  
  1236  /*
  1237   *	mparith2.c
  1238   */
  1239  void	mpaddfixfix(Mpint *a, Mpint *b, int);
  1240  void	mpandfixfix(Mpint *a, Mpint *b);
  1241  void	mpandnotfixfix(Mpint *a, Mpint *b);
  1242  void	mpdivfract(Mpint *a, Mpint *b);
  1243  void	mpdivmodfixfix(Mpint *q, Mpint *r, Mpint *n, Mpint *d);
  1244  vlong	mpgetfix(Mpint *a);
  1245  void	mplshfixfix(Mpint *a, Mpint *b);
  1246  void	mpmovecfix(Mpint *a, vlong c);
  1247  void	mpmulfixfix(Mpint *a, Mpint *b);
  1248  void	mpmulfract(Mpint *a, Mpint *b);
  1249  void	mpnegfix(Mpint *a);
  1250  void	mporfixfix(Mpint *a, Mpint *b);
  1251  void	mprshfixfix(Mpint *a, Mpint *b);
  1252  void	mpshiftfix(Mpint *a, int s);
  1253  int	mptestfix(Mpint *a);
  1254  void	mpxorfixfix(Mpint *a, Mpint *b);
  1255  
  1256  /*
  1257   *	mparith3.c
  1258   */
  1259  void	mpaddfltflt(Mpflt *a, Mpflt *b);
  1260  void	mpdivfltflt(Mpflt *a, Mpflt *b);
  1261  double	mpgetflt(Mpflt *a);
  1262  double	mpgetflt32(Mpflt *a);
  1263  void	mpmovecflt(Mpflt *a, double c);
  1264  void	mpmulfltflt(Mpflt *a, Mpflt *b);
  1265  void	mpnegflt(Mpflt *a);
  1266  void	mpnorm(Mpflt *a);
  1267  void	mpsetexp(Mpflt *a, int exp);
  1268  int	mptestflt(Mpflt *a);
  1269  int	sigfig(Mpflt *a);
  1270  
  1271  /*
  1272   *	obj.c
  1273   */
  1274  void	Bputname(Biobuf *b, LSym *s);
  1275  int	duint16(Sym *s, int off, uint16 v);
  1276  int	duint32(Sym *s, int off, uint32 v);
  1277  int	duint64(Sym *s, int off, uint64 v);
  1278  int	duint8(Sym *s, int off, uint8 v);
  1279  int	duintptr(Sym *s, int off, uint64 v);
  1280  int	dsname(Sym *s, int off, char *dat, int ndat);
  1281  void	dumpobj(void);
  1282  Sym*	stringsym(char*, int);
  1283  void	slicebytes(Node*, char*, int);
  1284  LSym*	linksym(Sym*);
  1285  
  1286  /*
  1287   *	order.c
  1288   */
  1289  void	order(Node *fn);
  1290  void	orderstmtinplace(Node **stmt);
  1291  
  1292  /*
  1293   *	range.c
  1294   */
  1295  void	typecheckrange(Node *n);
  1296  void	walkrange(Node *n);
  1297  
  1298  /*
  1299   *	reflect.c
  1300   */
  1301  void	dumptypestructs(void);
  1302  Type*	methodfunc(Type *f, Type*);
  1303  Node*	typename(Type *t);
  1304  Sym*	typesym(Type *t);
  1305  Sym*	typenamesym(Type *t);
  1306  Sym*	tracksym(Type *t);
  1307  Sym*	typesymprefix(char *prefix, Type *t);
  1308  int	haspointers(Type *t);
  1309  Type*	hiter(Type* t);
  1310  
  1311  /*
  1312   *	select.c
  1313   */
  1314  void	typecheckselect(Node *sel);
  1315  void	walkselect(Node *sel);
  1316  
  1317  /*
  1318   *	sinit.c
  1319   */
  1320  void	anylit(int, Node *n, Node *var, NodeList **init);
  1321  int	gen_as_init(Node *n);
  1322  NodeList*	initfix(NodeList *l);
  1323  int	oaslit(Node *n, NodeList **init);
  1324  int	stataddr(Node *nam, Node *n);
  1325  
  1326  /*
  1327   *	subr.c
  1328   */
  1329  Node*	adddot(Node *n);
  1330  int	adddot1(Sym *s, Type *t, int d, Type **save, int ignorecase);
  1331  void	addinit(Node**, NodeList*);
  1332  Type*	aindex(Node *b, Type *t);
  1333  int	algtype(Type *t);
  1334  int	algtype1(Type *t, Type **bad);
  1335  void	argtype(Node *on, Type *t);
  1336  Node*	assignconv(Node *n, Type *t, char *context);
  1337  int	assignop(Type *src, Type *dst, char **why);
  1338  void	badtype(int o, Type *tl, Type *tr);
  1339  int	brcom(int a);
  1340  int	brrev(int a);
  1341  NodeList*	concat(NodeList *a, NodeList *b);
  1342  int	convertop(Type *src, Type *dst, char **why);
  1343  Node*	copyexpr(Node*, Type*, NodeList**);
  1344  int	count(NodeList *l);
  1345  int	cplxsubtype(int et);
  1346  int	eqtype(Type *t1, Type *t2);
  1347  int	eqtypenoname(Type *t1, Type *t2);
  1348  void	errorexit(void);
  1349  void	expandmeth(Type *t);
  1350  void	fatal(char *fmt, ...);
  1351  void	flusherrors(void);
  1352  void	frame(int context);
  1353  Type*	funcfirst(Iter *s, Type *t);
  1354  Type*	funcnext(Iter *s);
  1355  void	genwrapper(Type *rcvr, Type *method, Sym *newnam, int iface);
  1356  void	genhash(Sym *sym, Type *t);
  1357  void	geneq(Sym *sym, Type *t);
  1358  Type**	getinarg(Type *t);
  1359  Type*	getinargx(Type *t);
  1360  Type**	getoutarg(Type *t);
  1361  Type*	getoutargx(Type *t);
  1362  Type**	getthis(Type *t);
  1363  Type*	getthisx(Type *t);
  1364  int	implements(Type *t, Type *iface, Type **missing, Type **have, int *ptr);
  1365  void	importdot(Pkg *opkg, Node *pack);
  1366  int	is64(Type *t);
  1367  int	isbadimport(Strlit *s);
  1368  int	isblank(Node *n);
  1369  int	isblanksym(Sym *s);
  1370  int	isdirectiface(Type*);
  1371  int	isfixedarray(Type *t);
  1372  int	isideal(Type *t);
  1373  int	isinter(Type *t);
  1374  int	isnil(Node *n);
  1375  int	isnilinter(Type *t);
  1376  int	isptrto(Type *t, int et);
  1377  int	isslice(Type *t);
  1378  int	istype(Type *t, int et);
  1379  int	iszero(Node *n);
  1380  void	linehist(char *file, int32 off, int relative);
  1381  NodeList*	list(NodeList *l, Node *n);
  1382  NodeList*	list1(Node *n);
  1383  void	listsort(NodeList**, int(*f)(Node*, Node*));
  1384  Node*	liststmt(NodeList *l);
  1385  NodeList*	listtreecopy(NodeList *l);
  1386  Sym*	lookup(char *name);
  1387  void*	mal(int32 n);
  1388  Type*	maptype(Type *key, Type *val);
  1389  Type*	methtype(Type *t, int mustname);
  1390  Pkg*	mkpkg(Strlit *path);
  1391  Sym*	ngotype(Node *n);
  1392  int	noconv(Type *t1, Type *t2);
  1393  Node*	nod(int op, Node *nleft, Node *nright);
  1394  Node*	nodbool(int b);
  1395  void	nodconst(Node *n, Type *t, int64 v);
  1396  Node*	nodintconst(int64 v);
  1397  Node*	nodfltconst(Mpflt *v);
  1398  Node*	nodnil(void);
  1399  int	parserline(void);
  1400  Sym*	pkglookup(char *name, Pkg *pkg);
  1401  int	powtwo(Node *n);
  1402  Type*	ptrto(Type *t);
  1403  void*	remal(void *p, int32 on, int32 n);
  1404  Sym*	restrictlookup(char *name, Pkg *pkg);
  1405  Node*	safeexpr(Node *n, NodeList **init);
  1406  void	saveerrors(void);
  1407  Node*	cheapexpr(Node *n, NodeList **init);
  1408  Node*	localexpr(Node *n, Type *t, NodeList **init);
  1409  void	saveorignode(Node *n);
  1410  int32	setlineno(Node *n);
  1411  void	setmaxarg(Type *t);
  1412  Type*	shallow(Type *t);
  1413  int	simsimtype(Type *t);
  1414  void	smagic(Magic *m);
  1415  Type*	sortinter(Type *t);
  1416  uint32	stringhash(char *p);
  1417  Strlit*	strlit(char *s);
  1418  int	structcount(Type *t);
  1419  Type*	structfirst(Iter *s, Type **nn);
  1420  Type*	structnext(Iter *s);
  1421  Node*	syslook(char *name, int copy);
  1422  Type*	tounsigned(Type *t);
  1423  Node*	treecopy(Node *n);
  1424  Type*	typ(int et);
  1425  uint32	typehash(Type *t);
  1426  void	ullmancalc(Node *n);
  1427  void	umagic(Magic *m);
  1428  void	warn(char *fmt, ...);
  1429  void	warnl(int line, char *fmt, ...);
  1430  void	yyerror(char *fmt, ...);
  1431  void	yyerrorl(int line, char *fmt, ...);
  1432  
  1433  /*
  1434   *	swt.c
  1435   */
  1436  void	typecheckswitch(Node *n);
  1437  void	walkswitch(Node *sw);
  1438  
  1439  /*
  1440   *	typecheck.c
  1441   */
  1442  int	islvalue(Node *n);
  1443  Node*	typecheck(Node **np, int top);
  1444  void	typechecklist(NodeList *l, int top);
  1445  Node*	typecheckdef(Node *n);
  1446  void	copytype(Node *n, Type *t);
  1447  void	checkreturn(Node*);
  1448  void	queuemethod(Node *n);
  1449  
  1450  /*
  1451   *	unsafe.c
  1452   */
  1453  int	isunsafebuiltin(Node *n);
  1454  Node*	unsafenmagic(Node *n);
  1455  
  1456  /*
  1457   *	walk.c
  1458   */
  1459  Node*	callnew(Type *t);
  1460  Node*	chanfn(char *name, int n, Type *t);
  1461  Node*	mkcall(char *name, Type *t, NodeList **init, ...);
  1462  Node*	mkcall1(Node *fn, Type *t, NodeList **init, ...);
  1463  int	vmatch1(Node *l, Node *r);
  1464  void	walk(Node *fn);
  1465  void	walkexpr(Node **np, NodeList **init);
  1466  void	walkexprlist(NodeList *l, NodeList **init);
  1467  void	walkexprlistsafe(NodeList *l, NodeList **init);
  1468  void	walkstmt(Node **np);
  1469  void	walkstmtlist(NodeList *l);
  1470  Node*	conv(Node*, Type*);
  1471  int	candiscard(Node*);
  1472  int	needwritebarrier(Node*, Node*);
  1473  Node*	outervalue(Node*);
  1474  void	usefield(Node*);
  1475  
  1476  /*
  1477   *	arch-specific ggen.c/gsubr.c/gobj.c/pgen.c/plive.c
  1478   */
  1479  #define	P	((Prog*)0)
  1480  
  1481  EXTERN	Prog*	continpc;
  1482  EXTERN	Prog*	breakpc;
  1483  EXTERN	Prog*	pc;
  1484  EXTERN	Prog*	firstpc;
  1485  
  1486  EXTERN	Node*	nodfp;
  1487  EXTERN	int	disable_checknil;
  1488  EXTERN	vlong	zerosize;
  1489  
  1490  int	anyregalloc(void);
  1491  void	betypeinit(void);
  1492  void	bgen(Node *n, int true, int likely, Prog *to);
  1493  void	checknil(Node*, NodeList**);
  1494  void	expandchecks(Prog*);
  1495  void	cgen(Node*, Node*);
  1496  void	cgen_asop(Node *n);
  1497  void	cgen_call(Node *n, int proc);
  1498  void	cgen_callinter(Node *n, Node *res, int proc);
  1499  void	cgen_checknil(Node*);
  1500  void	cgen_ret(Node *n);
  1501  void	clearfat(Node *n);
  1502  void	compile(Node*);
  1503  void	defframe(Prog*);
  1504  int	dgostringptr(Sym*, int off, char *str);
  1505  int	dgostrlitptr(Sym*, int off, Strlit*);
  1506  int	dstringptr(Sym *s, int off, char *str);
  1507  int	dsymptr(Sym *s, int off, Sym *x, int xoff);
  1508  int	duintxx(Sym *s, int off, uint64 v, int wid);
  1509  void	dumpdata(void);
  1510  void	fixautoused(Prog*);
  1511  void	gdata(Node*, Node*, int);
  1512  void	gdatacomplex(Node*, Mpcplx*);
  1513  void	gdatastring(Node*, Strlit*);
  1514  void	ggloblnod(Node *nam);
  1515  void	ggloblsym(Sym *s, int32 width, int8 flags);
  1516  void	gvardef(Node*);
  1517  void	gvarkill(Node*);
  1518  Prog*	gjmp(Prog*);
  1519  void	gused(Node*);
  1520  void	movelarge(NodeList*);
  1521  int	isfat(Type*);
  1522  void	linkarchinit(void);
  1523  void	liveness(Node*, Prog*, Sym*, Sym*);
  1524  void	twobitwalktype1(Type*, vlong*, Bvec*);
  1525  void	markautoused(Prog*);
  1526  Plist*	newplist(void);
  1527  Node*	nodarg(Type*, int);
  1528  void	nopout(Prog*);
  1529  void	patch(Prog*, Prog*);
  1530  Prog*	unpatch(Prog*);
  1531  
  1532  #pragma	varargck	type	"B"	Mpint*
  1533  #pragma	varargck	type	"E"	int
  1534  #pragma	varargck	type	"E"	uint
  1535  #pragma	varargck	type	"F"	Mpflt*
  1536  #pragma	varargck	type	"H"	NodeList*
  1537  #pragma	varargck	type	"J"	Node*
  1538  #pragma	varargck	type	"lL"	int32
  1539  #pragma	varargck	type	"L"	int32
  1540  #pragma	varargck	type	"N"	Node*
  1541  #pragma	varargck	type	"lN"	Node*
  1542  #pragma	varargck	type	"O"	int
  1543  #pragma	varargck	type	"O"	uint
  1544  #pragma	varargck	type	"Q"	Bits
  1545  #pragma	varargck	type	"S"	Sym*
  1546  #pragma	varargck	type	"lS"	LSym*
  1547  #pragma	varargck	type	"T"	Type*
  1548  #pragma	varargck	type	"lT"	Type*
  1549  #pragma	varargck	type	"V"	Val*
  1550  #pragma	varargck	type	"Z"	Strlit*
  1551  
  1552  /*
  1553   *	racewalk.c
  1554   */
  1555  void	racewalk(Node *fn);