Skip to content

Commit

Permalink
added location data to type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ASDAlexander77 committed Oct 22, 2024
1 parent 74a8e9b commit 45ce343
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 190 deletions.
8 changes: 4 additions & 4 deletions tsc/include/TypeScript/LowerToLLVM/CastLogicHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class CastLogicHelper
{
MLIRTypeHelper mth(unionType.getContext());
mlir::Type baseType;
bool needTag = mth.isUnionTypeNeedsTag(unionType, baseType);
bool needTag = mth.isUnionTypeNeedsTag(loc, unionType, baseType);
if (!needTag)
{
auto llvmBoolType = tch.convertType(boolType);
Expand Down Expand Up @@ -512,7 +512,7 @@ class CastLogicHelper
{
MLIRTypeHelper mth(resUnionType.getContext());
mlir::Type baseType;
bool needTag = mth.isUnionTypeNeedsTag(resUnionType, baseType);
bool needTag = mth.isUnionTypeNeedsTag(loc, resUnionType, baseType);
if (needTag)
{
auto typeOfValue = rewriter.create<mlir_ts::TypeOfOp>(loc, mlir_ts::StringType::get(rewriter.getContext()), in);
Expand All @@ -530,7 +530,7 @@ class CastLogicHelper
{
MLIRTypeHelper mth(inUnionType.getContext());
mlir::Type baseType;
bool needTag = mth.isUnionTypeNeedsTag(inUnionType, baseType);
bool needTag = mth.isUnionTypeNeedsTag(loc, inUnionType, baseType);
if (!needTag)
{
return cast(in, baseType, tch.convertType(baseType), resType, resLLVMType);
Expand Down Expand Up @@ -983,7 +983,7 @@ class CastLogicHelper
{
MLIRTypeHelper mth(unionType.getContext());
mlir::Type baseType;
bool needTag = mth.isUnionTypeNeedsTag(unionType, baseType);
bool needTag = mth.isUnionTypeNeedsTag(loc, unionType, baseType);
if (needTag)
{
typeOfValue = toh.typeOfLogic(loc, valueForBoxing, unionType);
Expand Down
72 changes: 36 additions & 36 deletions tsc/include/TypeScript/LowerToLLVM/LLVMDebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ class LLVMDebugInfoHelper
{
}

LLVM::DITypeAttr getDIType(mlir::Type llvmType, mlir::Type type, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
LLVM::DITypeAttr getDIType(mlir::Location location, mlir::Type llvmType, mlir::Type type, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
{
auto diType = getDITypeScriptType(type, file, line, scope);
auto diType = getDITypeScriptType(location, type, file, line, scope);
if (diType)
{
return diType;
}

return getDILLVMType(llvmType, file, line, scope);
return getDILLVMType(location, llvmType, file, line, scope);
}

LLVM::DITypeAttr getDITypeScriptType(mlir::Type type, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
LLVM::DITypeAttr getDITypeScriptType(mlir::Location location, mlir::Type type, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
{
if (!type)
{
Expand All @@ -132,7 +132,7 @@ class LLVMDebugInfoHelper
// special case
if (auto anyType = type.dyn_cast<mlir_ts::AnyType>())
{
return getDIType(anyType, file, line, scope);
return getDIType(location, anyType, file, line, scope);
}

#ifdef ENABLE_DEBUGINFO_PATCH_INFO
Expand All @@ -145,33 +145,33 @@ class LLVMDebugInfoHelper
if (auto unionType = type.dyn_cast<mlir_ts::UnionType>())
{
MLIRTypeHelper mth(context);
if (mth.isUnionTypeNeedsTag(unionType))
if (mth.isUnionTypeNeedsTag(location, unionType))
{
return getDIType(unionType, file, line, scope);
return getDIType(location, unionType, file, line, scope);
}
}

if (auto tupleType = type.dyn_cast<mlir_ts::TupleType>())
{
return getDITypeWithFields(tupleType, "tuple", true, file, line, scope);
return getDITypeWithFields(location, tupleType, "tuple", true, file, line, scope);
}

if (auto classType = type.dyn_cast_or_null<mlir_ts::ClassType>())
{
return getDIType(classType, file, line, scope);
return getDIType(location, classType, file, line, scope);
}

if (auto classStorageType = type.dyn_cast<mlir_ts::ClassStorageType>())
{
return getDITypeWithFields(classStorageType, classStorageType.getName().getValue().str(), false, file, line, scope);
return getDITypeWithFields(location, classStorageType, classStorageType.getName().getValue().str(), false, file, line, scope);
}

if (auto enumType = type.dyn_cast<mlir_ts::EnumType>())
{
return getDIType(enumType, file, line, scope);
return getDIType(location, enumType, file, line, scope);
}

return getDILLVMType(llvmtch.typeConverter.convertType(type), file, line, scope);
return getDILLVMType(location, llvmtch.typeConverter.convertType(type), file, line, scope);
}

LLVM::DITypeAttr getDITypeScriptBasicType(mlir::Type type, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
Expand Down Expand Up @@ -220,7 +220,7 @@ class LLVMDebugInfoHelper
return diTypeAttr;
}

LLVM::DITypeAttr getDILLVMType(mlir::Type llvmType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
LLVM::DITypeAttr getDILLVMType(mlir::Location location, mlir::Type llvmType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
{
LLVM::DITypeAttr diTypeAttr;

Expand Down Expand Up @@ -260,13 +260,13 @@ class LLVMDebugInfoHelper
diTypeAttr = LLVM::DIBasicTypeAttr::get(context, dwarf::DW_TAG_base_type, StringAttr::get(context, typeName), floatType.getIntOrFloatBitWidth(), dwarf::DW_ATE_float);
})
.Case<LLVM::LLVMStructType>([&](auto structType) {
diTypeAttr = getDIStructType(structType, file, line, scope);
diTypeAttr = getDIStructType(location, structType, file, line, scope);
})
.Case<LLVM::LLVMPointerType>([&](auto llvmPointerType) {
diTypeAttr = getDIPointerType(getDILLVMType(llvmPointerType.getElementType(), file, line, scope), file, line);
diTypeAttr = getDIPointerType(getDILLVMType(location, llvmPointerType.getElementType(), file, line, scope), file, line);
})
.Case<LLVM::LLVMFunctionType>([&](auto funcType) {
diTypeAttr = getDISubroutineType(funcType, file, line, scope);
diTypeAttr = getDISubroutineType(location, funcType, file, line, scope);
})
.Default([&](auto type) {
// TODO: review it
Expand Down Expand Up @@ -294,9 +294,9 @@ class LLVMDebugInfoHelper
return getDIPointerType(diTypeAttr, file, line);
}

LLVM::DITypeAttr getDIType(mlir_ts::AnyType anyType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
LLVM::DITypeAttr getDIType(mlir::Location location, mlir_ts::AnyType anyType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
{
auto diBodyType = getDIStructType("any", {
auto diBodyType = getDIStructType(location, "any", {
{"size", mlir::IndexType::get(context)},
{"type", mlir_ts::StringType::get(context)},
}, file, line, scope);
Expand All @@ -318,28 +318,28 @@ class LLVMDebugInfoHelper
}
#endif

LLVM::DITypeAttr getDIType(mlir_ts::UnionType unionType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
LLVM::DITypeAttr getDIType(mlir::Location location, mlir_ts::UnionType unionType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
{
auto strType = mlir_ts::StringType::get(context);
auto diStrType = getDITypeScriptType(strType, file, line, scope);
auto diStrType = getDITypeScriptType(location, strType, file, line, scope);

auto diTypeAttrUnion = getDIUnionType(unionType, file, line, scope);
auto diTypeAttrUnion = getDIUnionType(location, unionType, file, line, scope);

return getDIStructType(MLIRHelper::getAnonymousName(unionType, "union"), {
{"type", diStrType},
{"data", diTypeAttrUnion},
}, file, line, scope);
}

LLVM::DITypeAttr getDIType(mlir_ts::ClassType classType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
LLVM::DITypeAttr getDIType(mlir::Location location, mlir_ts::ClassType classType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
{
auto diTypeAttrClassType = getDIPointerType(getDITypeScriptType(classType.getStorageType(), file, line, scope), file, line);
auto diTypeAttrClassType = getDIPointerType(getDITypeScriptType(location, classType.getStorageType(), file, line, scope), file, line);
return diTypeAttrClassType;
}

LLVM::DITypeAttr getDIType(mlir_ts::EnumType enumType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
LLVM::DITypeAttr getDIType(mlir::Location location, mlir_ts::EnumType enumType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
{
auto diBaseType = getDITypeScriptType(enumType.getElementType(), file, line, scope);
auto diBaseType = getDITypeScriptType(location, enumType.getElementType(), file, line, scope);

//auto enumName = MLIRHelper::getAnonymousName(enumType, "enum");

Expand All @@ -364,7 +364,7 @@ class LLVMDebugInfoHelper
return diBaseType;
}

LLVM::DITypeAttr getDITypeWithFields(mlir::Type typeWithFields, std::string name, bool isNamePrefix, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
LLVM::DITypeAttr getDITypeWithFields(mlir::Location location, mlir::Type typeWithFields, std::string name, bool isNamePrefix, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
{
if (!isNamePrefix)
{
Expand Down Expand Up @@ -409,7 +409,7 @@ class LLVMDebugInfoHelper
}
}

auto elementDiType = getDITypeScriptType(elementType, file, line, scope);
auto elementDiType = getDITypeScriptType(location, elementType, file, line, scope);
auto wrapperDiType = LLVM::DIDerivedTypeAttr::get(context, dwarf::DW_TAG_member, name, elementDiType,
sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, sizesTrack.offsetInBits);
elements.push_back(wrapperDiType);
Expand Down Expand Up @@ -438,12 +438,12 @@ class LLVMDebugInfoHelper
sizeInBits, alignInBits, offsetInBits);
}

LLVM::DISubroutineTypeAttr getDISubroutineType(LLVM::LLVMFunctionType funcType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
LLVM::DISubroutineTypeAttr getDISubroutineType(mlir::Location location, LLVM::LLVMFunctionType funcType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
{
llvm::SmallVector<LLVM::DITypeAttr> elements;
for (auto retType : funcType.getReturnTypes())
{
elements.push_back(getDITypeScriptType(retType, file, line, scope));
elements.push_back(getDITypeScriptType(location, retType, file, line, scope));
}

if (funcType.getParams().size() > 0 && funcType.getReturnTypes().size() == 0)
Expand All @@ -454,15 +454,15 @@ class LLVMDebugInfoHelper

for (auto paramType : funcType.getParams())
{
elements.push_back(getDITypeScriptType(paramType, file, line, scope));
elements.push_back(getDITypeScriptType(location, paramType, file, line, scope));
}

auto subroutineType = LLVM::DISubroutineTypeAttr::get(context, elements);
return subroutineType;
}

// Seems LLVM::DIFlags::FwdDecl is resolving issue for me
LLVM::DITypeAttr getDIStructType(LLVM::LLVMStructType structType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
LLVM::DITypeAttr getDIStructType(mlir::Location location, LLVM::LLVMStructType structType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
{
if (structType.isIdentified())
{
Expand Down Expand Up @@ -494,7 +494,7 @@ class LLVMDebugInfoHelper

StringAttr elementName = StringAttr::get(context, std::to_string(index));

auto elementDiType = getDILLVMType(llvmElementType, file, line, scope);
auto elementDiType = getDILLVMType(location, llvmElementType, file, line, scope);
auto wrapperDiType = LLVM::DIDerivedTypeAttr::get(context, dwarf::DW_TAG_member,
elementName, elementDiType, sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, sizesTrack.offsetInBits);
elements.push_back(wrapperDiType);
Expand All @@ -514,7 +514,7 @@ class LLVMDebugInfoHelper
return compositeType;
}

LLVM::DICompositeTypeAttr getDIStructType(StringRef name, ArrayRef<std::pair<StringRef, mlir::Type>> fields, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
LLVM::DICompositeTypeAttr getDIStructType(mlir::Location location, StringRef name, ArrayRef<std::pair<StringRef, mlir::Type>> fields, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
{
MLIRTypeHelper mth(context);

Expand All @@ -531,7 +531,7 @@ class LLVMDebugInfoHelper

sizesTrack.nextElementType(llvmElementType);

auto elementDiType = getDIType(llvmElementType, elementType, file, line, scope);
auto elementDiType = getDIType(location, llvmElementType, elementType, file, line, scope);
auto wrapperDiType = LLVM::DIDerivedTypeAttr::get(context, dwarf::DW_TAG_member, name, elementDiType,
sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, sizesTrack.offsetInBits);
elements.push_back(wrapperDiType);
Expand Down Expand Up @@ -566,7 +566,7 @@ class LLVMDebugInfoHelper
file, line, scope, LLVM::DITypeAttr(), LLVM::DIFlags::TypePassByValue, sizesTrack.sizeInBits, sizesTrack.alignInBits, elements);
}

LLVM::DICompositeTypeAttr getDIUnionType(mlir_ts::UnionType unionType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
LLVM::DICompositeTypeAttr getDIUnionType(mlir::Location location, mlir_ts::UnionType unionType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope)
{
auto sizeInBits = 0;

Expand All @@ -584,7 +584,7 @@ class LLVMDebugInfoHelper
// name
auto name = mth.getLabelName(elementType);

auto elementDiType = getDITypeScriptType(elementType, file, line, scope);
auto elementDiType = getDITypeScriptType(location, elementType, file, line, scope);
auto wrapperDiType = LLVM::DIDerivedTypeAttr::get(context, dwarf::DW_TAG_member, name,
elementDiType, sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, 0);
elements.push_back(wrapperDiType);
Expand Down
4 changes: 2 additions & 2 deletions tsc/include/TypeScript/LowerToLLVM/LLVMDebugInfoFixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class LLVMDebugInfoHelperFixer
SmallVector <mlir::LLVM::DITypeAttr> resultTypes;
for (auto resType : funcOp.getResultTypes())
{
auto diType = di.getDIType({}, resType, file, line, file);
auto diType = di.getDIType(location, {}, resType, file, line, file);
resultTypes.push_back(diType);
}

Expand All @@ -65,7 +65,7 @@ class LLVMDebugInfoHelperFixer

for (auto argType : funcOp.getArgumentTypes())
{
auto diType = di.getDIType({}, argType, file, line, file);
auto diType = di.getDIType(location, {}, argType, file, line, file);
resultTypes.push_back(diType);
}

Expand Down
2 changes: 1 addition & 1 deletion tsc/include/TypeScript/MLIRLogic/MLIRHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MLIRHelper
assert(line != 0 || column != 0);

auto hashCode = hash_value(fileName);
ssName << 'L' << line << 'C' << column << 'FH' << hashCode;
ssName << 'L' << line << 'C' << column << "FH" << hashCode;
})
.Case<mlir::NameLoc>([&](auto loc) {
getAnonymousNameStep(ssName, loc.getChildLoc());
Expand Down
Loading

0 comments on commit 45ce343

Please sign in to comment.