Nimrod can now compile itself with --lineDir enabled

This commit is contained in:
Zahary Karadjov 2011-09-09 04:37:35 +03:00
commit 0f0dfd6379
7 changed files with 25 additions and 12 deletions

View file

@ -128,7 +128,7 @@ proc genSetNode(p: BProc, n: PNode): PRope =
if id == gid: if id == gid:
# not found in cache: # not found in cache:
inc(gid) inc(gid)
appf(p.module.s[cfsData], "static NIM_CONST $1 $2 = $3;", appf(p.module.s[cfsData], "static NIM_CONST $1 $2 = $3;$n",
[getTypeDesc(p.module, n.typ), result, genRawSetData(cs, size)]) [getTypeDesc(p.module, n.typ), result, genRawSetData(cs, size)])
else: else:
result = genRawSetData(cs, size) result = genRawSetData(cs, size)
@ -371,8 +371,8 @@ proc binaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
else: else:
storage = getTypeDesc(p.module, t) storage = getTypeDesc(p.module, t)
var tmp = getTempName() var tmp = getTempName()
appcg(p, cpsLocals, "$1 $2;", [storage, tmp]) appcg(p, cpsLocals, "$1 $2;$n", [storage, tmp])
appcg(p, cpsStmts, "$1 = #$2($3, $4);", [tmp, toRope(prc[m]), appcg(p, cpsStmts, "$1 = #$2($3, $4);$n", [tmp, toRope(prc[m]),
rdLoc(a), rdLoc(b)]) rdLoc(a), rdLoc(b)])
if size < platform.IntSize or t.kind in {tyRange, tyEnum, tySet}: if size < platform.IntSize or t.kind in {tyRange, tyEnum, tySet}:
appcg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseOverflow();$n", appcg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseOverflow();$n",

View file

@ -19,7 +19,7 @@ proc genLineDir(p: BProc, t: PNode) =
line = 0 # negative numbers are not allowed in #line line = 0 # negative numbers are not allowed in #line
if optLineDir in p.Options and line > 0: if optLineDir in p.Options and line > 0:
appff(p.s[cpsStmts], "#line $2 $1$n", "; line $2 \"$1\"$n", appff(p.s[cpsStmts], "#line $2 $1$n", "; line $2 \"$1\"$n",
[makeCString(toFilename(t.info)), toRope(line)]) [toRope(makeSingleLineCString(toFullPath(t.info))), toRope(line)])
if ({optStackTrace, optEndb} * p.Options == {optStackTrace, optEndb}) and if ({optStackTrace, optEndb} * p.Options == {optStackTrace, optEndb}) and
(p.prc == nil or sfPure notin p.prc.flags): (p.prc == nil or sfPure notin p.prc.flags):
appcg(p, cpsStmts, "#endb($1);$n", [toRope(line)]) appcg(p, cpsStmts, "#endb($1);$n", [toRope(line)])

View file

@ -104,6 +104,12 @@ proc toCChar*(c: Char): string =
of '\'', '\"', '\\': result = '\\' & c of '\'', '\"', '\\': result = '\\' & c
else: result = $(c) else: result = $(c)
proc makeSingleLineCString*(s: string): string =
result = "\""
for c in items(s):
result.add(c.toCChar)
result.add('\"')
proc makeCString*(s: string): PRope = proc makeCString*(s: string): PRope =
# BUGFIX: We have to split long strings into many ropes. Otherwise # BUGFIX: We have to split long strings into many ropes. Otherwise
# this could trigger an InternalError(). See the ropes module for # this could trigger an InternalError(). See the ropes module for
@ -113,10 +119,10 @@ proc makeCString*(s: string): PRope =
var res: string var res: string
result = nil result = nil
res = "\"" res = "\""
for i in countup(0, len(s) + 0 - 1): for i in countup(0, len(s) - 1):
if (i - 0 + 1) mod MaxLineLength == 0: if (i + 1) mod MaxLineLength == 0:
add(res, '\"') add(res, '\"')
add(res, "\n") add(res, tnl)
app(result, toRope(res)) # reset: app(result, toRope(res)) # reset:
setlen(res, 1) setlen(res, 1)
res[0] = '\"' res[0] = '\"'
@ -129,8 +135,8 @@ proc makeLLVMString*(s: string): PRope =
var res: string var res: string
result = nil result = nil
res = "c\"" res = "c\""
for i in countup(0, len(s) + 0 - 1): for i in countup(0, len(s) - 1):
if (i - 0 + 1) mod MaxLineLength == 0: if (i + 1) mod MaxLineLength == 0:
app(result, toRope(res)) app(result, toRope(res))
setlen(res, 0) setlen(res, 0)
case s[i] case s[i]

View file

@ -439,6 +439,11 @@ proc ToFilename*(info: TLineInfo): string =
if info.fileIndex < 0: result = "???" if info.fileIndex < 0: result = "???"
else: result = filenames[info.fileIndex] else: result = filenames[info.fileIndex]
proc toFullPath*(info: TLineInfo): string =
result = info.toFilename
if not isAbsolute(result):
result = JoinPath(options.projectPath, result)
proc ToLinenumber*(info: TLineInfo): int {.inline.} = proc ToLinenumber*(info: TLineInfo): int {.inline.} =
result = info.line result = info.line

View file

@ -66,7 +66,8 @@ proc HandleCmdLine() =
var filename = "" var filename = ""
ProcessCmdLine(passCmd1, command, filename) ProcessCmdLine(passCmd1, command, filename)
if filename != "": if filename != "":
var p = splitFile(filename) var fullPath = expandFilename(filename)
var p = splitFile(fullPath)
options.projectPath = p.dir options.projectPath = p.dir
options.projectName = p.name options.projectName = p.name
nimconf.LoadConfig(filename) # load the right config file nimconf.LoadConfig(filename) # load the right config file

View file

@ -74,7 +74,8 @@ icc.options.linker = "-cxxlib"
@if windows: @if windows:
gcc.path = r"$nimrod\dist\mingw\bin" gcc.path = r"$nimrod\dist\mingw\bin"
@end @end
gcc.options.debug = "-g" gcc.options.debug = "-g3 -O0"
@if macosx: @if macosx:
@if not release: @if not release:
gcc.options.always = "-w -fasm-blocks -O1" gcc.options.always = "-w -fasm-blocks -O1"