summaryrefslogtreecommitdiff
path: root/utils/ABITest
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-02-17 23:13:43 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-02-17 23:13:43 +0000
commit9dd60b4526ccfab13cf0976999bf5f90b3423f43 (patch)
tree341ea340b6c7a90d093bfe712ae6ddb58f4e8581 /utils/ABITest
parent05104aa7b6fb01a39c2ee6a889dd8beba8d3e509 (diff)
downloadclang-9dd60b4526ccfab13cf0976999bf5f90b3423f43.tar.gz
ABITest: Add some checking of values for return types; useful for
catching internal consistency problems (esp. w/ reference compiler). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64847 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/ABITest')
-rwxr-xr-xutils/ABITest/ABITestGen.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/utils/ABITest/ABITestGen.py b/utils/ABITest/ABITestGen.py
index bdf0be4f1d..dfea36af3f 100755
--- a/utils/ABITest/ABITestGen.py
+++ b/utils/ABITest/ABITestGen.py
@@ -31,7 +31,9 @@ class TypePrinter:
if self.writeBody:
print >>self.output, '#include <stdio.h>\n'
if self.outputTests:
- print >>self.outputTests, '#include <stdio.h>\n'
+ print >>self.outputTests, '#include <stdio.h>'
+ print >>self.outputTests, '#include <string.h>'
+ print >>self.outputTests, '#include <assert.h>\n'
if headerName:
for f in (self.output,self.outputTests,self.outputDriver):
@@ -39,6 +41,7 @@ class TypePrinter:
print >>f, '#include "%s"\n'%(headerName,)
if self.outputDriver:
+ print >>self.outputDriver, '#include <stdio.h>\n'
print >>self.outputDriver, 'int main(int argc, char **argv) {'
def finish(self):
@@ -50,6 +53,7 @@ class TypePrinter:
print >>self.output, '}'
if self.outputDriver:
+ print >>self.outputDriver, ' printf("DONE\\n");'
print >>self.outputDriver, ' return 0;'
print >>self.outputDriver, '}'
@@ -139,6 +143,7 @@ class TypePrinter:
print >>self.outputTests, ' %s = %s[i];'%(retvalName, retvalTests[0])
print >>self.outputTests, ' RV = %s(%s);'%(fnName, args)
self.printValueOfType(' %s_RV'%fnName, 'RV', FT.returnType, output=self.outputTests, indent=4)
+ self.checkTypeValues('RV', '%s[i]' % retvalTests[0], FT.returnType, output=self.outputTests, indent=4)
print >>self.outputTests, ' }'
if tests:
@@ -270,6 +275,35 @@ class TypePrinter:
else:
raise NotImplementedError,'Cannot print value of type: "%s"'%(t,)
+ def checkTypeValues(self, nameLHS, nameRHS, t, output=None, indent=2):
+ prefix = 'foo'
+ if output is None:
+ output = self.output
+ if isinstance(t, BuiltinType):
+ print >>output, '%*sassert(%s == %s);' % (indent, '', nameLHS, nameRHS)
+ elif isinstance(t, RecordType):
+ for i,f in enumerate(t.fields):
+ self.checkTypeValues('%s.field%d'%(nameLHS,i), '%s.field%d'%(nameRHS,i),
+ f, output=output, indent=indent)
+ if t.isUnion:
+ break
+ elif isinstance(t, ComplexType):
+ self.checkTypeValues('(__real %s)'%nameLHS, '(__real %s)'%nameRHS, t.elementType, output=output,indent=indent)
+ self.checkTypeValues('(__imag %s)'%nameLHS, '(__imag %s)'%nameRHS, t.elementType, output=output,indent=indent)
+ elif isinstance(t, ArrayType):
+ for i in range(t.numElements):
+ # Access in this fashion as a hackish way to portably
+ # access vectors.
+ if t.isVector:
+ self.checkTypeValues('((%s*) &%s)[%d]'%(t.elementType,nameLHS,i),
+ '((%s*) &%s)[%d]'%(t.elementType,nameRHS,i),
+ t.elementType, output=output,indent=indent)
+ else:
+ self.checkTypeValues('%s[%d]'%(nameLHS,i), '%s[%d]'%(nameRHS,i),
+ t.elementType, output=output,indent=indent)
+ else:
+ raise NotImplementedError,'Cannot print value of type: "%s"'%(t,)
+
import sys
def main():