adds an option to interleave the generated code with snippets from the original source

Lines from the original source are outputted as comments next to line directives.
Hopefully, this will make debugging codegen problems easier.

Other changes:
The frame setup code now uses a single-line C macro. My motivation was to reduce
the noise in the generated output and make it easier to step over the boiler-plate
code, but counter-intuitively this also improved the overall compilation speed a
little bit so I applied the same treatment to line tracking too (this reduces the size of
the generated files and the explanation is that probably the I/O overhead dominates
the macro expansion costs).
This commit is contained in:
Zahary Karadjov 2012-12-02 20:36:29 +02:00
commit d0edb1826b
9 changed files with 149 additions and 85 deletions

View file

@ -508,16 +508,31 @@ proc getEscapedChar(L: var TLexer, tok: var TToken) =
if (xi <= 255): add(tok.literal, Chr(xi))
else: lexMessage(L, errInvalidCharacterConstant)
else: lexMessage(L, errInvalidCharacterConstant)
proc newString(s: cstring, l: int): string =
## XXX, how come there is no support for this?
result = newString(l)
for i in 0 .. <l:
result[i] = s[i]
proc HandleCRLF(L: var TLexer, pos: int): int =
template registerLine =
let col = L.getColNumber(pos)
if col > MaxLineLength:
lexMessagePos(L, hintLineTooLong, pos)
if optEmbedOrigSrc in gGlobalOptions:
let lineStart = cast[TAddress](L.buf) + L.lineStart
let line = newString(cast[cstring](lineStart), col)
addSourceLine(L.fileIdx, line)
proc HandleCRLF(L: var TLexer, pos: int): int =
case L.buf[pos]
of CR:
if getColNumber(L, pos) > MaxLineLength:
lexMessagePos(L, hintLineTooLong, pos)
of CR:
registerLine()
result = lexbase.HandleCR(L, pos)
of LF:
if getColNumber(L, pos) > MaxLineLength:
lexMessagePos(L, hintLineTooLong, pos)
of LF:
registerLine()
result = lexbase.HandleLF(L, pos)
else: result = pos