/* Generated by Nim Compiler v0.13.0 */
/*   (c) 2015 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 64

#include "nimbase.h"
#include <string.h>
typedef struct Ropeobj169006 Ropeobj169006;
typedef struct Tpasscontext261002 Tpasscontext261002;
typedef struct Tsym214822 Tsym214822;
typedef struct Tgen514007 Tgen514007;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Cell47505 Cell47505;
typedef struct Cellseq47521 Cellseq47521;
typedef struct Gcheap49818 Gcheap49818;
typedef struct Gcstack49816 Gcstack49816;
typedef struct Cellset47517 Cellset47517;
typedef struct Pagedesc47513 Pagedesc47513;
typedef struct Memregion29688 Memregion29688;
typedef struct Smallchunk29640 Smallchunk29640;
typedef struct Llchunk29682 Llchunk29682;
typedef struct Bigchunk29642 Bigchunk29642;
typedef struct Intset29614 Intset29614;
typedef struct Trunk29610 Trunk29610;
typedef struct Avlnode29686 Avlnode29686;
typedef struct Gcstat49814 Gcstat49814;
typedef struct Tnode214790 Tnode214790;
typedef struct Ttype214828 Ttype214828;
typedef struct Tlineinfo182337 Tlineinfo182337;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Tident189012 Tident189012;
typedef struct Tnodeseq214784 Tnodeseq214784;
typedef struct Tidobj189006 Tidobj189006;
typedef struct Ttypeseq214824 Ttypeseq214824;
typedef struct Tscope214816 Tscope214816;
typedef struct TY214925 TY214925;
typedef struct Tstrtable214794 Tstrtable214794;
typedef struct Tsymseq214792 Tsymseq214792;
typedef struct Tloc214804 Tloc214804;
typedef struct Tlib214808 Tlib214808;
typedef struct Basechunk29638 Basechunk29638;
typedef struct Freecell29630 Freecell29630;
typedef struct Tinstantiation214812 Tinstantiation214812;
typedef struct Tlistentry135010 Tlistentry135010;
typedef struct TY214913 TY214913;
typedef N_NIMCALL_PTR(void, TY3489) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3494) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3489 marker;
TY3494 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Tpasscontext261002  {
  TNimObject Sup;
NIM_BOOL fromcache;
};
struct  Tgen514007  {
  Tpasscontext261002 Sup;
Tsym214822* module;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  Cell47505  {
NI refcount;
TNimType* typ;
};
struct  Cellseq47521  {
NI len;
NI cap;
Cell47505** d;
};
struct  Cellset47517  {
NI counter;
NI max;
Pagedesc47513* head;
Pagedesc47513** data;
};
typedef Smallchunk29640* TY29703[512];
typedef Trunk29610* Trunkbuckets29612[256];
struct  Intset29614  {
Trunkbuckets29612 data;
};
struct  Memregion29688  {
NI minlargeobj;
NI maxlargeobj;
TY29703 freesmallchunks;
Llchunk29682* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk29642* freechunkslist;
Intset29614 chunkstarts;
Avlnode29686* root;
Avlnode29686* deleted;
Avlnode29686* last;
Avlnode29686* freeavlnodes;
};
struct  Gcstat49814  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap49818  {
Gcstack49816* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq47521 zct;
Cellseq47521 decstack;
Cellset47517 cycleroots;
Cellseq47521 tempstack;
NI recgclock;
Memregion29688 region;
Gcstat49814 stat;
};
struct  Tlineinfo182337  {
NI16 line;
NI16 col;
NI32 fileindex;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tnode214790  {
Ttype214828* typ;
Tlineinfo182337 info;
NU16 flags;
NU8 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym214822* sym;
} S4;
struct {Tident189012* ident;
} S5;
struct {Tnodeseq214784* sons;
} S6;
} kindU;
NimStringDesc* comment;
};
typedef Ropeobj169006* TY501232[2];
struct  Tidobj189006  {
  TNimObject Sup;
NI id;
};
struct  Tstrtable214794  {
NI counter;
Tsymseq214792* data;
};
struct  Tloc214804  {
NU8 k;
NU8 s;
NU16 flags;
Ttype214828* t;
Ropeobj169006* r;
Ropeobj169006* heaproot;
};
struct  Tsym214822  {
  Tidobj189006 Sup;
NU8 kind;
union{
struct {Ttypeseq214824* typeinstcache;
Tscope214816* typscope;
} S1;
struct {TY214925* procinstcache;
Tsym214822* gcunsafetyreason;
} S2;
struct {TY214925* usedgenerics;
Tstrtable214794 tab;
} S3;
struct {Tsym214822* guard;
NI bitsize;
} S4;
} kindU;
NU8 magic;
Ttype214828* typ;
Tident189012* name;
Tlineinfo182337 info;
Tsym214822* owner;
NU32 flags;
Tnode214790* ast;
NU32 options;
NI position;
NI offset;
Tloc214804 loc;
Tlib214808* annex;
Tnode214790* constraint;
};
struct  Tident189012  {
  Tidobj189006 Sup;
NimStringDesc* s;
Tident189012* next;
NI h;
};
struct  Ropeobj169006  {
  TNimObject Sup;
Ropeobj169006* left;
Ropeobj169006* right;
NI length;
NimStringDesc* data;
};
struct  Gcstack49816  {
Gcstack49816* prev;
Gcstack49816* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY29619[8];
struct  Pagedesc47513  {
Pagedesc47513* next;
NI key;
TY29619 bits;
};
struct  Basechunk29638  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk29640  {
  Basechunk29638 Sup;
Smallchunk29640* next;
Smallchunk29640* prev;
Freecell29630* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk29682  {
NI size;
NI acc;
Llchunk29682* next;
};
struct  Bigchunk29642  {
  Basechunk29638 Sup;
Bigchunk29642* next;
Bigchunk29642* prev;
NI align;
NF data;
};
struct  Trunk29610  {
Trunk29610* next;
NI key;
TY29619 bits;
};
typedef Avlnode29686* TY29693[2];
struct  Avlnode29686  {
TY29693 link;
NI key;
NI upperbound;
NI level;
};
struct  Ttype214828  {
  Tidobj189006 Sup;
NU8 kind;
NU8 callconv;
NU32 flags;
Ttypeseq214824* sons;
Tnode214790* n;
Tsym214822* owner;
Tsym214822* sym;
Tsym214822* destructor;
Tsym214822* deepcopy;
Tsym214822* assignment;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc214804 loc;
};
struct  Tscope214816  {
NI depthlevel;
Tstrtable214794 symbols;
Tnodeseq214784* usingsyms;
Tscope214816* parent;
};
struct  Tlistentry135010  {
  TNimObject Sup;
Tlistentry135010* prev;
Tlistentry135010* next;
};
struct  Tlib214808  {
  Tlistentry135010 Sup;
NU8 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj169006* name;
Tnode214790* path;
};
struct  Freecell29630  {
Freecell29630* next;
NI zerofield;
};
struct  Tinstantiation214812  {
Tsym214822* sym;
Ttypeseq214824* concretetypes;
TY214913* usedby;
NI compilesid;
};
struct Tnodeseq214784 {
  TGenericSeq Sup;
  Tnode214790* data[SEQ_DECL_SIZE];
};
struct Ttypeseq214824 {
  TGenericSeq Sup;
  Ttype214828* data[SEQ_DECL_SIZE];
};
struct TY214925 {
  TGenericSeq Sup;
  Tinstantiation214812* data[SEQ_DECL_SIZE];
};
struct Tsymseq214792 {
  TGenericSeq Sup;
  Tsym214822* data[SEQ_DECL_SIZE];
};
struct TY214913 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP5230)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(Cell47505*, usrtocell_51440)(void* usr);
static N_INLINE(void, rtladdzct_53001)(Cell47505* c);
N_NOINLINE(void, addzct_51417)(Cellseq47521* s, Cell47505* c);
N_NIMCALL(NI, sonslen_217351)(Tnode214790* n);
N_NIMCALL(NimStringDesc*, getmodulename_271009)(Tnode214790* n);
N_NIMCALL(void, adddependencyaux_514013)(NimStringDesc* importing, NimStringDesc* imported);
N_NIMCALL(void, addf_170205)(Ropeobj169006** c, NimStringDesc* frmt, Ropeobj169006** args, NI argsLen0);
N_NIMCALL(Ropeobj169006*, rope_169277)(NimStringDesc* s);
N_NIMCALL(Tnode214790*, adddotdependency_514020)(Tpasscontext261002* c, Tnode214790* n);
N_NIMCALL(void, writerope_169836)(Ropeobj169006* head, NimStringDesc* filename, NIM_BOOL usewarning);
N_NIMCALL(Ropeobj169006*, HEX25_169905)(NimStringDesc* frmt, Ropeobj169006** args, NI argsLen0);
N_NIMCALL(NimStringDesc*, noschangeFileExt)(NimStringDesc* filename, NimStringDesc* ext);
N_NIMCALL(NimStringDesc*, nosextractFilename)(NimStringDesc* path);
STRING_LITERAL(TMP5231, "$1 -> $2;$n", 11);
STRING_LITERAL(TMP5232, "digraph $1 {$n$2}$n", 19);
STRING_LITERAL(TMP5233, "", 0);
STRING_LITERAL(TMP5234, "dot", 3);
Ropeobj169006* gdotgraph_514011;
extern TNimType NTI261002; /* TPassContext */
TNimType NTI514007; /* TGen */
extern TNimType NTI214788; /* PSym */
TNimType NTI514009; /* PGen */
extern Gcheap49818 gch_49859;
N_NIMCALL(void, TMP5230)(void* p, NI op) {
	Tgen514007* a;
	a = (Tgen514007*)p;
	nimGCvisit((void*)(*a).module, op);
}

static N_INLINE(Cell47505*, usrtocell_51440)(void* usr) {
	Cell47505* result;
	result = 0;
	result = ((Cell47505*) ((NI)((NU64)(((NI) (usr))) - (NU64)(((NI)sizeof(Cell47505))))));
	return result;
}

static N_INLINE(void, rtladdzct_53001)(Cell47505* c) {
	addzct_51417((&gch_49859.zct), c);
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		Cell47505* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_51440(src);
		(*c).refcount += ((NI) 8);
	}
	LA3: ;
	{
		Cell47505* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_51440((*dest));
		{
			(*c).refcount -= ((NI) 8);
			if (!((NU64)((*c).refcount) < (NU64)(((NI) 8)))) goto LA11;
			rtladdzct_53001(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

N_NIMCALL(Tpasscontext261002*, myopen_514078)(Tsym214822* module) {
	Tpasscontext261002* result;
	Tgen514007* g;
	result = 0;
	g = 0;
	g = (Tgen514007*) newObj((&NTI514009), sizeof(Tgen514007));
	(*g).Sup.Sup.m_type = (&NTI514007);
	asgnRefNoCycle((void**) (&(*g).module), module);
	result = &g->Sup;
	return result;
}

N_NIMCALL(void, adddependencyaux_514013)(NimStringDesc* importing, NimStringDesc* imported) {
	TY501232 LOC1;
	memset((void*)LOC1, 0, sizeof(LOC1));
	LOC1[0] = rope_169277(importing);
	LOC1[1] = rope_169277(imported);
	addf_170205(&gdotgraph_514011, ((NimStringDesc*) &TMP5231), LOC1, 2);
}

N_NIMCALL(Tnode214790*, adddotdependency_514020)(Tpasscontext261002* c, Tnode214790* n) {
	Tnode214790* result;
	Tgen514007* g;
	result = 0;
	result = n;
	g = ((Tgen514007*) (c));
	switch ((*n).kind) {
	case ((NU8) 116):
	{
		{
			NI i_514037;
			NI HEX3Atmp_514058;
			NI LOC3;
			NI res_514061;
			i_514037 = 0;
			HEX3Atmp_514058 = 0;
			LOC3 = 0;
			LOC3 = sonslen_217351(n);
			HEX3Atmp_514058 = (NI)(LOC3 - ((NI) 1));
			res_514061 = ((NI) 0);
			{
				while (1) {
					NimStringDesc* imported;
					if (!(res_514061 <= HEX3Atmp_514058)) goto LA5;
					i_514037 = res_514061;
					imported = getmodulename_271009((*n).kindU.S6.sons->data[i_514037]);
					adddependencyaux_514013((*(*(*g).module).name).s, imported);
					res_514061 += ((NI) 1);
				} LA5: ;
			}
		}
	}
	break;
	case ((NU8) 120):
	case ((NU8) 117):
	{
		NimStringDesc* imported;
		imported = getmodulename_271009((*n).kindU.S6.sons->data[((NI) 0)]);
		adddependencyaux_514013((*(*(*g).module).name).s, imported);
	}
	break;
	case ((NU8) 115):
	case ((NU8) 112):
	case ((NU8) 126):
	case ((NU8) 127):
	{
		{
			NI i_514055;
			NI HEX3Atmp_514066;
			NI LOC9;
			NI res_514069;
			i_514055 = 0;
			HEX3Atmp_514066 = 0;
			LOC9 = 0;
			LOC9 = sonslen_217351(n);
			HEX3Atmp_514066 = (NI)(LOC9 - ((NI) 1));
			res_514069 = ((NI) 0);
			{
				while (1) {
					Tnode214790* LOC12;
					if (!(res_514069 <= HEX3Atmp_514066)) goto LA11;
					i_514055 = res_514069;
					LOC12 = 0;
					LOC12 = adddotdependency_514020(c, (*n).kindU.S6.sons->data[i_514055]);
					res_514069 += ((NI) 1);
				} LA11: ;
			}
		}
	}
	break;
	default:
	{
	}
	break;
	}
	return result;
}

N_NIMCALL(void, generatedot_514003)(NimStringDesc* project) {
	TY501232 LOC1;
	NimStringDesc* LOC2;
	NimStringDesc* LOC3;
	Ropeobj169006* LOC4;
	NimStringDesc* LOC5;
	memset((void*)LOC1, 0, sizeof(LOC1));
	LOC2 = 0;
	LOC2 = nosextractFilename(project);
	LOC3 = 0;
	LOC3 = noschangeFileExt(LOC2, ((NimStringDesc*) &TMP5233));
	LOC1[0] = rope_169277(LOC3);
	LOC1[1] = gdotgraph_514011;
	LOC4 = 0;
	LOC4 = HEX25_169905(((NimStringDesc*) &TMP5232), LOC1, 2);
	LOC5 = 0;
	LOC5 = noschangeFileExt(project, ((NimStringDesc*) &TMP5234));
	writerope_169836(LOC4, LOC5, NIM_FALSE);
}
NIM_EXTERNC N_NOINLINE(void, compiler_dependsInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, compiler_dependsDatInit000)(void) {
static TNimNode TMP1183[1];
NTI514007.size = sizeof(Tgen514007);
NTI514007.kind = 17;
NTI514007.base = (&NTI261002);
TMP1183[0].kind = 1;
TMP1183[0].offset = offsetof(Tgen514007, module);
TMP1183[0].typ = (&NTI214788);
TMP1183[0].name = "module";
NTI514007.node = &TMP1183[0];
NTI514009.size = sizeof(Tgen514007*);
NTI514009.kind = 22;
NTI514009.base = (&NTI514007);
NTI514009.marker = TMP5230;
}

