/* 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 Ropeobj170006 Ropeobj170006;
typedef struct Tpasscontext262002 Tpasscontext262002;
typedef struct Tsym215822 Tsym215822;
typedef struct Tgen515007 Tgen515007;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Cell47504 Cell47504;
typedef struct Cellseq47520 Cellseq47520;
typedef struct Gcheap49818 Gcheap49818;
typedef struct Gcstack49816 Gcstack49816;
typedef struct Cellset47516 Cellset47516;
typedef struct Pagedesc47512 Pagedesc47512;
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 Tnode215790 Tnode215790;
typedef struct Ttype215828 Ttype215828;
typedef struct Tlineinfo183337 Tlineinfo183337;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Tident190012 Tident190012;
typedef struct Tnodeseq215784 Tnodeseq215784;
typedef struct Tidobj190006 Tidobj190006;
typedef struct Ttypeseq215824 Ttypeseq215824;
typedef struct Tscope215816 Tscope215816;
typedef struct TY215925 TY215925;
typedef struct Tstrtable215794 Tstrtable215794;
typedef struct Tsymseq215792 Tsymseq215792;
typedef struct Tloc215804 Tloc215804;
typedef struct Tlib215808 Tlib215808;
typedef struct Basechunk29638 Basechunk29638;
typedef struct Freecell29630 Freecell29630;
typedef struct Tinstantiation215812 Tinstantiation215812;
typedef struct Tlistentry135010 Tlistentry135010;
typedef struct TY215913 TY215913;
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  Tpasscontext262002  {
  TNimObject Sup;
NIM_BOOL fromcache;
};
struct  Tgen515007  {
  Tpasscontext262002 Sup;
Tsym215822* module;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  Cell47504  {
NI refcount;
TNimType* typ;
};
struct  Cellseq47520  {
NI len;
NI cap;
Cell47504** d;
};
struct  Cellset47516  {
NI counter;
NI max;
Pagedesc47512* head;
Pagedesc47512** 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;
Cellseq47520 zct;
Cellseq47520 decstack;
Cellset47516 cycleroots;
Cellseq47520 tempstack;
NI recgclock;
Memregion29688 region;
Gcstat49814 stat;
};
struct  Tlineinfo183337  {
NI16 line;
NI16 col;
NI32 fileindex;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tnode215790  {
Ttype215828* typ;
Tlineinfo183337 info;
NU16 flags;
NU8 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym215822* sym;
} S4;
struct {Tident190012* ident;
} S5;
struct {Tnodeseq215784* sons;
} S6;
} kindU;
NimStringDesc* comment;
};
typedef Ropeobj170006* TY502232[2];
struct  Tidobj190006  {
  TNimObject Sup;
NI id;
};
struct  Tstrtable215794  {
NI counter;
Tsymseq215792* data;
};
struct  Tloc215804  {
NU8 k;
NU8 s;
NU16 flags;
Ttype215828* t;
Ropeobj170006* r;
Ropeobj170006* heaproot;
};
struct  Tsym215822  {
  Tidobj190006 Sup;
NU8 kind;
union{
struct {Ttypeseq215824* typeinstcache;
Tscope215816* typscope;
} S1;
struct {TY215925* procinstcache;
Tsym215822* gcunsafetyreason;
} S2;
struct {TY215925* usedgenerics;
Tstrtable215794 tab;
} S3;
struct {Tsym215822* guard;
NI bitsize;
} S4;
} kindU;
NU8 magic;
Ttype215828* typ;
Tident190012* name;
Tlineinfo183337 info;
Tsym215822* owner;
NU32 flags;
Tnode215790* ast;
NU32 options;
NI position;
NI offset;
Tloc215804 loc;
Tlib215808* annex;
Tnode215790* constraint;
};
struct  Tident190012  {
  Tidobj190006 Sup;
NimStringDesc* s;
Tident190012* next;
NI h;
};
struct  Ropeobj170006  {
  TNimObject Sup;
Ropeobj170006* left;
Ropeobj170006* right;
NI length;
NimStringDesc* data;
};
struct  Gcstack49816  {
Gcstack49816* prev;
Gcstack49816* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY29619[8];
struct  Pagedesc47512  {
Pagedesc47512* 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  Ttype215828  {
  Tidobj190006 Sup;
NU8 kind;
NU8 callconv;
NU32 flags;
Ttypeseq215824* sons;
Tnode215790* n;
Tsym215822* owner;
Tsym215822* sym;
Tsym215822* destructor;
Tsym215822* deepcopy;
Tsym215822* assignment;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc215804 loc;
};
struct  Tscope215816  {
NI depthlevel;
Tstrtable215794 symbols;
Tnodeseq215784* usingsyms;
Tscope215816* parent;
};
struct  Tlistentry135010  {
  TNimObject Sup;
Tlistentry135010* prev;
Tlistentry135010* next;
};
struct  Tlib215808  {
  Tlistentry135010 Sup;
NU8 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj170006* name;
Tnode215790* path;
};
struct  Freecell29630  {
Freecell29630* next;
NI zerofield;
};
struct  Tinstantiation215812  {
Tsym215822* sym;
Ttypeseq215824* concretetypes;
TY215913* usedby;
NI compilesid;
};
struct Tnodeseq215784 {
  TGenericSeq Sup;
  Tnode215790* data[SEQ_DECL_SIZE];
};
struct Ttypeseq215824 {
  TGenericSeq Sup;
  Ttype215828* data[SEQ_DECL_SIZE];
};
struct TY215925 {
  TGenericSeq Sup;
  Tinstantiation215812* data[SEQ_DECL_SIZE];
};
struct Tsymseq215792 {
  TGenericSeq Sup;
  Tsym215822* data[SEQ_DECL_SIZE];
};
struct TY215913 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP5232)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(Cell47504*, usrtocell_51440)(void* usr);
static N_INLINE(void, rtladdzct_53001)(Cell47504* c);
N_NOINLINE(void, addzct_51417)(Cellseq47520* s, Cell47504* c);
N_NIMCALL(NI, sonslen_218351)(Tnode215790* n);
N_NIMCALL(NimStringDesc*, getmodulename_272009)(Tnode215790* n);
N_NIMCALL(void, adddependencyaux_515013)(NimStringDesc* importing, NimStringDesc* imported);
N_NIMCALL(void, addf_171205)(Ropeobj170006** c, NimStringDesc* frmt, Ropeobj170006** args, NI argsLen0);
N_NIMCALL(Ropeobj170006*, rope_170277)(NimStringDesc* s);
N_NIMCALL(Tnode215790*, adddotdependency_515020)(Tpasscontext262002* c, Tnode215790* n);
N_NIMCALL(void, writerope_170836)(Ropeobj170006* head, NimStringDesc* filename, NIM_BOOL usewarning);
N_NIMCALL(Ropeobj170006*, HEX25_170905)(NimStringDesc* frmt, Ropeobj170006** args, NI argsLen0);
N_NIMCALL(NimStringDesc*, noschangeFileExt)(NimStringDesc* filename, NimStringDesc* ext);
N_NIMCALL(NimStringDesc*, nosextractFilename)(NimStringDesc* path);
STRING_LITERAL(TMP5233, "$1 -> $2;$n", 11);
STRING_LITERAL(TMP5234, "digraph $1 {$n$2}$n", 19);
STRING_LITERAL(TMP5235, "", 0);
STRING_LITERAL(TMP5236, "dot", 3);
Ropeobj170006* gdotgraph_515011;
extern TNimType NTI262002; /* TPassContext */
TNimType NTI515007; /* TGen */
extern TNimType NTI215788; /* PSym */
TNimType NTI515009; /* PGen */
extern Gcheap49818 gch_49859;
N_NIMCALL(void, TMP5232)(void* p, NI op) {
	Tgen515007* a;
	a = (Tgen515007*)p;
	nimGCvisit((void*)(*a).module, op);
}

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

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

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		Cell47504* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_51440(src);
		(*c).refcount += ((NI) 8);
	}
	LA3: ;
	{
		Cell47504* 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(Tpasscontext262002*, myopen_515078)(Tsym215822* module) {
	Tpasscontext262002* result;
	Tgen515007* g;
	result = 0;
	g = 0;
	g = (Tgen515007*) newObj((&NTI515009), sizeof(Tgen515007));
	(*g).Sup.Sup.m_type = (&NTI515007);
	asgnRefNoCycle((void**) (&(*g).module), module);
	result = &g->Sup;
	return result;
}

N_NIMCALL(void, adddependencyaux_515013)(NimStringDesc* importing, NimStringDesc* imported) {
	TY502232 LOC1;
	memset((void*)LOC1, 0, sizeof(LOC1));
	LOC1[0] = rope_170277(importing);
	LOC1[1] = rope_170277(imported);
	addf_171205(&gdotgraph_515011, ((NimStringDesc*) &TMP5233), LOC1, 2);
}

N_NIMCALL(Tnode215790*, adddotdependency_515020)(Tpasscontext262002* c, Tnode215790* n) {
	Tnode215790* result;
	Tgen515007* g;
	result = 0;
	result = n;
	g = ((Tgen515007*) (c));
	switch ((*n).kind) {
	case ((NU8) 116):
	{
		{
			NI i_515037;
			NI HEX3Atmp_515058;
			NI LOC3;
			NI res_515061;
			i_515037 = 0;
			HEX3Atmp_515058 = 0;
			LOC3 = 0;
			LOC3 = sonslen_218351(n);
			HEX3Atmp_515058 = (NI)(LOC3 - ((NI) 1));
			res_515061 = ((NI) 0);
			{
				while (1) {
					NimStringDesc* imported;
					if (!(res_515061 <= HEX3Atmp_515058)) goto LA5;
					i_515037 = res_515061;
					imported = getmodulename_272009((*n).kindU.S6.sons->data[i_515037]);
					adddependencyaux_515013((*(*(*g).module).name).s, imported);
					res_515061 += ((NI) 1);
				} LA5: ;
			}
		}
	}
	break;
	case ((NU8) 120):
	case ((NU8) 117):
	{
		NimStringDesc* imported;
		imported = getmodulename_272009((*n).kindU.S6.sons->data[((NI) 0)]);
		adddependencyaux_515013((*(*(*g).module).name).s, imported);
	}
	break;
	case ((NU8) 115):
	case ((NU8) 112):
	case ((NU8) 126):
	case ((NU8) 127):
	{
		{
			NI i_515055;
			NI HEX3Atmp_515066;
			NI LOC9;
			NI res_515069;
			i_515055 = 0;
			HEX3Atmp_515066 = 0;
			LOC9 = 0;
			LOC9 = sonslen_218351(n);
			HEX3Atmp_515066 = (NI)(LOC9 - ((NI) 1));
			res_515069 = ((NI) 0);
			{
				while (1) {
					Tnode215790* LOC12;
					if (!(res_515069 <= HEX3Atmp_515066)) goto LA11;
					i_515055 = res_515069;
					LOC12 = 0;
					LOC12 = adddotdependency_515020(c, (*n).kindU.S6.sons->data[i_515055]);
					res_515069 += ((NI) 1);
				} LA11: ;
			}
		}
	}
	break;
	default:
	{
	}
	break;
	}
	return result;
}

N_NIMCALL(void, generatedot_515003)(NimStringDesc* project) {
	TY502232 LOC1;
	NimStringDesc* LOC2;
	NimStringDesc* LOC3;
	Ropeobj170006* LOC4;
	NimStringDesc* LOC5;
	memset((void*)LOC1, 0, sizeof(LOC1));
	LOC2 = 0;
	LOC2 = nosextractFilename(project);
	LOC3 = 0;
	LOC3 = noschangeFileExt(LOC2, ((NimStringDesc*) &TMP5235));
	LOC1[0] = rope_170277(LOC3);
	LOC1[1] = gdotgraph_515011;
	LOC4 = 0;
	LOC4 = HEX25_170905(((NimStringDesc*) &TMP5234), LOC1, 2);
	LOC5 = 0;
	LOC5 = noschangeFileExt(project, ((NimStringDesc*) &TMP5236));
	writerope_170836(LOC4, LOC5, NIM_FALSE);
}
NIM_EXTERNC N_NOINLINE(void, compiler_dependsInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, compiler_dependsDatInit000)(void) {
static TNimNode TMP1185[1];
NTI515007.size = sizeof(Tgen515007);
NTI515007.kind = 17;
NTI515007.base = (&NTI262002);
TMP1185[0].kind = 1;
TMP1185[0].offset = offsetof(Tgen515007, module);
TMP1185[0].typ = (&NTI215788);
TMP1185[0].name = "module";
NTI515007.node = &TMP1185[0];
NTI515009.size = sizeof(Tgen515007*);
NTI515009.kind = 22;
NTI515009.base = (&NTI515007);
NTI515009.marker = TMP5232;
}

