From b35add7bfab01ca43ece8c0295f9444a5e325e3a Mon Sep 17 00:00:00 2001 From: shubhamnarlawar77 Date: Sun, 17 May 2020 17:21:09 +0530 Subject: [PATCH] Added support for signed and unsigned integer of size 128 bits --- src/CGOptions.cpp | 4 ++++ src/CGOptions.h | 8 ++++++++ src/Constant.cpp | 11 +++++++++++ src/Probabilities.cpp | 14 ++++++++++++++ src/Probabilities.h | 8 ++++++++ src/RandomProgramGenerator.cpp | 22 ++++++++++++++++++++++ src/Type.cpp | 16 +++++++++++++++- src/Type.h | 4 +++- 8 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/CGOptions.cpp b/src/CGOptions.cpp index 1c8f9efad..6629f853a 100644 --- a/src/CGOptions.cpp +++ b/src/CGOptions.cpp @@ -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() @@ -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 diff --git a/src/CGOptions.h b/src/CGOptions.h index f402dd2a6..c948800b6 100644 --- a/src/CGOptions.h +++ b/src/CGOptions.h @@ -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); @@ -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); diff --git a/src/Constant.cpp b/src/Constant.cpp index 526c6cc8f..9ad24131b 100644 --- a/src/Constant.cpp +++ b/src/Constant.cpp @@ -122,6 +122,15 @@ GenerateRandomIntConstant(void) return val; } +// -------------------------------------------------------------- +static string +GenerateRandomInt128Constant(void) +{ + string val; + val = "0x" + RandomHexDigits( 16 ) ; + return val; +} + // -------------------------------------------------------------- static string GenerateRandomShortConstant(void) @@ -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!"); diff --git a/src/Probabilities.cpp b/src/Probabilities.cpp index 866f566a9..30f43eca0 100644 --- a/src/Probabilities.cpp +++ b/src/Probabilities.cpp @@ -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); diff --git a/src/Probabilities.h b/src/Probabilities.h index ec280b29c..646ca79d9 100644 --- a/src/Probabilities.h +++ b/src/Probabilities.h @@ -139,6 +139,8 @@ enum ProbName { pULongProb, pULongLongProb, pFloatProb, + pInt128Prob, + pUInt128Prob, // for safe math ops pSafeOpsSizeProb, @@ -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) diff --git a/src/RandomProgramGenerator.cpp b/src/RandomProgramGenerator.cpp index fac0e9be2..5e508b7dc 100644 --- a/src/RandomProgramGenerator.cpp +++ b/src/RandomProgramGenerator.cpp @@ -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; } @@ -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++; diff --git a/src/Type.cpp b/src/Type.cpp index b5174474d..65f7bf8f7 100644 --- a/src/Type.cpp +++ b/src/Type.cpp @@ -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; @@ -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; } @@ -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: { @@ -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); diff --git a/src/Type.h b/src/Type.h index 720f0b3ab..209ca5094 100644 --- a/src/Type.h +++ b/src/Type.h @@ -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 {