aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-09-17 17:29:31 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-09-17 17:29:31 -0700
commit38d3c35a77d1bb43990726241a7fa02d0f6caaf3 (patch)
tree2699b458a3ca2aed48c9569e03fc45cecac62ce5
parent9d3794f7fb6db0ecf61548f8ea5ef300e397594b (diff)
optional memcpy support for autodebugger
-rw-r--r--tools/autodebugger.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/tools/autodebugger.py b/tools/autodebugger.py
index 0b75d055..f4c580a2 100644
--- a/tools/autodebugger.py
+++ b/tools/autodebugger.py
@@ -8,6 +8,7 @@ compare that to the output when compiled using emscripten.
import os, sys, re
ALLOW_POINTERS = False
+MEMCPY = False
POSTAMBLE = '''
@.emscripten.autodebug.str = private constant [10 x i8] c"AD:%d,%d\\0A\\00", align 1 ; [#uses=1]
@@ -139,9 +140,68 @@ LLVM_STYLE_OLD = '<label>' not in data and 'entry:' in data
if not LLVM_STYLE_OLD:
POSTAMBLE = POSTAMBLE_NEW
+if MEMCPY:
+ POSTAMBLE = '''
+@.emscripten.memcpy.str = private constant [7 x i8] c"MC:%d\\0A\\00", align 1 ; [#uses=1]
+
+''' + POSTAMBLE + '''
+; [#uses=1]
+define void @emscripten_memcpy(i8* %destination, i8* %source, i32 %num, i32 %whati, i1 %sthis) nounwind {
+entry:
+ %destination.addr = alloca i8*, align 4 ; [#uses=3]
+ %source.addr = alloca i8*, align 4 ; [#uses=2]
+ %num.addr = alloca i32, align 4 ; [#uses=3]
+ %i = alloca i32, align 4 ; [#uses=5]
+ %src = alloca i8*, align 4 ; [#uses=5]
+ %dst = alloca i8*, align 4 ; [#uses=4]
+ store i8* %destination, i8** %destination.addr, align 4
+ store i8* %source, i8** %source.addr, align 4
+ store i32 %num, i32* %num.addr, align 4
+ %tmp = load i8** %source.addr, align 4 ; [#uses=1]
+ store i8* %tmp, i8** %src, align 4
+ %tmp2 = load i8** %destination.addr, align 4 ; [#uses=1]
+ store i8* %tmp2, i8** %dst, align 4
+ store i32 0, i32* %i, align 4
+ %tmp31 = load i32* %i, align 4 ; [#uses=1]
+ %tmp42 = load i32* %num.addr, align 4 ; [#uses=1]
+ %cmp3 = icmp ult i32 %tmp31, %tmp42 ; [#uses=1]
+ br i1 %cmp3, label %for.body, label %for.end
+
+for.body: ; preds = %for.body, %entry
+ %tmp5 = load i8** %src, align 4 ; [#uses=1]
+ %tmp6 = load i8* %tmp5 ; [#uses=1]
+ %conv = zext i8 %tmp6 to i32 ; [#uses=1]
+ %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([7 x i8]* @.emscripten.memcpy.str, i32 0, i32 0), i32 %conv); [#uses=0]
+ %tmp7 = load i8** %src, align 4 ; [#uses=1]
+ %tmp8 = load i8* %tmp7 ; [#uses=1]
+ %tmp9 = load i8** %dst, align 4 ; [#uses=1]
+ store i8 %tmp8, i8* %tmp9
+ %tmp10 = load i32* %i, align 4 ; [#uses=1]
+ %inc = add i32 %tmp10, 1 ; [#uses=1]
+ store i32 %inc, i32* %i, align 4
+ %tmp11 = load i8** %src, align 4 ; [#uses=1]
+ %incdec.ptr = getelementptr inbounds i8* %tmp11, i32 1 ; [#uses=1]
+ store i8* %incdec.ptr, i8** %src, align 4
+ %tmp12 = load i8** %dst, align 4 ; [#uses=1]
+ %incdec.ptr13 = getelementptr inbounds i8* %tmp12, i32 1 ; [#uses=1]
+ store i8* %incdec.ptr13, i8** %dst, align 4
+ %tmp3 = load i32* %i, align 4 ; [#uses=1]
+ %tmp4 = load i32* %num.addr, align 4 ; [#uses=1]
+ %cmp = icmp ult i32 %tmp3, %tmp4 ; [#uses=1]
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.body, %entry
+ %tmp14 = load i8** %destination.addr, align 4 ; [#uses=1]
+ ret void
+}
+'''
+
lines_added = 0
lines = data.split('\n')
for i in range(len(lines)):
+ if MEMCPY:
+ if not lines[i].startswith('declare void'):
+ lines[i] = lines[i].replace('@llvm.memcpy.p0i8.p0i8.i32', '@emscripten_memcpy')
m = re.match(' store (?P<type>i64|i32|i16|i8|float|double|%?[\w\.\*]+) (?P<var>%?[\w.+_]+), .*', lines[i])
if m:
index = i+1+lines_added