go.h 26.4 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include	<u.h>
#include	<libc.h>
#include	<bio.h>

Russ Cox's avatar
Russ Cox committed
9 10
#undef OAPPEND

Russ Cox's avatar
Russ Cox committed
11 12 13 14
// avoid <ctype.h>
#undef isblank
#define isblank goisblank

15
#ifndef	EXTERN
Russ Cox's avatar
Russ Cox committed
16
#define	EXTERN	extern
17
#endif
18

Russ Cox's avatar
Russ Cox committed
19
#undef	BUFSIZ
20

21 22 23 24 25 26 27 28 29 30
enum
{
	NHUNK		= 50000,
	BUFSIZ		= 8192,
	NSYMB		= 500,
	NHASH		= 1024,
	STRINGSZ	= 200,
	YYMAXDEPTH	= 500,
	MAXALIGN	= 7,
	UINF		= 100,
31
	HISTSZ		= 10,
32 33

	PRIME1		= 3,
Ken Thompson's avatar
Ken Thompson committed
34 35

	AUNK		= 100,
36

Ken Thompson's avatar
Ken Thompson committed
37
	// these values are known by runtime
38 39
	AMEM		= 0,
	ANOEQ,
Ken Thompson's avatar
Ken Thompson committed
40 41
	ASTRING,
	AINTER,
42
	ANILINTER,
43
	AMEMWORD,
44

45
	BADWIDTH	= -1000000000,
46 47
};

48 49
extern vlong	MAXWIDTH;

50 51 52
/*
 * note this is the representation
 * of the compilers string literals,
53
 * it is not the runtime representation
54
 */
55 56
typedef	struct	Strlit	Strlit;
struct	Strlit
57
{
58
	int32	len;
59 60 61
	char	s[3];	// variable
};

Ken Thompson's avatar
Ken Thompson committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
/*
 * note this is the runtime representation
 * of hashmap iterator. it is probably
 * insafe to use it this way, but it puts
 * all the changes in one place.
 * only flag is referenced from go.
 * actual placement does not matter as long
 * as the size is >= actual size.
 */
typedef	struct	Hiter	Hiter;
struct	Hiter
{
	uchar	data[8];		// return val from next
	int32	elemsize;		// size of elements in table */
	int32	changes;		// number of changes observed last time */
	int32	i;			// stack pointer in subtable_state */
	uchar	last[8];		// last hash value returned */
	uchar	h[8];			// the hash table */
	struct
	{
		uchar	sub[8];		// pointer into subtable */
		uchar	start[8];	// pointer into start of subtable */
		uchar	end[8];		// pointer into end of subtable */
		uchar	pad[8];
	} sub[4];
};

Ken Thompson's avatar
Ken Thompson committed
89 90
enum
{
91 92 93 94
	Mpscale	= 29,		// safely smaller than bits in a long
	Mpprec	= 16,		// Mpscale*Mpprec is max number of bits
	Mpnorm	= Mpprec - 1,	// significant words in a normalized float
	Mpbase	= 1L << Mpscale,
Ken Thompson's avatar
Ken Thompson committed
95
	Mpsign	= Mpbase >> 1,
96 97
	Mpmask	= Mpbase - 1,
	Mpdebug	= 0,
Ken Thompson's avatar
Ken Thompson committed
98 99 100 101 102 103 104 105 106 107 108 109 110
};

typedef	struct	Mpint	Mpint;
struct	Mpint
{
	long	a[Mpprec];
	uchar	neg;
	uchar	ovf;
};

typedef	struct	Mpflt	Mpflt;
struct	Mpflt
{
111 112
	Mpint	val;
	short	exp;
Ken Thompson's avatar
Ken Thompson committed
113 114
};

115 116 117 118 119 120 121
typedef	struct	Mpcplx	Mpcplx;
struct	Mpcplx
{
	Mpflt	real;
	Mpflt	imag;
};

122 123 124
typedef	struct	Val	Val;
struct	Val
{
Ken Thompson's avatar
Ken Thompson committed
125 126 127 128 129 130 131
	short	ctype;
	union
	{
		short	reg;		// OREGISTER
		short	bval;		// bool value CTBOOL
		Mpint*	xval;		// int CTINT
		Mpflt*	fval;		// float CTFLT
132
		Mpcplx*	cval;		// float CTCPLX
133
		Strlit*	sval;		// string CTSTR
Ken Thompson's avatar
Ken Thompson committed
134
	} u;
135 136
};

137
typedef	struct	Pkg Pkg;
138 139
typedef	struct	Sym	Sym;
typedef	struct	Node	Node;
140
typedef	struct	NodeList	NodeList;
141
typedef	struct	Type	Type;
Russ Cox's avatar
Russ Cox committed
142
typedef	struct	Label	Label;
143 144 145

struct	Type
{
146 147
	uchar	etype;
	uchar	chan;
148 149
	uchar	recur;		// to detect loops
	uchar	trecur;		// to detect loops
Russ Cox's avatar
Russ Cox committed
150
	uchar	printed;
Ken Thompson's avatar
Ken Thompson committed
151
	uchar	embedded;	// TFIELD embedded type
Russ Cox's avatar
Russ Cox committed
152
	uchar	siggen;
Russ Cox's avatar
Russ Cox committed
153
	uchar	funarg;
154
	uchar	copyany;
155
	uchar	local;		// created in this file
156
	uchar	deferwidth;
Russ Cox's avatar
Russ Cox committed
157
	uchar	broke;
Russ Cox's avatar
Russ Cox committed
158
	uchar	isddd;	// TFIELD is ... argument
Russ Cox's avatar
Russ Cox committed
159
	uchar	align;
160

Russ Cox's avatar
Russ Cox committed
161
	Node*	nod;		// canonical OTYPE node
Russ Cox's avatar
Russ Cox committed
162
	Type*	orig;		// original type (type literal or predefined type)
Russ Cox's avatar
Russ Cox committed
163
	int		lineno;
Russ Cox's avatar
Russ Cox committed
164

165 166 167 168
	// TFUNCT
	uchar	thistuple;
	uchar	outtuple;
	uchar	intuple;
Ken Thompson's avatar
Ken Thompson committed
169
	uchar	outnamed;
170

Ken Thompson's avatar
Ken Thompson committed
171
	Type*	method;
Russ Cox's avatar
Russ Cox committed
172
	Type*	xmethod;
Ken Thompson's avatar
Ken Thompson committed
173

174
	Sym*	sym;
175
	int32	vargen;		// unique name for OTYPE/ONAME
176

Ken Thompson's avatar
Ken Thompson committed
177 178 179
	Node*	nname;
	vlong	argwid;

180 181 182 183 184 185
	// most nodes
	Type*	type;
	vlong	width;		// offset in TFIELD, width in all others

	// TFIELD
	Type*	down;		// also used in TMAP
186
	Strlit*	note;		// literal string annotation
187 188

	// TARRAY
189
	int32	bound;		// negative is dynamic array
Russ Cox's avatar
Russ Cox committed
190

Russ Cox's avatar
Russ Cox committed
191
	int32	maplineno;	// first use of TFORW as map key
192
	int32	embedlineno;	// first use of TFORW as embedded type
193 194 195 196 197
};
#define	T	((Type*)0)

struct	Node
{
198 199 200 201 202
	uchar	op;
	uchar	ullman;		// sethi/ullman number
	uchar	addable;	// type of addressability - 0 is not addressable
	uchar	trecur;		// to detect loops
	uchar	etype;		// op for OASOP, etype for OTYPE, exclam for export
203
	uchar	class;		// PPARAM, PAUTO, PEXTERN, etc
204
	uchar	method;		// OCALLMETH name
Ken Thompson's avatar
Ken Thompson committed
205
	uchar	embedded;	// ODCLFIELD embedded type
206
	uchar	colas;		// OAS resulting from :=
Russ Cox's avatar
Russ Cox committed
207
	uchar	diag;		// already printed error about this
208
	uchar	noescape;	// ONAME never move to heap
Russ Cox's avatar
Russ Cox committed
209
	uchar	funcdepth;
Russ Cox's avatar
Russ Cox committed
210
	uchar	builtin;	// built-in name, like len or close
211
	uchar	walkdef;
212
	uchar	typecheck;
213
	uchar	local;
Russ Cox's avatar
Russ Cox committed
214
	uchar	initorder;
Ken Thompson's avatar
Ken Thompson committed
215
	uchar	dodata;		// compile literal assignment as data statement
216
	uchar	used;
Russ Cox's avatar
Russ Cox committed
217
	uchar	isddd;
218
	uchar	pun;		// don't registerize variable ONAME
219
	uchar	readonly;
220
	uchar	implicit;	// don't show in printout
221 222 223 224 225

	// most nodes
	Node*	left;
	Node*	right;
	Type*	type;
226
	Type*	realtype;	// as determined by typecheck
227 228
	NodeList*	list;
	NodeList*	rlist;
Luuk van Dijk's avatar
Luuk van Dijk committed
229
	Node*	orig;		// original form, for printing, and tracking copies of ONAMEs
230 231

	// for-body
232
	NodeList*	ninit;
233 234
	Node*	ntest;
	Node*	nincr;
235
	NodeList*	nbody;
236 237

	// if-body
238
	NodeList*	nelse;
239 240 241 242 243 244

	// cases
	Node*	ncase;

	// func
	Node*	nname;
245
	Node*	shortname;
246 247 248
	NodeList*	enter;
	NodeList*	exit;
	NodeList*	cvars;	// closure params
249
	NodeList*	dcl;	// autodcl for this func/closure
250

Ken Thompson's avatar
Ken Thompson committed
251
	// OLITERAL/OREGISTER
252 253
	Val	val;

254 255 256
	// ONAME
	Node*	ntype;
	Node*	defn;
Russ Cox's avatar
Russ Cox committed
257
	Node*	pack;	// real package for import . names
258
	Node*	curfn;	// function for local variables
259

260 261 262 263 264
	// ONAME func param with PHEAP
	Node*	heapaddr;	// temp holding heap address of param
	Node*	stackparam;	// OPARAM node referring to stack copy of param
	Node*	alloc;	// allocation call

Russ Cox's avatar
Russ Cox committed
265 266 267 268
	// ONAME closure param with PPARAMREF
	Node*	outer;	// outer PPARAMREF in nested closure
	Node*	closure;	// ONAME/PHEAP <-> ONAME/PPARAMREF

269 270 271
	// OPACK
	Pkg*	pkg;

272
	Sym*	sym;		// various
273 274
	int32	vargen;		// unique name for OTYPE/ONAME
	int32	lineno;
275
	int32	endlineno;
276
	vlong	xoffset;
Luuk van Dijk's avatar
Luuk van Dijk committed
277
	int32	stkdelta;	// offset added by stack frame compaction phase.
Russ Cox's avatar
Russ Cox committed
278
	int32	ostk;
279
	int32	iota;
280 281
};
#define	N	((Node*)0)
Russ Cox's avatar
Russ Cox committed
282
EXTERN	int32	walkgen;
283

284
struct	NodeList
285 286 287 288 289 290
{
	Node*	n;
	NodeList*	next;
	NodeList*	end;
};

Russ Cox's avatar
Russ Cox committed
291
enum
292
{
Russ Cox's avatar
Russ Cox committed
293 294 295
	SymExport	= 1<<0,
	SymPackage	= 1<<1,
	SymExported	= 1<<2,
296 297
	SymUniq		= 1<<3,
	SymSiggen	= 1<<4,
Russ Cox's avatar
Russ Cox committed
298
};
299

Russ Cox's avatar
Russ Cox committed
300 301 302 303
struct	Sym
{
	ushort	lexical;
	uchar	flags;
304
	uchar	sym;		// huffman encoding in object file
Russ Cox's avatar
Russ Cox committed
305
	Sym*	link;
306
	int32	npkg;	// number of imported packages with this name
307

Russ Cox's avatar
Russ Cox committed
308
	// saved and restored by dcopy
309
	Pkg*	pkg;
310
	char*	name;		// variable name
Russ Cox's avatar
Russ Cox committed
311
	Node*	def;		// definition: ONAME OTYPE OPACK or OLITERAL
Russ Cox's avatar
Russ Cox committed
312
	Label*	label;	// corresponding label (ephemeral)
Russ Cox's avatar
Russ Cox committed
313
	int32	block;		// blocknumber to catch redeclaration
Ken Thompson's avatar
Ken Thompson committed
314
	int32	lastlineno;	// last declaration for diagnostic
315 316 317
};
#define	S	((Sym*)0)

Russ Cox's avatar
Russ Cox committed
318 319
EXTERN	Sym*	dclstack;

320 321 322 323
struct	Pkg
{
	char*	name;
	Strlit*	path;
324
	Sym*	pathsym;
325 326
	char*	prefix;
	Pkg*	link;
327 328
	char	exported;	// import line written in export data
	char	direct;	// imported directly
329 330
};

331 332 333 334 335 336 337 338 339 340
typedef	struct	Iter	Iter;
struct	Iter
{
	int	done;
	Type*	tfunc;
	Type*	t;
	Node**	an;
	Node*	n;
};

341 342 343 344 345
typedef	struct	Hist	Hist;
struct	Hist
{
	Hist*	link;
	char*	name;
346 347
	int32	line;
	int32	offset;
348 349 350
};
#define	H	((Hist*)0)

351 352 353 354
enum
{
	OXXX,

355 356 357 358 359 360 361 362
	// names
	ONAME,
	ONONAME,
	OTYPE,
	OPACK,
	OLITERAL,

	// exprs
Russ Cox's avatar
Russ Cox committed
363
	OADD, OSUB, OOR, OXOR, OADDSTR,
364
	OADDR,
365
	OANDAND,
Russ Cox's avatar
Russ Cox committed
366
	OAPPEND,
367
	OARRAY,
Russ Cox's avatar
Russ Cox committed
368
	OARRAYBYTESTR, OARRAYRUNESTR,
369
	OSTRARRAYBYTE, OSTRARRAYRUNE,
370
	OAS, OAS2, OAS2MAPW, OAS2FUNC, OAS2RECV, OAS2MAPR, OAS2DOTTYPE, OASOP,
371 372 373 374
	OBAD,
	OCALL, OCALLFUNC, OCALLMETH, OCALLINTER,
	OCAP,
	OCLOSE,
375
	OCLOSURE,
Russ Cox's avatar
Russ Cox committed
376 377
	OCMPIFACE, OCMPSTR,
	OCOMPLIT, OMAPLIT, OSTRUCTLIT, OARRAYLIT,
378
	OCONV, OCONVIFACE, OCONVNOP,
Ken Thompson's avatar
Ken Thompson committed
379
	OCOPY,
380
	ODCL, ODCLFUNC, ODCLFIELD, ODCLCONST, ODCLTYPE,
381
	ODOT, ODOTPTR, ODOTMETH, ODOTINTER, OXDOT,
382
	ODOTTYPE,
Russ Cox's avatar
Russ Cox committed
383
	ODOTTYPE2,
384 385
	OEQ, ONE, OLT, OLE, OGE, OGT,
	OIND,
386
	OINDEX, OINDEXMAP,
Russ Cox's avatar
Russ Cox committed
387
	OKEY, OPARAM,
388
	OLEN,
Russ Cox's avatar
Russ Cox committed
389
	OMAKE, OMAKECHAN, OMAKEMAP, OMAKESLICE,
390 391
	OHMUL, ORRC, OLRC,	// high-mul and rotate-carry
	OMUL, ODIV, OMOD, OLSH, ORSH, OAND, OANDNOT,
392 393 394
	ONEW,
	ONOT, OCOM, OPLUS, OMINUS,
	OOROR,
Ken Thompson's avatar
Ken Thompson committed
395
	OPANIC, OPRINT, OPRINTN,
Russ Cox's avatar
Russ Cox committed
396
	OPAREN,
397
	OSEND,
Russ Cox's avatar
Russ Cox committed
398
	OSLICE, OSLICEARR, OSLICESTR,
399
	ORECOVER,
400
	ORECV,
Russ Cox's avatar
Russ Cox committed
401
	ORUNESTR,
Russ Cox's avatar
Russ Cox committed
402
	OSELRECV,
403
	OSELRECV2,
404
	OIOTA,
Russ Cox's avatar
Russ Cox committed
405
	OREAL, OIMAG, OCOMPLEX,
406

407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
	// stmts
	OBLOCK,
	OBREAK,
	OCASE, OXCASE,
	OCONTINUE,
	ODEFER,
	OEMPTY,
	OFALL, OXFALL,
	OFOR,
	OGOTO,
	OIF,
	OLABEL,
	OPROC,
	ORANGE,
	ORETURN,
	OSELECT,
	OSWITCH,
Russ Cox's avatar
Russ Cox committed
424
	OTYPESW,	// l = r.(type)
425 426 427 428 429 430 431 432

	// types
	OTCHAN,
	OTMAP,
	OTSTRUCT,
	OTINTER,
	OTFUNC,
	OTARRAY,
Russ Cox's avatar
Russ Cox committed
433
	OTPAREN,
434

Russ Cox's avatar
Russ Cox committed
435 436
	// misc
	ODDD,
437 438 439

	// for back ends
	OCMP, ODEC, OEXTEND, OINC, OREGISTER, OINDREG,
440 441 442 443 444 445 446 447 448 449 450

	OEND,
};
enum
{
	Txxx,			// 0

	TINT8,	TUINT8,		// 1
	TINT16,	TUINT16,
	TINT32,	TUINT32,
	TINT64,	TUINT64,
Ken Thompson's avatar
Ken Thompson committed
451
	TINT, TUINT, TUINTPTR,
452

453 454 455
	TCOMPLEX64,		// 12
	TCOMPLEX128,

Lorenzo Stoakes's avatar
Lorenzo Stoakes committed
456
	TFLOAT32,		// 14
457 458
	TFLOAT64,

Lorenzo Stoakes's avatar
Lorenzo Stoakes committed
459
	TBOOL,			// 16
460

Lorenzo Stoakes's avatar
Lorenzo Stoakes committed
461
	TPTR32, TPTR64,		// 17
462

Lorenzo Stoakes's avatar
Lorenzo Stoakes committed
463
	TFUNC,			// 19
464
	TARRAY,
465
	T_old_DARRAY,
Lorenzo Stoakes's avatar
Lorenzo Stoakes committed
466
	TSTRUCT,		// 22
467 468
	TCHAN,
	TMAP,
Lorenzo Stoakes's avatar
Lorenzo Stoakes committed
469
	TINTER,			// 25
470 471 472 473
	TFORW,
	TFIELD,
	TANY,
	TSTRING,
474
	TUNSAFEPTR,
475

476
	// pseudo-types for literals
Lorenzo Stoakes's avatar
Lorenzo Stoakes committed
477
	TIDEAL,			// 31
478
	TNIL,
Russ Cox's avatar
Russ Cox committed
479
	TBLANK,
480

Russ Cox's avatar
Russ Cox committed
481 482
	// pseudo-type for frame layout
	TFUNCARGS,
483
	TCHANARGS,
Russ Cox's avatar
Russ Cox committed
484
	TINTERMETH,
485

Ken Thompson's avatar
Ken Thompson committed
486
	NTYPE,
487 488 489 490 491 492 493
};
enum
{
	CTxxx,

	CTINT,
	CTFLT,
494
	CTCPLX,
495 496 497 498 499 500 501 502
	CTSTR,
	CTBOOL,
	CTNIL,
};

enum
{
	/* types of channel */
503
	/* must match ../../pkg/nreflect/type.go:/Chandir */
504
	Cxxx,
Russ Cox's avatar
Russ Cox committed
505 506 507
	Crecv = 1<<0,
	Csend = 1<<1,
	Cboth = Crecv | Csend,
508 509 510 511 512 513 514 515 516
};

enum
{
	Pxxx,

	PEXTERN,	// declaration context
	PAUTO,
	PPARAM,
517
	PPARAMOUT,
Russ Cox's avatar
Russ Cox committed
518
	PPARAMREF,	// param passed by reference
Russ Cox's avatar
Russ Cox committed
519
	PFUNC,
520 521

	PHEAP = 1<<7,
522 523
};

524 525
enum
{
526 527
	Etop = 1<<1,		// evaluated at statement level
	Erv = 1<<2,		// evaluated in value context
Russ Cox's avatar
Russ Cox committed
528
	Etype = 1<<3,
529
	Ecall = 1<<4,		// call-only expressions are ok
Russ Cox's avatar
Russ Cox committed
530
	Efnstruct = 1<<5,	// multivalue function returns are ok
Russ Cox's avatar
Russ Cox committed
531
	Eiota = 1<<6,		// iota is ok
Russ Cox's avatar
Russ Cox committed
532
	Easgn = 1<<7,		// assigning to expression
533 534
	Eindir = 1<<8,		// indirecting through expression
	Eaddr = 1<<9,		// taking address of expression
535
	Eproc = 1<<10,		// inside a go statement
536
	Ecomplit = 1<<11,	// type in composite literal
537 538
};

Russ Cox's avatar
Russ Cox committed
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
#define	BITS	5
#define	NVAR	(BITS*sizeof(uint32)*8)

typedef	struct	Bits	Bits;
struct	Bits
{
	uint32	b[BITS];
};

EXTERN	Bits	zbits;

typedef	struct	Var	Var;
struct	Var
{
	vlong	offset;
	Sym*	sym;
Russ Cox's avatar
Russ Cox committed
555
	Sym*	gotype;
Luuk van Dijk's avatar
Luuk van Dijk committed
556
	Node*	node;
557
	int	width;
Russ Cox's avatar
Russ Cox committed
558 559
	char	name;
	char	etype;
Ken Thompson's avatar
Ken Thompson committed
560
	char	addr;
Russ Cox's avatar
Russ Cox committed
561 562 563 564
};

EXTERN	Var	var[NVAR];

565 566 567 568 569 570 571 572 573
typedef	struct	Typedef	Typedef;
struct	Typedef
{
	char*	name;
	int	etype;
	int	sameas;
};

extern	Typedef	typedefs[];
Russ Cox's avatar
Russ Cox committed
574

575
typedef	struct	Sig	Sig;
576
struct	Sig
577 578
{
	char*	name;
579
	Pkg*	pkg;
580 581 582
	Sym*	isym;
	Sym*	tsym;
	Type*	type;
583
	Type*	mtype;
584 585 586 587
	int32	offset;
	Sig*	link;
};

588 589 590 591 592
typedef	struct	Io	Io;
struct	Io
{
	char*	infile;
	Biobuf*	bin;
593
	int32	ilineno;
Russ Cox's avatar
Russ Cox committed
594
	int	nlsemi;
Russ Cox's avatar
Russ Cox committed
595
	int	eofnl;
596
	int	peekc;
Ken Thompson's avatar
Ken Thompson committed
597
	int	peekc1;	// second peekc for ...
598
	char*	cp;	// used for content when bin==nil
599
	int	importsafe;
600 601
};

602 603 604
typedef	struct	Dlist	Dlist;
struct	Dlist
{
Ken Thompson's avatar
Ken Thompson committed
605
	Type*	field;
606 607
};

608 609 610 611 612 613 614
typedef	struct	Idir	Idir;
struct Idir
{
	Idir*	link;
	char*	dir;
};

615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
/*
 * argument passing to/from
 * smagic and umagic
 */
typedef	struct	Magic Magic;
struct	Magic
{
	int	w;	// input for both - width
	int	s;	// output for both - shift
	int	bad;	// output for both - unexpected failure

	// magic multiplier for signed literal divisors
	int64	sd;	// input - literal divisor
	int64	sm;	// output - multiplier

	// magic multiplier for unsigned literal divisors
	uint64	ud;	// input - literal divisor
	uint64	um;	// output - multiplier
	int	ua;	// output - adder
};

Russ Cox's avatar
Russ Cox committed
636 637 638 639
typedef struct	Prog Prog;

struct	Label
{
Russ Cox's avatar
Russ Cox committed
640
	uchar	used;
Russ Cox's avatar
Russ Cox committed
641
	Sym*	sym;
Russ Cox's avatar
Russ Cox committed
642 643 644 645 646 647 648
	Node*	def;
	NodeList*	use;
	Label*	link;
	
	// for use during gen
	Prog*	gotopc;	// pointer to unresolved gotos
	Prog*	labelpc;	// pointer to code
Russ Cox's avatar
Russ Cox committed
649 650 651 652 653
	Prog*	breakpc;	// pointer to code
	Prog*	continpc;	// pointer to code
};
#define	L	((Label*)0)

654 655 656 657 658 659
/*
 * note this is the runtime representation
 * of the compilers arrays.
 *
 * typedef	struct
 * {				// must not move anything
660 661 662
 *	uchar	array[8];	// pointer to data
 *	uchar	nel[4];		// number of elements
 *	uchar	cap[4];		// allocated number of elements
663 664
 * } Array;
 */
665 666
EXTERN	int	Array_array;	// runtime offsetof(Array,array) - same for String
EXTERN	int	Array_nel;	// runtime offsetof(Array,nel) - same for String
667 668 669
EXTERN	int	Array_cap;	// runtime offsetof(Array,cap)
EXTERN	int	sizeof_Array;	// runtime sizeof(Array)

670 671 672 673 674 675 676

/*
 * note this is the runtime representation
 * of the compilers strings.
 *
 * typedef	struct
 * {				// must not move anything
677 678
 *	uchar	array[8];	// pointer to data
 *	uchar	nel[4];		// number of elements
679 680 681 682
 * } String;
 */
EXTERN	int	sizeof_String;	// runtime sizeof(String)

683 684
EXTERN	Dlist	dotlist[10];	// size is max depth of embeddeds

685 686
EXTERN	Io	curio;
EXTERN	Io	pushedio;
687
EXTERN	int32	lexlineno;
688
EXTERN	int32	lineno;
689
EXTERN	int32	prevlineno;
690 691 692 693
EXTERN	char*	pathname;
EXTERN	Hist*	hist;
EXTERN	Hist*	ehist;

Ken Thompson's avatar
Ken Thompson committed
694
EXTERN	char*	infile;
695 696 697
EXTERN	char*	outfile;
EXTERN	Biobuf*	bout;
EXTERN	int	nerrors;
Russ Cox's avatar
Russ Cox committed
698
EXTERN	int	nsavederrors;
Russ Cox's avatar
Russ Cox committed
699
EXTERN	int	nsyntaxerrors;
Russ Cox's avatar
Russ Cox committed
700
EXTERN	int	safemode;
701
EXTERN	char	namebuf[NSYMB];
702
EXTERN	char	lexbuf[NSYMB];
Russ Cox's avatar
Russ Cox committed
703
EXTERN	char	litbuf[NSYMB];
704 705
EXTERN	char	debug[256];
EXTERN	Sym*	hash[NHASH];
706 707 708 709 710 711 712 713 714 715
EXTERN	Sym*	importmyname;	// my name for package
EXTERN	Pkg*	localpkg;	// package being compiled
EXTERN	Pkg*	importpkg;	// package being imported
EXTERN	Pkg*	structpkg;	// package that declared struct, during import
EXTERN	Pkg*	builtinpkg;	// fake package for builtins
EXTERN	Pkg*	gostringpkg;	// fake pkg for Go strings
EXTERN	Pkg*	runtimepkg;	// package runtime
EXTERN	Pkg*	stringpkg;	// fake package for C strings
EXTERN	Pkg*	typepkg;	// fake package for runtime type info
EXTERN	Pkg*	unsafepkg;	// package unsafe
716
EXTERN	Pkg*	phash[128];
717
EXTERN	int	tptr;		// either TPTR32 or TPTR64
Russ Cox's avatar
Russ Cox committed
718
extern	char*	runtimeimport;
Ken Thompson's avatar
Ken Thompson committed
719
extern	char*	unsafeimport;
720
EXTERN	Idir*	idirs;
721 722

EXTERN	Type*	types[NTYPE];
723
EXTERN	Type*	idealstring;
Russ Cox's avatar
Russ Cox committed
724
EXTERN	Type*	idealbool;
Ken Thompson's avatar
Ken Thompson committed
725
EXTERN	uchar	simtype[NTYPE];
726
EXTERN	uchar	isptr[NTYPE];
Russ Cox's avatar
Russ Cox committed
727
EXTERN	uchar	isforw[NTYPE];
728 729
EXTERN	uchar	isint[NTYPE];
EXTERN	uchar	isfloat[NTYPE];
730
EXTERN	uchar	iscomplex[NTYPE];
731
EXTERN	uchar	issigned[NTYPE];
732
EXTERN	uchar	issimple[NTYPE];
733

734 735 736
EXTERN	uchar	okforeq[NTYPE];
EXTERN	uchar	okforadd[NTYPE];
EXTERN	uchar	okforand[NTYPE];
737 738 739 740 741 742
EXTERN	uchar	okfornone[NTYPE];
EXTERN	uchar	okforcmp[NTYPE];
EXTERN	uchar	okforbool[NTYPE];
EXTERN	uchar	okforcap[NTYPE];
EXTERN	uchar	okforlen[NTYPE];
EXTERN	uchar	okforarith[NTYPE];
Russ Cox's avatar
Russ Cox committed
743
EXTERN	uchar	okforconst[NTYPE];
744
EXTERN	uchar*	okfor[OEND];
Russ Cox's avatar
Russ Cox committed
745
EXTERN	uchar	iscmp[OEND];
Ken Thompson's avatar
Ken Thompson committed
746 747 748 749 750

EXTERN	Mpint*	minintval[NTYPE];
EXTERN	Mpint*	maxintval[NTYPE];
EXTERN	Mpflt*	minfltval[NTYPE];
EXTERN	Mpflt*	maxfltval[NTYPE];
751

Russ Cox's avatar
Russ Cox committed
752
EXTERN	NodeList*	xtop;
Russ Cox's avatar
Russ Cox committed
753
EXTERN	NodeList*	externdcl;
754
EXTERN	NodeList*	closures;
Russ Cox's avatar
Russ Cox committed
755 756
EXTERN	NodeList*	exportlist;
EXTERN	NodeList*	typelist;
757
EXTERN	int	dclcontext;		// PEXTERN/PAUTO
Russ Cox's avatar
Russ Cox committed
758
EXTERN	int	incannedimport;
759
EXTERN	int	statuniqgen;		// name generator for static temps
Russ Cox's avatar
Russ Cox committed
760
EXTERN	int	loophack;
761

762
EXTERN	int32	iota;
763
EXTERN	NodeList*	lastconst;
764
EXTERN	Node*	lasttype;
765
EXTERN	int32	maxarg;
766
EXTERN	int32	stksize;		// stack size for current frame
Russ Cox's avatar
Russ Cox committed
767 768
EXTERN	int32	blockgen;		// max block number
EXTERN	int32	block;			// current block number
Ken Thompson's avatar
defer  
Ken Thompson committed
769
EXTERN	int	hasdefer;		// flag that curfn has defer statetment
770

Russ Cox's avatar
Russ Cox committed
771 772
EXTERN	Node*	curfn;

773 774
EXTERN	int	widthptr;

Russ Cox's avatar
Russ Cox committed
775 776
EXTERN	Node*	typesw;
EXTERN	Node*	nblank;
777

778 779
extern	int	thechar;
extern	char*	thestring;
780
EXTERN	char*	hunk;
781 782
EXTERN	int32	nhunk;
EXTERN	int32	thunk;
783

Russ Cox's avatar
Russ Cox committed
784
EXTERN	int	exporting;
785
EXTERN	int	erroring;
Russ Cox's avatar
Russ Cox committed
786
EXTERN	int	noargnames;
Russ Cox's avatar
Russ Cox committed
787

Russ Cox's avatar
Russ Cox committed
788
EXTERN	int	funcdepth;
789
EXTERN	int	typecheckok;
790
EXTERN	int	packagequotes;
791
EXTERN	int	longsymnames;
792 793
EXTERN	int	compiling_runtime;

794 795 796 797 798
/*
 *	y.tab.c
 */
int	yyparse(void);

Russ Cox's avatar
Russ Cox committed
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
/*
 *	align.c
 */
int	argsize(Type *t);
void	checkwidth(Type *t);
void	defercheckwidth(void);
void	dowidth(Type *t);
void	resumecheckwidth(void);
uint32	rnd(uint32 o, uint32 r);
void	typeinit(void);

/*
 *	bits.c
 */
int	Qconv(Fmt *fp);
Bits	band(Bits a, Bits b);
int	bany(Bits *a);
int	beq(Bits a, Bits b);
int	bitno(int32 b);
Bits	blsh(uint n);
Bits	bnot(Bits a);
int	bnum(Bits a);
Bits	bor(Bits a, Bits b);
int	bset(Bits a, uint n);

/*
 *	closure.c
 */
Node*	closurebody(NodeList *body);
void	closurehdr(Node *ntype);
829
void	typecheckclosure(Node *func, int top);
Russ Cox's avatar
Russ Cox committed
830
Node*	walkclosure(Node *func, NodeList **init);
831
void	walkcallclosure(Node *n, NodeList **init);
Russ Cox's avatar
Russ Cox committed
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883

/*
 *	const.c
 */
int	cmpslit(Node *l, Node *r);
int	consttype(Node *n);
void	convconst(Node *con, Type *t, Val *val);
void	convlit(Node **np, Type *t);
void	convlit1(Node **np, Type *t, int explicit);
void	defaultlit(Node **np, Type *t);
void	defaultlit2(Node **lp, Node **rp, int force);
void	evconst(Node *n);
int	isconst(Node *n, int ct);
Node*	nodcplxlit(Val r, Val i);
Node*	nodlit(Val v);
long	nonnegconst(Node *n);
void	overflow(Val v, Type *t);
int	smallintconst(Node *n);
Val	toint(Val v);
Mpflt*	truncfltlit(Mpflt *oldv, Type *t);

/*
 *	cplx.c
 */
void	complexadd(int op, Node *nl, Node *nr, Node *res);
void	complexbool(int op, Node *nl, Node *nr, int true, Prog *to);
void	complexgen(Node *n, Node *res);
void	complexminus(Node *nl, Node *res);
void	complexmove(Node *f, Node *t);
void	complexmul(Node *nl, Node *nr, Node *res);
int	complexop(Node *n, Node *res);
void	nodfconst(Node *n, Type *t, Mpflt* fval);

/*
 *	dcl.c
 */
void	addmethod(Sym *sf, Type *t, int local);
void	addvar(Node *n, Type *t, int ctxt);
NodeList*	checkarglist(NodeList *all, int input);
Node*	colas(NodeList *left, NodeList *right);
void	colasdefn(NodeList *left, Node *defn);
NodeList*	constiter(NodeList *vl, Node *t, NodeList *cl);
Node*	dclname(Sym *s);
void	declare(Node *n, int ctxt);
Type*	dostruct(NodeList *l, int et);
void	dumpdcl(char *st);
Node*	embedded(Sym *s);
Node*	fakethis(void);
void	funcbody(Node *n);
void	funccompile(Node *n, int isclosure);
void	funchdr(Node *n);
Type*	functype(Node *this, NodeList *in, NodeList *out);
884
void	ifacedcl(Node *n);
Russ Cox's avatar
Russ Cox committed
885 886 887 888
int	isifacemethod(Type *f);
void	markdcl(void);
Node*	methodname(Node *n, Type *t);
Node*	methodname1(Node *n, Node *t);
889
Sym*	methodsym(Sym *nsym, Type *t0, int iface);
Russ Cox's avatar
Russ Cox committed
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922
Node*	newname(Sym *s);
Type*	newtype(Sym *s);
Node*	oldname(Sym *s);
void	popdcl(void);
void	poptodcl(void);
void	redeclare(Sym *s, char *where);
void	testdclstack(void);
Node*	typedcl0(Sym *s);
Node*	typedcl1(Node *n, Node *t, int local);
void	typedcl2(Type *pt, Type *t);
Node*	typenod(Type *t);
NodeList*	variter(NodeList *vl, Node *t, NodeList *el);

/*
 *	export.c
 */
void	autoexport(Node *n, int ctxt);
void	dumpexport(void);
int	exportname(char *s);
void	exportsym(Node *n);
void	importconst(Sym *s, Type *t, Node *n);
void	importmethod(Sym *s, Type *t);
Sym*	importsym(Sym *s, int op);
void	importtype(Type *pt, Type *t);
void	importvar(Sym *s, Type *t, int ctxt);
Type*	pkgtype(Sym *s);

/*
 *	gen.c
 */
void	allocparams(void);
void	cgen_as(Node *nl, Node *nr);
void	cgen_callmeth(Node *n, int proc);
Russ Cox's avatar
Russ Cox committed
923
void	clearlabels(void);
Russ Cox's avatar
Russ Cox committed
924
void	checklabels(void);
Russ Cox's avatar
Russ Cox committed
925 926 927 928 929 930 931 932 933 934 935 936
int	dotoffset(Node *n, int *oary, Node **nn);
void	gen(Node *n);
void	genlist(NodeList *l);
Node*	sysfunc(char *name);
void	tempname(Node *n, Type *t);

/*
 *	init.c
 */
void	fninit(NodeList *n);
Node*	renameinit(Node *n);

937 938 939
/*
 *	lex.c
 */
Russ Cox's avatar
Russ Cox committed
940 941 942 943
void	cannedimports(char *file, char *cp);
void	importfile(Val *f, int line);
char*	lexname(int lex);
void	mkpackage(char* pkgname);
944
void	unimportfile(void);
945
int32	yylex(void);
946
extern	int	windows;
Russ Cox's avatar
Russ Cox committed
947 948
extern	int	yylast;
extern	int	yyprev;
949 950

/*
Ken Thompson's avatar
Ken Thompson committed
951
 *	mparith1.c
952
 */
Russ Cox's avatar
Russ Cox committed
953 954 955 956 957 958 959 960
int	Bconv(Fmt *fp);
int	Fconv(Fmt *fp);
void	mpaddcfix(Mpint *a, vlong c);
void	mpaddcflt(Mpflt *a, double c);
void	mpatofix(Mpint *a, char *as);
void	mpatoflt(Mpflt *a, char *as);
int	mpcmpfixc(Mpint *b, vlong c);
int	mpcmpfixfix(Mpint *a, Mpint *b);
Ken Thompson's avatar
Ken Thompson committed
961
int	mpcmpfixflt(Mpint *a, Mpflt *b);
Russ Cox's avatar
Russ Cox committed
962
int	mpcmpfltc(Mpflt *b, double c);
Ken Thompson's avatar
Ken Thompson committed
963
int	mpcmpfltfix(Mpflt *a, Mpint *b);
Ken Thompson's avatar
Ken Thompson committed
964
int	mpcmpfltflt(Mpflt *a, Mpflt *b);
Russ Cox's avatar
Russ Cox committed
965
void	mpcomfix(Mpint *a);
Ken Thompson's avatar
Ken Thompson committed
966
void	mpdivfixfix(Mpint *a, Mpint *b);
Ken Thompson's avatar
Ken Thompson committed
967
void	mpmodfixfix(Mpint *a, Mpint *b);
Russ Cox's avatar
Russ Cox committed
968
void	mpmovefixfix(Mpint *a, Mpint *b);
Ken Thompson's avatar
Ken Thompson committed
969
void	mpmovefixflt(Mpflt *a, Mpint *b);
Russ Cox's avatar
Russ Cox committed
970 971 972 973 974 975
int	mpmovefltfix(Mpint *a, Mpflt *b);
void	mpmovefltflt(Mpflt *a, Mpflt *b);
void	mpmulcfix(Mpint *a, vlong c);
void	mpmulcflt(Mpflt *a, double c);
void	mpsubfixfix(Mpint *a, Mpint *b);
void	mpsubfltflt(Mpflt *a, Mpflt *b);
Ken Thompson's avatar
Ken Thompson committed
976

Ken Thompson's avatar
Ken Thompson committed
977 978 979 980
/*
 *	mparith2.c
 */
void	mpaddfixfix(Mpint *a, Mpint *b);
Ken Thompson's avatar
Ken Thompson committed
981
void	mpandfixfix(Mpint *a, Mpint *b);
982
void	mpandnotfixfix(Mpint *a, Mpint *b);
Russ Cox's avatar
Russ Cox committed
983 984 985
void	mpdivfract(Mpint *a, Mpint *b);
void	mpdivmodfixfix(Mpint *q, Mpint *r, Mpint *n, Mpint *d);
vlong	mpgetfix(Mpint *a);
Ken Thompson's avatar
Ken Thompson committed
986
void	mplshfixfix(Mpint *a, Mpint *b);
Russ Cox's avatar
Russ Cox committed
987 988 989 990
void	mpmovecfix(Mpint *a, vlong c);
void	mpmulfixfix(Mpint *a, Mpint *b);
void	mpmulfract(Mpint *a, Mpint *b);
void	mpnegfix(Mpint *a);
Ken Thompson's avatar
Ken Thompson committed
991 992
void	mporfixfix(Mpint *a, Mpint *b);
void	mprshfixfix(Mpint *a, Mpint *b);
993
void	mpshiftfix(Mpint *a, int s);
Russ Cox's avatar
Russ Cox committed
994 995
int	mptestfix(Mpint *a);
void	mpxorfixfix(Mpint *a, Mpint *b);
Ken Thompson's avatar
Ken Thompson committed
996

Ken Thompson's avatar
Ken Thompson committed
997 998 999 1000 1001 1002
/*
 *	mparith3.c
 */
void	mpaddfltflt(Mpflt *a, Mpflt *b);
void	mpdivfltflt(Mpflt *a, Mpflt *b);
double	mpgetflt(Mpflt *a);
Russ Cox's avatar
Russ Cox committed
1003 1004 1005 1006 1007 1008
void	mpmovecflt(Mpflt *a, double c);
void	mpmulfltflt(Mpflt *a, Mpflt *b);
void	mpnegflt(Mpflt *a);
void	mpnorm(Mpflt *a);
int	mptestflt(Mpflt *a);
int	sigfig(Mpflt *a);
1009 1010

/*
Russ Cox's avatar
Russ Cox committed
1011
 *	obj.c
1012
 */
Russ Cox's avatar
Russ Cox committed
1013 1014 1015 1016 1017 1018
void	Bputname(Biobuf *b, Sym *s);
int	duint16(Sym *s, int off, uint16 v);
int	duint32(Sym *s, int off, uint32 v);
int	duint64(Sym *s, int off, uint64 v);
int	duint8(Sym *s, int off, uint8 v);
int	duintptr(Sym *s, int off, uint64 v);
Russ Cox's avatar
Russ Cox committed
1019
int	dsname(Sym *s, int off, char *dat, int ndat);
Russ Cox's avatar
Russ Cox committed
1020 1021
void	dumpobj(void);
void	ieeedtod(uint64 *ieee, double native);
Russ Cox's avatar
Russ Cox committed
1022
Sym*	stringsym(char*, int);
1023

1024
/*
Russ Cox's avatar
Russ Cox committed
1025
 *	print.c
1026
 */
Russ Cox's avatar
Russ Cox committed
1027 1028
void	exprfmt(Fmt *f, Node *n, int prec);
void	exprlistfmt(Fmt *f, NodeList *l);
1029 1030

/*
Russ Cox's avatar
Russ Cox committed
1031
 *	range.c
1032
 */
Russ Cox's avatar
Russ Cox committed
1033 1034
void	typecheckrange(Node *n);
void	walkrange(Node *n);
1035

Russ Cox's avatar
Russ Cox committed
1036 1037 1038 1039
/*
 *	reflect.c
 */
void	dumptypestructs(void);
1040
Type*	methodfunc(Type *f, Type*);
Russ Cox's avatar
Russ Cox committed
1041 1042
Node*	typename(Type *t);
Sym*	typesym(Type *t);
Russ Cox's avatar
Russ Cox committed
1043

Ken Thompson's avatar
Ken Thompson committed
1044
/*
Russ Cox's avatar
Russ Cox committed
1045
 *	select.c
Ken Thompson's avatar
Ken Thompson committed
1046
 */
Russ Cox's avatar
Russ Cox committed
1047 1048
void	typecheckselect(Node *sel);
void	walkselect(Node *sel);
Ken Thompson's avatar
Ken Thompson committed
1049

Russ Cox's avatar
Russ Cox committed
1050 1051 1052
/*
 *	sinit.c
 */
Ken Thompson's avatar
Ken Thompson committed
1053
void	anylit(int, Node *n, Node *var, NodeList **init);
Russ Cox's avatar
Russ Cox committed
1054 1055 1056 1057
int	gen_as_init(Node *n);
NodeList*	initfix(NodeList *l);
int	oaslit(Node *n, NodeList **init);
int	stataddr(Node *nam, Node *n);
Ken Thompson's avatar
Ken Thompson committed
1058

1059
/*
Russ Cox's avatar
Russ Cox committed
1060
 *	subr.c
1061
 */
Russ Cox's avatar
Russ Cox committed
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
int	Econv(Fmt *fp);
int	Jconv(Fmt *fp);
int	Lconv(Fmt *fp);
int	Nconv(Fmt *fp);
int	Oconv(Fmt *fp);
int	Sconv(Fmt *fp);
int	Tconv(Fmt *fp);
int	Tpretty(Fmt *fp, Type *t);
int	Zconv(Fmt *fp);
Node*	adddot(Node *n);
1072
int	adddot1(Sym *s, Type *t, int d, Type **save, int ignorecase);
Russ Cox's avatar
Russ Cox committed
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
Type*	aindex(Node *b, Type *t);
int	algtype(Type *t);
void	argtype(Node *on, Type *t);
Node*	assignconv(Node *n, Type *t, char *context);
int	assignop(Type *src, Type *dst, char **why);
void	badtype(int o, Type *tl, Type *tr);
int	brcom(int a);
int	brrev(int a);
NodeList*	concat(NodeList *a, NodeList *b);
int	convertop(Type *src, Type *dst, char **why);
int	count(NodeList *l);
int	cplxsubtype(int et);
void	dump(char *s, Node *n);
void	dumplist(char *s, NodeList *l);
int	eqtype(Type *t1, Type *t2);
int	eqtypenoname(Type *t1, Type *t2);
void	errorexit(void);
void	expandmeth(Sym *s, Type *t);
void	fatal(char *fmt, ...);
void	flusherrors(void);
void	frame(int context);
Type*	funcfirst(Iter *s, Type *t);
Type*	funcnext(Iter *s);
1096
void	genwrapper(Type *rcvr, Type *method, Sym *newnam, int iface);
Russ Cox's avatar
Russ Cox committed
1097 1098 1099 1100 1101 1102
Type**	getinarg(Type *t);
Type*	getinargx(Type *t);
Type**	getoutarg(Type *t);
Type*	getoutargx(Type *t);
Type**	getthis(Type *t);
Type*	getthisx(Type *t);
1103
int	implements(Type *t, Type *iface, Type **missing, Type **have, int *ptr);
Russ Cox's avatar
Russ Cox committed
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
void	importdot(Pkg *opkg, Node *pack);
int	is64(Type *t);
int	isblank(Node *n);
int	isfixedarray(Type *t);
int	isideal(Type *t);
int	isinter(Type *t);
int	isnil(Node *n);
int	isnilinter(Type *t);
int	isptrto(Type *t, int et);
int	isslice(Type *t);
int	istype(Type *t, int et);
void	linehist(char *file, int32 off, int relative);
NodeList*	list(NodeList *l, Node *n);
NodeList*	list1(Node *n);
Luuk van Dijk's avatar
Luuk van Dijk committed
1118
void	listsort(NodeList**, int(*f)(Node*, Node*));
Russ Cox's avatar
Russ Cox committed
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
Node*	liststmt(NodeList *l);
NodeList*	listtreecopy(NodeList *l);
Sym*	lookup(char *name);
void*	mal(int32 n);
Type*	maptype(Type *key, Type *val);
Type*	methtype(Type *t);
Pkg*	mkpkg(Strlit *path);
Sym*	ngotype(Node *n);
int	noconv(Type *t1, Type *t2);
Node*	nod(int op, Node *nleft, Node *nright);
Node*	nodbool(int b);
void	nodconst(Node *n, Type *t, int64 v);
Node*	nodintconst(int64 v);
1132
Node*	nodfltconst(Mpflt *v);
Russ Cox's avatar
Russ Cox committed
1133 1134 1135 1136 1137 1138 1139 1140
Node*	nodnil(void);
int	parserline(void);
Sym*	pkglookup(char *name, Pkg *pkg);
int	powtwo(Node *n);
Type*	ptrto(Type *t);
void*	remal(void *p, int32 on, int32 n);
Sym*	restrictlookup(char *name, Pkg *pkg);
Node*	safeexpr(Node *n, NodeList **init);
Russ Cox's avatar
Russ Cox committed
1141
void	saveerrors(void);
1142
Node*	cheapexpr(Node *n, NodeList **init);
1143
Node*	localexpr(Node *n, Type *t, NodeList **init);
Russ Cox's avatar
Russ Cox committed
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
int32	setlineno(Node *n);
void	setmaxarg(Type *t);
Type*	shallow(Type *t);
int	simsimtype(Type *t);
void	smagic(Magic *m);
Type*	sortinter(Type *t);
uint32	stringhash(char *p);
Strlit*	strlit(char *s);
int	structcount(Type *t);
Type*	structfirst(Iter *s, Type **nn);
Type*	structnext(Iter *s);
Node*	syslook(char *name, int copy);
Type*	tounsigned(Type *t);
Node*	treecopy(Node *n);
Type*	typ(int et);
uint32	typehash(Type *t);
void	ullmancalc(Node *n);
void	umagic(Magic *m);
void	warn(char *fmt, ...);
void	yyerror(char *fmt, ...);
void	yyerrorl(int line, char *fmt, ...);
1165 1166

/*
Russ Cox's avatar
Russ Cox committed
1167
 *	swt.c
1168
 */
Russ Cox's avatar
Russ Cox committed
1169 1170
void	typecheckswitch(Node *n);
void	walkswitch(Node *sw);
1171 1172

/*
Russ Cox's avatar
Russ Cox committed
1173
 *	typecheck.c
1174
 */
Russ Cox's avatar
Russ Cox committed
1175 1176 1177 1178
int	exportassignok(Type *t, char *desc);
int	islvalue(Node *n);
Node*	typecheck(Node **np, int top);
void	typechecklist(NodeList *l, int top);
1179 1180 1181 1182 1183
Node*	typecheckdef(Node *n);
void	resumetypecopy(void);
void	copytype(Node *n, Type *t);
void	defertypecopy(Node *n, Type *t);
void	queuemethod(Node *n);
1184

Russ Cox's avatar
Russ Cox committed
1185
/*
Russ Cox's avatar
Russ Cox committed
1186
 *	unsafe.c
1187
 */
Russ Cox's avatar
Russ Cox committed
1188
Node*	unsafenmagic(Node *n);
1189 1190

/*
Russ Cox's avatar
Russ Cox committed
1191
 *	walk.c
Russ Cox's avatar
Russ Cox committed
1192
 */
Russ Cox's avatar
Russ Cox committed
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
Node*	callnew(Type *t);
Node*	chanfn(char *name, int n, Type *t);
Node*	mkcall(char *name, Type *t, NodeList **init, ...);
Node*	mkcall1(Node *fn, Type *t, NodeList **init, ...);
int	vmatch1(Node *l, Node *r);
void	walk(Node *fn);
void	walkexpr(Node **np, NodeList **init);
void	walkexprlist(NodeList *l, NodeList **init);
void	walkexprlistsafe(NodeList *l, NodeList **init);
void	walkstmt(Node **np);
void	walkstmtlist(NodeList *l);
1204

1205
/*
1206
 *	arch-specific ggen.c/gsubr.c/gobj.c/pgen.c
1207 1208 1209
 */
#define	P	((Prog*)0)

1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
typedef	struct	Plist	Plist;
struct	Plist
{
	Node*	name;
	Prog*	firstpc;
	int	recur;
	Plist*	link;
};

EXTERN	Plist*	plist;
EXTERN	Plist*	plast;

1222 1223 1224 1225
EXTERN	Prog*	continpc;
EXTERN	Prog*	breakpc;
EXTERN	Prog*	pc;
EXTERN	Prog*	firstpc;
1226
EXTERN	Prog*	retpc;
1227

Russ Cox's avatar
Russ Cox committed
1228 1229
EXTERN	Node*	nodfp;

Russ Cox's avatar
Russ Cox committed
1230
int	anyregalloc(void);
1231 1232
void	betypeinit(void);
void	bgen(Node *n, int true, Prog *to);
Russ Cox's avatar
Russ Cox committed
1233
void	cgen(Node*, Node*);
1234 1235 1236 1237 1238
void	cgen_asop(Node *n);
void	cgen_call(Node *n, int proc);
void	cgen_callinter(Node *n, Node *res, int proc);
void	cgen_ret(Node *n);
void	clearfat(Node *n);
Russ Cox's avatar
Russ Cox committed
1239
void	compile(Node*);
1240
void	defframe(Prog*);
Russ Cox's avatar
Russ Cox committed
1241 1242 1243 1244 1245 1246 1247
int	dgostringptr(Sym*, int off, char *str);
int	dgostrlitptr(Sym*, int off, Strlit*);
int	dstringptr(Sym *s, int off, char *str);
int	dsymptr(Sym *s, int off, Sym *x, int xoff);
int	duintxx(Sym *s, int off, uint64 v, int wid);
void	dumpdata(void);
void	dumpfuncs(void);
1248
void	fixautoused(Prog*);
1249
void	gdata(Node*, Node*, int);
Ken Thompson's avatar
Ken Thompson committed
1250
void	gdatacomplex(Node*, Mpcplx*);
Russ Cox's avatar
Russ Cox committed
1251
void	gdatastring(Node*, Strlit*);
Russ Cox's avatar
Russ Cox committed
1252
void	genembedtramp(Type*, Type*, Sym*, int iface);
1253 1254
void	ggloblnod(Node *nam, int32 width);
void	ggloblsym(Sym *s, int32 width, int dupok);
Russ Cox's avatar
Russ Cox committed
1255 1256 1257
Prog*	gjmp(Prog*);
void	gused(Node*);
int	isfat(Type*);
1258
void	markautoused(Prog*);
Russ Cox's avatar
Russ Cox committed
1259 1260 1261 1262
Plist*	newplist(void);
Node*	nodarg(Type*, int);
void	nopout(Prog*);
void	patch(Prog*, Prog*);
Russ Cox's avatar
Russ Cox committed
1263
Prog*	unpatch(Prog*);
1264 1265 1266
void	zfile(Biobuf *b, char *p, int n);
void	zhist(Biobuf *b, int line, vlong offset);
void	zname(Biobuf *b, Sym *s, int t);
Russ Cox's avatar
Russ Cox committed
1267 1268
void	data(void);
void	text(void);
Russ Cox's avatar
Russ Cox committed
1269