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

rewrote the code that allocates registers for marshalling. code now compiles without errors

parent 70e13017
......@@ -7,7 +7,7 @@ CXXFLAGS = -g -fsanitize=address -fno-omit-frame-pointer -Iinclude/ -lasan
CXX = g++
LDFLAGS = -fsanitize=address
objects = lcd_ast.o main.o lcd_idl.o scope.o variable.o types.o error.o marshal_op.o ccst.o server.o client.o helper.o unmarshal.o marshal.o
objects = lcd_ast.o main.o lcd_idl.o scope.o symbol_table.o variable.o types.o type_name_visitor.o error.o marshal_op.o ccst.o server.o client.o helper.o unmarshal.o marshal.o
$(bin): $(objects)
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
......@@ -18,16 +18,16 @@ main.o: main/main.cpp include/lcd_ast.h include/lcd_idl.h include/error.h includ
error.o: error/error.cpp include/error.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
marshal.o: code_gen/marshal.cpp include/ccst.h include/marshal_op.h
marshal.o: code_gen/marshal.cpp include/ccst.h include/code_gen.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
unmarshal.o: code_gen/unmarshal.cpp include/ccst.h include/marshal_op.h
unmarshal.o: code_gen/unmarshal.cpp include/ccst.h include/code_gen.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
helper.o: code_gen/helper.cpp include/ccst.h include/code_gen.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
client.o: code_gen/client.cpp inclue/ccst.h include/code_gen.h
client.o: code_gen/client.cpp include/ccst.h include/code_gen.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
server.o: code_gen/server.cpp include/ccst.h include/code_gen.h
......@@ -36,6 +36,9 @@ server.o: code_gen/server.cpp include/ccst.h include/code_gen.h
ccst.o: ccst.cpp include/ccst.h include/marshal_op.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
type_name_visitor.o: type_name_visitor.cpp include/lcd_ast.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
types.o: ast/types.cpp include/lcd_ast.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
......@@ -48,6 +51,9 @@ lcd_idl.o: $(idl) include/lcd_ast.h
scope.o: ast/scope.cpp include/lcd_ast.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
symbol_table.o: symbol_table.cpp include/symbol_table.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
marshal_op.o: marshal_op.cpp include/marshal_op.h include/lcd_ast.h include/assert.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
......
......@@ -7,7 +7,6 @@ Rpc::Rpc(ReturnVariable *return_value, char* name, std::vector<Parameter* > para
this->explicit_return_ = return_value;
this->name_ = name;
this->parameters_ = parameters;
this->set_implicit_returns();
this->symbol_table_ = new SymbolTable();
for(std::vector<Parameter*>::iterator it = parameters.begin(); it != parameters.end(); it ++)
......@@ -17,28 +16,11 @@ Rpc::Rpc(ReturnVariable *return_value, char* name, std::vector<Parameter* > para
}
}
ReturnVariable* Rpc::return_value()
ReturnVariable* Rpc::return_variable()
{
return this->explicit_return_;
}
void Rpc::set_implicit_returns()
{
std::vector<ImplicitReturnVariable*> implicit_returns;
for(std::vector<Parameter*>::iterator it = this->parameters_.begin(); it != this->parameters_.end(); it ++)
{
Parameter *p = (Parameter*) *it;
if(p->type()->num() == 3) // Pointer //make an enum......
{
implicit_returns.push_back(new ImplicitReturnVariable(p));
}
}
this->implicit_returns_ = implicit_returns;
}
char* Rpc::name()
{
return name_;
......@@ -70,6 +52,22 @@ std::vector<Parameter*> Rpc::parameters()
return parameters_;
}
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);
}
}
// marshal prepare for return value
this->explicit_return_->prepare_marshal(worker);
}
Module::Module(std::vector<Rpc*> rpc_definitions, std::vector<GlobalVariable*> globals, LexicalScope *ls)
{
this->module_scope_ = ls;
......@@ -91,3 +89,26 @@ LexicalScope* Module::module_scope()
{
return this->module_scope_;
}
void Module::prepare_marshal()
{
for(std::vector<Rpc*>::iterator it = this->rpc_definitions_.begin(); it != this->rpc_definitions_.end(); it ++) {
Rpc *r = *it;
r->prepare_marshal();
}
}
Project::Project(LexicalScope *scope, std::vector<Module*> modules)
{
this->project_scope_ = scope;
this->project_modules_ = modules;
}
void Project::prepare_marshal()
{
for(std::vector<Module*>::iterator it = this->project_modules_.begin(); it != this->project_modules_.end(); it ++) {
Module *m = *it;
m->prepare_marshal();
}
}
......@@ -51,6 +51,12 @@ bool GlobalScope::insert(Rpc *r)
return ret.second;
}
std::vector<Rpc*> GlobalScope::rpc_in_scope()
{
std::vector<Rpc*> empty;
return empty;
}
bool GlobalScope::contains(const char *symbol)
{
std::string temp(symbol);
......@@ -136,6 +142,13 @@ bool LexicalScope::insert(Rpc *r)
return ret.second;
}
std::vector<Rpc*> LexicalScope::rpc_in_scope()
{
printf("rpc in scope lexical scope todo\n");
std::vector<Rpc*> empty;
return empty;
}
bool LexicalScope::contains(const char *symbol)
{
std::string temp(symbol);
......
......@@ -9,12 +9,17 @@ FunctionPointer::FunctionPointer(const char *id, ReturnVariable *return_var, std
this->parameters_ = parameters;
}
Marshal_type* FunctionPointer::accept(MarshalPrepareVisitor *worker)
{
return worker->visit(this);
}
CCSTTypeName* FunctionPointer::accept(TypeNameVisitor *worker)
{
return worker->visit(this);
}
CCSTStatement* FunctionPointer::accept(AllocateTypeVisitor *worker, Variable *v)
CCSTStatement* FunctionPointer::accept(TypeVisitor *worker, Variable *v)
{
return worker->visit(this, v);
}
......@@ -40,14 +45,18 @@ Typedef::Typedef(const char* alias, Type* type)
this->alias_ = alias;
this->type_ = type; // need to allocate?
}
/*
Marshal_type* Typedef::accept(MarshalVisitor *worker, Registers *data)
Marshal_type* Typedef::accept(MarshalPrepareVisitor *worker)
{
return worker->visit(this);
}
CCSTTypeName* Typedef::accept(TypeNameVisitor *worker)
{
return worker->visit(this, data);
return worker->visit(this);
}
*/
CCSTStatement* Typedef::accept(AllocateTypeVisitor *worker, Variable *v)
CCSTStatement* Typedef::accept(TypeVisitor *worker, Variable *v)
{
return worker->visit(this, v);
}
......@@ -79,14 +88,18 @@ const char* Typedef::name()
VoidType::VoidType()
{
}
/*
Marshal_type* VoidType::accept(MarshalVisitor *worker, Registers *data)
Marshal_type* VoidType::accept(MarshalPrepareVisitor *worker)
{
return worker->visit(this);
}
CCSTTypeName* VoidType::accept(TypeNameVisitor *worker)
{
return worker->visit(this, data);
return worker->visit(this);
}
*/
CCSTStatement* VoidType::accept(AllocateTypeVisitor *worker, Variable *v)
CCSTStatement* VoidType::accept(TypeVisitor *worker, Variable *v)
{
return worker->visit(this, v);
}
......@@ -112,14 +125,17 @@ IntegerType::IntegerType(PrimType type, bool un, int size)
this->size_ = size;
}
/*
Marshal_type* IntegerType::accept(MarshalVisitor* worker, Registers *data)
Marshal_type* IntegerType::accept(MarshalPrepareVisitor *worker)
{
return worker->visit(this);
}
CCSTTypeName* IntegerType::accept(TypeNameVisitor *worker)
{
return worker->visit(this, data);
return worker->visit(this);
}
*/
CCSTStatement* IntegerType::accept(AllocateTypeVisitor *worker, Variable *v)
CCSTStatement* IntegerType::accept(TypeVisitor *worker, Variable *v)
{
return worker->visit(this, v);
}
......@@ -147,57 +163,30 @@ const char* IntegerType::name()
/* end */
/* pointer type */
PointerType::PointerType(Type* type)
{
this->type_ = type;
}
int PointerType::num()
{
return 3;
}
Type* PointerType::type()
{
return this->type_;
}
/*
Marshal_type* PointerType::accept(MarshalVisitor* worker, Registers *data)
{
return worker->visit(this, data);
}
*/
/* projection type */
CCSTStatement* PointerType::accept(AllocateTypeVisitor *worker, Variable *v)
ProjectionType::ProjectionType(const char* id, const char* real_type, std::vector<ProjectionField*> fields)
{
return worker->visit(this, v);
this->id_ = id; this->real_type_ = real_type; this->fields_ = fields;
}
const char* PointerType::name()
ProjectionType::ProjectionType(const char* id, const char* real_type, std::vector<ProjectionField*> fields, std::vector<GlobalVariable*> init_vars)
{
return this->type_->name();
this->id_ = id; this->real_type_ = real_type; this->fields_ = fields;
this->init_variables_ = init_vars;
}
/* end */
/* projection type */
ProjectionType::ProjectionType(const char* id, const char* real_type, std::vector<ProjectionField*> fields)
Marshal_type* ProjectionType::accept(MarshalPrepareVisitor *worker)
{
this->id_ = id; this->real_type_ = real_type; this->fields_ = fields;
return worker->visit(this);
}
/*
Marshal_type* ProjectionType::accept(MarshalVisitor* worker, Registers *data)
CCSTTypeName* ProjectionType::accept(TypeNameVisitor *worker)
{
return worker->visit(this, data);
return worker->visit(this);
}
*/
CCSTStatement* ProjectionType::accept(AllocateTypeVisitor *worker, Variable *v)
CCSTStatement* ProjectionType::accept(TypeVisitor *worker, Variable *v)
{
return worker->visit(this, v);
}
......
......@@ -9,6 +9,11 @@ GlobalVariable::GlobalVariable(Type *type, const char *id, int pointer_count)
this->pointer_count_ = pointer_count;
}
void GlobalVariable::prepare_marshal(MarshalPrepareVisitor *worker)
{
printf("global variable prepare marshal todo\n");
}
Type* GlobalVariable::type()
{
return this->type_;
......@@ -30,10 +35,14 @@ Variable* GlobalVariable::accessor()
return 0x0;
}
void GlobalVariable::set_marshal_info(Marshal_type *mt)
{
this->marshal_info_ = mt;
}
Marshal_type* GlobalVariable::marshal_info()
{
printf("global variable marshal_info not yet implemented\n");
return 0x0;
return this->marshal_info_;
}
int GlobalVariable::pointer_count()
......@@ -135,12 +144,10 @@ Parameter::Parameter(Type* type, const char* name, int pointer_count)
this->alloc_callee_caller_ = false;
}
/*
Marshal_type* Parameter::accept(MarshalVisitor* worker, Registers *data)
void Parameter::prepare_marshal(MarshalPrepareVisitor *worker)
{
return worker->visit(this, data);
this->marshal_info_ = this->type_->accept(worker);
}
*/
const char* Parameter::identifier()
{
......@@ -253,6 +260,11 @@ ReturnVariable::ReturnVariable(Type *return_type, int pointer_count)
this->pointer_count_ = pointer_count;
}
void ReturnVariable::prepare_marshal(MarshalPrepareVisitor *worker)
{
this->marshal_info_ = this->type_->accept(worker);
}
void ReturnVariable::set_marshal_info(Marshal_type *mt)
{
this->marshal_info_ = mt;
......@@ -355,116 +367,6 @@ bool ReturnVariable::alloc_callee_caller()
/* end */
/* implicit return variable */
ImplicitReturnVariable::ImplicitReturnVariable(Parameter *p)
{
this->p_ = p;
}
void ImplicitReturnVariable::set_marshal_info(Marshal_type *mt)
{
this->marshal_info_ = mt;
}
Marshal_type* ImplicitReturnVariable::marshal_info()
{
return this->marshal_info_;
}
void ImplicitReturnVariable::set_accessor(Variable *v)
{
this->accessor_ = v;
}
Type* ImplicitReturnVariable::type()
{
return this->p_->type();
}
const char* ImplicitReturnVariable::identifier()
{
return this->p_->identifier();
}
int ImplicitReturnVariable::pointer_count()
{
return this->p_->pointer_count();
}
Variable* ImplicitReturnVariable::accessor()
{
return this->accessor_;
}
void ImplicitReturnVariable::set_in(bool b)
{
printf("error this operation not allowed\n");
}
void ImplicitReturnVariable::set_out(bool b)
{
printf("error this operation not allowed\n");
}
void ImplicitReturnVariable::set_alloc(bool b)
{
printf("error this operation not allowed\n");
}
void ImplicitReturnVariable::set_alloc_caller(bool b)
{
printf("error this operation not allowed\n");
}
void ImplicitReturnVariable::set_alloc_callee(bool b)
{
printf("error this operation not allowed\n");
}
void ImplicitReturnVariable::set_alloc_callee_caller(bool b)
{
printf("error this operation not allowed\n");
}
bool ImplicitReturnVariable::in()
{
printf("error this operation not allowed\n");
return false;
}
bool ImplicitReturnVariable::out()
{
printf("error this operation not allowed\n");
return false;
}
bool ImplicitReturnVariable::alloc()
{
printf("error this operation not allowed\n");
return false;
}
bool ImplicitReturnVariable::alloc_caller()
{
printf("error this operation not allowed\n");
return false;
}
bool ImplicitReturnVariable::alloc_callee()
{
printf("error this operation not allowed\n");
return false;
}
bool ImplicitReturnVariable::alloc_callee_caller()
{
printf("error this operation not allowed\n");
return false;
}
/* end */
/* projection field */
ProjectionField::ProjectionField(Type* field_type, const char* field_name, int pointer_count)
......@@ -480,12 +382,10 @@ ProjectionField::ProjectionField(Type* field_type, const char* field_name, int p
this->pointer_count_ = pointer_count;
}
/*
Marshal_type* ProjectionField::accept(MarshalVisitor* worker, Registers *data)
void ProjectionField::prepare_marshal(MarshalPrepareVisitor *worker)
{
return worker->visit(this, data);
this->marshal_info_ = this->field_type_->accept(worker);
}
*/
Type* ProjectionField::type()
{
......@@ -512,10 +412,14 @@ Variable* ProjectionField::accessor()
return this->accessor_;
}
void ProjectionField::set_marshal_info(Marshal_type *mt)
{
this->marshal_info_ = mt;
}
Marshal_type* ProjectionField::marshal_info()
{
printf("projection field marshal info incomplete\n");
return 0x0;
return this->marshal_info_;
}
void ProjectionField::set_in(bool b)
......@@ -584,16 +488,36 @@ FPParameter::FPParameter(Type *type, int pointer_count)
this->pointer_count_ = pointer_count;
}
void FPParameter::prepare_marshal(MarshalPrepareVisitor *worker)
{
this->marshal_info_ = this->type_->accept(worker);
}
Type* FPParameter::type()
{
return this->type_;
}
int FPParameter::pointer_count()
{
return this->pointer_count_;
}
const char* FPParameter::identifier()
{
Assert(1 == 0, "Error: operation not allowed on function pointer parameter\n");
}
void FPParameter::set_marshal_info(Marshal_type *mt)
{
this->marshal_info_ = mt;
}
Marshal_type* FPParameter::marshal_info()
{
return this->marshal_info_;
}
void FPParameter::set_in(bool b)
{
printf("this operation is now allowed\n");
......
......@@ -23,9 +23,8 @@ CCSTFile* generate_client_source(Module* f)
// create initialization function
std::vector<CCSTExDeclaration*> definitions;
for(std::vector<Rpc*>::iterator it = f->rpc_defs().begin(); it != f->rpc_defs().end(); it ++) {
std::vector<Rpc*> rpcs = f->rpc_definitions();
for(std::vector<Rpc*>::iterator it = rpcs.begin(); it != rpcs.end(); it ++) {
Rpc *r = (Rpc*) *it;
definitions.push_back(function_definition(function_declaration(r)
,caller_body(r)));
......@@ -34,17 +33,21 @@ CCSTFile* generate_client_source(Module* f)
return new CCSTFile(definitions);
}
CCSTCompoundStatement* create_caller_body(Rpc *r)
CCSTCompoundStatement* caller_body(Rpc *r)
{
std::vector<CCSTDeclaration*> declarations;
std::vector<CCSTStatement*> statements = marshal_parameters(r->parameters());
// implicit returns
std::vector<CCSTStatement*> uirs = unmarshal_implicit_return(r->implicit_ret_marshal_info());
statements.insert(statements.end(), uirs.begin(), uirs.end());
// replace with parameter loop
//std::vector<CCSTStatement*> uirs = unmarshal_implicit_return(r->implicit_ret_marshal_info());
//statements.insert(statements.end(), uirs.begin(), uirs.end());
if(r->explicit_return_type()->num() != 5) { // not void
Marshal_type *ret_info = r->explicit_ret_marshal_info();
ReturnVariable *rv = r->return_variable();
if(rv->type()->num() != 5) { // not void
// Marshal_type *ret_info = r->explicit_ret_marshal_info();
}
......@@ -52,7 +55,7 @@ CCSTCompoundStatement* create_caller_body(Rpc *r)
statements.push_back(new CCSTReturn());
}
return new CCSTCompoundstatement(declarations, statements);
return new CCSTCompoundStatement(declarations, statements);
}
......@@ -62,7 +65,7 @@ std::vector<CCSTStatement*> marshal_parameters(std::vector<Parameter*> params)
for(std::vector<Parameter*>::iterator it = params.begin(); it != params.end(); it ++) {
Parameter *p = (Parameter*) *it;
statements.push_back(marshal_parameter(p));
statements.push_back(marshal_variable(p));
}
return statements;
......@@ -70,6 +73,7 @@ std::vector<CCSTStatement*> marshal_parameters(std::vector<Parameter*> params)
std::vector<CCSTStatement*> unmarshal_implicit_return(std::vector<Parameter*> implicit_returns)
{
/*
std::vector<CCSTStatement*> statements;
for(std::vector<Parameter*>::iterator it = implicit_returns.begin(); it != implicit_returns.end(); it ++) {
Parameter *p = *it;
......@@ -78,8 +82,10 @@ std::vector<CCSTStatement*> unmarshal_implicit_return(std::vector<Parameter*> im
}
return statements;
*/
}
/*
CCSTStatement* unmarshal_explicit_return(Marshal_type* return_info)
{
CCSTPointer *p = 0x0;
......@@ -95,6 +101,7 @@ CCSTStatement* unmarshal_explicit_return(Marshal_type* return_info)
s.push_back(ret_info->accept(visitor));
s.push_back( new CCSTReturn(new CCSTPrimaryExprId("internal_ret")));
}
*/
......
......@@ -16,27 +16,27 @@ CCSTDeclaration* container_struct_definition(const char* name, ProjectionType *p
std::vector<CCSTStructDeclarator*> real_struct_field;
real_struct_field.push_back(new CCSTStructDeclarator(new CCSTDeclarator(0x0, new CCSTDirectDecId(pt->real_type()))));
container_fields.push_back(new CCSTStructDeclaration(type(pt), real_struct_field));