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
20namespace clang {
21SemaM68k::SemaM68k(Sema &S) : SemaBase(S) {}
22
23void SemaM68k::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
24 if (!AL.checkExactlyNumArgs(S&: SemaRef, Num: 1))
25 return;
26
27 if (!AL.isArgExpr(Arg: 0)) {
28 Diag(Loc: AL.getLoc(), DiagID: 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 = static_cast<Expr *>(AL.getArgAsExpr(Arg: 0));
36 auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(Ctx: getASTContext());
37 if (!MaybeNumParams) {
38 Diag(Loc: AL.getLoc(), DiagID: diag::err_attribute_argument_type)
39 << AL << AANT_ArgumentIntegerConstant
40 << NumParamsExpr->getSourceRange();
41 return;
42 }
43
44 unsigned Num = MaybeNumParams->getLimitedValue(Limit: 255);
45 if ((Num & 1) || Num > 30) {
46 Diag(Loc: AL.getLoc(), DiagID: diag::err_attribute_argument_out_of_bounds)
47 << AL << (int)MaybeNumParams->getSExtValue()
48 << NumParamsExpr->getSourceRange();
49 return;
50 }
51
52 D->addAttr(A: ::new (getASTContext())
53 M68kInterruptAttr(getASTContext(), AL, Num));
54 D->addAttr(A: UsedAttr::CreateImplicit(Ctx&: getASTContext()));
55}
56} // namespace clang
57