Commit 3c46c2ca authored by Sarah Spall's avatar Sarah Spall Committed by Vikram Narayanan

switching branch

parent 8a1f8a00
...@@ -45,13 +45,14 @@ Type * RootScope::lookup_symbol(const char * sym, int* err) ...@@ -45,13 +45,14 @@ Type * RootScope::lookup_symbol(const char * sym, int* err)
std::string temp = sym; std::string temp = sym;
if(this->types_->find(temp) == this->types_->end()) if(this->types_->find(temp) == this->types_->end())
{ {
// printf("looking up %s\n", sym);
// printf("is empty? %d\n", this->types_->size());
*err = 0; *err = 0;
return 0; return 0;
} }
else else
return (*(this->types_))[temp]; {
*err = 1;
return (*(this->types_))[temp];
}
} }
int RootScope::insert_symbol(const char* sym, Type * value) int RootScope::insert_symbol(const char* sym, Type * value)
...@@ -67,13 +68,16 @@ int RootScope::insert_symbol(const char* sym, Type * value) ...@@ -67,13 +68,16 @@ int RootScope::insert_symbol(const char* sym, Type * value)
Type* FileScope::lookup_symbol(const char* sym, int* err) Type* FileScope::lookup_symbol(const char* sym, int* err)
{ {
std::string temp = sym; std::string temp = sym;
// lookup here or root first?
if(types_->find(temp) == types_->end()) if(this->types_->find(temp) == this->types_->end())
{ {
// error return this->root_->lookup_symbol(sym, err);
} }
else else
return (*types_)[temp]; {
*err = 1;
return (*types_)[temp];
}
} }
...@@ -82,10 +86,9 @@ int FileScope::insert_symbol(const char* sym, Type* value) ...@@ -82,10 +86,9 @@ int FileScope::insert_symbol(const char* sym, Type* value)
std::string temp = sym; std::string temp = sym;
// redefinition of something at root scope? // redefinition of something at root scope?
std::pair<std::map<std::string,Type*>::iterator, bool> ret; std::pair<std::map<std::string,Type*>::iterator, bool> ret;
ret = types_->insert(std::pair<std::string,Type*>(temp, value)); // filescope map not rootscope
ret = this->types_->insert(std::pair<std::string,Type*>(temp, value));
return ret.second; return ret.second;
} }
FileScope::FileScope(RootScope* root) FileScope::FileScope(RootScope* root)
......
#include "gen_visitor.h" #include "gen_visitor.h"
SourceVisitor::SourceVisitor(FILE* out, int stub_proxy)
{
this->out_f_ = out;
this->stub_or_proxy_ = stub_proxy;
}
void SourceVisitor::visit(File* f) void SourceVisitor::visit(File* f)
{ {
for(std::vector<Rpc*>::iterator it = f->rpc_defs()->begin(); it != f->rpc_defs()->end(); it++)
{
Rpc* r = (Rpc*) *it;
r->accept(this);
fprintf(this->out_f_, "\n\n");
}
} }
void SourceVisitor::visit(Rpc* r) void SourceVisitor::visit(Rpc* r)
{ {
Type* rt = r->return_type();
printf("here in hv hisit rpc\n");
printf("%d\n", rt->num());
rt->accept(this); // this seems unnecessary in this case
const char* name = r->name();
fprintf(this->out_f_, " %s(", name);
for(std::vector<Parameter*>::iterator it = r->parameters()->begin(); it != r->parameters()->end(); it++)
{
Parameter* p = (Parameter*) *it;
p->accept(this);
if((it+1) != r->parameters()->end())
fprintf(this->out_f_, ", ");
}
fprintf(this->out_f_, ") {\n");
// print body
// TODO
fprintf(this->out_f_, "}\n");
} }
void SourceVisitor::visit(Parameter* p) void SourceVisitor::visit(Parameter* p)
{ {
p->type()->accept(this);
// print p->name_
fprintf(this->out_f_, " %s", p->name());
} }
void SourceVisitor::visit(ProjectionType *p) void SourceVisitor::visit(ProjectionType *p)
{ {
fprintf(this->out_f_, "%s", p->real_type());
} }
void SourceVisitor::visit(ProjectionField *pf) void SourceVisitor::visit(ProjectionField *pf)
...@@ -23,12 +58,19 @@ void SourceVisitor::visit(ProjectionField *pf) ...@@ -23,12 +58,19 @@ void SourceVisitor::visit(ProjectionField *pf)
void SourceVisitor::visit(IntegerType *it) void SourceVisitor::visit(IntegerType *it)
{ {
if(it->unsigned_huh())
fprintf(this->out_f_, "unsigned ");
fprintf(this->out_f_, "%s", it->type());
} }
void SourceVisitor::visit(PointerType *pt) void SourceVisitor::visit(PointerType *pt)
{ {
pt->type()->accept(this);
fprintf(this->out_f_, "* ");
} }
void SourceVisitor::visit(Typedef* td) void SourceVisitor::visit(Typedef* td)
{ {
fprintf(this->out_f_, "%s", td->alias());
} }
...@@ -35,9 +35,10 @@ class HeaderVisitor : public GenVisitor ...@@ -35,9 +35,10 @@ class HeaderVisitor : public GenVisitor
class SourceVisitor : public GenVisitor class SourceVisitor : public GenVisitor
{ {
// FILE* out_f_; FILE* out_f_;
public: int stub_or_proxy_; // 1 equals stub, 2 equals proxy
SourceVisitor(FILE* f); public:
SourceVisitor(FILE* out, int stub_proxy);
virtual void visit(File *f); virtual void visit(File *f);
virtual void visit(Rpc *rpc); virtual void visit(Rpc *rpc);
virtual void visit(Parameter * p); virtual void visit(Parameter * p);
......
...@@ -4,10 +4,13 @@ ...@@ -4,10 +4,13 @@
#include <string> #include <string>
namespace Parser{ namespace Parser{
/* filename should be a path to a file */ /* filename should be a path to a file */
extern const void * parse(const std::string & filename, bool stats = false); extern const void * parse(const std::string & filename, bool stats = false);
......
module name {
projection super_block<struct super_block> {
[in] int field1;
}
}
rpc int foo(capability cpa, char v1, int v2); rpc int foo(int cpa, char v1, int v2);
rpc int bar(projection super_block * rp); rpc int bar(projection super_block* rp);
...@@ -2,24 +2,26 @@ ...@@ -2,24 +2,26 @@
from os import getcwd, listdir from os import getcwd, listdir
from os.path import join from os.path import join
from subprocess import call, check_output from subprocess import check_call, check_output, CalledProcessError
def main(): def main():
print("in main") current_dir = getcwd()
test_dir = getcwd() test_dir = join(current_dir, "test")
comp_dir = "../compiler" comp_dir = join(current_dir, "compiler")
out_dir = join(test_dir, "out") out_dir = join(test_dir, "out")
for file in listdir(test_dir): for file in listdir(test_dir):
print("in loop: " + file)
if file.endswith(".idl"): if file.endswith(".idl"):
try: try:
result = check_output([comp_dir, '-header', file], timeout=2) print("in loop: " + file)
print("in try") idl_file = join("test", file)
except: out_file = join("test", file+".h")
print("in except") print(out_file)
pass print(idl_file)
check_call([comp_dir, '-header', idl_file, '-out', out_file])
except Exception as e:
print("f")
if __name__ == '__main__': if __name__ == '__main__':
main() main()
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