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 | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 20 | |
| 21 | // Global variables exported from the lexer... |
| 22 | |
| 23 | extern std::string CurFileName; |
| 24 | extern std::string Textin; |
| 25 | extern int Upgradelineno; |
Reid Spencer | 96839be | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 26 | extern std::istream* LexInput; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 27 | |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 28 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 29 | void UpgradeAssembly( |
| 30 | const std::string & infile, std::istream& in, std::ostream &out, bool debug); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 31 | |
| 32 | // Globals exported by the parser... |
| 33 | extern char* Upgradetext; |
| 34 | extern int Upgradeleng; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 35 | extern unsigned SizeOfPointer; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 36 | |
| 37 | int yyerror(const char *ErrorMsg) ; |
| 38 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 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. |
| 42 | enum Types { |
| 43 | BoolTy, SByteTy, UByteTy, ShortTy, UShortTy, IntTy, UIntTy, LongTy, ULongTy, |
| 44 | FloatTy, DoubleTy, PointerTy, PackedTy, ArrayTy, StructTy, OpaqueTy, VoidTy, |
| 45 | LabelTy, FunctionTy |
| 46 | }; |
| 47 | |
| 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". |
| 55 | struct TypeInfo { |
| 56 | std::string* newTy; |
| 57 | Types oldTy; |
| 58 | |
| 59 | void destroy() { delete newTy; } |
| 60 | |
| 61 | bool isSigned() { |
| 62 | return oldTy == SByteTy || oldTy == ShortTy || |
| 63 | oldTy == IntTy || oldTy == LongTy; |
| 64 | } |
| 65 | |
| 66 | bool isUnsigned() { |
| 67 | return oldTy == UByteTy || oldTy == UShortTy || |
| 68 | oldTy == UIntTy || oldTy == ULongTy; |
| 69 | } |
| 70 | |
| 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() |
| 78 | && !isIntegral(); } |
| 79 | |
| 80 | unsigned getBitWidth() { |
| 81 | switch (oldTy) { |
| 82 | case LabelTy: |
| 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 |
| 90 | default: |
| 91 | return 128; /// Struct/Packed/Array --> doesn't matter |
| 92 | |
| 93 | } |
| 94 | } |
| 95 | }; |
| 96 | |
| 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. |
| 100 | struct ValueInfo { |
| 101 | std::string* val; |
| 102 | TypeInfo type; |
| 103 | void destroy() { delete val; type.destroy(); } |
| 104 | }; |
| 105 | |
| 106 | /// This type is used to keep track of the signedness of constants. |
| 107 | struct ConstInfo { |
| 108 | std::string *cnst; |
| 109 | TypeInfo type; |
| 110 | void destroy() { delete cnst; type.destroy(); } |
| 111 | }; |
| 112 | |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 113 | #endif |