mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-31 02:12:11 +00:00
Nimrod can now compile itself with --lineDir enabled
This commit is contained in:
@@ -128,7 +128,7 @@ proc genSetNode(p: BProc, n: PNode): PRope =
|
||||
if id == gid:
|
||||
# not found in cache:
|
||||
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)])
|
||||
else:
|
||||
result = genRawSetData(cs, size)
|
||||
@@ -371,8 +371,8 @@ proc binaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
|
||||
else:
|
||||
storage = getTypeDesc(p.module, t)
|
||||
var tmp = getTempName()
|
||||
appcg(p, cpsLocals, "$1 $2;", [storage, tmp])
|
||||
appcg(p, cpsStmts, "$1 = #$2($3, $4);", [tmp, toRope(prc[m]),
|
||||
appcg(p, cpsLocals, "$1 $2;$n", [storage, tmp])
|
||||
appcg(p, cpsStmts, "$1 = #$2($3, $4);$n", [tmp, toRope(prc[m]),
|
||||
rdLoc(a), rdLoc(b)])
|
||||
if size < platform.IntSize or t.kind in {tyRange, tyEnum, tySet}:
|
||||
appcg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseOverflow();$n",
|
||||
|
||||
@@ -19,7 +19,7 @@ proc genLineDir(p: BProc, t: PNode) =
|
||||
line = 0 # negative numbers are not allowed in #line
|
||||
if optLineDir in p.Options and line > 0:
|
||||
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
|
||||
(p.prc == nil or sfPure notin p.prc.flags):
|
||||
appcg(p, cpsStmts, "#endb($1);$n", [toRope(line)])
|
||||
|
||||
@@ -103,6 +103,12 @@ proc toCChar*(c: Char): string =
|
||||
of '\0'..'\x1F', '\x80'..'\xFF': result = '\\' & toOctal(c)
|
||||
of '\'', '\"', '\\': 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 =
|
||||
# BUGFIX: We have to split long strings into many ropes. Otherwise
|
||||
@@ -113,10 +119,10 @@ proc makeCString*(s: string): PRope =
|
||||
var res: string
|
||||
result = nil
|
||||
res = "\""
|
||||
for i in countup(0, len(s) + 0 - 1):
|
||||
if (i - 0 + 1) mod MaxLineLength == 0:
|
||||
for i in countup(0, len(s) - 1):
|
||||
if (i + 1) mod MaxLineLength == 0:
|
||||
add(res, '\"')
|
||||
add(res, "\n")
|
||||
add(res, tnl)
|
||||
app(result, toRope(res)) # reset:
|
||||
setlen(res, 1)
|
||||
res[0] = '\"'
|
||||
@@ -129,8 +135,8 @@ proc makeLLVMString*(s: string): PRope =
|
||||
var res: string
|
||||
result = nil
|
||||
res = "c\""
|
||||
for i in countup(0, len(s) + 0 - 1):
|
||||
if (i - 0 + 1) mod MaxLineLength == 0:
|
||||
for i in countup(0, len(s) - 1):
|
||||
if (i + 1) mod MaxLineLength == 0:
|
||||
app(result, toRope(res))
|
||||
setlen(res, 0)
|
||||
case s[i]
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
import
|
||||
ast, astalgo, strutils, hashes, trees, platform, magicsys, extccomp,
|
||||
options, intsets,
|
||||
nversion, nimsets, msgs, crc, bitsets, idents, lists, types, ccgutils, os,
|
||||
nversion, nimsets, msgs, crc, bitsets, idents, lists, types, ccgutils, os,
|
||||
times, ropes, math, passes, rodread, wordrecg, treetab, cgmeth,
|
||||
rodutils, renderer
|
||||
|
||||
|
||||
@@ -438,6 +438,11 @@ proc newLineInfo*(filename: string, line, col: int): TLineInfo =
|
||||
proc ToFilename*(info: TLineInfo): string =
|
||||
if info.fileIndex < 0: result = "???"
|
||||
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.} =
|
||||
result = info.line
|
||||
|
||||
@@ -66,7 +66,8 @@ proc HandleCmdLine() =
|
||||
var filename = ""
|
||||
ProcessCmdLine(passCmd1, command, filename)
|
||||
if filename != "":
|
||||
var p = splitFile(filename)
|
||||
var fullPath = expandFilename(filename)
|
||||
var p = splitFile(fullPath)
|
||||
options.projectPath = p.dir
|
||||
options.projectName = p.name
|
||||
nimconf.LoadConfig(filename) # load the right config file
|
||||
|
||||
@@ -74,7 +74,8 @@ icc.options.linker = "-cxxlib"
|
||||
@if windows:
|
||||
gcc.path = r"$nimrod\dist\mingw\bin"
|
||||
@end
|
||||
gcc.options.debug = "-g"
|
||||
gcc.options.debug = "-g3 -O0"
|
||||
|
||||
@if macosx:
|
||||
@if not release:
|
||||
gcc.options.always = "-w -fasm-blocks -O1"
|
||||
|
||||
Reference in New Issue
Block a user