Skip to content

Commit

Permalink
Start classify array segfault (#82)
Browse files Browse the repository at this point in the history
* start of work to classify array

and creation of a shared classify_type function
* moving into common classify type function
* Pass types by pointer to classify_type
* Remove unused variables
* Add comment for classify_field

Co-authored-by: vsoch <vsoch@users.noreply.github.com>
Co-authored-by: Tim Haines <thaines@cs.wisc.edu>
  • Loading branch information
3 people committed Sep 10, 2021
1 parent e69bd26 commit d8aaf74
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions source/parser/x86_64/classifiers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,41 @@ namespace smeagle::x86_64 {
namespace st = Dyninst::SymtabAPI;

inline classification classify(st::Field *f);
inline classification classify(st::typeFunction *t);
inline classification classify(st::typeEnum *t);
inline classification classify(st::typeScalar *t);
inline classification classify(st::typeStruct *t);
inline classification classify(st::typeUnion *t);
inline classification classify(st::typeArray *t);

inline classification classify_pointer(int ptr_cnt) {
return {RegisterClass::INTEGER, RegisterClass::NO_CLASS, "Pointer", ptr_cnt};
}

// classify a base underlying type
inline classification classify_type(st::Type *fieldType) {
auto [underlying_type, ptr_cnt] = unwrap_underlying_type(fieldType);

if (ptr_cnt > 0) {
return classify_pointer(ptr_cnt);
}

if (auto *t = underlying_type->getScalarType()) {
return classify(t);
} else if (auto *t = underlying_type->getStructType()) {
return classify(t);
} else if (auto *t = underlying_type->getUnionType()) {
return classify(t);
} else if (auto *t = underlying_type->getArrayType()) {
return classify(t);
} else if (auto *t = underlying_type->getEnumType()) {
return classify(t);
} else if (auto *t = underlying_type->getFunctionType()) {
return classify(t);
}
return {RegisterClass::NO_CLASS, RegisterClass::NO_CLASS, "Unknown"};
}

inline classification classify(st::typeScalar *t) {
// paramType properties have booleans to indicate types
auto const &props = t->properties();
Expand Down Expand Up @@ -187,10 +217,13 @@ namespace smeagle::x86_64 {

inline classification classify(st::typeArray *t) {
const auto size = t->getSize();

if (size > 64) {
return {RegisterClass::MEMORY, RegisterClass::NO_CLASS, "Array"};
}
return {RegisterClass::INTEGER, RegisterClass::NO_CLASS, "Array"};

// Just classify the base type
return classify_type(t->getBaseType());
}

inline classification classify(st::typeEnum *t) {
Expand All @@ -201,27 +234,8 @@ namespace smeagle::x86_64 {

// Classify a single field
classification classify(st::Field *f) {
auto *fieldType = f->getType();
auto [underlying_type, ptr_cnt] = unwrap_underlying_type(fieldType);

if (ptr_cnt > 0) {
return classify_pointer(ptr_cnt);
}

if (auto *t = underlying_type->getScalarType()) {
return classify(t);
} else if (auto *t = underlying_type->getStructType()) {
return classify(t);
} else if (auto *t = underlying_type->getUnionType()) {
return classify(t);
} else if (auto *t = underlying_type->getArrayType()) {
return classify(t);
} else if (auto *t = underlying_type->getEnumType()) {
return classify(t);
} else if (auto *t = underlying_type->getFunctionType()) {
return classify(t);
}
return {RegisterClass::NO_CLASS, RegisterClass::NO_CLASS, "Unknown"};
// Just classify the type of the field
return classify_type(f->getType());
}

} // namespace smeagle::x86_64

0 comments on commit d8aaf74

Please sign in to comment.