blob: faa66c232572c3e41df48633cbe2b94c27c02f9b [file] [log] [blame]
Reid Spencere7c3c602006-11-30 06:36:44 +00001//===-- 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 Spencer96839be2006-11-30 16:50:26 +000019#include <istream>
Reid Spencere7c3c602006-11-30 06:36:44 +000020
21// Global variables exported from the lexer...
22
23extern std::string CurFileName;
24extern std::string Textin;
25extern int Upgradelineno;
Reid Spencer96839be2006-11-30 16:50:26 +000026extern std::istream* LexInput;
Reid Spencere7c3c602006-11-30 06:36:44 +000027
Reid Spencere7c3c602006-11-30 06:36:44 +000028
Reid Spencere77e35e2006-12-01 20:26:20 +000029void UpgradeAssembly(
30 const std::string & infile, std::istream& in, std::ostream &out, bool debug);
Reid Spencere7c3c602006-11-30 06:36:44 +000031
32// Globals exported by the parser...
33extern char* Upgradetext;
34extern int Upgradeleng;
Reid Spencere77e35e2006-12-01 20:26:20 +000035extern unsigned SizeOfPointer;
Reid Spencere7c3c602006-11-30 06:36:44 +000036
37int yyerror(const char *ErrorMsg) ;
38
Reid Spencere77e35e2006-12-01 20:26:20 +000039/// 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.
42enum 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".
55struct 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.
100struct 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.
107struct ConstInfo {
108 std::string *cnst;
109 TypeInfo type;
110 void destroy() { delete cnst; type.destroy(); }
111};
112
Reid Spencere7c3c602006-11-30 06:36:44 +0000113#endif