Minor changes
This commit is contained in:
parent
b9b5174759
commit
50eba9a485
2 changed files with 36 additions and 18 deletions
|
|
@ -34,16 +34,20 @@ macro cDebug*(): untyped =
|
||||||
macro cDefine*(name: static string, val: static string = ""): untyped =
|
macro cDefine*(name: static string, val: static string = ""): untyped =
|
||||||
result = newNimNode(nnkStmtList)
|
result = newNimNode(nnkStmtList)
|
||||||
|
|
||||||
var str = "-D" & name
|
var str = name
|
||||||
if val.nBl:
|
if val.nBl:
|
||||||
str &= &"=\"{val}\""
|
str &= &"=\"{val}\""
|
||||||
|
|
||||||
result.add(quote do:
|
if str notin gDefines:
|
||||||
{.passC: `str`.}
|
gDefines.add(str)
|
||||||
)
|
str = "-D" & str
|
||||||
|
|
||||||
if gDebug:
|
result.add(quote do:
|
||||||
echo result.repr
|
{.passC: `str`.}
|
||||||
|
)
|
||||||
|
|
||||||
|
if gDebug:
|
||||||
|
echo result.repr
|
||||||
|
|
||||||
macro cAddSearchDir*(dir: static string): untyped =
|
macro cAddSearchDir*(dir: static string): untyped =
|
||||||
result = newNimNode(nnkStmtList)
|
result = newNimNode(nnkStmtList)
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
import macros, strutils
|
import macros, strformat, strutils
|
||||||
|
|
||||||
import regex
|
import regex
|
||||||
|
|
||||||
import globals
|
import git, globals
|
||||||
|
|
||||||
proc getIdentifier*(str: string): string =
|
proc getIdentifier*(str: string): string =
|
||||||
result = str.strip(chars={'_'})
|
result = str.strip(chars={'_'})
|
||||||
|
|
||||||
proc getType*(str: string): string =
|
proc getType*(str: string): string =
|
||||||
result = str.strip(chars={'_'}).replace(re"([u]?int[\d]+)_t", "$1").replace(re"^void$", "object")
|
result = str.strip(chars={'_'}).replace(re"([u]?int[\d]+)_t", "$1").replace(re"^void$", "object")
|
||||||
|
|
||||||
proc getLit*(str: string): string =
|
proc getLit*(str: string): string =
|
||||||
if str.contains(re"^[\-]?[\d]+$") or
|
if str.contains(re"^[\-]?[\d]+$") or
|
||||||
str.contains(re"^[\-]?[\d]*\.[\d]+$") or
|
str.contains(re"^[\-]?[\d]*\.[\d]+$") or
|
||||||
|
|
@ -19,15 +19,8 @@ proc getLit*(str: string): string =
|
||||||
proc getNodeValIf*(node: ref Ast, esym: Sym): string =
|
proc getNodeValIf*(node: ref Ast, esym: Sym): string =
|
||||||
if esym != node.sym:
|
if esym != node.sym:
|
||||||
return
|
return
|
||||||
|
|
||||||
return gCode[node.start .. node.stop-1].strip()
|
|
||||||
|
|
||||||
proc getGccPaths*(mode = "c"): string =
|
return gCode[node.start .. node.stop-1].strip()
|
||||||
var
|
|
||||||
nul = when defined(Windows): "nul" else: "/dev/null"
|
|
||||||
mmode = if mode == "cpp": "c++" else: mode
|
|
||||||
|
|
||||||
return staticExec("gcc -Wp,-v -x" & mmode & " " & nul)
|
|
||||||
|
|
||||||
proc getLineCol*(node: ref Ast): tuple[line, col: int] =
|
proc getLineCol*(node: ref Ast): tuple[line, col: int] =
|
||||||
result.line = 1
|
result.line = 1
|
||||||
|
|
@ -36,4 +29,25 @@ proc getLineCol*(node: ref Ast): tuple[line, col: int] =
|
||||||
if gCode[i] == '\n':
|
if gCode[i] == '\n':
|
||||||
result.col = 0
|
result.col = 0
|
||||||
result.line += 1
|
result.line += 1
|
||||||
result.col += 1
|
result.col += 1
|
||||||
|
|
||||||
|
proc getGccPaths*(mode = "c"): string =
|
||||||
|
var
|
||||||
|
nul = when defined(Windows): "nul" else: "/dev/null"
|
||||||
|
mmode = if mode == "cpp": "c++" else: mode
|
||||||
|
|
||||||
|
return staticExec("gcc -Wp,-v -x" & mmode & " " & nul)
|
||||||
|
|
||||||
|
proc getPreprocessor*(fullpath: string, mode = "cpp"): string =
|
||||||
|
var
|
||||||
|
mmode = if mode == "cpp": "c++" else: mode
|
||||||
|
cmd = &"gcc -E -dD -x{mmode} "
|
||||||
|
|
||||||
|
for inc in gIncludeDirs:
|
||||||
|
cmd &= &"-I\"{inc}\" "
|
||||||
|
|
||||||
|
for def in gDefines:
|
||||||
|
cmd &= &"-D{def} "
|
||||||
|
|
||||||
|
cmd &= &"\"{fullpath}\""
|
||||||
|
return staticExec(cmd)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue