2003-10-06 03:27:59 +08:00
|
|
|
//===- Record.h - Classes to represent Table Records ------------*- C++ -*-===//
|
2005-04-22 08:00:37 +08:00
|
|
|
//
|
2003-10-21 04:20:30 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:37:13 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 08:00:37 +08:00
|
|
|
//
|
2003-10-21 04:20:30 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-10-06 03:27:59 +08:00
|
|
|
//
|
|
|
|
// This file defines the main TableGen data structures, including the TableGen
|
|
|
|
// types, values, and high-level data structures.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef RECORD_H
|
|
|
|
#define RECORD_H
|
|
|
|
|
2009-03-14 00:09:24 +08:00
|
|
|
#include "TGSourceMgr.h"
|
2008-10-22 17:54:13 +08:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2003-10-06 03:27:59 +08:00
|
|
|
#include <map>
|
2006-12-08 06:21:48 +08:00
|
|
|
#include <ostream>
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2003-11-12 06:41:34 +08:00
|
|
|
namespace llvm {
|
2009-03-14 00:09:24 +08:00
|
|
|
|
2005-04-19 11:36:21 +08:00
|
|
|
// RecTy subclasses.
|
2003-10-06 03:27:59 +08:00
|
|
|
class BitRecTy;
|
|
|
|
class BitsRecTy;
|
|
|
|
class IntRecTy;
|
|
|
|
class StringRecTy;
|
|
|
|
class ListRecTy;
|
|
|
|
class CodeRecTy;
|
|
|
|
class DagRecTy;
|
|
|
|
class RecordRecTy;
|
|
|
|
|
2005-04-19 11:36:21 +08:00
|
|
|
// Init subclasses.
|
2004-10-28 00:14:51 +08:00
|
|
|
struct Init;
|
2003-10-06 03:27:59 +08:00
|
|
|
class UnsetInit;
|
|
|
|
class BitInit;
|
|
|
|
class BitsInit;
|
|
|
|
class IntInit;
|
|
|
|
class StringInit;
|
|
|
|
class CodeInit;
|
|
|
|
class ListInit;
|
2009-05-15 05:22:49 +08:00
|
|
|
class UnOpInit;
|
2006-04-01 05:53:49 +08:00
|
|
|
class BinOpInit;
|
2009-05-15 05:54:42 +08:00
|
|
|
class TernOpInit;
|
2003-10-06 03:27:59 +08:00
|
|
|
class DefInit;
|
|
|
|
class DagInit;
|
|
|
|
class TypedInit;
|
|
|
|
class VarInit;
|
|
|
|
class FieldInit;
|
|
|
|
class VarBitInit;
|
2004-07-27 09:01:21 +08:00
|
|
|
class VarListElementInit;
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2005-04-19 11:36:21 +08:00
|
|
|
// Other classes.
|
2003-10-06 03:27:59 +08:00
|
|
|
class Record;
|
2005-04-19 11:36:21 +08:00
|
|
|
class RecordVal;
|
2009-05-01 01:35:11 +08:00
|
|
|
struct MultiClass;
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Type Classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
struct RecTy {
|
|
|
|
virtual ~RecTy() {}
|
|
|
|
|
2007-11-21 06:25:16 +08:00
|
|
|
virtual std::string getAsString() const = 0;
|
2007-11-23 04:51:34 +08:00
|
|
|
void print(std::ostream &OS) const { OS << getAsString(); }
|
2003-10-06 03:27:59 +08: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
|
|
|
|
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-15 05:22:49 +08:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) {
|
|
|
|
return convertValue((TypedInit*)UI);
|
|
|
|
}
|
2009-04-24 05:25:15 +08:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) {
|
|
|
|
return convertValue((TypedInit*)UI);
|
|
|
|
}
|
2009-05-15 05:54:42 +08:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) {
|
|
|
|
return convertValue((TypedInit*)UI);
|
|
|
|
}
|
2003-10-06 03:27:59 +08: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) { return 0; }
|
|
|
|
virtual Init *convertValue( VarInit *VI) {
|
|
|
|
return convertValue((TypedInit*)VI);
|
|
|
|
}
|
|
|
|
virtual Init *convertValue( FieldInit *FI) {
|
|
|
|
return convertValue((TypedInit*)FI);
|
|
|
|
}
|
|
|
|
|
|
|
|
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; }
|
|
|
|
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
|
|
|
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
inline std::ostream &operator<<(std::ostream &OS, const RecTy &Ty) {
|
|
|
|
Ty.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// BitRecTy - 'bit' - Represent a single bit
|
|
|
|
///
|
2004-10-28 00:14:51 +08:00
|
|
|
class BitRecTy : public RecTy {
|
|
|
|
public:
|
2004-12-07 07:42:37 +08: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-15 05:22:49 +08:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-04-24 05:25:15 +08:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-05-15 05:54:42 +08:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
|
2004-12-07 07:42:37 +08:00
|
|
|
virtual Init *convertValue( TypedInit *TI);
|
|
|
|
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
|
|
|
|
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2007-11-21 06:25:16 +08:00
|
|
|
std::string getAsString() const { return "bit"; }
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
2004-12-07 07:42:37 +08: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; }
|
|
|
|
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-04-15 23:30:15 +08:00
|
|
|
// BitsRecTy - 'bits<n>' - Represent a fixed number of bits
|
|
|
|
/// BitsRecTy - 'bits<n>' - Represent a fixed number of bits
|
2003-10-06 03:27:59 +08:00
|
|
|
///
|
|
|
|
class BitsRecTy : public RecTy {
|
|
|
|
unsigned Size;
|
|
|
|
public:
|
2008-07-08 02:00:37 +08:00
|
|
|
explicit BitsRecTy(unsigned Sz) : Size(Sz) {}
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
unsigned getNumBits() const { return Size; }
|
|
|
|
|
2004-12-07 07:42:37 +08: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-15 05:22:49 +08:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-04-24 05:25:15 +08:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-05-15 05:54:42 +08:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
|
2004-12-07 07:42:37 +08: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-21 06:25:16 +08:00
|
|
|
std::string getAsString() const;
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
2004-12-07 07:42:37 +08:00
|
|
|
virtual bool baseClassOf(const BitRecTy *RHS) const { return Size == 1; }
|
|
|
|
virtual bool baseClassOf(const BitsRecTy *RHS) const {
|
2003-10-06 03:27:59 +08:00
|
|
|
return RHS->Size == Size;
|
|
|
|
}
|
2004-12-07 07:42:37 +08: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; }
|
|
|
|
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// IntRecTy - 'int' - Represent an integer value of no particular size
|
|
|
|
///
|
2004-10-28 00:14:51 +08:00
|
|
|
class IntRecTy : public RecTy {
|
|
|
|
public:
|
2004-12-07 07:42:37 +08: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-15 05:22:49 +08:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-04-24 05:25:15 +08:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-05-15 05:54:42 +08:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
|
2004-12-07 07:42:37 +08: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-21 06:25:16 +08:00
|
|
|
std::string getAsString() const { return "int"; }
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
|
|
|
|
2004-12-07 07:42:37 +08: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; }
|
|
|
|
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// StringRecTy - 'string' - Represent an string value
|
|
|
|
///
|
2004-10-28 00:14:51 +08:00
|
|
|
class StringRecTy : public RecTy {
|
|
|
|
public:
|
2004-12-07 07:42:37 +08: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-15 05:22:49 +08:00
|
|
|
virtual Init *convertValue( UnOpInit *BO);
|
2006-04-01 05:53:49 +08:00
|
|
|
virtual Init *convertValue( BinOpInit *BO);
|
2009-05-15 05:54:42 +08:00
|
|
|
virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);}
|
2009-05-15 04:54:48 +08:00
|
|
|
|
2004-12-07 07:42:37 +08: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-21 06:25:16 +08:00
|
|
|
std::string getAsString() const { return "string"; }
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
|
|
|
|
2004-12-07 07:42:37 +08: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-10-06 03:27:59 +08:00
|
|
|
virtual bool baseClassOf(const StringRecTy *RHS) const { return true; }
|
2004-12-07 07:42:37 +08: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; }
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
2004-04-15 23:30:15 +08: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.
|
2003-10-06 03:27:59 +08:00
|
|
|
///
|
|
|
|
class ListRecTy : public RecTy {
|
|
|
|
RecTy *Ty;
|
|
|
|
public:
|
2008-07-08 02:00:37 +08:00
|
|
|
explicit ListRecTy(RecTy *T) : Ty(T) {}
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
RecTy *getElementType() const { return Ty; }
|
|
|
|
|
2004-12-07 07:42:37 +08: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-15 05:22:49 +08:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-04-24 05:25:15 +08:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-05-15 05:54:42 +08:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
|
2004-12-07 07:42:37 +08: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 08:00:37 +08:00
|
|
|
|
2007-11-21 06:25:16 +08:00
|
|
|
std::string getAsString() const;
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
|
|
|
|
2004-12-07 07:42:37 +08: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 08:00:37 +08:00
|
|
|
return RHS->getElementType()->typeIsConvertibleTo(Ty);
|
2003-10-06 03:27:59 +08:00
|
|
|
}
|
2004-12-07 07:42:37 +08: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; }
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// CodeRecTy - 'code' - Represent an code fragment, function or method.
|
|
|
|
///
|
2004-10-28 00:14:51 +08:00
|
|
|
class CodeRecTy : public RecTy {
|
|
|
|
public:
|
2004-12-07 07:42:37 +08: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-15 05:22:49 +08:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-04-24 05:25:15 +08:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-05-15 05:54:42 +08:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
|
2004-12-07 07:42:37 +08: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-21 06:25:16 +08:00
|
|
|
std::string getAsString() const { return "code"; }
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
2004-12-07 07:42:37 +08: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-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// DagRecTy - 'dag' - Represent a dag fragment
|
|
|
|
///
|
2004-10-28 00:14:51 +08:00
|
|
|
class DagRecTy : public RecTy {
|
|
|
|
public:
|
2004-12-07 07:42:37 +08: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-15 05:22:49 +08:00
|
|
|
virtual Init *convertValue( UnOpInit *BO);
|
2007-05-15 09:23:24 +08:00
|
|
|
virtual Init *convertValue( BinOpInit *BO);
|
2009-05-15 05:54:42 +08:00
|
|
|
virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);}
|
2004-12-07 07:42:37 +08: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-10-06 03:27:59 +08:00
|
|
|
|
2007-11-21 06:25:16 +08:00
|
|
|
std::string getAsString() const { return "dag"; }
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
2004-12-07 07:42:37 +08: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-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-04-15 23:30:15 +08:00
|
|
|
/// RecordRecTy - '[classname]' - Represent an instance of a class, such as:
|
2003-10-06 03:27:59 +08:00
|
|
|
/// (R32 X = EAX).
|
|
|
|
///
|
|
|
|
class RecordRecTy : public RecTy {
|
|
|
|
Record *Rec;
|
|
|
|
public:
|
2008-07-08 02:00:37 +08:00
|
|
|
explicit RecordRecTy(Record *R) : Rec(R) {}
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
Record *getRecord() const { return Rec; }
|
|
|
|
|
2004-12-07 07:42:37 +08: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-15 05:22:49 +08:00
|
|
|
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-04-24 05:25:15 +08:00
|
|
|
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
|
2009-05-15 05:54:42 +08:00
|
|
|
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
|
2004-12-07 07:42:37 +08:00
|
|
|
virtual Init *convertValue( DefInit *DI);
|
|
|
|
virtual Init *convertValue( DagInit *DI) { return 0; }
|
2005-04-22 08:00:37 +08:00
|
|
|
virtual Init *convertValue( TypedInit *VI);
|
2004-12-07 07:42:37 +08:00
|
|
|
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
|
|
|
|
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2007-11-21 06:25:16 +08:00
|
|
|
std::string getAsString() const;
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
bool typeIsConvertibleTo(const RecTy *RHS) const {
|
|
|
|
return RHS->baseClassOf(this);
|
|
|
|
}
|
2004-12-07 07:42:37 +08: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-10-06 03:27:59 +08:00
|
|
|
virtual bool baseClassOf(const RecordRecTy *RHS) const;
|
|
|
|
};
|
|
|
|
|
2009-06-09 04:23:18 +08:00
|
|
|
/// resolveTypes - Find a common type that T1 and T2 convert to.
|
|
|
|
/// Return 0 if no such type exists.
|
|
|
|
///
|
|
|
|
RecTy *resolveTypes(RecTy *T1, RecTy *T2);
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Initializer Classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
struct Init {
|
|
|
|
virtual ~Init() {}
|
|
|
|
|
|
|
|
/// 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.
|
2007-11-23 05:05:25 +08:00
|
|
|
void print(std::ostream &OS) const { OS << getAsString(); }
|
|
|
|
|
|
|
|
/// getAsString - Convert this value to a string form.
|
|
|
|
virtual std::string getAsString() const = 0;
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
/// dump - Debugging method that may be called through a debugger, just
|
|
|
|
/// invokes print on cerr.
|
|
|
|
void dump() const;
|
|
|
|
|
|
|
|
/// convertInitializerTo - This virtual function is a simple call-back
|
|
|
|
/// function that should be overridden to call the appropriate
|
|
|
|
/// RecTy::convertValue method.
|
|
|
|
///
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) = 0;
|
|
|
|
|
|
|
|
/// convertInitializerBitRange - This method is used to implement the bitrange
|
|
|
|
/// selection operator. Given an initializer, it selects the specified bits
|
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
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.
llvm-svn: 15247
2004-07-27 07:21:34 +08: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;
|
|
|
|
}
|
|
|
|
|
2003-10-06 03:27:59 +08: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; }
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
virtual Init *getFieldInit(Record &R, const std::string &FieldName) const {
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-22 08:00:37 +08:00
|
|
|
|
2003-10-06 03:27:59 +08: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 11:36:21 +08:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV) {
|
|
|
|
return this;
|
|
|
|
}
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
inline std::ostream &operator<<(std::ostream &OS, const Init &I) {
|
|
|
|
I.print(OS); return OS;
|
|
|
|
}
|
|
|
|
|
2009-05-15 06:23:47 +08: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);
|
|
|
|
|
|
|
|
/// 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;
|
|
|
|
};
|
|
|
|
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
/// UnsetInit - ? - Represents an uninitialized value
|
|
|
|
///
|
2004-10-28 00:14:51 +08:00
|
|
|
class UnsetInit : public Init {
|
|
|
|
public:
|
2003-10-06 03:27:59 +08:00
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isComplete() const { return false; }
|
2007-11-23 05:05:25 +08:00
|
|
|
virtual std::string getAsString() const { return "?"; }
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// BitInit - true/false - Represent a concrete initializer for a bit.
|
|
|
|
///
|
|
|
|
class BitInit : public Init {
|
|
|
|
bool Value;
|
|
|
|
public:
|
2008-03-26 06:06:05 +08:00
|
|
|
explicit BitInit(bool V) : Value(V) {}
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
bool getValue() const { return Value; }
|
|
|
|
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
2007-11-23 05:05:25 +08:00
|
|
|
virtual std::string getAsString() const { return Value ? "1" : "0"; }
|
2003-10-06 03:27:59 +08: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.
|
|
|
|
///
|
|
|
|
class BitsInit : public Init {
|
|
|
|
std::vector<Init*> Bits;
|
|
|
|
public:
|
2008-03-26 06:06:05 +08:00
|
|
|
explicit BitsInit(unsigned Size) : Bits(Size) {}
|
2003-10-06 03:27:59 +08: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!");
|
|
|
|
assert(Bits[Bit] == 0 && "Bit already set!");
|
|
|
|
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;
|
|
|
|
}
|
2007-11-23 05:05:25 +08:00
|
|
|
virtual std::string getAsString() const;
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2005-04-19 11:36:21 +08:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
// printXX - Print this bitstream with the specified format, returning true if
|
|
|
|
// it is not possible.
|
|
|
|
bool printInHex(std::ostream &OS) const;
|
|
|
|
bool printAsVariable(std::ostream &OS) const;
|
|
|
|
bool printAsUnset(std::ostream &OS) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// IntInit - 7 - Represent an initalization by a literal integer value.
|
|
|
|
///
|
2009-06-09 04:23:18 +08:00
|
|
|
class IntInit : public TypedInit {
|
2008-10-17 09:33:43 +08:00
|
|
|
int64_t Value;
|
2003-10-06 03:27:59 +08:00
|
|
|
public:
|
2009-06-09 04:23:18 +08:00
|
|
|
explicit IntInit(int64_t V) : TypedInit(new IntRecTy), Value(V) {}
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2008-10-17 09:33:43 +08:00
|
|
|
int64_t getValue() const { return Value; }
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
|
|
|
|
|
2007-11-23 05:05:25 +08:00
|
|
|
virtual std::string getAsString() const;
|
2009-06-09 04:23:18 +08: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;
|
|
|
|
}
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// StringInit - "foo" - Represent an initialization by a string value.
|
|
|
|
///
|
2009-05-15 06:23:47 +08:00
|
|
|
class StringInit : public TypedInit {
|
2003-10-06 03:27:59 +08:00
|
|
|
std::string Value;
|
|
|
|
public:
|
2009-05-15 11:03:14 +08:00
|
|
|
explicit StringInit(const std::string &V)
|
|
|
|
: TypedInit(new StringRecTy), Value(V) {}
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
const std::string &getValue() const { return Value; }
|
|
|
|
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
2007-11-23 05:05:25 +08:00
|
|
|
virtual std::string getAsString() const { return "\"" + Value + "\""; }
|
2009-05-15 06:23:47 +08: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;
|
|
|
|
}
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// CodeInit - "[{...}]" - Represent a code fragment.
|
|
|
|
///
|
|
|
|
class CodeInit : public Init {
|
|
|
|
std::string Value;
|
|
|
|
public:
|
2008-03-26 06:06:05 +08:00
|
|
|
explicit CodeInit(const std::string &V) : Value(V) {}
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
const std::string getValue() const { return Value; }
|
|
|
|
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
2007-11-23 05:05:25 +08:00
|
|
|
virtual std::string getAsString() const { return "[{" + Value + "}]"; }
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// ListInit - [AL, AH, CL] - Represent a list of defs
|
|
|
|
///
|
2009-06-09 04:23:18 +08:00
|
|
|
class ListInit : public TypedInit {
|
2003-10-06 03:27:59 +08:00
|
|
|
std::vector<Init*> Values;
|
|
|
|
public:
|
2009-05-15 06:38:31 +08:00
|
|
|
typedef std::vector<Init*>::iterator iterator;
|
|
|
|
typedef std::vector<Init*>::const_iterator const_iterator;
|
|
|
|
|
2009-06-09 04:23:18 +08:00
|
|
|
explicit ListInit(std::vector<Init*> &Vs, RecTy *EltTy)
|
|
|
|
: TypedInit(new ListRecTy(EltTy)) {
|
2003-10-06 03:27:59 +08:00
|
|
|
Values.swap(Vs);
|
|
|
|
}
|
2009-06-09 04:23:18 +08:00
|
|
|
explicit ListInit(iterator Start, iterator End, RecTy *EltTy)
|
|
|
|
: TypedInit(new ListRecTy(EltTy)), Values(Start, End) {}
|
2003-10-06 03:27:59 +08: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];
|
|
|
|
}
|
|
|
|
|
2007-02-28 06:08:27 +08:00
|
|
|
Record *getElementAsRecord(unsigned i) const;
|
|
|
|
|
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.
llvm-svn: 15247
2004-07-27 07:21:34 +08:00
|
|
|
Init *convertInitListSlice(const std::vector<unsigned> &Elements);
|
|
|
|
|
2003-10-06 03:27:59 +08:00
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
2004-07-27 09:01:21 +08: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 11:36:21 +08:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2004-07-27 09:01:21 +08:00
|
|
|
|
2007-11-23 05:05:25 +08:00
|
|
|
virtual std::string getAsString() const;
|
2008-01-22 06:30:26 +08: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-09 04:23:18 +08: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);
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-15 04:54:48 +08: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;
|
|
|
|
|
|
|
|
virtual int getNumOperands(void) const = 0;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-15 05:22:49 +08:00
|
|
|
class UnOpInit : public OpInit {
|
|
|
|
public:
|
2009-05-15 06:38:31 +08:00
|
|
|
enum UnaryOp { CAST, CAR, CDR, LNULL };
|
2009-05-15 05:22:49 +08:00
|
|
|
private:
|
|
|
|
UnaryOp Opc;
|
|
|
|
Init *LHS;
|
|
|
|
public:
|
|
|
|
UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type) :
|
|
|
|
OpInit(Type), Opc(opc), LHS(lhs) {
|
|
|
|
}
|
2009-05-15 04:54:48 +08:00
|
|
|
|
2009-05-15 05:22:49 +08:00
|
|
|
// Clone - Clone this operator, replacing arguments with the new list
|
|
|
|
virtual OpInit *clone(std::vector<Init *> &Operands) {
|
2009-05-15 11:03:14 +08:00
|
|
|
assert(Operands.size() == 1 &&
|
|
|
|
"Wrong number of operands for unary operation");
|
2009-05-15 05:22:49 +08:00
|
|
|
return new UnOpInit(getOpcode(), *Operands.begin(), getType());
|
|
|
|
}
|
2009-05-15 04:54:48 +08:00
|
|
|
|
2009-05-15 05:22:49 +08:00
|
|
|
int getNumOperands(void) const { return 1; }
|
|
|
|
Init *getOperand(int i) {
|
|
|
|
assert(i == 0 && "Invalid operand id for unary operator");
|
|
|
|
return getOperand();
|
|
|
|
}
|
2009-05-15 04:54:48 +08:00
|
|
|
|
2009-05-15 05:22:49 +08:00
|
|
|
UnaryOp getOpcode() const { return Opc; }
|
|
|
|
Init *getOperand() const { return LHS; }
|
2009-05-15 04:54:48 +08:00
|
|
|
|
2009-05-15 05:22:49 +08: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-15 04:54:48 +08:00
|
|
|
|
2009-05-15 05:22:49 +08:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2009-05-15 04:54:48 +08:00
|
|
|
|
2009-05-15 05:22:49 +08:00
|
|
|
virtual std::string getAsString() const;
|
|
|
|
};
|
2009-04-24 05:25:15 +08:00
|
|
|
|
|
|
|
/// BinOpInit - !op (X, Y) - Combine two inits.
|
|
|
|
///
|
2009-05-15 04:54:48 +08:00
|
|
|
class BinOpInit : public OpInit {
|
2009-04-24 05:25:15 +08:00
|
|
|
public:
|
2009-06-10 02:31:17 +08:00
|
|
|
enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, NAMECONCAT };
|
2009-04-24 05:25:15 +08:00
|
|
|
private:
|
|
|
|
BinaryOp Opc;
|
|
|
|
Init *LHS, *RHS;
|
|
|
|
public:
|
|
|
|
BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) :
|
2009-05-15 04:54:48 +08:00
|
|
|
OpInit(Type), Opc(opc), LHS(lhs), RHS(rhs) {
|
2009-04-24 05:25:15 +08:00
|
|
|
}
|
|
|
|
|
2009-05-15 04:54:48 +08:00
|
|
|
// Clone - Clone this operator, replacing arguments with the new list
|
|
|
|
virtual OpInit *clone(std::vector<Init *> &Operands) {
|
2009-05-15 11:03:14 +08:00
|
|
|
assert(Operands.size() == 2 &&
|
|
|
|
"Wrong number of operands for binary operation");
|
2009-05-15 04:54:48 +08:00
|
|
|
return new BinOpInit(getOpcode(), Operands[0], Operands[1], getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
int getNumOperands(void) const { return 2; }
|
|
|
|
Init *getOperand(int i) {
|
2009-05-15 11:03:14 +08:00
|
|
|
assert((i == 0 || i == 1) && "Invalid operand id for binary operator");
|
2009-05-15 04:54:48 +08:00
|
|
|
if (i == 0) {
|
|
|
|
return getLHS();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return getRHS();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-24 05:25:15 +08: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);
|
|
|
|
|
|
|
|
virtual std::string getAsString() const;
|
|
|
|
};
|
|
|
|
|
2009-05-15 04:54:48 +08:00
|
|
|
/// TernOpInit - !op (X, Y, Z) - Combine two inits.
|
|
|
|
///
|
2009-05-15 05:54:42 +08:00
|
|
|
class TernOpInit : public OpInit {
|
|
|
|
public:
|
2009-06-10 02:31:17 +08:00
|
|
|
enum TernaryOp { SUBST, FOREACH, IF };
|
2009-05-15 05:54:42 +08: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-05-15 04:54:48 +08:00
|
|
|
|
2009-05-15 05:54:42 +08:00
|
|
|
// Clone - Clone this operator, replacing arguments with the new list
|
|
|
|
virtual OpInit *clone(std::vector<Init *> &Operands) {
|
2009-05-15 11:03:14 +08: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-15 05:54:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int getNumOperands(void) const { return 3; }
|
|
|
|
Init *getOperand(int i) {
|
2009-05-15 11:03:14 +08:00
|
|
|
assert((i == 0 || i == 1 || i == 2) &&
|
|
|
|
"Invalid operand id for ternary operator");
|
2009-05-15 05:54:42 +08:00
|
|
|
if (i == 0) {
|
|
|
|
return getLHS();
|
|
|
|
}
|
|
|
|
else if (i == 1) {
|
|
|
|
return getMHS();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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-05-15 04:54:48 +08:00
|
|
|
|
2009-05-15 05:54:42 +08:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2009-05-15 04:54:48 +08:00
|
|
|
|
2009-05-15 05:54:42 +08:00
|
|
|
virtual std::string getAsString() const;
|
|
|
|
};
|
2009-05-15 04:54:48 +08:00
|
|
|
|
2009-04-24 05:25:15 +08:00
|
|
|
|
2003-10-06 03:27:59 +08:00
|
|
|
/// VarInit - 'Opcode' - Represent a reference to an entire variable object.
|
|
|
|
///
|
|
|
|
class VarInit : public TypedInit {
|
|
|
|
std::string VarName;
|
|
|
|
public:
|
2008-03-26 06:06:05 +08:00
|
|
|
explicit VarInit(const std::string &VN, RecTy *T)
|
|
|
|
: TypedInit(T), VarName(VN) {}
|
2005-04-22 08:00:37 +08:00
|
|
|
|
2003-10-06 03:27:59 +08:00
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string &getName() const { return VarName; }
|
|
|
|
|
2005-04-19 11:36:21 +08:00
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit);
|
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt);
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
virtual RecTy *getFieldType(const std::string &FieldName) const;
|
|
|
|
virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
|
|
|
|
|
|
|
|
/// 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 11:36:21 +08:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2005-04-22 08:00:37 +08:00
|
|
|
|
2007-11-23 05:05:25 +08:00
|
|
|
virtual std::string getAsString() const { return VarName; }
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field.
|
|
|
|
///
|
|
|
|
class VarBitInit : public Init {
|
|
|
|
TypedInit *TI;
|
|
|
|
unsigned Bit;
|
|
|
|
public:
|
|
|
|
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!");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
TypedInit *getVariable() const { return TI; }
|
|
|
|
unsigned getBitNum() const { return Bit; }
|
2005-04-22 08:00:37 +08:00
|
|
|
|
2007-11-23 05:05:25 +08:00
|
|
|
virtual std::string getAsString() const;
|
2005-04-19 11:36:21 +08:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
2005-04-22 08:00:37 +08:00
|
|
|
/// VarListElementInit - List[4] - Represent access to one element of a var or
|
2004-07-27 09:01:21 +08: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 11:36:21 +08:00
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit);
|
2004-07-27 09:01:21 +08: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 11:36:21 +08:00
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt);
|
2004-07-27 09:01:21 +08:00
|
|
|
|
2007-11-23 05:05:25 +08:00
|
|
|
virtual std::string getAsString() const;
|
2005-04-19 11:36:21 +08:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2004-07-27 09:01:21 +08:00
|
|
|
};
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
/// DefInit - AL - Represent a reference to a 'def' in the description
|
|
|
|
///
|
2009-05-15 06:23:47 +08:00
|
|
|
class DefInit : public TypedInit {
|
2003-10-06 03:27:59 +08:00
|
|
|
Record *Def;
|
|
|
|
public:
|
2009-05-15 06:23:47 +08:00
|
|
|
explicit DefInit(Record *D) : TypedInit(new RecordRecTy(D)), Def(D) {}
|
2005-04-22 08:00:37 +08:00
|
|
|
|
2003-10-06 03:27:59 +08:00
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Record *getDef() const { return Def; }
|
|
|
|
|
|
|
|
//virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
|
|
|
|
|
|
|
|
virtual RecTy *getFieldType(const std::string &FieldName) const;
|
|
|
|
virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
|
2005-04-22 08:00:37 +08:00
|
|
|
|
2007-11-23 05:05:25 +08:00
|
|
|
virtual std::string getAsString() const;
|
2009-05-15 06:23:47 +08: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;
|
|
|
|
}
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// FieldInit - X.Y - Represent a reference to a subfield of a variable
|
|
|
|
///
|
|
|
|
class FieldInit : public TypedInit {
|
|
|
|
Init *Rec; // Record we are referring to
|
|
|
|
std::string FieldName; // Field we are accessing
|
|
|
|
public:
|
|
|
|
FieldInit(Init *R, const std::string &FN)
|
|
|
|
: TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) {
|
|
|
|
assert(getType() && "FieldInit with non-record type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
2005-04-19 11:36:21 +08:00
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit);
|
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt);
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2005-04-19 11:36:21 +08:00
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2007-11-23 05:05:25 +08:00
|
|
|
virtual std::string getAsString() const {
|
|
|
|
return Rec->getAsString() + "." + FieldName;
|
2003-10-06 03:27:59 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-03-31 06:50:40 +08: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-10-06 03:27:59 +08:00
|
|
|
///
|
2009-05-15 06:23:47 +08:00
|
|
|
class DagInit : public TypedInit {
|
2006-03-31 06:50:40 +08:00
|
|
|
Init *Val;
|
2009-03-19 13:21:56 +08:00
|
|
|
std::string ValName;
|
2003-10-06 03:27:59 +08:00
|
|
|
std::vector<Init*> Args;
|
|
|
|
std::vector<std::string> ArgNames;
|
|
|
|
public:
|
2009-03-19 13:21:56 +08:00
|
|
|
DagInit(Init *V, std::string VN,
|
|
|
|
const std::vector<std::pair<Init*, std::string> > &args)
|
2009-05-15 06:23:47 +08:00
|
|
|
: TypedInit(new DagRecTy), Val(V), ValName(VN) {
|
2003-10-06 03:27:59 +08: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);
|
|
|
|
}
|
|
|
|
}
|
2009-03-19 13:21:56 +08:00
|
|
|
DagInit(Init *V, std::string VN, const std::vector<Init*> &args,
|
2006-01-31 14:02:35 +08:00
|
|
|
const std::vector<std::string> &argNames)
|
2009-05-15 06:23:47 +08:00
|
|
|
: TypedInit(new DagRecTy), Val(V), ValName(VN), Args(args), ArgNames(argNames) {
|
2006-01-31 14:02:35 +08:00
|
|
|
}
|
|
|
|
|
2003-10-06 03:27:59 +08:00
|
|
|
virtual Init *convertInitializerTo(RecTy *Ty) {
|
|
|
|
return Ty->convertValue(this);
|
|
|
|
}
|
|
|
|
|
2006-03-31 06:50:40 +08:00
|
|
|
Init *getOperator() const { return Val; }
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2009-03-19 13:21:56 +08:00
|
|
|
const std::string &getName() const { return ValName; }
|
|
|
|
|
2003-10-06 03:27:59 +08: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];
|
|
|
|
}
|
|
|
|
|
|
|
|
void setArg(unsigned Num, Init *I) {
|
|
|
|
assert(Num < Args.size() && "Arg number out of range!");
|
|
|
|
Args[Num] = I;
|
|
|
|
}
|
2006-01-31 14:02:35 +08:00
|
|
|
|
|
|
|
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2007-11-23 05:05:25 +08:00
|
|
|
virtual std::string getAsString() const;
|
2008-01-22 19:00:07 +08: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-15 06:23:47 +08:00
|
|
|
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Bit) {
|
|
|
|
assert(0 && "Illegal bit reference off dag");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
|
|
|
|
unsigned Elt) {
|
|
|
|
assert(0 && "Illegal element reference off dag");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-06 03:27:59 +08: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;
|
|
|
|
void print(std::ostream &OS, bool PrintSem = true) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline std::ostream &operator<<(std::ostream &OS, const RecordVal &RV) {
|
|
|
|
RV.print(OS << " ");
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
2004-10-23 12:58:50 +08:00
|
|
|
class Record {
|
2005-08-20 01:58:49 +08:00
|
|
|
std::string Name;
|
2009-03-14 00:09:24 +08:00
|
|
|
TGLoc Loc;
|
2003-10-06 03:27:59 +08:00
|
|
|
std::vector<std::string> TemplateArgs;
|
|
|
|
std::vector<RecordVal> Values;
|
|
|
|
std::vector<Record*> SuperClasses;
|
|
|
|
public:
|
|
|
|
|
2009-03-14 00:09:24 +08:00
|
|
|
explicit Record(const std::string &N, TGLoc loc) : Name(N), Loc(loc) {}
|
2003-10-06 03:27:59 +08:00
|
|
|
~Record() {}
|
2009-03-14 00:09:24 +08:00
|
|
|
|
2003-10-06 03:27:59 +08:00
|
|
|
const std::string &getName() const { return Name; }
|
2005-08-20 01:58:11 +08:00
|
|
|
void setName(const std::string &Name); // Also updates RecordKeeper.
|
2009-03-14 00:09:24 +08:00
|
|
|
|
|
|
|
TGLoc getLoc() const { return Loc; }
|
|
|
|
|
2003-10-06 03:27:59 +08: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; }
|
|
|
|
|
|
|
|
bool isTemplateArg(const std::string &Name) const {
|
|
|
|
for (unsigned i = 0, e = TemplateArgs.size(); i != e; ++i)
|
|
|
|
if (TemplateArgs[i] == Name) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const RecordVal *getValue(const std::string &Name) const {
|
|
|
|
for (unsigned i = 0, e = Values.size(); i != e; ++i)
|
|
|
|
if (Values[i].getName() == Name) return &Values[i];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
RecordVal *getValue(const std::string &Name) {
|
|
|
|
for (unsigned i = 0, e = Values.size(); i != e; ++i)
|
|
|
|
if (Values[i].getName() == Name) return &Values[i];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void addTemplateArg(const std::string &Name) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void removeValue(const std::string &Name) {
|
|
|
|
assert(getValue(Name) && "Cannot remove an entry that does not exist!");
|
|
|
|
for (unsigned i = 0, e = Values.size(); i != e; ++i)
|
|
|
|
if (Values[i].getName() == Name) {
|
|
|
|
Values.erase(Values.begin()+i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(0 && "Name does not exist in record!");
|
|
|
|
}
|
|
|
|
|
2009-03-14 06:20:10 +08:00
|
|
|
bool isSubClassOf(const Record *R) const {
|
2003-10-06 03:27:59 +08:00
|
|
|
for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
|
|
|
|
if (SuperClasses[i] == R)
|
2005-04-22 12:13:13 +08:00
|
|
|
return true;
|
2003-10-06 03:27:59 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSubClassOf(const std::string &Name) const {
|
|
|
|
for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
|
|
|
|
if (SuperClasses[i]->getName() == Name)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void addSuperClass(Record *R) {
|
|
|
|
assert(!isSubClassOf(R) && "Already subclassing record!");
|
|
|
|
SuperClasses.push_back(R);
|
|
|
|
}
|
|
|
|
|
2005-04-19 11:36:21 +08: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);
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
void dump() const;
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// High-level methods useful to tablegen back-ends
|
|
|
|
//
|
|
|
|
|
|
|
|
/// getValueInit - Return the initializer for a value with the specified name,
|
|
|
|
/// or throw an exception if the field does not exist.
|
|
|
|
///
|
|
|
|
Init *getValueInit(const std::string &FieldName) const;
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
std::string getValueAsString(const std::string &FieldName) const;
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
BitsInit *getValueAsBitsInit(const std::string &FieldName) const;
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
ListInit *getValueAsListInit(const std::string &FieldName) const;
|
|
|
|
|
2005-10-29 06:49:02 +08:00
|
|
|
/// getValueAsListOfDefs - This method looks up the specified field and
|
2007-11-11 19:19:37 +08:00
|
|
|
/// returns its value as a vector of records, throwing an exception if the
|
2005-10-29 06:49:02 +08:00
|
|
|
/// field does not exist or if the value is not the right type.
|
2005-10-29 05:46:31 +08:00
|
|
|
///
|
2005-10-29 06:49:02 +08:00
|
|
|
std::vector<Record*> getValueAsListOfDefs(const std::string &FieldName) const;
|
2005-10-29 05:46:31 +08:00
|
|
|
|
2007-11-11 19:19:37 +08: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.
|
|
|
|
///
|
2008-10-17 09:33:43 +08:00
|
|
|
std::vector<int64_t> getValueAsListOfInts(const std::string &FieldName) const;
|
2007-11-11 19:19:37 +08:00
|
|
|
|
2003-10-06 03:27:59 +08: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.
|
|
|
|
///
|
|
|
|
Record *getValueAsDef(const std::string &FieldName) const;
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
bool getValueAsBit(const std::string &FieldName) const;
|
|
|
|
|
|
|
|
/// getValueAsInt - This method looks up the specified field and returns its
|
2008-10-17 09:33:43 +08: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-10-06 03:27:59 +08:00
|
|
|
///
|
2008-10-17 09:33:43 +08:00
|
|
|
int64_t getValueAsInt(const std::string &FieldName) const;
|
2003-10-06 03:27:59 +08: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.
|
|
|
|
///
|
|
|
|
DagInit *getValueAsDag(const std::string &FieldName) const;
|
2005-09-14 05:44:28 +08: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.
|
|
|
|
///
|
|
|
|
std::string getValueAsCode(const std::string &FieldName) const;
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &OS, const Record &R);
|
|
|
|
|
2009-04-23 04:18:10 +08:00
|
|
|
struct MultiClass {
|
|
|
|
Record Rec; // Placeholder for template args and Name.
|
|
|
|
typedef std::vector<Record*> RecordVector;
|
|
|
|
RecordVector DefPrototypes;
|
2009-04-25 00:55:41 +08:00
|
|
|
|
|
|
|
void dump() const;
|
|
|
|
|
2009-04-23 04:18:10 +08:00
|
|
|
MultiClass(const std::string &Name, TGLoc Loc) : Rec(Name, Loc) {}
|
|
|
|
};
|
|
|
|
|
2003-10-06 03:27:59 +08: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 12:13:13 +08:00
|
|
|
E = Classes.end(); I != E; ++I)
|
2003-10-06 03:27:59 +08:00
|
|
|
delete I->second;
|
|
|
|
for (std::map<std::string, Record*>::iterator I = Defs.begin(),
|
2005-04-22 12:13:13 +08:00
|
|
|
E = Defs.end(); I != E; ++I)
|
2003-10-06 03:27:59 +08:00
|
|
|
delete I->second;
|
|
|
|
}
|
2005-04-22 08:00:37 +08:00
|
|
|
|
2003-10-06 03:27:59 +08: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-20 01:58:11 +08: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);
|
|
|
|
}
|
|
|
|
|
2003-10-06 03:27:59 +08: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
|
|
|
|
/// name does not exist, an exception is thrown.
|
|
|
|
std::vector<Record*>
|
|
|
|
getAllDerivedDefinitions(const std::string &ClassName) const;
|
|
|
|
|
|
|
|
|
|
|
|
void dump() const;
|
|
|
|
};
|
|
|
|
|
2008-08-26 14:43:25 +08:00
|
|
|
/// LessRecord - Sorting predicate to sort record pointers by name.
|
|
|
|
///
|
|
|
|
struct LessRecord {
|
|
|
|
bool operator()(const Record *Rec1, const Record *Rec2) const {
|
|
|
|
return Rec1->getName() < Rec2->getName();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-09-12 01:05:32 +08:00
|
|
|
/// LessRecordFieldName - Sorting predicate to sort record pointers by their
|
|
|
|
/// name field.
|
2008-08-26 14:43:25 +08:00
|
|
|
///
|
|
|
|
struct LessRecordFieldName {
|
|
|
|
bool operator()(const Record *Rec1, const Record *Rec2) const {
|
|
|
|
return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-03-14 00:25:21 +08:00
|
|
|
|
|
|
|
class TGError {
|
|
|
|
TGLoc Loc;
|
|
|
|
std::string Message;
|
|
|
|
public:
|
|
|
|
TGError(TGLoc loc, const std::string &message) : Loc(loc), Message(message) {}
|
|
|
|
|
|
|
|
TGLoc getLoc() const { return Loc; }
|
|
|
|
const std::string &getMessage() const { return Message; }
|
|
|
|
};
|
|
|
|
|
2008-08-26 14:43:25 +08:00
|
|
|
|
2003-10-06 03:27:59 +08:00
|
|
|
std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK);
|
|
|
|
|
|
|
|
extern RecordKeeper Records;
|
|
|
|
|
2009-03-14 00:09:24 +08:00
|
|
|
void PrintError(TGLoc ErrorLoc, const std::string &Msg);
|
|
|
|
|
|
|
|
|
2003-11-12 06:41:34 +08:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2003-10-06 03:27:59 +08:00
|
|
|
#endif
|