1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
//===-- ParserInternals.h - Definitions internal to the parser --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by Reid Spencer and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This header file defines the variables that are shared between the lexer,
// the parser, and the main program.
//
//===----------------------------------------------------------------------===//
#ifndef PARSER_INTERNALS_H
#define PARSER_INTERNALS_H
#include <string>
#include <istream>
#include <vector>
// Global variables exported from the lexer...
extern std::string CurFileName;
extern std::string Textin;
extern int Upgradelineno;
extern std::istream* LexInput;
void UpgradeAssembly(
const std::string & infile, std::istream& in, std::ostream &out, bool debug);
// Globals exported by the parser...
extern char* Upgradetext;
extern int Upgradeleng;
extern unsigned SizeOfPointer;
int yyerror(const char *ErrorMsg) ;
/// This enum is used to keep track of the original (1.9) type used to form
/// a type. These are needed for type upgrades and to determine how to upgrade
/// signed instructions with signless operands.
enum Types {
BoolTy, SByteTy, UByteTy, ShortTy, UShortTy, IntTy, UIntTy, LongTy, ULongTy,
FloatTy, DoubleTy, PointerTy, PackedTy, ArrayTy, StructTy, OpaqueTy, VoidTy,
LabelTy, FunctionTy, UnresolvedTy, NumericTy
};
/// This type is used to keep track of the signedness of the obsolete
/// integer types. Instead of creating an llvm::Type directly, the Lexer will
/// create instances of TypeInfo which retains the signedness indication so
/// it can be used by the parser for upgrade decisions.
/// For example if "uint" is encountered then the "first" field will be set
/// to "int32" and the "second" field will be set to "isUnsigned". If the
/// type is not obsolete then "second" will be set to "isSignless".
struct TypeInfo {
std::string* newTy;
Types oldTy;
Types elemTy;
void destroy() const { delete newTy; }
TypeInfo clone() const {
TypeInfo result = *this;
result.newTy = new std::string(*newTy);
return result;
}
Types getElementType() const { return elemTy; }
bool isSigned() const {
return oldTy == SByteTy || oldTy == ShortTy ||
oldTy == IntTy || oldTy == LongTy;
}
bool isUnsigned() const {
return oldTy == UByteTy || oldTy == UShortTy ||
oldTy == UIntTy || oldTy == ULongTy;
}
bool isBool() const {
return oldTy == BoolTy;
}
bool isSignless() const { return !isSigned() && !isUnsigned(); }
bool isInteger() const { return isSigned() || isUnsigned(); }
bool isIntegral() const { return oldTy == BoolTy || isInteger(); }
bool isFloatingPoint() const { return oldTy == DoubleTy || oldTy == FloatTy; }
bool isPacked() const { return oldTy == PackedTy; }
bool isPointer() const { return oldTy == PointerTy; }
bool isOther() const {
return !isPacked() && !isPointer() && !isFloatingPoint() && !isIntegral(); }
unsigned getBitWidth() const {
switch (oldTy) {
case LabelTy:
case VoidTy : return 0;
case BoolTy : return 1;
case SByteTy: case UByteTy : return 8;
case ShortTy: case UShortTy : return 16;
case IntTy: case UIntTy: case FloatTy: return 32;
case LongTy: case ULongTy: case DoubleTy : return 64;
case PointerTy: return SizeOfPointer; // global var
default:
return 128; /// Struct/Packed/Array --> doesn't matter
}
}
};
/// This type is used to keep track of the signedness of values. Instead
/// of creating llvm::Value directly, the parser will create ValueInfo which
/// associates a Value* with a Signedness indication.
struct ValueInfo {
std::string* val;
TypeInfo type;
bool constant;
bool isConstant() const { return constant; }
void destroy() { delete val; type.destroy(); }
};
/// This type is used to keep track of the signedness of constants.
struct ConstInfo {
std::string *cnst;
TypeInfo type;
void destroy() { delete cnst; type.destroy(); }
};
typedef std::vector<ValueInfo> ValueList;
#endif
|