Skip to content

Commit

Permalink
Added support for signed and unsigned integer of size 128 bits
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamnarlawar77 committed May 17, 2020
1 parent 48f4da9 commit b35add7
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/CGOptions.cpp
Expand Up @@ -200,6 +200,8 @@ DEFINE_GETTER_SETTER_BOOL(func_attr_flag);
DEFINE_GETTER_SETTER_BOOL(type_attr_flag);
DEFINE_GETTER_SETTER_BOOL(label_attr_flag);
DEFINE_GETTER_SETTER_BOOL(var_attr_flag);
DEFINE_GETTER_SETTER_BOOL(Int128);
DEFINE_GETTER_SETTER_BOOL(UInt128);

void
CGOptions::set_default_builtin_kinds()
Expand Down Expand Up @@ -311,6 +313,8 @@ CGOptions::set_default_settings(void)
fast_execution(false);

set_default_builtin_kinds();
Int128(false);
UInt128(false);
}

// Add options necessary for cpp
Expand Down
8 changes: 8 additions & 0 deletions src/CGOptions.h
Expand Up @@ -469,6 +469,12 @@ class CGOptions {

static bool var_attr_flag(void);
static bool var_attr_flag(bool p);

static bool Int128(void);
static bool Int128(bool p);

static bool UInt128(void);
static bool UInt128(bool p);
private:
static bool enabled_builtin_kind(const string &kind);

Expand Down Expand Up @@ -616,6 +622,8 @@ class CGOptions {
static bool type_attr_flag_;
static bool label_attr_flag_;
static bool var_attr_flag_;
static bool Int128_;
static bool UInt128_;
private:
CGOptions(void);
CGOptions(CGOptions &cgo);
Expand Down
11 changes: 11 additions & 0 deletions src/Constant.cpp
Expand Up @@ -122,6 +122,15 @@ GenerateRandomIntConstant(void)
return val;
}

// --------------------------------------------------------------
static string
GenerateRandomInt128Constant(void)
{
string val;
val = "0x" + RandomHexDigits( 16 ) ;
return val;
}

// --------------------------------------------------------------
static string
GenerateRandomShortConstant(void)
Expand Down Expand Up @@ -380,6 +389,8 @@ GenerateRandomConstant(const Type* type)
case eULong: v = GenerateRandomLongConstant(); break;
case eULongLong: v = GenerateRandomLongLongConstant(); break;
case eFloat: v = GenerateRandomFloatHexConstant(); break;
case eInt128: v = GenerateRandomInt128Constant(); break;
case eUInt128: v = GenerateRandomInt128Constant(); break;
// case eDouble: v = GenerateRandomFloatConstant(); break;
default:
assert(0 && "Unsupported type!");
Expand Down
14 changes: 14 additions & 0 deletions src/Probabilities.cpp
Expand Up @@ -699,6 +699,20 @@ Probabilities::set_default_simple_types_prob()
SET_SINGLE_NAME("char_prob", Char, 0);
}

if (CGOptions::Int128()) {
SET_SINGLE_NAME("Int128_prob", Int128, 1);
}
else {
SET_SINGLE_NAME("Int128_prob", Int128, 0);
}

if (CGOptions::UInt128()) {
SET_SINGLE_NAME("UInt128_prob", UInt128, 1);
}
else {
SET_SINGLE_NAME("UInt128_prob", UInt128, 0);
}

SET_SINGLE_NAME("int_prob", Int, 1);
SET_SINGLE_NAME("short_prob", Short, 1);

Expand Down
8 changes: 8 additions & 0 deletions src/Probabilities.h
Expand Up @@ -139,6 +139,8 @@ enum ProbName {
pULongProb,
pULongLongProb,
pFloatProb,
pInt128Prob,
pUInt128Prob,

// for safe math ops
pSafeOpsSizeProb,
Expand Down Expand Up @@ -241,6 +243,12 @@ enum ProbName {
#define VarAttrProb \
Probabilities::get_prob(pVarAttrProb)

#define Int128Prob \
Probabilities::get_prob(pInt128Prob)

#define UInt128Prob \
Probabilities::get_prob(pUInt128Prob)

//////////////////////////////////////////////////
#define UNARY_OPS_PROB_FILTER \
Probabilities::get_prob_filter(pUnaryOpsProb)
Expand Down
22 changes: 22 additions & 0 deletions src/RandomProgramGenerator.cpp
Expand Up @@ -215,6 +215,8 @@ static void print_help()
cout << " --label-attributes | --no-label-attributes: enable | disable generate common label attributes (disabled by default)." << endl << endl;
cout << " --variable-attributes | --no-variable-attributes: enable | disable generate common variable attributes (disabled by default)." << endl << endl;
cout << " --compiler-attributes | --no-compiler-attributes: enable | disable generate function, type, label and variable attributes (disabled by default)." << endl << endl;
cout << " --int128 | --no-int128: enable | disable generate __int128 as datatype extension (disabled by default)." << endl << endl;
cout << " --uint128 | --no-uint128: enable | disable generate unsigned __int128 as datatype extension (disabled by default)." << endl << endl;

}

Expand Down Expand Up @@ -859,6 +861,26 @@ main(int argc, char **argv)
continue;
}

if (strcmp (argv[i], "--int128") == 0) {
CGOptions::Int128(true);
continue;
}

if (strcmp (argv[i], "--no-int128") == 0) {
CGOptions::Int128(false);
continue;
}

if (strcmp (argv[i], "--uint128") == 0) {
CGOptions::UInt128(true);
continue;
}

if (strcmp (argv[i], "--no-uint128") == 0) {
CGOptions::UInt128(false);
continue;
}

if (strcmp (argv[i], "--max-array-dim") ==0 ) {
unsigned long dim;
i++;
Expand Down
16 changes: 15 additions & 1 deletion src/Type.cpp
Expand Up @@ -451,6 +451,12 @@ Type::get_type_from_string(const string &type_string)
else if (type_string == "Float") {
return &Type::get_simple_type(eFloat);
}
else if (type_string == "Int128") {
return &Type::get_simple_type(eInt128);
}
else if (type_string == "UInt128") {
return &Type::get_simple_type(eUInt128);
}

assert(0 && "Unsupported type string!");
return NULL;
Expand Down Expand Up @@ -1446,6 +1452,8 @@ Type::to_unsigned(void) const
case eShort: return &get_simple_type(eUShort);
case eLong: return &get_simple_type(eULong);
case eLongLong: return &get_simple_type(eULongLong);
case eInt128: return &get_simple_type(eInt128);
case eUInt128: return &get_simple_type(eUInt128);
default:
break;
}
Expand Down Expand Up @@ -1613,7 +1621,9 @@ Type::SizeInBytes(void) const
case eULong: return 4;
case eULongLong:return 8;
case eFloat: return 4;
// case eDouble: return 8;
case eInt128: return 16;
case eUInt128: return 16;
// case eDouble: return 8;
}
break;
case eUnion: {
Expand Down Expand Up @@ -1742,6 +1752,10 @@ Type::Output(std::ostream &out) const
out << "void";
} else if (this->simple_type == eFloat) {
out << "float";
} else if (this->simple_type == eInt128) {
out << "__int" << (SizeInBytes() * 8);
} else if (this->simple_type == eUInt128) {
out << "unsigned __int" << (SizeInBytes() * 8);
} else {
out << (is_signed() ? "int" : "uint");
out << (SizeInBytes() * 8);
Expand Down
4 changes: 3 additions & 1 deletion src/Type.h
Expand Up @@ -83,8 +83,10 @@ enum eSimpleType
eFloat,
// eDouble,
eULongLong,
eInt128,
eUInt128,
};
#define MAX_SIMPLE_TYPES ((eSimpleType) (eULongLong+1))
#define MAX_SIMPLE_TYPES ((eSimpleType) (eUInt128+1))

enum eMatchType
{
Expand Down

0 comments on commit b35add7

Please sign in to comment.