summary refs log tree commit diff stats
path: root/compiler/platform.nim
Commit message (Expand)AuthorAgeFilesLines
* first steps to thread local heapsAraq2011-06-021-2/+3
* big repo cleanupAraq2011-04-121-0/+213
href='#n33'>33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#
#
#           The Nimrod Compiler
#        (c) Copyright 2010 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

# This module implements a dependency file generator.

import 
  os, options, ast, astalgo, msgs, ropes, idents, passes, importer

proc genDependPass*(): TPass
proc generateDot*(project: string)

type 
  TGen = object of TPassContext
    module*: PSym
    filename*: string
  PGen = ref TGen

var gDotGraph: PRope # the generated DOT file; we need a global variable

proc addDependencyAux(importing, imported: string) = 
  appf(gDotGraph, "$1 -> $2;$n", [toRope(importing), toRope(imported)]) 
  # s1 -> s2_4[label="[0-9]"];
  
proc addDotDependency(c: PPassContext, n: PNode): PNode = 
  result = n
  var g = PGen(c)
  case n.kind
  of nkImportStmt: 
    for i in countup(0, sonsLen(n) - 1): 
      var imported = splitFile(getModuleFile(n.sons[i])).name
      addDependencyAux(g.module.name.s, imported)
  of nkFromStmt: 
    var imported = splitFile(getModuleFile(n.sons[0])).name
    addDependencyAux(g.module.name.s, imported)
  of nkStmtList, nkBlockStmt, nkStmtListExpr, nkBlockExpr: 
    for i in countup(0, sonsLen(n) - 1): discard addDotDependency(c, n.sons[i])
  else: 
    nil

proc generateDot(project: string) = 
  writeRope(ropef("digraph $1 {$n$2}$n", [
      toRope(changeFileExt(extractFileName(project), "")), gDotGraph]), 
            changeFileExt(project, "dot"))

proc myOpen(module: PSym, filename: string): PPassContext = 
  var g: PGen
  new(g)
  g.module = module
  g.filename = filename
  result = g

proc gendependPass(): TPass = 
  initPass(result)
  result.open = myOpen
  result.process = addDotDependency