blob: df9d2a80f3761d1001ad16b0dd1bdcb681c405ce [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(
31 const std::string & infile, std::istream& in, std::ostream &out, bool debug);
Reid Spencere7c3c602006-11-30 06:36:44 +000032
33// Globals exported by the parser...
34extern char* Upgradetext;
35extern int Upgradeleng;
Reid Spencere77e35e2006-12-01 20:26:20 +000036extern unsigned SizeOfPointer;
Reid Spencere7c3c602006-11-30 06:36:44 +000037
38int yyerror(const char *ErrorMsg) ;
39
Reid Spencere77e35e2006-12-01 20:26:20 +000040/// 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.
43enum Types {
44 BoolTy, SByteTy, UByteTy, ShortTy, UShortTy, IntTy, UIntTy, LongTy, ULongTy,
45 FloatTy, DoubleTy, PointerTy, PackedTy, ArrayTy, StructTy, OpaqueTy, VoidTy,
Reid Spencera50d5962006-12-02 04:11:07 +000046 LabelTy, FunctionTy, UnresolvedTy, NumericTy
Reid Spencere77e35e2006-12-01 20:26:20 +000047};
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".
56struct TypeInfo {
57 std::string* newTy;
58 Types oldTy;
Reid Spencera8ca0902006-12-02 20:19:56 +000059 Types elemTy;
Reid Spencere77e35e2006-12-01 20:26:20 +000060
Reid Spencera50d5962006-12-02 04:11:07 +000061 void destroy() const { delete newTy; }
Reid Spencere77e35e2006-12-01 20:26:20 +000062
Reid Spencera8ca0902006-12-02 20:19:56 +000063 Types getElementType() const { return elemTy; }
64
Reid Spencera50d5962006-12-02 04:11:07 +000065 bool isSigned() const {
Reid Spencere77e35e2006-12-01 20:26:20 +000066 return oldTy == SByteTy || oldTy == ShortTy ||
67 oldTy == IntTy || oldTy == LongTy;
68 }
69
Reid Spencera50d5962006-12-02 04:11:07 +000070 bool isUnsigned() const {
Reid Spencere77e35e2006-12-01 20:26:20 +000071 return oldTy == UByteTy || oldTy == UShortTy ||
72 oldTy == UIntTy || oldTy == ULongTy;
73 }
74
Reid Spencera50d5962006-12-02 04:11:07 +000075 bool isSignless() const { return !isSigned() && !isUnsigned(); }
76 bool isInteger() const { return isSigned() || isUnsigned(); }
77 bool isIntegral() const { return oldTy == BoolTy || isInteger(); }
78 bool isFloatingPoint() const { return oldTy == DoubleTy || oldTy == FloatTy; }
79 bool isPacked() const { return oldTy == PackedTy; }
80 bool isPointer() const { return oldTy == PointerTy; }
81 bool isOther() const {
82 return !isPacked() && !isPointer() && !isFloatingPoint() && !isIntegral(); }
Reid Spencere77e35e2006-12-01 20:26:20 +000083
Reid Spencera50d5962006-12-02 04:11:07 +000084 unsigned getBitWidth() const {
Reid Spencere77e35e2006-12-01 20:26:20 +000085 switch (oldTy) {
86 case LabelTy:
87 case VoidTy : return 0;
88 case BoolTy : return 1;
89 case SByteTy: case UByteTy : return 8;
90 case ShortTy: case UShortTy : return 16;
91 case IntTy: case UIntTy: case FloatTy: return 32;
92 case LongTy: case ULongTy: case DoubleTy : return 64;
93 case PointerTy: return SizeOfPointer; // global var
94 default:
95 return 128; /// Struct/Packed/Array --> doesn't matter
96
97 }
98 }
99};
100
101/// This type is used to keep track of the signedness of values. Instead
102/// of creating llvm::Value directly, the parser will create ValueInfo which
103/// associates a Value* with a Signedness indication.
104struct ValueInfo {
105 std::string* val;
106 TypeInfo type;
Reid Spencer1d64a6c2006-12-02 16:19:28 +0000107 bool constant;
108 bool isConstant() const { return constant; }
Reid Spencere77e35e2006-12-01 20:26:20 +0000109 void destroy() { delete val; type.destroy(); }
110};
111
112/// This type is used to keep track of the signedness of constants.
113struct ConstInfo {
114 std::string *cnst;
115 TypeInfo type;
116 void destroy() { delete cnst; type.destroy(); }
117};
118
Reid Spencerf8483652006-12-02 15:16:01 +0000119typedef std::vector<ValueInfo> ValueList;
120
121
Reid Spencere7c3c602006-11-30 06:36:44 +0000122#endif