forms.hpp revision 1472
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
// FORMS.HPP - ADL Parser Generic and Utility Forms Classes
#define TRUE 1
#define FALSE 0
// DEFINITIONS OF LEGAL ATTRIBUTE TYPES
#define INS_ATTR 0
#define OP_ATTR 1
// DEFINITIONS OF LEGAL CONSTRAINT TYPES
// Class List
class Form;
class InstructForm;
class MachNodeForm;
class OperandForm;
class OpClassForm;
class AttributeForm;
class RegisterForm;
class PipelineForm;
class SourceForm;
class EncodeForm;
class Component;
class Constraint;
class Predicate;
class MatchRule;
class Attribute;
class Effect;
class ExpandRule;
class RewriteRule;
class ConstructRule;
class FormatRule;
class Peephole;
class EncClass;
class Interface;
class RegInterface;
class ConstInterface;
class MemInterface;
class CondInterface;
class Opcode;
class InsEncode;
class RegDef;
class RegClass;
class AllocClass;
class ResourceForm;
class PipeClassForm;
class PeepMatch;
class PeepConstraint;
class PeepReplace;
class MatchList;
class ArchDesc;
//------------------------------FormDict---------------------------------------
// Dictionary containing Forms, and objects derived from forms
class FormDict {
private:
// Disable public use of constructor, copy-ctor, operator =, operator ==
FormDict( );
// == compares two dictionaries; they must have the same keys (their keys
// must match using CmpKey) and they must have the same values (pointer
// comparison). If so 1 is returned, if not 0 is returned.
bool operator ==(const FormDict &d) const; // Compare dictionaries for equal
public:
// cmp is a key comparision routine. hash is a routine to hash a key.
// FormDict( CmpKey cmp, Hash hash );
~FormDict();
// Return # of key-value pairs in dict
int Size(void) const;
// Insert inserts the given key-value pair into the dictionary. The prior
// value of the key is returned; NULL if the key was not previously defined.
// Find finds the value of a given key; or NULL if not found.
// The dictionary is NOT changed.
void dump();
};
// ***** Master Class for ADL Parser Forms *****
//------------------------------Form-------------------------------------------
class Form {
public:
private:
protected:
int _ftype; // Indicator for derived class type
public:
// Public Data
int _linenum; // Line number for debugging
// Dynamic type check for common forms.
virtual OpClassForm *is_opclass() const;
virtual OperandForm *is_operand() const;
virtual InstructForm *is_instruction() const;
virtual MachNodeForm *is_machnode() const;
virtual AttributeForm *is_attribute() const;
virtual ResourceForm *is_resource() const;
virtual PipeClassForm *is_pipeclass() const;
// Check if this form is an operand usable for cisc-spilling
// Public Methods
~Form() {};
virtual bool ideal_only() const {
assert(0,"Check of ideal status on non-instruction/operand form.\n");
return FALSE;
}
// Check constraints after parsing
virtual bool verify() { return true; }
// Write info to output files
public:
// ADLC types, match the last character on ideal operands and instructions
enum DataType {
none = 0, // Not a simple type
};
// Convert ideal name to a DataType, return DataType::none if not a 'ConX'
// Convert ideal name to a DataType, return DataType::none if not a 'sRegX
// Convert ideal name to a DataType, return DataType::none if not a 'RegX
// Convert ideal name to a DataType, return DataType::none if not a 'LoadX
// Convert ideal name to a DataType, return DataType::none if not a 'StoreX
// ADLC call types, matched with ideal world
enum CallType {
invalid_type = 0, // invalid call type
};
// Interface types for operands and operand classes
enum InterfaceType {
no_interface = 0, // unknown or inconsistent interface type
};
enum CiscSpillInfo {
Maybe_cisc_spillable = 0,
// ...
};
// LEGAL FORM TYPES
enum {
INS,
OPER,
SRC,
ADEF,
REG,
PIPE,
CNST,
PRED,
ATTR,
MAT,
ENC,
FOR,
EXP,
REW,
EFF,
RDEF,
RCL,
ACL,
RES,
PCL,
PDEF,
REGL,
RESL,
STAL,
COMP,
PEEP,
};
};
//------------------------------FormList---------------------------------------
class FormList {
private:
int _justReset; // Set immediately after reset
int _justReset2;
public:
};
return _cur;};
// Second iterator, state is internal
return _cur2;};
int count() {
return count;
}
void dump() {
reset();
};
}
bool verify() {
bool verified = true;
reset();
};
return verified;
}
reset();
};
}
FormList() { _justReset = 1; _justReset2 = 1; _root = NULL; _tail = NULL; _cur = NULL; _cur2 = NULL;};
~FormList();
};
//------------------------------NameList---------------------------------------
// Extendable list of pointers, <char *>
class NameList {
friend class PreserveIter;
private:
int _cur; // Insert next entry here; count of entries
int _max; // Number of spaces allocated
const char **_names; // Array of names
protected:
int _iter; // position during iteration
bool _justReset; // Set immediately after reset
public:
static const char *_signal; // reserved user-defined string
static const char *_signal2; // reserved user-defined string
static const char *_signal3; // reserved user-defined string
enum { Not_in_list = -1 };
void add_signal();
void clear(); // Remove all entries
int count() const;
void reset(); // Reset iteration
const char *iter(); // after reset(), first element : else next
const char *current(); // return current element in iteration.
bool current_is_signal(); // Return 'true' if current entry is signal
bool search(const char *); // Search for a name in the list
int index(const char *); // Return index of name in list
void dump(); // output to stderr
NameList();
~NameList();
};
// Convenience class to preserve iteration state since iterators are
// internal instead of being external.
class PreserveIter {
private:
int _iter;
bool _justReset;
public:
}
~PreserveIter() {
}
};
//------------------------------NameAndList------------------------------------
// Storage for a name and an associated list of names
class NameAndList {
private:
const char *_name;
public:
NameAndList(char *name);
~NameAndList();
// Add to entries in list
// Access the name and its associated list.
const char *name() const;
void reset();
const char *iter();
// Return the "index" entry in the list, zero-based
const char *operator[](int index);
void dump(); // output to stderr
};
//------------------------------ComponentList---------------------------------
// Component lists always have match rule operands first, followed by parameter
// operands which do not appear in the match list (in order of declaration).
class ComponentList : private NameList {
private:
int _matchcnt; // Count of match rule operands
public:
// This is a batch program. (And I have a destructor bug!)
void operator delete( void *ptr ) {}
int count();
void reset(); // Reset iteration
// Return element at "position", else NULL
// Return first component having this name.
// Return number of USEs + number of DEFs
int num_operands();
// Return zero-based position in list; -1 if not in list.
int operand_position(const char *name);
// Find position for this name when looked up for output via "format"
int operand_position_format(const char *name);
// Find position for the Label when looked up for output via "format"
int label_position();
// Find position for the Method when looked up for output via "format"
int method_position();
void dump(); // output to stderr
~ComponentList();
};
//------------------------------SourceForm-------------------------------------
class SourceForm : public Form {
private:
public:
// Public Data
char *_code; // Buffer for storing code text
// Public Methods
SourceForm(char* code);
~SourceForm();
virtual const char* classname() { return "SourceForm"; }
void dump(); // Debug printer
};
class HeaderForm : public SourceForm {
public:
virtual const char* classname() { return "HeaderForm"; }
};
class PreHeaderForm : public SourceForm {
public:
virtual const char* classname() { return "PreHeaderForm"; }
};
//------------------------------Expr------------------------------------------
#define STRING_BUFFER_LENGTH 2048
// class Expr represents integer expressions containing constants and addition
// Value must be in range zero through maximum positive integer. 32bits.
// Expected use: instruction and operand costs
class Expr {
public:
enum {
Zero = 0,
Max = 0x7fffffff
};
const char *_external_name; // if !NULL, then print this instead of _expr
const char *_expr;
int _min_value;
int _max_value;
Expr();
void add(const char *c);
void print() const;
static char *buffer() { return &external_buffer[0]; }
static bool init_buffers(); // Fill buffers with 0
static bool check_buffers(); // if buffer use may have overflowed, assert
private:
static Expr *_unknown_expr;
static char string_buffer[STRING_BUFFER_LENGTH];
static char external_buffer[STRING_BUFFER_LENGTH];
static bool _init_buffers;
const char *compute_expr(const Expr *c1, const Expr *c2); // cost as string after adding 'c1' and 'c2'
const char *compute_external(const Expr *c1, const Expr *c2); // external name after adding 'c1' and 'c2'
};
//------------------------------ExprDict---------------------------------------
// Dictionary containing Exprs
class ExprDict {
private:
// Disable public use of constructor, copy-ctor, operator =, operator ==
ExprDict( );
// == compares two dictionaries; they must have the same keys (their keys
// must match using CmpKey) and they must have the same values (pointer
// comparison). If so 1 is returned, if not 0 is returned.
bool operator ==(const ExprDict &d) const; // Compare dictionaries for equal
public:
// cmp is a key comparision routine. hash is a routine to hash a key.
~ExprDict();
// Return # of key-value pairs in dict
int Size(void) const;
// define inserts the given key-value pair into the dictionary,
// and records the name in order for later output, ...
// Insert inserts the given key-value pair into the dictionary. The prior
// value of the key is returned; NULL if the key was not previously defined.
// Find finds the value of a given key; or NULL if not found.
// The dictionary is NOT changed.
void dump();
};