Commit ff77bb17 authored by Sarah Spall's avatar Sarah Spall Committed by Vikram Narayanan

separated callee caller, added exec loop

parent 11325d8e
#include "gen_visitor.h"
Caller_SourceVisitor::SourceVisitor(FILE* out)
Caller_SourceVisitor::Caller_SourceVisitor(FILE* out)
{
this->out_f_ = out;
}
......@@ -18,7 +18,7 @@ void Caller_SourceVisitor::visit(File* f)
void Caller_SourceVisitor::visit(Rpc* r)
{
const char* indent = " ";
Type* rt = r->return_type();
printf("here in hv hisit rpc\n");
printf("%d\n", rt->num());
......@@ -38,7 +38,7 @@ void Caller_SourceVisitor::visit(Rpc* r)
for(std::vector<Parameter*>::iterator it = r->parameters()->begin(); it != r->parameters()->end(); it++)
{
Parameter* p = (Parameter*) *it;
fprintf(this->out_f_, "%s\n", p->marshal());
fprintf(this->out_f_, "%s%s\n", indent, p->marshal());
}
fprintf(this->out_f_, "}\n");
}
......@@ -78,7 +78,9 @@ void Caller_SourceVisitor::visit(Typedef* td)
fprintf(this->out_f_, "%s", td->alias());
}
Callee_SourceVisitor::SourceVisitor(FILE* out)
/* CALLEE code*/
Callee_SourceVisitor::Callee_SourceVisitor(FILE* out)
{
this->out_f_ = out;
}
......@@ -91,6 +93,7 @@ void Callee_SourceVisitor::visit(File* f)
r->accept(this);
fprintf(this->out_f_, "\n\n");
}
exec_loop(f);
}
......@@ -98,8 +101,9 @@ void Callee_SourceVisitor::visit(Rpc* r)
{
Type* rt = r->return_type();
/*
printf("here in hv hisit rpc\n");
printf("%d\n", rt->num());
printf("%d\n", rt->num()); */
rt->accept(this); // this seems unnecessary in this case
const char* name = r->name();
fprintf(this->out_f_, " %s(", name);
......@@ -112,12 +116,9 @@ void Callee_SourceVisitor::visit(Rpc* r)
fprintf(this->out_f_, ", ");
}
fprintf(this->out_f_, ") {\n");
for(std::vector<Parameter*>::iterator it = r->parameters()->begin(); it != r->parameters()->end(); it++)
{
Parameter* p = (Parameter*) *it;
fprintf(this->out_f_, "%s\n", p->marshal());
}
// TODO unmarshaling
fprintf(this->out_f_, "}\n");
}
......@@ -156,3 +157,40 @@ void Callee_SourceVisitor::visit(Typedef* td)
fprintf(this->out_f_, "%s", td->alias());
}
void Callee_SourceVisitor::exec_loop(File* f)
{
const char* indent = " ";
fprintf(this->out_f_, "int execution_loop(void) {\n");
fprintf(this->out_f_, "%sfor (;;) {\n", indent);
fprintf(this->out_f_, "%s%sret = lcd_recv(%s);\n",
indent, indent, "todo_cap_name");
fprintf(this->out_f_, "%s%sif (ret) {\n", indent, indent);
fprintf(this->out_f_, "%s%s%sgoto out; }\n", indent, indent, indent);
// switch
// don't like this hard coding
fprintf(this->out_f_, "%s%sswitch (lcd_r0()) {\n", indent, indent);
for(std::vector<Rpc*>::iterator it = f->rpc_defs()->begin(); it != f->rpc_defs()->end(); it++)
{
Rpc* r = (Rpc*) *it;
const char* enum_char = r->enum_val();
fprintf(this->out_f_, "%s%scase %s:\n", indent, indent, enum_char);
fprintf(this->out_f_, "%s%s%sLCD_MSG(\"todo\");\n", indent, indent, indent);
fprintf(this->out_f_, "%s%s%sret = %s();\n", indent, indent, indent, r->callee_name());
fprintf(this->out_f_, "%s%s%sbreak;\n", indent, indent, indent);
}
// fprintf(this->out_f_, "TODO DIE\n");
fprintf(this->out_f_, "%s%scase TODO_DIE:\n", indent, indent);
fprintf(this->out_f_, "%s%s%sLCD_MSG(\"todo\");\n", indent, indent, indent);
fprintf(this->out_f_, "%s%s%s die_callee();\n", indent, indent, indent);
fprintf(this->out_f_, "%s%s%sgoto out;\n", indent, indent, indent);
fprintf(this->out_f_, "%s%s}\n", indent, indent); // close switch
fprintf(this->out_f_, "%s}\n", indent); // close for loop
// out
fprintf(this->out_f_, "out: \n");
fprintf(this->out_f_, "%sreturn ret;\n", indent);
fprintf(this->out_f_, "}\n");
return;
}
......@@ -36,9 +36,9 @@ class HeaderVisitor : public GenVisitor
class Caller_SourceVisitor : public GenVisitor
{
FILE* out_f_;
// int stub_or_proxy_; // 1 equals stub, 2 equals proxy
public:
SourceVisitor(FILE* out);
Caller_SourceVisitor(FILE* out);
virtual void visit(File *f);
virtual void visit(Rpc *rpc);
virtual void visit(Parameter * p);
......@@ -52,9 +52,9 @@ class Caller_SourceVisitor : public GenVisitor
class Callee_SourceVisitor : public GenVisitor
{
FILE* out_f_;
// int stub_or_proxy_; // 1 equals stub, 2 equals proxy
void exec_loop(File* f);
public:
SourceVisitor(FILE* out);
Callee_SourceVisitor(FILE* out);
virtual void visit(File *f);
virtual void visit(Rpc *rpc);
virtual void visit(Parameter * p);
......
......@@ -169,6 +169,8 @@ class Rpc : public Base
Type* return_type();
std::vector<Parameter*>* parameters();
virtual void accept(ASTVisitor *worker);
const char* enum_val() {return "TODO";}
const char* callee_name() {return "TOdo";}
};
......
......@@ -46,7 +46,7 @@ int main(int argc, char ** argv)
else if(!strcmp(argv[1],"-source"))
{
printf("in source\n");
SourceVisitor* sv = new SourceVisitor(of);
Callee_SourceVisitor* sv = new Callee_SourceVisitor(of);
tree->accept(sv);
printf("have finished sv\n");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment