blob: 85182c5dc192350e855d236b91dc5cdb67825627 [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 Spencerf8483652006-12-02 15:16:01 +000020#include <vector>
Reid Spencere7c3c602006-11-30 06:36:44 +000021
22// Global variables exported from the lexer...
23
24extern std::string CurFileName;
25extern std::string Textin;
26extern int Upgradelineno;
Reid Spencer96839be2006-11-30 16:50:26 +000027extern std::istream* LexInput;
Reid Spencere7c3c602006-11-30 06:36:44 +000028
Reid Spencere7c3c602006-11-30 06:36:44 +000029
Reid Spencere77e35e2006-12-01 20:26:20 +000030void UpgradeAssembly(
Reid Spencer71d2ec92006-12-31 06:02:26 +000031 const std::string & infile, std::istream& in, std::ostream &out, bool debug,
32 bool addAttrs);
Reid Spencere7c3c602006-11-30 06:36:44 +000033
34// Globals exported by the parser...
35extern char* Upgradetext;
36extern int Upgradeleng;
Reid Spencere77e35e2006-12-01 20:26:20 +000037extern unsigned SizeOfPointer;
Reid Spencere7c3c602006-11-30 06:36:44 +000038
39int yyerror(const char *ErrorMsg) ;
40
Reid Spencere77e35e2006-12-01 20:26:20 +000041/// 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.
44enum Types {
45 BoolTy, SByteTy, UByteTy, ShortTy, UShortTy, IntTy, UIntTy, LongTy, ULongTy,
Reid Spencer71d2ec92006-12-31 06:02:26 +000046 FloatTy, DoubleTy, PointerTy, PackedTy, ArrayTy, StructTy, PackedStructTy,
47 OpaqueTy, VoidTy, LabelTy, FunctionTy, UnresolvedTy, NumericTy
Reid Spencere77e35e2006-12-01 20:26:20 +000048};
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".
57struct TypeInfo {
58 std::string* newTy;
59 Types oldTy;
Reid Spencera8ca0902006-12-02 20:19:56 +000060 Types elemTy;
Reid Spencere77e35e2006-12-01 20:26:20 +000061
Reid Spencera50d5962006-12-02 04:11:07 +000062 void destroy() const { delete newTy; }
Reid Spencere77e35e2006-12-01 20:26:20 +000063
Reid Spencer999b2df2006-12-05 19:18:29 +000064 TypeInfo clone() const {
65 TypeInfo result = *this;
66 result.newTy = new std::string(*newTy);
67 return result;
68 }
69
Reid Spencera8ca0902006-12-02 20:19:56 +000070 Types getElementType() const { return elemTy; }
71
Reid Spencera50d5962006-12-02 04:11:07 +000072 bool isSigned() const {
Reid Spencere77e35e2006-12-01 20:26:20 +000073 return oldTy == SByteTy || oldTy == ShortTy ||
74 oldTy == IntTy || oldTy == LongTy;
75 }
76
Reid Spencera50d5962006-12-02 04:11:07 +000077 bool isUnsigned() const {
Reid Spencere77e35e2006-12-01 20:26:20 +000078 return oldTy == UByteTy || oldTy == UShortTy ||
79 oldTy == UIntTy || oldTy == ULongTy;
80 }
81
Reid Spencer49aeed72006-12-06 06:25:22 +000082 bool isBool() const {
83 return oldTy == BoolTy;
84 }
85
Reid Spencera50d5962006-12-02 04:11:07 +000086 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 Spencere77e35e2006-12-01 20:26:20 +000094
Reid Spencer71d2ec92006-12-31 06:02:26 +000095 bool isAttributeCandidate() const {
96 return isIntegral() && getBitWidth() < 32;
97 }
98
Reid Spencera50d5962006-12-02 04:11:07 +000099 unsigned getBitWidth() const {
Reid Spencere77e35e2006-12-01 20:26:20 +0000100 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.
119struct ValueInfo {
120 std::string* val;
121 TypeInfo type;
Reid Spencer1d64a6c2006-12-02 16:19:28 +0000122 bool constant;
123 bool isConstant() const { return constant; }
Reid Spencere77e35e2006-12-01 20:26:20 +0000124 void destroy() { delete val; type.destroy(); }
125};
126
127/// This type is used to keep track of the signedness of constants.
128struct ConstInfo {
129 std::string *cnst;
130 TypeInfo type;
131 void destroy() { delete cnst; type.destroy(); }
132};
133
Reid Spencerf8483652006-12-02 15:16:01 +0000134typedef std::vector<ValueInfo> ValueList;
135
136
Reid Spencere7c3c602006-11-30 06:36:44 +0000137#endif