Neg instruction removed. Cast instruction implemented.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2001-07-08 04:57:15 +00:00
parent f22696f209
commit 0908309e3c
19 changed files with 752 additions and 722 deletions

View File

@ -60,7 +60,6 @@ protected:
inline ConstRules() {} // Can only be subclassed... inline ConstRules() {} // Can only be subclassed...
public: public:
// Unary Operators... // Unary Operators...
virtual ConstPoolVal *neg(const ConstPoolVal *V) const = 0;
virtual ConstPoolVal *not(const ConstPoolVal *V) const = 0; virtual ConstPoolVal *not(const ConstPoolVal *V) const = 0;
// Binary Operators... // Binary Operators...
@ -88,10 +87,6 @@ private :
}; };
inline ConstPoolVal *operator-(const ConstPoolVal &V) {
return ConstRules::get(V)->neg(&V);
}
inline ConstPoolVal *operator!(const ConstPoolVal &V) { inline ConstPoolVal *operator!(const ConstPoolVal &V) {
return ConstRules::get(V)->not(&V); return ConstRules::get(V)->not(&V);
} }
@ -154,7 +149,6 @@ inline ConstPoolVal *ConstantFoldUnaryInstruction(unsigned Opcode,
ConstPoolVal *V) { ConstPoolVal *V) {
switch (Opcode) { switch (Opcode) {
case Instruction::Not: return !*V; case Instruction::Not: return !*V;
case Instruction::Neg: return -*V;
} }
return 0; return 0;
} }

View File

@ -55,10 +55,12 @@ public:
// create() - Construct a unary instruction, given the opcode // create() - Construct a unary instruction, given the opcode
// and its operand. // and its operand.
// //
static UnaryOperator *create(UnaryOps Op, Value *Source); static UnaryOperator *create(UnaryOps Op, Value *Source,
const Type *DestTy = 0);
UnaryOperator(Value *S, UnaryOps iType, const string &Name = "") UnaryOperator(Value *S, UnaryOps iType, const Type *ResultType,
: Instruction(S->getType(), iType, Name) { const string &Name = "")
: Instruction(ResultType, iType, Name) {
Operands.reserve(1); Operands.reserve(1);
Operands.push_back(Use(S, this)); Operands.push_back(Use(S, this));
} }

View File

@ -77,14 +77,8 @@ public:
enum UnaryOps { enum UnaryOps {
FirstUnaryOp = NumTermOps, FirstUnaryOp = NumTermOps,
Neg = NumTermOps, Not, Not = NumTermOps, // Binary inverse
Cast, // Type cast...
// Type conversions...
ToBoolTy ,
ToUByteTy , ToSByteTy, ToUShortTy, ToShortTy,
ToUInt , ToInt, ToULongTy , ToLongTy,
ToFloatTy , ToDoubleTy, ToArrayTy , ToPointerTy,
NumUnaryOps // Must remain at end of enum NumUnaryOps // Must remain at end of enum
}; };

View File

@ -9,6 +9,20 @@
#include "llvm/InstrTypes.h" #include "llvm/InstrTypes.h"
//===----------------------------------------------------------------------===//
// Class to represent Unary operators
//===----------------------------------------------------------------------===//
//
class GenericUnaryInst : public UnaryOperator {
public:
GenericUnaryInst(UnaryOps Opcode, Value *S1, const Type *ResultTy = 0,
const string &Name = "")
: UnaryOperator(S1, Opcode, ResultTy, Name) {
}
virtual const char *getOpcodeName() const;
};
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Classes to represent Binary operators // Classes to represent Binary operators
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -308,26 +308,26 @@ static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
*yy_cp = '\0'; \ *yy_cp = '\0'; \
yy_c_buf_p = yy_cp; yy_c_buf_p = yy_cp;
#define YY_NUM_RULES 58 #define YY_NUM_RULES 59
#define YY_END_OF_BUFFER 59 #define YY_END_OF_BUFFER 60
static yyconst short int yy_acclist[113] = static yyconst short int yy_acclist[114] =
{ 0, { 0,
59, 57, 58, 56, 57, 58, 56, 58, 57, 58, 60, 58, 59, 57, 58, 59, 57, 59, 58, 59,
57, 58, 57, 58, 8, 57, 58, 52, 57, 58, 58, 59, 58, 59, 8, 58, 59, 53, 58, 59,
1, 57, 58, 57, 58, 57, 58, 57, 58, 57, 1, 58, 59, 58, 59, 58, 59, 58, 59, 58,
58, 57, 58, 57, 58, 57, 58, 57, 58, 57, 59, 58, 59, 58, 59, 58, 59, 58, 59, 58,
58, 57, 58, 57, 58, 57, 58, 57, 58, 57, 59, 58, 59, 58, 59, 58, 59, 58, 59, 58,
58, 57, 58, 57, 58, 57, 58, 50, 49, 54, 59, 58, 59, 58, 59, 58, 59, 51, 50, 55,
53, 52, 1, 9, 40, 51, 49, 55, 28, 31, 54, 53, 1, 9, 41, 26, 52, 50, 56, 29,
3, 16, 30, 24, 25, 26, 32, 39, 29, 11, 32, 3, 16, 31, 24, 27, 33, 40, 30, 11,
27, 44, 45, 18, 4, 22, 17, 10, 2, 5, 28, 25, 45, 46, 18, 4, 22, 17, 10, 2,
20, 23, 12, 34, 38, 36, 37, 35, 33, 14, 5, 20, 23, 12, 35, 39, 37, 38, 36, 34,
46, 13, 19, 43, 21, 42, 41, 15, 6, 47, 14, 47, 13, 19, 44, 21, 43, 42, 15, 6,
48, 7 48, 49, 7
} ; } ;
static yyconst short int yy_accept[199] = static yyconst short int yy_accept[200] =
{ 0, { 0,
1, 1, 1, 2, 4, 7, 9, 11, 13, 15, 1, 1, 1, 2, 4, 7, 9, 11, 13, 15,
18, 21, 24, 26, 28, 30, 32, 34, 36, 38, 18, 21, 24, 26, 28, 30, 32, 34, 36, 38,
@ -336,20 +336,20 @@ static yyconst short int yy_accept[199] =
64, 65, 65, 65, 66, 66, 66, 66, 66, 66, 64, 65, 65, 65, 66, 66, 66, 66, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 67, 68, 67, 67, 67, 67, 67, 67, 67, 67, 68, 69,
69, 70, 70, 70, 70, 70, 70, 71, 71, 72, 70, 71, 71, 71, 71, 71, 71, 71, 72, 72,
72, 72, 72, 72, 72, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 74, 74, 74, 74,
74, 75, 76, 77, 77, 78, 79, 79, 79, 79, 74, 75, 76, 77, 77, 78, 79, 79, 79, 79,
79, 80, 80, 80, 80, 80, 80, 80, 80, 80, 79, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 81, 82, 82, 82, 82, 82, 83, 83, 80, 80, 81, 82, 83, 83, 83, 83, 83, 84,
83, 83, 84, 85, 85, 85, 85, 85, 85, 85, 84, 84, 84, 85, 86, 86, 86, 86, 86, 86,
85, 85, 85, 85, 86, 87, 87, 88, 88, 88, 86, 86, 86, 86, 86, 87, 88, 88, 89, 89,
89, 89, 90, 90, 90, 91, 92, 92, 92, 93, 89, 90, 90, 91, 91, 91, 92, 93, 93, 93,
93, 93, 94, 95, 96, 97, 98, 99, 100, 101, 94, 94, 94, 95, 96, 97, 98, 99, 100, 101,
102, 102, 103, 104, 104, 105, 105, 106, 106, 106, 102, 103, 103, 104, 105, 105, 106, 106, 107, 107,
107, 107, 108, 109, 110, 110, 110, 110, 111, 111, 107, 108, 108, 109, 110, 111, 111, 111, 111, 112,
112, 112, 112, 112, 112, 112, 113, 113 112, 113, 113, 113, 113, 113, 113, 114, 114
} ; } ;
@ -393,61 +393,61 @@ static yyconst int yy_meta[33] =
4, 4 4, 4
} ; } ;
static yyconst short int yy_base[203] = static yyconst short int yy_base[204] =
{ 0, { 0,
0, 0, 389, 390, 390, 390, 0, 379, 26, 379, 0, 0, 391, 392, 392, 392, 0, 381, 26, 381,
27, 0, 28, 40, 29, 35, 34, 42, 30, 38, 27, 0, 28, 40, 29, 35, 34, 42, 30, 38,
56, 60, 55, 63, 65, 84, 68, 107, 52, 382, 56, 60, 52, 55, 61, 81, 65, 104, 63, 384,
376, 390, 0, 376, 375, 374, 74, 0, 32, 64, 378, 392, 0, 378, 377, 376, 69, 0, 32, 72,
372, 78, 67, 371, 77, 92, 76, 79, 89, 98, 374, 78, 71, 373, 91, 89, 73, 76, 92, 95,
100, 95, 102, 105, 108, 112, 111, 119, 122, 123, 98, 99, 108, 110, 111, 113, 118, 117, 121, 119,
116, 126, 128, 129, 132, 134, 137, 138, 139, 140, 123, 124, 129, 126, 134, 136, 137, 139, 135, 372,
143, 144, 145, 149, 146, 156, 154, 390, 0, 371, 140, 144, 146, 152, 147, 154, 156, 392, 0, 372,
369, 157, 166, 158, 161, 167, 368, 170, 367, 174, 370, 157, 158, 162, 164, 155, 167, 369, 176, 368,
175, 179, 180, 182, 366, 183, 181, 188, 184, 365, 170, 180, 177, 184, 181, 367, 187, 185, 186, 189,
364, 363, 362, 190, 361, 360, 191, 211, 198, 199, 366, 365, 364, 195, 363, 362, 196, 216, 197, 201,
359, 194, 200, 201, 202, 204, 205, 212, 203, 225, 361, 198, 199, 203, 204, 206, 207, 212, 208, 228,
214, 358, 357, 228, 209, 231, 232, 356, 233, 234, 221, 360, 359, 358, 231, 219, 235, 236, 357, 237,
235, 355, 354, 236, 238, 239, 241, 247, 249, 252, 238, 239, 356, 355, 240, 242, 243, 245, 251, 253,
242, 254, 259, 353, 352, 256, 351, 264, 265, 350, 256, 246, 258, 263, 354, 353, 260, 352, 268, 269,
267, 349, 270, 271, 348, 347, 273, 274, 346, 276, 351, 271, 350, 274, 275, 349, 348, 277, 278, 347,
275, 345, 344, 343, 342, 341, 340, 335, 330, 325, 280, 279, 346, 345, 344, 339, 334, 329, 324, 323,
283, 320, 319, 278, 317, 284, 316, 285, 288, 315, 321, 287, 320, 319, 282, 317, 288, 315, 289, 292,
289, 313, 311, 310, 293, 291, 301, 308, 295, 244, 314, 293, 312, 248, 211, 297, 295, 305, 210, 299,
303, 299, 302, 307, 309, 82, 390, 331, 334, 337, 172, 307, 303, 306, 311, 313, 74, 392, 335, 338,
342, 53 341, 346, 53
} ; } ;
static yyconst short int yy_def[203] = static yyconst short int yy_def[204] =
{ 0, { 0,
197, 1, 197, 197, 197, 197, 198, 199, 200, 197, 198, 1, 198, 198, 198, 198, 199, 200, 201, 198,
199, 201, 199, 199, 199, 199, 199, 199, 199, 199, 200, 202, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 198, 200, 200, 200, 200, 200, 200, 200, 200, 200, 199,
199, 197, 202, 197, 197, 197, 199, 201, 199, 199, 200, 198, 203, 198, 198, 198, 200, 202, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 197, 202, 197, 200, 200, 200, 200, 200, 200, 200, 198, 203, 198,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
199, 199, 199, 199, 199, 199, 0, 197, 197, 197, 200, 200, 200, 200, 200, 200, 200, 0, 198, 198,
197, 197 198, 198, 198
} ; } ;
static yyconst short int yy_nxt[423] = static yyconst short int yy_nxt[425] =
{ 0, { 0,
4, 5, 6, 7, 8, 9, 10, 11, 4, 12, 4, 5, 6, 7, 8, 9, 10, 11, 4, 12,
13, 14, 15, 16, 17, 18, 19, 8, 20, 21, 13, 14, 15, 16, 17, 18, 19, 8, 20, 21,
@ -455,98 +455,98 @@ static yyconst short int yy_nxt[423] =
8, 8, 34, 35, 37, 32, 32, 32, 32, 45, 8, 8, 34, 35, 37, 32, 32, 32, 32, 45,
32, 39, 32, 32, 53, 81, 32, 40, 32, 46, 32, 39, 32, 32, 53, 81, 32, 40, 32, 46,
32, 41, 50, 47, 42, 49, 79, 48, 54, 55, 32, 41, 50, 47, 42, 49, 79, 48, 54, 55,
32, 51, 43, 32, 32, 44, 56, 52, 32, 60, 32, 51, 43, 32, 32, 44, 56, 52, 32, 32,
58, 32, 32, 32, 77, 32, 32, 61, 57, 64, 58, 32, 61, 32, 60, 63, 37, 32, 57, 32,
62, 37, 32, 82, 32, 32, 32, 32, 59, 84, 32, 32, 32, 62, 32, 77, 32, 70, 59, 32,
32, 63, 32, 71, 83, 65, 85, 32, 66, 72, 71, 82, 64, 84, 83, 65, 72, 32, 66, 32,
32, 67, 89, 32, 86, 87, 32, 88, 32, 92, 32, 87, 88, 32, 89, 90, 32, 32, 67, 68,
32, 68, 69, 32, 70, 32, 32, 90, 73, 32, 85, 69, 32, 93, 91, 73, 32, 86, 32, 32,
32, 97, 91, 96, 32, 74, 75, 32, 94, 93, 92, 32, 74, 75, 97, 32, 32, 32, 98, 32,
32, 32, 98, 76, 32, 95, 32, 32, 99, 101, 76, 32, 32, 95, 32, 94, 100, 32, 96, 99,
32, 100, 32, 102, 103, 32, 32, 32, 32, 105, 101, 103, 32, 32, 32, 32, 102, 32, 32, 105,
111, 32, 32, 32, 32, 104, 106, 32, 112, 109, 111, 104, 32, 112, 32, 32, 106, 107, 109, 110,
110, 108, 32, 107, 32, 32, 32, 114, 117, 32, 32, 108, 32, 32, 32, 32, 32, 114, 113, 117,
116, 113, 119, 118, 32, 32, 115, 122, 32, 120, 32, 118, 32, 116, 119, 32, 121, 115, 32, 120,
123, 125, 32, 32, 121, 127, 124, 32, 32, 32, 32, 122, 124, 123, 32, 32, 125, 126, 32, 32,
32, 32, 32, 128, 132, 129, 32, 131, 32, 32, 128, 129, 32, 32, 32, 32, 127, 32, 133, 130,
126, 130, 32, 134, 133, 135, 32, 32, 32, 32, 131, 132, 134, 32, 32, 32, 32, 32, 135, 32,
32, 32, 32, 32, 144, 145, 150, 32, 136, 32, 136, 32, 32, 145, 32, 32, 32, 146, 32, 32,
32, 143, 32, 141, 142, 137, 148, 138, 154, 146, 32, 151, 142, 137, 32, 144, 143, 32, 149, 32,
139, 147, 140, 32, 149, 152, 32, 151, 153, 32, 138, 147, 139, 148, 150, 140, 32, 141, 155, 32,
32, 32, 32, 32, 32, 155, 32, 32, 158, 32, 152, 154, 153, 32, 32, 32, 32, 32, 32, 156,
32, 157, 32, 162, 159, 32, 161, 32, 160, 156, 32, 32, 159, 32, 32, 158, 32, 163, 160, 32,
32, 164, 32, 166, 32, 163, 168, 32, 170, 169, 162, 32, 161, 157, 32, 165, 32, 167, 32, 164,
172, 171, 32, 32, 165, 32, 167, 175, 32, 32, 169, 32, 171, 170, 173, 172, 32, 32, 166, 32,
173, 32, 32, 32, 32, 177, 32, 178, 180, 181, 168, 176, 32, 32, 174, 32, 32, 32, 32, 178,
174, 32, 32, 32, 179, 176, 32, 32, 184, 32, 32, 179, 181, 182, 175, 32, 32, 32, 180, 177,
182, 32, 186, 32, 185, 183, 188, 32, 187, 32, 32, 32, 185, 32, 183, 32, 187, 32, 186, 184,
32, 32, 189, 192, 190, 32, 32, 32, 32, 32, 189, 32, 188, 32, 32, 32, 190, 193, 191, 32,
194, 32, 191, 32, 32, 32, 193, 32, 32, 195, 32, 32, 32, 32, 195, 32, 192, 32, 32, 32,
196, 30, 30, 32, 30, 30, 30, 31, 32, 31, 194, 32, 32, 196, 197, 30, 30, 32, 30, 30,
33, 33, 38, 32, 38, 38, 38, 38, 32, 32, 30, 31, 32, 31, 33, 33, 38, 32, 38, 38,
38, 38, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 80,
32, 32, 32, 32, 32, 32, 32, 32, 80, 32, 32, 32, 32, 36, 35, 80, 32, 78, 36, 32,
32, 36, 35, 80, 32, 78, 36, 32, 197, 3, 198, 3, 198, 198, 198, 198, 198, 198, 198, 198,
197, 197, 197, 197, 197, 197, 197, 197, 197, 197,
197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198,
197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198,
197, 197 198, 198, 198, 198
} ; } ;
static yyconst short int yy_chk[423] = static yyconst short int yy_chk[425] =
{ 0, { 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 9, 9, 11, 11, 13, 15, 19, 15, 1, 1, 9, 9, 11, 11, 13, 15, 19, 15,
39, 13, 17, 16, 19, 39, 20, 13, 14, 16, 39, 13, 17, 16, 19, 39, 20, 13, 14, 16,
18, 14, 18, 16, 14, 17, 202, 16, 20, 20, 18, 14, 18, 16, 14, 17, 203, 16, 20, 20,
29, 18, 14, 23, 21, 14, 21, 18, 22, 23, 23, 18, 14, 24, 21, 14, 21, 18, 22, 25,
22, 24, 40, 25, 29, 43, 27, 23, 21, 25, 22, 29, 24, 27, 23, 25, 37, 37, 21, 43,
24, 37, 37, 40, 47, 45, 42, 48, 22, 43, 40, 47, 197, 24, 48, 29, 42, 27, 22, 26,
196, 24, 26, 27, 42, 26, 45, 49, 26, 27, 27, 40, 26, 43, 42, 26, 27, 46, 26, 45,
46, 26, 49, 52, 46, 47, 50, 48, 51, 52, 49, 46, 47, 50, 48, 49, 51, 52, 26, 26,
53, 26, 26, 54, 26, 28, 55, 50, 28, 57, 45, 26, 28, 52, 50, 28, 53, 45, 54, 55,
56, 57, 51, 56, 61, 28, 28, 58, 54, 53, 51, 56, 28, 28, 56, 58, 57, 60, 57, 59,
59, 60, 57, 28, 62, 55, 63, 64, 58, 60, 28, 61, 62, 54, 64, 53, 58, 63, 55, 57,
65, 59, 66, 61, 62, 67, 68, 69, 70, 64, 59, 61, 65, 69, 66, 67, 60, 68, 71, 63,
69, 71, 72, 73, 75, 63, 64, 74, 70, 67, 68, 62, 72, 69, 73, 75, 63, 64, 66, 67,
68, 66, 77, 65, 76, 82, 84, 72, 75, 85, 74, 65, 76, 86, 77, 82, 83, 72, 71, 75,
74, 71, 77, 76, 83, 86, 73, 84, 88, 82, 84, 76, 85, 74, 77, 87, 83, 73, 91, 82,
85, 88, 90, 91, 83, 91, 86, 92, 93, 97, 191, 84, 86, 85, 89, 93, 87, 89, 92, 95,
94, 96, 99, 92, 97, 93, 98, 96, 104, 107, 92, 93, 94, 98, 99, 97, 91, 100, 98, 94,
90, 94, 112, 99, 98, 104, 109, 110, 113, 114, 95, 97, 99, 104, 107, 109, 112, 113, 100, 110,
115, 119, 116, 117, 113, 114, 119, 125, 107, 108, 104, 114, 115, 113, 116, 117, 119, 114, 189, 185,
118, 112, 121, 109, 110, 108, 117, 108, 125, 115, 118, 119, 109, 107, 108, 112, 110, 126, 117, 121,
108, 116, 108, 120, 118, 121, 124, 120, 124, 126, 108, 115, 108, 116, 118, 108, 120, 108, 126, 125,
127, 129, 130, 131, 134, 126, 135, 136, 130, 137, 120, 125, 121, 127, 128, 130, 131, 132, 135, 127,
141, 129, 190, 136, 131, 138, 135, 139, 134, 127, 136, 137, 131, 138, 142, 130, 184, 137, 132, 139,
140, 138, 142, 139, 146, 137, 140, 143, 142, 141, 136, 140, 135, 128, 141, 139, 143, 140, 147, 138,
146, 143, 148, 149, 138, 151, 139, 151, 153, 154, 141, 144, 143, 142, 147, 144, 149, 150, 139, 152,
148, 157, 158, 161, 160, 154, 174, 157, 160, 161, 140, 152, 154, 155, 149, 158, 159, 162, 161, 155,
149, 171, 176, 178, 158, 153, 179, 181, 176, 186, 175, 158, 161, 162, 150, 172, 177, 179, 159, 154,
171, 185, 179, 189, 178, 174, 185, 192, 181, 187, 180, 182, 177, 187, 172, 186, 180, 190, 179, 175,
193, 191, 186, 191, 187, 194, 188, 195, 184, 183, 186, 193, 182, 188, 194, 192, 187, 192, 188, 195,
193, 182, 189, 180, 177, 175, 192, 173, 172, 194, 183, 196, 181, 178, 194, 176, 190, 174, 173, 171,
195, 198, 198, 170, 198, 198, 198, 199, 169, 199, 193, 170, 169, 195, 196, 199, 199, 168, 199, 199,
200, 200, 201, 168, 201, 201, 201, 201, 167, 166, 199, 200, 167, 200, 201, 201, 202, 166, 202, 202,
165, 164, 163, 162, 159, 156, 155, 152, 150, 147, 202, 202, 165, 164, 163, 160, 157, 156, 153, 151,
145, 144, 133, 132, 128, 123, 122, 111, 106, 105, 148, 146, 145, 134, 133, 129, 124, 123, 122, 111,
103, 102, 101, 100, 95, 89, 87, 81, 80, 44, 106, 105, 103, 102, 101, 96, 90, 88, 81, 80,
41, 36, 35, 34, 31, 30, 10, 8, 3, 197, 70, 44, 41, 36, 35, 34, 31, 30, 10, 8,
197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 3, 198, 198, 198, 198, 198, 198, 198, 198, 198,
197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198,
197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198,
197, 197 198, 198, 198, 198
} ; } ;
static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr; static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;
@ -816,14 +816,14 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 198 ) if ( yy_current_state >= 199 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
*yy_state_ptr++ = yy_current_state; *yy_state_ptr++ = yy_current_state;
++yy_cp; ++yy_cp;
} }
while ( yy_current_state != 197 ); while ( yy_current_state != 198 );
yy_find_action: yy_find_action:
yy_current_state = *--yy_state_ptr; yy_current_state = *--yy_state_ptr;
@ -976,159 +976,164 @@ YY_RULE_SETUP
case 24: case 24:
YY_RULE_SETUP YY_RULE_SETUP
#line 114 "Lexer.l" #line 114 "Lexer.l"
{ RET_TOK(UnaryOpVal, Neg, NEG); } { RET_TOK(UnaryOpVal, Not, NOT); }
YY_BREAK YY_BREAK
case 25: case 25:
YY_RULE_SETUP YY_RULE_SETUP
#line 115 "Lexer.l" #line 115 "Lexer.l"
{ RET_TOK(UnaryOpVal, Not, NOT); } { RET_TOK(UnaryOpVal, Cast, CAST); }
YY_BREAK YY_BREAK
case 26: case 26:
YY_RULE_SETUP YY_RULE_SETUP
#line 117 "Lexer.l" #line 117 "Lexer.l"
{ return PHI; } { return TO; }
YY_BREAK YY_BREAK
case 27: case 27:
YY_RULE_SETUP YY_RULE_SETUP
#line 118 "Lexer.l" #line 118 "Lexer.l"
{ return CALL; } { return PHI; }
YY_BREAK YY_BREAK
case 28: case 28:
YY_RULE_SETUP YY_RULE_SETUP
#line 119 "Lexer.l" #line 119 "Lexer.l"
{ RET_TOK(BinaryOpVal, Add, ADD); } { return CALL; }
YY_BREAK YY_BREAK
case 29: case 29:
YY_RULE_SETUP YY_RULE_SETUP
#line 120 "Lexer.l" #line 120 "Lexer.l"
{ RET_TOK(BinaryOpVal, Sub, SUB); } { RET_TOK(BinaryOpVal, Add, ADD); }
YY_BREAK YY_BREAK
case 30: case 30:
YY_RULE_SETUP YY_RULE_SETUP
#line 121 "Lexer.l" #line 121 "Lexer.l"
{ RET_TOK(BinaryOpVal, Mul, MUL); } { RET_TOK(BinaryOpVal, Sub, SUB); }
YY_BREAK YY_BREAK
case 31: case 31:
YY_RULE_SETUP YY_RULE_SETUP
#line 122 "Lexer.l" #line 122 "Lexer.l"
{ RET_TOK(BinaryOpVal, Div, DIV); } { RET_TOK(BinaryOpVal, Mul, MUL); }
YY_BREAK YY_BREAK
case 32: case 32:
YY_RULE_SETUP YY_RULE_SETUP
#line 123 "Lexer.l" #line 123 "Lexer.l"
{ RET_TOK(BinaryOpVal, Rem, REM); } { RET_TOK(BinaryOpVal, Div, DIV); }
YY_BREAK YY_BREAK
case 33: case 33:
YY_RULE_SETUP YY_RULE_SETUP
#line 124 "Lexer.l" #line 124 "Lexer.l"
{ RET_TOK(BinaryOpVal, SetNE, SETNE); } { RET_TOK(BinaryOpVal, Rem, REM); }
YY_BREAK YY_BREAK
case 34: case 34:
YY_RULE_SETUP YY_RULE_SETUP
#line 125 "Lexer.l" #line 125 "Lexer.l"
{ RET_TOK(BinaryOpVal, SetEQ, SETEQ); } { RET_TOK(BinaryOpVal, SetNE, SETNE); }
YY_BREAK YY_BREAK
case 35: case 35:
YY_RULE_SETUP YY_RULE_SETUP
#line 126 "Lexer.l" #line 126 "Lexer.l"
{ RET_TOK(BinaryOpVal, SetLT, SETLT); } { RET_TOK(BinaryOpVal, SetEQ, SETEQ); }
YY_BREAK YY_BREAK
case 36: case 36:
YY_RULE_SETUP YY_RULE_SETUP
#line 127 "Lexer.l" #line 127 "Lexer.l"
{ RET_TOK(BinaryOpVal, SetGT, SETGT); } { RET_TOK(BinaryOpVal, SetLT, SETLT); }
YY_BREAK YY_BREAK
case 37: case 37:
YY_RULE_SETUP YY_RULE_SETUP
#line 128 "Lexer.l" #line 128 "Lexer.l"
{ RET_TOK(BinaryOpVal, SetLE, SETLE); } { RET_TOK(BinaryOpVal, SetGT, SETGT); }
YY_BREAK YY_BREAK
case 38: case 38:
YY_RULE_SETUP YY_RULE_SETUP
#line 129 "Lexer.l" #line 129 "Lexer.l"
{ RET_TOK(BinaryOpVal, SetGE, SETGE); } { RET_TOK(BinaryOpVal, SetLE, SETLE); }
YY_BREAK YY_BREAK
case 39: case 39:
YY_RULE_SETUP YY_RULE_SETUP
#line 131 "Lexer.l" #line 130 "Lexer.l"
{ RET_TOK(TermOpVal, Ret, RET); } { RET_TOK(BinaryOpVal, SetGE, SETGE); }
YY_BREAK YY_BREAK
case 40: case 40:
YY_RULE_SETUP YY_RULE_SETUP
#line 132 "Lexer.l" #line 132 "Lexer.l"
{ RET_TOK(TermOpVal, Br, BR); } { RET_TOK(TermOpVal, Ret, RET); }
YY_BREAK YY_BREAK
case 41: case 41:
YY_RULE_SETUP YY_RULE_SETUP
#line 133 "Lexer.l" #line 133 "Lexer.l"
{ RET_TOK(TermOpVal, Switch, SWITCH); } { RET_TOK(TermOpVal, Br, BR); }
YY_BREAK YY_BREAK
case 42: case 42:
YY_RULE_SETUP YY_RULE_SETUP
#line 136 "Lexer.l" #line 134 "Lexer.l"
{ RET_TOK(MemOpVal, Malloc, MALLOC); } { RET_TOK(TermOpVal, Switch, SWITCH); }
YY_BREAK YY_BREAK
case 43: case 43:
YY_RULE_SETUP YY_RULE_SETUP
#line 137 "Lexer.l" #line 137 "Lexer.l"
{ RET_TOK(MemOpVal, Alloca, ALLOCA); } { RET_TOK(MemOpVal, Malloc, MALLOC); }
YY_BREAK YY_BREAK
case 44: case 44:
YY_RULE_SETUP YY_RULE_SETUP
#line 138 "Lexer.l" #line 138 "Lexer.l"
{ RET_TOK(MemOpVal, Free, FREE); } { RET_TOK(MemOpVal, Alloca, ALLOCA); }
YY_BREAK YY_BREAK
case 45: case 45:
YY_RULE_SETUP YY_RULE_SETUP
#line 139 "Lexer.l" #line 139 "Lexer.l"
{ RET_TOK(MemOpVal, Load, LOAD); } { RET_TOK(MemOpVal, Free, FREE); }
YY_BREAK YY_BREAK
case 46: case 46:
YY_RULE_SETUP YY_RULE_SETUP
#line 140 "Lexer.l" #line 140 "Lexer.l"
{ RET_TOK(MemOpVal, Store, STORE); } { RET_TOK(MemOpVal, Load, LOAD); }
YY_BREAK YY_BREAK
case 47: case 47:
YY_RULE_SETUP YY_RULE_SETUP
#line 141 "Lexer.l" #line 141 "Lexer.l"
{ RET_TOK(MemOpVal, GetField, GETFIELD); } { RET_TOK(MemOpVal, Store, STORE); }
YY_BREAK YY_BREAK
case 48: case 48:
YY_RULE_SETUP YY_RULE_SETUP
#line 142 "Lexer.l" #line 142 "Lexer.l"
{ RET_TOK(MemOpVal, PutField, PUTFIELD); } { RET_TOK(MemOpVal, GetField, GETFIELD); }
YY_BREAK YY_BREAK
case 49: case 49:
YY_RULE_SETUP YY_RULE_SETUP
#line 145 "Lexer.l" #line 143 "Lexer.l"
{ llvmAsmlval.StrVal = strdup(yytext+1); return VAR_ID; } { RET_TOK(MemOpVal, PutField, PUTFIELD); }
YY_BREAK YY_BREAK
case 50: case 50:
YY_RULE_SETUP YY_RULE_SETUP
#line 146 "Lexer.l" #line 146 "Lexer.l"
{ llvmAsmlval.StrVal = strdup(yytext+1); return VAR_ID; }
YY_BREAK
case 51:
YY_RULE_SETUP
#line 147 "Lexer.l"
{ {
yytext[strlen(yytext)-1] = 0; // nuke colon yytext[strlen(yytext)-1] = 0; // nuke colon
llvmAsmlval.StrVal = strdup(yytext); llvmAsmlval.StrVal = strdup(yytext);
return LABELSTR; return LABELSTR;
} }
YY_BREAK YY_BREAK
case 51: case 52:
YY_RULE_SETUP YY_RULE_SETUP
#line 152 "Lexer.l" #line 153 "Lexer.l"
{ {
yytext[strlen(yytext)-1] = 0; // nuke end quote yytext[strlen(yytext)-1] = 0; // nuke end quote
llvmAsmlval.StrVal = strdup(yytext+1); // Nuke start quote llvmAsmlval.StrVal = strdup(yytext+1); // Nuke start quote
return STRINGCONSTANT; return STRINGCONSTANT;
} }
YY_BREAK YY_BREAK
case 52:
YY_RULE_SETUP
#line 159 "Lexer.l"
{ llvmAsmlval.UInt64Val = atoull(yytext); return EUINT64VAL; }
YY_BREAK
case 53: case 53:
YY_RULE_SETUP YY_RULE_SETUP
#line 160 "Lexer.l" #line 160 "Lexer.l"
{ llvmAsmlval.UInt64Val = atoull(yytext); return EUINT64VAL; }
YY_BREAK
case 54:
YY_RULE_SETUP
#line 161 "Lexer.l"
{ {
uint64_t Val = atoull(yytext+1); uint64_t Val = atoull(yytext+1);
// +1: we have bigger negative range // +1: we have bigger negative range
@ -1138,14 +1143,14 @@ YY_RULE_SETUP
return ESINT64VAL; return ESINT64VAL;
} }
YY_BREAK YY_BREAK
case 54:
YY_RULE_SETUP
#line 170 "Lexer.l"
{ llvmAsmlval.UIntVal = atoull(yytext+1); return UINTVAL; }
YY_BREAK
case 55: case 55:
YY_RULE_SETUP YY_RULE_SETUP
#line 171 "Lexer.l" #line 171 "Lexer.l"
{ llvmAsmlval.UIntVal = atoull(yytext+1); return UINTVAL; }
YY_BREAK
case 56:
YY_RULE_SETUP
#line 172 "Lexer.l"
{ {
uint64_t Val = atoull(yytext+2); uint64_t Val = atoull(yytext+2);
// +1: we have bigger negative range // +1: we have bigger negative range
@ -1155,22 +1160,22 @@ YY_RULE_SETUP
return SINTVAL; return SINTVAL;
} }
YY_BREAK YY_BREAK
case 56:
YY_RULE_SETUP
#line 181 "Lexer.l"
{ /* Ignore whitespace */ }
YY_BREAK
case 57: case 57:
YY_RULE_SETUP YY_RULE_SETUP
#line 182 "Lexer.l" #line 182 "Lexer.l"
{ /*printf("'%s'", yytext);*/ return yytext[0]; } { /* Ignore whitespace */ }
YY_BREAK YY_BREAK
case 58: case 58:
YY_RULE_SETUP YY_RULE_SETUP
#line 184 "Lexer.l" #line 183 "Lexer.l"
{ /*printf("'%s'", yytext);*/ return yytext[0]; }
YY_BREAK
case 59:
YY_RULE_SETUP
#line 185 "Lexer.l"
YY_FATAL_ERROR( "flex scanner jammed" ); YY_FATAL_ERROR( "flex scanner jammed" );
YY_BREAK YY_BREAK
#line 1175 "Lexer.cpp" #line 1180 "Lexer.cpp"
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
yyterminate(); yyterminate();
@ -1459,7 +1464,7 @@ static yy_state_type yy_get_previous_state()
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 198 ) if ( yy_current_state >= 199 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@ -1489,11 +1494,11 @@ yy_state_type yy_current_state;
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 198 ) if ( yy_current_state >= 199 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 197); yy_is_jam = (yy_current_state == 198);
if ( ! yy_is_jam ) if ( ! yy_is_jam )
*yy_state_ptr++ = yy_current_state; *yy_state_ptr++ = yy_current_state;
@ -2054,5 +2059,5 @@ int main()
return 0; return 0;
} }
#endif #endif
#line 184 "Lexer.l" #line 185 "Lexer.l"

View File

@ -111,9 +111,10 @@ type { llvmAsmlval.TypeVal = Type::TypeTy ; return TYPE; }
label { llvmAsmlval.TypeVal = Type::LabelTy ; return LABEL; } label { llvmAsmlval.TypeVal = Type::LabelTy ; return LABEL; }
neg { RET_TOK(UnaryOpVal, Neg, NEG); }
not { RET_TOK(UnaryOpVal, Not, NOT); } not { RET_TOK(UnaryOpVal, Not, NOT); }
cast { RET_TOK(UnaryOpVal, Cast, CAST); }
to { return TO; }
phi { return PHI; } phi { return PHI; }
call { return CALL; } call { return CALL; }
add { RET_TOK(BinaryOpVal, Add, ADD); } add { RET_TOK(BinaryOpVal, Add, ADD); }

File diff suppressed because it is too large Load Diff

View File

@ -56,33 +56,32 @@ typedef union {
#define BEGINTOK 282 #define BEGINTOK 282
#define END 283 #define END 283
#define DECLARE 284 #define DECLARE 284
#define PHI 285 #define TO 285
#define CALL 286 #define PHI 286
#define RET 287 #define CALL 287
#define BR 288 #define RET 288
#define SWITCH 289 #define BR 289
#define NEG 290 #define SWITCH 290
#define NOT 291 #define NOT 291
#define TOINT 292 #define CAST 292
#define TOUINT 293 #define ADD 293
#define ADD 294 #define SUB 294
#define SUB 295 #define MUL 295
#define MUL 296 #define DIV 296
#define DIV 297 #define REM 297
#define REM 298 #define SETLE 298
#define SETLE 299 #define SETGE 299
#define SETGE 300 #define SETLT 300
#define SETLT 301 #define SETGT 301
#define SETGT 302 #define SETEQ 302
#define SETEQ 303 #define SETNE 303
#define SETNE 304 #define MALLOC 304
#define MALLOC 305 #define ALLOCA 305
#define ALLOCA 306 #define FREE 306
#define FREE 307 #define LOAD 307
#define LOAD 308 #define STORE 308
#define STORE 309 #define GETFIELD 309
#define GETFIELD 310 #define PUTFIELD 310
#define PUTFIELD 311
extern YYSTYPE llvmAsmlval; extern YYSTYPE llvmAsmlval;

View File

@ -26,8 +26,8 @@
#include <utility> // Get definition of pair class #include <utility> // Get definition of pair class
#include <stdio.h> // This embarasment is due to our flex lexer... #include <stdio.h> // This embarasment is due to our flex lexer...
int yyerror(char *ErrorMsg); // Forward declarations to prevent "implicit int yyerror(const char *ErrorMsg); // Forward declarations to prevent "implicit
int yylex(); // declaration" of xxx warnings. int yylex(); // declaration" of xxx warnings.
int yyparse(); int yyparse();
static Module *ParserResult; static Module *ParserResult;
@ -403,7 +403,7 @@ Module *RunVMAsmParser(const ToolCommandLine &Opts, FILE *F) {
%type <StrVal> OptVAR_ID OptAssign %type <StrVal> OptVAR_ID OptAssign
%token IMPLEMENTATION TRUE FALSE BEGINTOK END DECLARE %token IMPLEMENTATION TRUE FALSE BEGINTOK END DECLARE TO
%token PHI CALL %token PHI CALL
// Basic Block Terminating Operators // Basic Block Terminating Operators
@ -411,10 +411,7 @@ Module *RunVMAsmParser(const ToolCommandLine &Opts, FILE *F) {
// Unary Operators // Unary Operators
%type <UnaryOpVal> UnaryOps // all the unary operators %type <UnaryOpVal> UnaryOps // all the unary operators
%token <UnaryOpVal> NEG NOT %token <UnaryOpVal> NOT CAST
// Unary Conversion Operators
%token <UnaryOpVal> TOINT TOUINT
// Binary Operators // Binary Operators
%type <BinaryOpVal> BinaryOps // all the binary operators %type <BinaryOpVal> BinaryOps // all the binary operators
@ -461,7 +458,7 @@ TypesV : Types | VOID
// Operations that are notably excluded from this list include: // Operations that are notably excluded from this list include:
// RET, BR, & SWITCH because they end basic blocks and are treated specially. // RET, BR, & SWITCH because they end basic blocks and are treated specially.
// //
UnaryOps : NEG | NOT | TOINT | TOUINT UnaryOps : NOT
BinaryOps : ADD | SUB | MUL | DIV | REM BinaryOps : ADD | SUB | MUL | DIV | REM
BinaryOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE BinaryOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE
@ -874,7 +871,10 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef {
$$ = UnaryOperator::create($1, getVal($2, $3)); $$ = UnaryOperator::create($1, getVal($2, $3));
if ($$ == 0) if ($$ == 0)
ThrowException("unary operator returned null!"); ThrowException("unary operator returned null!");
} }
| CAST Types ValueRef TO Types {
$$ = UnaryOperator::create($1, getVal($2, $3), $5);
}
| PHI PHIList { | PHI PHIList {
const Type *Ty = $2->front().first->getType(); const Type *Ty = $2->front().first->getType();
$$ = new PHINode(Ty); $$ = new PHINode(Ty);
@ -962,7 +962,7 @@ MemoryInst : MALLOC Types {
} }
%% %%
int yyerror(char *ErrorMsg) { int yyerror(const char *ErrorMsg) {
ThrowException(string("Parse error: ") + ErrorMsg); ThrowException(string("Parse error: ") + ErrorMsg);
return 0; return 0;
} }

View File

@ -105,6 +105,10 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
getValue(Raw.Ty, Raw.Arg1), getValue(Raw.Ty, Raw.Arg1),
getValue(Raw.Ty, Raw.Arg2)); getValue(Raw.Ty, Raw.Arg2));
return false; return false;
} else if (Raw.Opcode == Instruction::Cast) {
Res = UnaryOperator::create(Instruction::Cast, getValue(Raw.Ty, Raw.Arg1),
getType(Raw.Arg2));
return false;
} else if (Raw.Opcode == Instruction::PHINode) { } else if (Raw.Opcode == Instruction::PHINode) {
PHINode *PN = new PHINode(Raw.Ty); PHINode *PN = new PHINode(Raw.Ty);
switch (Raw.NumOperands) { switch (Raw.NumOperands) {

View File

@ -145,6 +145,15 @@ bool BytecodeWriter::processInstruction(const Instruction *I) {
assert(Slot != -1 && "Type not available!!?!"); assert(Slot != -1 && "Type not available!!?!");
Type = (unsigned)Slot; Type = (unsigned)Slot;
// Handle the special case for cast...
if (I->getOpcode() == Instruction::Cast) {
// Cast has to encode the destination type as the second argument in the
// packet, or else we won't know what type to cast to!
Slots[1] = Table.getValSlot(I->getType());
assert(Slots[1] != -1 && "Cast return type unknown?");
if (Slots[1] > MaxOpSlot) MaxOpSlot = Slots[1];
NumOperands++;
}
// Decide which instruction encoding to use. This is determined primarily by // Decide which instruction encoding to use. This is determined primarily by
// the number of operands, and secondarily by whether or not the max operand // the number of operands, and secondarily by whether or not the max operand

View File

@ -79,16 +79,6 @@ static LIVType isLinearInductionVariableH(cfg::Interval *Int, Value *V,
// loop variant computations must be instructions! // loop variant computations must be instructions!
Instruction *I = V->castInstructionAsserting(); Instruction *I = V->castInstructionAsserting();
switch (I->getOpcode()) { // Handle each instruction seperately switch (I->getOpcode()) { // Handle each instruction seperately
case Instruction::Neg: {
Value *SubV = ((UnaryOperator*)I)->getOperand(0);
LIVType SubLIVType = isLinearInductionVariableH(Int, SubV, PN);
switch (SubLIVType) {
case isLIC: // Loop invariant & other computations remain the same
case isOther: return SubLIVType;
case isLIV: // Return the opposite signed LIV type
case isNLIV: return neg(isLIV);
}
}
case Instruction::Add: case Instruction::Add:
case Instruction::Sub: { case Instruction::Sub: {
Value *SubV1 = ((BinaryOperator*)I)->getOperand(0); Value *SubV1 = ((BinaryOperator*)I)->getOperand(0);

View File

@ -207,7 +207,9 @@ bool AssemblyWriter::processInstruction(const Instruction *I) {
Out << ","; Out << ",";
writeOperand(I->getOperand(0), true); writeOperand(I->getOperand(0), true);
} }
} else if (I->getOpcode() == Instruction::Cast) {
writeOperand(Operand, true);
Out << " to " << I->getType();
} else if (Operand) { // Print the normal way... } else if (Operand) { // Print the normal way...
// PrintAllTypes - Instructions who have operands of all the same type // PrintAllTypes - Instructions who have operands of all the same type

View File

@ -27,10 +27,6 @@ class TemplateRules : public ConstRules {
// Redirecting functions that cast to the appropriate types // Redirecting functions that cast to the appropriate types
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
virtual ConstPoolVal *neg(const ConstPoolVal *V) const {
return SubClassName::Neg((const ArgType *)V);
}
virtual ConstPoolVal *not(const ConstPoolVal *V) const { virtual ConstPoolVal *not(const ConstPoolVal *V) const {
return SubClassName::Not((const ArgType *)V); return SubClassName::Not((const ArgType *)V);
} }
@ -55,7 +51,6 @@ class TemplateRules : public ConstRules {
// Default "noop" implementations // Default "noop" implementations
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
inline static ConstPoolVal *Neg(const ArgType *V) { return 0; }
inline static ConstPoolVal *Not(const ArgType *V) { return 0; } inline static ConstPoolVal *Not(const ArgType *V) { return 0; }
inline static ConstPoolVal *Add(const ArgType *V1, const ArgType *V2) { inline static ConstPoolVal *Add(const ArgType *V1, const ArgType *V2) {
@ -125,9 +120,6 @@ struct DirectRules
: public TemplateRules<ConstPoolClass, : public TemplateRules<ConstPoolClass,
DirectRules<ConstPoolClass, BuiltinType, Ty> > { DirectRules<ConstPoolClass, BuiltinType, Ty> > {
inline static ConstPoolVal *Neg(const ConstPoolClass *V) {
return new ConstPoolClass(*Ty, -(BuiltinType)V->getValue());;
}
inline static ConstPoolVal *Not(const ConstPoolClass *V) { inline static ConstPoolVal *Not(const ConstPoolClass *V) {
return new ConstPoolClass(*Ty, !(BuiltinType)V->getValue());; return new ConstPoolClass(*Ty, !(BuiltinType)V->getValue());;
} }

View File

@ -60,7 +60,6 @@ protected:
inline ConstRules() {} // Can only be subclassed... inline ConstRules() {} // Can only be subclassed...
public: public:
// Unary Operators... // Unary Operators...
virtual ConstPoolVal *neg(const ConstPoolVal *V) const = 0;
virtual ConstPoolVal *not(const ConstPoolVal *V) const = 0; virtual ConstPoolVal *not(const ConstPoolVal *V) const = 0;
// Binary Operators... // Binary Operators...
@ -88,10 +87,6 @@ private :
}; };
inline ConstPoolVal *operator-(const ConstPoolVal &V) {
return ConstRules::get(V)->neg(&V);
}
inline ConstPoolVal *operator!(const ConstPoolVal &V) { inline ConstPoolVal *operator!(const ConstPoolVal &V) {
return ConstRules::get(V)->not(&V); return ConstRules::get(V)->not(&V);
} }
@ -154,7 +149,6 @@ inline ConstPoolVal *ConstantFoldUnaryInstruction(unsigned Opcode,
ConstPoolVal *V) { ConstPoolVal *V) {
switch (Opcode) { switch (Opcode) {
case Instruction::Not: return !*V; case Instruction::Not: return !*V;
case Instruction::Neg: return -*V;
} }
return 0; return 0;
} }

View File

@ -60,7 +60,6 @@ protected:
inline ConstRules() {} // Can only be subclassed... inline ConstRules() {} // Can only be subclassed...
public: public:
// Unary Operators... // Unary Operators...
virtual ConstPoolVal *neg(const ConstPoolVal *V) const = 0;
virtual ConstPoolVal *not(const ConstPoolVal *V) const = 0; virtual ConstPoolVal *not(const ConstPoolVal *V) const = 0;
// Binary Operators... // Binary Operators...
@ -88,10 +87,6 @@ private :
}; };
inline ConstPoolVal *operator-(const ConstPoolVal &V) {
return ConstRules::get(V)->neg(&V);
}
inline ConstPoolVal *operator!(const ConstPoolVal &V) { inline ConstPoolVal *operator!(const ConstPoolVal &V) {
return ConstRules::get(V)->not(&V); return ConstRules::get(V)->not(&V);
} }
@ -154,7 +149,6 @@ inline ConstPoolVal *ConstantFoldUnaryInstruction(unsigned Opcode,
ConstPoolVal *V) { ConstPoolVal *V) {
switch (Opcode) { switch (Opcode) {
case Instruction::Not: return !*V; case Instruction::Not: return !*V;
case Instruction::Neg: return -*V;
} }
return 0; return 0;
} }

View File

@ -11,15 +11,6 @@
#include "llvm/Type.h" #include "llvm/Type.h"
#include <algorithm> // find #include <algorithm> // find
// TODO: Move to getUnaryOperator iUnary.cpp when and if it exists!
UnaryOperator *UnaryOperator::create(UnaryOps Op, Value *Source) {
switch (Op) {
default:
cerr << "Don't know how to GetUnaryOperator " << Op << endl;
return 0;
}
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// TerminatorInst Class // TerminatorInst Class
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -7,6 +7,32 @@
#include "llvm/iBinary.h" #include "llvm/iBinary.h"
#include "llvm/Type.h" #include "llvm/Type.h"
UnaryOperator *UnaryOperator::create(UnaryOps Op, Value *Source,
const Type *DestTy = 0) {
if (DestTy == 0) DestTy = Source->getType();
switch (Op) {
case Not: assert(DestTy == Source->getType());
case Cast: return new GenericUnaryInst(Op, Source, DestTy);
default:
cerr << "Don't know how to GetUnaryOperator " << Op << endl;
return 0;
}
}
const char *GenericUnaryInst::getOpcodeName() const {
switch (getOpcode()) {
case Not: return "not";
case Cast: return "cast";
default:
cerr << "Invalid unary operator type!" << getOpcode() << endl;
abort();
}
}
//===----------------------------------------------------------------------===//
// BinaryOperator Class
//===----------------------------------------------------------------------===//
BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2, BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
const string &Name) { const string &Name) {
switch (Op) { switch (Op) {
@ -20,6 +46,10 @@ BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
} }
} }
//===----------------------------------------------------------------------===//
// GenericBinaryInst Class
//===----------------------------------------------------------------------===//
const char *GenericBinaryInst::getOpcodeName() const { const char *GenericBinaryInst::getOpcodeName() const {
switch (getOpcode()) { switch (getOpcode()) {
// Standard binary operators... // Standard binary operators...
@ -35,7 +65,7 @@ const char *GenericBinaryInst::getOpcodeName() const {
case Xor: return "xor"; case Xor: return "xor";
default: default:
cerr << "Invalid binary operator type!" << getOpcode() << endl; cerr << "Invalid binary operator type!" << getOpcode() << endl;
return 0; abort();
} }
} }

11
test/Feature/casttest.ll Normal file
View File

@ -0,0 +1,11 @@
implementation
short "FunFunc"(long %x, sbyte %z)
begin
bb0: ;;<label>
%cast110 = cast sbyte %z to short ;;<short>:(signed operands)
%cast10 = cast long %x to short ;;<short>
%reg109 = add short %cast110, %cast10 ;;<short>
ret short %reg109 ;;<void>
end