2008-06-04 15:37:38 -06:00
|
|
|
// 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 <bio.h>
|
|
|
|
|
2010-10-27 18:56:32 -06:00
|
|
|
#undef OAPPEND
|
|
|
|
|
2009-09-09 00:16:19 -06:00
|
|
|
// avoid <ctype.h>
|
|
|
|
#undef isblank
|
|
|
|
#define isblank goisblank
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
#ifndef EXTERN
|
2009-03-30 17:13:11 -06:00
|
|
|
#define EXTERN extern
|
2008-06-04 15:37:38 -06:00
|
|
|
#endif
|
2009-11-11 14:08:35 -07:00
|
|
|
|
2009-11-11 17:33:23 -07:00
|
|
|
#undef BUFSIZ
|
2009-11-11 14:08:35 -07:00
|
|
|
|
2011-11-16 14:58:02 -07:00
|
|
|
// The parser's maximum stack size.
|
|
|
|
// We have to use a #define macro here since yacc
|
|
|
|
// or bison will check for its definition and use
|
|
|
|
// a potentially smaller value if it is undefined.
|
|
|
|
#define YYMAXDEPTH 500
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
NHUNK = 50000,
|
|
|
|
BUFSIZ = 8192,
|
|
|
|
NSYMB = 500,
|
|
|
|
NHASH = 1024,
|
|
|
|
STRINGSZ = 200,
|
|
|
|
MAXALIGN = 7,
|
|
|
|
UINF = 100,
|
2008-06-13 19:16:23 -06:00
|
|
|
HISTSZ = 10,
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
PRIME1 = 3,
|
2008-09-28 21:22:31 -06:00
|
|
|
|
|
|
|
AUNK = 100,
|
2009-01-26 10:56:42 -07:00
|
|
|
|
2011-12-12 20:22:09 -07:00
|
|
|
// These values are known by runtime.
|
|
|
|
// The MEMx and NOEQx values must run in parallel. See algtype.
|
2009-01-26 10:56:42 -07:00
|
|
|
AMEM = 0,
|
2012-01-19 23:32:55 -07:00
|
|
|
AMEM0,
|
2011-08-08 07:35:32 -06:00
|
|
|
AMEM8,
|
|
|
|
AMEM16,
|
|
|
|
AMEM32,
|
|
|
|
AMEM64,
|
|
|
|
AMEM128,
|
2011-12-12 20:22:09 -07:00
|
|
|
ANOEQ,
|
2012-01-19 23:32:55 -07:00
|
|
|
ANOEQ0,
|
2011-08-08 07:35:32 -06:00
|
|
|
ANOEQ8,
|
|
|
|
ANOEQ16,
|
|
|
|
ANOEQ32,
|
|
|
|
ANOEQ64,
|
|
|
|
ANOEQ128,
|
2011-12-12 20:22:09 -07:00
|
|
|
ASTRING,
|
|
|
|
AINTER,
|
|
|
|
ANILINTER,
|
|
|
|
ASLICE,
|
2012-01-26 14:25:07 -07:00
|
|
|
AFLOAT32,
|
|
|
|
AFLOAT64,
|
|
|
|
ACPLX64,
|
|
|
|
ACPLX128,
|
2008-11-14 17:35:08 -07:00
|
|
|
|
2009-12-03 13:46:34 -07:00
|
|
|
BADWIDTH = -1000000000,
|
2008-06-04 15:37:38 -06:00
|
|
|
};
|
|
|
|
|
2011-07-27 14:47:45 -06:00
|
|
|
extern vlong MAXWIDTH;
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
/*
|
|
|
|
* note this is the representation
|
|
|
|
* of the compilers string literals,
|
2009-04-09 19:16:21 -06:00
|
|
|
* it is not the runtime representation
|
2008-06-04 15:37:38 -06:00
|
|
|
*/
|
2009-04-09 19:16:21 -06:00
|
|
|
typedef struct Strlit Strlit;
|
|
|
|
struct Strlit
|
2008-06-04 15:37:38 -06:00
|
|
|
{
|
2008-08-03 18:25:15 -06:00
|
|
|
int32 len;
|
2008-06-04 15:37:38 -06:00
|
|
|
char s[3]; // variable
|
|
|
|
};
|
|
|
|
|
2008-08-08 18:13:31 -06:00
|
|
|
enum
|
|
|
|
{
|
2008-12-01 18:22:05 -07:00
|
|
|
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,
|
2008-08-08 18:13:31 -06:00
|
|
|
Mpsign = Mpbase >> 1,
|
2008-12-01 18:22:05 -07:00
|
|
|
Mpmask = Mpbase - 1,
|
|
|
|
Mpdebug = 0,
|
2008-08-08 18:13:31 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct Mpint Mpint;
|
|
|
|
struct Mpint
|
|
|
|
{
|
|
|
|
long a[Mpprec];
|
|
|
|
uchar neg;
|
|
|
|
uchar ovf;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct Mpflt Mpflt;
|
|
|
|
struct Mpflt
|
|
|
|
{
|
2008-12-01 18:22:05 -07:00
|
|
|
Mpint val;
|
|
|
|
short exp;
|
2008-08-08 18:13:31 -06:00
|
|
|
};
|
|
|
|
|
2010-02-17 23:08:30 -07:00
|
|
|
typedef struct Mpcplx Mpcplx;
|
|
|
|
struct Mpcplx
|
|
|
|
{
|
|
|
|
Mpflt real;
|
|
|
|
Mpflt imag;
|
|
|
|
};
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
typedef struct Val Val;
|
|
|
|
struct Val
|
|
|
|
{
|
2008-08-08 18:13:31 -06:00
|
|
|
short ctype;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
short reg; // OREGISTER
|
|
|
|
short bval; // bool value CTBOOL
|
2011-12-08 20:07:43 -07:00
|
|
|
Mpint* xval; // int CTINT, rune CTRUNE
|
2008-08-08 18:13:31 -06:00
|
|
|
Mpflt* fval; // float CTFLT
|
2010-02-17 23:08:30 -07:00
|
|
|
Mpcplx* cval; // float CTCPLX
|
2009-04-09 19:16:21 -06:00
|
|
|
Strlit* sval; // string CTSTR
|
2008-08-08 18:13:31 -06:00
|
|
|
} u;
|
2008-06-04 15:37:38 -06:00
|
|
|
};
|
|
|
|
|
2010-01-22 18:06:20 -07:00
|
|
|
typedef struct Pkg Pkg;
|
2008-06-04 15:37:38 -06:00
|
|
|
typedef struct Sym Sym;
|
|
|
|
typedef struct Node Node;
|
2009-07-17 02:00:44 -06:00
|
|
|
typedef struct NodeList NodeList;
|
2008-06-04 15:37:38 -06:00
|
|
|
typedef struct Type Type;
|
2011-03-15 12:05:37 -06:00
|
|
|
typedef struct Label Label;
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
struct Type
|
|
|
|
{
|
2008-06-21 16:11:29 -06:00
|
|
|
uchar etype;
|
|
|
|
uchar chan;
|
2008-06-04 15:37:38 -06:00
|
|
|
uchar trecur; // to detect loops
|
2008-10-03 17:15:55 -06:00
|
|
|
uchar printed;
|
2008-10-21 21:55:40 -06:00
|
|
|
uchar embedded; // TFIELD embedded type
|
2008-11-05 12:27:50 -07:00
|
|
|
uchar siggen;
|
2011-12-05 12:40:19 -07:00
|
|
|
uchar funarg; // on TSTRUCT and TFIELD
|
2008-12-09 14:00:50 -07:00
|
|
|
uchar copyany;
|
2008-12-11 12:54:33 -07:00
|
|
|
uchar local; // created in this file
|
2009-08-07 13:50:26 -06:00
|
|
|
uchar deferwidth;
|
2009-10-09 00:03:34 -06:00
|
|
|
uchar broke;
|
2011-12-14 07:05:33 -07:00
|
|
|
uchar isddd; // TFIELD is ... argument
|
2010-12-13 09:57:41 -07:00
|
|
|
uchar align;
|
2008-06-21 16:11:29 -06:00
|
|
|
|
2009-06-06 13:46:38 -06:00
|
|
|
Node* nod; // canonical OTYPE node
|
2010-06-08 19:50:02 -06:00
|
|
|
Type* orig; // original type (type literal or predefined type)
|
2009-08-19 18:27:08 -06:00
|
|
|
int lineno;
|
2009-06-06 13:46:38 -06:00
|
|
|
|
2008-06-21 16:11:29 -06:00
|
|
|
// TFUNCT
|
|
|
|
uchar thistuple;
|
|
|
|
uchar outtuple;
|
|
|
|
uchar intuple;
|
2008-07-05 13:49:25 -06:00
|
|
|
uchar outnamed;
|
2008-06-21 16:11:29 -06:00
|
|
|
|
2008-09-14 17:57:55 -06:00
|
|
|
Type* method;
|
2009-07-07 17:05:55 -06:00
|
|
|
Type* xmethod;
|
2008-09-14 17:57:55 -06:00
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
Sym* sym;
|
2008-08-03 18:25:15 -06:00
|
|
|
int32 vargen; // unique name for OTYPE/ONAME
|
2008-06-04 15:37:38 -06:00
|
|
|
|
2008-09-14 17:57:55 -06:00
|
|
|
Node* nname;
|
|
|
|
vlong argwid;
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
// most nodes
|
|
|
|
Type* type;
|
|
|
|
vlong width; // offset in TFIELD, width in all others
|
|
|
|
|
|
|
|
// TFIELD
|
|
|
|
Type* down; // also used in TMAP
|
2009-04-09 19:16:21 -06:00
|
|
|
Strlit* note; // literal string annotation
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
// TARRAY
|
2008-08-28 16:17:37 -06:00
|
|
|
int32 bound; // negative is dynamic array
|
2009-07-06 23:31:20 -06:00
|
|
|
|
2009-06-25 22:02:39 -06:00
|
|
|
int32 maplineno; // first use of TFORW as map key
|
2009-08-07 14:14:01 -06:00
|
|
|
int32 embedlineno; // first use of TFORW as embedded type
|
2012-06-07 01:06:40 -06:00
|
|
|
|
|
|
|
// for TFORW, where to copy the eventual value to
|
|
|
|
NodeList *copyto;
|
2008-06-04 15:37:38 -06:00
|
|
|
};
|
|
|
|
#define T ((Type*)0)
|
|
|
|
|
2011-08-31 05:37:14 -06:00
|
|
|
typedef struct InitEntry InitEntry;
|
|
|
|
typedef struct InitPlan InitPlan;
|
|
|
|
|
|
|
|
struct InitEntry
|
|
|
|
{
|
|
|
|
vlong xoffset; // struct, array only
|
|
|
|
Node *key; // map only
|
|
|
|
Node *expr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InitPlan
|
|
|
|
{
|
|
|
|
vlong lit; // bytes of initialized non-zero literals
|
|
|
|
vlong zero; // bytes of zeros
|
|
|
|
vlong expr; // bytes of run-time computed expressions
|
|
|
|
|
|
|
|
InitEntry *e;
|
|
|
|
int len;
|
|
|
|
int cap;
|
|
|
|
};
|
|
|
|
|
2011-08-24 11:07:08 -06:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
EscUnknown,
|
|
|
|
EscHeap,
|
|
|
|
EscScope,
|
|
|
|
EscNone,
|
|
|
|
EscNever,
|
|
|
|
};
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
struct Node
|
|
|
|
{
|
2011-08-28 10:05:00 -06:00
|
|
|
// Tree structure.
|
|
|
|
// Generic recursive walks should follow these fields.
|
|
|
|
Node* left;
|
|
|
|
Node* right;
|
|
|
|
Node* ntest;
|
|
|
|
Node* nincr;
|
|
|
|
NodeList* ninit;
|
|
|
|
NodeList* nbody;
|
|
|
|
NodeList* nelse;
|
|
|
|
NodeList* list;
|
|
|
|
NodeList* rlist;
|
|
|
|
|
2008-06-21 16:11:29 -06:00
|
|
|
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
|
2012-05-24 15:20:07 -06:00
|
|
|
uchar bounded; // bounds check unnecessary
|
2009-01-29 18:38:58 -07:00
|
|
|
uchar class; // PPARAM, PAUTO, PEXTERN, etc
|
2008-06-21 16:11:29 -06:00
|
|
|
uchar method; // OCALLMETH name
|
2008-10-21 21:55:40 -06:00
|
|
|
uchar embedded; // ODCLFIELD embedded type
|
2008-12-15 14:44:27 -07:00
|
|
|
uchar colas; // OAS resulting from :=
|
2009-01-26 18:20:29 -07:00
|
|
|
uchar diag; // already printed error about this
|
2011-08-24 11:07:08 -06:00
|
|
|
uchar esc; // EscXXX
|
2009-02-06 14:47:10 -07:00
|
|
|
uchar funcdepth;
|
2009-06-06 13:46:38 -06:00
|
|
|
uchar builtin; // built-in name, like len or close
|
2009-07-29 13:00:34 -06:00
|
|
|
uchar walkdef;
|
2009-07-29 13:47:51 -06:00
|
|
|
uchar typecheck;
|
2009-08-07 13:50:26 -06:00
|
|
|
uchar local;
|
2011-08-31 05:37:14 -06:00
|
|
|
uchar dodata;
|
2009-08-12 14:18:19 -06:00
|
|
|
uchar initorder;
|
2009-09-14 19:38:30 -06:00
|
|
|
uchar used;
|
2010-02-01 01:25:59 -07:00
|
|
|
uchar isddd;
|
2010-09-11 22:17:44 -06:00
|
|
|
uchar readonly;
|
2012-02-08 22:26:08 -07:00
|
|
|
uchar implicit;
|
2011-10-13 13:46:39 -06:00
|
|
|
uchar addrtaken; // address taken, even if not moved to heap
|
2011-12-12 20:22:09 -07:00
|
|
|
uchar dupok; // duplicate definitions ok (for func)
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
// most nodes
|
|
|
|
Type* type;
|
2010-10-15 13:25:34 -06:00
|
|
|
Type* realtype; // as determined by typecheck
|
2011-06-09 16:02:34 -06:00
|
|
|
Node* orig; // original form, for printing, and tracking copies of ONAMEs
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
// func
|
|
|
|
Node* nname;
|
2009-08-07 13:50:26 -06:00
|
|
|
Node* shortname;
|
2009-07-17 02:00:44 -06:00
|
|
|
NodeList* enter;
|
|
|
|
NodeList* exit;
|
|
|
|
NodeList* cvars; // closure params
|
2009-08-07 13:50:26 -06:00
|
|
|
NodeList* dcl; // autodcl for this func/closure
|
2011-12-14 07:05:33 -07:00
|
|
|
NodeList* inl; // copy of the body for use in inlining
|
2008-06-04 15:37:38 -06:00
|
|
|
|
2008-08-08 18:13:31 -06:00
|
|
|
// OLITERAL/OREGISTER
|
2008-06-04 15:37:38 -06:00
|
|
|
Val val;
|
|
|
|
|
2009-07-17 14:38:16 -06:00
|
|
|
// ONAME
|
|
|
|
Node* ntype;
|
2011-09-01 11:44:46 -06:00
|
|
|
Node* defn; // ONAME: initializing assignment; OLABEL: labeled statement
|
2009-09-17 17:42:10 -06:00
|
|
|
Node* pack; // real package for import . names
|
2011-06-01 09:02:43 -06:00
|
|
|
Node* curfn; // function for local variables
|
2011-08-24 11:07:08 -06:00
|
|
|
Type* paramfld; // TFIELD for this PPARAM
|
2009-07-17 14:38:16 -06:00
|
|
|
|
2009-01-29 18:38:58 -07:00
|
|
|
// 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
|
|
|
|
|
2009-02-06 14:47:10 -07:00
|
|
|
// ONAME closure param with PPARAMREF
|
|
|
|
Node* outer; // outer PPARAMREF in nested closure
|
|
|
|
Node* closure; // ONAME/PHEAP <-> ONAME/PPARAMREF
|
|
|
|
|
2011-12-14 07:05:33 -07:00
|
|
|
// ONAME substitute while inlining
|
|
|
|
Node* inlvar;
|
|
|
|
|
2010-01-22 18:06:20 -07:00
|
|
|
// OPACK
|
|
|
|
Pkg* pkg;
|
2011-08-31 05:37:14 -06:00
|
|
|
|
|
|
|
// OARRAYLIT, OMAPLIT, OSTRUCTLIT.
|
|
|
|
InitPlan* initplan;
|
2010-01-22 18:06:20 -07:00
|
|
|
|
2011-08-24 11:07:08 -06:00
|
|
|
// Escape analysis.
|
|
|
|
NodeList* escflowsrc; // flow(this, src)
|
|
|
|
int escloopdepth; // -1: global, 0: not set, function top level:1, increased inside function for every loop or label to mark scopes
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
Sym* sym; // various
|
2008-08-03 18:25:15 -06:00
|
|
|
int32 vargen; // unique name for OTYPE/ONAME
|
|
|
|
int32 lineno;
|
2010-09-10 09:53:27 -06:00
|
|
|
int32 endlineno;
|
2008-06-04 15:37:38 -06:00
|
|
|
vlong xoffset;
|
2011-06-09 16:02:34 -06:00
|
|
|
int32 stkdelta; // offset added by stack frame compaction phase.
|
2009-05-26 15:46:06 -06:00
|
|
|
int32 ostk;
|
2010-06-12 12:17:24 -06:00
|
|
|
int32 iota;
|
2011-08-28 10:05:00 -06:00
|
|
|
uint32 walkgen;
|
2008-06-04 15:37:38 -06:00
|
|
|
};
|
|
|
|
#define N ((Node*)0)
|
2011-08-28 10:05:00 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Every node has a walkgen field.
|
|
|
|
* If you want to do a traversal of a node graph that
|
|
|
|
* might contain duplicates and want to avoid
|
|
|
|
* visiting the same nodes twice, increment walkgen
|
|
|
|
* before starting. Then before processing a node, do
|
|
|
|
*
|
|
|
|
* if(n->walkgen == walkgen)
|
|
|
|
* return;
|
|
|
|
* n->walkgen = walkgen;
|
|
|
|
*
|
|
|
|
* Such a walk cannot call another such walk recursively,
|
|
|
|
* because of the use of the global walkgen.
|
|
|
|
*/
|
|
|
|
EXTERN uint32 walkgen;
|
2008-06-04 15:37:38 -06:00
|
|
|
|
2009-08-07 13:50:26 -06:00
|
|
|
struct NodeList
|
2009-07-17 02:00:44 -06:00
|
|
|
{
|
|
|
|
Node* n;
|
|
|
|
NodeList* next;
|
|
|
|
NodeList* end;
|
|
|
|
};
|
|
|
|
|
2009-08-04 23:59:23 -06:00
|
|
|
enum
|
2008-06-04 15:37:38 -06:00
|
|
|
{
|
2011-12-05 12:40:19 -07:00
|
|
|
SymExport = 1<<0, // to be exported
|
2009-08-04 23:59:23 -06:00
|
|
|
SymPackage = 1<<1,
|
2011-12-05 12:40:19 -07:00
|
|
|
SymExported = 1<<2, // already written out by export
|
2010-01-22 18:06:20 -07:00
|
|
|
SymUniq = 1<<3,
|
|
|
|
SymSiggen = 1<<4,
|
2009-08-04 23:59:23 -06:00
|
|
|
};
|
2008-06-21 16:11:29 -06:00
|
|
|
|
2009-08-04 23:59:23 -06:00
|
|
|
struct Sym
|
|
|
|
{
|
|
|
|
ushort lexical;
|
|
|
|
uchar flags;
|
2008-06-21 16:11:29 -06:00
|
|
|
uchar sym; // huffman encoding in object file
|
2009-08-04 23:59:23 -06:00
|
|
|
Sym* link;
|
2011-06-27 16:44:30 -06:00
|
|
|
int32 npkg; // number of imported packages with this name
|
2008-06-21 16:11:29 -06:00
|
|
|
|
2009-08-04 23:59:23 -06:00
|
|
|
// saved and restored by dcopy
|
2010-01-22 18:06:20 -07:00
|
|
|
Pkg* pkg;
|
2008-06-04 15:37:38 -06:00
|
|
|
char* name; // variable name
|
2009-06-06 13:46:38 -06:00
|
|
|
Node* def; // definition: ONAME OTYPE OPACK or OLITERAL
|
2011-03-15 12:05:37 -06:00
|
|
|
Label* label; // corresponding label (ephemeral)
|
2009-08-04 23:59:23 -06:00
|
|
|
int32 block; // blocknumber to catch redeclaration
|
2008-12-09 19:31:31 -07:00
|
|
|
int32 lastlineno; // last declaration for diagnostic
|
2008-06-04 15:37:38 -06:00
|
|
|
};
|
|
|
|
#define S ((Sym*)0)
|
|
|
|
|
2011-03-15 12:05:37 -06:00
|
|
|
EXTERN Sym* dclstack;
|
|
|
|
|
2010-01-22 18:06:20 -07:00
|
|
|
struct Pkg
|
|
|
|
{
|
2011-10-08 11:37:06 -06:00
|
|
|
char* name; // package name
|
|
|
|
Strlit* path; // string literal used in import statement
|
2011-04-21 06:14:50 -06:00
|
|
|
Sym* pathsym;
|
2011-10-08 11:37:06 -06:00
|
|
|
char* prefix; // escaped path for use in symbol table
|
2010-01-22 18:06:20 -07:00
|
|
|
Pkg* link;
|
2010-01-25 00:33:59 -07:00
|
|
|
char exported; // import line written in export data
|
|
|
|
char direct; // imported directly
|
2010-01-22 18:06:20 -07:00
|
|
|
};
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
typedef struct Iter Iter;
|
|
|
|
struct Iter
|
|
|
|
{
|
|
|
|
int done;
|
|
|
|
Type* tfunc;
|
|
|
|
Type* t;
|
|
|
|
Node** an;
|
|
|
|
Node* n;
|
|
|
|
};
|
|
|
|
|
2008-06-13 19:16:23 -06:00
|
|
|
typedef struct Hist Hist;
|
|
|
|
struct Hist
|
|
|
|
{
|
|
|
|
Hist* link;
|
|
|
|
char* name;
|
2008-08-03 18:25:15 -06:00
|
|
|
int32 line;
|
|
|
|
int32 offset;
|
2008-06-13 19:16:23 -06:00
|
|
|
};
|
|
|
|
#define H ((Hist*)0)
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
OXXX,
|
|
|
|
|
2009-07-31 10:29:28 -06:00
|
|
|
// names
|
|
|
|
ONAME,
|
|
|
|
ONONAME,
|
|
|
|
OTYPE,
|
|
|
|
OPACK,
|
|
|
|
OLITERAL,
|
|
|
|
|
|
|
|
// exprs
|
2009-08-03 12:58:52 -06:00
|
|
|
OADD, OSUB, OOR, OXOR, OADDSTR,
|
2009-07-31 10:29:28 -06:00
|
|
|
OADDR,
|
2008-06-04 15:37:38 -06:00
|
|
|
OANDAND,
|
2010-10-27 18:56:32 -06:00
|
|
|
OAPPEND,
|
2009-08-03 12:58:52 -06:00
|
|
|
OARRAYBYTESTR, OARRAYRUNESTR,
|
2010-02-25 16:11:07 -07:00
|
|
|
OSTRARRAYBYTE, OSTRARRAYRUNE,
|
2011-11-11 14:48:25 -07:00
|
|
|
OAS, OAS2, OAS2FUNC, OAS2RECV, OAS2MAPR, OAS2DOTTYPE,
|
2011-10-18 07:41:32 -06:00
|
|
|
OASOP,
|
2009-07-31 10:29:28 -06:00
|
|
|
OBAD,
|
|
|
|
OCALL, OCALLFUNC, OCALLMETH, OCALLINTER,
|
|
|
|
OCAP,
|
|
|
|
OCLOSE,
|
2009-08-07 13:50:26 -06:00
|
|
|
OCLOSURE,
|
2009-08-03 12:58:52 -06:00
|
|
|
OCMPIFACE, OCMPSTR,
|
2011-12-02 12:13:12 -07:00
|
|
|
OCOMPLIT, OMAPLIT, OSTRUCTLIT, OARRAYLIT, OPTRLIT,
|
2010-09-10 09:53:27 -06:00
|
|
|
OCONV, OCONVIFACE, OCONVNOP,
|
2009-11-17 21:41:44 -07:00
|
|
|
OCOPY,
|
2009-08-07 13:50:26 -06:00
|
|
|
ODCL, ODCLFUNC, ODCLFIELD, ODCLCONST, ODCLTYPE,
|
2011-10-18 07:41:32 -06:00
|
|
|
ODELETE,
|
2009-08-05 03:33:30 -06:00
|
|
|
ODOT, ODOTPTR, ODOTMETH, ODOTINTER, OXDOT,
|
2009-07-31 10:29:28 -06:00
|
|
|
ODOTTYPE,
|
2010-06-08 19:50:02 -06:00
|
|
|
ODOTTYPE2,
|
2008-06-04 15:37:38 -06:00
|
|
|
OEQ, ONE, OLT, OLE, OGE, OGT,
|
|
|
|
OIND,
|
2010-10-26 22:11:17 -06:00
|
|
|
OINDEX, OINDEXMAP,
|
2009-02-13 15:48:16 -07:00
|
|
|
OKEY, OPARAM,
|
2009-07-31 10:29:28 -06:00
|
|
|
OLEN,
|
2009-08-03 12:58:52 -06:00
|
|
|
OMAKE, OMAKECHAN, OMAKEMAP, OMAKESLICE,
|
2009-08-09 16:16:06 -06:00
|
|
|
OHMUL, ORRC, OLRC, // high-mul and rotate-carry
|
|
|
|
OMUL, ODIV, OMOD, OLSH, ORSH, OAND, OANDNOT,
|
2009-07-31 10:29:28 -06:00
|
|
|
ONEW,
|
|
|
|
ONOT, OCOM, OPLUS, OMINUS,
|
|
|
|
OOROR,
|
2010-03-24 17:53:54 -06:00
|
|
|
OPANIC, OPRINT, OPRINTN,
|
2011-07-27 15:39:30 -06:00
|
|
|
OPAREN,
|
2011-01-31 16:52:16 -07:00
|
|
|
OSEND,
|
2009-08-03 12:58:52 -06:00
|
|
|
OSLICE, OSLICEARR, OSLICESTR,
|
2010-03-30 11:53:16 -06:00
|
|
|
ORECOVER,
|
2009-07-31 10:29:28 -06:00
|
|
|
ORECV,
|
2009-08-03 12:58:52 -06:00
|
|
|
ORUNESTR,
|
2009-08-04 13:57:48 -06:00
|
|
|
OSELRECV,
|
2011-03-11 12:47:26 -07:00
|
|
|
OSELRECV2,
|
2009-09-09 02:01:39 -06:00
|
|
|
OIOTA,
|
2011-01-19 21:08:11 -07:00
|
|
|
OREAL, OIMAG, OCOMPLEX,
|
2009-07-14 00:38:39 -06:00
|
|
|
|
2009-07-31 10:29:28 -06:00
|
|
|
// stmts
|
|
|
|
OBLOCK,
|
|
|
|
OBREAK,
|
|
|
|
OCASE, OXCASE,
|
|
|
|
OCONTINUE,
|
|
|
|
ODEFER,
|
|
|
|
OEMPTY,
|
|
|
|
OFALL, OXFALL,
|
|
|
|
OFOR,
|
|
|
|
OGOTO,
|
|
|
|
OIF,
|
|
|
|
OLABEL,
|
|
|
|
OPROC,
|
|
|
|
ORANGE,
|
|
|
|
ORETURN,
|
|
|
|
OSELECT,
|
|
|
|
OSWITCH,
|
2009-09-09 01:18:16 -06:00
|
|
|
OTYPESW, // l = r.(type)
|
2009-07-31 10:29:28 -06:00
|
|
|
|
|
|
|
// types
|
|
|
|
OTCHAN,
|
|
|
|
OTMAP,
|
|
|
|
OTSTRUCT,
|
|
|
|
OTINTER,
|
|
|
|
OTFUNC,
|
|
|
|
OTARRAY,
|
2010-08-23 21:10:25 -06:00
|
|
|
OTPAREN,
|
2010-02-25 16:11:07 -07:00
|
|
|
|
2010-02-01 01:25:59 -07:00
|
|
|
// misc
|
|
|
|
ODDD,
|
2011-08-24 11:07:08 -06:00
|
|
|
ODDDARG,
|
2011-12-14 07:05:33 -07:00
|
|
|
OINLCALL, // intermediary representation of an inlined call
|
2012-06-13 18:43:20 -06:00
|
|
|
OEFACE, // itable and data words of empty-interface value
|
2012-02-10 22:19:24 -07:00
|
|
|
OITAB, // itable word of interface value
|
2009-07-31 10:29:28 -06:00
|
|
|
|
|
|
|
// for back ends
|
|
|
|
OCMP, ODEC, OEXTEND, OINC, OREGISTER, OINDREG,
|
2012-05-24 15:20:07 -06:00
|
|
|
OLROT,
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
OEND,
|
|
|
|
};
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
Txxx, // 0
|
|
|
|
|
|
|
|
TINT8, TUINT8, // 1
|
|
|
|
TINT16, TUINT16,
|
|
|
|
TINT32, TUINT32,
|
|
|
|
TINT64, TUINT64,
|
2008-10-29 13:46:44 -06:00
|
|
|
TINT, TUINT, TUINTPTR,
|
2008-06-04 15:37:38 -06:00
|
|
|
|
2010-02-17 23:08:30 -07:00
|
|
|
TCOMPLEX64, // 12
|
|
|
|
TCOMPLEX128,
|
|
|
|
|
2011-03-09 09:35:18 -07:00
|
|
|
TFLOAT32, // 14
|
2008-06-04 15:37:38 -06:00
|
|
|
TFLOAT64,
|
|
|
|
|
2011-03-09 09:35:18 -07:00
|
|
|
TBOOL, // 16
|
2008-06-04 15:37:38 -06:00
|
|
|
|
2011-03-09 09:35:18 -07:00
|
|
|
TPTR32, TPTR64, // 17
|
2008-06-04 15:37:38 -06:00
|
|
|
|
2011-03-09 09:35:18 -07:00
|
|
|
TFUNC, // 19
|
2008-06-04 15:37:38 -06:00
|
|
|
TARRAY,
|
2008-08-28 16:17:37 -06:00
|
|
|
T_old_DARRAY,
|
2011-03-09 09:35:18 -07:00
|
|
|
TSTRUCT, // 22
|
2008-06-04 15:37:38 -06:00
|
|
|
TCHAN,
|
|
|
|
TMAP,
|
2011-03-09 09:35:18 -07:00
|
|
|
TINTER, // 25
|
2008-06-04 15:37:38 -06:00
|
|
|
TFORW,
|
|
|
|
TFIELD,
|
|
|
|
TANY,
|
|
|
|
TSTRING,
|
2011-03-07 13:10:01 -07:00
|
|
|
TUNSAFEPTR,
|
2008-06-04 15:37:38 -06:00
|
|
|
|
2009-03-12 20:04:38 -06:00
|
|
|
// pseudo-types for literals
|
2011-03-09 09:35:18 -07:00
|
|
|
TIDEAL, // 31
|
2009-03-12 20:04:38 -06:00
|
|
|
TNIL,
|
2009-09-09 00:16:19 -06:00
|
|
|
TBLANK,
|
2010-02-25 16:11:07 -07:00
|
|
|
|
2009-10-19 19:47:37 -06:00
|
|
|
// pseudo-type for frame layout
|
|
|
|
TFUNCARGS,
|
2009-11-19 19:20:06 -07:00
|
|
|
TCHANARGS,
|
2010-02-18 12:15:36 -07:00
|
|
|
TINTERMETH,
|
2009-03-12 20:04:38 -06:00
|
|
|
|
2008-10-29 13:46:44 -06:00
|
|
|
NTYPE,
|
2008-06-04 15:37:38 -06:00
|
|
|
};
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CTxxx,
|
|
|
|
|
|
|
|
CTINT,
|
2011-12-08 20:07:43 -07:00
|
|
|
CTRUNE,
|
2008-06-04 15:37:38 -06:00
|
|
|
CTFLT,
|
2010-02-17 23:08:30 -07:00
|
|
|
CTCPLX,
|
2008-06-04 15:37:38 -06:00
|
|
|
CTSTR,
|
|
|
|
CTBOOL,
|
|
|
|
CTNIL,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* types of channel */
|
2009-07-07 12:03:04 -06:00
|
|
|
/* must match ../../pkg/nreflect/type.go:/Chandir */
|
2008-06-04 15:37:38 -06:00
|
|
|
Cxxx,
|
2009-05-21 18:32:44 -06:00
|
|
|
Crecv = 1<<0,
|
|
|
|
Csend = 1<<1,
|
|
|
|
Cboth = Crecv | Csend,
|
2008-06-04 15:37:38 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
Pxxx,
|
|
|
|
|
|
|
|
PEXTERN, // declaration context
|
|
|
|
PAUTO,
|
|
|
|
PPARAM,
|
2009-01-29 18:38:58 -07:00
|
|
|
PPARAMOUT,
|
2009-02-06 14:47:10 -07:00
|
|
|
PPARAMREF, // param passed by reference
|
2009-01-30 15:39:42 -07:00
|
|
|
PFUNC,
|
2009-01-29 18:38:58 -07:00
|
|
|
|
|
|
|
PHEAP = 1<<7,
|
2008-06-04 15:37:38 -06:00
|
|
|
};
|
|
|
|
|
2008-06-15 21:24:30 -06:00
|
|
|
enum
|
|
|
|
{
|
2011-06-01 09:02:43 -06:00
|
|
|
Etop = 1<<1, // evaluated at statement level
|
|
|
|
Erv = 1<<2, // evaluated in value context
|
2009-08-03 12:58:52 -06:00
|
|
|
Etype = 1<<3,
|
2011-06-01 09:02:43 -06:00
|
|
|
Ecall = 1<<4, // call-only expressions are ok
|
2009-08-05 01:42:44 -06:00
|
|
|
Efnstruct = 1<<5, // multivalue function returns are ok
|
2009-08-11 18:05:22 -06:00
|
|
|
Eiota = 1<<6, // iota is ok
|
2009-09-09 00:16:19 -06:00
|
|
|
Easgn = 1<<7, // assigning to expression
|
2009-10-15 17:03:01 -06:00
|
|
|
Eindir = 1<<8, // indirecting through expression
|
|
|
|
Eaddr = 1<<9, // taking address of expression
|
2011-06-01 09:02:43 -06:00
|
|
|
Eproc = 1<<10, // inside a go statement
|
2011-07-25 22:52:02 -06:00
|
|
|
Ecomplit = 1<<11, // type in composite literal
|
2008-06-15 21:24:30 -06:00
|
|
|
};
|
|
|
|
|
2009-03-30 17:13:11 -06:00
|
|
|
#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;
|
2009-08-20 18:33:28 -06:00
|
|
|
Sym* gotype;
|
2011-06-09 16:02:34 -06:00
|
|
|
Node* node;
|
2009-05-23 16:34:29 -06:00
|
|
|
int width;
|
2009-03-30 17:13:11 -06:00
|
|
|
char name;
|
|
|
|
char etype;
|
2009-12-11 16:55:09 -07:00
|
|
|
char addr;
|
2009-03-30 17:13:11 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
EXTERN Var var[NVAR];
|
|
|
|
|
2009-03-30 18:09:28 -06:00
|
|
|
typedef struct Typedef Typedef;
|
|
|
|
struct Typedef
|
|
|
|
{
|
|
|
|
char* name;
|
|
|
|
int etype;
|
|
|
|
int sameas;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern Typedef typedefs[];
|
2009-03-30 17:13:11 -06:00
|
|
|
|
2009-03-30 18:52:21 -06:00
|
|
|
typedef struct Sig Sig;
|
2010-01-22 18:06:20 -07:00
|
|
|
struct Sig
|
2009-03-30 18:52:21 -06:00
|
|
|
{
|
|
|
|
char* name;
|
2010-01-22 18:06:20 -07:00
|
|
|
Pkg* pkg;
|
2009-07-07 12:03:04 -06:00
|
|
|
Sym* isym;
|
|
|
|
Sym* tsym;
|
|
|
|
Type* type;
|
2010-01-25 19:23:20 -07:00
|
|
|
Type* mtype;
|
2009-03-30 18:52:21 -06:00
|
|
|
int32 offset;
|
|
|
|
Sig* link;
|
|
|
|
};
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
typedef struct Io Io;
|
|
|
|
struct Io
|
|
|
|
{
|
|
|
|
char* infile;
|
|
|
|
Biobuf* bin;
|
2008-08-03 18:25:15 -06:00
|
|
|
int32 ilineno;
|
2009-12-11 16:59:41 -07:00
|
|
|
int nlsemi;
|
2011-04-23 08:54:05 -06:00
|
|
|
int eofnl;
|
2008-06-04 15:37:38 -06:00
|
|
|
int peekc;
|
2008-10-29 13:46:44 -06:00
|
|
|
int peekc1; // second peekc for ...
|
2008-06-04 15:37:38 -06:00
|
|
|
char* cp; // used for content when bin==nil
|
2010-06-11 16:28:43 -06:00
|
|
|
int importsafe;
|
2008-06-04 15:37:38 -06:00
|
|
|
};
|
|
|
|
|
2008-10-24 21:14:28 -06:00
|
|
|
typedef struct Dlist Dlist;
|
|
|
|
struct Dlist
|
|
|
|
{
|
2008-10-25 14:31:25 -06:00
|
|
|
Type* field;
|
2008-10-24 21:14:28 -06:00
|
|
|
};
|
|
|
|
|
2009-03-10 21:03:31 -06:00
|
|
|
typedef struct Idir Idir;
|
|
|
|
struct Idir
|
|
|
|
{
|
|
|
|
Idir* link;
|
|
|
|
char* dir;
|
|
|
|
};
|
|
|
|
|
2009-08-09 16:16:06 -06:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
};
|
|
|
|
|
2010-06-14 12:24:51 -06:00
|
|
|
typedef struct Prog Prog;
|
2011-08-30 07:40:46 -06:00
|
|
|
#pragma incomplete Prog
|
2010-06-14 12:24:51 -06:00
|
|
|
|
|
|
|
struct Label
|
|
|
|
{
|
2011-03-15 12:05:37 -06:00
|
|
|
uchar used;
|
2010-06-14 12:24:51 -06:00
|
|
|
Sym* sym;
|
2011-06-17 13:25:05 -06:00
|
|
|
Node* def;
|
|
|
|
NodeList* use;
|
|
|
|
Label* link;
|
|
|
|
|
|
|
|
// for use during gen
|
|
|
|
Prog* gotopc; // pointer to unresolved gotos
|
|
|
|
Prog* labelpc; // pointer to code
|
2010-06-14 12:24:51 -06:00
|
|
|
Prog* breakpc; // pointer to code
|
|
|
|
Prog* continpc; // pointer to code
|
|
|
|
};
|
|
|
|
#define L ((Label*)0)
|
|
|
|
|
2009-03-30 18:09:28 -06:00
|
|
|
/*
|
|
|
|
* note this is the runtime representation
|
|
|
|
* of the compilers arrays.
|
|
|
|
*
|
|
|
|
* typedef struct
|
|
|
|
* { // must not move anything
|
2010-10-15 13:25:34 -06:00
|
|
|
* uchar array[8]; // pointer to data
|
|
|
|
* uchar nel[4]; // number of elements
|
|
|
|
* uchar cap[4]; // allocated number of elements
|
2009-03-30 18:09:28 -06:00
|
|
|
* } Array;
|
|
|
|
*/
|
2009-04-09 19:16:21 -06:00
|
|
|
EXTERN int Array_array; // runtime offsetof(Array,array) - same for String
|
|
|
|
EXTERN int Array_nel; // runtime offsetof(Array,nel) - same for String
|
2009-03-30 18:09:28 -06:00
|
|
|
EXTERN int Array_cap; // runtime offsetof(Array,cap)
|
|
|
|
EXTERN int sizeof_Array; // runtime sizeof(Array)
|
|
|
|
|
2009-04-09 19:16:21 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* note this is the runtime representation
|
|
|
|
* of the compilers strings.
|
|
|
|
*
|
|
|
|
* typedef struct
|
|
|
|
* { // must not move anything
|
2010-10-15 13:25:34 -06:00
|
|
|
* uchar array[8]; // pointer to data
|
|
|
|
* uchar nel[4]; // number of elements
|
2009-04-09 19:16:21 -06:00
|
|
|
* } String;
|
|
|
|
*/
|
|
|
|
EXTERN int sizeof_String; // runtime sizeof(String)
|
|
|
|
|
2008-10-24 21:14:28 -06:00
|
|
|
EXTERN Dlist dotlist[10]; // size is max depth of embeddeds
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
EXTERN Io curio;
|
|
|
|
EXTERN Io pushedio;
|
2009-08-19 16:18:08 -06:00
|
|
|
EXTERN int32 lexlineno;
|
2008-08-03 18:25:15 -06:00
|
|
|
EXTERN int32 lineno;
|
2008-11-18 10:32:05 -07:00
|
|
|
EXTERN int32 prevlineno;
|
2008-06-13 19:16:23 -06:00
|
|
|
EXTERN char* pathname;
|
|
|
|
EXTERN Hist* hist;
|
|
|
|
EXTERN Hist* ehist;
|
|
|
|
|
2008-06-05 20:38:39 -06:00
|
|
|
EXTERN char* infile;
|
2008-06-04 15:37:38 -06:00
|
|
|
EXTERN char* outfile;
|
|
|
|
EXTERN Biobuf* bout;
|
|
|
|
EXTERN int nerrors;
|
2011-06-17 13:25:05 -06:00
|
|
|
EXTERN int nsavederrors;
|
2009-06-23 16:30:59 -06:00
|
|
|
EXTERN int nsyntaxerrors;
|
2010-06-09 12:00:55 -06:00
|
|
|
EXTERN int safemode;
|
2008-06-04 15:37:38 -06:00
|
|
|
EXTERN char namebuf[NSYMB];
|
2009-04-02 18:59:09 -06:00
|
|
|
EXTERN char lexbuf[NSYMB];
|
2011-07-27 12:36:21 -06:00
|
|
|
EXTERN char litbuf[NSYMB];
|
2008-06-04 15:37:38 -06:00
|
|
|
EXTERN char debug[256];
|
|
|
|
EXTERN Sym* hash[NHASH];
|
2010-01-22 18:06:20 -07:00
|
|
|
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
|
2012-07-02 17:09:05 -06:00
|
|
|
EXTERN Pkg* itabpkg; // fake pkg for itab cache
|
2010-01-22 18:06:20 -07:00
|
|
|
EXTERN Pkg* runtimepkg; // package runtime
|
|
|
|
EXTERN Pkg* stringpkg; // fake package for C strings
|
|
|
|
EXTERN Pkg* typepkg; // fake package for runtime type info
|
2012-02-12 21:26:20 -07:00
|
|
|
EXTERN Pkg* weaktypepkg; // weak references to runtime type info
|
2010-01-22 18:06:20 -07:00
|
|
|
EXTERN Pkg* unsafepkg; // package unsafe
|
2010-01-25 00:33:59 -07:00
|
|
|
EXTERN Pkg* phash[128];
|
2008-06-04 15:37:38 -06:00
|
|
|
EXTERN int tptr; // either TPTR32 or TPTR64
|
2009-10-16 00:10:49 -06:00
|
|
|
extern char* runtimeimport;
|
2008-12-08 20:46:39 -07:00
|
|
|
extern char* unsafeimport;
|
2011-09-07 13:50:21 -06:00
|
|
|
EXTERN char* myimportpath;
|
2009-03-10 21:03:31 -06:00
|
|
|
EXTERN Idir* idirs;
|
cmd/go: fix relative imports again
I tried before to make relative imports work by simply
invoking the compiler in the right directory, so that
an import of ./foo could be resolved by ./foo.a.
This required creating a separate tree of package binaries
that included the full path to the source directory, so that
/home/gopher/bar.go would be compiled in
tmpdir/work/local/home/gopher and perhaps find
a ./foo.a in that directory.
This model breaks on Windows because : appears in path
names but cannot be used in subdirectory names, and I
missed one or two places where it needed to be removed.
The model breaks more fundamentally when compiling
a test of a package that lives outside the Go path, because
we effectively use a ./ import in the generated testmain,
but there we want to be able to resolve the ./ import
of the test package to one directory and all the other ./
imports to a different directory. Piggybacking on the compiler's
current working directory is then no longer possible.
Instead, introduce a new compiler option -D prefix that
makes the compiler turn a ./ import into prefix+that,
so that import "./foo" with -D a/b/c turns into import
"a/b/c/foo". Then we can invent a package hierarchy
"_/" with subdirectories named for file system paths:
import "./foo" in the directory /home/gopher becomes
import "_/home/gopher/foo", and since that final path
is just an ordinary import now, all the ordinary processing
works, without special cases.
We will have to change the name of the hierarchy if we
ever decide to introduce a standard package with import
path "_", but that seems unlikely, and the detail is known
only in temporary packages that get thrown away at the
end of a build.
Fixes #3169.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5732045
2012-03-02 20:16:02 -07:00
|
|
|
EXTERN char* localimport;
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
EXTERN Type* types[NTYPE];
|
2009-07-29 13:47:51 -06:00
|
|
|
EXTERN Type* idealstring;
|
2012-02-21 20:54:07 -07:00
|
|
|
EXTERN Type* idealbool;
|
2011-10-18 12:55:50 -06:00
|
|
|
EXTERN Type* bytetype;
|
2011-10-25 23:19:39 -06:00
|
|
|
EXTERN Type* runetype;
|
2011-11-01 19:46:41 -06:00
|
|
|
EXTERN Type* errortype;
|
2008-10-29 13:46:44 -06:00
|
|
|
EXTERN uchar simtype[NTYPE];
|
2008-06-04 15:37:38 -06:00
|
|
|
EXTERN uchar isptr[NTYPE];
|
2009-07-06 23:31:20 -06:00
|
|
|
EXTERN uchar isforw[NTYPE];
|
2008-06-04 15:37:38 -06:00
|
|
|
EXTERN uchar isint[NTYPE];
|
|
|
|
EXTERN uchar isfloat[NTYPE];
|
2010-02-17 23:08:30 -07:00
|
|
|
EXTERN uchar iscomplex[NTYPE];
|
2008-06-04 15:37:38 -06:00
|
|
|
EXTERN uchar issigned[NTYPE];
|
2008-06-15 21:24:30 -06:00
|
|
|
EXTERN uchar issimple[NTYPE];
|
2009-07-29 13:47:51 -06:00
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
EXTERN uchar okforeq[NTYPE];
|
|
|
|
EXTERN uchar okforadd[NTYPE];
|
|
|
|
EXTERN uchar okforand[NTYPE];
|
2009-07-29 13:47:51 -06:00
|
|
|
EXTERN uchar okfornone[NTYPE];
|
|
|
|
EXTERN uchar okforcmp[NTYPE];
|
|
|
|
EXTERN uchar okforbool[NTYPE];
|
|
|
|
EXTERN uchar okforcap[NTYPE];
|
|
|
|
EXTERN uchar okforlen[NTYPE];
|
|
|
|
EXTERN uchar okforarith[NTYPE];
|
2010-02-02 00:05:15 -07:00
|
|
|
EXTERN uchar okforconst[NTYPE];
|
2009-07-29 13:47:51 -06:00
|
|
|
EXTERN uchar* okfor[OEND];
|
2009-07-30 17:53:08 -06:00
|
|
|
EXTERN uchar iscmp[OEND];
|
2008-08-08 18:13:31 -06:00
|
|
|
|
|
|
|
EXTERN Mpint* minintval[NTYPE];
|
|
|
|
EXTERN Mpint* maxintval[NTYPE];
|
|
|
|
EXTERN Mpflt* minfltval[NTYPE];
|
|
|
|
EXTERN Mpflt* maxfltval[NTYPE];
|
2008-06-04 15:37:38 -06:00
|
|
|
|
2009-08-12 14:18:19 -06:00
|
|
|
EXTERN NodeList* xtop;
|
2009-08-04 23:59:23 -06:00
|
|
|
EXTERN NodeList* externdcl;
|
2009-08-07 13:50:26 -06:00
|
|
|
EXTERN NodeList* closures;
|
2009-08-04 23:59:23 -06:00
|
|
|
EXTERN NodeList* exportlist;
|
2011-12-05 12:40:19 -07:00
|
|
|
EXTERN NodeList* importlist; // imported functions and methods with inlinable bodies
|
2009-05-18 23:11:22 -06:00
|
|
|
EXTERN int dclcontext; // PEXTERN/PAUTO
|
2009-10-16 00:10:49 -06:00
|
|
|
EXTERN int incannedimport;
|
2009-05-18 23:11:22 -06:00
|
|
|
EXTERN int statuniqgen; // name generator for static temps
|
2009-06-06 13:46:38 -06:00
|
|
|
EXTERN int loophack;
|
2008-06-04 15:37:38 -06:00
|
|
|
|
2010-06-12 12:17:24 -06:00
|
|
|
EXTERN int32 iota;
|
2009-07-17 02:00:44 -06:00
|
|
|
EXTERN NodeList* lastconst;
|
2009-07-17 14:38:16 -06:00
|
|
|
EXTERN Node* lasttype;
|
2008-08-03 18:25:15 -06:00
|
|
|
EXTERN int32 maxarg;
|
2008-10-13 21:14:09 -06:00
|
|
|
EXTERN int32 stksize; // stack size for current frame
|
2009-08-04 23:59:23 -06:00
|
|
|
EXTERN int32 blockgen; // max block number
|
|
|
|
EXTERN int32 block; // current block number
|
2009-01-27 13:03:53 -07:00
|
|
|
EXTERN int hasdefer; // flag that curfn has defer statetment
|
2008-06-04 15:37:38 -06:00
|
|
|
|
2009-08-03 12:58:52 -06:00
|
|
|
EXTERN Node* curfn;
|
|
|
|
|
2009-03-30 18:09:28 -06:00
|
|
|
EXTERN int widthptr;
|
|
|
|
|
2009-09-09 01:18:16 -06:00
|
|
|
EXTERN Node* typesw;
|
|
|
|
EXTERN Node* nblank;
|
2008-11-06 14:31:13 -07:00
|
|
|
|
2009-03-30 22:31:29 -06:00
|
|
|
extern int thechar;
|
|
|
|
extern char* thestring;
|
2011-10-25 23:19:39 -06:00
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
EXTERN char* hunk;
|
2008-08-03 18:25:15 -06:00
|
|
|
EXTERN int32 nhunk;
|
|
|
|
EXTERN int32 thunk;
|
2008-06-04 15:37:38 -06:00
|
|
|
|
2009-02-06 14:47:10 -07:00
|
|
|
EXTERN int funcdepth;
|
2009-08-07 13:50:26 -06:00
|
|
|
EXTERN int typecheckok;
|
2010-01-25 00:33:59 -07:00
|
|
|
EXTERN int compiling_runtime;
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
/*
|
|
|
|
* y.tab.c
|
|
|
|
*/
|
|
|
|
int yyparse(void);
|
|
|
|
|
2010-06-14 12:24:51 -06:00
|
|
|
/*
|
|
|
|
* 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);
|
2011-06-01 09:02:43 -06:00
|
|
|
void typecheckclosure(Node *func, int top);
|
2010-06-14 12:24:51 -06:00
|
|
|
Node* walkclosure(Node *func, NodeList **init);
|
2011-05-31 12:52:21 -06:00
|
|
|
void walkcallclosure(Node *n, NodeList **init);
|
2010-06-14 12:24:51 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
2012-05-30 16:07:39 -06:00
|
|
|
void complexbool(int op, Node *nl, Node *nr, int true, int likely, Prog *to);
|
2010-06-14 12:24:51 -06:00
|
|
|
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);
|
2012-07-29 20:24:19 -06:00
|
|
|
Node* colas(NodeList *left, NodeList *right, int32 lno);
|
2010-06-14 12:24:51 -06:00
|
|
|
void colasdefn(NodeList *left, Node *defn);
|
|
|
|
NodeList* constiter(NodeList *vl, Node *t, NodeList *cl);
|
|
|
|
Node* dclname(Sym *s);
|
|
|
|
void declare(Node *n, int ctxt);
|
|
|
|
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);
|
2011-05-31 11:41:32 -06:00
|
|
|
void ifacedcl(Node *n);
|
2010-06-14 12:24:51 -06:00
|
|
|
int isifacemethod(Type *f);
|
|
|
|
void markdcl(void);
|
|
|
|
Node* methodname(Node *n, Type *t);
|
|
|
|
Node* methodname1(Node *n, Node *t);
|
2010-07-26 16:25:10 -06:00
|
|
|
Sym* methodsym(Sym *nsym, Type *t0, int iface);
|
2010-06-14 12:24:51 -06:00
|
|
|
Node* newname(Sym *s);
|
|
|
|
Node* oldname(Sym *s);
|
|
|
|
void popdcl(void);
|
|
|
|
void poptodcl(void);
|
|
|
|
void redeclare(Sym *s, char *where);
|
|
|
|
void testdclstack(void);
|
2011-11-07 13:35:13 -07:00
|
|
|
Type* tointerface(NodeList *l);
|
|
|
|
Type* tostruct(NodeList *l);
|
2010-06-14 12:24:51 -06:00
|
|
|
Node* typedcl0(Sym *s);
|
|
|
|
Node* typedcl1(Node *n, Node *t, int local);
|
|
|
|
Node* typenod(Type *t);
|
|
|
|
NodeList* variter(NodeList *vl, Node *t, NodeList *el);
|
|
|
|
|
2011-08-24 11:07:08 -06:00
|
|
|
/*
|
|
|
|
* esc.c
|
|
|
|
*/
|
2012-02-23 21:09:53 -07:00
|
|
|
void escapes(NodeList*);
|
2011-08-24 11:07:08 -06:00
|
|
|
|
2010-06-14 12:24:51 -06:00
|
|
|
/*
|
|
|
|
* export.c
|
|
|
|
*/
|
|
|
|
void autoexport(Node *n, int ctxt);
|
|
|
|
void dumpexport(void);
|
|
|
|
int exportname(char *s);
|
|
|
|
void exportsym(Node *n);
|
2011-12-05 12:40:19 -07:00
|
|
|
void importconst(Sym *s, Type *t, Node *n);
|
|
|
|
void importimport(Sym *s, Strlit *z);
|
|
|
|
Sym* importsym(Sym *s, int op);
|
|
|
|
void importtype(Type *pt, Type *t);
|
|
|
|
void importvar(Sym *s, Type *t);
|
2010-06-14 12:24:51 -06:00
|
|
|
Type* pkgtype(Sym *s);
|
|
|
|
|
2011-10-31 11:09:40 -06:00
|
|
|
/*
|
|
|
|
* fmt.c
|
|
|
|
*/
|
|
|
|
void fmtinstallgo(void);
|
|
|
|
void dump(char *s, Node *n);
|
|
|
|
void dumplist(char *s, NodeList *l);
|
|
|
|
|
2010-06-14 12:24:51 -06:00
|
|
|
/*
|
|
|
|
* gen.c
|
|
|
|
*/
|
2011-08-24 11:07:08 -06:00
|
|
|
void addrescapes(Node *n);
|
2010-06-14 12:24:51 -06:00
|
|
|
void cgen_as(Node *nl, Node *nr);
|
|
|
|
void cgen_callmeth(Node *n, int proc);
|
2012-06-13 18:43:20 -06:00
|
|
|
void cgen_eface(Node* n, Node* res);
|
2012-06-02 20:50:57 -06:00
|
|
|
void cgen_slice(Node* n, Node* res);
|
2011-03-15 12:05:37 -06:00
|
|
|
void clearlabels(void);
|
2011-06-17 13:25:05 -06:00
|
|
|
void checklabels(void);
|
2010-06-14 12:24:51 -06:00
|
|
|
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);
|
2011-09-02 13:35:16 -06:00
|
|
|
Node* temp(Type*);
|
2010-06-14 12:24:51 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* init.c
|
|
|
|
*/
|
|
|
|
void fninit(NodeList *n);
|
2011-12-05 12:40:19 -07:00
|
|
|
Sym* renameinit(void);
|
2010-06-14 12:24:51 -06:00
|
|
|
|
2011-12-14 07:05:33 -07:00
|
|
|
/*
|
|
|
|
* inl.c
|
|
|
|
*/
|
|
|
|
void caninl(Node *fn);
|
|
|
|
void inlcalls(Node *fn);
|
2012-01-10 13:24:31 -07:00
|
|
|
void typecheckinl(Node *fn);
|
2011-12-14 07:05:33 -07:00
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
/*
|
|
|
|
* lex.c
|
|
|
|
*/
|
2010-06-14 12:24:51 -06:00
|
|
|
void cannedimports(char *file, char *cp);
|
|
|
|
void importfile(Val *f, int line);
|
|
|
|
char* lexname(int lex);
|
2011-10-25 23:19:39 -06:00
|
|
|
char* expstring(void);
|
2010-06-14 12:24:51 -06:00
|
|
|
void mkpackage(char* pkgname);
|
2009-12-27 10:32:30 -07:00
|
|
|
void unimportfile(void);
|
2008-08-03 18:25:15 -06:00
|
|
|
int32 yylex(void);
|
2010-09-12 02:07:13 -06:00
|
|
|
extern int windows;
|
2010-07-15 16:05:56 -06:00
|
|
|
extern int yylast;
|
|
|
|
extern int yyprev;
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
/*
|
2008-08-09 18:29:26 -06:00
|
|
|
* mparith1.c
|
2008-06-04 15:37:38 -06:00
|
|
|
*/
|
2010-06-14 12:24:51 -06:00
|
|
|
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);
|
2008-08-12 15:04:03 -06:00
|
|
|
int mpcmpfixflt(Mpint *a, Mpflt *b);
|
2010-06-14 12:24:51 -06:00
|
|
|
int mpcmpfltc(Mpflt *b, double c);
|
2008-08-12 15:04:03 -06:00
|
|
|
int mpcmpfltfix(Mpflt *a, Mpint *b);
|
2008-08-09 18:29:26 -06:00
|
|
|
int mpcmpfltflt(Mpflt *a, Mpflt *b);
|
2010-06-14 12:24:51 -06:00
|
|
|
void mpcomfix(Mpint *a);
|
2008-08-08 18:13:31 -06:00
|
|
|
void mpdivfixfix(Mpint *a, Mpint *b);
|
2008-08-09 18:29:26 -06:00
|
|
|
void mpmodfixfix(Mpint *a, Mpint *b);
|
2010-06-14 12:24:51 -06:00
|
|
|
void mpmovefixfix(Mpint *a, Mpint *b);
|
2008-08-09 18:29:26 -06:00
|
|
|
void mpmovefixflt(Mpflt *a, Mpint *b);
|
2010-06-14 12:24:51 -06:00
|
|
|
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);
|
2008-08-08 18:13:31 -06:00
|
|
|
|
2008-08-09 18:29:26 -06:00
|
|
|
/*
|
|
|
|
* mparith2.c
|
|
|
|
*/
|
2012-02-10 22:50:56 -07:00
|
|
|
void mpaddfixfix(Mpint *a, Mpint *b, int);
|
2008-08-08 18:13:31 -06:00
|
|
|
void mpandfixfix(Mpint *a, Mpint *b);
|
2009-03-12 20:04:38 -06:00
|
|
|
void mpandnotfixfix(Mpint *a, Mpint *b);
|
2010-06-14 12:24:51 -06:00
|
|
|
void mpdivfract(Mpint *a, Mpint *b);
|
|
|
|
void mpdivmodfixfix(Mpint *q, Mpint *r, Mpint *n, Mpint *d);
|
|
|
|
vlong mpgetfix(Mpint *a);
|
2008-08-08 18:13:31 -06:00
|
|
|
void mplshfixfix(Mpint *a, Mpint *b);
|
2010-06-14 12:24:51 -06:00
|
|
|
void mpmovecfix(Mpint *a, vlong c);
|
|
|
|
void mpmulfixfix(Mpint *a, Mpint *b);
|
|
|
|
void mpmulfract(Mpint *a, Mpint *b);
|
|
|
|
void mpnegfix(Mpint *a);
|
2008-08-08 18:13:31 -06:00
|
|
|
void mporfixfix(Mpint *a, Mpint *b);
|
|
|
|
void mprshfixfix(Mpint *a, Mpint *b);
|
2008-12-01 18:22:05 -07:00
|
|
|
void mpshiftfix(Mpint *a, int s);
|
2010-06-14 12:24:51 -06:00
|
|
|
int mptestfix(Mpint *a);
|
|
|
|
void mpxorfixfix(Mpint *a, Mpint *b);
|
2008-08-08 18:13:31 -06:00
|
|
|
|
2008-08-09 18:29:26 -06:00
|
|
|
/*
|
|
|
|
* mparith3.c
|
|
|
|
*/
|
|
|
|
void mpaddfltflt(Mpflt *a, Mpflt *b);
|
|
|
|
void mpdivfltflt(Mpflt *a, Mpflt *b);
|
|
|
|
double mpgetflt(Mpflt *a);
|
2010-06-14 12:24:51 -06:00
|
|
|
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);
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
/*
|
2010-06-14 12:24:51 -06:00
|
|
|
* obj.c
|
2008-06-04 15:37:38 -06:00
|
|
|
*/
|
2010-06-14 12:24:51 -06:00
|
|
|
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);
|
2011-04-09 07:44:20 -06:00
|
|
|
int dsname(Sym *s, int off, char *dat, int ndat);
|
2010-06-14 12:24:51 -06:00
|
|
|
void dumpobj(void);
|
|
|
|
void ieeedtod(uint64 *ieee, double native);
|
2011-04-09 07:44:20 -06:00
|
|
|
Sym* stringsym(char*, int);
|
2010-01-19 22:34:44 -07:00
|
|
|
|
2012-01-25 15:53:50 -07:00
|
|
|
/*
|
|
|
|
* order.c
|
|
|
|
*/
|
|
|
|
void order(Node *fn);
|
|
|
|
|
2009-08-07 13:50:26 -06:00
|
|
|
/*
|
2010-06-14 12:24:51 -06:00
|
|
|
* range.c
|
2009-08-07 13:50:26 -06:00
|
|
|
*/
|
2010-06-14 12:24:51 -06:00
|
|
|
void typecheckrange(Node *n);
|
|
|
|
void walkrange(Node *n);
|
2009-08-07 13:50:26 -06:00
|
|
|
|
2010-06-14 12:24:51 -06:00
|
|
|
/*
|
|
|
|
* reflect.c
|
|
|
|
*/
|
|
|
|
void dumptypestructs(void);
|
2010-09-28 11:43:50 -06:00
|
|
|
Type* methodfunc(Type *f, Type*);
|
2010-06-14 12:24:51 -06:00
|
|
|
Node* typename(Type *t);
|
|
|
|
Sym* typesym(Type *t);
|
2011-12-12 20:22:09 -07:00
|
|
|
Sym* typesymprefix(char *prefix, Type *t);
|
2011-08-24 11:07:08 -06:00
|
|
|
int haspointers(Type *t);
|
2009-02-06 14:47:10 -07:00
|
|
|
|
2009-05-21 14:46:07 -06:00
|
|
|
/*
|
2010-06-14 12:24:51 -06:00
|
|
|
* select.c
|
2009-05-21 14:46:07 -06:00
|
|
|
*/
|
2010-06-14 12:24:51 -06:00
|
|
|
void typecheckselect(Node *sel);
|
|
|
|
void walkselect(Node *sel);
|
2009-05-21 14:46:07 -06:00
|
|
|
|
2010-06-14 12:24:51 -06:00
|
|
|
/*
|
|
|
|
* sinit.c
|
|
|
|
*/
|
2010-09-20 15:23:25 -06:00
|
|
|
void anylit(int, Node *n, Node *var, NodeList **init);
|
2010-06-14 12:24:51 -06:00
|
|
|
int gen_as_init(Node *n);
|
|
|
|
NodeList* initfix(NodeList *l);
|
|
|
|
int oaslit(Node *n, NodeList **init);
|
|
|
|
int stataddr(Node *nam, Node *n);
|
2009-05-21 14:46:07 -06:00
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
/*
|
2010-06-14 12:24:51 -06:00
|
|
|
* subr.c
|
2008-06-04 15:37:38 -06:00
|
|
|
*/
|
2010-06-14 12:24:51 -06:00
|
|
|
Node* adddot(Node *n);
|
2010-06-20 12:45:53 -06:00
|
|
|
int adddot1(Sym *s, Type *t, int d, Type **save, int ignorecase);
|
2012-01-25 15:53:50 -07:00
|
|
|
void addinit(Node**, NodeList*);
|
2010-06-14 12:24:51 -06:00
|
|
|
Type* aindex(Node *b, Type *t);
|
|
|
|
int algtype(Type *t);
|
2011-12-12 20:22:09 -07:00
|
|
|
int algtype1(Type *t, Type **bad);
|
2010-06-14 12:24:51 -06:00
|
|
|
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);
|
2012-01-25 15:53:50 -07:00
|
|
|
Node* copyexpr(Node*, Type*, NodeList**);
|
2010-06-14 12:24:51 -06:00
|
|
|
int count(NodeList *l);
|
|
|
|
int cplxsubtype(int et);
|
|
|
|
int eqtype(Type *t1, Type *t2);
|
|
|
|
int eqtypenoname(Type *t1, Type *t2);
|
|
|
|
void errorexit(void);
|
2012-03-07 00:27:15 -07:00
|
|
|
void expandmeth(Type *t);
|
2010-06-14 12:24:51 -06:00
|
|
|
void fatal(char *fmt, ...);
|
|
|
|
void flusherrors(void);
|
|
|
|
void frame(int context);
|
|
|
|
Type* funcfirst(Iter *s, Type *t);
|
|
|
|
Type* funcnext(Iter *s);
|
2010-07-26 16:25:10 -06:00
|
|
|
void genwrapper(Type *rcvr, Type *method, Sym *newnam, int iface);
|
2011-12-12 20:22:09 -07:00
|
|
|
void genhash(Sym *sym, Type *t);
|
|
|
|
void geneq(Sym *sym, Type *t);
|
2010-06-14 12:24:51 -06:00
|
|
|
Type** getinarg(Type *t);
|
|
|
|
Type* getinargx(Type *t);
|
|
|
|
Type** getoutarg(Type *t);
|
|
|
|
Type* getoutargx(Type *t);
|
|
|
|
Type** getthis(Type *t);
|
|
|
|
Type* getthisx(Type *t);
|
2010-06-20 12:45:53 -06:00
|
|
|
int implements(Type *t, Type *iface, Type **missing, Type **have, int *ptr);
|
2010-06-14 12:24:51 -06:00
|
|
|
void importdot(Pkg *opkg, Node *pack);
|
|
|
|
int is64(Type *t);
|
2012-02-24 12:48:36 -07:00
|
|
|
int isbadimport(Strlit *s);
|
2010-06-14 12:24:51 -06:00
|
|
|
int isblank(Node *n);
|
2012-02-17 12:45:29 -07:00
|
|
|
int isblanksym(Sym *s);
|
2010-06-14 12:24:51 -06:00
|
|
|
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);
|
2011-06-09 16:02:34 -06:00
|
|
|
void listsort(NodeList**, int(*f)(Node*, Node*));
|
2010-06-14 12:24:51 -06:00
|
|
|
Node* liststmt(NodeList *l);
|
|
|
|
NodeList* listtreecopy(NodeList *l);
|
|
|
|
Sym* lookup(char *name);
|
|
|
|
void* mal(int32 n);
|
|
|
|
Type* maptype(Type *key, Type *val);
|
2012-03-07 00:27:15 -07:00
|
|
|
Type* methtype(Type *t, int mustname);
|
2010-06-14 12:24:51 -06:00
|
|
|
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);
|
2011-01-05 11:12:30 -07:00
|
|
|
Node* nodfltconst(Mpflt *v);
|
2010-06-14 12:24:51 -06:00
|
|
|
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);
|
2011-06-17 13:25:05 -06:00
|
|
|
void saveerrors(void);
|
2010-10-06 07:53:12 -06:00
|
|
|
Node* cheapexpr(Node *n, NodeList **init);
|
2011-07-25 10:25:37 -06:00
|
|
|
Node* localexpr(Node *n, Type *t, NodeList **init);
|
2010-06-14 12:24:51 -06:00
|
|
|
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, ...);
|
2011-08-28 10:05:00 -06:00
|
|
|
void warnl(int line, char *fmt, ...);
|
2010-06-14 12:24:51 -06:00
|
|
|
void yyerror(char *fmt, ...);
|
|
|
|
void yyerrorl(int line, char *fmt, ...);
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
/*
|
2010-06-14 12:24:51 -06:00
|
|
|
* swt.c
|
2008-06-04 15:37:38 -06:00
|
|
|
*/
|
2010-06-14 12:24:51 -06:00
|
|
|
void typecheckswitch(Node *n);
|
|
|
|
void walkswitch(Node *sw);
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
/*
|
2010-06-14 12:24:51 -06:00
|
|
|
* typecheck.c
|
2008-06-04 15:37:38 -06:00
|
|
|
*/
|
2010-06-14 12:24:51 -06:00
|
|
|
int islvalue(Node *n);
|
|
|
|
Node* typecheck(Node **np, int top);
|
|
|
|
void typechecklist(NodeList *l, int top);
|
2011-06-03 09:44:02 -06:00
|
|
|
Node* typecheckdef(Node *n);
|
|
|
|
void copytype(Node *n, Type *t);
|
|
|
|
void queuemethod(Node *n);
|
2008-06-04 15:37:38 -06:00
|
|
|
|
2009-03-30 17:13:11 -06:00
|
|
|
/*
|
2010-06-14 12:24:51 -06:00
|
|
|
* unsafe.c
|
2009-03-30 18:09:28 -06:00
|
|
|
*/
|
2011-11-09 10:30:54 -07:00
|
|
|
int isunsafebuiltin(Node *n);
|
2010-07-15 17:13:47 -06:00
|
|
|
Node* unsafenmagic(Node *n);
|
2009-03-30 18:09:28 -06:00
|
|
|
|
|
|
|
/*
|
2010-06-14 12:24:51 -06:00
|
|
|
* walk.c
|
2009-03-30 17:13:11 -06:00
|
|
|
*/
|
2010-06-14 12:24:51 -06:00
|
|
|
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);
|
2011-12-12 20:22:09 -07:00
|
|
|
Node* conv(Node*, Type*);
|
2009-03-30 18:09:28 -06:00
|
|
|
|
2009-03-30 20:15:07 -06:00
|
|
|
/*
|
2011-06-14 09:03:37 -06:00
|
|
|
* arch-specific ggen.c/gsubr.c/gobj.c/pgen.c
|
2009-03-30 20:15:07 -06:00
|
|
|
*/
|
|
|
|
#define P ((Prog*)0)
|
|
|
|
|
2009-03-30 22:31:29 -06:00
|
|
|
typedef struct Plist Plist;
|
|
|
|
struct Plist
|
|
|
|
{
|
|
|
|
Node* name;
|
|
|
|
Prog* firstpc;
|
|
|
|
int recur;
|
|
|
|
Plist* link;
|
|
|
|
};
|
|
|
|
|
|
|
|
EXTERN Plist* plist;
|
|
|
|
EXTERN Plist* plast;
|
|
|
|
|
2009-03-30 20:15:07 -06:00
|
|
|
EXTERN Prog* continpc;
|
|
|
|
EXTERN Prog* breakpc;
|
|
|
|
EXTERN Prog* pc;
|
|
|
|
EXTERN Prog* firstpc;
|
2011-06-02 10:48:17 -06:00
|
|
|
EXTERN Prog* retpc;
|
2009-03-30 20:15:07 -06:00
|
|
|
|
2010-03-31 12:46:01 -06:00
|
|
|
EXTERN Node* nodfp;
|
|
|
|
|
2010-06-14 12:24:51 -06:00
|
|
|
int anyregalloc(void);
|
2009-03-30 20:15:07 -06:00
|
|
|
void betypeinit(void);
|
2012-05-30 16:07:39 -06:00
|
|
|
void bgen(Node *n, int true, int likely, Prog *to);
|
2012-06-02 20:50:57 -06:00
|
|
|
void checkref(Node*);
|
2010-06-14 12:24:51 -06:00
|
|
|
void cgen(Node*, Node*);
|
2009-03-30 20:15:07 -06:00
|
|
|
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);
|
2010-06-14 12:24:51 -06:00
|
|
|
void compile(Node*);
|
2011-06-02 10:48:17 -06:00
|
|
|
void defframe(Prog*);
|
2010-06-14 12:24:51 -06:00
|
|
|
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);
|
2011-06-14 09:03:37 -06:00
|
|
|
void fixautoused(Prog*);
|
2009-09-17 20:15:54 -06:00
|
|
|
void gdata(Node*, Node*, int);
|
2010-03-20 19:50:01 -06:00
|
|
|
void gdatacomplex(Node*, Mpcplx*);
|
2010-06-14 12:24:51 -06:00
|
|
|
void gdatastring(Node*, Strlit*);
|
2010-07-27 14:43:58 -06:00
|
|
|
void genembedtramp(Type*, Type*, Sym*, int iface);
|
2009-03-30 22:31:29 -06:00
|
|
|
void ggloblnod(Node *nam, int32 width);
|
2012-07-02 17:09:05 -06:00
|
|
|
void ggloblsym(Sym *s, int32 width, int dupok, int rodata);
|
2010-06-14 12:24:51 -06:00
|
|
|
Prog* gjmp(Prog*);
|
|
|
|
void gused(Node*);
|
|
|
|
int isfat(Type*);
|
2011-06-14 09:03:37 -06:00
|
|
|
void markautoused(Prog*);
|
2010-06-14 12:24:51 -06:00
|
|
|
Plist* newplist(void);
|
|
|
|
Node* nodarg(Type*, int);
|
|
|
|
void nopout(Prog*);
|
|
|
|
void patch(Prog*, Prog*);
|
2011-06-17 13:25:05 -06:00
|
|
|
Prog* unpatch(Prog*);
|
2009-03-30 22:31:29 -06:00
|
|
|
void zfile(Biobuf *b, char *p, int n);
|
|
|
|
void zhist(Biobuf *b, int line, vlong offset);
|
|
|
|
void zname(Biobuf *b, Sym *s, int t);
|
2011-06-15 22:18:43 -06:00
|
|
|
|
2011-08-29 07:35:04 -06:00
|
|
|
#pragma varargck type "A" int
|
|
|
|
#pragma varargck type "B" Mpint*
|
|
|
|
#pragma varargck type "D" Addr*
|
|
|
|
#pragma varargck type "lD" Addr*
|
|
|
|
#pragma varargck type "E" int
|
2011-11-07 09:42:08 -07:00
|
|
|
#pragma varargck type "E" uint
|
2011-08-29 07:35:04 -06:00
|
|
|
#pragma varargck type "F" Mpflt*
|
2011-10-31 11:09:40 -06:00
|
|
|
#pragma varargck type "H" NodeList*
|
2011-08-29 07:35:04 -06:00
|
|
|
#pragma varargck type "J" Node*
|
2011-12-02 12:13:12 -07:00
|
|
|
#pragma varargck type "lL" int
|
|
|
|
#pragma varargck type "lL" uint
|
2011-08-29 07:35:04 -06:00
|
|
|
#pragma varargck type "L" int
|
|
|
|
#pragma varargck type "L" uint
|
|
|
|
#pragma varargck type "N" Node*
|
2011-12-12 13:42:02 -07:00
|
|
|
#pragma varargck type "lN" Node*
|
2011-08-29 07:35:04 -06:00
|
|
|
#pragma varargck type "O" uint
|
|
|
|
#pragma varargck type "P" Prog*
|
|
|
|
#pragma varargck type "Q" Bits
|
|
|
|
#pragma varargck type "R" int
|
|
|
|
#pragma varargck type "S" Sym*
|
|
|
|
#pragma varargck type "lS" Sym*
|
|
|
|
#pragma varargck type "T" Type*
|
|
|
|
#pragma varargck type "lT" Type*
|
2011-10-08 11:37:06 -06:00
|
|
|
#pragma varargck type "V" Val*
|
2011-08-29 07:35:04 -06:00
|
|
|
#pragma varargck type "Y" char*
|
|
|
|
#pragma varargck type "Z" Strlit*
|