go.h 24.7 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 11 12
// avoid <ctype.h>
#undef isblank
#define isblank goisblank

13
#ifndef	EXTERN
Russ Cox's avatar
Russ Cox committed
14
#define	EXTERN	extern
15
#endif
16

17 18
#undef	getc
#undef	ungetc
Russ Cox's avatar
Russ Cox committed
19
#undef	BUFSIZ
20

21 22 23
#define	getc	ccgetc
#define	ungetc	ccungetc

24 25 26 27 28 29 30 31 32 33
enum
{
	NHUNK		= 50000,
	BUFSIZ		= 8192,
	NSYMB		= 500,
	NHASH		= 1024,
	STRINGSZ	= 200,
	YYMAXDEPTH	= 500,
	MAXALIGN	= 7,
	UINF		= 100,
34
	HISTSZ		= 10,
35 36 37 38 39 40 41 42 43 44

	PRIME1		= 3,
	PRIME2		= 10007,
	PRIME3		= 10009,
	PRIME4		= 10037,
	PRIME5		= 10039,
	PRIME6		= 10061,
	PRIME7		= 10067,
	PRIME8		= 10079,
	PRIME9		= 10091,
45
	PRIME10		= 10093,
Ken Thompson's avatar
Ken Thompson committed
46 47

	AUNK		= 100,
48

Ken Thompson's avatar
Ken Thompson committed
49
	// these values are known by runtime
50 51
	AMEM		= 0,
	ANOEQ,
Ken Thompson's avatar
Ken Thompson committed
52 53
	ASTRING,
	AINTER,
54
	ANILINTER,
55

56 57
	BADWIDTH	= -1000000000,
	MAXWIDTH        = 1<<30
58 59 60 61 62
};

/*
 * note this is the representation
 * of the compilers string literals,
63
 * it is not the runtime representation
64
 */
65 66
typedef	struct	Strlit	Strlit;
struct	Strlit
67
{
68
	int32	len;
69 70 71
	char	s[3];	// variable
};

Ken Thompson's avatar
Ken Thompson committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
/*
 * 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
99 100
enum
{
101 102 103 104
	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
105
	Mpsign	= Mpbase >> 1,
106 107
	Mpmask	= Mpbase - 1,
	Mpdebug	= 0,
Ken Thompson's avatar
Ken Thompson committed
108 109 110 111 112 113 114 115 116 117 118 119 120
};

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

typedef	struct	Mpflt	Mpflt;
struct	Mpflt
{
121 122
	Mpint	val;
	short	exp;
Ken Thompson's avatar
Ken Thompson committed
123 124
};

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

139
typedef	struct	Pkg Pkg;
140 141
typedef	struct	Sym	Sym;
typedef	struct	Node	Node;
142
typedef	struct	NodeList	NodeList;
143 144 145 146
typedef	struct	Type	Type;

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

Russ Cox's avatar
Russ Cox committed
160
	Node*	nod;		// canonical OTYPE node
Russ Cox's avatar
Russ Cox committed
161
	int		lineno;
Russ Cox's avatar
Russ Cox committed
162

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

Ken Thompson's avatar
Ken Thompson committed
169
	Type*	method;
Russ Cox's avatar
Russ Cox committed
170
	Type*	xmethod;
Ken Thompson's avatar
Ken Thompson committed
171

172
	Sym*	sym;
173
	int32	vargen;		// unique name for OTYPE/ONAME
174

Ken Thompson's avatar
Ken Thompson committed
175 176 177
	Node*	nname;
	vlong	argwid;

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

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

	// TARRAY
187
	int32	bound;		// negative is dynamic array
Russ Cox's avatar
Russ Cox committed
188

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

struct	Node
{
196 197 198 199 200
	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
201
	uchar	class;		// PPARAM, PAUTO, PEXTERN, etc
202
	uchar	method;		// OCALLMETH name
Ken Thompson's avatar
Ken Thompson committed
203
	uchar	iota;		// OLITERAL made from iota
Ken Thompson's avatar
Ken Thompson committed
204
	uchar	embedded;	// ODCLFIELD embedded type
205
	uchar	colas;		// OAS resulting from :=
Russ Cox's avatar
Russ Cox committed
206
	uchar	diag;		// already printed error about this
207
	uchar	noescape;	// ONAME never move to heap
Russ Cox's avatar
Russ Cox committed
208
	uchar	funcdepth;
Russ Cox's avatar
Russ Cox committed
209
	uchar	builtin;	// built-in name, like len or close
210
	uchar	walkdef;
211
	uchar	typecheck;
212
	uchar	local;
Russ Cox's avatar
Russ Cox committed
213
	uchar	initorder;
Ken Thompson's avatar
Ken Thompson committed
214
	uchar	dodata;		// compile literal assignment as data statement
215
	uchar	used;
216
	uchar	oldref;
217 218 219 220 221

	// most nodes
	Node*	left;
	Node*	right;
	Type*	type;
222 223
	NodeList*	list;
	NodeList*	rlist;
224 225

	// for-body
226
	NodeList*	ninit;
227 228
	Node*	ntest;
	Node*	nincr;
229
	NodeList*	nbody;
230 231

	// if-body
232
	NodeList*	nelse;
233 234 235 236 237 238

	// cases
	Node*	ncase;

	// func
	Node*	nname;
239
	Node*	shortname;
240 241 242
	NodeList*	enter;
	NodeList*	exit;
	NodeList*	cvars;	// closure params
243
	NodeList*	dcl;	// autodcl for this func/closure
244

Ken Thompson's avatar
Ken Thompson committed
245
	// OLITERAL/OREGISTER
246 247
	Val	val;

248 249 250
	// ONAME
	Node*	ntype;
	Node*	defn;
Russ Cox's avatar
Russ Cox committed
251
	Node*	pack;	// real package for import . names
252

253 254 255 256 257
	// 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
258 259 260 261
	// ONAME closure param with PPARAMREF
	Node*	outer;	// outer PPARAMREF in nested closure
	Node*	closure;	// ONAME/PHEAP <-> ONAME/PPARAMREF

262 263 264
	// OPACK
	Pkg*	pkg;

265
	Sym*	sym;		// various
266 267
	int32	vargen;		// unique name for OTYPE/ONAME
	int32	lineno;
268
	vlong	xoffset;
Russ Cox's avatar
Russ Cox committed
269
	int32	ostk;
270 271 272
};
#define	N	((Node*)0)

273
struct	NodeList
274 275 276 277 278 279
{
	Node*	n;
	NodeList*	next;
	NodeList*	end;
};

Russ Cox's avatar
Russ Cox committed
280
enum
281
{
Russ Cox's avatar
Russ Cox committed
282 283 284
	SymExport	= 1<<0,
	SymPackage	= 1<<1,
	SymExported	= 1<<2,
285 286
	SymUniq		= 1<<3,
	SymSiggen	= 1<<4,
Russ Cox's avatar
Russ Cox committed
287
};
288

Russ Cox's avatar
Russ Cox committed
289 290 291 292
struct	Sym
{
	ushort	lexical;
	uchar	flags;
293
	uchar	sym;		// huffman encoding in object file
Russ Cox's avatar
Russ Cox committed
294
	Sym*	link;
295

Russ Cox's avatar
Russ Cox committed
296
	// saved and restored by dcopy
297
	Pkg*	pkg;
298
	char*	name;		// variable name
Russ Cox's avatar
Russ Cox committed
299
	Node*	def;		// definition: ONAME OTYPE OPACK or OLITERAL
Russ Cox's avatar
Russ Cox committed
300
	int32	block;		// blocknumber to catch redeclaration
Ken Thompson's avatar
Ken Thompson committed
301
	int32	lastlineno;	// last declaration for diagnostic
302 303 304
};
#define	S	((Sym*)0)

305 306 307 308 309 310
struct	Pkg
{
	char*	name;
	Strlit*	path;
	char*	prefix;
	Pkg*	link;
311 312
	char	exported;	// import line written in export data
	char	direct;	// imported directly
313 314
};

315 316 317 318 319 320 321 322 323 324
typedef	struct	Iter	Iter;
struct	Iter
{
	int	done;
	Type*	tfunc;
	Type*	t;
	Node**	an;
	Node*	n;
};

325 326 327 328 329
typedef	struct	Hist	Hist;
struct	Hist
{
	Hist*	link;
	char*	name;
330 331
	int32	line;
	int32	offset;
332 333 334
};
#define	H	((Hist*)0)

335 336 337 338
enum
{
	OXXX,

339 340 341 342 343 344 345 346
	// names
	ONAME,
	ONONAME,
	OTYPE,
	OPACK,
	OLITERAL,

	// exprs
Russ Cox's avatar
Russ Cox committed
347
	OADD, OSUB, OOR, OXOR, OADDSTR,
348
	OADDR,
349
	OANDAND,
Russ Cox's avatar
Russ Cox committed
350
	OAPPENDSTR,
351
	OARRAY,
Russ Cox's avatar
Russ Cox committed
352
	OARRAYBYTESTR, OARRAYRUNESTR,
353
	OAS, OAS2, OAS2MAPW, OAS2FUNC, OAS2RECV, OAS2MAPR, OAS2DOTTYPE, OASOP,
354 355 356 357 358
	OBAD,
	OCALL, OCALLFUNC, OCALLMETH, OCALLINTER,
	OCAP,
	OCLOSE,
	OCLOSED,
359
	OCLOSURE,
Russ Cox's avatar
Russ Cox committed
360 361
	OCMPIFACE, OCMPSTR,
	OCOMPLIT, OMAPLIT, OSTRUCTLIT, OARRAYLIT,
Russ Cox's avatar
Russ Cox committed
362
	OCONV, OCONVNOP, OCONVIFACE, OCONVSLICE,
Ken Thompson's avatar
Ken Thompson committed
363
	OCOPY,
364
	ODCL, ODCLFUNC, ODCLFIELD, ODCLCONST, ODCLTYPE,
365
	ODOT, ODOTPTR, ODOTMETH, ODOTINTER, OXDOT,
366
	ODOTTYPE,
367 368
	OEQ, ONE, OLT, OLE, OGE, OGT,
	OIND,
Russ Cox's avatar
Russ Cox committed
369
	OINDEX, OINDEXSTR, OINDEXMAP,
Russ Cox's avatar
Russ Cox committed
370
	OKEY, OPARAM,
371
	OLEN,
Russ Cox's avatar
Russ Cox committed
372
	OMAKE, OMAKECHAN, OMAKEMAP, OMAKESLICE,
373 374
	OHMUL, ORRC, OLRC,	// high-mul and rotate-carry
	OMUL, ODIV, OMOD, OLSH, ORSH, OAND, OANDNOT,
375 376 377 378
	ONEW,
	ONOT, OCOM, OPLUS, OMINUS,
	OOROR,
	OPANIC, OPANICN, OPRINT, OPRINTN,
Russ Cox's avatar
Russ Cox committed
379 380
	OSEND, OSENDNB,
	OSLICE, OSLICEARR, OSLICESTR,
381
	ORECV,
Russ Cox's avatar
Russ Cox committed
382
	ORUNESTR,
Russ Cox's avatar
Russ Cox committed
383
	OSELRECV,
384
	OIOTA,
385

386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
	// stmts
	OBLOCK,
	OBREAK,
	OCASE, OXCASE,
	OCONTINUE,
	ODEFER,
	OEMPTY,
	OFALL, OXFALL,
	OFOR,
	OGOTO,
	OIF,
	OLABEL,
	OPROC,
	ORANGE,
	ORETURN,
	OSELECT,
	OSWITCH,
	OTYPECASE,
Russ Cox's avatar
Russ Cox committed
404
	OTYPESW,	// l = r.(type)
405 406 407 408 409 410 411 412 413 414 415

	// types
	OTCHAN,
	OTMAP,
	OTSTRUCT,
	OTINTER,
	OTFUNC,
	OTARRAY,

	// for back ends
	OCMP, ODEC, OEXTEND, OINC, OREGISTER, OINDREG,
416 417 418 419 420 421 422 423 424 425 426

	OEND,
};
enum
{
	Txxx,			// 0

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

Ken Thompson's avatar
Ken Thompson committed
429
	TFLOAT32,		// 12
430
	TFLOAT64,
Ken Thompson's avatar
Ken Thompson committed
431
	TFLOAT,
432

Ken Thompson's avatar
Ken Thompson committed
433
	TBOOL,			// 15
434

Ken Thompson's avatar
Ken Thompson committed
435
	TPTR32, TPTR64,		// 16
436

Ken Thompson's avatar
Ken Thompson committed
437
	TDDD,			// 18
438 439
	TFUNC,
	TARRAY,
440
	T_old_DARRAY,
Ken Thompson's avatar
Ken Thompson committed
441
	TSTRUCT,		// 22
442 443
	TCHAN,
	TMAP,
Ken Thompson's avatar
Ken Thompson committed
444
	TINTER,			// 25
445 446 447 448 449
	TFORW,
	TFIELD,
	TANY,
	TSTRING,

450
	// pseudo-types for literals
Ken Thompson's avatar
Ken Thompson committed
451
	TIDEAL,			// 30
452
	TNIL,
Russ Cox's avatar
Russ Cox committed
453
	TBLANK,
Russ Cox's avatar
Russ Cox committed
454 455 456
	
	// pseudo-type for frame layout
	TFUNCARGS,
457
	TCHANARGS,
458

Ken Thompson's avatar
Ken Thompson committed
459
	NTYPE,
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
};
enum
{
	CTxxx,

	CTINT,
	CTFLT,
	CTSTR,
	CTBOOL,
	CTNIL,
};

enum
{
	/* types of channel */
475
	/* must match ../../pkg/nreflect/type.go:/Chandir */
476
	Cxxx,
Russ Cox's avatar
Russ Cox committed
477 478 479
	Crecv = 1<<0,
	Csend = 1<<1,
	Cboth = Crecv | Csend,
480 481 482 483 484 485 486 487 488
};

enum
{
	Pxxx,

	PEXTERN,	// declaration context
	PAUTO,
	PPARAM,
489
	PPARAMOUT,
Russ Cox's avatar
Russ Cox committed
490
	PPARAMREF,	// param passed by reference
Russ Cox's avatar
Russ Cox committed
491
	PFUNC,
492 493

	PHEAP = 1<<7,
494 495
};

496 497
enum
{
498
	Etop = 1<<1,	// evaluated at statement level
Russ Cox's avatar
Russ Cox committed
499 500
	Erv = 1<<2,	// evaluated in value context
	Etype = 1<<3,
Russ Cox's avatar
Russ Cox committed
501 502
	Ecall = 1<<4,	// call-only expressions are ok
	Efnstruct = 1<<5,	// multivalue function returns are ok
Russ Cox's avatar
Russ Cox committed
503
	Eiota = 1<<6,		// iota is ok
Russ Cox's avatar
Russ Cox committed
504
	Easgn = 1<<7,		// assigning to expression
505 506
	Eindir = 1<<8,		// indirecting through expression
	Eaddr = 1<<9,		// taking address of expression
507 508
};

Russ Cox's avatar
Russ Cox committed
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
#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
525
	Sym*	gotype;
526
	int	width;
Russ Cox's avatar
Russ Cox committed
527 528
	char	name;
	char	etype;
Ken Thompson's avatar
Ken Thompson committed
529
	char	addr;
Russ Cox's avatar
Russ Cox committed
530 531 532 533
};

EXTERN	Var	var[NVAR];

534 535 536 537 538 539 540 541 542
typedef	struct	Typedef	Typedef;
struct	Typedef
{
	char*	name;
	int	etype;
	int	sameas;
};

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

544
typedef	struct	Sig	Sig;
545
struct	Sig
546 547
{
	char*	name;
548
	Pkg*	pkg;
549 550 551
	Sym*	isym;
	Sym*	tsym;
	Type*	type;
552 553 554 555 556 557
	uint32	hash;
	int32	perm;
	int32	offset;
	Sig*	link;
};

558 559 560 561 562
typedef	struct	Io	Io;
struct	Io
{
	char*	infile;
	Biobuf*	bin;
563
	int32	ilineno;
Russ Cox's avatar
Russ Cox committed
564
	int	nlsemi;
565
	int	peekc;
Ken Thompson's avatar
Ken Thompson committed
566
	int	peekc1;	// second peekc for ...
567 568 569
	char*	cp;	// used for content when bin==nil
};

570 571 572
typedef	struct	Dlist	Dlist;
struct	Dlist
{
Ken Thompson's avatar
Ken Thompson committed
573
	Type*	field;
574 575
};

576 577 578 579 580 581 582
typedef	struct	Idir	Idir;
struct Idir
{
	Idir*	link;
	char*	dir;
};

583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
/*
 * 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
};

604 605 606 607 608 609 610 611 612 613 614
/*
 * note this is the runtime representation
 * of the compilers arrays.
 *
 * typedef	struct
 * {				// must not move anything
 * 	uchar	array[8];	// pointer to data
 * 	uchar	nel[4];		// number of elements
 * 	uchar	cap[4];		// allocated number of elements
 * } Array;
 */
615 616
EXTERN	int	Array_array;	// runtime offsetof(Array,array) - same for String
EXTERN	int	Array_nel;	// runtime offsetof(Array,nel) - same for String
617 618 619
EXTERN	int	Array_cap;	// runtime offsetof(Array,cap)
EXTERN	int	sizeof_Array;	// runtime sizeof(Array)

620 621 622 623 624 625 626 627 628 629 630 631 632

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

633 634
EXTERN	Dlist	dotlist[10];	// size is max depth of embeddeds

635 636
EXTERN	Io	curio;
EXTERN	Io	pushedio;
637
EXTERN	int32	lexlineno;
638
EXTERN	int32	lineno;
639
EXTERN	int32	prevlineno;
640 641 642 643
EXTERN	char*	pathname;
EXTERN	Hist*	hist;
EXTERN	Hist*	ehist;

Ken Thompson's avatar
Ken Thompson committed
644
EXTERN	char*	infile;
645 646 647
EXTERN	char*	outfile;
EXTERN	Biobuf*	bout;
EXTERN	int	nerrors;
Russ Cox's avatar
Russ Cox committed
648
EXTERN	int	nsyntaxerrors;
649
EXTERN	char	namebuf[NSYMB];
650
EXTERN	char	lexbuf[NSYMB];
651 652
EXTERN	char	debug[256];
EXTERN	Sym*	hash[NHASH];
653 654 655 656 657 658 659 660 661 662
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
663
EXTERN	Pkg*	phash[128];
664
EXTERN	int	tptr;		// either TPTR32 or TPTR64
Russ Cox's avatar
Russ Cox committed
665
extern	char*	runtimeimport;
Ken Thompson's avatar
Ken Thompson committed
666
extern	char*	unsafeimport;
667
EXTERN	Idir*	idirs;
668 669

EXTERN	Type*	types[NTYPE];
670
EXTERN	Type*	idealstring;
Russ Cox's avatar
Russ Cox committed
671
EXTERN	Type*	idealbool;
Ken Thompson's avatar
Ken Thompson committed
672
EXTERN	uchar	simtype[NTYPE];
673
EXTERN	uchar	isptr[NTYPE];
Russ Cox's avatar
Russ Cox committed
674
EXTERN	uchar	isforw[NTYPE];
675 676 677
EXTERN	uchar	isint[NTYPE];
EXTERN	uchar	isfloat[NTYPE];
EXTERN	uchar	issigned[NTYPE];
678
EXTERN	uchar	issimple[NTYPE];
679

680 681 682
EXTERN	uchar	okforeq[NTYPE];
EXTERN	uchar	okforadd[NTYPE];
EXTERN	uchar	okforand[NTYPE];
683 684 685 686 687 688 689
EXTERN	uchar	okfornone[NTYPE];
EXTERN	uchar	okforcmp[NTYPE];
EXTERN	uchar	okforbool[NTYPE];
EXTERN	uchar	okforcap[NTYPE];
EXTERN	uchar	okforlen[NTYPE];
EXTERN	uchar	okforarith[NTYPE];
EXTERN	uchar*	okfor[OEND];
Russ Cox's avatar
Russ Cox committed
690
EXTERN	uchar	iscmp[OEND];
Ken Thompson's avatar
Ken Thompson committed
691 692 693 694 695

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

Russ Cox's avatar
Russ Cox committed
697
EXTERN	NodeList*	xtop;
Russ Cox's avatar
Russ Cox committed
698
EXTERN	NodeList*	externdcl;
699
EXTERN	NodeList*	closures;
Russ Cox's avatar
Russ Cox committed
700 701
EXTERN	NodeList*	exportlist;
EXTERN	NodeList*	typelist;
702
EXTERN	int	dclcontext;		// PEXTERN/PAUTO
Russ Cox's avatar
Russ Cox committed
703
EXTERN	int	incannedimport;
704
EXTERN	int	statuniqgen;		// name generator for static temps
Russ Cox's avatar
Russ Cox committed
705
EXTERN	int	loophack;
706

707
EXTERN	uint32	iota;
708
EXTERN	NodeList*	lastconst;
709
EXTERN	Node*	lasttype;
710
EXTERN	int32	maxarg;
711
EXTERN	int32	stksize;		// stack size for current frame
Russ Cox's avatar
Russ Cox committed
712 713
EXTERN	int32	blockgen;		// max block number
EXTERN	int32	block;			// current block number
Ken Thompson's avatar
defer  
Ken Thompson committed
714
EXTERN	int	hasdefer;		// flag that curfn has defer statetment
715

Russ Cox's avatar
Russ Cox committed
716 717
EXTERN	Node*	curfn;

718 719 720
EXTERN	int	maxround;
EXTERN	int	widthptr;

Russ Cox's avatar
Russ Cox committed
721 722
EXTERN	Node*	typesw;
EXTERN	Node*	nblank;
723

724 725
extern	int	thechar;
extern	char*	thestring;
726
EXTERN	char*	hunk;
727 728
EXTERN	int32	nhunk;
EXTERN	int32	thunk;
729

Russ Cox's avatar
Russ Cox committed
730
EXTERN	int	exporting;
Russ Cox's avatar
Russ Cox committed
731
EXTERN	int	noargnames;
Russ Cox's avatar
Russ Cox committed
732

Russ Cox's avatar
Russ Cox committed
733
EXTERN	int	funcdepth;
734
EXTERN	int	typecheckok;
735
EXTERN	int	packagequotes;
Russ Cox's avatar
Russ Cox committed
736

737 738
EXTERN	int	compiling_runtime;

739 740 741 742 743 744 745 746
/*
 *	y.tab.c
 */
int	yyparse(void);

/*
 *	lex.c
 */
747
void	addidir(char*);
Russ Cox's avatar
Russ Cox committed
748
void	importfile(Val*, int line);
Ken Thompson's avatar
Ken Thompson committed
749
void	cannedimports(char*, char*);
750
void	unimportfile(void);
751
int32	yylex(void);
Russ Cox's avatar
Russ Cox committed
752
void	typeinit(void);
753 754
void	lexinit(void);
char*	lexname(int);
755
int32	getr(void);
Ken Thompson's avatar
Ken Thompson committed
756
int	escchar(int, int*, vlong*);
757 758 759 760 761
int	getc(void);
void	ungetc(int);
void	mkpackage(char*);

/*
Ken Thompson's avatar
Ken Thompson committed
762
 *	mparith1.c
763
 */
Ken Thompson's avatar
Ken Thompson committed
764 765
int	mpcmpfixflt(Mpint *a, Mpflt *b);
int	mpcmpfltfix(Mpflt *a, Mpint *b);
Ken Thompson's avatar
Ken Thompson committed
766 767
int	mpcmpfixfix(Mpint *a, Mpint *b);
int	mpcmpfixc(Mpint *b, vlong c);
Ken Thompson's avatar
Ken Thompson committed
768 769
int	mpcmpfltflt(Mpflt *a, Mpflt *b);
int	mpcmpfltc(Mpflt *b, double c);
Ken Thompson's avatar
Ken Thompson committed
770 771
void	mpsubfixfix(Mpint *a, Mpint *b);
void	mpsubfltflt(Mpflt *a, Mpflt *b);
Ken Thompson's avatar
Ken Thompson committed
772 773 774 775
void	mpaddcfix(Mpint *a, vlong c);
void	mpaddcflt(Mpflt *a, double c);
void	mpmulcfix(Mpint *a, vlong c);
void	mpmulcflt(Mpflt *a, double c);
Ken Thompson's avatar
Ken Thompson committed
776
void	mpdivfixfix(Mpint *a, Mpint *b);
Ken Thompson's avatar
Ken Thompson committed
777 778 779
void	mpmodfixfix(Mpint *a, Mpint *b);
void	mpatofix(Mpint *a, char *s);
void	mpatoflt(Mpflt *a, char *s);
780
int	mpmovefltfix(Mpint *a, Mpflt *b);
Ken Thompson's avatar
Ken Thompson committed
781
void	mpmovefixflt(Mpflt *a, Mpint *b);
Ken Thompson's avatar
Ken Thompson committed
782
int	Bconv(Fmt*);
Ken Thompson's avatar
Ken Thompson committed
783

Ken Thompson's avatar
Ken Thompson committed
784 785 786 787 788 789 790 791
/*
 *	mparith2.c
 */
void	mpmovefixfix(Mpint *a, Mpint *b);
void	mpmovecfix(Mpint *a, vlong v);
int	mptestfix(Mpint *a);
void	mpaddfixfix(Mpint *a, Mpint *b);
void	mpmulfixfix(Mpint *a, Mpint *b);
792
void	mpmulfract(Mpint *a, Mpint *b);
Ken Thompson's avatar
Ken Thompson committed
793
void	mpdivmodfixfix(Mpint *q, Mpint *r, Mpint *n, Mpint *d);
794
void	mpdivfract(Mpint *a, Mpint *b);
Ken Thompson's avatar
Ken Thompson committed
795
void	mpnegfix(Mpint *a);
Ken Thompson's avatar
Ken Thompson committed
796
void	mpandfixfix(Mpint *a, Mpint *b);
797
void	mpandnotfixfix(Mpint *a, Mpint *b);
Ken Thompson's avatar
Ken Thompson committed
798 799 800 801 802 803
void	mplshfixfix(Mpint *a, Mpint *b);
void	mporfixfix(Mpint *a, Mpint *b);
void	mprshfixfix(Mpint *a, Mpint *b);
void	mpxorfixfix(Mpint *a, Mpint *b);
void	mpcomfix(Mpint *a);
vlong	mpgetfix(Mpint *a);
804
void	mpshiftfix(Mpint *a, int s);
Ken Thompson's avatar
Ken Thompson committed
805

Ken Thompson's avatar
Ken Thompson committed
806 807 808
/*
 *	mparith3.c
 */
809 810
int	sigfig(Mpflt *a);
void	mpnorm(Mpflt *a);
Ken Thompson's avatar
Ken Thompson committed
811 812 813 814 815 816 817 818
void	mpmovefltflt(Mpflt *a, Mpflt *b);
void	mpmovecflt(Mpflt *a, double f);
int	mptestflt(Mpflt *a);
void	mpaddfltflt(Mpflt *a, Mpflt *b);
void	mpmulfltflt(Mpflt *a, Mpflt *b);
void	mpdivfltflt(Mpflt *a, Mpflt *b);
void	mpnegflt(Mpflt *a);
double	mpgetflt(Mpflt *a);
819
int	Fconv(Fmt*);
820 821 822 823

/*
 *	subr.c
 */
824 825
void*	mal(int32);
void*	remal(void*, int32, int32);
826
void	errorexit(void);
827
uint32	stringhash(char*);
828
Sym*	lookup(char*);
829 830 831 832 833
Sym*	pkglookup(char*, Pkg*);
Sym*	restrictlookup(char*, Pkg*);
Pkg*	mkpkg(Strlit*);
Strlit*	strlit(char*);
void	importdot(Pkg*, Node*);
834
void	yyerror(char*, ...);
Russ Cox's avatar
Russ Cox committed
835 836
void	yyerrorl(int, char*, ...);
void	flusherrors(void);
837
int	parserline(void);
838 839
void	warn(char*, ...);
void	fatal(char*, ...);
840
void	linehist(char*, int32, int);
841
int32	setlineno(Node*);
842
Node*	nod(int, Node*, Node*);
843
Node*	nodlit(Val);
844
Type*	typ(int);
Ken Thompson's avatar
Ken Thompson committed
845
int	algtype(Type*);
846 847
void	dodump(Node*, int);
void	dump(char*, Node*);
848
void	dumplist(char*, NodeList*);
849 850 851
Type*	aindex(Node*, Type*);
int	isnil(Node*);
int	isptrto(Type*, int);
Russ Cox's avatar
Russ Cox committed
852
int	istype(Type*, int);
853 854
int	isfixedarray(Type*);
int	isslice(Type*);
855
int	isinter(Type*);
Ken Thompson's avatar
Ken Thompson committed
856
int	isnilinter(Type*);
Ken Thompson's avatar
Ken Thompson committed
857
int	isddd(Type*);
858
int	isideal(Type*);
Russ Cox's avatar
Russ Cox committed
859
int	isblank(Node*);
860
Type*	maptype(Type*, Type*);
Ken Thompson's avatar
Ken Thompson committed
861
Type*	methtype(Type*);
862
Node*	typename(Type*);
863
int	eqtype(Type*, Type*);
Russ Cox's avatar
6g:  
Russ Cox committed
864
int	cvttype(Type*, Type*);
Russ Cox's avatar
Russ Cox committed
865
int	eqtypenoname(Type*, Type*);
866
void	argtype(Node*, Type*);
867
int	eqargs(Type*, Type*);
868
uint32	typehash(Type*);
869
void	frame(int);
870
Node*	nodintconst(int64);
871
void	nodconst(Node*, Type*, int64);
872 873
Node*	nodnil(void);
Node*	nodbool(int);
874 875 876
void	ullmancalc(Node*);
void	badtype(int, Type*, Type*);
Type*	ptrto(Type*);
877
NodeList*	cleanidlist(NodeList*);
878
Node*	syslook(char*, int);
Ken Thompson's avatar
Ken Thompson committed
879
Node*	treecopy(Node*);
880
NodeList*	listtreecopy(NodeList*);
Russ Cox's avatar
Russ Cox committed
881
int	isselect(Node*);
882
Node*	staticname(Type*);
883
int	iscomposite(Type*);
884
Node*	callnew(Type*);
885
Node*	saferef(Node*, NodeList**);
Russ Cox's avatar
Russ Cox committed
886
Node*	safeval(Node*, NodeList**);
887 888
int	is64(Type*);
int	noconv(Type*, Type*);
889 890 891 892 893
NodeList*	list1(Node*);
NodeList*	list(NodeList*, Node*);
NodeList*	concat(NodeList*, NodeList*);
int		count(NodeList*);
Node*	liststmt(NodeList*);
894 895 896 897 898 899 900 901 902 903 904 905 906 907

Type**	getthis(Type*);
Type**	getoutarg(Type*);
Type**	getinarg(Type*);

Type*	getthisx(Type*);
Type*	getoutargx(Type*);
Type*	getinargx(Type*);

Type*	structfirst(Iter*, Type**);
Type*	structnext(Iter*);
Type*	funcfirst(Iter*, Type*);
Type*	funcnext(Iter*);

908 909 910 911 912 913
int	brcom(int);
int	brrev(int);
void	setmaxarg(Type*);
int	dotoffset(Node*, int*, Node**);
void	tempname(Node*, Type*);

914 915
int	Econv(Fmt*);
int	Jconv(Fmt*);
916
int	Lconv(Fmt*);
917 918 919 920
int	Oconv(Fmt*);
int	Sconv(Fmt*);
int	Tconv(Fmt*);
int	Nconv(Fmt*);
Russ Cox's avatar
Russ Cox committed
921
void	exprfmt(Fmt*, Node*, int);
922
int	Wconv(Fmt*);
923 924
int	Zconv(Fmt*);

Russ Cox's avatar
Russ Cox committed
925 926
int	lookdot0(Sym*, Type*, Type**);
int	adddot1(Sym*, Type*, int, Type**);
927 928
Node*	adddot(Node*);
void	expandmeth(Sym*, Type*);
929
void	genwrapper(Type*, Type*, Sym*);
930

Russ Cox's avatar
Russ Cox committed
931 932
int	simsimtype(Type*);

933 934 935 936 937
int	powtwo(Node*);
Type*	tounsigned(Type*);
void	smagic(Magic*);
void	umagic(Magic*);

938
void	redeclare(Sym*, char*);
Russ Cox's avatar
Russ Cox committed
939
Sym*	ngotype(Node*);
940

941

942 943 944
/*
 *	dcl.c
 */
Russ Cox's avatar
Russ Cox committed
945
void	declare(Node*, int);
946 947
Type*	dodcltype(Type*);
void	updatetype(Type*, Type*);
948
void	defaultlit(Node**, Type*);
Russ Cox's avatar
Russ Cox committed
949
void	defaultlit2(Node**, Node**, int);
Russ Cox's avatar
Russ Cox committed
950
int	structcount(Type*);
951
void	addmethod(Sym*, Type*, int);
952
Node*	methodname(Node*, Type*);
953
Node*	methodname1(Node*, Node*);
954
Type*	methodfunc(Type*);
Russ Cox's avatar
Russ Cox committed
955
Sym*	methodsym(Sym*, Type*);
956
Type*	functype(Node*, NodeList*, NodeList*);
957 958
char*	thistypenam(Node*);
void	funcnam(Type*, char*);
Ken Thompson's avatar
init  
Ken Thompson committed
959
Node*	renameinit(Node*);
960 961
void	funchdr(Node*);
void	funcbody(Node*);
Russ Cox's avatar
Russ Cox committed
962
Node*	typenod(Type*);
963 964
Type*	dostruct(NodeList*, int);
Type**	stotype(NodeList*, int, Type**);
965
Type*	sortinter(Type*);
Ken Thompson's avatar
Ken Thompson committed
966 967
void	markdcl(void);
void	popdcl(void);
968
void	poptodcl(void);
969
void	dumpdcl(char*);
970 971 972 973
void	markdclstack(void);
void	testdclstack(void);
Sym*	pushdcl(Sym*);
void	addvar(Node*, Type*, int);
974 975
void	addtyp(Type*, int);
void	addconst(Node*, Node*, int);
976
Node*	fakethis(void);
977
int	isifacemethod(Type*);
978
Node*	dclname(Sym*);
979 980 981 982
Node*	newname(Sym*);
Node*	oldname(Sym*);
Type*	newtype(Sym*);
Type*	oldtype(Sym*);
983
void	fninit(NodeList*);
984
Node*	nametodcl(Node*, Type*);
Russ Cox's avatar
Russ Cox committed
985
NodeList*	checkarglist(NodeList*, int);
986 987 988
void	checkwidth(Type*);
void	defercheckwidth(void);
void	resumecheckwidth(void);
Ken Thompson's avatar
Ken Thompson committed
989
Node*	embedded(Sym*);
Russ Cox's avatar
Russ Cox committed
990
NodeList*	variter(NodeList*, Node*, NodeList*);
991
NodeList*	constiter(NodeList*, Node*, NodeList*);
992

993
Node*	unsafenmagic(Node*, NodeList*);
Russ Cox's avatar
Russ Cox committed
994
void	dclchecks(void);
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
void	funccompile(Node*);

Node*	typedcl0(Sym*);
Node*	typedcl1(Node*, Node*, int);
void	typedcl2(Type*, Type*);

/*
 * closure.c
 */
void	closurehdr(Node*);
Node*	closurebody(NodeList*);
void	typecheckclosure(Node*);
Node*	walkclosure(Node*, NodeList**);

Russ Cox's avatar
Russ Cox committed
1009

Ken Thompson's avatar
Ken Thompson committed
1010 1011 1012 1013
/*
 * sinit.c
 */

1014
NodeList*	initfix(NodeList*);
Ken Thompson's avatar
Ken Thompson committed
1015

1016 1017 1018
/*
 *	export.c
 */
Russ Cox's avatar
Russ Cox committed
1019
void	autoexport(Node*, int);
1020
int	exportname(char*);
Russ Cox's avatar
Russ Cox committed
1021 1022
void	exportsym(Node*);
void	packagesym(Node*);
1023 1024 1025 1026 1027
void	dumpe(Sym*);
void	dumpexport(void);
void	dumpexporttype(Sym*);
void	dumpexportvar(Sym*);
void	dumpexportconst(Sym*);
Russ Cox's avatar
Russ Cox committed
1028
void	importconst(Sym *s, Type *t, Node *v);
Russ Cox's avatar
Russ Cox committed
1029
void	importmethod(Sym *s, Type *t);
1030
void	importtype(Type *s, Type *t);
Russ Cox's avatar
Russ Cox committed
1031 1032
void	importvar(Sym *s, Type *t, int ctxt);
Type*	pkgtype(Sym*);
1033
Sym*	importsym(Sym*, int);
1034 1035 1036 1037 1038

/*
 *	walk.c
 */
void	walk(Node*);
1039
void	walkstmt(Node**);
1040
void	walkstmtlist(NodeList*);
1041
void	walkexprlist(NodeList*, NodeList**);
1042
void	walkconv(Node**, NodeList**);
1043
void	walkdottype(Node*, NodeList**);
Ken Thompson's avatar
Ken Thompson committed
1044
void	walkas(Node*);
Ken Thompson's avatar
Ken Thompson committed
1045
void	walkswitch(Node*);
1046
void	walkrange(Node*);
Ken Thompson's avatar
Ken Thompson committed
1047
void	walkselect(Node*);
1048
void	walkdot(Node*, NodeList**);
1049
void	walkexpr(Node**, NodeList**);
Russ Cox's avatar
Russ Cox committed
1050 1051 1052
Node*	mkcall(char*, Type*, NodeList**, ...);
Node*	mkcall1(Node*, Type*, NodeList**, ...);
Node*	chanfn(char*, int, Type*);
1053 1054 1055 1056
Node*	ascompatee1(int, Node*, Node*, NodeList**);
NodeList*	ascompatee(int, NodeList*, NodeList*, NodeList**);
NodeList*	ascompatet(int, NodeList*, Type**, int, NodeList**);
NodeList*	ascompatte(int, Type**, NodeList*, int, NodeList**);
1057
Node*	mapop(Node*, NodeList**);
Ken Thompson's avatar
Ken Thompson committed
1058
Type*	fixchan(Type*);
Russ Cox's avatar
Russ Cox committed
1059
Node*	ifacecvt(Type*, Node*, int, NodeList**);
1060 1061 1062
int	ifaceas(Type*, Type*, int);
int	ifaceas1(Type*, Type*, int);
void	ifacecheck(Type*, Type*, int, int);
1063
void	runifacechecks(void);
1064 1065
Node*	convas(Node*, NodeList**);
Node*	colas(NodeList*, NodeList*);
1066
void	colasdefn(NodeList*, Node*);
1067 1068 1069
NodeList*	reorder1(NodeList*);
NodeList*	reorder3(NodeList*);
NodeList*	reorder4(NodeList*);
Ken Thompson's avatar
Ken Thompson committed
1070
int	vmatch1(Node*, Node*);
Ken Thompson's avatar
Ken Thompson committed
1071
void	anylit(Node*, Node*, NodeList**);
1072
int	oaslit(Node*, NodeList**);
1073
void	heapmoves(void);
1074 1075
void	walkdeflist(NodeList*);
void	walkdef(Node*);
1076
void	typechecklist(NodeList*, int);
1077
void	typecheckswitch(Node*);
Russ Cox's avatar
Russ Cox committed
1078
void	typecheckselect(Node*);
1079
void	typecheckrange(Node*);
1080 1081
Node*	typecheckconv(Node*, Node*, Type*, int, char*);
int	checkconv(Type*, Type*, int, int*, int*, char*);
1082
Node*	typecheck(Node**, int);
1083 1084 1085 1086

/*
 *	const.c
 */
1087 1088
void	convlit1(Node**, Type*, int);
void	convlit(Node**, Type*);
1089 1090
void	evconst(Node*);
int	cmpslit(Node *l, Node *r);
Ken Thompson's avatar
Ken Thompson committed
1091
int	smallintconst(Node*);
Ken Thompson's avatar
Ken Thompson committed
1092
long	nonnegconst(Node*);
1093 1094
int	consttype(Node*);
int	isconst(Node*, int);
Russ Cox's avatar
Russ Cox committed
1095 1096
Mpflt*	truncfltlit(Mpflt*, Type*);
void	convconst(Node*, Type*, Val*);
1097

Russ Cox's avatar
Russ Cox committed
1098
/*
1099 1100 1101 1102
 *	align.c
 */
uint32	rnd(uint32, uint32);
void	dowidth(Type*);
1103
int	argsize(Type*);
1104 1105 1106

/*
 *	bits.c
Russ Cox's avatar
Russ Cox committed
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
 */
Bits	bor(Bits, Bits);
Bits	band(Bits, Bits);
Bits	bnot(Bits);
int	bany(Bits*);
int	bnum(Bits);
Bits	blsh(uint);
int	beq(Bits, Bits);
int	bset(Bits, uint);
int	Qconv(Fmt *fp);
int	bitno(int32);
1118

1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
/*
 *	gen.c
 */
typedef	struct	Prog	Prog;
#define	P	((Prog*)0)

typedef	struct	Label Label;
struct	Label
{
	uchar	op;		// OGOTO/OLABEL
	Sym*	sym;
Russ Cox's avatar
Russ Cox committed
1130
	Node*	stmt;
1131 1132 1133 1134 1135 1136 1137 1138 1139
	Prog*	label;		// pointer to code
	Prog*	breakpc;	// pointer to code
	Prog*	continpc;	// pointer to code
	Label*	link;
};
#define	L	((Label*)0)

EXTERN	Label*	labellist;

1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
typedef	struct	Plist	Plist;
struct	Plist
{
	Node*	name;
	Prog*	firstpc;
	int	recur;
	Plist*	link;
};

EXTERN	Plist*	plist;
EXTERN	Plist*	plast;

1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
EXTERN	Prog*	continpc;
EXTERN	Prog*	breakpc;
EXTERN	Prog*	pc;
EXTERN	Prog*	firstpc;

void	allocparams(void);
void	cgen_as(Node *nl, Node *nr);
void	cgen_callmeth(Node *n, int proc);
void	cgen_dcl(Node *n);
void	cgen_proc(Node *n, int proc);
void	checklabels(void);
void	gen(Node *n);
1164
void	genlist(NodeList *l);
Russ Cox's avatar
Russ Cox committed
1165
void	newlab(int op, Sym *s, Node*);
1166
Node*	sysfunc(char *name);
1167
Plist*	newplist(void);
1168

1169 1170 1171
/*
 *	obj.c
 */
1172
void	Bputname(Biobuf*, Sym*);
1173 1174 1175 1176
void	dumpglobls(void);
void	dumpobj(void);
void	ieeedtod(uint64 *ieee, double native);
void	outhist(Biobuf *b);
1177 1178

/*
1179
 *	arch-specific gen.c/gsubr.c/obj.c
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
 */
void	betypeinit(void);
vlong	convvtox(vlong, int);
void	compile(Node*);
void	proglist(void);
int	optopop(int);
void	dumpobj(void);
void	dowidth(Type*);
void	argspace(int32);
Node*	nodarg(Type*, int);
Type*	deep(Type*);
Type*	shallow(Type*);
Prog*	gjmp(Prog*);
void	patch(Prog*, Prog*);
void	bgen(Node *n, int true, Prog *to);
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);
int	isfat(Type*);
void	clearfat(Node *n);
void	cgen(Node*, Node*);
void	gused(Node*);
1203 1204
void	gdata(Node*, Node*, int);
void	gdatastring(Node*, Strlit*);
1205
void	dumptypestructs(void);
1206
void	dumpfuncs(void);
1207
void	dumpdata(void);
1208 1209 1210 1211 1212 1213 1214
void	ggloblnod(Node *nam, int32 width);
void	ggloblsym(Sym *s, int32 width, int dupok);
void	zfile(Biobuf *b, char *p, int n);
void	zhist(Biobuf *b, int line, vlong offset);
void	zname(Biobuf *b, Sym *s, int t);
void	nopout(Prog*);
int	dstringptr(Sym *s, int off, char *str);
Russ Cox's avatar
Russ Cox committed
1215 1216 1217 1218 1219
int	dgostringptr(Sym*, int off, char *str);
int	dgostrlitptr(Sym*, int off, Strlit*);
int	dsymptr(Sym *s, int off, Sym *x, int xoff);
int	duint8(Sym *s, int off, uint8 v);
int	duint16(Sym *s, int off, uint16 v);
1220
int	duint32(Sym *s, int off, uint32 v);
Russ Cox's avatar
Russ Cox committed
1221 1222
int	duint64(Sym *s, int off, uint64 v);
int	duintptr(Sym *s, int off, uint64 v);
1223
int	duintxx(Sym *s, int off, uint64 v, int wid);
Russ Cox's avatar
Russ Cox committed
1224
void	genembedtramp(Type*, Type*, Sym*);
Ken Thompson's avatar
Ken Thompson committed
1225
int	gen_as_init(Node*);
1226