mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
Implement PR2538
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53438 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c563e1d8fe
commit
d15990189d
@ -23,6 +23,7 @@
|
|||||||
#include "llvm/Assembly/Parser.h"
|
#include "llvm/Assembly/Parser.h"
|
||||||
#include "llvm/ADT/StringExtras.h"
|
#include "llvm/ADT/StringExtras.h"
|
||||||
#include "llvm/ADT/APFloat.h"
|
#include "llvm/ADT/APFloat.h"
|
||||||
|
#include "llvm/ADT/APSInt.h"
|
||||||
namespace llvm { class MemoryBuffer; }
|
namespace llvm { class MemoryBuffer; }
|
||||||
|
|
||||||
// Global variables exported from the lexer...
|
// Global variables exported from the lexer...
|
||||||
@ -72,7 +73,7 @@ struct InlineAsmDescriptor {
|
|||||||
struct ValID {
|
struct ValID {
|
||||||
enum {
|
enum {
|
||||||
LocalID, GlobalID, LocalName, GlobalName,
|
LocalID, GlobalID, LocalName, GlobalName,
|
||||||
ConstSIntVal, ConstUIntVal, ConstFPVal, ConstNullVal,
|
ConstSIntVal, ConstUIntVal, ConstAPInt, ConstFPVal, ConstNullVal,
|
||||||
ConstUndefVal, ConstZeroVal, ConstantVal, InlineAsmVal
|
ConstUndefVal, ConstZeroVal, ConstantVal, InlineAsmVal
|
||||||
} Type;
|
} Type;
|
||||||
|
|
||||||
@ -80,7 +81,8 @@ struct ValID {
|
|||||||
unsigned Num; // If it's a numeric reference like %1234
|
unsigned Num; // If it's a numeric reference like %1234
|
||||||
std::string *Name; // If it's a named reference. Memory must be deleted.
|
std::string *Name; // If it's a named reference. Memory must be deleted.
|
||||||
int64_t ConstPool64; // Constant pool reference. This is the value
|
int64_t ConstPool64; // Constant pool reference. This is the value
|
||||||
uint64_t UConstPool64;// Unsigned constant pool reference.
|
uint64_t UConstPool64; // Unsigned constant pool reference.
|
||||||
|
APSInt *ConstPoolInt; // Large Integer constant pool reference
|
||||||
APFloat *ConstPoolFP; // Floating point constant pool reference
|
APFloat *ConstPoolFP; // Floating point constant pool reference
|
||||||
Constant *ConstantValue; // Fully resolved constant for ConstantVal case.
|
Constant *ConstantValue; // Fully resolved constant for ConstantVal case.
|
||||||
InlineAsmDescriptor *IAD;
|
InlineAsmDescriptor *IAD;
|
||||||
@ -111,6 +113,13 @@ struct ValID {
|
|||||||
ValID D; D.Type = ConstFPVal; D.ConstPoolFP = Val; return D;
|
ValID D; D.Type = ConstFPVal; D.ConstPoolFP = Val; return D;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ValID create(const APInt &Val, bool isSigned) {
|
||||||
|
ValID D; D.Type = ConstAPInt;
|
||||||
|
D.ConstPoolInt = new APSInt(Val, !isSigned);
|
||||||
|
return D;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static ValID createNull() {
|
static ValID createNull() {
|
||||||
ValID D; D.Type = ConstNullVal; return D;
|
ValID D; D.Type = ConstNullVal; return D;
|
||||||
}
|
}
|
||||||
@ -141,11 +150,16 @@ struct ValID {
|
|||||||
delete Name; // Free this strdup'd memory.
|
delete Name; // Free this strdup'd memory.
|
||||||
else if (Type == InlineAsmVal)
|
else if (Type == InlineAsmVal)
|
||||||
delete IAD;
|
delete IAD;
|
||||||
|
else if (Type == ConstAPInt)
|
||||||
|
delete ConstPoolInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ValID copy() const {
|
inline ValID copy() const {
|
||||||
if (Type != LocalName && Type != GlobalName) return *this;
|
|
||||||
ValID Result = *this;
|
ValID Result = *this;
|
||||||
|
if (Type == ConstAPInt)
|
||||||
|
Result.ConstPoolInt = new APSInt(*ConstPoolInt);
|
||||||
|
|
||||||
|
if (Type != LocalName && Type != GlobalName) return Result;
|
||||||
Result.Name = new std::string(*Name);
|
Result.Name = new std::string(*Name);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
@ -156,6 +170,7 @@ struct ValID {
|
|||||||
case GlobalID : return '@' + utostr(Num);
|
case GlobalID : return '@' + utostr(Num);
|
||||||
case LocalName : return *Name;
|
case LocalName : return *Name;
|
||||||
case GlobalName : return *Name;
|
case GlobalName : return *Name;
|
||||||
|
case ConstAPInt : return ConstPoolInt->toString();
|
||||||
case ConstFPVal : return ftostr(*ConstPoolFP);
|
case ConstFPVal : return ftostr(*ConstPoolFP);
|
||||||
case ConstNullVal : return "null";
|
case ConstNullVal : return "null";
|
||||||
case ConstUndefVal : return "undef";
|
case ConstUndefVal : return "undef";
|
||||||
@ -182,6 +197,7 @@ struct ValID {
|
|||||||
case GlobalName: return *Name < *V.Name;
|
case GlobalName: return *Name < *V.Name;
|
||||||
case ConstSIntVal: return ConstPool64 < V.ConstPool64;
|
case ConstSIntVal: return ConstPool64 < V.ConstPool64;
|
||||||
case ConstUIntVal: return UConstPool64 < V.UConstPool64;
|
case ConstUIntVal: return UConstPool64 < V.UConstPool64;
|
||||||
|
case ConstAPInt : return ConstPoolInt->ult(*V.ConstPoolInt);
|
||||||
case ConstFPVal: return ConstPoolFP->compare(*V.ConstPoolFP) ==
|
case ConstFPVal: return ConstPoolFP->compare(*V.ConstPoolFP) ==
|
||||||
APFloat::cmpLessThan;
|
APFloat::cmpLessThan;
|
||||||
case ConstNullVal: return false;
|
case ConstNullVal: return false;
|
||||||
@ -193,25 +209,25 @@ struct ValID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const ValID &V) const {
|
bool operator==(const ValID &V) const {
|
||||||
if (Type == V.Type) {
|
if (Type != V.Type) return false;
|
||||||
|
|
||||||
switch (Type) {
|
switch (Type) {
|
||||||
|
default: assert(0 && "Unknown value type!");
|
||||||
case LocalID:
|
case LocalID:
|
||||||
case GlobalID: return Num == V.Num;
|
case GlobalID: return Num == V.Num;
|
||||||
case LocalName:
|
case LocalName:
|
||||||
case GlobalName: return *Name == *(V.Name);
|
case GlobalName: return *Name == *(V.Name);
|
||||||
case ConstSIntVal: return ConstPool64 == V.ConstPool64;
|
case ConstSIntVal: return ConstPool64 == V.ConstPool64;
|
||||||
case ConstUIntVal: return UConstPool64 == V.UConstPool64;
|
case ConstUIntVal: return UConstPool64 == V.UConstPool64;
|
||||||
|
case ConstAPInt: return *ConstPoolInt == *V.ConstPoolInt;
|
||||||
case ConstFPVal: return ConstPoolFP->compare(*V.ConstPoolFP) ==
|
case ConstFPVal: return ConstPoolFP->compare(*V.ConstPoolFP) ==
|
||||||
APFloat::cmpEqual;
|
APFloat::cmpEqual;
|
||||||
case ConstantVal: return ConstantValue == V.ConstantValue;
|
case ConstantVal: return ConstantValue == V.ConstantValue;
|
||||||
case ConstNullVal: return true;
|
case ConstNullVal: return true;
|
||||||
case ConstUndefVal: return true;
|
case ConstUndefVal: return true;
|
||||||
case ConstZeroVal: return true;
|
case ConstZeroVal: return true;
|
||||||
default: assert(0 && "Unknown value type!"); return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TypeWithAttrs {
|
struct TypeWithAttrs {
|
||||||
|
@ -402,6 +402,20 @@ static Value *getExistingVal(const Type *Ty, const ValID &D) {
|
|||||||
// This is really a signed reference. Transmogrify.
|
// This is really a signed reference. Transmogrify.
|
||||||
return ConstantInt::get(Ty, D.ConstPool64, true);
|
return ConstantInt::get(Ty, D.ConstPool64, true);
|
||||||
|
|
||||||
|
case ValID::ConstAPInt: // Is it an unsigned const pool reference?
|
||||||
|
if (!isa<IntegerType>(Ty)) {
|
||||||
|
GenerateError("Integral constant '" + D.getName() +
|
||||||
|
"' is invalid or out of range for type '" +
|
||||||
|
Ty->getDescription() + "'");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
APSInt Tmp = *D.ConstPoolInt;
|
||||||
|
Tmp.extOrTrunc(Ty->getPrimitiveSizeInBits());
|
||||||
|
return ConstantInt::get(Tmp);
|
||||||
|
}
|
||||||
|
|
||||||
case ValID::ConstFPVal: // Is it a floating point const pool reference?
|
case ValID::ConstFPVal: // Is it a floating point const pool reference?
|
||||||
if (!Ty->isFloatingPoint() ||
|
if (!Ty->isFloatingPoint() ||
|
||||||
!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP)) {
|
!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP)) {
|
||||||
@ -2453,6 +2467,16 @@ ConstValueRef : ESINT64VAL { // A reference to a direct constant
|
|||||||
$$ = ValID::create($1);
|
$$ = ValID::create($1);
|
||||||
CHECK_FOR_ERROR
|
CHECK_FOR_ERROR
|
||||||
}
|
}
|
||||||
|
| ESAPINTVAL { // arbitrary precision integer constants
|
||||||
|
$$ = ValID::create(*$1, true);
|
||||||
|
delete $1;
|
||||||
|
CHECK_FOR_ERROR
|
||||||
|
}
|
||||||
|
| EUAPINTVAL { // arbitrary precision integer constants
|
||||||
|
$$ = ValID::create(*$1, false);
|
||||||
|
delete $1;
|
||||||
|
CHECK_FOR_ERROR
|
||||||
|
}
|
||||||
| FPVAL { // Perhaps it's an FP constant?
|
| FPVAL { // Perhaps it's an FP constant?
|
||||||
$$ = ValID::create($1);
|
$$ = ValID::create($1);
|
||||||
CHECK_FOR_ERROR
|
CHECK_FOR_ERROR
|
||||||
|
9
test/Assembler/2008-07-10-APInt.ll
Normal file
9
test/Assembler/2008-07-10-APInt.ll
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
; RUN: llvm-as < %s | llvm-dis
|
||||||
|
; PR2538
|
||||||
|
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
|
||||||
|
target triple = "i686-pc-linux-gnu"
|
||||||
|
|
||||||
|
define i128 @a() {
|
||||||
|
ret i128 18446744073709551616
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user