From 8351c1e187d8f65477db05a07bacd5d184c2b950 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 22 Feb 2013 15:04:20 +0000 Subject: [PATCH 1/1] Be more lenient with shader matching. --- tracematch.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/tracematch.py b/tracematch.py index ec0509e..45228bf 100755 --- a/tracematch.py +++ b/tracematch.py @@ -112,6 +112,27 @@ class ApproxMatcher(Matcher): return repr(self.refValue) +class StringMatcher(Matcher): + + def __init__(self, refValue): + self.refValue = refValue + + def isShaderDisassembly(self, value): + return value.find('// Generated by Microsoft (R) D3D Shader Disassembler\n') != -1 + + def normalizeShaderDisassembly(self, value): + # Unfortunately slightly different disassemblers produce different output + return '\n'.join([line.strip() for line in value.split('\n') if line.strip() and not line.startswith('//')]) + + def match(self, value, mo): + if self.isShaderDisassembly(self.refValue) and self.isShaderDisassembly(value): + return self.normalizeShaderDisassembly(self.refValue) == self.normalizeShaderDisassembly(value) + return self.refValue == value + + def __str__(self): + return repr(self.refValue) + + class BitmaskMatcher(Matcher): def __init__(self, refElements): @@ -398,6 +419,9 @@ class Lexer: self.col = ((self.col - 1)//self.tabsize + 1)*self.tabsize + 1 pos = tabpos + 1 self.col += len(text) - pos + + def filter(self, type, text): + return type, text class Parser: @@ -486,16 +510,9 @@ class CallLexer(Lexer): if type == STRING: text = text[1:-1] - # line continuations - text = text.replace('\\\r\n', '') - text = text.replace('\\\r', '') - text = text.replace('\\\n', '') - # quotes text = text.replace('\\"', '"') - type = ID - return type, text @@ -702,7 +719,7 @@ class RefTraceParser(TraceParser): return ApproxMatcher(value) def handleString(self, value): - return LiteralMatcher(value) + return StringMatcher(value) def handleBitmask(self, value): return BitmaskMatcher(value) -- 2.43.0