Open rdaly525 opened 6 years ago
@leonardt, want to do a mini design review of this with me some time this week? The goal is to create a very simple Type language which can be stored/executed symbolically (and therefore serializable). This could alleviate the need to run python code for typegens.
http://www.drdobbs.com/cpp/the-spirit-parser-library-inline-parsing/184401692
If I wanted to actually have a parseable language, this seems like a great C++ tool to do it. This way I could simply pass around the typegen as a string representing the code.
Here is a small example of how I would imagine creating this in coreir.
Context* c = newContext();
Namespace* g = c->getGlobal();
Params params({{"width",c->Int()}});
SymTypeGen* tg = SymTypeGen::make(g,"unary",params);
tg->addStmt(Assign::make(tg,"w",Arg::make(tg,"width")));
Value* inArr = Ops::Array::make(tg,Var::make(tg,"w"),Const::make(c,c->BitIn()));
Value* outArr = Ops::Flip::make(tg,Var::make(tg,"inArr"));
tg->addStmt(Assign::make(tg,"inArr",inArr);
tg->addStmt(Assign::make(tg,"outArr",outArr);
tg->addStmt(Assign::make(tg,"finalType",Record::make(tg,
"in",Var::make(tg,"inArr"), Const::make(c,true),
"out",Var::make(tg,"outArr"), Const::make(c,true)
)));
tg->addStmt(Return::make(tg,Var(tg,"finalType")));
Also here is an example of some potential future syntax for the language itself.
Type function unary(int width) {
int w = width;
Type inArr = Array(w,BitIn);
Type outArr = Flip(inArr);
Type finalType = Record(
in : (inArr,true)
out : (outArr,true)
);
return finalType;
}
Type function unary_with_en(int width, bool has_en) {
int w = width;
Type inArr = Array(w,BitIn);
Type outArr = Flip(inArr);
Type final = Record(
in : (inArr,true),
out : (outArr,true),
en : (BitIn,has_en),
);
return final;
}