clang 20.0.0git
SemaM68k.cpp
Go to the documentation of this file.
1//===------ SemaM68k.cpp -------- M68k target-specific routines -----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements semantic analysis functions specific to M68k.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/Sema/SemaM68k.h"
15#include "clang/AST/Attr.h"
16#include "clang/AST/DeclBase.h"
19
20namespace clang {
22
24 if (!AL.checkExactlyNumArgs(SemaRef, 1))
25 return;
26
27 if (!AL.isArgExpr(0)) {
28 Diag(AL.getLoc(), diag::err_attribute_argument_type)
30 return;
31 }
32
33 // FIXME: Check for decl - it should be void ()(void).
34
35 Expr *NumParamsExpr = static_cast<Expr *>(AL.getArgAsExpr(0));
36 auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(getASTContext());
37 if (!MaybeNumParams) {
38 Diag(AL.getLoc(), diag::err_attribute_argument_type)
40 << NumParamsExpr->getSourceRange();
41 return;
42 }
43
44 unsigned Num = MaybeNumParams->getLimitedValue(255);
45 if ((Num & 1) || Num > 30) {
46 Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
47 << AL << (int)MaybeNumParams->getSExtValue()
48 << NumParamsExpr->getSourceRange();
49 return;
50 }
51
52 D->addAttr(::new (getASTContext())
53 M68kInterruptAttr(getASTContext(), AL, Num));
54 D->addAttr(UsedAttr::CreateImplicit(getASTContext()));
55}
56} // namespace clang
Defines the clang::ASTContext interface.
const Decl * D
This file declares semantic analysis functions specific to M68k.
__device__ int
SourceLocation getLoc() const
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
This represents one expression.
Definition: Expr.h:110
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
ParsedAttr - Represents a syntactic attribute.
Definition: ParsedAttr.h:129
bool checkExactlyNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has exactly as many args as Num.
Definition: ParsedAttr.cpp:298
Expr * getArgAsExpr(unsigned Arg) const
Definition: ParsedAttr.h:398
bool isArgExpr(unsigned Arg) const
Definition: ParsedAttr.h:394
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:60
ASTContext & getASTContext() const
Definition: SemaBase.cpp:9
Sema & SemaRef
Definition: SemaBase.h:40
SemaM68k(Sema &S)
Definition: SemaM68k.cpp:21
void handleInterruptAttr(Decl *D, const ParsedAttr &AL)
Definition: SemaM68k.cpp:23
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:535
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:326
The JSON file list parser is used to communicate input to InstallAPI.
@ AANT_ArgumentIntegerConstant
Definition: ParsedAttr.h:1081