1*6b755b0cSVlad Serebrennikov //===------ SemaM68k.cpp -------- M68k target-specific routines -----------===// 2*6b755b0cSVlad Serebrennikov // 3*6b755b0cSVlad Serebrennikov // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*6b755b0cSVlad Serebrennikov // See https://llvm.org/LICENSE.txt for license information. 5*6b755b0cSVlad Serebrennikov // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*6b755b0cSVlad Serebrennikov // 7*6b755b0cSVlad Serebrennikov //===----------------------------------------------------------------------===// 8*6b755b0cSVlad Serebrennikov // 9*6b755b0cSVlad Serebrennikov // This file implements semantic analysis functions specific to M68k. 10*6b755b0cSVlad Serebrennikov // 11*6b755b0cSVlad Serebrennikov //===----------------------------------------------------------------------===// 12*6b755b0cSVlad Serebrennikov 13*6b755b0cSVlad Serebrennikov #include "clang/Sema/SemaM68k.h" 14*6b755b0cSVlad Serebrennikov #include "clang/AST/ASTContext.h" 15*6b755b0cSVlad Serebrennikov #include "clang/AST/Attr.h" 16*6b755b0cSVlad Serebrennikov #include "clang/AST/DeclBase.h" 17*6b755b0cSVlad Serebrennikov #include "clang/Basic/DiagnosticSema.h" 18*6b755b0cSVlad Serebrennikov #include "clang/Sema/ParsedAttr.h" 19*6b755b0cSVlad Serebrennikov 20*6b755b0cSVlad Serebrennikov namespace clang { SemaM68k(Sema & S)21*6b755b0cSVlad SerebrennikovSemaM68k::SemaM68k(Sema &S) : SemaBase(S) {} 22*6b755b0cSVlad Serebrennikov handleInterruptAttr(Decl * D,const ParsedAttr & AL)23*6b755b0cSVlad Serebrennikovvoid SemaM68k::handleInterruptAttr(Decl *D, const ParsedAttr &AL) { 24*6b755b0cSVlad Serebrennikov if (!AL.checkExactlyNumArgs(SemaRef, 1)) 25*6b755b0cSVlad Serebrennikov return; 26*6b755b0cSVlad Serebrennikov 27*6b755b0cSVlad Serebrennikov if (!AL.isArgExpr(0)) { 28*6b755b0cSVlad Serebrennikov Diag(AL.getLoc(), diag::err_attribute_argument_type) 29*6b755b0cSVlad Serebrennikov << AL << AANT_ArgumentIntegerConstant; 30*6b755b0cSVlad Serebrennikov return; 31*6b755b0cSVlad Serebrennikov } 32*6b755b0cSVlad Serebrennikov 33*6b755b0cSVlad Serebrennikov // FIXME: Check for decl - it should be void ()(void). 34*6b755b0cSVlad Serebrennikov 35*6b755b0cSVlad Serebrennikov Expr *NumParamsExpr = static_cast<Expr *>(AL.getArgAsExpr(0)); 36*6b755b0cSVlad Serebrennikov auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(getASTContext()); 37*6b755b0cSVlad Serebrennikov if (!MaybeNumParams) { 38*6b755b0cSVlad Serebrennikov Diag(AL.getLoc(), diag::err_attribute_argument_type) 39*6b755b0cSVlad Serebrennikov << AL << AANT_ArgumentIntegerConstant 40*6b755b0cSVlad Serebrennikov << NumParamsExpr->getSourceRange(); 41*6b755b0cSVlad Serebrennikov return; 42*6b755b0cSVlad Serebrennikov } 43*6b755b0cSVlad Serebrennikov 44*6b755b0cSVlad Serebrennikov unsigned Num = MaybeNumParams->getLimitedValue(255); 45*6b755b0cSVlad Serebrennikov if ((Num & 1) || Num > 30) { 46*6b755b0cSVlad Serebrennikov Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds) 47*6b755b0cSVlad Serebrennikov << AL << (int)MaybeNumParams->getSExtValue() 48*6b755b0cSVlad Serebrennikov << NumParamsExpr->getSourceRange(); 49*6b755b0cSVlad Serebrennikov return; 50*6b755b0cSVlad Serebrennikov } 51*6b755b0cSVlad Serebrennikov 52*6b755b0cSVlad Serebrennikov D->addAttr(::new (getASTContext()) 53*6b755b0cSVlad Serebrennikov M68kInterruptAttr(getASTContext(), AL, Num)); 54*6b755b0cSVlad Serebrennikov D->addAttr(UsedAttr::CreateImplicit(getASTContext())); 55*6b755b0cSVlad Serebrennikov } 56*6b755b0cSVlad Serebrennikov } // namespace clang 57