Skip to content

Commit

Permalink
Added support for vtable visualization in Cfront mode.
Browse files Browse the repository at this point in the history
Unsupported for now is virtual inheritance as well as how a
`dynamic_cast` translates.
  • Loading branch information
andreasfertig committed Jul 15, 2024
1 parent f170064 commit 103d803
Show file tree
Hide file tree
Showing 27 changed files with 1,941 additions and 65 deletions.
50 changes: 50 additions & 0 deletions ASTHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@ CanQualType VoidTy()
}
//-----------------------------------------------------------------------------

ParenExpr* Paren(Expr* expr)
{
return new(GetGlobalAST()) ParenExpr({}, {}, expr);
}
//-----------------------------------------------------------------------------

QualType ContantArrayTy(QualType t, int size)
{
return GetGlobalAST().getConstantArrayType(t,
llvm::APInt(32, size, false),
/*const Expr* SizeExpr*/ nullptr,
ArraySizeModifier::Normal,
0u);
}
//-----------------------------------------------------------------------------

static QualType mkAnonVoidFunctionPointer()
{
auto voidPtr = Ptr(VoidTy());
Expand All @@ -215,6 +231,25 @@ CXXStaticCastExpr* CastToVoidFunPtr(std::string_view name)
}
//-----------------------------------------------------------------------------

CXXReinterpretCastExpr* ReinterpretCast(QualType toType, const Expr* toExpr, bool makePointer)
{
auto& ctx = GetGlobalAST();

QualType sourceInfoToType = makePointer ? Ptr(toType) : toType;

return CXXReinterpretCastExpr::Create(ctx,
toType,
VK_LValue,
CK_BitCast,
const_cast<Expr*>(toExpr),
nullptr,
ctx.getTrivialTypeSourceInfo(sourceInfoToType),
{},
{},
{});
}
//-----------------------------------------------------------------------------

CXXStaticCastExpr* StaticCast(QualType toType, const Expr* toExpr, bool makePointer)
{
auto& ctx = GetGlobalAST();
Expand Down Expand Up @@ -298,6 +333,12 @@ BinaryOperator* Equal(Expr* var, Expr* assignExpr)
}
//-----------------------------------------------------------------------------

BinaryOperator* Plus(Expr* var, Expr* assignExpr)
{
return mkBinaryOperator(var, assignExpr, BO_Add, var->getType());
}
//-----------------------------------------------------------------------------

GotoStmt* Goto(std::string_view labelName)
{
return new(GetGlobalAST()) GotoStmt(mkLabelDecl(labelName), {}, {});
Expand Down Expand Up @@ -511,6 +552,15 @@ FieldDecl* mkFieldDecl(DeclContext* dc, std::string_view name, QualType type)
}
//-----------------------------------------------------------------------------

InitListExpr* InitList(ArrayRef<Expr*> initExprs, QualType t)
{
auto* initList = new(GetGlobalAST()) InitListExpr(GetGlobalAST(), SourceLocation{}, initExprs, SourceLocation{});
initList->setType(t);

return initList;
}
//-----------------------------------------------------------------------------

ArraySubscriptExpr* ArraySubscript(const Expr* lhs, uint64_t index, QualType type)
{
return new(GetGlobalAST()) ArraySubscriptExpr(
Expand Down
5 changes: 5 additions & 0 deletions ASTHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ DeclRefExpr* mkDeclRefExpr(const ValueDecl* vd);
NullStmt* mkNullStmt();
FieldDecl* mkFieldDecl(DeclContext* dc, std::string_view name, QualType type);

ParenExpr* Paren(Expr*);
QualType ContantArrayTy(QualType t, int size);
InitListExpr* InitList(ArrayRef<Expr*> initExprs, QualType t);
ArraySubscriptExpr* ArraySubscript(const Expr* lhs, uint64_t index, QualType type);
MemberExpr* AccessMember(const Expr* expr, const ValueDecl* vd, bool isArrow = true);
CXXMemberCallExpr* CallMemberFun(Expr* memExpr, QualType retType);
Expand All @@ -120,6 +123,8 @@ BinaryOperator* Assign(const VarDecl* var, Expr* assignExpr);
BinaryOperator* Assign(UnaryOperator* var, Expr* assignExpr);
BinaryOperator* Assign(Expr* var, Expr* assignExpr);
BinaryOperator* Equal(Expr* var, Expr* assignExpr);
BinaryOperator* Plus(Expr* var, Expr* assignExpr);
CXXReinterpretCastExpr* ReinterpretCast(QualType toType, const Expr* toExpr, bool makePointer = false);
CXXStaticCastExpr* StaticCast(QualType toType, const Expr* toExpr, bool makePointer = false);
CXXStaticCastExpr* CastToVoidFunPtr(std::string_view name);
CXXStaticCastExpr* Cast(const Expr* toExpr, QualType toType);
Expand Down
Loading

0 comments on commit 103d803

Please sign in to comment.