 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
20.0% |
6 / 30 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
20.0% |
6 / 30 |
| |
|
Line Coverage: |
29.0% |
9 / 31 |
| |
 |
|
 |
1 : //===-- TargetAttributesSema.cpp - Encapsulate target attributes-*- C++ -*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : // This file contains semantic analysis implementation for target-specific
11 : // attributes.
12 : //
13 : //===----------------------------------------------------------------------===//
14 :
15 : #include "Sema.h"
16 : #include "TargetAttributesSema.h"
17 : #include "clang/Basic/TargetInfo.h"
18 : #include "llvm/ADT/Triple.h"
19 :
20 : using namespace clang;
21 :
1: branch 0 taken
0: branch 1 not taken
1: branch 3 taken
1: branch 4 taken
0: branch 6 not taken
0: branch 7 not taken
22 1: TargetAttributesSema::~TargetAttributesSema() {}
23 : bool TargetAttributesSema::ProcessDeclAttribute(Scope *scope, Decl *D,
24 2: const AttributeList &Attr, Sema &S) const {
25 2: return false;
26 : }
27 :
28 : static void HandleMSP430InterruptAttr(Decl *d,
29 0: const AttributeList &Attr, Sema &S) {
30 : // Check the attribute arguments.
0: branch 1 not taken
0: branch 2 not taken
31 0: if (Attr.getNumArgs() != 1) {
32 0: S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
33 0: return;
34 : }
35 :
36 : // FIXME: Check for decl - it should be void ()(void).
37 :
38 0: Expr *NumParamsExpr = static_cast<Expr *>(Attr.getArg(0));
39 0: llvm::APSInt NumParams(32);
0: branch 1 not taken
0: branch 2 not taken
40 0: if (!NumParamsExpr->isIntegerConstantExpr(NumParams, S.Context)) {
41 : S.Diag(Attr.getLoc(), diag::err_attribute_argument_not_int)
42 0: << "interrupt" << NumParamsExpr->getSourceRange();
43 0: return;
44 : }
45 :
46 0: unsigned Num = NumParams.getLimitedValue(255);
0: branch 0 not taken
0: branch 1 not taken
0: branch 2 not taken
0: branch 3 not taken
47 0: if ((Num & 1) || Num > 30) {
48 : S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds)
49 : << "interrupt" << (int)NumParams.getSExtValue()
50 0: << NumParamsExpr->getSourceRange();
51 : return;
52 : }
53 :
0: branch 1 not taken
0: branch 2 not taken
54 0: d->addAttr(::new (S.Context) MSP430InterruptAttr(Num));
0: branch 1 not taken
0: branch 2 not taken
0: branch 6 not taken
0: branch 7 not taken
55 0: d->addAttr(::new (S.Context) UsedAttr());
56 : }
57 :
58 : namespace {
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
59 0: class MSP430AttributesSema : public TargetAttributesSema {
60 : public:
61 0: MSP430AttributesSema() { }
62 : bool ProcessDeclAttribute(Scope *scope, Decl *D,
63 0: const AttributeList &Attr, Sema &S) const {
0: branch 4 not taken
0: branch 5 not taken
64 0: if (Attr.getName()->getName() == "interrupt") {
65 0: HandleMSP430InterruptAttr(D, Attr, S);
66 0: return true;
67 : }
68 0: return false;
69 : }
70 : };
71 : }
72 :
73 2: const TargetAttributesSema &Sema::getTargetAttributesSema() const {
1: branch 0 taken
1: branch 1 taken
74 2: if (TheTargetAttributesSema)
75 1: return *TheTargetAttributesSema;
76 :
77 1: const llvm::Triple &Triple(Context.Target.getTriple());
1: branch 1 taken
0: branch 2 not taken
78 1: switch (Triple.getArch()) {
79 : default:
80 1: return *(TheTargetAttributesSema = new TargetAttributesSema);
81 :
82 : case llvm::Triple::msp430:
83 0: return *(TheTargetAttributesSema = new MSP430AttributesSema);
84 : }
85 : }
86 :
Generated: 2010-02-10 01:31 by zcov