summary refs log tree commit diff stats
path: root/compiler/main.nim
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2013-05-01 20:20:48 +0300
committerZahary Karadjov <zahary@gmail.com>2013-05-01 20:46:05 +0300
commit89f9772f15f93fd27531d341ed762d5236c67be0 (patch)
treed0af58319b7685e23d019a90f06b059310008f9c /compiler/main.nim
parente0f706804f115d7a2b88abe18616dd00a3bc3034 (diff)
downloadNim-89f9772f15f93fd27531d341ed762d5236c67be0.tar.gz
nimrod dump can now produce a machine readable json report
The data in the report includes necessary information for starting
the compiler service and setting up the project paths in the IDE.

the default verbosity of 1 is now set in the compiler code to fix an
issue with verbosity being temporary set to 1 during config parsing
even when it's explicitly overridden on the command-line.

compiler/lexbase was temporary renamed to nimlexbase as a
work-around for a codegen naming conflict with lib/pure/lexbase
resulting in linking errors (further investigation needed).
Diffstat (limited to 'compiler/main.nim')
-rw-r--r--compiler/main.nim40
1 files changed, 35 insertions, 5 deletions
diff --git a/compiler/main.nim b/compiler/main.nim
index b5186ba6c..46ef65e81 100644
--- a/compiler/main.nim
+++ b/compiler/main.nim
@@ -14,7 +14,7 @@ import
   llstream, strutils, ast, astalgo, lexer, syntaxes, renderer, options, msgs, 
   os, lists, condsyms, rodread, rodwrite, ropes, trees, times,
   wordrecg, sem, semdata, idents, passes, docgen, extccomp,
-  cgen, jsgen, cgendata,
+  cgen, jsgen, cgendata, json, nversion,
   platform, nimconf, importer, passaux, depends, evals, types, idgen,
   tables, docgen2, service, magicsys, parser, crc, ccgutils
 
@@ -392,6 +392,15 @@ proc wantMainModule =
 
   gProjectMainIdx = addFileExt(gProjectFull, nimExt).fileInfoIdx
 
+proc requireMainModuleOption =
+  if optMainModule.len == 0:
+    Fatal(gCmdLineInfo, errMainModuleMustBeSpecified)
+  else:
+    gProjectName = optMainModule
+    gProjectFull = gProjectPath / gProjectName
+
+  gProjectMainIdx = addFileExt(gProjectFull, nimExt).fileInfoIdx
+
 proc resetMemory =
   resetCompilationLists()
   ccgutils.resetCaches()
@@ -529,9 +538,30 @@ proc MainCommand =
     wantMainModule()
     CommandGenDepend()
   of "dump":
-    gCmd = cmdDump
-    condsyms.ListSymbols()
-    for it in iterSearchPath(searchPaths): MsgWriteln(it)
+    gcmd = cmdDump
+    if getconfigvar("dump.format") == "json":
+      requireMainModuleOption()
+
+      var definedSymbols = newJArray()
+      for s in definedSymbolNames(): definedSymbols.elems.add(%s)
+
+      var libpaths = newJArray()
+      for dir in itersearchpath(searchpaths): libpaths.elems.add(%dir)
+
+      var dumpdata = % [
+        (key: "version", val: %VersionAsString),
+        (key: "project_path", val: %gProjectFull),
+        (key: "defined_symbols", val: definedSymbols),
+        (key: "lib_paths", val: libpaths)
+      ]
+
+      outWriteLn($dumpdata)
+    else:
+      outWriteLn("-- list of currently defined symbols --")
+      for s in definedSymbolNames(): outWriteLn(s)
+      outWriteLn("-- end of list --")
+
+      for it in iterSearchPath(searchpaths): msgWriteLn(it)
   of "check":
     gCmd = cmdCheck
     wantMainModule()
@@ -568,7 +598,7 @@ proc MainCommand =
   else:
     rawMessage(errInvalidCommandX, command)
   
-  if msgs.gErrorCounter == 0 and gCmd notin {cmdInterpret, cmdRun}:
+  if msgs.gErrorCounter == 0 and gCmd notin {cmdInterpret, cmdRun, cmdDump}:
     rawMessage(hintSuccessX, [$gLinesCompiled,
                formatFloat(epochTime() - gLastCmdTime, ffDecimal, 3),
                formatSize(getTotalMem())])