diff options
author | Araq <rumpf_a@web.de> | 2014-07-15 09:30:58 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-07-15 09:30:58 +0200 |
commit | 0743f78012e954f5295df7923ccabd472a5a7502 (patch) | |
tree | 5d681c9835f01019e8ae83e14c0cd49d1a6c0d38 /compiler/ccgutils.nim | |
parent | 7fa399f51c39e6661876223009d5003cd2e0cf99 (diff) | |
parent | 18ded6c23d72cd21fa0aa10ff61dc6f9af40832c (diff) | |
download | Nim-0743f78012e954f5295df7923ccabd472a5a7502.tar.gz |
Merge branch 'master' of https://github.com/Araq/Nimrod
Diffstat (limited to 'compiler/ccgutils.nim')
-rw-r--r-- | compiler/ccgutils.nim | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/compiler/ccgutils.nim b/compiler/ccgutils.nim index 1d8f0158b..04983d6a4 100644 --- a/compiler/ccgutils.nim +++ b/compiler/ccgutils.nim @@ -161,6 +161,30 @@ proc makeSingleLineCString*(s: string): string = result.add(c.toCChar) result.add('\"') +proc mangle*(name: string): string = + ## Lowercases the given name and manges any non-alphanumeric characters + ## so they are represented as `HEX____`. If the name starts with a number, + ## `N` is prepended + result = "" + case name[0] + of Letters: + result.add(name[0].toLower) + of Digits: + result.add("N" & name[0]) + else: + result = "HEX" & toHex(ord(name[0]), 2) + for i in 1..(name.len-1): + let c = name[i] + case c + of 'A'..'Z': + add(result, c.toLower) + of '_': + discard + of 'a'..'z', '0'..'9': + add(result, c) + else: + add(result, "HEX" & toHex(ord(c), 2)) + proc makeLLVMString*(s: string): PRope = const MaxLineLength = 64 result = nil |