]> granicus.if.org Git - clang/commitdiff
ABITest: Add some checking of values for return types; useful for
authorDaniel Dunbar <daniel@zuster.org>
Tue, 17 Feb 2009 23:13:43 +0000 (23:13 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 17 Feb 2009 23:13:43 +0000 (23:13 +0000)
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

utils/ABITest/ABITestGen.py

index bdf0be4f1d90aa20e8aff4f014eba9e2564ab15a..dfea36af3f2a595072f499d35e6e56f38dbb64a4 100755 (executable)
@@ -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():