~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/Target/X86/AsmParser/X86AsmLexer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===-- X86AsmLexer.cpp - Tokenize X86 assembly to AsmTokens --------------===//
 
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
#include "llvm/ADT/SmallVector.h"
 
11
#include "llvm/ADT/StringExtras.h"
 
12
#include "llvm/Target/TargetAsmLexer.h"
 
13
#include "llvm/Target/TargetRegistry.h"
 
14
#include "llvm/MC/MCAsmInfo.h"
 
15
#include "llvm/MC/MCParser/MCAsmLexer.h"
 
16
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
 
17
#include "X86.h"
 
18
 
 
19
using namespace llvm;
 
20
 
 
21
namespace {
 
22
  
 
23
class X86AsmLexer : public TargetAsmLexer {
 
24
  const MCAsmInfo &AsmInfo;
 
25
  
 
26
  bool tentativeIsValid;
 
27
  AsmToken tentativeToken;
 
28
  
 
29
  const AsmToken &lexTentative() {
 
30
    tentativeToken = getLexer()->Lex();
 
31
    tentativeIsValid = true;
 
32
    return tentativeToken;
 
33
  }
 
34
  
 
35
  const AsmToken &lexDefinite() {
 
36
    if(tentativeIsValid) {
 
37
      tentativeIsValid = false;
 
38
      return tentativeToken;
 
39
    }
 
40
    else {
 
41
      return getLexer()->Lex();
 
42
    }
 
43
  }
 
44
  
 
45
  AsmToken LexTokenATT();
 
46
  AsmToken LexTokenIntel();
 
47
protected:
 
48
  AsmToken LexToken() {
 
49
    if (!Lexer) {
 
50
      SetError(SMLoc(), "No MCAsmLexer installed");
 
51
      return AsmToken(AsmToken::Error, "", 0);
 
52
    }
 
53
    
 
54
    switch (AsmInfo.getAssemblerDialect()) {
 
55
    default:
 
56
      SetError(SMLoc(), "Unhandled dialect");
 
57
      return AsmToken(AsmToken::Error, "", 0);
 
58
    case 0:
 
59
      return LexTokenATT();
 
60
    case 1:
 
61
      return LexTokenIntel();
 
62
    }
 
63
  }
 
64
public:
 
65
  X86AsmLexer(const Target &T, const MCAsmInfo &MAI)
 
66
    : TargetAsmLexer(T), AsmInfo(MAI), tentativeIsValid(false) {
 
67
  }
 
68
};
 
69
 
 
70
}
 
71
 
 
72
static unsigned MatchRegisterName(StringRef Name);
 
73
 
 
74
AsmToken X86AsmLexer::LexTokenATT() {
 
75
  const AsmToken lexedToken = lexDefinite();
 
76
  
 
77
  switch (lexedToken.getKind()) {
 
78
  default:
 
79
    return AsmToken(lexedToken);
 
80
  case AsmToken::Error:
 
81
    SetError(Lexer->getErrLoc(), Lexer->getErr());
 
82
    return AsmToken(lexedToken);
 
83
  case AsmToken::Percent:
 
84
  {
 
85
    const AsmToken &nextToken = lexTentative();
 
86
    if (nextToken.getKind() == AsmToken::Identifier) {
 
87
      unsigned regID = MatchRegisterName(nextToken.getString());
 
88
      
 
89
      if (regID) {
 
90
        lexDefinite();
 
91
        
 
92
        StringRef regStr(lexedToken.getString().data(),
 
93
                         lexedToken.getString().size() + 
 
94
                         nextToken.getString().size());
 
95
        
 
96
        return AsmToken(AsmToken::Register, 
 
97
                        regStr, 
 
98
                        static_cast<int64_t>(regID));
 
99
      }
 
100
      else {
 
101
        return AsmToken(lexedToken);
 
102
      }
 
103
    }
 
104
    else {
 
105
      return AsmToken(lexedToken);
 
106
    }
 
107
  }    
 
108
  }
 
109
}
 
110
 
 
111
AsmToken X86AsmLexer::LexTokenIntel() {
 
112
  const AsmToken &lexedToken = lexDefinite();
 
113
  
 
114
  switch(lexedToken.getKind()) {
 
115
  default:
 
116
    return AsmToken(lexedToken);
 
117
  case AsmToken::Error:
 
118
    SetError(Lexer->getErrLoc(), Lexer->getErr());
 
119
    return AsmToken(lexedToken);
 
120
  case AsmToken::Identifier:
 
121
  {
 
122
    std::string upperCase = lexedToken.getString().str();
 
123
    std::string lowerCase = LowercaseString(upperCase);
 
124
    StringRef lowerRef(lowerCase);
 
125
    
 
126
    unsigned regID = MatchRegisterName(lowerRef);
 
127
    
 
128
    if (regID) {
 
129
      return AsmToken(AsmToken::Register,
 
130
                      lexedToken.getString(),
 
131
                      static_cast<int64_t>(regID));
 
132
    }
 
133
    else {
 
134
      return AsmToken(lexedToken);
 
135
    }
 
136
  }
 
137
  }
 
138
}
 
139
 
 
140
extern "C" void LLVMInitializeX86AsmLexer() {
 
141
  RegisterAsmLexer<X86AsmLexer> X(TheX86_32Target);
 
142
  RegisterAsmLexer<X86AsmLexer> Y(TheX86_64Target);
 
143
}
 
144
 
 
145
#define REGISTERS_ONLY
 
146
#include "X86GenAsmMatcher.inc"
 
147
#undef REGISTERS_ONLY