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

function pointer related code

parent 2f3eab59
......@@ -372,7 +372,7 @@ Parameter::Parameter(const Parameter& other)
void Parameter::create_container_variable(LexicalScope *ls)
{
if(this->pointer_count() <= 0 || (this->type_->num() != 4 && this->type_->num() != 9 && this->type_->num() != 10)) {
if(this->pointer_count() <= 0 || (this->type_->num() != 4 && this->type_->num() != 9 && this->type_->num() != 10) || (!this->bind_caller() && !this->bind_callee() && !this->alloc_caller() && !this->alloc_callee())) {
return;
}
Type *tmp = this->type_;
......@@ -1018,7 +1018,7 @@ ProjectionField::ProjectionField(const ProjectionField& other)
void ProjectionField::create_container_variable(LexicalScope *ls)
{
if(this->pointer_count() <= 0 || (this->type_->num() != 4 && this->type_->num() != 9 && this->type_->num() != 10)) {
if(this->pointer_count() <= 0 || (this->type_->num() != 4 && this->type_->num() != 9 && this->type_->num() != 10) || (!this->bind_caller() && !this->bind_callee() && !this->alloc_caller() && !this->alloc_callee())) {
return;
}
Type *tmp = this->type_;
......
......@@ -53,8 +53,8 @@ CCSTFile* generate_client_source(Module* f)
definitions.push_back(function_definition(callee_declaration(r_tmp)
, callee_body(r_tmp, f)));
} else {
definitions.push_back(function_definition(function_declaration(r_tmp)
,caller_body(r_tmp, f)));
// definitions.push_back(function_definition(function_declaration(r_tmp)
// ,caller_body(r_tmp, f)));
}
}
......@@ -102,6 +102,14 @@ CCSTCompoundStatement* caller_body(Rpc *r, Module *m)
// loop through params, declare a tmp and pull out marshal value
std::vector<Parameter*> params = r->parameters();
const char* cspace_to_use;
if(r->function_pointer_defined()) { // cspace is 1st hidden arg
cspace_to_use = r->hidden_args_.at(0)->identifier();
} else {
cspace_to_use = m->cspaces_.at(0)->identifier();
}
// for every parameter that has a container. declare containers. then alloc or container of
for(std::vector<Parameter*>::iterator it = params.begin(); it != params.end(); it ++)
{
......@@ -111,7 +119,7 @@ CCSTCompoundStatement* caller_body(Rpc *r, Module *m)
std::vector<CCSTDeclaration*> tmp = declare_containers(p);
declarations.insert(declarations.end(), tmp.begin(), tmp.end());
statements.push_back(alloc_link_container_caller(p, m->cspaces_.at(0)->identifier()));
statements.push_back(alloc_link_container_caller(p, cspace_to_use));
}
}
......@@ -155,6 +163,18 @@ CCSTCompoundStatement* caller_body(Rpc *r, Module *m)
statements.push_back(marshal_variable(p, "in"));
}
}
/* if it is a function pointer need to marshal hidden args */
if (r->function_pointer_defined()) {
std::vector<Parameter*> hidden_args = r->hidden_args_;
for(std::vector<Parameter*>::iterator it = hidden_args.begin(); it != hidden_args.end(); it ++) {
Parameter *p = *it;
if(p->in()) {
printf("going to marshal hdiden arg %s for function %s\n", p->identifier(), r->name());
statements.push_back(marshal_variable(p, "in"));
}
}
}
/* marshal function tag */
statements.push_back(marshal(new CCSTInteger(r->tag()), 0));
......@@ -187,10 +207,22 @@ CCSTCompoundStatement* caller_body(Rpc *r, Module *m)
}
}
/* if function pointer defined unmarshal hidden args*/
if(r->function_pointer_defined()) {
std::vector<Parameter*> hidden_args = r->hidden_args_;
for(std::vector<Parameter*>::iterator it = hidden_args.begin(); it != hidden_args.end(); it ++) {
Parameter *p = *it;
if(p->out()) {
std::vector<CCSTStatement*> tmp_stmts = unmarshal_variable_caller(p);
statements.insert(statements.end(), tmp_stmts.begin(), tmp_stmts.end());
}
}
}
// if anything is marked dealloc. dealloc
for(std::vector<Parameter*>::iterator it = parameters.begin(); it != parameters.end(); it ++) {
Parameter *p = *it;
std::vector<CCSTStatement*> tmp_statements = dealloc_containers_caller(p, m->cspaces_.at(0)->identifier(), r->current_scope());
std::vector<CCSTStatement*> tmp_statements = dealloc_containers_caller(p, cspace_to_use, r->current_scope());
statements.insert(statements.end(), tmp_statements.begin(), tmp_statements.end());
}
......
......@@ -77,6 +77,7 @@ CCSTDeclaration* function_declaration(Rpc* r)
CCSTDirectDecId *name = new CCSTDirectDecId(r->name());
CCSTParamTypeList *param_list = parameter_list(r->parameters());
CCSTDirectDecParamTypeList *name_params = new CCSTDirectDecParamTypeList(name, param_list);
func.push_back(new CCSTDeclarator(p, name_params));
......@@ -84,6 +85,33 @@ CCSTDeclaration* function_declaration(Rpc* r)
return new CCSTDeclaration(specifier, func);
}
CCSTDeclaration* function_pointer_function_declaration(Rpc *r)
{
std::vector<CCSTDecSpecifier*> specifier = type2(r->return_variable()->type());
std::vector<CCSTInitDeclarator*> func; // = new std::vector<CCSTInitDeclarator*>(); // pointer name, params
CCSTPointer *p = pointer(r->return_variable()->pointer_count());
CCSTDirectDecId *name = new CCSTDirectDecId(r->name());
std::vector<Parameter*> all_params;
std::vector<Parameter*> r_parameters = r->parameters();
std::vector<Parameter*> r_hidden_args = r->hidden_args_;
all_params.insert(all_params.end(), r_parameters.begin(), r_parameters.end());
all_params.insert(all_params.end(), r_hidden_args.begin(), r_hidden_args.end());
CCSTParamTypeList *param_list = parameter_list(all_params);
CCSTDirectDecParamTypeList *name_params = new CCSTDirectDecParamTypeList(name, param_list);
func.push_back(new CCSTDeclarator(p, name_params));
return new CCSTDeclaration(specifier, func);
}
//
CCSTPostFixExpr* access(Variable *v)
{
......
......@@ -149,12 +149,21 @@ CCSTCompoundStatement* callee_body(Rpc *r, Module *m)
declarations.insert(declarations.end(), tmp_decs.begin(), tmp_decs.end());
}
if(r->function_pointer_defined()) {
std::vector<Parameter*> hidden_args = r->hidden_args_;
for(std::vector<Parameter*>::iterator it = hidden_args.begin(); it != hidden_args.end(); it ++) {
Parameter *p = *it;
// declare hiiden args.
}
}
// TODO: unmarshal channel refs;
// allocate/initiliaze and link these
for(std::vector<Parameter*>::iterator it = params.begin(); it != params.end(); it ++)
{
Parameter *p = *it; // allocs and lookups but doesn't link yet.
printf("Parameter is %s\n", p->identifier());
statements.push_back(allocate_and_link_containers_callee(p
, m->cspaces_.at(0)->identifier()));
}
......@@ -406,15 +415,15 @@ 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, m)));
// need definitions.push_back( function_definition(trampoline_function_declaration(r_tmp)
// , trampoline_function_body(r_tmp)));
definitions.push_back( function_definition(function_pointer_function_declaration(r_tmp)
,caller_body(r_tmp, m)));
definitions.push_back( function_definition(trampoline_function_declaration(r_tmp)
, trampoline_function_body(r_tmp)));
} else {
printf("doing callee_declaration\n");
definitions.push_back( function_definition(callee_declaration(r_tmp)
,callee_body(r_tmp, m)));
// definitions.push_back( function_definition(callee_declaration(r_tmp)
// ,callee_body(r_tmp, m)));
}
}
......
......@@ -92,6 +92,7 @@ CCSTDeclaration* interface_exit_function_declaration(Module *m); // complete
CCSTFuncDef* function_definition(CCSTDeclaration *function_declaration, CCSTCompoundStatement *body); // complete
CCSTDeclaration* function_declaration(Rpc *r); // complete
CCSTDeclaration* function_pointer_function_declaration(Rpc *r);
CCSTParamTypeList* parameter_list(std::vector<Parameter*> params); // complete
......
Supports Markdown
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