@@ -31,7 +31,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
3131 DiagnosticsEngine &diags)
3232 : builder(&context), astCtx(astctx), langOpts(astctx.getLangOpts()),
3333 theModule{mlir::ModuleOp::create (mlir::UnknownLoc::get (&context))},
34- diags (diags), target(astCtx.getTargetInfo()), genTypes(* this ) {}
34+ diags (diags), target(astCtx.getTargetInfo()) {}
3535
3636mlir::Location CIRGenModule::getLoc (SourceLocation cLoc) {
3737 assert (cLoc.isValid () && " expected valid source location" );
@@ -67,8 +67,7 @@ void CIRGenModule::emitGlobal(clang::GlobalDecl gd) {
6767 return ;
6868 }
6969 } else {
70- assert (cast<VarDecl>(global)->isFileVarDecl () &&
71- " Cannot emit local var decl as global" );
70+ errorNYI (global->getSourceRange (), " global variable declaration" );
7271 }
7372
7473 // TODO(CIR): Defer emitting some global definitions until later
@@ -78,27 +77,9 @@ void CIRGenModule::emitGlobal(clang::GlobalDecl gd) {
7877void CIRGenModule::emitGlobalFunctionDefinition (clang::GlobalDecl gd,
7978 mlir::Operation *op) {
8079 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);
10283}
10384
10485void CIRGenModule::emitGlobalDefinition (clang::GlobalDecl gd,
@@ -122,9 +103,6 @@ void CIRGenModule::emitGlobalDefinition(clang::GlobalDecl gd,
122103 return ;
123104 }
124105
125- if (const auto *vd = dyn_cast<VarDecl>(decl))
126- return emitGlobalVarDefinition (vd, !vd->hasDefinition ());
127-
128106 llvm_unreachable (" Invalid argument to CIRGenModule::emitGlobalDefinition" );
129107}
130108
@@ -148,23 +126,37 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
148126 emitGlobal (fd);
149127 break ;
150128 }
151-
152- case Decl::Var: {
153- auto *vd = cast<VarDecl>(decl);
154- emitGlobal (vd);
155- break ;
156- }
157129 }
158130}
159131
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+
160138DiagnosticBuilder CIRGenModule::errorNYI (SourceLocation loc,
161139 llvm::StringRef feature) {
162140 unsigned diagID = diags.getCustomDiagID (
163141 DiagnosticsEngine::Error, " ClangIR code gen Not Yet Implemented: %0" );
164142 return diags.Report (loc, diagID) << feature;
165143}
166144
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+
167153DiagnosticBuilder CIRGenModule::errorNYI (SourceRange loc,
168154 llvm::StringRef feature) {
169155 return errorNYI (loc.getBegin (), feature) << loc;
170156}
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