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