diff options
author | Miguel <leu-gim@moy-server.ru> | 2014-01-26 05:37:18 +0400 |
---|---|---|
committer | Miguel <leu-gim@moy-server.ru> | 2014-01-26 05:37:18 +0400 |
commit | a8b4e3c764dd967e1ac90305a574c4cd5e0d019b (patch) | |
tree | 9165419d8557b493bf65a3de04f248ae6f2288b9 /compiler/c2nim/c2nim.nim | |
parent | 4396270fc7c447fa7ce9478a6bf9682ba7c496a7 (diff) | |
parent | 5d712e0d3f9f5b8e486720c8bedd749656b527d8 (diff) | |
download | Nim-a8b4e3c764dd967e1ac90305a574c4cd5e0d019b.tar.gz |
Merge branch 'devel' of git://github.com/Araq/Nimrod
Diffstat (limited to 'compiler/c2nim/c2nim.nim')
-rw-r--r-- | compiler/c2nim/c2nim.nim | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/compiler/c2nim/c2nim.nim b/compiler/c2nim/c2nim.nim index df1e42f23..9b12b9e47 100644 --- a/compiler/c2nim/c2nim.nim +++ b/compiler/c2nim/c2nim.nim @@ -34,25 +34,36 @@ Options: --skipcomments do not copy comments --ignoreRValueRefs translate C++'s ``T&&`` to ``T`` instead ``of var T`` --keepBodies keep C++'s method bodies + --spliceHeader parse and emit header before source file -v, --version write c2nim's version -h, --help show this help """ -proc main(infile, outfile: string, options: PParserOptions) = - var start = getTime() - var stream = LLStreamOpen(infile, fmRead) +proc parse(infile: string, options: PParserOptions): PNode = + var stream = llStreamOpen(infile, fmRead) if stream == nil: rawMessage(errCannotOpenFile, infile) var p: TParser openParser(p, infile, stream, options) - var module = parseUnit(p) + result = parseUnit(p) closeParser(p) - renderModule(module, outfile) + +proc main(infile, outfile: string, options: PParserOptions, spliceHeader: bool) = + var start = getTime() + if spliceHeader and infile.splitFile.ext == ".c" and existsFile(infile.changeFileExt(".h")): + var header_module = parse(infile.changeFileExt(".h"), options) + var source_module = parse(infile, options) + for n in source_module: + addson(header_module, n) + renderModule(header_module, outfile) + else: + renderModule(parse(infile, options), outfile) rawMessage(hintSuccessX, [$gLinesCompiled, $(getTime() - start), formatSize(getTotalMem())]) var infile = "" outfile = "" + spliceHeader = false parserOptions = newParserOptions() for kind, key, val in getopt(): case kind @@ -66,6 +77,7 @@ for kind, key, val in getopt(): stdout.write(Version & "\n") quit(0) of "o", "out": outfile = val + of "spliceheader": spliceHeader = true else: if not parserOptions.setOption(key, val): stdout.writeln("[Error] unknown option: " & key) @@ -77,4 +89,4 @@ else: if outfile.len == 0: outfile = changeFileExt(infile, "nim") infile = addFileExt(infile, "h") - main(infile, outfile, parserOptions) + main(infile, outfile, parserOptions, spliceHeader) |