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

#include "nimbase.h"
#include <string.h>
typedef struct Ropeobj175009 Ropeobj175009;
typedef struct Tpasscontext276005 Tpasscontext276005;
typedef struct Tsym224841 Tsym224841;
typedef struct Tgen558016 Tgen558016;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Cell48947 Cell48947;
typedef struct Cellseq48963 Cellseq48963;
typedef struct Gcheap51018 Gcheap51018;
typedef struct Gcstack51016 Gcstack51016;
typedef struct Cellset48959 Cellset48959;
typedef struct Pagedesc48955 Pagedesc48955;
typedef struct Memregion30890 Memregion30890;
typedef struct Smallchunk30842 Smallchunk30842;
typedef struct Llchunk30884 Llchunk30884;
typedef struct Bigchunk30844 Bigchunk30844;
typedef struct Intset30817 Intset30817;
typedef struct Trunk30813 Trunk30813;
typedef struct Avlnode30888 Avlnode30888;
typedef struct Gcstat51014 Gcstat51014;
typedef struct Tnode224809 Tnode224809;
typedef struct Ttype224847 Ttype224847;
typedef struct Tlineinfo189352 Tlineinfo189352;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Tident197021 Tident197021;
typedef struct Tnodeseq224803 Tnodeseq224803;
typedef struct Tidobj197015 Tidobj197015;
typedef struct Ttypeseq224843 Ttypeseq224843;
typedef struct Tscope224835 Tscope224835;
typedef struct TY224944 TY224944;
typedef struct Tstrtable224813 Tstrtable224813;
typedef struct Tsymseq224811 Tsymseq224811;
typedef struct Tloc224823 Tloc224823;
typedef struct Tlib224827 Tlib224827;
typedef struct Basechunk30840 Basechunk30840;
typedef struct Freecell30832 Freecell30832;
typedef struct Tinstantiation224831 Tinstantiation224831;
typedef struct Tlistentry140022 Tlistentry140022;
typedef struct TY224932 TY224932;
typedef N_NIMCALL_PTR(void, TY3889) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3894) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3889 marker;
TY3894 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Tpasscontext276005  {
  TNimObject Sup;
NIM_BOOL fromcache;
};
struct  Tgen558016  {
  Tpasscontext276005 Sup;
Tsym224841* module;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  Cell48947  {
NI refcount;
TNimType* typ;
};
struct  Cellseq48963  {
NI len;
NI cap;
Cell48947** d;
};
struct  Cellset48959  {
NI counter;
NI max;
Pagedesc48955* head;
Pagedesc48955** data;
};
typedef Smallchunk30842* TY30905[512];
typedef Trunk30813* Trunkbuckets30815[256];
struct  Intset30817  {
Trunkbuckets30815 data;
};
struct  Memregion30890  {
NI minlargeobj;
NI maxlargeobj;
TY30905 freesmallchunks;
Llchunk30884* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk30844* freechunkslist;
Intset30817 chunkstarts;
Avlnode30888* root;
Avlnode30888* deleted;
Avlnode30888* last;
Avlnode30888* freeavlnodes;
};
struct  Gcstat51014  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap51018  {
Gcstack51016* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq48963 zct;
Cellseq48963 decstack;
Cellset48959 cycleroots;
Cellseq48963 tempstack;
NI recgclock;
Memregion30890 region;
Gcstat51014 stat;
};
struct  Tlineinfo189352  {
NI16 line;
NI16 col;
NI32 fileindex;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tnode224809  {
Ttype224847* typ;
Tlineinfo189352 info;
NU16 flags;
NU8 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym224841* sym;
} S4;
struct {Tident197021* ident;
} S5;
struct {Tnodeseq224803* sons;
} S6;
} kindU;
NimStringDesc* comment;
};
typedef Ropeobj175009* TY542257[2];
struct  Tidobj197015  {
  TNimObject Sup;
NI id;
};
struct  Tstrtable224813  {
NI counter;
Tsymseq224811* data;
};
struct  Tloc224823  {
NU8 k;
NU8 s;
NU16 flags;
Ttype224847* t;
Ropeobj175009* r;
Ropeobj175009* heaproot;
};
struct  Tsym224841  {
  Tidobj197015 Sup;
NU8 kind;
union{
struct {Ttypeseq224843* typeinstcache;
Tscope224835* typscope;
} S1;
struct {TY224944* procinstcache;
Tsym224841* gcunsafetyreason;
} S2;
struct {TY224944* usedgenerics;
Tstrtable224813 tab;
} S3;
struct {Tsym224841* guard;
NI bitsize;
} S4;
} kindU;
NU8 magic;
Ttype224847* typ;
Tident197021* name;
Tlineinfo189352 info;
Tsym224841* owner;
NU32 flags;
Tnode224809* ast;
NU32 options;
NI position;
NI offset;
Tloc224823 loc;
Tlib224827* annex;
Tnode224809* constraint;
};
struct  Tident197021  {
  Tidobj197015 Sup;
NimStringDesc* s;
Tident197021* next;
NI h;
};
struct  Ropeobj175009  {
  TNimObject Sup;
Ropeobj175009* left;
Ropeobj175009* right;
NI length;
NimStringDesc* data;
};
struct  Gcstack51016  {
Gcstack51016* prev;
Gcstack51016* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY30821[16];
struct  Pagedesc48955  {
Pagedesc48955* next;
NI key;
TY30821 bits;
};
struct  Basechunk30840  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk30842  {
  Basechunk30840 Sup;
Smallchunk30842* next;
Smallchunk30842* prev;
Freecell30832* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk30884  {
NI size;
NI acc;
Llchunk30884* next;
};
struct  Bigchunk30844  {
  Basechunk30840 Sup;
Bigchunk30844* next;
Bigchunk30844* prev;
NI align;
NF data;
};
struct  Trunk30813  {
Trunk30813* next;
NI key;
TY30821 bits;
};
typedef Avlnode30888* TY30895[2];
struct  Avlnode30888  {
TY30895 link;
NI key;
NI upperbound;
NI level;
};
struct  Ttype224847  {
  Tidobj197015 Sup;
NU8 kind;
NU8 callconv;
NU32 flags;
Ttypeseq224843* sons;
Tnode224809* n;
Tsym224841* owner;
Tsym224841* sym;
Tsym224841* destructor;
Tsym224841* deepcopy;
Tsym224841* assignment;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc224823 loc;
};
struct  Tscope224835  {
NI depthlevel;
Tstrtable224813 symbols;
Tnodeseq224803* usingsyms;
Tscope224835* parent;
};
struct  Tlistentry140022  {
  TNimObject Sup;
Tlistentry140022* prev;
Tlistentry140022* next;
};
struct  Tlib224827  {
  Tlistentry140022 Sup;
NU8 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj175009* name;
Tnode224809* path;
};
struct  Freecell30832  {
Freecell30832* next;
NI zerofield;
};
struct  Tinstantiation224831  {
Tsym224841* sym;
Ttypeseq224843* concretetypes;
TY224932* usedby;
NI compilesid;
};
struct Tnodeseq224803 {
  TGenericSeq Sup;
  Tnode224809* data[SEQ_DECL_SIZE];
};
struct Ttypeseq224843 {
  TGenericSeq Sup;
  Ttype224847* data[SEQ_DECL_SIZE];
};
struct TY224944 {
  TGenericSeq Sup;
  Tinstantiation224831* data[SEQ_DECL_SIZE];
};
struct Tsymseq224811 {
  TGenericSeq Sup;
  Tsym224841* data[SEQ_DECL_SIZE];
};
struct TY224932 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP5213)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(Cell48947*, usrtocell_52646)(void* usr);
static N_INLINE(void, rtladdzct_54204)(Cell48947* c);
N_NOINLINE(void, addzct_52617)(Cellseq48963* s, Cell48947* c);
N_NIMCALL(NI, sonslen_227387)(Tnode224809* n);
N_NIMCALL(NimStringDesc*, getmodulename_287018)(Tnode224809* n);
N_NIMCALL(void, adddependencyaux_558028)(NimStringDesc* importing, NimStringDesc* imported);
N_NIMCALL(void, addf_176635)(Ropeobj175009** c, NimStringDesc* frmt, Ropeobj175009** args, NI argsLen0);
N_NIMCALL(Ropeobj175009*, rope_175322)(NimStringDesc* s);
N_NIMCALL(Tnode224809*, adddotdependency_558041)(Tpasscontext276005* c, Tnode224809* n);
N_NIMCALL(void, writerope_176106)(Ropeobj175009* head, NimStringDesc* filename, NIM_BOOL usewarning);
N_NIMCALL(Ropeobj175009*, HEX25_176236)(NimStringDesc* frmt, Ropeobj175009** args, NI argsLen0);
N_NIMCALL(NimStringDesc*, noschangeFileExt)(NimStringDesc* filename, NimStringDesc* ext);
N_NIMCALL(NimStringDesc*, nosextractFilename)(NimStringDesc* path);
STRING_LITERAL(TMP5214, "$1 -> $2;$n", 11);
STRING_LITERAL(TMP5215, "digraph $1 {$n$2}$n", 19);
STRING_LITERAL(TMP5216, "", 0);
STRING_LITERAL(TMP5217, "dot", 3);
Ropeobj175009* gdotgraph_558023;
extern TNimType NTI276005; /* TPassContext */
TNimType NTI558016; /* TGen */
extern TNimType NTI224807; /* PSym */
TNimType NTI558018; /* PGen */
extern Gcheap51018 gch_51059;
N_NIMCALL(void, TMP5213)(void* p, NI op) {
	Tgen558016* a;
	a = (Tgen558016*)p;
	nimGCvisit((void*)(*a).module, op);
}

static N_INLINE(Cell48947*, usrtocell_52646)(void* usr) {
	Cell48947* result;
	result = 0;
	result = ((Cell48947*) ((NI)((NU32)(((NI) (usr))) - (NU32)(((NI)sizeof(Cell48947))))));
	return result;
}

static N_INLINE(void, rtladdzct_54204)(Cell48947* c) {
	addzct_52617((&gch_51059.zct), c);
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		Cell48947* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_52646(src);
		(*c).refcount += ((NI) 8);
	}
	LA3: ;
	{
		Cell48947* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_52646((*dest));
		{
			(*c).refcount -= ((NI) 8);
			if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA11;
			rtladdzct_54204(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

N_NIMCALL(Tpasscontext276005*, myopen_558131)(Tsym224841* module) {
	Tpasscontext276005* result;
	Tgen558016* g;
	result = 0;
	g = 0;
	g = (Tgen558016*) newObj((&NTI558018), sizeof(Tgen558016));
	(*g).Sup.Sup.m_type = (&NTI558016);
	asgnRefNoCycle((void**) (&(*g).module), module);
	result = &g->Sup;
	return result;
}

N_NIMCALL(void, adddependencyaux_558028)(NimStringDesc* importing, NimStringDesc* imported) {
	TY542257 LOC1;
	memset((void*)LOC1, 0, sizeof(LOC1));
	LOC1[0] = rope_175322(importing);
	LOC1[1] = rope_175322(imported);
	addf_176635(&gdotgraph_558023, ((NimStringDesc*) &TMP5214), LOC1, 2);
}

N_NIMCALL(Tnode224809*, adddotdependency_558041)(Tpasscontext276005* c, Tnode224809* n) {
	Tnode224809* result;
	Tgen558016* g;
	result = 0;
	result = n;
	g = ((Tgen558016*) (c));
	switch ((*n).kind) {
	case ((NU8) 116):
	{
		{
			NI i_558059;
			NI HEX3Atmp_558081;
			NI LOC3;
			NI res_558084;
			i_558059 = 0;
			HEX3Atmp_558081 = 0;
			LOC3 = 0;
			LOC3 = sonslen_227387(n);
			HEX3Atmp_558081 = (NI)(LOC3 - ((NI) 1));
			res_558084 = ((NI) 0);
			{
				while (1) {
					NimStringDesc* imported;
					if (!(res_558084 <= HEX3Atmp_558081)) goto LA5;
					i_558059 = res_558084;
					imported = getmodulename_287018((*n).kindU.S6.sons->data[i_558059]);
					adddependencyaux_558028((*(*(*g).module).name).s, imported);
					res_558084 += ((NI) 1);
				} LA5: ;
			}
		}
	}
	break;
	case ((NU8) 120):
	case ((NU8) 117):
	{
		NimStringDesc* imported;
		imported = getmodulename_287018((*n).kindU.S6.sons->data[((NI) 0)]);
		adddependencyaux_558028((*(*(*g).module).name).s, imported);
	}
	break;
	case ((NU8) 115):
	case ((NU8) 112):
	case ((NU8) 126):
	case ((NU8) 127):
	{
		{
			NI i_558078;
			NI HEX3Atmp_558089;
			NI LOC9;
			NI res_558092;
			i_558078 = 0;
			HEX3Atmp_558089 = 0;
			LOC9 = 0;
			LOC9 = sonslen_227387(n);
			HEX3Atmp_558089 = (NI)(LOC9 - ((NI) 1));
			res_558092 = ((NI) 0);
			{
				while (1) {
					Tnode224809* LOC12;
					if (!(res_558092 <= HEX3Atmp_558089)) goto LA11;
					i_558078 = res_558092;
					LOC12 = 0;
					LOC12 = adddotdependency_558041(c, (*n).kindU.S6.sons->data[i_558078]);
					res_558092 += ((NI) 1);
				} LA11: ;
			}
		}
	}
	break;
	default:
	{
	}
	break;
	}
	return result;
}

N_NIMCALL(void, generatedot_558009)(NimStringDesc* project) {
	TY542257 LOC1;
	NimStringDesc* LOC2;
	NimStringDesc* LOC3;
	Ropeobj175009* LOC4;
	NimStringDesc* LOC5;
	memset((void*)LOC1, 0, sizeof(LOC1));
	LOC2 = 0;
	LOC2 = nosextractFilename(project);
	LOC3 = 0;
	LOC3 = noschangeFileExt(LOC2, ((NimStringDesc*) &TMP5216));
	LOC1[0] = rope_175322(LOC3);
	LOC1[1] = gdotgraph_558023;
	LOC4 = 0;
	LOC4 = HEX25_176236(((NimStringDesc*) &TMP5215), LOC1, 2);
	LOC5 = 0;
	LOC5 = noschangeFileExt(project, ((NimStringDesc*) &TMP5217));
	writerope_176106(LOC4, LOC5, NIM_FALSE);
}
NIM_EXTERNC N_NOINLINE(void, compiler_dependsInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, compiler_dependsDatInit000)(void) {
static TNimNode TMP1146[1];
NTI558016.size = sizeof(Tgen558016);
NTI558016.kind = 17;
NTI558016.base = (&NTI276005);
TMP1146[0].kind = 1;
TMP1146[0].offset = offsetof(Tgen558016, module);
TMP1146[0].typ = (&NTI224807);
TMP1146[0].name = "module";
NTI558016.node = &TMP1146[0];
NTI558018.size = sizeof(Tgen558016*);
NTI558018.kind = 22;
NTI558018.base = (&NTI558016);
NTI558018.marker = TMP5213;
}

