LLVM API Documentation

GenericValue.h
Go to the documentation of this file.
00001 //===-- GenericValue.h - Represent any type of LLVM value -------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // The GenericValue class is used to represent an LLVM value of arbitrary type.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 
00015 #ifndef LLVM_EXECUTIONENGINE_GENERICVALUE_H
00016 #define LLVM_EXECUTIONENGINE_GENERICVALUE_H
00017 
00018 #include "llvm/ADT/APInt.h"
00019 #include "llvm/Support/DataTypes.h"
00020 
00021 namespace llvm {
00022 
00023 typedef void* PointerTy;
00024 class APInt;
00025 
00026 struct GenericValue {
00027   struct IntPair {
00028     unsigned int first;
00029     unsigned int second;
00030   };
00031   union {
00032     double          DoubleVal;
00033     float           FloatVal;
00034     PointerTy       PointerVal;
00035     struct IntPair  UIntPairVal;
00036     unsigned char   Untyped[8];
00037   };
00038   APInt IntVal;   // also used for long doubles.
00039   // For aggregate data types.
00040   std::vector<GenericValue> AggregateVal;
00041 
00042   // to make code faster, set GenericValue to zero could be omitted, but it is
00043   // potentially can cause problems, since GenericValue to store garbage
00044   // instead of zero.
00045   GenericValue() : IntVal(1,0) {UIntPairVal.first = 0; UIntPairVal.second = 0;}
00046   explicit GenericValue(void *V) : PointerVal(V), IntVal(1,0) { }
00047 };
00048 
00049 inline GenericValue PTOGV(void *P) { return GenericValue(P); }
00050 inline void* GVTOP(const GenericValue &GV) { return GV.PointerVal; }
00051 
00052 } // End llvm namespace.
00053 #endif