Type.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #include "Type.h"
  2. #include "Semantic.h"
  3. #include "Builtin.h"
  4. #include <llvm/IR/DerivedTypes.h>
  5. #include <llvm/IR/Type.h>
  6. using namespace qlow;
  7. sem::Type::~Type(void)
  8. {
  9. }
  10. bool sem::Type::equals(const Type& other) const
  11. {
  12. return this == &other;
  13. }
  14. sem::Type* sem::Type::VOID = new sem::NativeType(sem::NativeType::Type::VOID);
  15. sem::Type* sem::Type::INTEGER = new sem::NativeType(sem::NativeType::Type::INTEGER);
  16. sem::Type* sem::Type::BOOLEAN = new sem::NativeType(sem::NativeType::Type::BOOLEAN);
  17. sem::Scope& sem::ClassType::getScope(void)
  18. {
  19. return classType->scope;
  20. }
  21. llvm::Type* sem::ClassType::getLlvmType (llvm::LLVMContext& context) const
  22. {
  23. return classType->llvmType;
  24. }
  25. bool sem::ClassType::equals(const Type& other) const
  26. {
  27. if (auto* oct = dynamic_cast<const ClassType*>(&other); oct) {
  28. return this->classType == oct->classType;
  29. }
  30. else {
  31. return false;
  32. }
  33. }
  34. sem::Scope& sem::ArrayType::getScope(void)
  35. {
  36. }
  37. llvm::Type* sem::ArrayType::getLlvmType (llvm::LLVMContext& context) const
  38. {
  39. // TODO implement
  40. return nullptr;
  41. }
  42. bool sem::ArrayType::equals(const Type& other) const
  43. {
  44. if (auto* oct = dynamic_cast<const ArrayType*>(&other); oct) {
  45. return this->arrayType->equals(*oct->arrayType);
  46. }
  47. else {
  48. return false;
  49. }
  50. }
  51. sem::Scope& sem::NativeType::getScope(void)
  52. {
  53. }
  54. bool sem::NativeType::isIntegerType(void) const
  55. {
  56. switch(type) {
  57. case INTEGER:
  58. case INT8:
  59. case INT16:
  60. case INT32:
  61. case INT64:
  62. case INT128:
  63. case UINT8:
  64. case UINT16:
  65. case UINT32:
  66. case UINT64:
  67. case UINT128:
  68. return true;
  69. default:
  70. return false;
  71. }
  72. }
  73. llvm::Type* sem::NativeType::getLlvmType (llvm::LLVMContext& context) const
  74. {
  75. switch (type) {
  76. case VOID:
  77. return llvm::Type::getVoidTy(context);
  78. case INTEGER:
  79. return llvm::Type::getInt32Ty(context);
  80. case BOOLEAN:
  81. return llvm::Type::getInt1Ty(context);
  82. case CHAR:
  83. return llvm::Type::getInt32Ty(context);
  84. case INT8:
  85. return llvm::Type::getInt8Ty(context);
  86. case INT16:
  87. return llvm::Type::getInt16Ty(context);
  88. case INT32:
  89. return llvm::Type::getInt32Ty(context);
  90. case INT64:
  91. return llvm::Type::getInt64Ty(context);
  92. case INT128:
  93. return llvm::Type::getInt128Ty(context);
  94. case UINT8:
  95. return llvm::Type::getInt8Ty(context);
  96. case UINT16:
  97. return llvm::Type::getInt16Ty(context);
  98. case UINT32:
  99. return llvm::Type::getInt32Ty(context);
  100. case UINT64:
  101. return llvm::Type::getInt64Ty(context);
  102. case UINT128:
  103. return llvm::Type::getInt128Ty(context);
  104. case FLOAT32:
  105. return llvm::Type::getFloatTy(context);
  106. case FLOAT64:
  107. return llvm::Type::getDoubleTy(context);
  108. case FLOAT128:
  109. return llvm::Type::getFP128Ty(context);
  110. }
  111. }
  112. bool sem::NativeType::equals(const sem::Type& other) const
  113. {
  114. if (auto* oct = dynamic_cast<const NativeType*>(&other); oct) {
  115. return this->type == oct->type;
  116. }
  117. else {
  118. return false;
  119. }
  120. }
  121. llvm::Value* sem::NativeType::generateImplicitCast(llvm::Value* value)
  122. {
  123. // TODO implement
  124. }