gg.h 3.67 KB
Newer Older
Russ Cox's avatar
Russ Cox committed
1 2 3 4 5
// 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.

#ifndef	EXTERN
Russ Cox's avatar
Russ Cox committed
6
#define	EXTERN	extern
Russ Cox's avatar
Russ Cox committed
7 8
#endif

9 10 11
#include "../gc/go.h"
#include "../8l/8.out.h"

Russ Cox's avatar
Russ Cox committed
12 13 14 15 16 17 18 19 20 21 22
typedef	struct	Addr	Addr;

struct	Addr
{
	int32	offset;
	int32	offset2;

	double	dval;
	Prog*	branch;
	char	sval[NSNAME];

Ken Thompson's avatar
Ken Thompson committed
23
	Sym*	gotype;
Russ Cox's avatar
Russ Cox committed
24
	Sym*	sym;
Luuk van Dijk's avatar
Luuk van Dijk committed
25
	Node*	node;
Ken Thompson's avatar
Ken Thompson committed
26
	int	width;
Russ Cox's avatar
Russ Cox committed
27 28 29 30
	uchar	type;
	uchar	index;
	uchar	etype;
	uchar	scale;	/* doubles as width in DATA op */
Ken Thompson's avatar
Ken Thompson committed
31
	uchar	pun;	/* dont register variable */
Russ Cox's avatar
Russ Cox committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45
};
#define	A	((Addr*)0)

struct	Prog
{
	short	as;		// opcode
	uint32	loc;		// pc offset in this func
	uint32	lineno;		// source line that generated this
	Addr	from;		// src address
	Addr	to;		// dst address
	Prog*	link;		// next instruction in this func
	void*	reg;		// pointer to containing Reg struct
};

46 47
#define TEXTFLAG from.scale

Russ Cox's avatar
Russ Cox committed
48 49 50 51 52 53 54 55
// foptoas flags
enum
{
	Frev = 1<<0,
	Fpop = 1<<1,
	Fpop2 = 1<<2,
};

Russ Cox's avatar
Russ Cox committed
56 57 58
EXTERN	int32	dynloc;
EXTERN	uchar	reg[D_NONE];
EXTERN	int32	pcloc;		// instruction counter
Russ Cox's avatar
Russ Cox committed
59
EXTERN	Strlit	emptystring;
Russ Cox's avatar
Russ Cox committed
60 61 62 63 64
extern	char*	anames[];
EXTERN	Prog	zprog;
EXTERN	Node*	newproc;
EXTERN	Node*	deferproc;
EXTERN	Node*	deferreturn;
65 66
EXTERN	Node*	panicindex;
EXTERN	Node*	panicslice;
Russ Cox's avatar
Russ Cox committed
67
EXTERN	Node*	throwreturn;
Russ Cox's avatar
Russ Cox committed
68
EXTERN	int	maxstksize;
Russ Cox's avatar
Russ Cox committed
69 70
extern	uint32	unmappedzero;

Russ Cox's avatar
Russ Cox committed
71 72

/*
Russ Cox's avatar
8g:  
Russ Cox committed
73
 * ggen.c
Russ Cox's avatar
Russ Cox committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
 */
void	compile(Node*);
void	proglist(void);
void	gen(Node*);
Node*	lookdot(Node*, Node*, int);
void	cgen_as(Node*, Node*);
void	cgen_callmeth(Node*, int);
void	cgen_callinter(Node*, Node*, int);
void	cgen_proc(Node*, int);
void	cgen_callret(Node*, Node*);
void	cgen_div(int, Node*, Node*, Node*);
void	cgen_bmul(int, Node*, Node*, Node*);
void	cgen_shift(int, Node*, Node*, Node*);
void	cgen_dcl(Node*);
int	needconvert(Type*, Type*);
void	genconv(Type*, Type*);
void	allocparams(void);
void	checklabels();
void	ginscall(Node*, int);

/*
Russ Cox's avatar
8g:  
Russ Cox committed
95
 * cgen.c
Russ Cox's avatar
Russ Cox committed
96 97
 */
void	agen(Node*, Node*);
Russ Cox's avatar
Russ Cox committed
98
void	agenr(Node *n, Node *a, Node *res);
Russ Cox's avatar
Russ Cox committed
99 100 101 102 103 104 105
void	igen(Node*, Node*, Node*);
vlong	fieldoffset(Type*, Node*);
void	bgen(Node*, int, Prog*);
void	sgen(Node*, Node*, int32);
void	gmove(Node*, Node*);
Prog*	gins(int, Node*, Node*);
int	samaddr(Node*, Node*);
Russ Cox's avatar
Russ Cox committed
106
void	naddr(Node*, Addr*, int);
Russ Cox's avatar
Russ Cox committed
107
void	cgen_aret(Node*, Node*);
Russ Cox's avatar
Russ Cox committed
108
int	cgen_inline(Node*, Node*);
Russ Cox's avatar
Russ Cox committed
109
Node*	ncon(uint32);
110 111
void	mgen(Node*, Node*, Node*);
void	mfree(Node*);
Russ Cox's avatar
Russ Cox committed
112

Russ Cox's avatar
8g:  
Russ Cox committed
113 114 115 116 117 118
/*
 * cgen64.c
 */
void	cmp64(Node*, Node*, int, Prog*);
void	cgen64(Node*, Node*);

Russ Cox's avatar
Russ Cox committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
/*
 * gsubr.c
 */
void	clearp(Prog*);
void	proglist(void);
Prog*	gbranch(int, Type*);
Prog*	prog(int);
void	gaddoffset(Node*);
void	gconv(int, int);
int	conv2pt(Type*);
vlong	convvtox(vlong, int);
void	fnparam(Type*, int, int);
Prog*	gop(int, Node*, Node*, Node*);
void	setconst(Addr*, vlong);
void	setaddr(Addr*, Node*);
int	optoas(int, Type*);
Russ Cox's avatar
Russ Cox committed
135
int	foptoas(int, Type*, int);
Russ Cox's avatar
Russ Cox committed
136 137 138 139 140 141 142
void	ginit(void);
void	gclean(void);
void	regalloc(Node*, Type*, Node*);
void	regfree(Node*);
Node*	nodarg(Type*, int);
void	nodreg(Node*, Type*, int);
void	nodindreg(Node*, Type*, int);
Russ Cox's avatar
8g:  
Russ Cox committed
143
void	nodconst(Node*, Type*, int64);
Russ Cox's avatar
Russ Cox committed
144
void	gconreg(int, vlong, int);
Russ Cox's avatar
Russ Cox committed
145
void	datagostring(Strlit*, Addr*);
Russ Cox's avatar
8g:  
Russ Cox committed
146
void	datastring(char*, int, Addr*);
Russ Cox's avatar
Russ Cox committed
147 148 149 150
void	buildtxt(void);
Plist*	newplist(void);
int	isfat(Type*);
void	sudoclean(void);
Russ Cox's avatar
Russ Cox committed
151
int	sudoaddable(int, Node*, Addr*);
Russ Cox's avatar
Russ Cox committed
152
int	dotaddable(Node*, Node*);
Russ Cox's avatar
Russ Cox committed
153
void	afunclit(Addr*);
Russ Cox's avatar
Russ Cox committed
154 155
void	split64(Node*, Node*, Node*);
void	splitclean(void);
Russ Cox's avatar
8g:  
Russ Cox committed
156
void	nswap(Node*, Node*);
Russ Cox's avatar
Russ Cox committed
157

158 159 160 161 162 163 164 165
/*
 * cplx.c
 */
int	complexop(Node*, Node*);
void	complexmove(Node*, Node*);
void	complexgen(Node*, Node*);
void	complexbool(int, Node*, Node*, int, Prog*);

Russ Cox's avatar
Russ Cox committed
166 167 168 169 170 171 172 173 174 175
/*
 * list.c
 */
int	Aconv(Fmt*);
int	Dconv(Fmt*);
int	Pconv(Fmt*);
int	Rconv(Fmt*);
int	Yconv(Fmt*);
void	listinit(void);

Russ Cox's avatar
Russ Cox committed
176
void	zaddr(Biobuf*, Addr*, int, int);
Russ Cox's avatar
Russ Cox committed
177

Lucio De Re's avatar
Lucio De Re committed
178 179
#pragma	varargck	type	"D"	Addr*
#pragma	varargck	type	"lD"	Addr*