Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1 | //===- Record.h - Classes to represent Table Records ------------*- C++ -*-===// |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | d303203 | 2003-10-20 20:20:30 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 8adcd9f | 2007-12-29 20:37:13 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | d303203 | 2003-10-20 20:20:30 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file defines the main TableGen data structures, including the TableGen |
| 11 | // types, values, and high-level data structures. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef RECORD_H |
| 16 | #define RECORD_H |
| 17 | |
Chris Lattner | 1b30e1ac | 2009-06-21 03:36:54 +0000 | [diff] [blame] | 18 | #include "llvm/Support/SourceMgr.h" |
Chandler Carruth | 56869f2 | 2009-10-26 01:35:46 +0000 | [diff] [blame] | 19 | #include "llvm/System/DataTypes.h" |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 21 | #include <map> |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 22 | |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 23 | namespace llvm { |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 24 | class raw_ostream; |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 25 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 26 | // RecTy subclasses. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 27 | class BitRecTy; |
| 28 | class BitsRecTy; |
| 29 | class IntRecTy; |
| 30 | class StringRecTy; |
| 31 | class ListRecTy; |
| 32 | class CodeRecTy; |
| 33 | class DagRecTy; |
| 34 | class RecordRecTy; |
| 35 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 36 | // Init subclasses. |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 37 | struct Init; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 38 | class UnsetInit; |
| 39 | class BitInit; |
| 40 | class BitsInit; |
| 41 | class IntInit; |
| 42 | class StringInit; |
| 43 | class CodeInit; |
| 44 | class ListInit; |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 45 | class UnOpInit; |
Chris Lattner | 51ffbf1 | 2006-03-31 21:53:49 +0000 | [diff] [blame] | 46 | class BinOpInit; |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 47 | class TernOpInit; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 48 | class DefInit; |
| 49 | class DagInit; |
| 50 | class TypedInit; |
| 51 | class VarInit; |
| 52 | class FieldInit; |
| 53 | class VarBitInit; |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 54 | class VarListElementInit; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 55 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 56 | // Other classes. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 57 | class Record; |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 58 | class RecordVal; |
Bob Wilson | 56d86254 | 2009-04-30 17:35:11 +0000 | [diff] [blame] | 59 | struct MultiClass; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 60 | |
| 61 | //===----------------------------------------------------------------------===// |
| 62 | // Type Classes |
| 63 | //===----------------------------------------------------------------------===// |
| 64 | |
| 65 | struct RecTy { |
| 66 | virtual ~RecTy() {} |
| 67 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 68 | virtual std::string getAsString() const = 0; |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 69 | void print(raw_ostream &OS) const { OS << getAsString(); } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 70 | void dump() const; |
| 71 | |
| 72 | /// typeIsConvertibleTo - Return true if all values of 'this' type can be |
| 73 | /// converted to the specified type. |
| 74 | virtual bool typeIsConvertibleTo(const RecTy *RHS) const = 0; |
| 75 | |
| 76 | public: // These methods should only be called from subclasses of Init |
| 77 | virtual Init *convertValue( UnsetInit *UI) { return 0; } |
| 78 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 79 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 80 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 81 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 82 | virtual Init *convertValue( ListInit *LI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 83 | virtual Init *convertValue( UnOpInit *UI) { |
| 84 | return convertValue((TypedInit*)UI); |
| 85 | } |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 86 | virtual Init *convertValue( BinOpInit *UI) { |
| 87 | return convertValue((TypedInit*)UI); |
| 88 | } |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 89 | virtual Init *convertValue( TernOpInit *UI) { |
| 90 | return convertValue((TypedInit*)UI); |
| 91 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 92 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 93 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 94 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 95 | virtual Init *convertValue( DagInit *DI) { return 0; } |
| 96 | virtual Init *convertValue( TypedInit *TI) { return 0; } |
| 97 | virtual Init *convertValue( VarInit *VI) { |
| 98 | return convertValue((TypedInit*)VI); |
| 99 | } |
| 100 | virtual Init *convertValue( FieldInit *FI) { |
| 101 | return convertValue((TypedInit*)FI); |
| 102 | } |
| 103 | |
| 104 | public: // These methods should only be called by subclasses of RecTy. |
| 105 | // baseClassOf - These virtual methods should be overloaded to return true iff |
| 106 | // all values of type 'RHS' can be converted to the 'this' type. |
| 107 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 108 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 109 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 110 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 111 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 112 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 113 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 114 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
| 115 | }; |
| 116 | |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 117 | inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 118 | Ty.print(OS); |
| 119 | return OS; |
| 120 | } |
| 121 | |
| 122 | |
| 123 | /// BitRecTy - 'bit' - Represent a single bit |
| 124 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 125 | class BitRecTy : public RecTy { |
| 126 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 127 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 128 | virtual Init *convertValue( BitInit *BI) { return (Init*)BI; } |
| 129 | virtual Init *convertValue( BitsInit *BI); |
| 130 | virtual Init *convertValue( IntInit *II); |
| 131 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 132 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 133 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 134 | virtual Init *convertValue(VarBitInit *VB) { return (Init*)VB; } |
| 135 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 136 | virtual Init *convertValue( DagInit *DI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 137 | virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 138 | virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 139 | virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 140 | virtual Init *convertValue( TypedInit *TI); |
| 141 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 142 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 143 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 144 | std::string getAsString() const { return "bit"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 145 | |
| 146 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 147 | return RHS->baseClassOf(this); |
| 148 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 149 | virtual bool baseClassOf(const BitRecTy *RHS) const { return true; } |
| 150 | virtual bool baseClassOf(const BitsRecTy *RHS) const; |
| 151 | virtual bool baseClassOf(const IntRecTy *RHS) const { return true; } |
| 152 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 153 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 154 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 155 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 156 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
| 157 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | |
Misha Brukman | b4f20ea | 2004-04-15 15:30:15 +0000 | [diff] [blame] | 161 | // BitsRecTy - 'bits<n>' - Represent a fixed number of bits |
| 162 | /// BitsRecTy - 'bits<n>' - Represent a fixed number of bits |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 163 | /// |
| 164 | class BitsRecTy : public RecTy { |
| 165 | unsigned Size; |
| 166 | public: |
Dan Gohman | 56e3f63 | 2008-07-07 18:00:37 +0000 | [diff] [blame] | 167 | explicit BitsRecTy(unsigned Sz) : Size(Sz) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 168 | |
| 169 | unsigned getNumBits() const { return Size; } |
| 170 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 171 | virtual Init *convertValue( UnsetInit *UI); |
| 172 | virtual Init *convertValue( BitInit *UI); |
| 173 | virtual Init *convertValue( BitsInit *BI); |
| 174 | virtual Init *convertValue( IntInit *II); |
| 175 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 176 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 177 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 178 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 179 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 180 | virtual Init *convertValue( DagInit *DI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 181 | virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 182 | virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 183 | virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 184 | virtual Init *convertValue( TypedInit *TI); |
| 185 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 186 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
| 187 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 188 | std::string getAsString() const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 189 | |
| 190 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 191 | return RHS->baseClassOf(this); |
| 192 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 193 | virtual bool baseClassOf(const BitRecTy *RHS) const { return Size == 1; } |
| 194 | virtual bool baseClassOf(const BitsRecTy *RHS) const { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 195 | return RHS->Size == Size; |
| 196 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 197 | virtual bool baseClassOf(const IntRecTy *RHS) const { return true; } |
| 198 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 199 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 200 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 201 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 202 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
| 203 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | |
| 207 | /// IntRecTy - 'int' - Represent an integer value of no particular size |
| 208 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 209 | class IntRecTy : public RecTy { |
| 210 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 211 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 212 | virtual Init *convertValue( BitInit *BI); |
| 213 | virtual Init *convertValue( BitsInit *BI); |
| 214 | virtual Init *convertValue( IntInit *II) { return (Init*)II; } |
| 215 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 216 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 217 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 218 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 219 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 220 | virtual Init *convertValue( DagInit *DI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 221 | virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 222 | virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 223 | virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 224 | virtual Init *convertValue( TypedInit *TI); |
| 225 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 226 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
| 227 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 228 | std::string getAsString() const { return "int"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 229 | |
| 230 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 231 | return RHS->baseClassOf(this); |
| 232 | } |
| 233 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 234 | virtual bool baseClassOf(const BitRecTy *RHS) const { return true; } |
| 235 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return true; } |
| 236 | virtual bool baseClassOf(const IntRecTy *RHS) const { return true; } |
| 237 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 238 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 239 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 240 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 241 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
| 242 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 243 | }; |
| 244 | |
| 245 | /// StringRecTy - 'string' - Represent an string value |
| 246 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 247 | class StringRecTy : public RecTy { |
| 248 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 249 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 250 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 251 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 252 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 253 | virtual Init *convertValue(StringInit *SI) { return (Init*)SI; } |
| 254 | virtual Init *convertValue( ListInit *LI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 255 | virtual Init *convertValue( UnOpInit *BO); |
Chris Lattner | 51ffbf1 | 2006-03-31 21:53:49 +0000 | [diff] [blame] | 256 | virtual Init *convertValue( BinOpInit *BO); |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 257 | virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);} |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 258 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 259 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 260 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 261 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 262 | virtual Init *convertValue( DagInit *DI) { return 0; } |
| 263 | virtual Init *convertValue( TypedInit *TI); |
| 264 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 265 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
| 266 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 267 | std::string getAsString() const { return "string"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 268 | |
| 269 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 270 | return RHS->baseClassOf(this); |
| 271 | } |
| 272 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 273 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 274 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 275 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 276 | virtual bool baseClassOf(const StringRecTy *RHS) const { return true; } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 277 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 278 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 279 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 280 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 281 | }; |
| 282 | |
Misha Brukman | b4f20ea | 2004-04-15 15:30:15 +0000 | [diff] [blame] | 283 | // ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of |
| 284 | // the specified type. |
| 285 | /// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must |
| 286 | /// be of the specified type. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 287 | /// |
| 288 | class ListRecTy : public RecTy { |
| 289 | RecTy *Ty; |
| 290 | public: |
Dan Gohman | 56e3f63 | 2008-07-07 18:00:37 +0000 | [diff] [blame] | 291 | explicit ListRecTy(RecTy *T) : Ty(T) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 292 | |
| 293 | RecTy *getElementType() const { return Ty; } |
| 294 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 295 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 296 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 297 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 298 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 299 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 300 | virtual Init *convertValue( ListInit *LI); |
| 301 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 302 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 303 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 304 | virtual Init *convertValue( DagInit *DI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 305 | virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 306 | virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 307 | virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 308 | virtual Init *convertValue( TypedInit *TI); |
| 309 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 310 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 311 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 312 | std::string getAsString() const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 313 | |
| 314 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 315 | return RHS->baseClassOf(this); |
| 316 | } |
| 317 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 318 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 319 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 320 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 321 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 322 | virtual bool baseClassOf(const ListRecTy *RHS) const { |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 323 | return RHS->getElementType()->typeIsConvertibleTo(Ty); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 324 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 325 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 326 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 327 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 328 | }; |
| 329 | |
| 330 | /// CodeRecTy - 'code' - Represent an code fragment, function or method. |
| 331 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 332 | class CodeRecTy : public RecTy { |
| 333 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 334 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 335 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 336 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 337 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 338 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 339 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 340 | virtual Init *convertValue( CodeInit *CI) { return (Init*)CI; } |
| 341 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 342 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 343 | virtual Init *convertValue( DagInit *DI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 344 | virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 345 | virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 346 | virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 347 | virtual Init *convertValue( TypedInit *TI); |
| 348 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 349 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
| 350 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 351 | std::string getAsString() const { return "code"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 352 | |
| 353 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 354 | return RHS->baseClassOf(this); |
| 355 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 356 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 357 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 358 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 359 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 360 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 361 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return true; } |
| 362 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 363 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 364 | }; |
| 365 | |
| 366 | /// DagRecTy - 'dag' - Represent a dag fragment |
| 367 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 368 | class DagRecTy : public RecTy { |
| 369 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 370 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 371 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 372 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 373 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 374 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 375 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 376 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 377 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 378 | virtual Init *convertValue( DefInit *DI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 379 | virtual Init *convertValue( UnOpInit *BO); |
Evan Cheng | a32dee2 | 2007-05-15 01:23:24 +0000 | [diff] [blame] | 380 | virtual Init *convertValue( BinOpInit *BO); |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 381 | virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 382 | virtual Init *convertValue( DagInit *CI) { return (Init*)CI; } |
| 383 | virtual Init *convertValue( TypedInit *TI); |
| 384 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 385 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 386 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 387 | std::string getAsString() const { return "dag"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 388 | |
| 389 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 390 | return RHS->baseClassOf(this); |
| 391 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 392 | |
| 393 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 394 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 395 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 396 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 397 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 398 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 399 | virtual bool baseClassOf(const DagRecTy *RHS) const { return true; } |
| 400 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 401 | }; |
| 402 | |
| 403 | |
Misha Brukman | b4f20ea | 2004-04-15 15:30:15 +0000 | [diff] [blame] | 404 | /// RecordRecTy - '[classname]' - Represent an instance of a class, such as: |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 405 | /// (R32 X = EAX). |
| 406 | /// |
| 407 | class RecordRecTy : public RecTy { |
| 408 | Record *Rec; |
| 409 | public: |
Dan Gohman | 56e3f63 | 2008-07-07 18:00:37 +0000 | [diff] [blame] | 410 | explicit RecordRecTy(Record *R) : Rec(R) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 411 | |
| 412 | Record *getRecord() const { return Rec; } |
| 413 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 414 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 415 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 416 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 417 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 418 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 419 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 420 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 421 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 422 | virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 423 | virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 424 | virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 425 | virtual Init *convertValue( DefInit *DI); |
| 426 | virtual Init *convertValue( DagInit *DI) { return 0; } |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 427 | virtual Init *convertValue( TypedInit *VI); |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 428 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 429 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 430 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 431 | std::string getAsString() const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 432 | |
| 433 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 434 | return RHS->baseClassOf(this); |
| 435 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 436 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 437 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 438 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 439 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 440 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 441 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 442 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 443 | virtual bool baseClassOf(const RecordRecTy *RHS) const; |
| 444 | }; |
| 445 | |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 446 | /// resolveTypes - Find a common type that T1 and T2 convert to. |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 447 | /// Return 0 if no such type exists. |
| 448 | /// |
| 449 | RecTy *resolveTypes(RecTy *T1, RecTy *T2); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 450 | |
| 451 | //===----------------------------------------------------------------------===// |
| 452 | // Initializer Classes |
| 453 | //===----------------------------------------------------------------------===// |
| 454 | |
| 455 | struct Init { |
| 456 | virtual ~Init() {} |
| 457 | |
| 458 | /// isComplete - This virtual method should be overridden by values that may |
| 459 | /// not be completely specified yet. |
| 460 | virtual bool isComplete() const { return true; } |
| 461 | |
| 462 | /// print - Print out this value. |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 463 | void print(raw_ostream &OS) const { OS << getAsString(); } |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 464 | |
| 465 | /// getAsString - Convert this value to a string form. |
| 466 | virtual std::string getAsString() const = 0; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 467 | |
| 468 | /// dump - Debugging method that may be called through a debugger, just |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 469 | /// invokes print on stderr. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 470 | void dump() const; |
| 471 | |
| 472 | /// convertInitializerTo - This virtual function is a simple call-back |
| 473 | /// function that should be overridden to call the appropriate |
| 474 | /// RecTy::convertValue method. |
| 475 | /// |
| 476 | virtual Init *convertInitializerTo(RecTy *Ty) = 0; |
| 477 | |
| 478 | /// convertInitializerBitRange - This method is used to implement the bitrange |
| 479 | /// selection operator. Given an initializer, it selects the specified bits |
| 480 | /// out, returning them as a new init of bits type. If it is not legal to use |
| 481 | /// the bit subscript operator on this initializer, return null. |
| 482 | /// |
| 483 | virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits) { |
| 484 | return 0; |
| 485 | } |
| 486 | |
Chris Lattner | 8bf9e06 | 2004-07-26 23:21:34 +0000 | [diff] [blame] | 487 | /// convertInitListSlice - This method is used to implement the list slice |
| 488 | /// selection operator. Given an initializer, it selects the specified list |
| 489 | /// elements, returning them as a new init of list type. If it is not legal |
| 490 | /// to take a slice of this, return null. |
| 491 | /// |
| 492 | virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements) { |
| 493 | return 0; |
| 494 | } |
| 495 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 496 | /// getFieldType - This method is used to implement the FieldInit class. |
| 497 | /// Implementors of this method should return the type of the named field if |
| 498 | /// they are of record type. |
| 499 | /// |
| 500 | virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; } |
| 501 | |
| 502 | /// getFieldInit - This method complements getFieldType to return the |
| 503 | /// initializer for the specified field. If getFieldType returns non-null |
| 504 | /// this method should return non-null, otherwise it returns null. |
| 505 | /// |
Jakob Stoklund Olesen | 0e45762 | 2010-03-25 06:23:34 +0000 | [diff] [blame] | 506 | virtual Init *getFieldInit(Record &R, const RecordVal *RV, |
| 507 | const std::string &FieldName) const { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 508 | return 0; |
| 509 | } |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 510 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 511 | /// resolveReferences - This method is used by classes that refer to other |
Bob Wilson | 159905a | 2009-11-21 22:44:20 +0000 | [diff] [blame] | 512 | /// variables which may not be defined at the time the expression is formed. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 513 | /// If a value is set for the variable later, this method will be called on |
| 514 | /// users of the value to allow the value to propagate out. |
| 515 | /// |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 516 | virtual Init *resolveReferences(Record &R, const RecordVal *RV) { |
| 517 | return this; |
| 518 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 519 | }; |
| 520 | |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 521 | inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 522 | I.print(OS); return OS; |
| 523 | } |
| 524 | |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 525 | /// TypedInit - This is the common super-class of types that have a specific, |
| 526 | /// explicit, type. |
| 527 | /// |
| 528 | class TypedInit : public Init { |
| 529 | RecTy *Ty; |
| 530 | public: |
| 531 | explicit TypedInit(RecTy *T) : Ty(T) {} |
| 532 | |
| 533 | RecTy *getType() const { return Ty; } |
| 534 | |
| 535 | virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); |
| 536 | virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements); |
| 537 | |
David Greene | 2a9de4d | 2010-09-03 21:00:49 +0000 | [diff] [blame] | 538 | /// getFieldType - This method is used to implement the FieldInit class. |
| 539 | /// Implementors of this method should return the type of the named field if |
| 540 | /// they are of record type. |
| 541 | /// |
| 542 | virtual RecTy *getFieldType(const std::string &FieldName) const; |
| 543 | |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 544 | /// resolveBitReference - This method is used to implement |
| 545 | /// VarBitInit::resolveReferences. If the bit is able to be resolved, we |
| 546 | /// simply return the resolved value, otherwise we return null. |
| 547 | /// |
| 548 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 549 | unsigned Bit) = 0; |
| 550 | |
| 551 | /// resolveListElementReference - This method is used to implement |
| 552 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 553 | /// now, we return the resolved value, otherwise we return null. |
| 554 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 555 | unsigned Elt) = 0; |
| 556 | }; |
| 557 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 558 | |
| 559 | /// UnsetInit - ? - Represents an uninitialized value |
| 560 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 561 | class UnsetInit : public Init { |
| 562 | public: |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 563 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 564 | return Ty->convertValue(this); |
| 565 | } |
| 566 | |
| 567 | virtual bool isComplete() const { return false; } |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 568 | virtual std::string getAsString() const { return "?"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 569 | }; |
| 570 | |
| 571 | |
| 572 | /// BitInit - true/false - Represent a concrete initializer for a bit. |
| 573 | /// |
| 574 | class BitInit : public Init { |
| 575 | bool Value; |
| 576 | public: |
Dan Gohman | c60c67f | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 577 | explicit BitInit(bool V) : Value(V) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 578 | |
| 579 | bool getValue() const { return Value; } |
| 580 | |
| 581 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 582 | return Ty->convertValue(this); |
| 583 | } |
| 584 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 585 | virtual std::string getAsString() const { return Value ? "1" : "0"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 586 | }; |
| 587 | |
| 588 | /// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value. |
| 589 | /// It contains a vector of bits, whose size is determined by the type. |
| 590 | /// |
| 591 | class BitsInit : public Init { |
| 592 | std::vector<Init*> Bits; |
| 593 | public: |
Dan Gohman | c60c67f | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 594 | explicit BitsInit(unsigned Size) : Bits(Size) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 595 | |
| 596 | unsigned getNumBits() const { return Bits.size(); } |
| 597 | |
| 598 | Init *getBit(unsigned Bit) const { |
| 599 | assert(Bit < Bits.size() && "Bit index out of range!"); |
| 600 | return Bits[Bit]; |
| 601 | } |
| 602 | void setBit(unsigned Bit, Init *V) { |
| 603 | assert(Bit < Bits.size() && "Bit index out of range!"); |
| 604 | assert(Bits[Bit] == 0 && "Bit already set!"); |
| 605 | Bits[Bit] = V; |
| 606 | } |
| 607 | |
| 608 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 609 | return Ty->convertValue(this); |
| 610 | } |
| 611 | virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); |
| 612 | |
| 613 | virtual bool isComplete() const { |
| 614 | for (unsigned i = 0; i != getNumBits(); ++i) |
| 615 | if (!getBit(i)->isComplete()) return false; |
| 616 | return true; |
| 617 | } |
Johnny Chen | 4e8bd58 | 2010-04-09 21:01:02 +0000 | [diff] [blame] | 618 | bool allInComplete() const { |
| 619 | for (unsigned i = 0; i != getNumBits(); ++i) |
| 620 | if (getBit(i)->isComplete()) return false; |
| 621 | return true; |
| 622 | } |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 623 | virtual std::string getAsString() const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 624 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 625 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 626 | }; |
| 627 | |
| 628 | |
| 629 | /// IntInit - 7 - Represent an initalization by a literal integer value. |
| 630 | /// |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 631 | class IntInit : public TypedInit { |
Dan Gohman | ca0546f | 2008-10-17 01:33:43 +0000 | [diff] [blame] | 632 | int64_t Value; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 633 | public: |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 634 | explicit IntInit(int64_t V) : TypedInit(new IntRecTy), Value(V) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 635 | |
Dan Gohman | ca0546f | 2008-10-17 01:33:43 +0000 | [diff] [blame] | 636 | int64_t getValue() const { return Value; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 637 | |
| 638 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 639 | return Ty->convertValue(this); |
| 640 | } |
| 641 | virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); |
| 642 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 643 | virtual std::string getAsString() const; |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 644 | |
| 645 | /// resolveBitReference - This method is used to implement |
| 646 | /// VarBitInit::resolveReferences. If the bit is able to be resolved, we |
| 647 | /// simply return the resolved value, otherwise we return null. |
| 648 | /// |
| 649 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 650 | unsigned Bit) { |
| 651 | assert(0 && "Illegal bit reference off int"); |
| 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | /// resolveListElementReference - This method is used to implement |
| 656 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 657 | /// now, we return the resolved value, otherwise we return null. |
| 658 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 659 | unsigned Elt) { |
| 660 | assert(0 && "Illegal element reference off int"); |
| 661 | return 0; |
| 662 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 663 | }; |
| 664 | |
| 665 | |
| 666 | /// StringInit - "foo" - Represent an initialization by a string value. |
| 667 | /// |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 668 | class StringInit : public TypedInit { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 669 | std::string Value; |
| 670 | public: |
Nick Lewycky | d449e7c | 2009-05-15 03:03:14 +0000 | [diff] [blame] | 671 | explicit StringInit(const std::string &V) |
| 672 | : TypedInit(new StringRecTy), Value(V) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 673 | |
| 674 | const std::string &getValue() const { return Value; } |
| 675 | |
| 676 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 677 | return Ty->convertValue(this); |
| 678 | } |
| 679 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 680 | virtual std::string getAsString() const { return "\"" + Value + "\""; } |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 681 | |
| 682 | /// resolveBitReference - This method is used to implement |
| 683 | /// VarBitInit::resolveReferences. If the bit is able to be resolved, we |
| 684 | /// simply return the resolved value, otherwise we return null. |
| 685 | /// |
| 686 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 687 | unsigned Bit) { |
| 688 | assert(0 && "Illegal bit reference off string"); |
| 689 | return 0; |
| 690 | } |
| 691 | |
| 692 | /// resolveListElementReference - This method is used to implement |
| 693 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 694 | /// now, we return the resolved value, otherwise we return null. |
| 695 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 696 | unsigned Elt) { |
| 697 | assert(0 && "Illegal element reference off string"); |
| 698 | return 0; |
| 699 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 700 | }; |
| 701 | |
| 702 | /// CodeInit - "[{...}]" - Represent a code fragment. |
| 703 | /// |
| 704 | class CodeInit : public Init { |
| 705 | std::string Value; |
| 706 | public: |
Dan Gohman | c60c67f | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 707 | explicit CodeInit(const std::string &V) : Value(V) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 708 | |
| 709 | const std::string getValue() const { return Value; } |
| 710 | |
| 711 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 712 | return Ty->convertValue(this); |
| 713 | } |
| 714 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 715 | virtual std::string getAsString() const { return "[{" + Value + "}]"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 716 | }; |
| 717 | |
| 718 | /// ListInit - [AL, AH, CL] - Represent a list of defs |
| 719 | /// |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 720 | class ListInit : public TypedInit { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 721 | std::vector<Init*> Values; |
| 722 | public: |
David Greene | d571b3c | 2009-05-14 22:38:31 +0000 | [diff] [blame] | 723 | typedef std::vector<Init*>::iterator iterator; |
| 724 | typedef std::vector<Init*>::const_iterator const_iterator; |
| 725 | |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 726 | explicit ListInit(std::vector<Init*> &Vs, RecTy *EltTy) |
| 727 | : TypedInit(new ListRecTy(EltTy)) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 728 | Values.swap(Vs); |
| 729 | } |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 730 | explicit ListInit(iterator Start, iterator End, RecTy *EltTy) |
| 731 | : TypedInit(new ListRecTy(EltTy)), Values(Start, End) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 732 | |
| 733 | unsigned getSize() const { return Values.size(); } |
| 734 | Init *getElement(unsigned i) const { |
| 735 | assert(i < Values.size() && "List element index out of range!"); |
| 736 | return Values[i]; |
| 737 | } |
| 738 | |
Chris Lattner | cbebe46 | 2007-02-27 22:08:27 +0000 | [diff] [blame] | 739 | Record *getElementAsRecord(unsigned i) const; |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 740 | |
Chris Lattner | 8bf9e06 | 2004-07-26 23:21:34 +0000 | [diff] [blame] | 741 | Init *convertInitListSlice(const std::vector<unsigned> &Elements); |
| 742 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 743 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 744 | return Ty->convertValue(this); |
| 745 | } |
| 746 | |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 747 | /// resolveReferences - This method is used by classes that refer to other |
| 748 | /// variables which may not be defined at the time they expression is formed. |
| 749 | /// If a value is set for the variable later, this method will be called on |
| 750 | /// users of the value to allow the value to propagate out. |
| 751 | /// |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 752 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 753 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 754 | virtual std::string getAsString() const; |
Anton Korobeynikov | e49cc26 | 2008-01-21 22:30:26 +0000 | [diff] [blame] | 755 | |
Anton Korobeynikov | e49cc26 | 2008-01-21 22:30:26 +0000 | [diff] [blame] | 756 | inline iterator begin() { return Values.begin(); } |
| 757 | inline const_iterator begin() const { return Values.begin(); } |
| 758 | inline iterator end () { return Values.end(); } |
| 759 | inline const_iterator end () const { return Values.end(); } |
| 760 | |
| 761 | inline size_t size () const { return Values.size(); } |
| 762 | inline bool empty() const { return Values.empty(); } |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 763 | |
| 764 | /// resolveBitReference - This method is used to implement |
| 765 | /// VarBitInit::resolveReferences. If the bit is able to be resolved, we |
| 766 | /// simply return the resolved value, otherwise we return null. |
| 767 | /// |
| 768 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 769 | unsigned Bit) { |
| 770 | assert(0 && "Illegal bit reference off list"); |
| 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | /// resolveListElementReference - This method is used to implement |
| 775 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 776 | /// now, we return the resolved value, otherwise we return null. |
| 777 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 778 | unsigned Elt); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 779 | }; |
| 780 | |
| 781 | |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 782 | /// OpInit - Base class for operators |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 783 | /// |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 784 | class OpInit : public TypedInit { |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 785 | public: |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 786 | OpInit(RecTy *Type) : TypedInit(Type) {} |
| 787 | |
| 788 | // Clone - Clone this operator, replacing arguments with the new list |
| 789 | virtual OpInit *clone(std::vector<Init *> &Operands) = 0; |
| 790 | |
Dan Gohman | 1432ef8 | 2009-08-12 22:10:57 +0000 | [diff] [blame] | 791 | virtual int getNumOperands() const = 0; |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 792 | virtual Init *getOperand(int i) = 0; |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 793 | |
| 794 | // Fold - If possible, fold this to a simpler init. Return this if not |
| 795 | // possible to fold. |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 796 | virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) = 0; |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 797 | |
| 798 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 799 | return Ty->convertValue(this); |
| 800 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 801 | |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 802 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 803 | unsigned Bit); |
| 804 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 805 | unsigned Elt); |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 806 | }; |
| 807 | |
| 808 | |
| 809 | /// UnOpInit - !op (X) - Transform an init. |
| 810 | /// |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 811 | class UnOpInit : public OpInit { |
| 812 | public: |
David Greene | d571b3c | 2009-05-14 22:38:31 +0000 | [diff] [blame] | 813 | enum UnaryOp { CAST, CAR, CDR, LNULL }; |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 814 | private: |
| 815 | UnaryOp Opc; |
| 816 | Init *LHS; |
| 817 | public: |
| 818 | UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type) : |
| 819 | OpInit(Type), Opc(opc), LHS(lhs) { |
| 820 | } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 821 | |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 822 | // Clone - Clone this operator, replacing arguments with the new list |
| 823 | virtual OpInit *clone(std::vector<Init *> &Operands) { |
Nick Lewycky | d449e7c | 2009-05-15 03:03:14 +0000 | [diff] [blame] | 824 | assert(Operands.size() == 1 && |
| 825 | "Wrong number of operands for unary operation"); |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 826 | return new UnOpInit(getOpcode(), *Operands.begin(), getType()); |
| 827 | } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 828 | |
Dan Gohman | 1432ef8 | 2009-08-12 22:10:57 +0000 | [diff] [blame] | 829 | int getNumOperands() const { return 1; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 830 | Init *getOperand(int i) { |
| 831 | assert(i == 0 && "Invalid operand id for unary operator"); |
| 832 | return getOperand(); |
| 833 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 834 | |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 835 | UnaryOp getOpcode() const { return Opc; } |
| 836 | Init *getOperand() const { return LHS; } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 837 | |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 838 | // Fold - If possible, fold this to a simpler init. Return this if not |
| 839 | // possible to fold. |
| 840 | Init *Fold(Record *CurRec, MultiClass *CurMultiClass); |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 841 | |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 842 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 843 | |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 844 | virtual std::string getAsString() const; |
| 845 | }; |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 846 | |
| 847 | /// BinOpInit - !op (X, Y) - Combine two inits. |
| 848 | /// |
| 849 | class BinOpInit : public OpInit { |
| 850 | public: |
David Greene | 297bfe6 | 2010-01-05 19:11:42 +0000 | [diff] [blame] | 851 | enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, NAMECONCAT, EQ }; |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 852 | private: |
| 853 | BinaryOp Opc; |
| 854 | Init *LHS, *RHS; |
| 855 | public: |
| 856 | BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) : |
| 857 | OpInit(Type), Opc(opc), LHS(lhs), RHS(rhs) { |
| 858 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 859 | |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 860 | // Clone - Clone this operator, replacing arguments with the new list |
| 861 | virtual OpInit *clone(std::vector<Init *> &Operands) { |
Nick Lewycky | d449e7c | 2009-05-15 03:03:14 +0000 | [diff] [blame] | 862 | assert(Operands.size() == 2 && |
| 863 | "Wrong number of operands for binary operation"); |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 864 | return new BinOpInit(getOpcode(), Operands[0], Operands[1], getType()); |
| 865 | } |
| 866 | |
Dan Gohman | 1432ef8 | 2009-08-12 22:10:57 +0000 | [diff] [blame] | 867 | int getNumOperands() const { return 2; } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 868 | Init *getOperand(int i) { |
Nick Lewycky | d449e7c | 2009-05-15 03:03:14 +0000 | [diff] [blame] | 869 | assert((i == 0 || i == 1) && "Invalid operand id for binary operator"); |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 870 | if (i == 0) { |
| 871 | return getLHS(); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 872 | } else { |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 873 | return getRHS(); |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | BinaryOp getOpcode() const { return Opc; } |
| 878 | Init *getLHS() const { return LHS; } |
| 879 | Init *getRHS() const { return RHS; } |
| 880 | |
| 881 | // Fold - If possible, fold this to a simpler init. Return this if not |
| 882 | // possible to fold. |
| 883 | Init *Fold(Record *CurRec, MultiClass *CurMultiClass); |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 884 | |
| 885 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 886 | |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 887 | virtual std::string getAsString() const; |
| 888 | }; |
| 889 | |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 890 | /// TernOpInit - !op (X, Y, Z) - Combine two inits. |
| 891 | /// |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 892 | class TernOpInit : public OpInit { |
| 893 | public: |
David Greene | 58a6b76 | 2009-06-09 18:31:17 +0000 | [diff] [blame] | 894 | enum TernaryOp { SUBST, FOREACH, IF }; |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 895 | private: |
| 896 | TernaryOp Opc; |
| 897 | Init *LHS, *MHS, *RHS; |
| 898 | public: |
| 899 | TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type) : |
| 900 | OpInit(Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) { |
| 901 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 902 | |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 903 | // Clone - Clone this operator, replacing arguments with the new list |
| 904 | virtual OpInit *clone(std::vector<Init *> &Operands) { |
Nick Lewycky | d449e7c | 2009-05-15 03:03:14 +0000 | [diff] [blame] | 905 | assert(Operands.size() == 3 && |
| 906 | "Wrong number of operands for ternary operation"); |
| 907 | return new TernOpInit(getOpcode(), Operands[0], Operands[1], Operands[2], |
| 908 | getType()); |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 909 | } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 910 | |
Dan Gohman | 1432ef8 | 2009-08-12 22:10:57 +0000 | [diff] [blame] | 911 | int getNumOperands() const { return 3; } |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 912 | Init *getOperand(int i) { |
Nick Lewycky | d449e7c | 2009-05-15 03:03:14 +0000 | [diff] [blame] | 913 | assert((i == 0 || i == 1 || i == 2) && |
| 914 | "Invalid operand id for ternary operator"); |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 915 | if (i == 0) { |
| 916 | return getLHS(); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 917 | } else if (i == 1) { |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 918 | return getMHS(); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 919 | } else { |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 920 | return getRHS(); |
| 921 | } |
| 922 | } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 923 | |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 924 | TernaryOp getOpcode() const { return Opc; } |
| 925 | Init *getLHS() const { return LHS; } |
| 926 | Init *getMHS() const { return MHS; } |
| 927 | Init *getRHS() const { return RHS; } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 928 | |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 929 | // Fold - If possible, fold this to a simpler init. Return this if not |
| 930 | // possible to fold. |
| 931 | Init *Fold(Record *CurRec, MultiClass *CurMultiClass); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 932 | |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 933 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 934 | |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 935 | virtual std::string getAsString() const; |
| 936 | }; |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 937 | |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 938 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 939 | /// VarInit - 'Opcode' - Represent a reference to an entire variable object. |
| 940 | /// |
| 941 | class VarInit : public TypedInit { |
| 942 | std::string VarName; |
| 943 | public: |
Dan Gohman | c60c67f | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 944 | explicit VarInit(const std::string &VN, RecTy *T) |
| 945 | : TypedInit(T), VarName(VN) {} |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 946 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 947 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 948 | return Ty->convertValue(this); |
| 949 | } |
| 950 | |
| 951 | const std::string &getName() const { return VarName; } |
| 952 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 953 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 954 | unsigned Bit); |
| 955 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 956 | unsigned Elt); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 957 | |
| 958 | virtual RecTy *getFieldType(const std::string &FieldName) const; |
Jakob Stoklund Olesen | 0e45762 | 2010-03-25 06:23:34 +0000 | [diff] [blame] | 959 | virtual Init *getFieldInit(Record &R, const RecordVal *RV, |
| 960 | const std::string &FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 961 | |
| 962 | /// resolveReferences - This method is used by classes that refer to other |
| 963 | /// variables which may not be defined at the time they expression is formed. |
| 964 | /// If a value is set for the variable later, this method will be called on |
| 965 | /// users of the value to allow the value to propagate out. |
| 966 | /// |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 967 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 968 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 969 | virtual std::string getAsString() const { return VarName; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 970 | }; |
| 971 | |
| 972 | |
| 973 | /// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field. |
| 974 | /// |
| 975 | class VarBitInit : public Init { |
| 976 | TypedInit *TI; |
| 977 | unsigned Bit; |
| 978 | public: |
| 979 | VarBitInit(TypedInit *T, unsigned B) : TI(T), Bit(B) { |
| 980 | assert(T->getType() && dynamic_cast<BitsRecTy*>(T->getType()) && |
| 981 | ((BitsRecTy*)T->getType())->getNumBits() > B && |
| 982 | "Illegal VarBitInit expression!"); |
| 983 | } |
| 984 | |
| 985 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 986 | return Ty->convertValue(this); |
| 987 | } |
| 988 | |
| 989 | TypedInit *getVariable() const { return TI; } |
| 990 | unsigned getBitNum() const { return Bit; } |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 991 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 992 | virtual std::string getAsString() const; |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 993 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 994 | }; |
| 995 | |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 996 | /// VarListElementInit - List[4] - Represent access to one element of a var or |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 997 | /// field. |
| 998 | class VarListElementInit : public TypedInit { |
| 999 | TypedInit *TI; |
| 1000 | unsigned Element; |
| 1001 | public: |
| 1002 | VarListElementInit(TypedInit *T, unsigned E) |
| 1003 | : TypedInit(dynamic_cast<ListRecTy*>(T->getType())->getElementType()), |
| 1004 | TI(T), Element(E) { |
| 1005 | assert(T->getType() && dynamic_cast<ListRecTy*>(T->getType()) && |
| 1006 | "Illegal VarBitInit expression!"); |
| 1007 | } |
| 1008 | |
| 1009 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 1010 | return Ty->convertValue(this); |
| 1011 | } |
| 1012 | |
| 1013 | TypedInit *getVariable() const { return TI; } |
| 1014 | unsigned getElementNum() const { return Element; } |
| 1015 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 1016 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 1017 | unsigned Bit); |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 1018 | |
| 1019 | /// resolveListElementReference - This method is used to implement |
| 1020 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 1021 | /// now, we return the resolved value, otherwise we return null. |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 1022 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 1023 | unsigned Elt); |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 1024 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 1025 | virtual std::string getAsString() const; |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 1026 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 1027 | }; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1028 | |
| 1029 | /// DefInit - AL - Represent a reference to a 'def' in the description |
| 1030 | /// |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1031 | class DefInit : public TypedInit { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1032 | Record *Def; |
| 1033 | public: |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1034 | explicit DefInit(Record *D) : TypedInit(new RecordRecTy(D)), Def(D) {} |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 1035 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1036 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 1037 | return Ty->convertValue(this); |
| 1038 | } |
| 1039 | |
| 1040 | Record *getDef() const { return Def; } |
| 1041 | |
| 1042 | //virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); |
| 1043 | |
| 1044 | virtual RecTy *getFieldType(const std::string &FieldName) const; |
Jakob Stoklund Olesen | 0e45762 | 2010-03-25 06:23:34 +0000 | [diff] [blame] | 1045 | virtual Init *getFieldInit(Record &R, const RecordVal *RV, |
| 1046 | const std::string &FieldName) const; |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 1047 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 1048 | virtual std::string getAsString() const; |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1049 | |
| 1050 | /// resolveBitReference - This method is used to implement |
| 1051 | /// VarBitInit::resolveReferences. If the bit is able to be resolved, we |
| 1052 | /// simply return the resolved value, otherwise we return null. |
| 1053 | /// |
| 1054 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 1055 | unsigned Bit) { |
| 1056 | assert(0 && "Illegal bit reference off def"); |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | /// resolveListElementReference - This method is used to implement |
| 1061 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 1062 | /// now, we return the resolved value, otherwise we return null. |
| 1063 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 1064 | unsigned Elt) { |
| 1065 | assert(0 && "Illegal element reference off def"); |
| 1066 | return 0; |
| 1067 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1068 | }; |
| 1069 | |
| 1070 | |
| 1071 | /// FieldInit - X.Y - Represent a reference to a subfield of a variable |
| 1072 | /// |
| 1073 | class FieldInit : public TypedInit { |
| 1074 | Init *Rec; // Record we are referring to |
| 1075 | std::string FieldName; // Field we are accessing |
| 1076 | public: |
| 1077 | FieldInit(Init *R, const std::string &FN) |
| 1078 | : TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) { |
| 1079 | assert(getType() && "FieldInit with non-record type!"); |
| 1080 | } |
| 1081 | |
| 1082 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 1083 | return Ty->convertValue(this); |
| 1084 | } |
| 1085 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 1086 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 1087 | unsigned Bit); |
| 1088 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 1089 | unsigned Elt); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1090 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 1091 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1092 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 1093 | virtual std::string getAsString() const { |
| 1094 | return Rec->getAsString() + "." + FieldName; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1095 | } |
| 1096 | }; |
| 1097 | |
Chris Lattner | b59cf3c | 2006-03-30 22:50:40 +0000 | [diff] [blame] | 1098 | /// DagInit - (v a, b) - Represent a DAG tree value. DAG inits are required |
| 1099 | /// to have at least one value then a (possibly empty) list of arguments. Each |
| 1100 | /// argument can have a name associated with it. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1101 | /// |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1102 | class DagInit : public TypedInit { |
Chris Lattner | b59cf3c | 2006-03-30 22:50:40 +0000 | [diff] [blame] | 1103 | Init *Val; |
Nate Begeman | dbe3f77 | 2009-03-19 05:21:56 +0000 | [diff] [blame] | 1104 | std::string ValName; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1105 | std::vector<Init*> Args; |
| 1106 | std::vector<std::string> ArgNames; |
| 1107 | public: |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1108 | DagInit(Init *V, std::string VN, |
Nate Begeman | dbe3f77 | 2009-03-19 05:21:56 +0000 | [diff] [blame] | 1109 | const std::vector<std::pair<Init*, std::string> > &args) |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1110 | : TypedInit(new DagRecTy), Val(V), ValName(VN) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1111 | Args.reserve(args.size()); |
| 1112 | ArgNames.reserve(args.size()); |
| 1113 | for (unsigned i = 0, e = args.size(); i != e; ++i) { |
| 1114 | Args.push_back(args[i].first); |
| 1115 | ArgNames.push_back(args[i].second); |
| 1116 | } |
| 1117 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1118 | DagInit(Init *V, std::string VN, const std::vector<Init*> &args, |
Chris Lattner | 0d3ef40 | 2006-01-31 06:02:35 +0000 | [diff] [blame] | 1119 | const std::vector<std::string> &argNames) |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1120 | : TypedInit(new DagRecTy), Val(V), ValName(VN), Args(args), |
| 1121 | ArgNames(argNames) { } |
| 1122 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1123 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 1124 | return Ty->convertValue(this); |
| 1125 | } |
| 1126 | |
Chris Lattner | b59cf3c | 2006-03-30 22:50:40 +0000 | [diff] [blame] | 1127 | Init *getOperator() const { return Val; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1128 | |
Nate Begeman | dbe3f77 | 2009-03-19 05:21:56 +0000 | [diff] [blame] | 1129 | const std::string &getName() const { return ValName; } |
| 1130 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1131 | unsigned getNumArgs() const { return Args.size(); } |
| 1132 | Init *getArg(unsigned Num) const { |
| 1133 | assert(Num < Args.size() && "Arg number out of range!"); |
| 1134 | return Args[Num]; |
| 1135 | } |
| 1136 | const std::string &getArgName(unsigned Num) const { |
| 1137 | assert(Num < ArgNames.size() && "Arg number out of range!"); |
| 1138 | return ArgNames[Num]; |
| 1139 | } |
| 1140 | |
| 1141 | void setArg(unsigned Num, Init *I) { |
| 1142 | assert(Num < Args.size() && "Arg number out of range!"); |
| 1143 | Args[Num] = I; |
| 1144 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1145 | |
Chris Lattner | 0d3ef40 | 2006-01-31 06:02:35 +0000 | [diff] [blame] | 1146 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1147 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 1148 | virtual std::string getAsString() const; |
Anton Korobeynikov | 010bd77 | 2008-01-22 11:00:07 +0000 | [diff] [blame] | 1149 | |
| 1150 | typedef std::vector<Init*>::iterator arg_iterator; |
| 1151 | typedef std::vector<Init*>::const_iterator const_arg_iterator; |
| 1152 | typedef std::vector<std::string>::iterator name_iterator; |
| 1153 | typedef std::vector<std::string>::const_iterator const_name_iterator; |
| 1154 | |
| 1155 | inline arg_iterator arg_begin() { return Args.begin(); } |
| 1156 | inline const_arg_iterator arg_begin() const { return Args.begin(); } |
| 1157 | inline arg_iterator arg_end () { return Args.end(); } |
| 1158 | inline const_arg_iterator arg_end () const { return Args.end(); } |
| 1159 | |
| 1160 | inline size_t arg_size () const { return Args.size(); } |
| 1161 | inline bool arg_empty() const { return Args.empty(); } |
| 1162 | |
| 1163 | inline name_iterator name_begin() { return ArgNames.begin(); } |
| 1164 | inline const_name_iterator name_begin() const { return ArgNames.begin(); } |
| 1165 | inline name_iterator name_end () { return ArgNames.end(); } |
| 1166 | inline const_name_iterator name_end () const { return ArgNames.end(); } |
| 1167 | |
| 1168 | inline size_t name_size () const { return ArgNames.size(); } |
| 1169 | inline bool name_empty() const { return ArgNames.empty(); } |
| 1170 | |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1171 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 1172 | unsigned Bit) { |
| 1173 | assert(0 && "Illegal bit reference off dag"); |
| 1174 | return 0; |
| 1175 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1176 | |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1177 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 1178 | unsigned Elt) { |
| 1179 | assert(0 && "Illegal element reference off dag"); |
| 1180 | return 0; |
| 1181 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1182 | }; |
| 1183 | |
| 1184 | //===----------------------------------------------------------------------===// |
| 1185 | // High-Level Classes |
| 1186 | //===----------------------------------------------------------------------===// |
| 1187 | |
| 1188 | class RecordVal { |
| 1189 | std::string Name; |
| 1190 | RecTy *Ty; |
| 1191 | unsigned Prefix; |
| 1192 | Init *Value; |
| 1193 | public: |
| 1194 | RecordVal(const std::string &N, RecTy *T, unsigned P); |
| 1195 | |
| 1196 | const std::string &getName() const { return Name; } |
| 1197 | |
| 1198 | unsigned getPrefix() const { return Prefix; } |
| 1199 | RecTy *getType() const { return Ty; } |
| 1200 | Init *getValue() const { return Value; } |
| 1201 | |
| 1202 | bool setValue(Init *V) { |
| 1203 | if (V) { |
| 1204 | Value = V->convertInitializerTo(Ty); |
| 1205 | return Value == 0; |
| 1206 | } |
| 1207 | Value = 0; |
| 1208 | return false; |
| 1209 | } |
| 1210 | |
| 1211 | void dump() const; |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 1212 | void print(raw_ostream &OS, bool PrintSem = true) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1213 | }; |
| 1214 | |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 1215 | inline raw_ostream &operator<<(raw_ostream &OS, const RecordVal &RV) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1216 | RV.print(OS << " "); |
| 1217 | return OS; |
| 1218 | } |
| 1219 | |
Chris Lattner | 87a1061 | 2004-10-23 04:58:50 +0000 | [diff] [blame] | 1220 | class Record { |
Daniel Dunbar | ced0081 | 2009-08-23 09:47:37 +0000 | [diff] [blame] | 1221 | static unsigned LastID; |
| 1222 | |
| 1223 | // Unique record ID. |
| 1224 | unsigned ID; |
Chris Lattner | f9b2edb | 2005-08-19 17:58:49 +0000 | [diff] [blame] | 1225 | std::string Name; |
Chris Lattner | 526c8cb | 2009-06-21 03:39:35 +0000 | [diff] [blame] | 1226 | SMLoc Loc; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1227 | std::vector<std::string> TemplateArgs; |
| 1228 | std::vector<RecordVal> Values; |
| 1229 | std::vector<Record*> SuperClasses; |
| 1230 | public: |
| 1231 | |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1232 | explicit Record(const std::string &N, SMLoc loc) : |
Daniel Dunbar | ced0081 | 2009-08-23 09:47:37 +0000 | [diff] [blame] | 1233 | ID(LastID++), Name(N), Loc(loc) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1234 | ~Record() {} |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1235 | |
Mikhail Glushenkov | 5be6764 | 2010-09-21 14:59:50 +0000 | [diff] [blame] | 1236 | |
Chris Lattner | d39f75b | 2010-03-01 22:09:11 +0000 | [diff] [blame] | 1237 | static unsigned getNewUID() { return LastID++; } |
Mikhail Glushenkov | 5be6764 | 2010-09-21 14:59:50 +0000 | [diff] [blame] | 1238 | |
| 1239 | |
Daniel Dunbar | ced0081 | 2009-08-23 09:47:37 +0000 | [diff] [blame] | 1240 | unsigned getID() const { return ID; } |
| 1241 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1242 | const std::string &getName() const { return Name; } |
Chris Lattner | ac28425 | 2005-08-19 17:58:11 +0000 | [diff] [blame] | 1243 | void setName(const std::string &Name); // Also updates RecordKeeper. |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1244 | |
Chris Lattner | 526c8cb | 2009-06-21 03:39:35 +0000 | [diff] [blame] | 1245 | SMLoc getLoc() const { return Loc; } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1246 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1247 | const std::vector<std::string> &getTemplateArgs() const { |
| 1248 | return TemplateArgs; |
| 1249 | } |
| 1250 | const std::vector<RecordVal> &getValues() const { return Values; } |
| 1251 | const std::vector<Record*> &getSuperClasses() const { return SuperClasses; } |
| 1252 | |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1253 | bool isTemplateArg(StringRef Name) const { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1254 | for (unsigned i = 0, e = TemplateArgs.size(); i != e; ++i) |
| 1255 | if (TemplateArgs[i] == Name) return true; |
| 1256 | return false; |
| 1257 | } |
| 1258 | |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1259 | const RecordVal *getValue(StringRef Name) const { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1260 | for (unsigned i = 0, e = Values.size(); i != e; ++i) |
| 1261 | if (Values[i].getName() == Name) return &Values[i]; |
| 1262 | return 0; |
| 1263 | } |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1264 | RecordVal *getValue(StringRef Name) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1265 | for (unsigned i = 0, e = Values.size(); i != e; ++i) |
| 1266 | if (Values[i].getName() == Name) return &Values[i]; |
| 1267 | return 0; |
| 1268 | } |
| 1269 | |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1270 | void addTemplateArg(StringRef Name) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1271 | assert(!isTemplateArg(Name) && "Template arg already defined!"); |
| 1272 | TemplateArgs.push_back(Name); |
| 1273 | } |
| 1274 | |
| 1275 | void addValue(const RecordVal &RV) { |
| 1276 | assert(getValue(RV.getName()) == 0 && "Value already added!"); |
| 1277 | Values.push_back(RV); |
| 1278 | } |
| 1279 | |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1280 | void removeValue(StringRef Name) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1281 | for (unsigned i = 0, e = Values.size(); i != e; ++i) |
| 1282 | if (Values[i].getName() == Name) { |
| 1283 | Values.erase(Values.begin()+i); |
| 1284 | return; |
| 1285 | } |
Bob Wilson | 3b793a4 | 2009-11-21 22:39:27 +0000 | [diff] [blame] | 1286 | assert(0 && "Cannot remove an entry that does not exist!"); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1287 | } |
| 1288 | |
Ted Kremenek | 58e3287 | 2009-03-13 22:20:10 +0000 | [diff] [blame] | 1289 | bool isSubClassOf(const Record *R) const { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1290 | for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i) |
| 1291 | if (SuperClasses[i] == R) |
Jeff Cohen | 88e7b72 | 2005-04-22 04:13:13 +0000 | [diff] [blame] | 1292 | return true; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1293 | return false; |
| 1294 | } |
| 1295 | |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1296 | bool isSubClassOf(StringRef Name) const { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1297 | for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i) |
| 1298 | if (SuperClasses[i]->getName() == Name) |
| 1299 | return true; |
| 1300 | return false; |
| 1301 | } |
| 1302 | |
| 1303 | void addSuperClass(Record *R) { |
| 1304 | assert(!isSubClassOf(R) && "Already subclassing record!"); |
| 1305 | SuperClasses.push_back(R); |
| 1306 | } |
| 1307 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 1308 | /// resolveReferences - If there are any field references that refer to fields |
| 1309 | /// that have been filled in, we can propagate the values now. |
| 1310 | /// |
| 1311 | void resolveReferences() { resolveReferencesTo(0); } |
| 1312 | |
| 1313 | /// resolveReferencesTo - If anything in this record refers to RV, replace the |
| 1314 | /// reference to RV with the RHS of RV. If RV is null, we resolve all |
| 1315 | /// possible references. |
| 1316 | void resolveReferencesTo(const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1317 | |
| 1318 | void dump() const; |
| 1319 | |
| 1320 | //===--------------------------------------------------------------------===// |
| 1321 | // High-level methods useful to tablegen back-ends |
| 1322 | // |
| 1323 | |
| 1324 | /// getValueInit - Return the initializer for a value with the specified name, |
| 1325 | /// or throw an exception if the field does not exist. |
| 1326 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1327 | Init *getValueInit(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1328 | |
| 1329 | /// getValueAsString - This method looks up the specified field and returns |
| 1330 | /// its value as a string, throwing an exception if the field does not exist |
| 1331 | /// or if the value is not a string. |
| 1332 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1333 | std::string getValueAsString(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1334 | |
| 1335 | /// getValueAsBitsInit - This method looks up the specified field and returns |
| 1336 | /// its value as a BitsInit, throwing an exception if the field does not exist |
| 1337 | /// or if the value is not the right type. |
| 1338 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1339 | BitsInit *getValueAsBitsInit(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1340 | |
| 1341 | /// getValueAsListInit - This method looks up the specified field and returns |
| 1342 | /// its value as a ListInit, throwing an exception if the field does not exist |
| 1343 | /// or if the value is not the right type. |
| 1344 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1345 | ListInit *getValueAsListInit(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1346 | |
Chris Lattner | 7ad0bed | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 1347 | /// getValueAsListOfDefs - This method looks up the specified field and |
Anton Korobeynikov | a468a11 | 2007-11-11 11:19:37 +0000 | [diff] [blame] | 1348 | /// returns its value as a vector of records, throwing an exception if the |
Chris Lattner | 7ad0bed | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 1349 | /// field does not exist or if the value is not the right type. |
Jim Laskey | b04feb6 | 2005-10-28 21:46:31 +0000 | [diff] [blame] | 1350 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1351 | std::vector<Record*> getValueAsListOfDefs(StringRef FieldName) const; |
Jim Laskey | b04feb6 | 2005-10-28 21:46:31 +0000 | [diff] [blame] | 1352 | |
Mikhail Glushenkov | 5be6764 | 2010-09-21 14:59:50 +0000 | [diff] [blame] | 1353 | /// getValueAsListOfInts - This method looks up the specified field and |
| 1354 | /// returns its value as a vector of integers, throwing an exception if the |
| 1355 | /// field does not exist or if the value is not the right type. |
Anton Korobeynikov | a468a11 | 2007-11-11 11:19:37 +0000 | [diff] [blame] | 1356 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1357 | std::vector<int64_t> getValueAsListOfInts(StringRef FieldName) const; |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1358 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1359 | /// getValueAsDef - This method looks up the specified field and returns its |
| 1360 | /// value as a Record, throwing an exception if the field does not exist or if |
| 1361 | /// the value is not the right type. |
| 1362 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1363 | Record *getValueAsDef(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1364 | |
| 1365 | /// getValueAsBit - This method looks up the specified field and returns its |
| 1366 | /// value as a bit, throwing an exception if the field does not exist or if |
| 1367 | /// the value is not the right type. |
| 1368 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1369 | bool getValueAsBit(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1370 | |
| 1371 | /// getValueAsInt - This method looks up the specified field and returns its |
Dan Gohman | ca0546f | 2008-10-17 01:33:43 +0000 | [diff] [blame] | 1372 | /// value as an int64_t, throwing an exception if the field does not exist or |
| 1373 | /// if the value is not the right type. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1374 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1375 | int64_t getValueAsInt(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1376 | |
| 1377 | /// getValueAsDag - This method looks up the specified field and returns its |
| 1378 | /// value as an Dag, throwing an exception if the field does not exist or if |
| 1379 | /// the value is not the right type. |
| 1380 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1381 | DagInit *getValueAsDag(StringRef FieldName) const; |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1382 | |
Chris Lattner | ae939eb | 2005-09-13 21:44:28 +0000 | [diff] [blame] | 1383 | /// getValueAsCode - This method looks up the specified field and returns |
| 1384 | /// its value as the string data in a CodeInit, throwing an exception if the |
| 1385 | /// field does not exist or if the value is not a code object. |
| 1386 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1387 | std::string getValueAsCode(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1388 | }; |
| 1389 | |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 1390 | raw_ostream &operator<<(raw_ostream &OS, const Record &R); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1391 | |
David Greene | a9c6c5d | 2009-04-22 20:18:10 +0000 | [diff] [blame] | 1392 | struct MultiClass { |
| 1393 | Record Rec; // Placeholder for template args and Name. |
| 1394 | typedef std::vector<Record*> RecordVector; |
| 1395 | RecordVector DefPrototypes; |
David Greene | 7049e79 | 2009-04-24 16:55:41 +0000 | [diff] [blame] | 1396 | |
| 1397 | void dump() const; |
| 1398 | |
Chris Lattner | 526c8cb | 2009-06-21 03:39:35 +0000 | [diff] [blame] | 1399 | MultiClass(const std::string &Name, SMLoc Loc) : Rec(Name, Loc) {} |
David Greene | a9c6c5d | 2009-04-22 20:18:10 +0000 | [diff] [blame] | 1400 | }; |
| 1401 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1402 | class RecordKeeper { |
| 1403 | std::map<std::string, Record*> Classes, Defs; |
| 1404 | public: |
| 1405 | ~RecordKeeper() { |
| 1406 | for (std::map<std::string, Record*>::iterator I = Classes.begin(), |
Jeff Cohen | 88e7b72 | 2005-04-22 04:13:13 +0000 | [diff] [blame] | 1407 | E = Classes.end(); I != E; ++I) |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1408 | delete I->second; |
| 1409 | for (std::map<std::string, Record*>::iterator I = Defs.begin(), |
Jeff Cohen | 88e7b72 | 2005-04-22 04:13:13 +0000 | [diff] [blame] | 1410 | E = Defs.end(); I != E; ++I) |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1411 | delete I->second; |
| 1412 | } |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 1413 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1414 | const std::map<std::string, Record*> &getClasses() const { return Classes; } |
| 1415 | const std::map<std::string, Record*> &getDefs() const { return Defs; } |
| 1416 | |
| 1417 | Record *getClass(const std::string &Name) const { |
| 1418 | std::map<std::string, Record*>::const_iterator I = Classes.find(Name); |
| 1419 | return I == Classes.end() ? 0 : I->second; |
| 1420 | } |
| 1421 | Record *getDef(const std::string &Name) const { |
| 1422 | std::map<std::string, Record*>::const_iterator I = Defs.find(Name); |
| 1423 | return I == Defs.end() ? 0 : I->second; |
| 1424 | } |
| 1425 | void addClass(Record *R) { |
| 1426 | assert(getClass(R->getName()) == 0 && "Class already exists!"); |
| 1427 | Classes.insert(std::make_pair(R->getName(), R)); |
| 1428 | } |
| 1429 | void addDef(Record *R) { |
| 1430 | assert(getDef(R->getName()) == 0 && "Def already exists!"); |
| 1431 | Defs.insert(std::make_pair(R->getName(), R)); |
| 1432 | } |
| 1433 | |
Chris Lattner | ac28425 | 2005-08-19 17:58:11 +0000 | [diff] [blame] | 1434 | /// removeClass - Remove, but do not delete, the specified record. |
| 1435 | /// |
| 1436 | void removeClass(const std::string &Name) { |
| 1437 | assert(Classes.count(Name) && "Class does not exist!"); |
| 1438 | Classes.erase(Name); |
| 1439 | } |
| 1440 | /// removeDef - Remove, but do not delete, the specified record. |
| 1441 | /// |
| 1442 | void removeDef(const std::string &Name) { |
| 1443 | assert(Defs.count(Name) && "Def does not exist!"); |
| 1444 | Defs.erase(Name); |
| 1445 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1446 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1447 | //===--------------------------------------------------------------------===// |
| 1448 | // High-level helper methods, useful for tablegen backends... |
| 1449 | |
| 1450 | /// getAllDerivedDefinitions - This method returns all concrete definitions |
| 1451 | /// that derive from the specified class name. If a class with the specified |
| 1452 | /// name does not exist, an exception is thrown. |
| 1453 | std::vector<Record*> |
| 1454 | getAllDerivedDefinitions(const std::string &ClassName) const; |
| 1455 | |
| 1456 | |
| 1457 | void dump() const; |
| 1458 | }; |
| 1459 | |
Chris Lattner | bd7ccd01 | 2008-08-26 06:43:25 +0000 | [diff] [blame] | 1460 | /// LessRecord - Sorting predicate to sort record pointers by name. |
| 1461 | /// |
| 1462 | struct LessRecord { |
| 1463 | bool operator()(const Record *Rec1, const Record *Rec2) const { |
Jakob Stoklund Olesen | d1d7ed6 | 2010-05-26 21:47:28 +0000 | [diff] [blame] | 1464 | return StringRef(Rec1->getName()).compare_numeric(Rec2->getName()) < 0; |
Chris Lattner | bd7ccd01 | 2008-08-26 06:43:25 +0000 | [diff] [blame] | 1465 | } |
| 1466 | }; |
| 1467 | |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1468 | /// LessRecordFieldName - Sorting predicate to sort record pointers by their |
Jim Grosbach | 56938af | 2008-09-11 17:05:32 +0000 | [diff] [blame] | 1469 | /// name field. |
Chris Lattner | bd7ccd01 | 2008-08-26 06:43:25 +0000 | [diff] [blame] | 1470 | /// |
| 1471 | struct LessRecordFieldName { |
| 1472 | bool operator()(const Record *Rec1, const Record *Rec2) const { |
| 1473 | return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name"); |
| 1474 | } |
| 1475 | }; |
| 1476 | |
Chris Lattner | ba42e49 | 2009-03-13 16:25:21 +0000 | [diff] [blame] | 1477 | |
| 1478 | class TGError { |
Chris Lattner | 526c8cb | 2009-06-21 03:39:35 +0000 | [diff] [blame] | 1479 | SMLoc Loc; |
Chris Lattner | ba42e49 | 2009-03-13 16:25:21 +0000 | [diff] [blame] | 1480 | std::string Message; |
| 1481 | public: |
Chris Lattner | 526c8cb | 2009-06-21 03:39:35 +0000 | [diff] [blame] | 1482 | TGError(SMLoc loc, const std::string &message) : Loc(loc), Message(message) {} |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1483 | |
Chris Lattner | 526c8cb | 2009-06-21 03:39:35 +0000 | [diff] [blame] | 1484 | SMLoc getLoc() const { return Loc; } |
Chris Lattner | ba42e49 | 2009-03-13 16:25:21 +0000 | [diff] [blame] | 1485 | const std::string &getMessage() const { return Message; } |
| 1486 | }; |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1487 | |
| 1488 | |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 1489 | raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1490 | |
| 1491 | extern RecordKeeper Records; |
| 1492 | |
Chris Lattner | 526c8cb | 2009-06-21 03:39:35 +0000 | [diff] [blame] | 1493 | void PrintError(SMLoc ErrorLoc, const std::string &Msg); |
Chris Lattner | bd9b921 | 2009-03-13 16:09:24 +0000 | [diff] [blame] | 1494 | |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 1495 | } // End llvm namespace |
| 1496 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1497 | #endif |