ABITestGen: Add generation of vector types.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63024 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/ABITest/ABITestGen.py b/utils/ABITest/ABITestGen.py
index c50abe1..957ce2b 100755
--- a/utils/ABITest/ABITestGen.py
+++ b/utils/ABITest/ABITestGen.py
@@ -181,14 +181,14 @@
                     yield '{ %s }'%(', '.join(elements))
         elif isinstance(t, ComplexType):
             for t in self.getTestValues(t.elementType):
-                yield '%s + %si'%(t,t)
-        elif isinstance(t, ArrayType) and not t.isVector:
+                yield '%s + %s * 1i'%(t,t)
+        elif isinstance(t, ArrayType):
             values = list(self.getTestValues(t.elementType))
             if not values:
                 yield '{ }'
-            for i in range(t.size):
+            for i in range(t.numElements):
                 for v in values:
-                    elements = [random.choice(values) for i in range(t.size)]
+                    elements = [random.choice(values) for i in range(t.numElements)]
                     elements[i] = v
                     yield '{ %s }'%(', '.join(elements))
         else:
@@ -220,9 +220,11 @@
         elif isinstance(t, ComplexType):
             self.printValueOfType(prefix, '(__real %s)'%name, t.elementType, output=output,indent=indent)
             self.printValueOfType(prefix, '(__imag %s)'%name, t.elementType, output=output,indent=indent)
-        elif isinstance(t, ArrayType) and not t.isVector:
-            for i in range(t.size):
-                self.printValueOfType(prefix, '(%s)[%d]'%(name,i), 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.
+                self.printValueOfType(prefix, '((%s*) &%s)[%d]'%(t.elementType,name,i), t.elementType, output=output,indent=indent)                            
         else:
             raise NotImplementedError,'Cannot print value of type: "%s"'%(t,)
 
@@ -346,24 +348,28 @@
     # Contruct type generator
     builtins = []
     ints = []
-    if opts.useChar: ints.append('char')
-    if opts.useShort: ints.append('short')
-    if opts.useInt: ints.append('int')
-    if opts.useLong: ints.append('long')
-    if opts.useLongLong: ints.append('long long')
+    if opts.useChar: ints.append(('char',1))
+    if opts.useShort: ints.append(('short',2))
+    if opts.useInt: ints.append(('int',4))
+    # FIXME: Wrong size.
+    if opts.useLong: ints.append(('long',4))
+    if opts.useLongLong: ints.append(('long long',8))
     if opts.useUnsigned: 
-        ints = (['unsigned %s'%i for i in ints] + 
-                ['signed %s'%i for i in ints])
+        ints = ([('unsigned %s'%i,s) for i,s in ints] + 
+                [('signed %s'%i,s) for i,s in ints])
     builtins.extend(ints)
 
-    if opts.useBool: builtins.append('_Bool')
-    if opts.useFloat: builtins.append('float')
-    if opts.useDouble: builtins.append('double')
-    if opts.useLongDouble: builtins.append('long double')
-    if opts.useVoidPointer:  builtins.append('void*')
+    if opts.useBool: builtins.append(('_Bool',1))
+    if opts.useFloat: builtins.append(('float',4))
+    if opts.useDouble: builtins.append(('double',8))
+    if opts.useLongDouble: builtins.append(('long double',16))
+    # FIXME: Wrong size.
+    if opts.useVoidPointer:  builtins.append(('void*',4))
 
-    btg = FixedTypeGenerator(map(BuiltinType,builtins))
-    sbtg = FixedTypeGenerator(map(BuiltinType,['char','int','float']))
+    btg = FixedTypeGenerator([BuiltinType(n,s) for n,s in builtins])
+    sbtg = FixedTypeGenerator([BuiltinType('char',1),
+                               BuiltinType('int',4),
+                               BuiltinType('float',4)])
 
     atg = AnyTypeGenerator()
     artg = AnyTypeGenerator()
diff --git a/utils/ABITest/TypeGen.py b/utils/ABITest/TypeGen.py
index 3074a56..50dd77c 100644
--- a/utils/ABITest/TypeGen.py
+++ b/utils/ABITest/TypeGen.py
@@ -15,8 +15,12 @@
 # Actual type types
 
 class BuiltinType:
-    def __init__(self, name):
+    def __init__(self, name, size):
         self.name = name
+        self.size = size
+
+    def sizeof(self):
+        return self.size
 
     def __str__(self):
         return self.name
@@ -49,6 +53,12 @@
         self.isVector = isVector
         self.elementType = elementType
         self.size = size
+        if isVector:
+            eltSize = self.elementType.sizeof()
+            assert not (self.size % eltSize)
+            self.numElements = self.size // eltSize
+        else:
+            self.numElements = self.size
 
     def __str__(self):
         if self.isVector:
@@ -305,7 +315,8 @@
 
 def test():
     atg = AnyTypeGenerator()
-    btg = FixedTypeGenerator(map(BuiltinType,['int','float']))
+    btg = FixedTypeGenerator([BuiltinType('int',4),
+                              BuiltinType('float',4)])
     atg.addGenerator( btg )
     atg.addGenerator( ComplexTypeGenerator(btg) )
     atg.addGenerator( RecordTypeGenerator(atg, True, 2) )