Commit 8cdd4871 authored by Sarah Spall's avatar Sarah Spall Committed by Vikram Narayanan

marshalling and printing, untested

parent e26f85d5
......@@ -6,12 +6,12 @@ idl = parser/lcd_idl.cpp include/lcd_idl.h
CXXFLAGS = -g -Iinclude/
CXX = g++
objects = lcd_ast.o main.o lcd_idl.o scope.o header_gen.o error.o
objects = lcd_ast.o main.o lcd_idl.o scope.o header_gen.o error.o marshal_op.o
$(bin): $(objects)
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
main.o: main/main.cpp include/lcd_ast.h include/lcd_idl.h include/gen_visitor.h include/error.h
main.o: main/main.cpp include/lcd_ast.h include/lcd_idl.h include/gen_visitor.h include/error.h include/marshal_op.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
error.o: error/error.cpp include/error.h
......@@ -26,6 +26,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,$^)
marshal_op.o: marshal_op.cpp include/marshal_op.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
lcd_ast.o: ast/lcd_ast.cpp include/lcd_ast.h
$(CXX) $(CXXFLAGS) -c -o $@ $(filter-out %.h,$^)
......@@ -36,7 +39,7 @@ parser/lcd_idl.cpp: parser/lcd_idl.peg
parser/vembyr-1.1/peg.py --cpp $^ > $@
clean:
-rm -f $(objects) $(bin) $(idl) lcd_ast.h.gch
-rm -f $(objects) $(bin) $(idl) inclue/lcd_ast.h.gch
test: $(bin)
./test/test.py
......@@ -17,6 +17,11 @@ const char* Typedef::alias()
return this->alias_;
}
const char* Typedef::type()
{
return alias_;
}
IntegerType::IntegerType(const char* type, bool un, int size)
{
this->type_ = type;
......@@ -49,11 +54,17 @@ void PointerType::accept(ASTVisitor* worker)
worker->visit(this);
}
Type* PointerType::type()
Type* PointerType::p_type()
{
return this->type_;
}
const char* PointerType::type()
{
// may need *
return this->type_->type();
}
ProjectionField::ProjectionField(bool in, bool out, bool alloc, bool bind, Type* field_type, const char* field_name)
{
this->in_ = in; this->out_ = out; this->alloc_ = alloc; this->bind_ = bind; this->field_type_ = field_type; this->field_name_ = field_name;
......@@ -99,11 +110,18 @@ const char* ProjectionType::id()
return this->id_;
}
// may never be used
const char* ProjectionType::real_type()
{
return this->real_type_;
}
// may never be used
const char* ProjectionType::type()
{
return this->real_type_;
}
Parameter::Parameter(Type* type, const char* name)
{
this->type_ = type;
......@@ -125,15 +143,20 @@ const char* Parameter::name()
return this->name_;
}
char* Parameter::marshal()
const char* Parameter::marshal()
{
//allocate?
std::ostringstream ret;
ret <<
ret << "lcd_store_r?( " << this->name_ << " );";
return ret.str().c_str();
}
char* Parameter::unmarshal()
const char* Parameter::unmarshal()
{
// allocate?
std::ostringstream ret;
ret << this->name_ << " = " << "( " << this->type_->type() << " ) " << "lcd_r?()";
return ret.str().c_str();
}
Rpc::Rpc(Type* return_type, const char* name, std::vector<Parameter* >* parameters)
......
......@@ -93,7 +93,7 @@ void HeaderVisitor::visit(IntegerType* it)
void HeaderVisitor::visit(PointerType* pt)
{
pt->type()->accept(this);
pt->p_type()->accept(this);
fprintf(this->out_f_, "* ");
}
......
......@@ -4,6 +4,10 @@
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <stdio.h>
#include "marshal_op.h"
enum PrimType { kChar = 1, kShort, kInt, kLong, kLongLong, kCapability};
......@@ -11,7 +15,6 @@ class ASTVisitor;
class Base
{
//M_info info;
};
class Type : public Base
......@@ -20,8 +23,8 @@ class Type : public Base
public:
virtual void accept(ASTVisitor *worker) = 0;
virtual int num() = 0;
// virtual void marshal() = 0;
// virtual int size() = 0;
virtual const char* type() = 0;
virtual ~Type(){printf("type destructor\n");}
};
class Scope : public Base
......@@ -64,6 +67,7 @@ class Typedef : public Type
public:
Typedef(const char* alias, Type* type);
virtual void accept(ASTVisitor *worker);
virtual const char* type();
const char* alias();
virtual int num() {return 1;}
// virtual void marshal();
......@@ -78,26 +82,27 @@ class IntegerType : public Type
public:
IntegerType(const char* type, bool un, int size);
virtual void accept(ASTVisitor *worker);
const char* type();
virtual const char* type();
bool unsigned_huh();
virtual int num() {return 2;}
// virtual void marshal();
~IntegerType(){printf("inttype destructor\n");}
};
/*
class CapabilityType : public IntegerType
{
// is this needed?
};
*/
class PointerType : public Type
{
Type* type_;
public:
PointerType(Type* type);
virtual void accept(ASTVisitor *worker);
Type* type();
virtual const char* type();
Type* p_type();
virtual int num() {return 3;}
// virtual void marshal();
~PointerType(){printf("pointer type destructor\n");}
};
class ProjectionField : public Base
......@@ -128,10 +133,12 @@ class ProjectionType : public Type // complex type
public:
ProjectionType(const char* id, const char* real_type, std::vector<ProjectionField*>* fields);
virtual void accept(ASTVisitor *worker);
virtual const char* type();
const char* id();
const char* real_type();
virtual int num() {return 4;}
// virtual void marshal();
~ProjectionType(){printf("projection type destructor\n");}
};
class Parameter : public Base
......@@ -144,8 +151,8 @@ class Parameter : public Base
virtual void accept(ASTVisitor *worker);
Type* type();
const char* name();
char* marshal();
char* unmarshal();
const char* marshal();
const char* unmarshal();
};
class Rpc : public Base
......
#ifndef MARSHAL_OP
#define MARSHAL_OP
#ifndef MARSHAL_OP_H
#define MARSHAL_OP_H
#define LCD_MAX_REGS 64
#define LCD_MAX_CAP_REGS 8
#include <stdlib.h>
class M_info
{
public:
size_t size_;
};
class M_rpc : public M_info
{
bool regs[LCD_MAX_REGS];
bool cap_regs[LCD_MAX_CAP_REGS];
int* regs;
int* cap_regs;
public:
M_rpc();
int allocate_register(int reg);
int next_free_register();
void init();
};
class M_type : public M_info
......@@ -25,4 +31,7 @@ class M_type : public M_info
public:
M_type();
void set_size(size_t s);
void set_register(int reg);
};
#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