2002-12-02 01:23:04 +00:00
|
|
|
//===- Record.h - Classes to represent Table Records ------------*- C++ -*-===//
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2003-10-20 20:20:30 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:37:13 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2003-10-20 20:20:30 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-12-02 01:23:04 +00:00
|
|
|
//
|
2003-07-31 04:37:57 +00:00
|
|
|
// This file defines the main TableGen data structures, including the TableGen
|
|
|
|
// types, values, and high-level data structures.
|
2002-12-02 01:23:04 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef RECORD_H
|
|
|
|
#define RECORD_H
|
|
|
|
|
2009-06-21 03:36:54 +00:00
|
|
|
#include "llvm/Support/SourceMgr.h"
|
2009-10-26 01:35:46 +00:00
|
|
|
#include "llvm/System/DataTypes.h"
|
2009-07-03 00:10:29 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2002-12-02 01:23:04 +00:00
|
|
|
#include <map>
|
2003-06-11 14:17:21 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
2009-07-03 00:10:29 +00:00
|
|
|
class raw_ostream;
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2005-04-19 03:36:21 +00:00
|
|
|
// RecTy subclasses.
|
2003-08-03 18:17:22 +00:00
|
|
|
class BitRecTy;
|
|
|
|
class BitsRecTy;
|
|
|
|
class IntRecTy;
|
|
|
|
class StringRecTy;
|
|
|
|
class ListRecTy;
|
|
|
|
class CodeRecTy;
|
2003-08-04 04:50:57 +00:00
|
|
|
class DagRecTy;
|
2003-08-03 18:17:22 +00:00
|
|
|
class RecordRecTy;
|
|
|
|
|
2005-04-19 03:36:21 +00:00
|
|
|
// Init subclasses.
|
2004-10-27 16:14:51 +00:00
|
|
|
struct Init;
|
2002-12-02 01:23:04 +00:00
|
|
|
class UnsetInit;
|
|
|
|
class BitInit;
|
|
|
|
class BitsInit;
|
|
|
|
class IntInit;
|
|
|
|
class StringInit;
|
2003-07-30 22:15:58 +00:00
|
|
|
class CodeInit;
|
2002-12-02 01:23:04 +00:00
|
|
|
class ListInit;
|
2009-05-14 21:22:49 +00:00
|
|
|
class UnOpInit;
|
2006-03-31 21:53:49 +00:00
|
|
|
class BinOpInit;
|
2009-05-14 21:54:42 +00:00
|
|
|
class TernOpInit;
|
2002-12-02 01:23:04 +00:00
|
|
|
class DefInit;
|
2003-08-04 20:44:17 +00:00
|
|
|
class DagInit;
|
2002-12-02 17:53:54 +00:00
|
|
|
class TypedInit;
|
|
|
|
class VarInit;
|
2002-12-02 16:42:52 +00:00
|
|
|
class FieldInit;
|
2002-12-02 17:53:54 +00:00
|
|
|
class VarBitInit;
|
2004-07-27 01:01:21 +00:00
|
|
|
class VarListElementInit;
|
2003-08-03 18:17:22 +00:00
|
|
|
|
2005-04-19 03:36:21 +00:00
|
|
|
// Other classes.
|
2002-12-02 01:23:04 +00:00
|
|
|
class Record;
|
2005-04-19 03:36:21 +00:00
|
|
|
class RecordVal;
|
2009-04-30 17:35:11 +00:00
|
|
|
struct MultiClass;
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Type Classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
struct RecTy {
|
|
|
|
virtual ~RecTy() {}
|
|
|
|
|
2007-11-20 22:25:16 +00:00
|
|
|
virtual std::string getAsString() const = 0;
|
2009-07-03 00:10:29 +00:00
|
|
|
void print(raw_ostream &OS) const { OS << getAsString(); }
|
2003-08-03 18:17:22 +00:00
|
|
|
void dump() const;
|
|
|
|
|
|
|
|
/// typeIsConvertibleTo - Return true if all values of 'this' type can be
|
|
|
|
/// converted to the specified type.
|
|
|
|
virtual bool typeIsConvertibleTo(const RecTy *RHS) const = 0;
|
|
|
|
|
|
|
|
public: // These methods should only be called from subclasses of Init
|
2002-12-02 01:23:04 +00:00
|
|
|
virtual Init *convertValue( UnsetInit *UI) { return 0; }
|
|
|
|
virtual Init *convertValue( BitInit *BI) { return 0; }
|
|
|
|
virtual Init *convertValue( BitsInit *BI) { return 0; }
|
|
|
|
virtual Init *convertValue( IntInit *II) { return 0; }
|
|
|
|
virtual Init *convertValue(StringInit *SI) { return 0; }
|
|
|
|
virtual Init *convertValue( ListInit *LI) { return 0; }
|
2009-05-14 21:22:49 +00:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) {
|
|
|
|
return convertValue((TypedInit*)UI);
|
|
|
|
}
|
2009-04-23 21:25:15 +00:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) {
|
|
|
|
return convertValue((TypedInit*)UI);
|
|
|
|
}
|
2009-05-14 21:54:42 +00:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) {
|
|
|
|
return convertValue((TypedInit*)UI);
|
|
|
|
}
|
2003-07-30 22:15:58 +00:00
|
|
|
virtual Init *convertValue( CodeInit *CI) { return 0; }
|
2002-12-02 01:23:04 +00:00
|
|
|
virtual Init *convertValue(VarBitInit *VB) { return 0; }
|
|
|
|
virtual Init *convertValue( DefInit *DI) { return 0; }
|
2003-08-04 20:44:17 +00:00
|
|
|
virtual Init *convertValue( DagInit *DI) { return 0; }
|
2002-12-02 17:53:54 +00:00
|
|
|
virtual Init *convertValue( TypedInit *TI) { return 0; }
|
|
|
|
virtual Init *convertValue( VarInit *VI) {
|
|
|
|
return convertValue((TypedInit*)VI);
|
|
|
|
}
|
|
|
|
virtual Init *convertValue( FieldInit *FI) {
|
|
|
|
return convertValue((TypedInit*)FI);
|
|
|
|
}
|
2002-12-02 01:23:04 +00:00
|
|
|
|
2003-08-03 18:17:22 +00:00
|
|
|
public: // These methods should only be called by subclasses of RecTy.
|
|
|
|
// baseClassOf - These virtual methods should be overloaded to return true iff
|
|
|
|
// all values of type 'RHS' can be converted to the 'this' type.
|
|
|
|
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
|
2003-08-04 04:50:57 +00:00
|
|
|
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
2003-08-03 18:17:22 +00:00
|
|
|
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2009-07-03 00:10:29 +00:00
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {
|
2002-12-02 01:23:04 +00:00
|
|
|
Ty.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
2002-12-02 16:13:23 +00:00
|
|
|
|
|
|
|
/// BitRecTy - 'bit' - Represent a single bit
|
|
|
|
///
|
2004-10-27 16:14:51 +00:00
|
|
|
class BitRecTy : public RecTy {
|
|
|
|
public:
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
|
|
|
|
virtual Init *convertValue( BitInit *BI) { return (Init*)BI; }
|
|
|
|
virtual Init *convertValue( BitsInit *BI);
|
|
|
|
virtual Init *convertValue( IntInit *II);
|
|
|
|
virtual Init *convertValue(StringInit *SI) { return 0; }
|
|
|
|
virtual Init *convertValue( ListInit *LI) { return 0; }
|
|
|
|
virtual Init *convertValue( CodeInit *CI) { return 0; }
|
|
|
|
virtual Init *convertValue(VarBitInit *VB) { return (Init*)VB; }
|
|
|
|
virtual Init *convertValue( DefInit *DI) { return 0; }
|
|
|
|
virtual Init *convertValue( DagInit *DI) { return 0; }
|
2009-05-14 21:22:49 +00:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-04-23 21:25:15 +00:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-05-14 21:54:42 +00:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( TypedInit *TI);
|
|
|
|
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
|
|
|
|
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
|
2002-12-02 01:23:04 +00:00
|
|
|
|
2007-11-20 22:25:16 +00:00
|
|
|
std::string getAsString() const { return "bit"; }
|
2003-08-03 18:17:22 +00:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
|
|
|
|
virtual bool baseClassOf(const BitsRecTy *RHS) const;
|
|
|
|
virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
|
|
|
|
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2002-12-02 16:13:23 +00:00
|
|
|
|
2004-04-15 15:30:15 +00:00
|
|
|
// BitsRecTy - 'bits<n>' - Represent a fixed number of bits
|
|
|
|
/// BitsRecTy - 'bits<n>' - Represent a fixed number of bits
|
2002-12-02 16:13:23 +00:00
|
|
|
///
|
2002-12-02 01:23:04 +00:00
|
|
|
class BitsRecTy : public RecTy {
|
|
|
|
unsigned Size;
|
|
|
|
public:
|
2008-07-07 18:00:37 +00:00
|
|
|
explicit BitsRecTy(unsigned Sz) : Size(Sz) {}
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
unsigned getNumBits() const { return Size; }
|
|
|
|
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( UnsetInit *UI);
|
|
|
|
virtual Init *convertValue( BitInit *UI);
|
|
|
|
virtual Init *convertValue( BitsInit *BI);
|
|
|
|
virtual Init *convertValue( IntInit *II);
|
|
|
|
virtual Init *convertValue(StringInit *SI) { return 0; }
|
|
|
|
virtual Init *convertValue( ListInit *LI) { return 0; }
|
|
|
|
virtual Init *convertValue( CodeInit *CI) { return 0; }
|
|
|
|
virtual Init *convertValue(VarBitInit *VB) { return 0; }
|
|
|
|
virtual Init *convertValue( DefInit *DI) { return 0; }
|
|
|
|
virtual Init *convertValue( DagInit *DI) { return 0; }
|
2009-05-14 21:22:49 +00:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-04-23 21:25:15 +00:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-05-14 21:54:42 +00:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( TypedInit *TI);
|
|
|
|
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
|
|
|
|
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
|
|
|
|
|
2007-11-20 22:25:16 +00:00
|
|
|
std::string getAsString() const;
|
2003-08-03 18:17:22 +00:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual bool baseClassOf(const BitRecTy *RHS) const { return Size == 1; }
|
|
|
|
virtual bool baseClassOf(const BitsRecTy *RHS) const {
|
2003-08-03 18:17:22 +00:00
|
|
|
return RHS->Size == Size;
|
|
|
|
}
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
|
|
|
|
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2002-12-02 16:13:23 +00:00
|
|
|
|
|
|
|
/// IntRecTy - 'int' - Represent an integer value of no particular size
|
|
|
|
///
|
2004-10-27 16:14:51 +00:00
|
|
|
class IntRecTy : public RecTy {
|
|
|
|
public:
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
|
|
|
|
virtual Init *convertValue( BitInit *BI);
|
|
|
|
virtual Init *convertValue( BitsInit *BI);
|
|
|
|
virtual Init *convertValue( IntInit *II) { return (Init*)II; }
|
|
|
|
virtual Init *convertValue(StringInit *SI) { return 0; }
|
|
|
|
virtual Init *convertValue( ListInit *LI) { return 0; }
|
|
|
|
virtual Init *convertValue( CodeInit *CI) { return 0; }
|
|
|
|
virtual Init *convertValue(VarBitInit *VB) { return 0; }
|
|
|
|
virtual Init *convertValue( DefInit *DI) { return 0; }
|
|
|
|
virtual Init *convertValue( DagInit *DI) { return 0; }
|
2009-05-14 21:22:49 +00:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-04-23 21:25:15 +00:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-05-14 21:54:42 +00:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( TypedInit *TI);
|
|
|
|
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
|
|
|
|
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
|
|
|
|
|
2007-11-20 22:25:16 +00:00
|
|
|
std::string getAsString() const { return "int"; }
|
2003-08-03 18:17:22 +00:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
|
|
|
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
|
|
|
|
virtual bool baseClassOf(const BitsRecTy *RHS) const { return true; }
|
|
|
|
virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
|
|
|
|
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2002-12-02 16:13:23 +00:00
|
|
|
/// StringRecTy - 'string' - Represent an string value
|
|
|
|
///
|
2004-10-27 16:14:51 +00:00
|
|
|
class StringRecTy : public RecTy {
|
|
|
|
public:
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
|
|
|
|
virtual Init *convertValue( BitInit *BI) { return 0; }
|
|
|
|
virtual Init *convertValue( BitsInit *BI) { return 0; }
|
|
|
|
virtual Init *convertValue( IntInit *II) { return 0; }
|
|
|
|
virtual Init *convertValue(StringInit *SI) { return (Init*)SI; }
|
|
|
|
virtual Init *convertValue( ListInit *LI) { return 0; }
|
2009-05-14 21:22:49 +00:00
|
|
|
virtual Init *convertValue( UnOpInit *BO);
|
2006-03-31 21:53:49 +00:00
|
|
|
virtual Init *convertValue( BinOpInit *BO);
|
2009-05-14 21:54:42 +00:00
|
|
|
virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);}
|
2009-05-14 20:54:48 +00:00
|
|
|
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( CodeInit *CI) { return 0; }
|
|
|
|
virtual Init *convertValue(VarBitInit *VB) { return 0; }
|
|
|
|
virtual Init *convertValue( DefInit *DI) { return 0; }
|
|
|
|
virtual Init *convertValue( DagInit *DI) { return 0; }
|
|
|
|
virtual Init *convertValue( TypedInit *TI);
|
|
|
|
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
|
|
|
|
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
|
|
|
|
|
2007-11-20 22:25:16 +00:00
|
|
|
std::string getAsString() const { return "string"; }
|
2003-08-03 18:17:22 +00:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
|
|
|
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
|
2003-08-03 18:17:22 +00:00
|
|
|
virtual bool baseClassOf(const StringRecTy *RHS) const { return true; }
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2004-04-15 15:30:15 +00:00
|
|
|
// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of
|
|
|
|
// the specified type.
|
|
|
|
/// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must
|
|
|
|
/// be of the specified type.
|
2002-12-02 16:13:23 +00:00
|
|
|
///
|
2002-12-02 01:23:04 +00:00
|
|
|
class ListRecTy : public RecTy {
|
2003-08-03 18:17:22 +00:00
|
|
|
RecTy *Ty;
|
2002-12-02 01:23:04 +00:00
|
|
|
public:
|
2008-07-07 18:00:37 +00:00
|
|
|
explicit ListRecTy(RecTy *T) : Ty(T) {}
|
2003-07-30 04:16:52 +00:00
|
|
|
|
2003-08-03 18:17:22 +00:00
|
|
|
RecTy *getElementType() const { return Ty; }
|
2003-07-30 04:16:52 +00:00
|
|
|
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
|
|
|
|
virtual Init *convertValue( BitInit *BI) { return 0; }
|
|
|
|
virtual Init *convertValue( BitsInit *BI) { return 0; }
|
|
|
|
virtual Init *convertValue( IntInit *II) { return 0; }
|
|
|
|
virtual Init *convertValue(StringInit *SI) { return 0; }
|
|
|
|
virtual Init *convertValue( ListInit *LI);
|
|
|
|
virtual Init *convertValue( CodeInit *CI) { return 0; }
|
|
|
|
virtual Init *convertValue(VarBitInit *VB) { return 0; }
|
|
|
|
virtual Init *convertValue( DefInit *DI) { return 0; }
|
|
|
|
virtual Init *convertValue( DagInit *DI) { return 0; }
|
2009-05-14 21:22:49 +00:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-04-23 21:25:15 +00:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-05-14 21:54:42 +00:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( TypedInit *TI);
|
|
|
|
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
|
|
|
|
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
|
2005-04-22 00:00:37 +00:00
|
|
|
|
2007-11-20 22:25:16 +00:00
|
|
|
std::string getAsString() const;
|
2003-08-03 18:17:22 +00:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
|
|
|
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const ListRecTy *RHS) const {
|
2005-04-22 00:00:37 +00:00
|
|
|
return RHS->getElementType()->typeIsConvertibleTo(Ty);
|
2003-08-03 18:17:22 +00:00
|
|
|
}
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2003-07-30 21:47:42 +00:00
|
|
|
/// CodeRecTy - 'code' - Represent an code fragment, function or method.
|
|
|
|
///
|
2004-10-27 16:14:51 +00:00
|
|
|
class CodeRecTy : public RecTy {
|
|
|
|
public:
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
|
|
|
|
virtual Init *convertValue( BitInit *BI) { return 0; }
|
|
|
|
virtual Init *convertValue( BitsInit *BI) { return 0; }
|
|
|
|
virtual Init *convertValue( IntInit *II) { return 0; }
|
|
|
|
virtual Init *convertValue(StringInit *SI) { return 0; }
|
|
|
|
virtual Init *convertValue( ListInit *LI) { return 0; }
|
|
|
|
virtual Init *convertValue( CodeInit *CI) { return (Init*)CI; }
|
|
|
|
virtual Init *convertValue(VarBitInit *VB) { return 0; }
|
|
|
|
virtual Init *convertValue( DefInit *DI) { return 0; }
|
|
|
|
virtual Init *convertValue( DagInit *DI) { return 0; }
|
2009-05-14 21:22:49 +00:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-04-23 21:25:15 +00:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-05-14 21:54:42 +00:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( TypedInit *TI);
|
|
|
|
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
|
|
|
|
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
|
|
|
|
|
2007-11-20 22:25:16 +00:00
|
|
|
std::string getAsString() const { return "code"; }
|
2003-08-03 18:17:22 +00:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const CodeRecTy *RHS) const { return true; }
|
|
|
|
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
2003-07-30 21:47:42 +00:00
|
|
|
};
|
|
|
|
|
2003-08-04 04:50:57 +00:00
|
|
|
/// DagRecTy - 'dag' - Represent a dag fragment
|
|
|
|
///
|
2004-10-27 16:14:51 +00:00
|
|
|
class DagRecTy : public RecTy {
|
|
|
|
public:
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
|
|
|
|
virtual Init *convertValue( BitInit *BI) { return 0; }
|
|
|
|
virtual Init *convertValue( BitsInit *BI) { return 0; }
|
|
|
|
virtual Init *convertValue( IntInit *II) { return 0; }
|
|
|
|
virtual Init *convertValue(StringInit *SI) { return 0; }
|
|
|
|
virtual Init *convertValue( ListInit *LI) { return 0; }
|
|
|
|
virtual Init *convertValue( CodeInit *CI) { return 0; }
|
|
|
|
virtual Init *convertValue(VarBitInit *VB) { return 0; }
|
|
|
|
virtual Init *convertValue( DefInit *DI) { return 0; }
|
2009-05-14 21:22:49 +00:00
|
|
|
virtual Init *convertValue( UnOpInit *BO);
|
2007-05-15 01:23:24 +00:00
|
|
|
virtual Init *convertValue( BinOpInit *BO);
|
2009-05-14 21:54:42 +00:00
|
|
|
virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);}
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( DagInit *CI) { return (Init*)CI; }
|
|
|
|
virtual Init *convertValue( TypedInit *TI);
|
|
|
|
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
|
|
|
|
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
|
2003-08-04 04:50:57 +00:00
|
|
|
|
2007-11-20 22:25:16 +00:00
|
|
|
std::string getAsString() const { return "dag"; }
|
2003-08-04 04:50:57 +00:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
2004-12-06 23:42:37 +00:00
|
|
|
|
|
|
|
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const DagRecTy *RHS) const { return true; }
|
|
|
|
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
2003-08-04 04:50:57 +00:00
|
|
|
};
|
|
|
|
|
2003-07-30 21:47:42 +00:00
|
|
|
|
2004-04-15 15:30:15 +00:00
|
|
|
/// RecordRecTy - '[classname]' - Represent an instance of a class, such as:
|
2002-12-02 16:13:23 +00:00
|
|
|
/// (R32 X = EAX).
|
|
|
|
///
|
2002-12-02 01:23:04 +00:00
|
|
|
class RecordRecTy : public RecTy {
|
|
|
|
Record *Rec;
|
|
|
|
public:
|
2008-07-07 18:00:37 +00:00
|
|
|
explicit RecordRecTy(Record *R) : Rec(R) {}
|
2002-12-02 01:23:04 +00:00
|
|
|
|
2002-12-02 16:42:52 +00:00
|
|
|
Record *getRecord() const { return Rec; }
|
|
|
|
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
|
|
|
|
virtual Init *convertValue( BitInit *BI) { return 0; }
|
|
|
|
virtual Init *convertValue( BitsInit *BI) { return 0; }
|
|
|
|
virtual Init *convertValue( IntInit *II) { return 0; }
|
|
|
|
virtual Init *convertValue(StringInit *SI) { return 0; }
|
|
|
|
virtual Init *convertValue( ListInit *LI) { return 0; }
|
|
|
|
virtual Init *convertValue( CodeInit *CI) { return 0; }
|
|
|
|
virtual Init *convertValue(VarBitInit *VB) { return 0; }
|
2009-05-14 21:22:49 +00:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-04-23 21:25:15 +00:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-05-14 21:54:42 +00:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( DefInit *DI);
|
|
|
|
virtual Init *convertValue( DagInit *DI) { return 0; }
|
2005-04-22 00:00:37 +00:00
|
|
|
virtual Init *convertValue( TypedInit *VI);
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
|
|
|
|
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
|
2002-12-02 01:23:04 +00:00
|
|
|
|
2007-11-20 22:25:16 +00:00
|
|
|
std::string getAsString() const;
|
2003-08-03 18:17:22 +00:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
2004-12-06 23:42:37 +00:00
|
|
|
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
2003-08-03 18:17:22 +00:00
|
|
|
virtual bool baseClassOf(const RecordRecTy *RHS) const;
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2009-11-22 04:24:42 +00:00
|
|
|
/// resolveTypes - Find a common type that T1 and T2 convert to.
|
2009-06-08 20:23:18 +00:00
|
|
|
/// Return 0 if no such type exists.
|
|
|
|
///
|
|
|
|
RecTy *resolveTypes(RecTy *T1, RecTy *T2);
|
2002-12-02 16:13:23 +00:00
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Initializer Classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
struct Init {
|
|
|
|
virtual ~Init() {}
|
|
|
|
|
2002-12-02 16:57:01 +00:00
|
|
|
/// isComplete - This virtual method should be overridden by values that may
|
|
|
|
/// not be completely specified yet.
|
|
|
|
virtual bool isComplete() const { return true; }
|
|
|
|
|
|
|
|
/// print - Print out this value.
|
2009-07-03 00:10:29 +00:00
|
|
|
void print(raw_ostream &OS) const { OS << getAsString(); }
|
2007-11-22 21:05:25 +00:00
|
|
|
|
|
|
|
/// getAsString - Convert this value to a string form.
|
|
|
|
virtual std::string getAsString() const = 0;
|
2002-12-02 16:57:01 +00:00
|
|
|
|
|
|
|
/// dump - Debugging method that may be called through a debugger, just
|
2009-07-03 00:10:29 +00:00
|
|
|
/// invokes print on stderr.
|
2002-12-02 01:23:04 +00:00
|
|
|
void dump() const;
|
|
|
|
|
2002-12-02 16:57:01 +00:00
|
|
|
/// convertInitializerTo - This virtual function is a simple call-back
|
|
|
|
/// function that should be overridden to call the appropriate
|
|
|
|
/// RecTy::convertValue method.
|
|
|
|
///
|
2002-12-02 01:23:04 +00:00
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) = 0;
|
2002-12-02 16:57:01 +00:00
|
|
|
|
|
|
|
/// convertInitializerBitRange - This method is used to implement the bitrange
|
|
|
|
/// selection operator. Given an initializer, it selects the specified bits
|
2002-12-02 17:43:58 +00:00
|
|
|
/// out, returning them as a new init of bits type. If it is not legal to use
|
|
|
|
/// the bit subscript operator on this initializer, return null.
|
2002-12-02 16:57:01 +00:00
|
|
|
///
|
2002-12-02 01:23:04 +00:00
|
|
|
virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Add initial support for list slices. This currently allows you to do stuff
like this:
def B {
list<int> X = [10, 20, 30, 4, 1, 1231, 20] [2-4,2,2,0-6];
}
... which isn't particularly useful, but more is to come.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15247 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-26 23:21:34 +00:00
|
|
|
/// convertInitListSlice - This method is used to implement the list slice
|
|
|
|
/// selection operator. Given an initializer, it selects the specified list
|
|
|
|
/// elements, returning them as a new init of list type. If it is not legal
|
|
|
|
/// to take a slice of this, return null.
|
|
|
|
///
|
|
|
|
virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-02 16:42:52 +00:00
|
|
|
/// getFieldType - This method is used to implement the FieldInit class.
|
|
|
|
/// Implementors of this method should return the type of the named field if
|
|
|
|
/// they are of record type.
|
|
|
|
///
|
|
|
|
virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; }
|
|
|
|
|
2002-12-03 06:00:33 +00:00
|
|
|
/// getFieldInit - This method complements getFieldType to return the
|
|
|
|
/// initializer for the specified field. If getFieldType returns non-null
|
|
|
|
/// this method should return non-null, otherwise it returns null.
|
|
|
|
///
|
2010-03-25 06:23:34 +00:00
|
|
|
virtual Init *getFieldInit(Record &R, const RecordVal *RV,
|
|
|
|
const std::string &FieldName) const {
|
2002-12-03 06:00:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-22 00:00:37 +00:00
|
|
|
|
2002-12-02 16:57:01 +00:00
|
|
|
/// resolveReferences - This method is used by classes that refer to other
|
2009-11-21 22:44:20 +00:00
|
|
|
/// variables which may not be defined at the time the expression is formed.
|
2002-12-02 16:57:01 +00:00
|
|
|
/// If a value is set for the variable later, this method will be called on
|
|
|
|
/// users of the value to allow the value to propagate out.
|
|
|
|
///
|
2005-04-19 03:36:21 +00:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV) {
|
|
|
|
return this;
|
|
|
|
}
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2009-07-03 00:10:29 +00:00
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) {
|
2002-12-02 01:23:04 +00:00
|
|
|
I.print(OS); return OS;
|
|
|
|
}
|
|
|
|
|
2009-05-14 22:23:47 +00:00
|
|
|
/// TypedInit - This is the common super-class of types that have a specific,
|
|
|
|
/// explicit, type.
|
|
|
|
///
|
|
|
|
class TypedInit : public Init {
|
|
|
|
RecTy *Ty;
|
|
|
|
public:
|
|
|
|
explicit TypedInit(RecTy *T) : Ty(T) {}
|
|
|
|
|
|
|
|
RecTy *getType() const { return Ty; }
|
|
|
|
|
|
|
|
virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
|
|
|
|
virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements);
|
|
|
|
|
2010-09-03 21:00:49 +00:00
|
|
|
/// getFieldType - This method is used to implement the FieldInit class.
|
|
|
|
/// Implementors of this method should return the type of the named field if
|
|
|
|
/// they are of record type.
|
|
|
|
///
|
|
|
|
virtual RecTy *getFieldType(const std::string &FieldName) const;
|
|
|
|
|
2009-05-14 22:23:47 +00:00
|
|
|
/// resolveBitReference - This method is used to implement
|
|
|
|
/// VarBitInit::resolveReferences. If the bit is able to be resolved, we
|
|
|
|
/// simply return the resolved value, otherwise we return null.
|
|
|
|
///
|
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit) = 0;
|
|
|
|
|
|
|
|
/// resolveListElementReference - This method is used to implement
|
|
|
|
/// VarListElementInit::resolveReferences. If the list element is resolvable
|
|
|
|
/// now, we return the resolved value, otherwise we return null.
|
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt) = 0;
|
|
|
|
};
|
|
|
|
|
2002-12-02 16:13:23 +00:00
|
|
|
|
|
|
|
/// UnsetInit - ? - Represents an uninitialized value
|
|
|
|
///
|
2004-10-27 16:14:51 +00:00
|
|
|
class UnsetInit : public Init {
|
|
|
|
public:
|
2002-12-02 01:23:04 +00:00
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isComplete() const { return false; }
|
2007-11-22 21:05:25 +00:00
|
|
|
virtual std::string getAsString() const { return "?"; }
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2002-12-02 16:13:23 +00:00
|
|
|
|
|
|
|
/// BitInit - true/false - Represent a concrete initializer for a bit.
|
|
|
|
///
|
2002-12-02 01:23:04 +00:00
|
|
|
class BitInit : public Init {
|
|
|
|
bool Value;
|
|
|
|
public:
|
2008-03-25 22:06:05 +00:00
|
|
|
explicit BitInit(bool V) : Value(V) {}
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
bool getValue() const { return Value; }
|
|
|
|
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
2007-11-22 21:05:25 +00:00
|
|
|
virtual std::string getAsString() const { return Value ? "1" : "0"; }
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2002-12-02 16:13:23 +00:00
|
|
|
/// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value.
|
|
|
|
/// It contains a vector of bits, whose size is determined by the type.
|
|
|
|
///
|
2002-12-02 01:23:04 +00:00
|
|
|
class BitsInit : public Init {
|
|
|
|
std::vector<Init*> Bits;
|
|
|
|
public:
|
2008-03-25 22:06:05 +00:00
|
|
|
explicit BitsInit(unsigned Size) : Bits(Size) {}
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
unsigned getNumBits() const { return Bits.size(); }
|
|
|
|
|
|
|
|
Init *getBit(unsigned Bit) const {
|
|
|
|
assert(Bit < Bits.size() && "Bit index out of range!");
|
|
|
|
return Bits[Bit];
|
|
|
|
}
|
|
|
|
void setBit(unsigned Bit, Init *V) {
|
|
|
|
assert(Bit < Bits.size() && "Bit index out of range!");
|
2002-12-06 03:55:39 +00:00
|
|
|
assert(Bits[Bit] == 0 && "Bit already set!");
|
2002-12-02 01:23:04 +00:00
|
|
|
Bits[Bit] = V;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
|
|
|
|
|
|
|
|
virtual bool isComplete() const {
|
|
|
|
for (unsigned i = 0; i != getNumBits(); ++i)
|
|
|
|
if (!getBit(i)->isComplete()) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2010-04-09 21:01:02 +00:00
|
|
|
bool allInComplete() const {
|
|
|
|
for (unsigned i = 0; i != getNumBits(); ++i)
|
|
|
|
if (getBit(i)->isComplete()) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2007-11-22 21:05:25 +00:00
|
|
|
virtual std::string getAsString() const;
|
2002-12-02 01:23:04 +00:00
|
|
|
|
2005-04-19 03:36:21 +00:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2002-12-02 16:13:23 +00:00
|
|
|
|
|
|
|
/// IntInit - 7 - Represent an initalization by a literal integer value.
|
|
|
|
///
|
2009-06-08 20:23:18 +00:00
|
|
|
class IntInit : public TypedInit {
|
2008-10-17 01:33:43 +00:00
|
|
|
int64_t Value;
|
2002-12-02 01:23:04 +00:00
|
|
|
public:
|
2009-06-08 20:23:18 +00:00
|
|
|
explicit IntInit(int64_t V) : TypedInit(new IntRecTy), Value(V) {}
|
2002-12-02 01:23:04 +00:00
|
|
|
|
2008-10-17 01:33:43 +00:00
|
|
|
int64_t getValue() const { return Value; }
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
|
|
|
|
|
2007-11-22 21:05:25 +00:00
|
|
|
virtual std::string getAsString() const;
|
2009-06-08 20:23:18 +00:00
|
|
|
|
|
|
|
/// resolveBitReference - This method is used to implement
|
|
|
|
/// VarBitInit::resolveReferences. If the bit is able to be resolved, we
|
|
|
|
/// simply return the resolved value, otherwise we return null.
|
|
|
|
///
|
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit) {
|
|
|
|
assert(0 && "Illegal bit reference off int");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// resolveListElementReference - This method is used to implement
|
|
|
|
/// VarListElementInit::resolveReferences. If the list element is resolvable
|
|
|
|
/// now, we return the resolved value, otherwise we return null.
|
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt) {
|
|
|
|
assert(0 && "Illegal element reference off int");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2002-12-02 16:13:23 +00:00
|
|
|
|
|
|
|
/// StringInit - "foo" - Represent an initialization by a string value.
|
|
|
|
///
|
2009-05-14 22:23:47 +00:00
|
|
|
class StringInit : public TypedInit {
|
2002-12-02 01:23:04 +00:00
|
|
|
std::string Value;
|
|
|
|
public:
|
2009-05-15 03:03:14 +00:00
|
|
|
explicit StringInit(const std::string &V)
|
|
|
|
: TypedInit(new StringRecTy), Value(V) {}
|
2002-12-02 01:23:04 +00:00
|
|
|
|
2003-08-01 04:37:57 +00:00
|
|
|
const std::string &getValue() const { return Value; }
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
2007-11-22 21:05:25 +00:00
|
|
|
virtual std::string getAsString() const { return "\"" + Value + "\""; }
|
2009-05-14 22:23:47 +00:00
|
|
|
|
|
|
|
/// resolveBitReference - This method is used to implement
|
|
|
|
/// VarBitInit::resolveReferences. If the bit is able to be resolved, we
|
|
|
|
/// simply return the resolved value, otherwise we return null.
|
|
|
|
///
|
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit) {
|
|
|
|
assert(0 && "Illegal bit reference off string");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// resolveListElementReference - This method is used to implement
|
|
|
|
/// VarListElementInit::resolveReferences. If the list element is resolvable
|
|
|
|
/// now, we return the resolved value, otherwise we return null.
|
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt) {
|
|
|
|
assert(0 && "Illegal element reference off string");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2003-07-30 22:15:58 +00:00
|
|
|
/// CodeInit - "[{...}]" - Represent a code fragment.
|
|
|
|
///
|
|
|
|
class CodeInit : public Init {
|
|
|
|
std::string Value;
|
|
|
|
public:
|
2008-03-25 22:06:05 +00:00
|
|
|
explicit CodeInit(const std::string &V) : Value(V) {}
|
2003-07-30 22:15:58 +00:00
|
|
|
|
2003-08-01 06:27:59 +00:00
|
|
|
const std::string getValue() const { return Value; }
|
|
|
|
|
2003-07-30 22:15:58 +00:00
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
2007-11-22 21:05:25 +00:00
|
|
|
virtual std::string getAsString() const { return "[{" + Value + "}]"; }
|
2003-07-30 22:15:58 +00:00
|
|
|
};
|
|
|
|
|
2002-12-02 16:13:23 +00:00
|
|
|
/// ListInit - [AL, AH, CL] - Represent a list of defs
|
|
|
|
///
|
2009-06-08 20:23:18 +00:00
|
|
|
class ListInit : public TypedInit {
|
2003-08-03 18:17:22 +00:00
|
|
|
std::vector<Init*> Values;
|
2002-12-02 01:23:04 +00:00
|
|
|
public:
|
2009-05-14 22:38:31 +00:00
|
|
|
typedef std::vector<Init*>::iterator iterator;
|
|
|
|
typedef std::vector<Init*>::const_iterator const_iterator;
|
|
|
|
|
2009-06-08 20:23:18 +00:00
|
|
|
explicit ListInit(std::vector<Init*> &Vs, RecTy *EltTy)
|
|
|
|
: TypedInit(new ListRecTy(EltTy)) {
|
2003-08-03 18:17:22 +00:00
|
|
|
Values.swap(Vs);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
2009-06-08 20:23:18 +00:00
|
|
|
explicit ListInit(iterator Start, iterator End, RecTy *EltTy)
|
|
|
|
: TypedInit(new ListRecTy(EltTy)), Values(Start, End) {}
|
2002-12-02 01:23:04 +00:00
|
|
|
|
2003-08-03 18:17:22 +00:00
|
|
|
unsigned getSize() const { return Values.size(); }
|
|
|
|
Init *getElement(unsigned i) const {
|
|
|
|
assert(i < Values.size() && "List element index out of range!");
|
|
|
|
return Values[i];
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
|
2007-02-27 22:08:27 +00:00
|
|
|
Record *getElementAsRecord(unsigned i) const;
|
2009-11-22 04:24:42 +00:00
|
|
|
|
Add initial support for list slices. This currently allows you to do stuff
like this:
def B {
list<int> X = [10, 20, 30, 4, 1, 1231, 20] [2-4,2,2,0-6];
}
... which isn't particularly useful, but more is to come.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15247 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-26 23:21:34 +00:00
|
|
|
Init *convertInitListSlice(const std::vector<unsigned> &Elements);
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
2004-07-27 01:01:21 +00:00
|
|
|
/// resolveReferences - This method is used by classes that refer to other
|
|
|
|
/// variables which may not be defined at the time they expression is formed.
|
|
|
|
/// If a value is set for the variable later, this method will be called on
|
|
|
|
/// users of the value to allow the value to propagate out.
|
|
|
|
///
|
2005-04-19 03:36:21 +00:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2004-07-27 01:01:21 +00:00
|
|
|
|
2007-11-22 21:05:25 +00:00
|
|
|
virtual std::string getAsString() const;
|
2008-01-21 22:30:26 +00:00
|
|
|
|
|
|
|
inline iterator begin() { return Values.begin(); }
|
|
|
|
inline const_iterator begin() const { return Values.begin(); }
|
|
|
|
inline iterator end () { return Values.end(); }
|
|
|
|
inline const_iterator end () const { return Values.end(); }
|
|
|
|
|
|
|
|
inline size_t size () const { return Values.size(); }
|
|
|
|
inline bool empty() const { return Values.empty(); }
|
2009-06-08 20:23:18 +00:00
|
|
|
|
|
|
|
/// resolveBitReference - This method is used to implement
|
|
|
|
/// VarBitInit::resolveReferences. If the bit is able to be resolved, we
|
|
|
|
/// simply return the resolved value, otherwise we return null.
|
|
|
|
///
|
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit) {
|
|
|
|
assert(0 && "Illegal bit reference off list");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// resolveListElementReference - This method is used to implement
|
|
|
|
/// VarListElementInit::resolveReferences. If the list element is resolvable
|
|
|
|
/// now, we return the resolved value, otherwise we return null.
|
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt);
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2002-12-02 17:43:58 +00:00
|
|
|
|
2009-05-14 20:54:48 +00:00
|
|
|
/// OpInit - Base class for operators
|
|
|
|
///
|
|
|
|
class OpInit : public TypedInit {
|
|
|
|
public:
|
|
|
|
OpInit(RecTy *Type) : TypedInit(Type) {}
|
|
|
|
|
|
|
|
// Clone - Clone this operator, replacing arguments with the new list
|
|
|
|
virtual OpInit *clone(std::vector<Init *> &Operands) = 0;
|
|
|
|
|
2009-08-12 22:10:57 +00:00
|
|
|
virtual int getNumOperands() const = 0;
|
2009-05-14 20:54:48 +00:00
|
|
|
virtual Init *getOperand(int i) = 0;
|
|
|
|
|
|
|
|
// Fold - If possible, fold this to a simpler init. Return this if not
|
|
|
|
// possible to fold.
|
|
|
|
virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) = 0;
|
|
|
|
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2009-05-14 20:54:48 +00:00
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit);
|
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// UnOpInit - !op (X) - Transform an init.
|
|
|
|
///
|
2009-05-14 21:22:49 +00:00
|
|
|
class UnOpInit : public OpInit {
|
|
|
|
public:
|
2009-05-14 22:38:31 +00:00
|
|
|
enum UnaryOp { CAST, CAR, CDR, LNULL };
|
2009-05-14 21:22:49 +00:00
|
|
|
private:
|
|
|
|
UnaryOp Opc;
|
|
|
|
Init *LHS;
|
|
|
|
public:
|
|
|
|
UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type) :
|
|
|
|
OpInit(Type), Opc(opc), LHS(lhs) {
|
|
|
|
}
|
2009-05-14 20:54:48 +00:00
|
|
|
|
2009-05-14 21:22:49 +00:00
|
|
|
// Clone - Clone this operator, replacing arguments with the new list
|
|
|
|
virtual OpInit *clone(std::vector<Init *> &Operands) {
|
2009-05-15 03:03:14 +00:00
|
|
|
assert(Operands.size() == 1 &&
|
|
|
|
"Wrong number of operands for unary operation");
|
2009-05-14 21:22:49 +00:00
|
|
|
return new UnOpInit(getOpcode(), *Operands.begin(), getType());
|
|
|
|
}
|
2009-05-14 20:54:48 +00:00
|
|
|
|
2009-08-12 22:10:57 +00:00
|
|
|
int getNumOperands() const { return 1; }
|
2009-05-14 21:22:49 +00:00
|
|
|
Init *getOperand(int i) {
|
|
|
|
assert(i == 0 && "Invalid operand id for unary operator");
|
|
|
|
return getOperand();
|
|
|
|
}
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2009-05-14 21:22:49 +00:00
|
|
|
UnaryOp getOpcode() const { return Opc; }
|
|
|
|
Init *getOperand() const { return LHS; }
|
2009-05-14 20:54:48 +00:00
|
|
|
|
2009-05-14 21:22:49 +00:00
|
|
|
// Fold - If possible, fold this to a simpler init. Return this if not
|
|
|
|
// possible to fold.
|
|
|
|
Init *Fold(Record *CurRec, MultiClass *CurMultiClass);
|
2009-05-14 20:54:48 +00:00
|
|
|
|
2009-05-14 21:22:49 +00:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2009-05-14 21:22:49 +00:00
|
|
|
virtual std::string getAsString() const;
|
|
|
|
};
|
2009-04-23 21:25:15 +00:00
|
|
|
|
|
|
|
/// BinOpInit - !op (X, Y) - Combine two inits.
|
|
|
|
///
|
2009-05-14 20:54:48 +00:00
|
|
|
class BinOpInit : public OpInit {
|
2009-04-23 21:25:15 +00:00
|
|
|
public:
|
2010-01-05 19:11:42 +00:00
|
|
|
enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, NAMECONCAT, EQ };
|
2009-04-23 21:25:15 +00:00
|
|
|
private:
|
|
|
|
BinaryOp Opc;
|
|
|
|
Init *LHS, *RHS;
|
|
|
|
public:
|
|
|
|
BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) :
|
2009-05-14 20:54:48 +00:00
|
|
|
OpInit(Type), Opc(opc), LHS(lhs), RHS(rhs) {
|
2009-04-23 21:25:15 +00:00
|
|
|
}
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2009-05-14 20:54:48 +00:00
|
|
|
// Clone - Clone this operator, replacing arguments with the new list
|
|
|
|
virtual OpInit *clone(std::vector<Init *> &Operands) {
|
2009-05-15 03:03:14 +00:00
|
|
|
assert(Operands.size() == 2 &&
|
|
|
|
"Wrong number of operands for binary operation");
|
2009-05-14 20:54:48 +00:00
|
|
|
return new BinOpInit(getOpcode(), Operands[0], Operands[1], getType());
|
|
|
|
}
|
|
|
|
|
2009-08-12 22:10:57 +00:00
|
|
|
int getNumOperands() const { return 2; }
|
2009-05-14 20:54:48 +00:00
|
|
|
Init *getOperand(int i) {
|
2009-05-15 03:03:14 +00:00
|
|
|
assert((i == 0 || i == 1) && "Invalid operand id for binary operator");
|
2009-05-14 20:54:48 +00:00
|
|
|
if (i == 0) {
|
|
|
|
return getLHS();
|
2009-11-22 04:24:42 +00:00
|
|
|
} else {
|
2009-05-14 20:54:48 +00:00
|
|
|
return getRHS();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-23 21:25:15 +00:00
|
|
|
BinaryOp getOpcode() const { return Opc; }
|
|
|
|
Init *getLHS() const { return LHS; }
|
|
|
|
Init *getRHS() const { return RHS; }
|
|
|
|
|
|
|
|
// Fold - If possible, fold this to a simpler init. Return this if not
|
|
|
|
// possible to fold.
|
|
|
|
Init *Fold(Record *CurRec, MultiClass *CurMultiClass);
|
|
|
|
|
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2009-04-23 21:25:15 +00:00
|
|
|
virtual std::string getAsString() const;
|
|
|
|
};
|
|
|
|
|
2009-05-14 20:54:48 +00:00
|
|
|
/// TernOpInit - !op (X, Y, Z) - Combine two inits.
|
|
|
|
///
|
2009-05-14 21:54:42 +00:00
|
|
|
class TernOpInit : public OpInit {
|
|
|
|
public:
|
2009-06-09 18:31:17 +00:00
|
|
|
enum TernaryOp { SUBST, FOREACH, IF };
|
2009-05-14 21:54:42 +00:00
|
|
|
private:
|
|
|
|
TernaryOp Opc;
|
|
|
|
Init *LHS, *MHS, *RHS;
|
|
|
|
public:
|
|
|
|
TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type) :
|
|
|
|
OpInit(Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) {
|
|
|
|
}
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2009-05-14 21:54:42 +00:00
|
|
|
// Clone - Clone this operator, replacing arguments with the new list
|
|
|
|
virtual OpInit *clone(std::vector<Init *> &Operands) {
|
2009-05-15 03:03:14 +00:00
|
|
|
assert(Operands.size() == 3 &&
|
|
|
|
"Wrong number of operands for ternary operation");
|
|
|
|
return new TernOpInit(getOpcode(), Operands[0], Operands[1], Operands[2],
|
|
|
|
getType());
|
2009-05-14 21:54:42 +00:00
|
|
|
}
|
|
|
|
|
2009-08-12 22:10:57 +00:00
|
|
|
int getNumOperands() const { return 3; }
|
2009-05-14 21:54:42 +00:00
|
|
|
Init *getOperand(int i) {
|
2009-05-15 03:03:14 +00:00
|
|
|
assert((i == 0 || i == 1 || i == 2) &&
|
|
|
|
"Invalid operand id for ternary operator");
|
2009-05-14 21:54:42 +00:00
|
|
|
if (i == 0) {
|
|
|
|
return getLHS();
|
2009-11-22 04:24:42 +00:00
|
|
|
} else if (i == 1) {
|
2009-05-14 21:54:42 +00:00
|
|
|
return getMHS();
|
2009-11-22 04:24:42 +00:00
|
|
|
} else {
|
2009-05-14 21:54:42 +00:00
|
|
|
return getRHS();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TernaryOp getOpcode() const { return Opc; }
|
|
|
|
Init *getLHS() const { return LHS; }
|
|
|
|
Init *getMHS() const { return MHS; }
|
|
|
|
Init *getRHS() const { return RHS; }
|
|
|
|
|
|
|
|
// Fold - If possible, fold this to a simpler init. Return this if not
|
|
|
|
// possible to fold.
|
|
|
|
Init *Fold(Record *CurRec, MultiClass *CurMultiClass);
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2009-05-14 21:54:42 +00:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2009-05-14 21:54:42 +00:00
|
|
|
virtual std::string getAsString() const;
|
|
|
|
};
|
2009-05-14 20:54:48 +00:00
|
|
|
|
2009-04-23 21:25:15 +00:00
|
|
|
|
2002-12-02 16:13:23 +00:00
|
|
|
/// VarInit - 'Opcode' - Represent a reference to an entire variable object.
|
|
|
|
///
|
2002-12-02 17:43:58 +00:00
|
|
|
class VarInit : public TypedInit {
|
2002-12-02 01:23:04 +00:00
|
|
|
std::string VarName;
|
|
|
|
public:
|
2008-03-25 22:06:05 +00:00
|
|
|
explicit VarInit(const std::string &VN, RecTy *T)
|
|
|
|
: TypedInit(T), VarName(VN) {}
|
2005-04-22 00:00:37 +00:00
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string &getName() const { return VarName; }
|
|
|
|
|
2005-04-19 03:36:21 +00:00
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit);
|
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt);
|
2002-12-02 17:43:58 +00:00
|
|
|
|
2002-12-02 16:42:52 +00:00
|
|
|
virtual RecTy *getFieldType(const std::string &FieldName) const;
|
2010-03-25 06:23:34 +00:00
|
|
|
virtual Init *getFieldInit(Record &R, const RecordVal *RV,
|
|
|
|
const std::string &FieldName) const;
|
2003-07-30 04:05:07 +00:00
|
|
|
|
|
|
|
/// resolveReferences - This method is used by classes that refer to other
|
|
|
|
/// variables which may not be defined at the time they expression is formed.
|
|
|
|
/// If a value is set for the variable later, this method will be called on
|
|
|
|
/// users of the value to allow the value to propagate out.
|
|
|
|
///
|
2005-04-19 03:36:21 +00:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2005-04-22 00:00:37 +00:00
|
|
|
|
2007-11-22 21:05:25 +00:00
|
|
|
virtual std::string getAsString() const { return VarName; }
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2002-12-02 16:13:23 +00:00
|
|
|
|
2002-12-02 17:43:58 +00:00
|
|
|
/// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field.
|
2002-12-02 16:13:23 +00:00
|
|
|
///
|
2002-12-02 01:23:04 +00:00
|
|
|
class VarBitInit : public Init {
|
2002-12-02 17:43:58 +00:00
|
|
|
TypedInit *TI;
|
2002-12-02 01:23:04 +00:00
|
|
|
unsigned Bit;
|
|
|
|
public:
|
2002-12-02 17:43:58 +00:00
|
|
|
VarBitInit(TypedInit *T, unsigned B) : TI(T), Bit(B) {
|
|
|
|
assert(T->getType() && dynamic_cast<BitsRecTy*>(T->getType()) &&
|
|
|
|
((BitsRecTy*)T->getType())->getNumBits() > B &&
|
|
|
|
"Illegal VarBitInit expression!");
|
|
|
|
}
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
2002-12-02 17:43:58 +00:00
|
|
|
TypedInit *getVariable() const { return TI; }
|
2002-12-02 01:23:04 +00:00
|
|
|
unsigned getBitNum() const { return Bit; }
|
2005-04-22 00:00:37 +00:00
|
|
|
|
2007-11-22 21:05:25 +00:00
|
|
|
virtual std::string getAsString() const;
|
2005-04-19 03:36:21 +00:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2005-04-22 00:00:37 +00:00
|
|
|
/// VarListElementInit - List[4] - Represent access to one element of a var or
|
2004-07-27 01:01:21 +00:00
|
|
|
/// field.
|
|
|
|
class VarListElementInit : public TypedInit {
|
|
|
|
TypedInit *TI;
|
|
|
|
unsigned Element;
|
|
|
|
public:
|
|
|
|
VarListElementInit(TypedInit *T, unsigned E)
|
|
|
|
: TypedInit(dynamic_cast<ListRecTy*>(T->getType())->getElementType()),
|
|
|
|
TI(T), Element(E) {
|
|
|
|
assert(T->getType() && dynamic_cast<ListRecTy*>(T->getType()) &&
|
|
|
|
"Illegal VarBitInit expression!");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
TypedInit *getVariable() const { return TI; }
|
|
|
|
unsigned getElementNum() const { return Element; }
|
|
|
|
|
2005-04-19 03:36:21 +00:00
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit);
|
2004-07-27 01:01:21 +00:00
|
|
|
|
|
|
|
/// resolveListElementReference - This method is used to implement
|
|
|
|
/// VarListElementInit::resolveReferences. If the list element is resolvable
|
|
|
|
/// now, we return the resolved value, otherwise we return null.
|
2005-04-19 03:36:21 +00:00
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt);
|
2004-07-27 01:01:21 +00:00
|
|
|
|
2007-11-22 21:05:25 +00:00
|
|
|
virtual std::string getAsString() const;
|
2005-04-19 03:36:21 +00:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2004-07-27 01:01:21 +00:00
|
|
|
};
|
2002-12-02 16:13:23 +00:00
|
|
|
|
|
|
|
/// DefInit - AL - Represent a reference to a 'def' in the description
|
|
|
|
///
|
2009-05-14 22:23:47 +00:00
|
|
|
class DefInit : public TypedInit {
|
2002-12-02 01:23:04 +00:00
|
|
|
Record *Def;
|
|
|
|
public:
|
2009-05-14 22:23:47 +00:00
|
|
|
explicit DefInit(Record *D) : TypedInit(new RecordRecTy(D)), Def(D) {}
|
2005-04-22 00:00:37 +00:00
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Record *getDef() const { return Def; }
|
|
|
|
|
|
|
|
//virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
|
2002-12-03 06:00:33 +00:00
|
|
|
|
|
|
|
virtual RecTy *getFieldType(const std::string &FieldName) const;
|
2010-03-25 06:23:34 +00:00
|
|
|
virtual Init *getFieldInit(Record &R, const RecordVal *RV,
|
|
|
|
const std::string &FieldName) const;
|
2005-04-22 00:00:37 +00:00
|
|
|
|
2007-11-22 21:05:25 +00:00
|
|
|
virtual std::string getAsString() const;
|
2009-05-14 22:23:47 +00:00
|
|
|
|
|
|
|
/// resolveBitReference - This method is used to implement
|
|
|
|
/// VarBitInit::resolveReferences. If the bit is able to be resolved, we
|
|
|
|
/// simply return the resolved value, otherwise we return null.
|
|
|
|
///
|
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit) {
|
|
|
|
assert(0 && "Illegal bit reference off def");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// resolveListElementReference - This method is used to implement
|
|
|
|
/// VarListElementInit::resolveReferences. If the list element is resolvable
|
|
|
|
/// now, we return the resolved value, otherwise we return null.
|
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt) {
|
|
|
|
assert(0 && "Illegal element reference off def");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-12-02 16:42:52 +00:00
|
|
|
/// FieldInit - X.Y - Represent a reference to a subfield of a variable
|
|
|
|
///
|
2002-12-02 17:43:58 +00:00
|
|
|
class FieldInit : public TypedInit {
|
2002-12-02 16:42:52 +00:00
|
|
|
Init *Rec; // Record we are referring to
|
|
|
|
std::string FieldName; // Field we are accessing
|
|
|
|
public:
|
|
|
|
FieldInit(Init *R, const std::string &FN)
|
2002-12-02 17:43:58 +00:00
|
|
|
: TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) {
|
|
|
|
assert(getType() && "FieldInit with non-record type!");
|
2002-12-02 16:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
2005-04-19 03:36:21 +00:00
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit);
|
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt);
|
2002-12-02 17:43:58 +00:00
|
|
|
|
2005-04-19 03:36:21 +00:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2003-08-01 05:58:58 +00:00
|
|
|
|
2007-11-22 21:05:25 +00:00
|
|
|
virtual std::string getAsString() const {
|
|
|
|
return Rec->getAsString() + "." + FieldName;
|
2002-12-02 16:42:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-03-30 22:50:40 +00:00
|
|
|
/// DagInit - (v a, b) - Represent a DAG tree value. DAG inits are required
|
|
|
|
/// to have at least one value then a (possibly empty) list of arguments. Each
|
|
|
|
/// argument can have a name associated with it.
|
2003-08-04 20:44:17 +00:00
|
|
|
///
|
2009-05-14 22:23:47 +00:00
|
|
|
class DagInit : public TypedInit {
|
2006-03-30 22:50:40 +00:00
|
|
|
Init *Val;
|
2009-03-19 05:21:56 +00:00
|
|
|
std::string ValName;
|
2003-08-04 20:44:17 +00:00
|
|
|
std::vector<Init*> Args;
|
2003-08-10 22:14:13 +00:00
|
|
|
std::vector<std::string> ArgNames;
|
2003-08-04 20:44:17 +00:00
|
|
|
public:
|
2009-11-22 04:24:42 +00:00
|
|
|
DagInit(Init *V, std::string VN,
|
2009-03-19 05:21:56 +00:00
|
|
|
const std::vector<std::pair<Init*, std::string> > &args)
|
2009-05-14 22:23:47 +00:00
|
|
|
: TypedInit(new DagRecTy), Val(V), ValName(VN) {
|
2003-08-10 22:14:13 +00:00
|
|
|
Args.reserve(args.size());
|
|
|
|
ArgNames.reserve(args.size());
|
|
|
|
for (unsigned i = 0, e = args.size(); i != e; ++i) {
|
|
|
|
Args.push_back(args[i].first);
|
|
|
|
ArgNames.push_back(args[i].second);
|
|
|
|
}
|
2003-08-04 20:44:17 +00:00
|
|
|
}
|
2009-11-22 04:24:42 +00:00
|
|
|
DagInit(Init *V, std::string VN, const std::vector<Init*> &args,
|
2006-01-31 06:02:35 +00:00
|
|
|
const std::vector<std::string> &argNames)
|
2009-11-22 04:24:42 +00:00
|
|
|
: TypedInit(new DagRecTy), Val(V), ValName(VN), Args(args),
|
|
|
|
ArgNames(argNames) { }
|
|
|
|
|
2003-08-04 20:44:17 +00:00
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
2006-03-30 22:50:40 +00:00
|
|
|
Init *getOperator() const { return Val; }
|
2003-08-10 22:14:13 +00:00
|
|
|
|
2009-03-19 05:21:56 +00:00
|
|
|
const std::string &getName() const { return ValName; }
|
|
|
|
|
2003-08-10 22:14:13 +00:00
|
|
|
unsigned getNumArgs() const { return Args.size(); }
|
|
|
|
Init *getArg(unsigned Num) const {
|
|
|
|
assert(Num < Args.size() && "Arg number out of range!");
|
|
|
|
return Args[Num];
|
|
|
|
}
|
|
|
|
const std::string &getArgName(unsigned Num) const {
|
|
|
|
assert(Num < ArgNames.size() && "Arg number out of range!");
|
|
|
|
return ArgNames[Num];
|
|
|
|
}
|
2003-08-04 20:44:17 +00:00
|
|
|
|
2003-08-10 22:38:36 +00:00
|
|
|
void setArg(unsigned Num, Init *I) {
|
|
|
|
assert(Num < Args.size() && "Arg number out of range!");
|
|
|
|
Args[Num] = I;
|
|
|
|
}
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2006-01-31 06:02:35 +00:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2003-08-10 22:38:36 +00:00
|
|
|
|
2007-11-22 21:05:25 +00:00
|
|
|
virtual std::string getAsString() const;
|
2008-01-22 11:00:07 +00:00
|
|
|
|
|
|
|
typedef std::vector<Init*>::iterator arg_iterator;
|
|
|
|
typedef std::vector<Init*>::const_iterator const_arg_iterator;
|
|
|
|
typedef std::vector<std::string>::iterator name_iterator;
|
|
|
|
typedef std::vector<std::string>::const_iterator const_name_iterator;
|
|
|
|
|
|
|
|
inline arg_iterator arg_begin() { return Args.begin(); }
|
|
|
|
inline const_arg_iterator arg_begin() const { return Args.begin(); }
|
|
|
|
inline arg_iterator arg_end () { return Args.end(); }
|
|
|
|
inline const_arg_iterator arg_end () const { return Args.end(); }
|
|
|
|
|
|
|
|
inline size_t arg_size () const { return Args.size(); }
|
|
|
|
inline bool arg_empty() const { return Args.empty(); }
|
|
|
|
|
|
|
|
inline name_iterator name_begin() { return ArgNames.begin(); }
|
|
|
|
inline const_name_iterator name_begin() const { return ArgNames.begin(); }
|
|
|
|
inline name_iterator name_end () { return ArgNames.end(); }
|
|
|
|
inline const_name_iterator name_end () const { return ArgNames.end(); }
|
|
|
|
|
|
|
|
inline size_t name_size () const { return ArgNames.size(); }
|
|
|
|
inline bool name_empty() const { return ArgNames.empty(); }
|
|
|
|
|
2009-05-14 22:23:47 +00:00
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit) {
|
|
|
|
assert(0 && "Illegal bit reference off dag");
|
|
|
|
return 0;
|
|
|
|
}
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2009-05-14 22:23:47 +00:00
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt) {
|
|
|
|
assert(0 && "Illegal element reference off dag");
|
|
|
|
return 0;
|
|
|
|
}
|
2003-08-04 20:44:17 +00:00
|
|
|
};
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// High-Level Classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class RecordVal {
|
|
|
|
std::string Name;
|
|
|
|
RecTy *Ty;
|
|
|
|
unsigned Prefix;
|
|
|
|
Init *Value;
|
|
|
|
public:
|
|
|
|
RecordVal(const std::string &N, RecTy *T, unsigned P);
|
|
|
|
|
|
|
|
const std::string &getName() const { return Name; }
|
|
|
|
|
|
|
|
unsigned getPrefix() const { return Prefix; }
|
|
|
|
RecTy *getType() const { return Ty; }
|
|
|
|
Init *getValue() const { return Value; }
|
|
|
|
|
|
|
|
bool setValue(Init *V) {
|
|
|
|
if (V) {
|
|
|
|
Value = V->convertInitializerTo(Ty);
|
|
|
|
return Value == 0;
|
|
|
|
}
|
|
|
|
Value = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump() const;
|
2009-07-03 00:10:29 +00:00
|
|
|
void print(raw_ostream &OS, bool PrintSem = true) const;
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2009-07-03 00:10:29 +00:00
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS, const RecordVal &RV) {
|
2002-12-02 01:23:04 +00:00
|
|
|
RV.print(OS << " ");
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
2004-10-23 04:58:50 +00:00
|
|
|
class Record {
|
2009-08-23 09:47:37 +00:00
|
|
|
static unsigned LastID;
|
|
|
|
|
|
|
|
// Unique record ID.
|
|
|
|
unsigned ID;
|
2005-08-19 17:58:49 +00:00
|
|
|
std::string Name;
|
2009-06-21 03:39:35 +00:00
|
|
|
SMLoc Loc;
|
2002-12-02 01:23:04 +00:00
|
|
|
std::vector<std::string> TemplateArgs;
|
|
|
|
std::vector<RecordVal> Values;
|
|
|
|
std::vector<Record*> SuperClasses;
|
|
|
|
public:
|
|
|
|
|
2009-11-22 04:24:42 +00:00
|
|
|
explicit Record(const std::string &N, SMLoc loc) :
|
2009-08-23 09:47:37 +00:00
|
|
|
ID(LastID++), Name(N), Loc(loc) {}
|
2002-12-02 01:23:04 +00:00
|
|
|
~Record() {}
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2010-09-21 14:59:50 +00:00
|
|
|
|
2010-03-01 22:09:11 +00:00
|
|
|
static unsigned getNewUID() { return LastID++; }
|
2010-09-21 14:59:50 +00:00
|
|
|
|
|
|
|
|
2009-08-23 09:47:37 +00:00
|
|
|
unsigned getID() const { return ID; }
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
const std::string &getName() const { return Name; }
|
2005-08-19 17:58:11 +00:00
|
|
|
void setName(const std::string &Name); // Also updates RecordKeeper.
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2009-06-21 03:39:35 +00:00
|
|
|
SMLoc getLoc() const { return Loc; }
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
const std::vector<std::string> &getTemplateArgs() const {
|
|
|
|
return TemplateArgs;
|
|
|
|
}
|
|
|
|
const std::vector<RecordVal> &getValues() const { return Values; }
|
|
|
|
const std::vector<Record*> &getSuperClasses() const { return SuperClasses; }
|
|
|
|
|
2009-09-18 18:31:37 +00:00
|
|
|
bool isTemplateArg(StringRef Name) const {
|
2002-12-02 01:23:04 +00:00
|
|
|
for (unsigned i = 0, e = TemplateArgs.size(); i != e; ++i)
|
|
|
|
if (TemplateArgs[i] == Name) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:31:37 +00:00
|
|
|
const RecordVal *getValue(StringRef Name) const {
|
2002-12-02 01:23:04 +00:00
|
|
|
for (unsigned i = 0, e = Values.size(); i != e; ++i)
|
|
|
|
if (Values[i].getName() == Name) return &Values[i];
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-18 18:31:37 +00:00
|
|
|
RecordVal *getValue(StringRef Name) {
|
2002-12-02 01:23:04 +00:00
|
|
|
for (unsigned i = 0, e = Values.size(); i != e; ++i)
|
|
|
|
if (Values[i].getName() == Name) return &Values[i];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:31:37 +00:00
|
|
|
void addTemplateArg(StringRef Name) {
|
2002-12-02 01:23:04 +00:00
|
|
|
assert(!isTemplateArg(Name) && "Template arg already defined!");
|
|
|
|
TemplateArgs.push_back(Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void addValue(const RecordVal &RV) {
|
|
|
|
assert(getValue(RV.getName()) == 0 && "Value already added!");
|
|
|
|
Values.push_back(RV);
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:31:37 +00:00
|
|
|
void removeValue(StringRef Name) {
|
2003-07-30 04:56:05 +00:00
|
|
|
for (unsigned i = 0, e = Values.size(); i != e; ++i)
|
|
|
|
if (Values[i].getName() == Name) {
|
|
|
|
Values.erase(Values.begin()+i);
|
|
|
|
return;
|
|
|
|
}
|
2009-11-21 22:39:27 +00:00
|
|
|
assert(0 && "Cannot remove an entry that does not exist!");
|
2003-07-30 04:56:05 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:20:10 +00:00
|
|
|
bool isSubClassOf(const Record *R) const {
|
2002-12-02 01:23:04 +00:00
|
|
|
for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
|
|
|
|
if (SuperClasses[i] == R)
|
2005-04-22 04:13:13 +00:00
|
|
|
return true;
|
2002-12-02 01:23:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:31:37 +00:00
|
|
|
bool isSubClassOf(StringRef Name) const {
|
2003-08-07 19:41:59 +00:00
|
|
|
for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
|
|
|
|
if (SuperClasses[i]->getName() == Name)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
void addSuperClass(Record *R) {
|
|
|
|
assert(!isSubClassOf(R) && "Already subclassing record!");
|
|
|
|
SuperClasses.push_back(R);
|
|
|
|
}
|
|
|
|
|
2005-04-19 03:36:21 +00:00
|
|
|
/// resolveReferences - If there are any field references that refer to fields
|
|
|
|
/// that have been filled in, we can propagate the values now.
|
|
|
|
///
|
|
|
|
void resolveReferences() { resolveReferencesTo(0); }
|
|
|
|
|
|
|
|
/// resolveReferencesTo - If anything in this record refers to RV, replace the
|
|
|
|
/// reference to RV with the RHS of RV. If RV is null, we resolve all
|
|
|
|
/// possible references.
|
|
|
|
void resolveReferencesTo(const RecordVal *RV);
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
void dump() const;
|
2003-08-01 04:37:57 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// High-level methods useful to tablegen back-ends
|
|
|
|
//
|
|
|
|
|
2003-08-01 06:27:59 +00:00
|
|
|
/// getValueInit - Return the initializer for a value with the specified name,
|
|
|
|
/// or throw an exception if the field does not exist.
|
|
|
|
///
|
2009-09-18 18:31:37 +00:00
|
|
|
Init *getValueInit(StringRef FieldName) const;
|
2003-08-01 06:27:59 +00:00
|
|
|
|
2003-08-01 04:37:57 +00:00
|
|
|
/// getValueAsString - This method looks up the specified field and returns
|
|
|
|
/// its value as a string, throwing an exception if the field does not exist
|
|
|
|
/// or if the value is not a string.
|
|
|
|
///
|
2009-09-18 18:31:37 +00:00
|
|
|
std::string getValueAsString(StringRef FieldName) const;
|
2003-08-01 04:37:57 +00:00
|
|
|
|
2003-08-01 04:46:24 +00:00
|
|
|
/// getValueAsBitsInit - This method looks up the specified field and returns
|
|
|
|
/// its value as a BitsInit, throwing an exception if the field does not exist
|
|
|
|
/// or if the value is not the right type.
|
|
|
|
///
|
2009-09-18 18:31:37 +00:00
|
|
|
BitsInit *getValueAsBitsInit(StringRef FieldName) const;
|
2003-08-01 04:46:24 +00:00
|
|
|
|
2003-08-01 06:15:10 +00:00
|
|
|
/// getValueAsListInit - This method looks up the specified field and returns
|
|
|
|
/// its value as a ListInit, throwing an exception if the field does not exist
|
|
|
|
/// or if the value is not the right type.
|
|
|
|
///
|
2009-09-18 18:31:37 +00:00
|
|
|
ListInit *getValueAsListInit(StringRef FieldName) const;
|
2003-08-01 06:15:10 +00:00
|
|
|
|
2005-10-28 22:49:02 +00:00
|
|
|
/// getValueAsListOfDefs - This method looks up the specified field and
|
2007-11-11 11:19:37 +00:00
|
|
|
/// returns its value as a vector of records, throwing an exception if the
|
2005-10-28 22:49:02 +00:00
|
|
|
/// field does not exist or if the value is not the right type.
|
2005-10-28 21:46:31 +00:00
|
|
|
///
|
2009-09-18 18:31:37 +00:00
|
|
|
std::vector<Record*> getValueAsListOfDefs(StringRef FieldName) const;
|
2005-10-28 21:46:31 +00:00
|
|
|
|
2010-09-21 14:59:50 +00:00
|
|
|
/// getValueAsListOfInts - This method looks up the specified field and
|
|
|
|
/// returns its value as a vector of integers, throwing an exception if the
|
|
|
|
/// field does not exist or if the value is not the right type.
|
2007-11-11 11:19:37 +00:00
|
|
|
///
|
2009-09-18 18:31:37 +00:00
|
|
|
std::vector<int64_t> getValueAsListOfInts(StringRef FieldName) const;
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2003-08-02 01:27:37 +00:00
|
|
|
/// getValueAsDef - This method looks up the specified field and returns its
|
|
|
|
/// value as a Record, throwing an exception if the field does not exist or if
|
|
|
|
/// the value is not the right type.
|
|
|
|
///
|
2009-09-18 18:31:37 +00:00
|
|
|
Record *getValueAsDef(StringRef FieldName) const;
|
2003-08-02 01:27:37 +00:00
|
|
|
|
2003-08-03 21:58:13 +00:00
|
|
|
/// getValueAsBit - This method looks up the specified field and returns its
|
|
|
|
/// value as a bit, throwing an exception if the field does not exist or if
|
|
|
|
/// the value is not the right type.
|
|
|
|
///
|
2009-09-18 18:31:37 +00:00
|
|
|
bool getValueAsBit(StringRef FieldName) const;
|
2003-08-03 21:58:13 +00:00
|
|
|
|
2003-08-01 06:15:10 +00:00
|
|
|
/// getValueAsInt - This method looks up the specified field and returns its
|
2008-10-17 01:33:43 +00:00
|
|
|
/// value as an int64_t, throwing an exception if the field does not exist or
|
|
|
|
/// if the value is not the right type.
|
2003-08-01 06:15:10 +00:00
|
|
|
///
|
2009-09-18 18:31:37 +00:00
|
|
|
int64_t getValueAsInt(StringRef FieldName) const;
|
2003-08-07 06:00:43 +00:00
|
|
|
|
|
|
|
/// getValueAsDag - This method looks up the specified field and returns its
|
|
|
|
/// value as an Dag, throwing an exception if the field does not exist or if
|
|
|
|
/// the value is not the right type.
|
|
|
|
///
|
2009-09-18 18:31:37 +00:00
|
|
|
DagInit *getValueAsDag(StringRef FieldName) const;
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2005-09-13 21:44:28 +00:00
|
|
|
/// getValueAsCode - This method looks up the specified field and returns
|
|
|
|
/// its value as the string data in a CodeInit, throwing an exception if the
|
|
|
|
/// field does not exist or if the value is not a code object.
|
|
|
|
///
|
2009-09-18 18:31:37 +00:00
|
|
|
std::string getValueAsCode(StringRef FieldName) const;
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2009-07-03 00:10:29 +00:00
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const Record &R);
|
2002-12-02 01:23:04 +00:00
|
|
|
|
2009-04-22 20:18:10 +00:00
|
|
|
struct MultiClass {
|
|
|
|
Record Rec; // Placeholder for template args and Name.
|
|
|
|
typedef std::vector<Record*> RecordVector;
|
|
|
|
RecordVector DefPrototypes;
|
2009-04-24 16:55:41 +00:00
|
|
|
|
|
|
|
void dump() const;
|
|
|
|
|
2009-06-21 03:39:35 +00:00
|
|
|
MultiClass(const std::string &Name, SMLoc Loc) : Rec(Name, Loc) {}
|
2009-04-22 20:18:10 +00:00
|
|
|
};
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
class RecordKeeper {
|
|
|
|
std::map<std::string, Record*> Classes, Defs;
|
|
|
|
public:
|
|
|
|
~RecordKeeper() {
|
|
|
|
for (std::map<std::string, Record*>::iterator I = Classes.begin(),
|
2005-04-22 04:13:13 +00:00
|
|
|
E = Classes.end(); I != E; ++I)
|
2002-12-02 01:23:04 +00:00
|
|
|
delete I->second;
|
|
|
|
for (std::map<std::string, Record*>::iterator I = Defs.begin(),
|
2005-04-22 04:13:13 +00:00
|
|
|
E = Defs.end(); I != E; ++I)
|
2002-12-02 01:23:04 +00:00
|
|
|
delete I->second;
|
|
|
|
}
|
2005-04-22 00:00:37 +00:00
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
const std::map<std::string, Record*> &getClasses() const { return Classes; }
|
|
|
|
const std::map<std::string, Record*> &getDefs() const { return Defs; }
|
|
|
|
|
|
|
|
Record *getClass(const std::string &Name) const {
|
|
|
|
std::map<std::string, Record*>::const_iterator I = Classes.find(Name);
|
|
|
|
return I == Classes.end() ? 0 : I->second;
|
|
|
|
}
|
|
|
|
Record *getDef(const std::string &Name) const {
|
|
|
|
std::map<std::string, Record*>::const_iterator I = Defs.find(Name);
|
|
|
|
return I == Defs.end() ? 0 : I->second;
|
|
|
|
}
|
|
|
|
void addClass(Record *R) {
|
|
|
|
assert(getClass(R->getName()) == 0 && "Class already exists!");
|
|
|
|
Classes.insert(std::make_pair(R->getName(), R));
|
|
|
|
}
|
|
|
|
void addDef(Record *R) {
|
|
|
|
assert(getDef(R->getName()) == 0 && "Def already exists!");
|
|
|
|
Defs.insert(std::make_pair(R->getName(), R));
|
|
|
|
}
|
|
|
|
|
2005-08-19 17:58:11 +00:00
|
|
|
/// removeClass - Remove, but do not delete, the specified record.
|
|
|
|
///
|
|
|
|
void removeClass(const std::string &Name) {
|
|
|
|
assert(Classes.count(Name) && "Class does not exist!");
|
|
|
|
Classes.erase(Name);
|
|
|
|
}
|
|
|
|
/// removeDef - Remove, but do not delete, the specified record.
|
|
|
|
///
|
|
|
|
void removeDef(const std::string &Name) {
|
|
|
|
assert(Defs.count(Name) && "Def does not exist!");
|
|
|
|
Defs.erase(Name);
|
|
|
|
}
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2003-08-01 04:09:58 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// High-level helper methods, useful for tablegen backends...
|
|
|
|
|
|
|
|
/// getAllDerivedDefinitions - This method returns all concrete definitions
|
|
|
|
/// that derive from the specified class name. If a class with the specified
|
2003-08-01 04:37:57 +00:00
|
|
|
/// name does not exist, an exception is thrown.
|
|
|
|
std::vector<Record*>
|
|
|
|
getAllDerivedDefinitions(const std::string &ClassName) const;
|
2003-08-01 04:09:58 +00:00
|
|
|
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
void dump() const;
|
|
|
|
};
|
|
|
|
|
2008-08-26 06:43:25 +00:00
|
|
|
/// LessRecord - Sorting predicate to sort record pointers by name.
|
|
|
|
///
|
|
|
|
struct LessRecord {
|
|
|
|
bool operator()(const Record *Rec1, const Record *Rec2) const {
|
Add StringRef::compare_numeric and use it to sort TableGen register records.
This means that our Registers are now ordered R7, R8, R9, R10, R12, ...
Not R1, R10, R11, R12, R2, R3, ...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104745 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-26 21:47:28 +00:00
|
|
|
return StringRef(Rec1->getName()).compare_numeric(Rec2->getName()) < 0;
|
2008-08-26 06:43:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-11-22 04:24:42 +00:00
|
|
|
/// LessRecordFieldName - Sorting predicate to sort record pointers by their
|
2008-09-11 17:05:32 +00:00
|
|
|
/// name field.
|
2008-08-26 06:43:25 +00:00
|
|
|
///
|
|
|
|
struct LessRecordFieldName {
|
|
|
|
bool operator()(const Record *Rec1, const Record *Rec2) const {
|
|
|
|
return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-03-13 16:25:21 +00:00
|
|
|
|
|
|
|
class TGError {
|
2009-06-21 03:39:35 +00:00
|
|
|
SMLoc Loc;
|
2009-03-13 16:25:21 +00:00
|
|
|
std::string Message;
|
|
|
|
public:
|
2009-06-21 03:39:35 +00:00
|
|
|
TGError(SMLoc loc, const std::string &message) : Loc(loc), Message(message) {}
|
2009-11-22 04:24:42 +00:00
|
|
|
|
2009-06-21 03:39:35 +00:00
|
|
|
SMLoc getLoc() const { return Loc; }
|
2009-03-13 16:25:21 +00:00
|
|
|
const std::string &getMessage() const { return Message; }
|
|
|
|
};
|
2009-11-22 04:24:42 +00:00
|
|
|
|
|
|
|
|
2009-07-03 00:10:29 +00:00
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK);
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
extern RecordKeeper Records;
|
|
|
|
|
2010-09-27 17:42:11 +00:00
|
|
|
void PrintError(SMLoc ErrorLoc, const Twine &Msg);
|
2009-03-13 16:09:24 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
#endif
|