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