6 #include "tir/Constant.h"
10 static_assert(
sizeof(IntegerType) ==
sizeof(
Type));
11 static_assert(
sizeof(FunctionType) ==
sizeof(
Type));
13 static_assert(
sizeof(StructType) ==
sizeof(
Type));
20 std::ostream&
Type::print(std::ostream& os)
const {
22 os <<
"i" <<
static_cast<
const IntegerType*>(
this)->getBitWidth();
23 }
else if(isFunctionType()) {
25 }
else if(isPointerType()) {
27 }
else if(isArrayType()) {
28 auto ty =
static_cast<
const ArrayType*>(
this);
29 os <<
"[" << ty->getLength() <<
" x " << *ty->getElementType() <<
"]";
30 }
else if(isStructType()) {
34 for(
auto ty : ctx_->pimpl().structTypes) {
41 }
else if(isVoidType()) {
49 void Type::dump()
const {
51 std::cerr << std::endl;
54 std::ostream& StructType::printDetail(std::ostream& os)
const {
55 os <<
"type " << *
this <<
" = ";
58 for(
auto& elem :
this->getElements()) {
59 if(!isFirst) os <<
", ";
67 std::ostream& operator<<(std::ostream& os,
const Type& type) {
68 return type.print(os);
74 indices.for_each([&](
auto* idx) {
75 if(subTy->isStructType()) {
76 subTy = cast<StructType>(subTy)->getTypeAtIndex(
77 cast<ConstantInt>(idx)->zextValue());
78 }
else if(subTy->isArrayType()) {
79 subTy = cast<
ArrayType>(subTy)->getElementType();
81 assert(
false &&
"Invalid index for GEP");