GenericValue.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- GenericValue.h - Represent any type of LLVM value --------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // The GenericValue class is used to represent an LLVM value of arbitrary type.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_EXECUTIONENGINE_GENERICVALUE_H
  18. #define LLVM_EXECUTIONENGINE_GENERICVALUE_H
  19. #include "llvm/ADT/APInt.h"
  20. #include <vector>
  21. namespace llvm {
  22. using PointerTy = void *;
  23. struct GenericValue {
  24. struct IntPair {
  25. unsigned int first;
  26. unsigned int second;
  27. };
  28. union {
  29. double DoubleVal;
  30. float FloatVal;
  31. PointerTy PointerVal;
  32. struct IntPair UIntPairVal;
  33. unsigned char Untyped[8];
  34. };
  35. APInt IntVal; // also used for long doubles.
  36. // For aggregate data types.
  37. std::vector<GenericValue> AggregateVal;
  38. // to make code faster, set GenericValue to zero could be omitted, but it is
  39. // potentially can cause problems, since GenericValue to store garbage
  40. // instead of zero.
  41. GenericValue() : IntVal(1, 0) {
  42. UIntPairVal.first = 0;
  43. UIntPairVal.second = 0;
  44. }
  45. explicit GenericValue(void *V) : PointerVal(V), IntVal(1, 0) {}
  46. };
  47. inline GenericValue PTOGV(void *P) { return GenericValue(P); }
  48. inline void *GVTOP(const GenericValue &GV) { return GV.PointerVal; }
  49. } // end namespace llvm
  50. #endif // LLVM_EXECUTIONENGINE_GENERICVALUE_H
  51. #ifdef __GNUC__
  52. #pragma GCC diagnostic pop
  53. #endif