[llvm-commits] [dragonegg] r128454 - in /dragonegg/trunk: Internals.h Types.cpp

Duncan Sands baldrick at free.fr
Mon Mar 28 23:26:30 PDT 2011


Author: baldrick
Date: Tue Mar 29 01:26:30 2011
New Revision: 128454

URL: http://llvm.org/viewvc/llvm-project?rev=128454&view=rev
Log:
Add a utility function for getting an array of units (aka bytes).

Modified:
    dragonegg/trunk/Internals.h
    dragonegg/trunk/Types.cpp

Modified: dragonegg/trunk/Internals.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/Internals.h?rev=128454&r1=128453&r2=128454&view=diff
==============================================================================
--- dragonegg/trunk/Internals.h (original)
+++ dragonegg/trunk/Internals.h Tue Mar 29 01:26:30 2011
@@ -1,4 +1,4 @@
-//=---- Internals.h - Interface between the backend components --*- C++ -*---=//
+//=---- Internals.h - Interface between the backend components ----*- C++ -*-=//
 //
 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011  Chris Lattner,
 // Duncan Sands et al.
@@ -227,6 +227,12 @@
     Constant::getNullValue(Ty) : UndefValue::get(Ty);
 }
 
+/// GetUnitType - Returns an integer one address unit wide if 'NumUnits' is 1;
+/// otherwise returns an array of such integers with 'NumUnits' elements.  For
+/// example, on a machine which has 16 bit bytes returns an i16 or an array of
+/// i16.
+extern const Type *GetUnitType(LLVMContext &C, unsigned NumUnits = 1);
+
 /// GetUnitPointerType - Returns an LLVM pointer type which points to memory one
 /// address unit wide.  For example, on a machine which has 16 bit bytes returns
 /// an i16*.

Modified: dragonegg/trunk/Types.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/Types.cpp?rev=128454&r1=128453&r2=128454&view=diff
==============================================================================
--- dragonegg/trunk/Types.cpp (original)
+++ dragonegg/trunk/Types.cpp Tue Mar 29 01:26:30 2011
@@ -230,12 +230,23 @@
   return Result;
 }
 
+/// GetUnitType - Returns an integer one address unit wide if 'NumUnits' is 1;
+/// otherwise returns an array of such integers with 'NumUnits' elements.  For
+/// example, on a machine which has 16 bit bytes returns an i16 or an array of
+/// i16.
+const Type *GetUnitType(LLVMContext &C, unsigned NumUnits) {
+  assert(!(BITS_PER_UNIT & 7) && "Unit size not a multiple of 8 bits!");
+  const Type *UnitTy = IntegerType::get(C, BITS_PER_UNIT);
+  if (NumUnits == 1)
+    return UnitTy;
+  return ArrayType::get(UnitTy, NumUnits);
+}
+
 /// GetUnitPointerType - Returns an LLVM pointer type which points to memory one
 /// address unit wide.  For example, on a machine which has 16 bit bytes returns
 /// an i16*.
 const Type *GetUnitPointerType(LLVMContext &C, unsigned AddrSpace) {
-  assert(!(BITS_PER_UNIT & 7) && "Unit size not a multiple of 8 bits!");
-  return IntegerType::get(C, BITS_PER_UNIT)->getPointerTo(AddrSpace);
+  return GetUnitType(C)->getPointerTo(AddrSpace);
 }
 
 // isPassedByInvisibleReference - Return true if an argument of the specified





More information about the llvm-commits mailing list