Skip to content

Commit

Permalink
Implement are_identical for Struct types
Browse files Browse the repository at this point in the history
References #73
  • Loading branch information
jrw972 committed Feb 22, 2016
1 parent d555e1c commit be013ef
Show file tree
Hide file tree
Showing 16 changed files with 422 additions and 233 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ executor_base.hpp executor_base.cpp \
field.hpp \
generate_code.hpp generate_code.cpp \
instance_scheduler.hpp instance_scheduler.cpp \
package.hpp \
parser.hpp parser.cpp \
partitioned_scheduler.hpp partitioned_scheduler.cpp \
process_definitions.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ executor_base.hpp executor_base.cpp \
field.hpp \
generate_code.hpp generate_code.cpp \
instance_scheduler.hpp instance_scheduler.cpp \
package.hpp \
parser.hpp parser.cpp \
partitioned_scheduler.hpp partitioned_scheduler.cpp \
process_definitions.cpp \
Expand Down
120 changes: 62 additions & 58 deletions src/executor_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,80 @@
#include "runtime.hpp"
#include "composition.hpp"

namespace runtime {
namespace runtime
{

bool ExecutorBase::execute (const composition::Action* action)
{
Event* e = begin_event ();
bool enabled = runtime::enabled (*this, action->instance->component, action->action, action->iota);
end_event (e, enabled ? Event::Precondition_True : Event::Precondition_False, action);
bool ExecutorBase::execute (const composition::Action* action)
{
Event* e = begin_event ();
bool enabled = runtime::enabled (*this, action->instance->component, action->action, action->iota);
end_event (e, enabled ? Event::Precondition_True : Event::Precondition_False, action);

if (enabled)
{
e = begin_event ();
runtime::execute_no_check (*this, action->instance->component, action->action, action->iota);
end_event (e, Event::Action, action);
}
if (enabled)
{
e = begin_event ();
runtime::execute_no_check (*this, action->instance->component, action->action, action->iota);
end_event (e, Event::Action, action);
}

return enabled;
}
return enabled;
}

void ExecutorBase::execute_no_check (const composition::Action* action)
{
Event* e = begin_event ();
runtime::execute_no_check (*this, action->instance->component, action->action, action->iota);
end_event (e, Event::Action, action);
}
void ExecutorBase::execute_no_check (const composition::Action* action)
{
Event* e = begin_event ();
runtime::execute_no_check (*this, action->instance->component, action->action, action->iota);
end_event (e, Event::Action, action);
}

bool ExecutorBase::collect_garbage (ComponentInfoBase* info)
{
this->current_info (info);
Event* e = begin_event ();
bool gc = this->heap ()->collect_garbage ();
end_event (e, gc ? Event::Garbage_Collection_True : Event::Garbage_Collection_False, info);
return gc;
}
bool ExecutorBase::collect_garbage (ComponentInfoBase* info)
{
this->current_info (info);
Event* e = begin_event ();
bool gc = this->heap ()->collect_garbage ();
end_event (e, gc ? Event::Garbage_Collection_True : Event::Garbage_Collection_False, info);
return gc;
}

void ExecutorBase::fini (FILE* profile_out, size_t thread)
{
if (!events_.empty ()) {
void ExecutorBase::fini (FILE* profile_out, size_t thread)
{
if (!events_.empty ())
{
fprintf (profile_out, "BEGIN thread %zd%s\n", thread, event_full_ ? " OVERFLOW" : "");
for (EventsType::const_iterator pos = events_.begin (),
limit = event_full_ ? events_.end () : events_.begin () + event_idx_;
limit = event_full_ ? events_.end () : events_.begin () + event_idx_;
pos != limit;
++pos) {
switch (pos->type) {
case Event::Precondition_True:
fprintf (profile_out, "PRECONDITION_TRUE %s %ld.%.09ld %ld.%.09ld\n", pos->action->name.c_str (), pos->begin.tv_sec, pos->begin.tv_nsec, pos->end.tv_sec, pos->end.tv_nsec);
break;
case Event::Precondition_False:
fprintf (profile_out, "PRECONDITION_FALSE %s %ld.%.09ld %ld.%.09ld\n", pos->action->name.c_str (), pos->begin.tv_sec, pos->begin.tv_nsec, pos->end.tv_sec, pos->end.tv_nsec);
break;
case Event::Action:
fprintf (profile_out, "ACTION %s %ld.%.09ld %ld.%.09ld\n", pos->action->name.c_str (), pos->begin.tv_sec, pos->begin.tv_nsec, pos->end.tv_sec, pos->end.tv_nsec);
break;
case Event::Garbage_Collection_True:
fprintf (profile_out, "GARBAGE_COLLECTION_TRUE %s %ld.%.09ld %ld.%.09ld\n", pos->info->instance ()->name.c_str (), pos->begin.tv_sec, pos->begin.tv_nsec, pos->end.tv_sec, pos->end.tv_nsec);
break;
case Event::Garbage_Collection_False:
fprintf (profile_out, "GARBAGE_COLLECTION_FALSE %s %ld.%.09ld %ld.%.09ld\n", pos->info->instance ()->name.c_str (), pos->begin.tv_sec, pos->begin.tv_nsec, pos->end.tv_sec, pos->end.tv_nsec);
break;
++pos)
{
switch (pos->type)
{
case Event::Precondition_True:
fprintf (profile_out, "PRECONDITION_TRUE %s %ld.%.09ld %ld.%.09ld\n", pos->action->name.c_str (), pos->begin.tv_sec, pos->begin.tv_nsec, pos->end.tv_sec, pos->end.tv_nsec);
break;
case Event::Precondition_False:
fprintf (profile_out, "PRECONDITION_FALSE %s %ld.%.09ld %ld.%.09ld\n", pos->action->name.c_str (), pos->begin.tv_sec, pos->begin.tv_nsec, pos->end.tv_sec, pos->end.tv_nsec);
break;
case Event::Action:
fprintf (profile_out, "ACTION %s %ld.%.09ld %ld.%.09ld\n", pos->action->name.c_str (), pos->begin.tv_sec, pos->begin.tv_nsec, pos->end.tv_sec, pos->end.tv_nsec);
break;
case Event::Garbage_Collection_True:
fprintf (profile_out, "GARBAGE_COLLECTION_TRUE %s %ld.%.09ld %ld.%.09ld\n", pos->info->instance ()->name.c_str (), pos->begin.tv_sec, pos->begin.tv_nsec, pos->end.tv_sec, pos->end.tv_nsec);
break;
case Event::Garbage_Collection_False:
fprintf (profile_out, "GARBAGE_COLLECTION_FALSE %s %ld.%.09ld %ld.%.09ld\n", pos->info->instance ()->name.c_str (), pos->begin.tv_sec, pos->begin.tv_nsec, pos->end.tv_sec, pos->end.tv_nsec);
break;
}
}
}
fprintf (profile_out, "END thread %zd\n", thread);
}
}
}

ComponentInfoBase::ComponentInfoBase (composition::Instance* instance)
: instance_ (instance)
, heap_ (new Heap (instance->component, instance->type->Size ()))
{
// Link the instance to its scheduling information.
*reinterpret_cast<ComponentInfoBase**> (instance->component) = this;
}
ComponentInfoBase::ComponentInfoBase (composition::Instance* instance)
: instance_ (instance)
, heap_ (new Heap (instance->component, instance->type->Size ()))
{
// Link the instance to its scheduling information.
*reinterpret_cast<ComponentInfoBase**> (instance->component) = this;
}

}
90 changes: 56 additions & 34 deletions src/executor_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,25 @@ class FileDescriptor
friend class ExecutorBase;
};

struct ComponentInfoBase {
ComponentInfoBase (composition::Instance* instance);
composition::Instance* instance () const { return instance_; }
Heap* heap () const { return heap_; }
void heap (Heap* h) { heap_ = h; }
private:
composition::Instance* instance_;
Heap* heap_;
};
struct ComponentInfoBase
{
ComponentInfoBase (composition::Instance* instance);
composition::Instance* instance () const
{
return instance_;
}
Heap* heap () const
{
return heap_;
}
void heap (Heap* h)
{
heap_ = h;
}
private:
composition::Instance* instance_;
Heap* heap_;
};

class ExecutorBase
{
Expand All @@ -53,8 +63,14 @@ class ExecutorBase
{
return stack_;
}
runtime::Heap* heap () const { return current_info_->heap (); }
void heap (runtime::Heap* heap) { current_info_->heap (heap); }
runtime::Heap* heap () const
{
return current_info_->heap ();
}
void heap (runtime::Heap* heap)
{
current_info_->heap (heap);
}
ComponentInfoBase* current_info () const
{
return current_info_;
Expand Down Expand Up @@ -103,15 +119,18 @@ class ExecutorBase
void fini (FILE* profile_out, size_t thread);

private:
struct Event {
enum Type {
struct Event
{
enum Type
{
Precondition_True,
Precondition_False,
Action,
Garbage_Collection_True,
Garbage_Collection_False,
} type;
union {
union
{
const composition::Action* action;
ComponentInfoBase* info;
};
Expand All @@ -122,31 +141,34 @@ class ExecutorBase
Event* begin_event ()
{
Event* e = NULL;
if (!events_.empty ()) {
e = &events_[event_idx_];
event_idx_ = (event_idx_ + 1) & (events_.size () - 1);
event_full_ = event_full_ || (event_idx_ == 0);
clock_gettime (CLOCK_MONOTONIC, &e->begin);
}
if (!events_.empty ())
{
e = &events_[event_idx_];
event_idx_ = (event_idx_ + 1) & (events_.size () - 1);
event_full_ = event_full_ || (event_idx_ == 0);
clock_gettime (CLOCK_MONOTONIC, &e->begin);
}
return e;
}

void end_event (Event* e, Event::Type type, const composition::Action* action)
{
if (e) {
clock_gettime (CLOCK_MONOTONIC, &e->end);
e->type = type;
e->action = action;
}
if (e)
{
clock_gettime (CLOCK_MONOTONIC, &e->end);
e->type = type;
e->action = action;
}
}

void end_event (Event* e, Event::Type type, ComponentInfoBase* info)
{
if (e) {
clock_gettime (CLOCK_MONOTONIC, &e->end);
e->type = type;
e->info = info;
}
if (e)
{
clock_gettime (CLOCK_MONOTONIC, &e->end);
e->type = type;
e->info = info;
}
}

runtime::Stack stack_;
Expand All @@ -159,10 +181,10 @@ class ExecutorBase
bool event_full_;
};

inline ComponentInfoBase* component_to_info (component_t* component)
{
return *reinterpret_cast<ComponentInfoBase**> (component);
}
inline ComponentInfoBase* component_to_info (component_t* component)
{
return *reinterpret_cast<ComponentInfoBase**> (component);
}

}

Expand Down
12 changes: 10 additions & 2 deletions src/field.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
#ifndef RC_SRC_FIELD_HPP
#define RC_SRC_FIELD_HPP

#include <set>

#include "types.hpp"

namespace type
{

struct Field
{
decl::Package* const package;
bool const is_anonymous;
std::string const name;
const type::Type* const type;
TagSet const tags;
ptrdiff_t const offset;

Field (const std::string& n, const type::Type* t, ptrdiff_t o)
: name (n)
Field (decl::Package* p, bool a, const std::string& n, const type::Type* t, const TagSet& tgs, ptrdiff_t o)
: package (p)
, is_anonymous (a)
, name (n)
, type (t)
, tags (tgs)
, offset (o)
{ }
};
Expand Down
18 changes: 9 additions & 9 deletions src/generate_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ using namespace type;
using namespace semantic;
using namespace decl;

static Operation* load (Node* node, Operation* op)
{
assert (node->expression_kind != kUnknown);
if (node->expression_kind == kVariable)
{
return new Load (op, node->type);
}
return op;
}
static Operation* load (Node* node, Operation* op)
{
assert (node->expression_kind != kUnknown);
if (node->expression_kind == kVariable)
{
return new Load (op, node->type);
}
return op;
}

struct CodeGenVisitor : public ast::DefaultVisitor
{
Expand Down
Loading

0 comments on commit be013ef

Please sign in to comment.