Debian Codegraph @

clang/lib/Sema/SemaM68k.cpp

raw
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"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Attr.h"
16 #include "clang/AST/DeclBase.h"
17 #include "clang/Basic/DiagnosticSema.h"
18 #include "clang/Sema/ParsedAttr.h"
19
20 namespace clang {
21 SemaM68k::SemaM68k(Sema &S) : SemaBase(S) {}
22
23 void SemaM68k::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
24 if (!AL.checkExactlyNumArgs(SemaRef, 1))
25 return;
26
27 if (!AL.isArgExpr(0)) {
28 Diag(AL.getLoc(), diag::err_attribute_argument_type)
29 << AL << AANT_ArgumentIntegerConstant;
30 return;
31 }
32
33 // FIXME: Check for decl - it should be void ()(void).
34
35 Expr *NumParamsExpr = AL.getArgAsExpr(0);
36 auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(getASTContext());
37 if (!MaybeNumParams) {
38 Diag(AL.getLoc(), diag::err_attribute_argument_type)
39 << AL << AANT_ArgumentIntegerConstant
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