1 //===-- ParserInternals.h - Definitions internal to the parser --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header file defines the variables that are shared between the lexer,
11 // the parser, and the main program.
13 //===----------------------------------------------------------------------===//
15 #ifndef PARSER_INTERNALS_H
16 #define PARSER_INTERNALS_H
21 // Global variables exported from the lexer...
23 extern std::string CurFileName;
24 extern std::string Textin;
25 extern int Upgradelineno;
26 extern std::istream* LexInput;
30 const std::string & infile, std::istream& in, std::ostream &out, bool debug);
32 // Globals exported by the parser...
33 extern char* Upgradetext;
34 extern int Upgradeleng;
35 extern unsigned SizeOfPointer;
37 int yyerror(const char *ErrorMsg) ;
39 /// This enum is used to keep track of the original (1.9) type used to form
40 /// a type. These are needed for type upgrades and to determine how to upgrade
41 /// signed instructions with signless operands.
43 BoolTy, SByteTy, UByteTy, ShortTy, UShortTy, IntTy, UIntTy, LongTy, ULongTy,
44 FloatTy, DoubleTy, PointerTy, PackedTy, ArrayTy, StructTy, OpaqueTy, VoidTy,
48 /// This type is used to keep track of the signedness of the obsolete
49 /// integer types. Instead of creating an llvm::Type directly, the Lexer will
50 /// create instances of TypeInfo which retains the signedness indication so
51 /// it can be used by the parser for upgrade decisions.
52 /// For example if "uint" is encountered then the "first" field will be set
53 /// to "int32" and the "second" field will be set to "isUnsigned". If the
54 /// type is not obsolete then "second" will be set to "isSignless".
59 void destroy() { delete newTy; }
62 return oldTy == SByteTy || oldTy == ShortTy ||
63 oldTy == IntTy || oldTy == LongTy;
67 return oldTy == UByteTy || oldTy == UShortTy ||
68 oldTy == UIntTy || oldTy == ULongTy;
71 bool isSignless() { return !isSigned() && !isUnsigned(); }
72 bool isInteger() { return isSigned() || isUnsigned(); }
73 bool isIntegral() { return oldTy == BoolTy || isInteger(); }
74 bool isFloatingPoint() { return oldTy == DoubleTy || oldTy == FloatTy; }
75 bool isPacked() { return oldTy == PackedTy; }
76 bool isPointer() { return oldTy == PointerTy; }
77 bool isOther() { return !isPacked() && !isPointer() && !isFloatingPoint()
80 unsigned getBitWidth() {
83 case VoidTy : return 0;
84 case BoolTy : return 1;
85 case SByteTy: case UByteTy : return 8;
86 case ShortTy: case UShortTy : return 16;
87 case IntTy: case UIntTy: case FloatTy: return 32;
88 case LongTy: case ULongTy: case DoubleTy : return 64;
89 case PointerTy: return SizeOfPointer; // global var
91 return 128; /// Struct/Packed/Array --> doesn't matter
97 /// This type is used to keep track of the signedness of values. Instead
98 /// of creating llvm::Value directly, the parser will create ValueInfo which
99 /// associates a Value* with a Signedness indication.
103 void destroy() { delete val; type.destroy(); }
106 /// This type is used to keep track of the signedness of constants.
110 void destroy() { delete cnst; type.destroy(); }