Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make number of declared structs contextual #294

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/rellic/AST/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ struct Provenance {
IRToValDeclMap value_decls;
ArgToTempMap temp_decls;
BlockToUsesMap outgoing_uses;

size_t num_literal_structs = 0;
size_t num_declared_structs = 0;
};

template <typename TKey1, typename TKey2, typename TKey3, typename TValue>
Expand Down
11 changes: 5 additions & 6 deletions lib/AST/IRToASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class ExprGen : public llvm::InstVisitor<ExprGen, clang::Expr *> {
ASTBuilder ast;

Provenance &provenance;
size_t num_literal_structs = 0;
size_t num_declared_structs = 0;

public:
ExprGen(clang::ASTUnit &unit, Provenance &provenance)
Expand Down Expand Up @@ -170,11 +168,12 @@ clang::QualType ExprGen::GetQualType(llvm::Type *type) {
if (!decl) {
auto tudecl{ast_ctx.getTranslationUnitDecl()};
auto strct{llvm::cast<llvm::StructType>(type)};
auto sname{strct->isLiteral() ? ("literal_struct_" +
std::to_string(num_literal_structs++))
: strct->getName().str()};
auto sname{strct->isLiteral()
? ("literal_struct_" +
std::to_string(provenance.num_literal_structs++))
: strct->getName().str()};
if (sname.empty()) {
sname = "struct" + std::to_string(num_declared_structs++);
sname = "struct" + std::to_string(provenance.num_declared_structs++);
}

// Create a C struct declaration
Expand Down