/* Generated by Nimrod Compiler v0.9.5 */
/*   (c) 2014 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: Linux, i386, gcc */
/* Command for C compiler:
   gcc -c  -w -O3 -fno-strict-aliasing  -I/build/nimrod/src/nimrod/lib -o compiler/nimcache/depends.o compiler/nimcache/depends.c */
#define NIM_INTBITS 32
#include "nimbase.h"

#include <string.h>
typedef struct trope145007 trope145007;
typedef struct tpasscontext246003 tpasscontext246003;
typedef struct tsym188833 tsym188833;
typedef struct tgen519012 tgen519012;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct tcell41090 tcell41090;
typedef struct tcellseq41106 tcellseq41106;
typedef struct tgcheap43016 tgcheap43016;
typedef struct tcellset41102 tcellset41102;
typedef struct tpagedesc41098 tpagedesc41098;
typedef struct tmemregion23410 tmemregion23410;
typedef struct tsmallchunk22638 tsmallchunk22638;
typedef struct tllchunk23404 tllchunk23404;
typedef struct tbigchunk22640 tbigchunk22640;
typedef struct tintset22615 tintset22615;
typedef struct ttrunk22611 ttrunk22611;
typedef struct tavlnode23408 tavlnode23408;
typedef struct tgcstat43014 tgcstat43014;
typedef struct tnode188803 tnode188803;
typedef struct ttype188837 ttype188837;
typedef struct tlineinfo163527 tlineinfo163527;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct tident167019 tident167019;
typedef struct tnodeseq188797 tnodeseq188797;
typedef struct tidobj167013 tidobj167013;
typedef struct ttypeseq188835 ttypeseq188835;
typedef struct tscope188827 tscope188827;
typedef struct TY188933 TY188933;
typedef struct tinstantiation188823 tinstantiation188823;
typedef struct tstrtable188807 tstrtable188807;
typedef struct tsymseq188805 tsymseq188805;
typedef struct tloc188817 tloc188817;
typedef struct tlib188821 tlib188821;
typedef struct tbasechunk22636 tbasechunk22636;
typedef struct tfreecell22628 tfreecell22628;
typedef struct TY188922 TY188922;
typedef struct tlistentry118017 tlistentry118017;
typedef N_NIMCALL_PTR(void, TY2289) (void* p, NI op);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY2289 marker;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  tpasscontext246003  {
  TNimObject Sup;
NIM_BOOL Fromcache;
};
struct  tgen519012  {
  tpasscontext246003 Sup;
tsym188833* Module;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  tcell41090  {
NI Refcount;
TNimType* Typ;
};
struct  tcellseq41106  {
NI Len;
NI Cap;
tcell41090** D;
};
struct  tcellset41102  {
NI Counter;
NI Max;
tpagedesc41098* Head;
tpagedesc41098** Data;
};
typedef tsmallchunk22638* TY23422[512];
typedef ttrunk22611* ttrunkbuckets22613[256];
struct  tintset22615  {
ttrunkbuckets22613 Data;
};
struct  tmemregion23410  {
NI Minlargeobj;
NI Maxlargeobj;
TY23422 Freesmallchunks;
tllchunk23404* Llmem;
NI Currmem;
NI Maxmem;
NI Freemem;
NI Lastsize;
tbigchunk22640* Freechunkslist;
tintset22615 Chunkstarts;
tavlnode23408* Root;
tavlnode23408* Deleted;
tavlnode23408* Last;
tavlnode23408* Freeavlnodes;
};
struct  tgcstat43014  {
NI Stackscans;
NI Cyclecollections;
NI Maxthreshold;
NI Maxstacksize;
NI Maxstackcells;
NI Cycletablesize;
NI64 Maxpause;
};
struct  tgcheap43016  {
void* Stackbottom;
NI Cyclethreshold;
tcellseq41106 Zct;
tcellseq41106 Decstack;
tcellset41102 Cycleroots;
tcellseq41106 Tempstack;
NI Recgclock;
tmemregion23410 Region;
tgcstat43014 Stat;
};
struct  tlineinfo163527  {
NI16 Line;
NI16 Col;
NI32 Fileindex;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  tnode188803  {
ttype188837* Typ;
tlineinfo163527 Info;
NU16 Flags;
NU8 Kind;
union {
struct {NI64 Intval;
} S1;
struct {NF Floatval;
} S2;
struct {NimStringDesc* Strval;
} S3;
struct {tsym188833* Sym;
} S4;
struct {tident167019* Ident;
} S5;
struct {tnodeseq188797* Sons;
} S6;
} kindU;
NimStringDesc* Comment;
};
typedef trope145007* TY503234[2];
struct  tidobj167013  {
  TNimObject Sup;
NI Id;
};
struct  tstrtable188807  {
NI Counter;
tsymseq188805* Data;
};
struct  tloc188817  {
NU8 K;
NU8 S;
NU8 Flags;
ttype188837* T;
trope145007* R;
trope145007* Heaproot;
NI A;
};
struct  tsym188833  {
  tidobj167013 Sup;
NU8 Kind;
union {
struct {ttypeseq188835* Typeinstcache;
tscope188827* Typscope;
} S1;
struct {TY188933* Procinstcache;
tscope188827* Scope;
} S2;
struct {TY188933* Usedgenerics;
tstrtable188807 Tab;
} S3;
} kindU;
NU16 Magic;
ttype188837* Typ;
tident167019* Name;
tlineinfo163527 Info;
tsym188833* Owner;
NU32 Flags;
tnode188803* Ast;
NU32 Options;
NI Position;
NI Offset;
tloc188817 Loc;
tlib188821* Annex;
tnode188803* Constraint;
};
struct  tident167019  {
  tidobj167013 Sup;
NimStringDesc* S;
tident167019* Next;
NI H;
};
struct  trope145007  {
  TNimObject Sup;
trope145007* Left;
trope145007* Right;
NI Length;
NimStringDesc* Data;
};
typedef NI TY22618[16];
struct  tpagedesc41098  {
tpagedesc41098* Next;
NI Key;
TY22618 Bits;
};
struct  tbasechunk22636  {
NI Prevsize;
NI Size;
NIM_BOOL Used;
};
struct  tsmallchunk22638  {
  tbasechunk22636 Sup;
tsmallchunk22638* Next;
tsmallchunk22638* Prev;
tfreecell22628* Freelist;
NI Free;
NI Acc;
NF Data;
};
struct  tllchunk23404  {
NI Size;
NI Acc;
tllchunk23404* Next;
};
struct  tbigchunk22640  {
  tbasechunk22636 Sup;
tbigchunk22640* Next;
tbigchunk22640* Prev;
NI Align;
NF Data;
};
struct  ttrunk22611  {
ttrunk22611* Next;
NI Key;
TY22618 Bits;
};
typedef tavlnode23408* TY23414[2];
struct  tavlnode23408  {
TY23414 Link;
NI Key;
NI Upperbound;
NI Level;
};
struct  ttype188837  {
  tidobj167013 Sup;
NU8 Kind;
NU8 Callconv;
NU32 Flags;
ttypeseq188835* Sons;
tnode188803* N;
tsym188833* Destructor;
tsym188833* Owner;
tsym188833* Sym;
NI64 Size;
NI Align;
tloc188817 Loc;
};
struct  tscope188827  {
NI Depthlevel;
tstrtable188807 Symbols;
tnodeseq188797* Usingsyms;
tscope188827* Parent;
};
struct  tinstantiation188823  {
tsym188833* Sym;
ttypeseq188835* Concretetypes;
TY188922* Usedby;
};
struct  tlistentry118017  {
  TNimObject Sup;
tlistentry118017* Prev;
tlistentry118017* Next;
};
struct  tlib188821  {
  tlistentry118017 Sup;
NU8 Kind;
NIM_BOOL Generated;
NIM_BOOL Isoverriden;
trope145007* Name;
tnode188803* Path;
};
struct  tfreecell22628  {
tfreecell22628* Next;
NI Zerofield;
};
struct tnodeseq188797 {
  TGenericSeq Sup;
  tnode188803* data[SEQ_DECL_SIZE];
};
struct ttypeseq188835 {
  TGenericSeq Sup;
  ttype188837* data[SEQ_DECL_SIZE];
};
struct TY188933 {
  TGenericSeq Sup;
  tinstantiation188823* data[SEQ_DECL_SIZE];
};
struct tsymseq188805 {
  TGenericSeq Sup;
  tsym188833* data[SEQ_DECL_SIZE];
};
struct TY188922 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP4497)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(tcell41090*, usrtocell_44443)(void* usr);
static N_INLINE(void, rtladdzct_46002)(tcell41090* c);
N_NOINLINE(void, addzct_44418)(tcellseq41106* s, tcell41090* c);
static N_INLINE(NI, sonslen_189181)(tnode188803* n);
N_NIMCALL(NimStringDesc*, getmodulename_255012)(tnode188803* n);
N_NIMCALL(void, adddependencyaux_519020)(NimStringDesc* importing, NimStringDesc* imported);
N_NIMCALL(void, appf_145085)(trope145007** c, NimStringDesc* frmt, trope145007** args, NI argsLen0);
N_NIMCALL(trope145007*, torope_145058)(NimStringDesc* s);
N_NIMCALL(tnode188803*, adddotdependency_519031)(tpasscontext246003* c, tnode188803* n);
N_NIMCALL(void, writerope_146407)(trope145007* head, NimStringDesc* filename, NIM_BOOL usewarning);
N_NIMCALL(trope145007*, ropef_145079)(NimStringDesc* frmt, trope145007** args, NI argsLen0);
N_NIMCALL(NimStringDesc*, noschangeFileExt)(NimStringDesc* filename, NimStringDesc* ext);
N_NIMCALL(NimStringDesc*, nosextractFilename)(NimStringDesc* path);
STRING_LITERAL(TMP4498, "$1 -> $2;$n", 11);
STRING_LITERAL(TMP4500, "digraph $1 {$n$2}$n", 19);
STRING_LITERAL(TMP4501, "", 0);
STRING_LITERAL(TMP4502, "dot", 3);
trope145007* gdotgraph_519017;
extern TNimType NTI246003; /* TPassContext */
TNimType NTI519012; /* TGen */
extern TNimType NTI188801; /* PSym */
TNimType NTI519014; /* PGen */
extern tgcheap43016 gch_43044;
N_NIMCALL(void, TMP4497)(void* p, NI op) {
	tgen519012* a;
	a = (tgen519012*)p;
	nimGCvisit((void*)(*a).Module, op);
}

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

static N_INLINE(void, rtladdzct_46002)(tcell41090* c) {
	addzct_44418(&gch_43044.Zct, c);
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		tcell41090* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_44443(src);
		(*c).Refcount += 8;
	}
	LA3: ;
	{
		tcell41090* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_44443((*dest));
		{
			(*c).Refcount -= 8;
			if (!((NU32)((*c).Refcount) < (NU32)(8))) goto LA11;
			rtladdzct_46002(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

N_NIMCALL(tpasscontext246003*, myopen_519128)(tsym188833* module) {
	tpasscontext246003* result;
	tgen519012* g;
	result = 0;
	g = 0;
	g = (tgen519012*) newObj((&NTI519014), sizeof(tgen519012));
	(*g).Sup.Sup.m_type = (&NTI519012);
	asgnRefNoCycle((void**) &(*g).Module, module);
	result = &g->Sup;
	return result;
}

static N_INLINE(NI, sonslen_189181)(tnode188803* n) {
	NI result;
	result = 0;
	{
		if (!(*n).kindU.S6.Sons == 0) goto LA3;
		result = 0;
	}
	goto LA1;
	LA3: ;
	{
		result = (*n).kindU.S6.Sons->Sup.len;
	}
	LA1: ;
	return result;
}

N_NIMCALL(void, adddependencyaux_519020)(NimStringDesc* importing, NimStringDesc* imported) {
	TY503234 LOC1;
	memset((void*)LOC1, 0, sizeof(LOC1));
	LOC1[0] = torope_145058(importing);
	LOC1[1] = torope_145058(imported);
	appf_145085(&gdotgraph_519017, ((NimStringDesc*) &TMP4498), LOC1, 2);
}

N_NIMCALL(tnode188803*, adddotdependency_519031)(tpasscontext246003* c, tnode188803* n) {
	tnode188803* result;
	tgen519012* g;
	result = 0;
	result = n;
	g = ((tgen519012*) (c));
	switch ((*n).Kind) {
	case ((NU8) 115):
	{
		NI i_519049;
		NI HEX3Atmp_519107;
		NI LOC2;
		NI res_519109;
		i_519049 = 0;
		HEX3Atmp_519107 = 0;
		LOC2 = 0;
		LOC2 = sonslen_189181(n);
		HEX3Atmp_519107 = (NI32)(LOC2 - 1);
		res_519109 = 0;
		while (1) {
			NimStringDesc* imported;
			if (!(res_519109 <= HEX3Atmp_519107)) goto LA3;
			i_519049 = res_519109;
			imported = getmodulename_255012((*n).kindU.S6.Sons->data[i_519049]);
			adddependencyaux_519020((*(*(*g).Module).Name).S, imported);
			res_519109 += 1;
		} LA3: ;
	}
	break;
	case ((NU8) 119):
	case ((NU8) 116):
	{
		NimStringDesc* imported;
		imported = getmodulename_255012((*n).kindU.S6.Sons->data[0]);
		adddependencyaux_519020((*(*(*g).Module).Name).S, imported);
	}
	break;
	case ((NU8) 114):
	case ((NU8) 111):
	case ((NU8) 125):
	case ((NU8) 126):
	{
		NI i_519092;
		NI HEX3Atmp_519111;
		NI LOC6;
		NI res_519113;
		i_519092 = 0;
		HEX3Atmp_519111 = 0;
		LOC6 = 0;
		LOC6 = sonslen_189181(n);
		HEX3Atmp_519111 = (NI32)(LOC6 - 1);
		res_519113 = 0;
		while (1) {
			tnode188803* LOC8;
			if (!(res_519113 <= HEX3Atmp_519111)) goto LA7;
			i_519092 = res_519113;
			LOC8 = 0;
			LOC8 = adddotdependency_519031(c, (*n).kindU.S6.Sons->data[i_519092]);
			res_519113 += 1;
		} LA7: ;
	}
	break;
	default:
	{
	}
	break;
	}
	return result;
}

N_NIMCALL(void, generatedot_519007)(NimStringDesc* project) {
	TY503234 LOC1;
	NimStringDesc* LOC2;
	NimStringDesc* LOC3;
	trope145007* LOC4;
	NimStringDesc* LOC5;
	memset((void*)LOC1, 0, sizeof(LOC1));
	LOC2 = 0;
	LOC2 = nosextractFilename(project);
	LOC3 = 0;
	LOC3 = noschangeFileExt(LOC2, ((NimStringDesc*) &TMP4501));
	LOC1[0] = torope_145058(LOC3);
	LOC1[1] = gdotgraph_519017;
	LOC4 = 0;
	LOC4 = ropef_145079(((NimStringDesc*) &TMP4500), LOC1, 2);
	LOC5 = 0;
	LOC5 = noschangeFileExt(project, ((NimStringDesc*) &TMP4502));
	writerope_146407(LOC4, LOC5, NIM_FALSE);
}
N_NOINLINE(void, dependsInit)(void) {
}

N_NOINLINE(void, dependsDatInit)(void) {
static TNimNode TMP966[1];
NTI519012.size = sizeof(tgen519012);
NTI519012.kind = 17;
NTI519012.base = (&NTI246003);
TMP966[0].kind = 1;
TMP966[0].offset = offsetof(tgen519012, Module);
TMP966[0].typ = (&NTI188801);
TMP966[0].name = "module";
NTI519012.node = &TMP966[0];
NTI519014.size = sizeof(tgen519012*);
NTI519014.kind = 22;
NTI519014.base = (&NTI519012);
NTI519014.marker = TMP4497;
}

