Commit ff2560df authored by Sarah Spall's avatar Sarah Spall Committed by Vikram Narayanan
Browse files

redid existing marshalling code. partly works

parent 8585db69
#include "lcd_ast.h"
#include <stdio.h>
Rpc::Rpc(ReturnVariable *return_value, const char* name, std::vector<Parameter* > parameters, LexicalScope *current_scope)
{
this->explicit_return_ = return_value;
......@@ -15,6 +14,75 @@ Rpc::Rpc(ReturnVariable *return_value, const char* name, std::vector<Parameter*
Parameter *p = (Parameter*) *it;
this->symbol_table_->insert(p->identifier());
}
construct_marshal_parameters();
}
void Rpc::construct_marshal_parameters()
{
std::vector<Variable*> marshal_parameters;
for(std::vector<Parameter*>::iterator it = this->parameters_.begin(); it != this->parameters_.end(); it ++) {
Parameter *p = *it;
if (p->type()->num() == 4 && (p->alloc_caller() || p->alloc_callee())) {
ProjectionType *pt = dynamic_cast<ProjectionType*>(p->type());
Assert(pt != 0x0, "Error: dynamic cast to projection type failed.\n");
std::vector<Variable*> tmp_params = construct_projection_parameters(pt, p->alloc_callee() || p->alloc_caller());
marshal_parameters.insert(marshal_parameters.end(), tmp_params.begin(), tmp_params.end());
} else if (p->in()) {
marshal_parameters.push_back(p);
}
}
this->marshal_parameters = marshal_parameters;
}
std::vector<Variable*> Rpc::construct_projection_parameters(ProjectionType *pt, bool alloc)
{
std::vector<Variable*> marshal_parameters;
// insert container ref here. // TODOOOO
int err;
Type* container_tmp = this->current_scope_->lookup(container_name(pt->name()), &err);
if(container_tmp == 0x0) {
printf("Error could not find container struct for %s\n", pt->name());
return marshal_parameters;
}
ProjectionType *container = dynamic_cast<ProjectionType*>(container_tmp);
Assert(container != 0x0, "Error: dynamic cast to projection type failed.\n");
if(alloc) {
ProjectionField *my_ref_field = container->get_field("my_ref");
Assert(my_ref_field != 0x0, "Error: could not find field %s in projection.\n", "my_ref");
ProjectionType* my_ref_field_struct = dynamic_cast<ProjectionType*>(my_ref_field->type());
Assert(my_ref_field_struct != 0x0, "Error: dynamic cast to projection type failed.\n");
ProjectionField *dptr = my_ref_field_struct->get_field("dptr");
Assert(dptr != 0x0, "Error: could not find field %s in projection. \n", "dptr");
marshal_parameters.push_back(dptr);
} else {
ProjectionField *other_ref_field = container->get_field("other_ref");
Assert(other_ref_field != 0x0, "Error: could not find field %s in projection.\n", "other_ref");
ProjectionType *other_ref_field_struct = dynamic_cast<ProjectionType*>(other_ref_field->type());
Assert(other_ref_field_struct != 0x0, "Error: dynamic cast to projection type failed.\n");
ProjectionField *dptr = other_ref_field_struct->get_field("dptr");
Assert(dptr != 0x0, "Error: could not find field %s in projection.\n", "dptr");
marshal_parameters.push_back(dptr);
}
std::vector<ProjectionField*> fields = pt->fields();
for(std::vector<ProjectionField*>::iterator it = fields.begin(); it != fields.end(); it ++) {
ProjectionField *pf = *it;
if (pf->type()->num() == 4 && (pf->alloc_caller() || pf->alloc_callee())) {
ProjectionType *pt_tmp = dynamic_cast<ProjectionType*>(pf->type());
Assert(pt_tmp != 0x0, "Error: dynamic cast to Projection type failed.\n");
std::vector<Variable*> tmp_params = construct_projection_parameters(pt_tmp
, pf->alloc_callee() || pf->alloc_caller());
marshal_parameters.insert(marshal_parameters.end(), tmp_params.begin(), tmp_params.end());
} else if (pf->in()) {
marshal_parameters.push_back(pf);
}
}
return marshal_parameters;
}
void Rpc::set_function_pointer_defined(bool b)
......@@ -73,11 +141,11 @@ void Rpc::prepare_marshal()
MarshalPrepareVisitor *worker = new MarshalPrepareVisitor(new Registers());
// marshal prepare for parameters as long as they are in or out
for(std::vector<Parameter*>::iterator it = this->parameters_.begin(); it != this->parameters_.end(); it ++) {
Parameter* p = *it;
if(p->in() || p->out()) {
p->prepare_marshal(worker);
}
for(std::vector<Variable*>::iterator it = this->marshal_parameters.begin(); it != this->marshal_parameters.end(); it ++) {
Variable* v = *it;
// if(v->in() || v->out()) {
v->prepare_marshal(worker);
// }
}
// marshal prepare for return value
......
......@@ -38,13 +38,13 @@ GlobalScope::GlobalScope()
int err;
fields.push_back(new ProjectionField(this->lookup("unsigned long", &err), "dptr", 0)); // unsigned long dptr;
this->type_definitions_.insert( std::pair<std::string, Type*>("dptr_t"
, new Typedef("dptr_t", "", new ProjectionType("", "", fields))));
, new ProjectionType("dptr_t", "dptr_t", fields)));
// cptr_t
std::vector<ProjectionField*> fields2;
fields2.push_back(new ProjectionField(this->lookup("unsigned long", &err), "cptr", 0)); // unsigned long cptr;
this->type_definitions_.insert( std::pair<std::string, Type*>("cptr_t"
, new Typedef("cptr_t", "", new ProjectionType("", "", fields2))));
, new ProjectionType("cptr_t", "cptr_t", fields2)));
// dstore no fields
......
......@@ -130,39 +130,17 @@ CCSTCompoundStatement* caller_body(Rpc *r)
statements.push_back(alloc_init_containers_driver(p, pt, r->current_scope(), "caller"));
}
}
// marshal parameters.
// if function pointer pass reference to container
// which will be a parameter.... so don't need to check... thank god
/*
// marshal_parameters
std::vector<Variable*> marshal_params = r->marshal_parameters;
printf("going to loop through marshal params\n");
for(std::vector<Variable*>::iterator it = marshal_params.begin(); it != marshal_params.end(); it ++) {
Variable *mp = *it;
if (mp->type()->num() == 4) { // is a projection and we need to pass a reference.
ProjectionType *pt = dynamic_cast<ProjectionType*>(mp->type());
Assert(pt != 0x0, "Error: dynamic cast to projection failed!\n");
std::vector<ProjectionField*> pt_fields = pt->fields();
for(std::vector<ProjectionField*>::iterator it2 = pt_fields.begin(); it2 != pt_fields.end(); it2 ++) {
ProjectionField *pf = *it2;
if (pf->in()) { // marshal this field
std::vector<CCSTAssignExpr*> register_args;
register_args.push_back(access(pf)); // pass field marked in.
statements.push_back(function_call(access_register_mapping(pf->marshal_info()->get_register())
, register_args));
}
}
} else {
std::vector<CCSTAssignExpr*> register_args;
register_args.push_back(access(mp));
statements.push_back(function_call(access_register_mapping(mp->marshal_info()->get_register())
, register_args));
}
Variable *v = *it;
printf("calling marshal variable for var %s\n", v->identifier());
statements.push_back(marshal_variable(v));
}
*/
// marshal_variable(variable);
return new CCSTCompoundStatement(declarations, statements);
......
#include "code_gen.h"
CCSTStatement* marshal_variable(Variable *param)
CCSTStatement* marshal_variable(Variable *v)
{
// todo
}
CCSTStatement* MarshalTypeVisitor::visit(Channel *c, Variable *v)
{
printf("Marshal type visitor channel todo\n");
return 0x0;
}
CCSTStatement* MarshalTypeVisitor::visit(Function *fp, Variable *v)
{
printf("Marshal function pointer not completed\n");
return 0x0;
}
// function call to set whatever register.
// access the variable.
// if the variable is a dptr call
// dptr_val
CCSTStatement* MarshalTypeVisitor::visit(Typedef *td, Variable *v)
{
// get register number
Marshal_type* mt = v->marshal_info();
CCSTPostFixExpr* access_v = access(v);
std::vector<CCSTAssignExpr*> arguments;
const char* store_reg_func = store_register_mapping(v->marshal_info()->get_register());
if (v->pointer_count() > 0) {
arguments.push_back(dereference(access_v));
std::vector<CCSTAssignExpr*> store_reg_args;
if(v->type()->name() == "dptr_t") {
std::vector<CCSTAssignExpr*> dptr_val_args;
dptr_val_args.push_back(access(v));
store_reg_args.push_back(function_call("dptr_val", dptr_val_args));
} else {
arguments.push_back(access_v);
store_reg_args.push_back(access(v));
}
return function_call(store_register_mapping(mt->get_register())
, arguments);
}
CCSTStatement* MarshalTypeVisitor::visit(VoidType *vt, Variable *v)
{
printf("Error: cannot marshal void type\n");
return 0x0;
return function_call(store_reg_func, store_reg_args);
}
CCSTStatement* MarshalTypeVisitor::visit(IntegerType *it, Variable *v)
CCSTStatement* marshal_projection_variable(Variable *v, ProjectionType *pt)
{
// get register number
Marshal_type* mt = v->marshal_info();
CCSTPostFixExpr* access_v = access(v);
std::vector<CCSTAssignExpr*> arguments;
if (v->pointer_count() > 0) {
arguments.push_back(dereference(access_v));
} else {
arguments.push_back(access_v);
}
return function_call( store_register_mapping(mt->get_register())
, arguments);
}
CCSTStatement* MarshalTypeVisitor::visit(ProjectionType *pt, Variable *v)
{
std::vector<CCSTDeclaration*> declarations;
std::vector<CCSTStatement*> statements;
// if alloc caller
// if alloc callee
// marshal fields
std::vector<ProjectionField*> fields = pt->fields();
for(std::vector<ProjectionField*>::iterator it = fields.begin(); it != fields.end(); it ++) {
// marshal each field.
ProjectionField *pf_tmp = *it;
statements.push_back(pf_tmp->type()->accept(this, pf_tmp));
}
// a channel???????
// todo
}
......@@ -336,6 +336,7 @@ CCSTFile* generate_server_source(Module *m)
{
Rpc* r_tmp = (Rpc*) *it;
if(r_tmp->function_pointer_defined()) {
printf("doing function pointer def\n");
definitions.push_back( function_definition(function_declaration(r_tmp)
,caller_body(r_tmp)));
} else {
......
......@@ -470,10 +470,10 @@ class Rpc : public Base
std::vector<Parameter* > parameters_;
bool function_pointer_defined_;
void construct_marshal_parameters();
std::vector<Variable*> construct_projection_parameters(ProjectionType *pt);
std::vector<Variable*> construct_projection_parameters(ProjectionType *pt, bool alloc);
public:
Rpc(ReturnVariable *return_var, const char* name, std::vector<Parameter* > parameters, LexicalScope *current_scope);
std::vector<Variable*> marshal_parameters; // wtf is this
std::vector<Variable*> marshal_parameters;
void set_function_pointer_defined(bool b);
bool function_pointer_defined();
const char* name();
......
......@@ -8,13 +8,13 @@
,REG50, REG51, REG52, REG53, REG54, REG55, REG56, REG57, REG58, REG59
,REG60, REG61, REG62, REG63};
static const char* register_store_mapping_[] = {REG0, REG1, REG2, REG3, REG4, REG5, REG6, REG7, REG8, REG9
,REG10, REG11, REG12, REG13, REG14, REG15, REG16, REG17, REG18, REG19
,REG20, REG21, REG22, REG23, REG24, REG25, REG26, REG27, REG28, REG29
,REG30, REG31, REG32, REG33, REG34, REG35, REG36, REG37, REG38, REG39
,REG40, REG41, REG42, REG43, REG44, REG45, REG46, REG47, REG48, REG49
,REG50, REG51, REG52, REG53, REG54, REG55, REG56, REG57, REG58, REG59
,REG60, REG61, REG62, REG63};
static const char* register_store_mapping_[] = {STORE_REG0, STORE_REG1, STORE_REG2, STORE_REG3, STORE_REG4, STORE_REG5, STORE_REG6, STORE_REG7, STORE_REG8, STORE_REG9
,STORE_REG10, STORE_REG11, STORE_REG12, STORE_REG13, STORE_REG14, STORE_REG15, STORE_REG16, STORE_REG17, STORE_REG18, STORE_REG19
,STORE_REG20, STORE_REG21, STORE_REG22, STORE_REG23, STORE_REG24, STORE_REG25, STORE_REG26, STORE_REG27, STORE_REG28, STORE_REG29
,STORE_REG30, STORE_REG31, STORE_REG32, STORE_REG33, STORE_REG34, STORE_REG35, STORE_REG36, STORE_REG37, STORE_REG38, STORE_REG39
,STORE_REG40, STORE_REG41, STORE_REG42, STORE_REG43, STORE_REG44, STORE_REG45, STORE_REG46, STORE_REG47, STORE_REG48, STORE_REG49
,STORE_REG50, STORE_REG51, STORE_REG52, STORE_REG53, STORE_REG54, STORE_REG55, STORE_REG56, STORE_REG57, STORE_REG58, STORE_REG59
,STORE_REG60, STORE_REG61, STORE_REG62, STORE_REG63};
const char* access_register_mapping(int register_index) { return register_access_mapping_[register_index]; }
......
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