Skip to content

Commit

Permalink
Add Class TypeConfig for extend type setting
Browse files Browse the repository at this point in the history
add extend type to AllTypes in class type, and using type convert
restriction in random_type_from_type

Signed-off-by: ZhuJunhua1104 tom.Zhu@huawei.com
  • Loading branch information
ZhuJunhua1104 committed Sep 8, 2015
1 parent f5e4898 commit 62386d5
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 209 deletions.
65 changes: 33 additions & 32 deletions src/AggregateType.cpp
Expand Up @@ -466,38 +466,39 @@ unsigned long
AggregateType::SizeInBytes(void) const
{
size_t i;
switch (eType) {
case eUnion: {
unsigned int max_size = 0;
for (i=0; i<fields.size(); i++) {
unsigned int sz = 0;
if (is_bitfield(i)) {
assert(i < bitfields_length_.size());
sz = (int)(ceil(bitfields_length_[i] / 8.0) * 8);
} else {
sz = fields[i]->SizeInBytes();
}
if (sz == SIZE_UNKNOWN) return sz;
if (sz > max_size) {
max_size = sz;
}
}
return max_size;
}
case eStruct: {
if (!this->packed_) return SIZE_UNKNOWN;
// give up if there are bitfields, too much compiler-dependence and machine-dependence
if (this->has_bitfields()) return SIZE_UNKNOWN;
unsigned int total_size = 0;
for (i=0; i<fields.size(); i++) {
unsigned int sz = fields[i]->SizeInBytes();
if (sz == SIZE_UNKNOWN) return sz;
total_size += sz;
}
return total_size;
}
}
return 0;
switch (eType) {
case eUnion: {
unsigned int max_size = 0;
for (i=0; i<fields.size(); i++) {
unsigned int sz = 0;
if (is_bitfield(i)) {
assert(i < bitfields_length_.size());
sz = (int)(ceil(bitfields_length_[i] / 8.0) * 8);
} else {
sz = fields[i]->SizeInBytes();
}
if (sz == SIZE_UNKNOWN) return sz;
if (sz > max_size) {
max_size = sz;
}
}
return max_size;
}
case eStruct: {
if (!this->packed_) return SIZE_UNKNOWN;
// give up if there are bitfields, too much compiler-dependence and machine-dependence
if (this->has_bitfields()) return SIZE_UNKNOWN;
unsigned int total_size = 0;
for (i=0; i<fields.size(); i++) {
unsigned int sz = fields[i]->SizeInBytes();
if (sz == SIZE_UNKNOWN) return sz;
total_size += sz;
}
return total_size;
}
default:
return 0;
}
}


Expand Down
6 changes: 4 additions & 2 deletions src/BuiltinConfig.cpp
Expand Up @@ -327,7 +327,8 @@ dump_intrin_info(TiXmlNode* pParent, unsigned int indent = 0) {

void BuiltinConfig::build_builtin_list_from_xml(std::string file_path) {
// read XML configuration file
TiXmlDocument builtinDoc(file_path.c_str());
std::string file_name = file_path + "/Builtin.xml";
TiXmlDocument builtinDoc(file_name.c_str());
bool loadOkay = builtinDoc.LoadFile();
if (loadOkay) {
dump_intrin_info(&builtinDoc);
Expand All @@ -337,7 +338,8 @@ void BuiltinConfig::build_builtin_list_from_xml(std::string file_path) {
}

// config all Types CVQualifiers
for (int i = 0; i < BuiltinConfig::builtin_config_list.size(); i++) {
unsigned int i = 0;
for (; i < BuiltinConfig::builtin_config_list.size(); i++) {
Function::make_builtin_function(BuiltinConfig::builtin_config_list[i]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/CGOptions.cpp
Expand Up @@ -182,7 +182,7 @@ DEFINE_GETTER_SETTER_BOOL(use_comma_exprs);
DEFINE_GETTER_SETTER_BOOL(take_union_field_addr);
DEFINE_GETTER_SETTER_BOOL(vol_struct_union_fields);
DEFINE_GETTER_SETTER_BOOL(lang_cpp);
DEFINE_GETTER_SETTER_STRING_REF(init_builtin_config_filepath);
DEFINE_GETTER_SETTER_STRING_REF(init_config_filepath);

void
CGOptions::set_default_builtin_kinds()
Expand Down Expand Up @@ -292,7 +292,7 @@ CGOptions::set_default_settings(void)

set_default_builtin_kinds();

init_builtin_config_filepath("");
init_config_filepath("");
}

/*
Expand Down
6 changes: 3 additions & 3 deletions src/CGOptions.h
Expand Up @@ -80,8 +80,8 @@ class CGOptions {
static int max_split_files(void);
static int max_split_files(int p);

static std::string init_builtin_config_filepath(void);
static std::string init_builtin_config_filepath(std::string p);
static std::string init_config_filepath(void);
static std::string init_config_filepath(std::string p);

static std::string split_files_dir(void);
static std::string split_files_dir(std::string p);
Expand Down Expand Up @@ -555,7 +555,7 @@ class CGOptions {
// flag to indicate language
static bool lang_cpp_;

static std::string init_builtin_config_filepath_;
static std::string init_config_filepath_;
private:
CGOptions(void);
CGOptions(CGOptions &cgo);
Expand Down
16 changes: 7 additions & 9 deletions src/PointerType.cpp
Expand Up @@ -50,6 +50,7 @@
#include "util.h"
#include "Bookkeeper.h"
#include "Probabilities.h"
#include "TypeConfig.h"

using namespace std;

Expand Down Expand Up @@ -188,16 +189,13 @@ PointerType::is_convertable(const Type* t) const
{
if (this == t)
return true;
if (t->eType == ePointer) {
if (ptr_type == (dynamic_cast<const PointerType *>(t))->ptr_type) {
return true;
}
if (ptr_type->eType == eSimple && (dynamic_cast<const PointerType *>(t))->ptr_type->eType == eSimple) {
if(ptr_type->simple_type == eFloat && (dynamic_cast<const PointerType *>(t))->ptr_type->simple_type == eFloat)
if (t->eType == ePointer) {
if (ptr_type == (dynamic_cast<const PointerType *>(t))->ptr_type) {
return true;
else
return ptr_type->SizeInBytes() == (dynamic_cast<const PointerType *>(t))->ptr_type->SizeInBytes();
}
}
if (ptr_type->eType == eSimple && (dynamic_cast<const PointerType *>(t))->ptr_type->eType == eSimple) {
return !(TypeConfig::check_exclude_by_convert((dynamic_cast<const PointerType *>(t))->ptr_type, ptr_type));
}
}
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/RandomProgramGenerator.cpp
Expand Up @@ -206,7 +206,7 @@ static void print_help()
cout << " --lang-cpp : generate C++ code (C by default)." << endl << endl;

// config file path
cout << " --builtin-config <builtin_file_path>: specify external builtins configuration file absolute path." << endl << endl;
cout << " --config <config_file_path>: specify extend syntax and builtins configuration file absolute path." << endl << endl;

}

Expand Down Expand Up @@ -334,15 +334,15 @@ main(int argc, char **argv)

for (int i=1; i<argc; i++) {

if (strcmp (argv[i], "--builtin-config") == 0) {
if (strcmp (argv[i], "--config") == 0) {
string filepath;
i++;
arg_check(argc, i);
if (!parse_string_arg(argv[i], filepath)) {
cout<< "please specify external builtins configuration file absolute path!" << std::endl;
exit(-1);
}
CGOptions::init_builtin_config_filepath(filepath);
CGOptions::init_config_filepath(filepath);
continue;
}

Expand Down

0 comments on commit 62386d5

Please sign in to comment.