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

code to create trampoline structs for function pointers defined in projections...

code to create trampoline structs for function pointers defined in projections and as parameters in rpcs
parent af7fa39f
......@@ -44,6 +44,11 @@ Marshal_type* Rpc::accept(MarshalVisitor* worker, Registers *data)
}
*/
LexicalScope* Rpc::current_scope()
{
return this->current_scope_;
}
const char* Rpc::callee_name()
{
char * callee_name = (char*) malloc((strlen(this->name_)+strlen("_callee")+1)*sizeof(char));
......@@ -91,6 +96,25 @@ void Rpc::resolve_types()
this->explicit_return_->resolve_types(this->current_scope_);
}
void Rpc::create_trampoline_structs()
{
for(std::vector<Parameter*>::iterator it = this->parameters_.begin(); it != this->parameters_.end(); it ++) {
Parameter* p = *it;
if (p->type()->num() == 7) {
Function *f = dynamic_cast<Function*>(p->type());
Assert(f != 0x0, "Error: dynamic cast to function type failed!\n");
std::vector<ProjectionField*> trampoline_fields;
int err;
trampoline_fields.push_back(new ProjectionField(this->current_scope_->lookup("dstore", &err), "dstore", 1)); // dstore field
trampoline_fields.push_back(new ProjectionField(this->current_scope_->lookup("lcd_trampoline_handle", &err), "t_handle", 1)); // lcd_trampoline handle field
const char* trampoline_struct_name = hidden_args_name(f->name());
this->current_scope_->insert(trampoline_struct_name, new ProjectionType(trampoline_struct_name, trampoline_struct_name, trampoline_fields));
}
}
}
Module::Module(const char *id, std::vector<Rpc*> rpc_definitions, std::vector<GlobalVariable*> globals, LexicalScope *ls)
{
this->module_name_ = id;
......@@ -139,6 +163,18 @@ void Module::function_pointer_to_rpc()
this->rpc_definitions_.insert(this->rpc_definitions_.end(), rpcs.begin(), rpcs.end());
}
void Module::create_trampoline_structs()
{
this->module_scope_->create_trampoline_structs();
// loop through rpc definitions
// todo
for(std::vector<Rpc*>::iterator it = this->rpc_definitions_.begin(); it != this->rpc_definitions_.end(); it ++) {
Rpc *r = *it;
r->create_trampoline_structs();
}
}
const char* Module::identifier()
{
return this->module_name_;
......@@ -179,6 +215,16 @@ void Project::function_pointer_to_rpc()
}
}
void Project::create_trampoline_structs()
{
// todo
for(std::vector<Module*>::iterator it = this->project_modules_.begin(); it != this->project_modules_.end(); it ++) {
Module *m = *it;
m->create_trampoline_structs();
}
}
std::vector<Module*> Project::modules()
{
return this->project_modules_;
......
......@@ -51,6 +51,10 @@ GlobalScope::GlobalScope()
std::vector<ProjectionField*> fields3;
this->type_definitions_.insert(std::pair<std::string, Type*>("dstore"
, new ProjectionType("dstore", "dstore", fields3)));
std::vector<ProjectionField*> fields4;
this->type_definitions_.insert(std::pair<std::string, Type*>("lcd_trampoline_handle"
, new ProjectionType("lcd_trampoline_handle", "lcd_trampoline_handle", fields4)));
}
GlobalScope* GlobalScope::instance()
......@@ -155,6 +159,19 @@ void GlobalScope::resolve_types()
}
}
// just call parent.......
void GlobalScope::create_trampoline_structs()
{
for(std::map<std::string, Type*>::iterator it = this->type_definitions_.begin(); it != this->type_definitions_.end(); it ++) {
it->second->create_trampoline_structs(this);
}
for(std::vector<LexicalScope*>::iterator it = this->inner_scopes_.begin(); it != this->inner_scopes_.end(); it ++) {
LexicalScope *ls = (LexicalScope*) *it;
ls->create_trampoline_structs();
}
}
std::vector<Rpc*> GlobalScope::function_pointer_to_rpc()
{
std::vector<Rpc*> rpcs;
......@@ -336,6 +353,18 @@ void LexicalScope::resolve_types()
}
}
void LexicalScope::create_trampoline_structs()
{
for(std::map<std::string, Type*>::iterator it = this->type_definitions_.begin(); it != this->type_definitions_.end(); it ++) {
it->second->create_trampoline_structs(this);
}
for(std::vector<LexicalScope*>::iterator it = this->inner_scopes_.begin(); it != this->inner_scopes_.end(); it ++) {
LexicalScope *ls = (LexicalScope*) *it;
ls->create_trampoline_structs();
}
}
std::vector<Rpc*> LexicalScope::function_pointer_to_rpc()
{
std::vector<Rpc*> rpcs;
......
#include "lcd_ast.h"
/* function pointer type*/
const char* container_name(const char* name)
const char* new_name(const char* name, const char* suffix)
{
int length = strlen(name);
int length2 = strlen("_container");
int length2 = strlen(suffix);
char *new_str = (char*) malloc(sizeof(char)*(length+length2+1));
std::ostringstream total;
total << name << "_container";
total << name << suffix;
strncpy(new_str, total.str().c_str(), length+length2+1);
return new_str;
}
/* function pointer type*/
const char* container_name(const char* name)
{
return new_name(name, "_container");
}
const char* hidden_args_name(const char* name)
{
return new_name(name, "_hidden_args");
}
Function::Function(const char *id, ReturnVariable *return_var, std::vector<Parameter*> parameters)
{
this->identifier_ = id;
......@@ -51,6 +61,11 @@ void Function::resolve_types(LexicalScope *ls)
return;
}
void Function::create_trampoline_structs(LexicalScope *ls)
{
return;
}
Rpc* Function::to_rpc(LexicalScope *ls, ProjectionType *pt)
{
// adding extra parameters here. but maybe depending on needs this could be done at parse time
......@@ -114,6 +129,10 @@ void UnresolvedType::resolve_types(LexicalScope *ls)
return;
}
void UnresolvedType::create_trampoline_structs(LexicalScope *ls)
{
return;
}
Channel::Channel()
{
......@@ -145,6 +164,11 @@ void Channel::resolve_types(LexicalScope *ls)
return;
}
void Channel::create_trampoline_structs(LexicalScope *ls)
{
return;
}
/* typedef type */
......@@ -195,6 +219,11 @@ void Typedef::resolve_types(LexicalScope *ls)
return;
}
void Typedef::create_trampoline_structs(LexicalScope *ls)
{
return; //todo?
}
/* end */
/* void type */
......@@ -233,6 +262,11 @@ void VoidType::resolve_types(LexicalScope *ls)
return;
}
void VoidType::create_trampoline_structs(LexicalScope *ls)
{
return;
}
/* end */
/* integer type */
......@@ -285,6 +319,11 @@ void IntegerType::resolve_types(LexicalScope *ls)
return;
}
void IntegerType::create_trampoline_structs(LexicalScope *ls)
{
return;
}
/* end */
/* projection type */
......@@ -344,5 +383,26 @@ void ProjectionType::resolve_types(LexicalScope *ls)
}
}
void ProjectionType::create_trampoline_structs(LexicalScope *ls)
{
for(std::vector<ProjectionField*>::iterator it = this->fields_.begin(); it != this->fields_.end(); it ++) {
ProjectionField *pf = (ProjectionField*) *it;
if (pf->type()->num() == 7) { // function pointer
Function *f = dynamic_cast<Function*>(pf->type());
Assert(f != 0x0, "Error: dynamic cast to function type failed!\n");
std::vector<ProjectionField*> trampoline_fields;
int err;
trampoline_fields.push_back(new ProjectionField(ls->lookup(container_name(this->name()), &err)
,container_name(this->name()), 1)); // container field
trampoline_fields.push_back(new ProjectionField(ls->lookup("dstore", &err), "dstore", 1)); // dstore field
trampoline_fields.push_back(new ProjectionField(ls->lookup("lcd_trampoline_handle", &err), "t_handle", 1)); // lcd_trampoline handle field
const char* trampoline_struct_name = hidden_args_name(f->name());
ls->insert(trampoline_struct_name, new ProjectionType(trampoline_struct_name, trampoline_struct_name, trampoline_fields));
}
}
}
/* end */
......@@ -285,6 +285,24 @@ CCSTFile* generate_server_source(Module *m)
}
}
// print trampoline structs
std::vector<Rpc*> rpcs = m->rpc_definitions();
for(std::vector<Rpc*>::iterator it = rpcs.begin(); it != rpcs.end(); it ++) {
Rpc *r = *it;
if (r->function_pointer_defined()) {
int err;
Type *t = r->current_scope()->lookup(hidden_args_name(r->name()), &err);
Assert(t != 0x0, "Error: failure looking up type\n");
ProjectionType *pt = dynamic_cast<ProjectionType*>(t);
Assert(t != 0x0, "Error: dynamic cast to projection type failed!\n");
std::vector<CCSTDecSpecifier*> specifier;
specifier.push_back(struct_declaration(pt));
std::vector<CCSTInitDeclarator*> empty;
definitions.push_back(new CCSTDeclaration(specifier, empty));
}
}
// globals.
std::vector<GlobalVariable*> globals = m->globals();
......
......@@ -30,6 +30,10 @@ enum type_k {};
template<class T, class T2>
class ASTVisitor;
const char* new_name(const char* name, const char* suffix);
const char* container_name(const char* name);
const char* hidden_args_name(const char* name);
class Base
{
public:
......@@ -56,6 +60,7 @@ class LexicalScope : public Base
virtual std::vector<LexicalScope*> inner_scopes();
virtual LexicalScope* outer_scope();
virtual void resolve_types();
virtual void create_trampoline_structs();
virtual std::vector<Rpc*> function_pointer_to_rpc();
virtual std::map<std::string, Type*> all_type_definitions();
virtual std::map<std::string, Type*> all_types_outer();
......@@ -84,6 +89,7 @@ class GlobalScope : public LexicalScope
static GlobalScope* instance(); // x
virtual LexicalScope* outer_scope();
virtual void resolve_types();
virtual void create_trampoline_structs();
virtual std::vector<Rpc*> function_pointer_to_rpc();
virtual std::map<std::string, Type*> all_type_definitions();
virtual std::map<std::string, Type*> all_types_outer();
......@@ -99,6 +105,7 @@ class Type : public Base
virtual int num() = 0;
virtual const char* name() = 0;
virtual void resolve_types(LexicalScope *ls) = 0;
virtual void create_trampoline_structs(LexicalScope *ls) = 0;
};
class UnresolvedType : public Type
......@@ -112,6 +119,7 @@ class UnresolvedType : public Type
virtual int num();
virtual const char* name();
virtual void resolve_types(LexicalScope *ls);
virtual void create_trampoline_structs(LexicalScope *ls);
};
class Variable : public Base
......@@ -310,6 +318,7 @@ class Function : public Type
virtual const char* name();
virtual void resolve_types(LexicalScope *ls);
Rpc* to_rpc(LexicalScope *ls, ProjectionType *pt);
virtual void create_trampoline_structs(LexicalScope *ls);
};
class Typedef : public Type
......@@ -330,6 +339,7 @@ class Typedef : public Type
virtual int num();
virtual void resolve_types(LexicalScope *ls);
// virtual void marshal();
virtual void create_trampoline_structs(LexicalScope *ls);
};
class Channel : public Type
......@@ -342,6 +352,7 @@ class Channel : public Type
virtual const char* name();
virtual int num();
virtual void resolve_types(LexicalScope *ls);
virtual void create_trampoline_structs(LexicalScope *ls);
};
class VoidType : public Type
......@@ -354,6 +365,7 @@ class VoidType : public Type
virtual const char* name();
virtual int num();
virtual void resolve_types(LexicalScope *ls);
virtual void create_trampoline_structs(LexicalScope *ls);
};
class IntegerType : public Type
......@@ -373,6 +385,7 @@ class IntegerType : public Type
virtual int num();
virtual void resolve_types(LexicalScope *ls);
~IntegerType(){printf("inttype destructor\n");}
virtual void create_trampoline_structs(LexicalScope *ls);
};
class ProjectionField : public Variable //?
......@@ -440,6 +453,7 @@ class ProjectionType : public Type // complex type
virtual int num();
virtual void resolve_types(LexicalScope *ls);
~ProjectionType(){printf("projection type destructor\n");}
virtual void create_trampoline_structs(LexicalScope *ls);
};
class Rpc : public Base
......@@ -466,6 +480,8 @@ class Rpc : public Base
SymbolTable* symbol_table();
void prepare_marshal();
void resolve_types();
void create_trampoline_structs();
LexicalScope *current_scope();
};
class Module : public Base
......@@ -483,6 +499,7 @@ class Module : public Base
void prepare_marshal();
void resolve_types();
void function_pointer_to_rpc();
void create_trampoline_structs();
const char* identifier();
};
......@@ -505,6 +522,7 @@ class Project : public Base
void prepare_marshal();
void resolve_types();
void function_pointer_to_rpc();
void create_trampoline_structs();
std::vector<Module*> modules();
};
......
......@@ -61,7 +61,7 @@ int main(int argc, char ** argv)
}
else if(!strcmp(argv[1],"-serversource")) // callee
{
tree->create_trampoline_structs();
tree->function_pointer_to_rpc();
tree->resolve_types();
tree->prepare_marshal();
......
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