From 0536c7e683fb522a024787b208f98f87ac9ae142 Mon Sep 17 00:00:00 2001 From: cfreksen Date: Mon, 30 Oct 2017 01:32:35 +0100 Subject: [PATCH] Implement encoding LLVM strings. --- ll.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ll.py b/ll.py index 81a9415..3fa27d7 100644 --- a/ll.py +++ b/ll.py @@ -217,6 +217,17 @@ def gdecl2s(gdecl): .format(gdecl.name, ty2s(gdecl.ty), ginit2s(gdecl.body))) -def ll_encode(s): - # TODO - return s +def ll_encode(string): + res_l = [] + for c in string: + code = ord(c) + if code <= 31 or code == 127: + res_l.append('\{:02X}'.format(code)) + elif c == '\\': + res_l.append('\\\\') + elif c == '"': + res_l.append('\\22') + else: + res_l.append(c) + + return ''.join(res_l)