@@ -31,7 +31,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
31
31
DiagnosticsEngine &diags)
32
32
: builder(&context), astCtx(astctx), langOpts(astctx.getLangOpts()),
33
33
theModule{mlir::ModuleOp::create (mlir::UnknownLoc::get (&context))},
34
- diags (diags), target(astCtx.getTargetInfo()), genTypes(* this ) {}
34
+ diags (diags), target(astCtx.getTargetInfo()) {}
35
35
36
36
mlir::Location CIRGenModule::getLoc (SourceLocation cLoc) {
37
37
assert (cLoc.isValid () && " expected valid source location" );
@@ -67,8 +67,7 @@ void CIRGenModule::emitGlobal(clang::GlobalDecl gd) {
67
67
return ;
68
68
}
69
69
} else {
70
- assert (cast<VarDecl>(global)->isFileVarDecl () &&
71
- " Cannot emit local var decl as global" );
70
+ errorNYI (global->getSourceRange (), " global variable declaration" );
72
71
}
73
72
74
73
// TODO(CIR): Defer emitting some global definitions until later
@@ -78,27 +77,9 @@ void CIRGenModule::emitGlobal(clang::GlobalDecl gd) {
78
77
void CIRGenModule::emitGlobalFunctionDefinition (clang::GlobalDecl gd,
79
78
mlir::Operation *op) {
80
79
auto const *funcDecl = cast<FunctionDecl>(gd.getDecl ());
81
- if (clang::IdentifierInfo *identifier = funcDecl->getIdentifier ()) {
82
- auto funcOp = builder.create <cir::FuncOp>(
83
- getLoc (funcDecl->getSourceRange ()), identifier->getName ());
84
- theModule.push_back (funcOp);
85
- } else {
86
- errorNYI (funcDecl->getSourceRange ().getBegin (),
87
- " function definition with a non-identifier for a name" );
88
- }
89
- }
90
-
91
- void CIRGenModule::emitGlobalVarDefinition (const clang::VarDecl *vd,
92
- bool isTentative) {
93
- mlir::Type type = getTypes ().convertType (vd->getType ());
94
- if (clang::IdentifierInfo *identifier = vd->getIdentifier ()) {
95
- auto varOp = builder.create <cir::GlobalOp>(getLoc (vd->getSourceRange ()),
96
- identifier->getName (), type);
97
- theModule.push_back (varOp);
98
- } else {
99
- errorNYI (vd->getSourceRange ().getBegin (),
100
- " variable definition with a non-identifier for a name" );
101
- }
80
+ auto funcOp = builder.create <cir::FuncOp>(
81
+ getLoc (funcDecl->getSourceRange ()), funcDecl->getIdentifier ()->getName ());
82
+ theModule.push_back (funcOp);
102
83
}
103
84
104
85
void CIRGenModule::emitGlobalDefinition (clang::GlobalDecl gd,
@@ -122,9 +103,6 @@ void CIRGenModule::emitGlobalDefinition(clang::GlobalDecl gd,
122
103
return ;
123
104
}
124
105
125
- if (const auto *vd = dyn_cast<VarDecl>(decl))
126
- return emitGlobalVarDefinition (vd, !vd->hasDefinition ());
127
-
128
106
llvm_unreachable (" Invalid argument to CIRGenModule::emitGlobalDefinition" );
129
107
}
130
108
@@ -148,23 +126,37 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
148
126
emitGlobal (fd);
149
127
break ;
150
128
}
151
-
152
- case Decl::Var: {
153
- auto *vd = cast<VarDecl>(decl);
154
- emitGlobal (vd);
155
- break ;
156
- }
157
129
}
158
130
}
159
131
132
+ DiagnosticBuilder CIRGenModule::errorNYI (llvm::StringRef feature) {
133
+ unsigned diagID = diags.getCustomDiagID (
134
+ DiagnosticsEngine::Error, " ClangIR code gen Not Yet Implemented: %0" );
135
+ return diags.Report (diagID) << feature;
136
+ }
137
+
160
138
DiagnosticBuilder CIRGenModule::errorNYI (SourceLocation loc,
161
139
llvm::StringRef feature) {
162
140
unsigned diagID = diags.getCustomDiagID (
163
141
DiagnosticsEngine::Error, " ClangIR code gen Not Yet Implemented: %0" );
164
142
return diags.Report (loc, diagID) << feature;
165
143
}
166
144
145
+ DiagnosticBuilder CIRGenModule::errorNYI (SourceLocation loc,
146
+ llvm::StringRef feature,
147
+ llvm::StringRef name) {
148
+ unsigned diagID = diags.getCustomDiagID (
149
+ DiagnosticsEngine::Error, " ClangIR code gen Not Yet Implemented: %0: %1" );
150
+ return diags.Report (loc, diagID) << feature << name;
151
+ }
152
+
167
153
DiagnosticBuilder CIRGenModule::errorNYI (SourceRange loc,
168
154
llvm::StringRef feature) {
169
155
return errorNYI (loc.getBegin (), feature) << loc;
170
156
}
157
+
158
+ DiagnosticBuilder CIRGenModule::errorNYI (SourceRange loc,
159
+ llvm::StringRef feature,
160
+ llvm::StringRef name) {
161
+ return errorNYI (loc.getBegin (), feature, name) << loc;
162
+ }
0 commit comments