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

insert containers into dstore and do error checking

parent cac85870
......@@ -12,7 +12,7 @@ objects = lcd_ast.o main.o lcd_idl.o scope.o symbol_table.o variable.o types.o t
$(bin): $(objects)
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
main.o: main/main.cpp include/lcd_ast.h include/lcd_idl.h include/error.h include/ccst.h
main.o: main/main.cpp include/lcd_ast.h include/lcd_idl.h include/error.h include/ccst.h include/code_gen.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
error.o: error/error.cpp include/error.h
......
......@@ -405,5 +405,16 @@ void ProjectionType::create_trampoline_structs(LexicalScope *ls)
}
}
ProjectionField* ProjectionType::get_field(const char *field_name)
{
for(std::vector<ProjectionField*>::iterator it = this->fields_.begin(); it != this->fields_.end(); it ++) {
ProjectionField *pf = *it;
if (strcmp(field_name, pf->identifier()) == 0) {
return pf;
}
}
return 0x0;
}
/* end */
......@@ -94,6 +94,11 @@ CCSTCompoundStatement* caller_body(Rpc *r)
// loop through params, declare a tmp and pull out marshal value
std::vector<Parameter*> params = r->parameters();
std::vector<CCSTInitDeclarator*> err_decs;
err_decs.push_back(new CCSTDeclarator(0x0, new CCSTDirectDecId("err")));
CCSTDeclaration *err_variable = new CCSTDeclaration(int_type(), err_decs);
declarations.push_back(err_variable);
// for each parameter that is ia projection -- & is alloc
for(std::vector<Parameter*>::iterator it = params.begin(); it != params.end(); it ++)
{
......@@ -130,23 +135,30 @@ CCSTCompoundStatement* caller_body(Rpc *r)
// if null
// LIBLCD_ERR("kzalloc");
// lcd_exit(-1); /* abort */
std::vector<CCSTDeclaration*> if_body_declarations;
std::vector<CCSTStatement*> if_body_statements;
std::vector<CCSTAssignExpr*> liblcd_err_args;
liblcd_err_args.push_back(new CCSTString("kzalloc"));
if_body_statements.push_back(function_call("LIBLCD_ERR", liblcd_err_args));
std::vector<CCSTAssignExpr*> lcd_exit_args;
lcd_exit_args.push_back(new CCSTInteger(-1));
if_body_statements.push_back(function_call("lcd_exit", lcd_exit_args));
CCSTCompoundStatement *if_body = new CCSTCompoundStatement(if_body_declarations, if_body_statements);
statements.push_back(new CCSTIfStatement(new CCSTUnaryExprCastExpr(Not(), new CCSTPrimaryExprId(container_name_))
, if_body));
statements.push_back(if_cond_fail(new CCSTUnaryExprCastExpr(Not(), new CCSTPrimaryExprId(container_name_))
, "kzalloc"));
// insert into dstore
// do error checking
// err = lcd_dstore_insert...
std::vector<CCSTAssignExpr*> dstore_insert_args;
dstore_insert_args.push_back(new CCSTPrimaryExprId("dstore")); // lookup this name in the future.
dstore_insert_args.push_back(new CCSTPrimaryExprId(container_name_)); // what we are inserting
dstore_insert_args.push_back(new CCSTEnumConst("STRUCT_FILE_TAG")); // this part is not clear
ProjectionField *my_ref_field = container->get_field("my_ref");
Assert(my_ref_field != 0x0, "Error: could not find field in projection\n");
dstore_insert_args.push_back(access(my_ref_field));
// insert into dstore
statements.push_back(new CCSTAssignExpr(new CCSTPrimaryExprId("err"), equals(), function_call("lcd_dstore_insert", dstore_insert_args)));
// do error checking
statements.push_back(if_cond_fail(new CCSTPrimaryExprId("err"), "dstore"));
}
}
......
......@@ -251,6 +251,14 @@ std::vector<CCSTDecSpecifier*> struct_type(const char *type_name)
return specifier;
}
std::vector<CCSTDecSpecifier*> int_type()
{
std::vector<CCSTDecSpecifier*>specifier;
specifier.push_back(new CCSTSimpleTypeSpecifier(int_t));
return specifier;
}
std::vector<CCSTDecSpecifier*> type2(Type *t)
{
std::vector<CCSTDecSpecifier*>specifier;
......@@ -612,3 +620,21 @@ CCSTStructUnionSpecifier* struct_declaration(ProjectionType *pt)
return new CCSTStructUnionSpecifier(struct_t, pt->name(), field_decs);
}
CCSTIfStatement* if_cond_fail(CCSTExpression *cond, const char *err_msg)
{
std::vector<CCSTDeclaration*> if_body_declarations;
std::vector<CCSTStatement*> if_body_statements;
std::vector<CCSTAssignExpr*> liblcd_err_args;
liblcd_err_args.push_back(new CCSTString(err_msg));
if_body_statements.push_back(function_call("LIBLCD_ERR", liblcd_err_args));
std::vector<CCSTAssignExpr*> lcd_exit_args;
lcd_exit_args.push_back(new CCSTInteger(-1));
if_body_statements.push_back(function_call("lcd_exit", lcd_exit_args));
CCSTCompoundStatement *if_body = new CCSTCompoundStatement(if_body_declarations, if_body_statements);
return new CCSTIfStatement(cond, if_body);
}
......@@ -132,71 +132,7 @@ CCSTCompoundStatement* dispatch_loop_body(std::vector<Rpc*> rps)
*/
CCSTCompoundStatement* callee_body(Rpc *r)
{
// unmarshal parameters based on marshal data.
// which says where params are stored.
std::vector<CCSTDeclaration*> declarations;
std::vector<CCSTStatement*> statements;
// loop through params, declare a tmp and pull out marshal value
std::vector<Parameter*> params = r->parameters();
// for each parameter that is ia projection -- & is alloc
for(std::vector<Parameter*>::iterator it = params.begin(); it != params.end(); it ++)
{
Parameter *p = *it;
if(p->type()->num() == 4 && p->alloc_caller()) {
ProjectionType *pt = dynamic_cast<ProjectionType*>(p->type());
Assert(pt != 0x0, "Error: dynamic cast to Projection type failed!\n");
// lookup container struct
int err;
const char* container_name_ = container_name(pt->name());
Type *container_tmp = r->current_scope()->lookup(container_name_, &err);
Assert(container_tmp != 0x0, "Error: could not find container in environment\n");
ProjectionType *container = dynamic_cast<ProjectionType*>(container_tmp);
Assert(container != 0x0, "Error: dynamic cast to Projection type failed!\n");
// declare instance of container
std::vector<CCSTInitDeclarator*> decs;
decs.push_back(new CCSTDeclarator(new CCSTPointer(), new CCSTDirectDecId(container_name_)));
CCSTDeclaration *container_declaration = new CCSTDeclaration(type2(container), decs);
// finish declaring instance of container
declarations.push_back(container_declaration);
// file_container = kzalloc(sizeof(*file_container), GFP_KERNEL);
std::vector<CCSTAssignExpr*> kzalloc_args;
kzalloc_args.push_back(new CCSTUnaryExprSizeOf(new CCSTUnaryExprCastExpr(new CCSTUnaryOp(unary_mult_t), new CCSTPrimaryExprId(container_name_))));
kzalloc_args.push_back(new CCSTEnumConst("GFP_KERNEL"));
statements.push_back(new CCSTAssignExpr(new CCSTPrimaryExprId(container_name_), equals(), function_call("kzalloc", kzalloc_args)));
// if null
// LIBLCD_ERR("kzalloc");
// lcd_exit(-1); /* abort */
std::vector<CCSTDeclaration*> if_body_declarations;
std::vector<CCSTStatement*> if_body_statements;
std::vector<CCSTAssignExpr*> liblcd_err_args;
liblcd_err_args.push_back(new CCSTString("kzalloc"));
if_body_statements.push_back(function_call("LIBLCD_ERR", liblcd_err_args));
std::vector<CCSTAssignExpr*> lcd_exit_args;
lcd_exit_args.push_back(new CCSTInteger(-1));
if_body_statements.push_back(function_call("lcd_exit", lcd_exit_args));
CCSTCompoundStatement *if_body = new CCSTCompoundStatement(if_body_declarations, if_body_statements);
statements.push_back(new CCSTIfStatement(new CCSTUnaryExprCastExpr(Not(), new CCSTPrimaryExprId(container_name_))
, if_body));
// insert into dstore
// do error checking
}
}
return new CCSTCompoundStatement(declarations, statements);
printf("callee body todo\n");
}
......@@ -372,6 +308,7 @@ CCSTFile* generate_server_source(Module *m)
definitions.push_back( function_definition(function_declaration(r_tmp)
,caller_body(r_tmp)));
} else {
printf("doing callee_declaration\n");
definitions.push_back( function_definition(callee_declaration(r_tmp)
,callee_body(r_tmp)));
}
......@@ -383,32 +320,3 @@ CCSTFile* generate_server_source(Module *m)
printf("in server source gen\n");
return c_file;
}
// one
/*
CCSTCompoundStatement* create_callee_body(Rpc *r)
{
std::vector<Parameter*> parameters = r->parameters();
for(std::vector<Parameter*>::iterator it = parameters.begin(); it != parameters.end(); it ++) {
Parameter *p = (Parameter*) *it;
if(p->alloc()) {
AllocateVariableVisitor *worker = new AllocateVariableVisitor();
p->type()->accept(worker); // allocates space if needed.
} else { // if not alloc must be bind?
// grab from some function.
}
UnmarshalVariableVisitor *worker = new UnmarshalVariableVisitor();
p->accept(worker);
}
// make real call.
// for each implicit return, marshal
// marshal explicit return
} */
......@@ -455,6 +455,7 @@ class ProjectionType : public Type // complex type
virtual void resolve_types(LexicalScope *ls);
~ProjectionType(){printf("projection type destructor\n");}
virtual void create_trampoline_structs(LexicalScope *ls);
ProjectionField* get_field(const char* field_name);
};
class Rpc : public Base
......
......@@ -2,7 +2,10 @@
#define SYMBOL_TABLE_H
#include <vector>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <sstream>
class SymbolTable
{
......@@ -10,10 +13,12 @@ class SymbolTable
std::vector<const char*> symbols_;
public:
SymbolTable();
SymbolTable(std::vector<const char*> symbols);
const char* unique_tmp();
bool contains();
void insert(const char *symbol);
void insert(std::vector<const char*> symbols);
bool contains(const char *symbol);
int insert(const char *symbol);
int insert(std::vector<const char*> symbols);
std::string to_string(int value);
};
#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