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

Removing old code gen files

parent 4b00fd30
#include "gen_visitor.h"
#include <stdio.h>
HeaderVisitor::HeaderVisitor(FILE* out)
{
this->out_f_ = out;
}
void HeaderVisitor::visit(File* f)
{
// where to print verbatim?
// print an ifndef?
// need to go through all typedef and print out
// a c typedef in file scope
printf("in file\n");
for(std::vector<Rpc*>::iterator it = f->rpc_defs()->begin(); it != f->rpc_defs()->end(); it++)
{
Rpc* r = (Rpc*) *it;
r->accept(this);
fprintf(this->out_f_, "\n\n");
}
}
void HeaderVisitor::visit(Rpc* r)
{
printf("here\n");
Type* rt = r->return_type();
printf("here in hv hisit rpc\n");
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);
for(std::vector<Parameter*>::iterator it = r->parameters()->begin(); it != r->parameters()->end(); it++)
{
Parameter* p = (Parameter*) *it;
p->accept(this);
if((it+1) != r->parameters()->end())
fprintf(this->out_f_, ", ");
}
fprintf(this->out_f_, ");");
}
void HeaderVisitor::visit(Parameter* p)
{
p->type()->accept(this);
// print p->name_
fprintf(this->out_f_, " %s", p->name());
}
void HeaderVisitor::visit(ProjectionType* p)
{
fprintf(this->out_f_, "%s", p->real_type());
}
void HeaderVisitor::visit(ProjectionField* pf)
{
// nothing to do here
}
void HeaderVisitor::visit(IntegerType* it)
{
if(it->unsigned_huh())
fprintf(this->out_f_, "unsigned ");
fprintf(this->out_f_, "%s", it->type());
/*
switch (it->type_) {
case kChar:
fprintf(this->out_f_, "char");
break;
case kShort:
fprintf(this->out_f_, "short");
break;
case kInt:
fprintf(this->out_f_, "int");
break;
case kLong:
fprintf(this->out_f_, "long");
break;
case kLongLong:
fprintf(this->out_f_, "long long");
break;
case kCapability:
fprintf(this->out_f_, "capability_t");
break;
default:
//error
}
*/
}
void HeaderVisitor::visit(PointerType* pt)
{
pt->p_type()->accept(this);
fprintf(this->out_f_, "* ");
}
void HeaderVisitor::visit(Typedef* td)
{
// print out their type so they arent confused
// print td->alias;
fprintf(this->out_f_, "%s", td->alias());
}
#include "gen_visitor.h"
Caller_SourceVisitor::Caller_SourceVisitor(FILE* out)
{
this->out_f_ = out;
}
void Caller_SourceVisitor::visit(File* f)
{
for(std::vector<Rpc*>::iterator it = f->rpc_defs()->begin(); it != f->rpc_defs()->end(); it++)
{
Rpc* r = (Rpc*) *it;
r->accept(this);
fprintf(this->out_f_, "\n\n");
}
}
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());
rt->accept(this); // this seems unnecessary in this case
const char* name = r->name();
fprintf(this->out_f_, " %s(", name);
for(std::vector<Parameter*>::iterator it = r->parameters()->begin(); it != r->parameters()->end(); it++)
{
Parameter* p = (Parameter*) *it;
p->accept(this);
if((it+1) != r->parameters()->end())
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%s\n", indent, p->marshal());
}
fprintf(this->out_f_, "}\n");
}
void Caller_SourceVisitor::visit(Parameter* p)
{
p->type()->accept(this);
// print p->name_
fprintf(this->out_f_, " %s", p->name());
}
void Caller_SourceVisitor::visit(ProjectionType *p)
{
fprintf(this->out_f_, "%s", p->real_type());
}
void Caller_SourceVisitor::visit(ProjectionField *pf)
{
}
void Caller_SourceVisitor::visit(IntegerType *it)
{
if(it->unsigned_huh())
fprintf(this->out_f_, "unsigned ");
fprintf(this->out_f_, "%s", it->type());
}
void Caller_SourceVisitor::visit(PointerType *pt)
{
pt->p_type()->accept(this);
fprintf(this->out_f_, "* ");
}
void Caller_SourceVisitor::visit(Typedef* td)
{
fprintf(this->out_f_, "%s", td->alias());
}
/* CALLEE code*/
Callee_SourceVisitor::Callee_SourceVisitor(FILE* out)
{
this->out_f_ = out;
}
void Callee_SourceVisitor::visit(File* f)
{
for(std::vector<Rpc*>::iterator it = f->rpc_defs()->begin(); it != f->rpc_defs()->end(); it++)
{
Rpc* r = (Rpc*) *it;
r->accept(this);
fprintf(this->out_f_, "\n\n");
}
exec_loop(f);
}
void Callee_SourceVisitor::visit(Rpc* r)
{
Type* rt = r->return_type();
/*
printf("here in hv hisit rpc\n");
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);
for(std::vector<Parameter*>::iterator it = r->parameters()->begin(); it != r->parameters()->end(); it++)
{
Parameter* p = (Parameter*) *it;
p->accept(this);
if((it+1) != r->parameters()->end())
fprintf(this->out_f_, ", ");
}
fprintf(this->out_f_, ") {\n");
// TODO unmarshaling
fprintf(this->out_f_, "}\n");
}
void Callee_SourceVisitor::visit(Parameter* p)
{
p->type()->accept(this);
// print p->name_
fprintf(this->out_f_, " %s", p->name());
}
void Callee_SourceVisitor::visit(ProjectionType *p)
{
fprintf(this->out_f_, "%s", p->real_type());
}
void Callee_SourceVisitor::visit(ProjectionField *pf)
{
}
void Callee_SourceVisitor::visit(IntegerType *it)
{
if(it->unsigned_huh())
fprintf(this->out_f_, "unsigned ");
fprintf(this->out_f_, "%s", it->type());
}
void Callee_SourceVisitor::visit(PointerType *pt)
{
pt->p_type()->accept(this);
fprintf(this->out_f_, "* ");
}
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;
}
#ifndef GEN_VISITOR
#define GEN_VISITOR
#include "lcd_ast.h"
#include <stdio.h>
class GenVisitor : public ASTVisitor
{
//FILE* out_f_;
public:
virtual void visit(File *f) =0;
virtual void visit(Rpc *rpc) =0;
virtual void visit(Parameter * p) =0;
virtual void visit(ProjectionType * p) =0;
virtual void visit(ProjectionField * pf) =0;
virtual void visit(IntegerType * it) =0;
virtual void visit(PointerType * it) =0;
virtual void visit(Typedef* td) =0;
};
class HeaderVisitor : public GenVisitor
{
FILE* out_f_;
public:
HeaderVisitor(FILE* f);
virtual void visit(File *f);
virtual void visit(Rpc *rpc);
virtual void visit(Parameter * p);
virtual void visit(ProjectionType * p);
virtual void visit(ProjectionField * pf);
virtual void visit(IntegerType * it);
virtual void visit(PointerType * it);
virtual void visit(Typedef* td);
};
class Caller_SourceVisitor : public GenVisitor
{
FILE* out_f_;
public:
Caller_SourceVisitor(FILE* out);
virtual void visit(File *f);
virtual void visit(Rpc *rpc);
virtual void visit(Parameter * p);
virtual void visit(ProjectionType * p);
virtual void visit(ProjectionField * pf);
virtual void visit(IntegerType * it);
virtual void visit(PointerType * it);
virtual void visit(Typedef* td);
};
class Callee_SourceVisitor : public GenVisitor
{
FILE* out_f_;
void exec_loop(File* f);
public:
Callee_SourceVisitor(FILE* out);
virtual void visit(File *f);
virtual void visit(Rpc *rpc);
virtual void visit(Parameter * p);
virtual void visit(ProjectionType * p);
virtual void visit(ProjectionField * pf);
virtual void visit(IntegerType * it);
virtual void visit(PointerType * it);
virtual void visit(Typedef* td);
};
#endif
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