Skip to content

Commit

Permalink
Move indirections to pointer type so not defined for all parameters (#58
Browse files Browse the repository at this point in the history
)

* move indirections to pointer type so not defined for all parameters
* updates to ensure that pointer indirections is defined

Signed-off-by: vsoch <vsoch@users.noreply.github.com>
Co-authored-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch and vsoch committed Jul 31, 2021
1 parent 1d007cc commit 1f340dd
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 296 deletions.
7 changes: 2 additions & 5 deletions include/smeagle/parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ namespace smeagle {
*/
class parameter {
public:
template <typename T> explicit parameter(T x) : self(std::make_shared<model<T>>(std::move(x))) {}
template <typename T>
explicit parameter(T x) : self(std::make_shared<model<T>>(std::move(x))) {}

std::string name() const { return self->name(); }
std::string type_name() const { return self->type_name(); }
std::string class_name() const { return self->class_name(); }
std::string direction() const { return self->direction(); }
std::string location() const { return self->location(); }
int pointer_indirections() const { return self->pointer_indirections(); }
size_t size_in_bytes() const { return self->size_in_bytes(); }
void toJson(std::ostream &out, int indent) const { self->toJson(out, indent); }


private:
struct concept_t {
virtual ~concept_t() = default;
Expand All @@ -39,7 +38,6 @@ namespace smeagle {
virtual std::string class_name() const = 0;
virtual std::string direction() const = 0;
virtual std::string location() const = 0;
virtual int pointer_indirections() const = 0;
virtual size_t size_in_bytes() const = 0;
virtual void toJson(std::ostream &, int) const = 0;
};
Expand All @@ -50,7 +48,6 @@ namespace smeagle {
std::string class_name() const override { return data.class_name(); }
std::string direction() const override { return data.direction(); }
std::string location() const override { return data.location(); }
int pointer_indirections() const override { return data.pointer_indirections(); }
size_t size_in_bytes() const override { return data.size_in_bytes(); }
void toJson(std::ostream &out, int indent) const { data.toJson(out, indent); }

Expand Down
2 changes: 1 addition & 1 deletion source/corpora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void Corpus::toJson() {

for (auto const &p : f.parameters) {
// Check if we are at the last entry (no comma) or not
auto endcomma = (&p == &f.parameters.back()) ? "": ",";
auto endcomma = (&p == &f.parameters.back()) ? "" : ",";
p.toJson(std::cout, 8);
std::cout << endcomma << '\n';
}
Expand Down
4 changes: 3 additions & 1 deletion source/parser/x86_64/classifiers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ namespace smeagle::x86_64 {
}
}

throw std::runtime_error{"Unknown scalar type"};
// TODO we will eventually want to throw this
// throw std::runtime_error{"Unknown scalar type"};
return {RegisterClass::NO_CLASS, RegisterClass::NO_CLASS, "Unknown"};
}

inline classification classify(st::typeStruct *) { return {}; }
Expand Down
6 changes: 3 additions & 3 deletions source/parser/x86_64/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ namespace smeagle::x86_64::types {
std::string class_name_;
std::string direction_;
std::string location_;
int pointer_indirections_;
size_t size_in_bytes_;

std::string name() const { return name_; }
std::string type_name() const { return type_name_; }
std::string class_name() const { return class_name_; }
std::string direction() const { return direction_; }
std::string location() const { return location_; }
int pointer_indirections() const { return pointer_indirections_; }
size_t size_in_bytes() const { return size_in_bytes_; }
};

Expand All @@ -36,7 +34,6 @@ namespace smeagle::x86_64::types {
<< buf << "\"type\":\"" << p.type_name() << "\",\n"
<< buf << "\"class\":\"" << p.class_name() << "\",\n"
<< buf << "\"location\":\"" << p.location() << "\",\n"
<< buf << "\"pointer_indirections\":\"" << p.pointer_indirections() << "\",\n"
<< buf << "\"direction\":\"" << p.direction() << "\",\n"
<< buf << "\"size\":\"" << p.size_in_bytes() << "\"";
}
Expand Down Expand Up @@ -94,11 +91,14 @@ namespace smeagle::x86_64::types {
}
};
template <typename T> struct pointer_t final : detail::param {
int pointer_indirections;
T underlying_type;

void toJson(std::ostream &out, int indent) const {
auto buf = std::string(indent, ' ');
out << buf << "{\n";
detail::toJson(*this, out, indent + 2);
out << ",\n" << buf << " \"indirections\":\"" << pointer_indirections << "\"";
out << ",\n" << buf << " \"underlying_type\":\n";
underlying_type.toJson(out, indent + 4);
out << "\n" << buf << "}";
Expand Down
8 changes: 4 additions & 4 deletions source/parser/x86_64/x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ namespace smeagle::x86_64 {
ptr_class.name,
direction,
ptr_loc,
ptr_cnt,
param_type->getSize(),
{"", base_type_name, base_class.name, "", "", 0, base_type->getSize()}}};
ptr_cnt,
{"", base_type_name, base_class.name, "", "", base_type->getSize()}}};
}
auto loc = allocator.getRegisterString(base_class.lo, base_class.hi, base_type);
return smeagle::parameter{class_t{param_name, base_type_name, base_class.name, direction, loc,
0, base_type->getSize()}};
return smeagle::parameter{
class_t{param_name, base_type_name, base_class.name, direction, loc, base_type->getSize()}};
}

std::vector<parameter> parse_parameters(st::Symbol *symbol) {
Expand Down

0 comments on commit 1f340dd

Please sign in to comment.