Skip to content
Snippets Groups Projects
Commit 4feea45d authored by Aaron Councilman's avatar Aaron Councilman
Browse files

New scheduler syntax

parent 1c8a4869
No related branches found
No related tags found
No related merge requests found
......@@ -42,8 +42,11 @@ false "false"
/ "/"
% "%"
\|\| "||"
&& "&&"
\| "|"
:: "::"
\. "."
, ","
_ "_"
......@@ -51,7 +54,10 @@ _ "_"
\) ")"
\{ "{"
\} "}"
\| "|"
if "if"
on "on"
partition "partition"
[a-zA-Z][a-zA-Z0-9_]* "ID"
[0-9]+ "INT"
......
......@@ -3,57 +3,84 @@
%avoid_insert "ID" "INT" "HEX_INT" "BIN_INT" "OCT_INT" "LABEL"
%expect-unused Unmatched 'UNMATCHED'
%left '||'
%left '&&'
%nonassoc '==' '!=' '<' '<=' '>' '>='
%left '+' '-'
%left '*' '/' '%'
%%
Schedule -> Vec<Inst> : InstList { rev($1) };
Schedule -> Vec<Partition> : PartitionList { $1 };
InstList -> Vec<Inst>
PartitionList -> Vec<Partition>
: { vec![] }
| Instruction Schedule { cons($1, $2) }
| PartitionList Partition { snoc($1, $2) }
;
Instruction -> Inst : Base '.' Commands { Inst { span : $span, base : $1, commands : $3 }};
Partition -> Partition
: 'partition' Func '{' Labels '}' Directives
{ Partition { span : $span, func : $2, labels : $4, directs : $6 } };
Commands -> Vec<Command>
: Command { vec![$1] }
| '{' CommandList '}' { rev($2) }
Func -> Func
: 'ID' { Func { span : $span, name : $span, args : None }}
| 'ID' '::' '<' TypeExprs '>' { Func { span : $span, name : span_of_tok($1), args : Some($4) }}
;
CommandList -> Vec<Command>
Labels -> Vec<Span> : LabelsRev { rev($1) };
LabelsRev -> Vec<Span>
: { vec![] }
| Command { vec![$1] }
| Command ',' CommandList { cons($1, $3) }
| 'LABEL' { vec![span_of_tok($1)] }
| 'LABEL' ',' LabelsRev { cons(span_of_tok($1), $3) }
;
Command -> Command
: 'ID' { Command { span : $span, name : $span, args : vec![] }}
| 'ID' '(' Values ')' { Command { span : $span, name : span_of_tok($1), args : rev($3) }}
Directives -> Vec<Directive>
: { vec![] }
| Directives Directive { snoc($1, $2) }
;
Base -> Base
: Func { Base::Function { span : $span, func : $1 }}
| Func 'LABEL' { Base::Label { span : $span, func : $1, label : span_of_tok($2) }}
Directive -> Directive
: 'on' Device '{' Directives '}'
{ Directive::OnDevice { span : $span, device : $2, directs : $4 } }
| 'if' Expr '{' Directives '}'
{ Directive::IfExpr { span : $span, cond : $2, directs : $4 } }
| 'LABEL' '{' Commands '}'
{ Directive::Command { span : $span, label : span_of_tok($1), commands : $3 } }
;
Func -> Func
: 'ID' { Func { span : $span, name : $span, args : None }}
| 'ID' '::' '<' TypeVals '>' { Func { span : $span, name : span_of_tok($1), args : Some(rev($4)) }}
Device -> Device
: 'ID'
{ Device { span : $span, name : span_of_tok($1), args : vec![] } }
| 'ID' '(' Exprs ')'
{ Device { span : $span, name : span_of_tok($1), args : $3 } }
;
Values -> Vec<Expr>
Commands -> Vec<Command> : CommandsRev { rev($1) };
CommandsRev -> Vec<Command>
: { vec![] }
| Command { vec![$1] }
| Command ',' CommandsRev { cons($1, $3) }
;
Command -> Command
: 'ID'
{ Command { span : $span, name : span_of_tok($1), args : vec![] } }
| 'ID' '(' Exprs ')'
{ Command { span : $span, name : span_of_tok($1), args : $3 } }
;
Exprs -> Vec<Expr> : ExprsRev { rev($1) };
ExprsRev -> Vec<Expr>
: { vec![] }
| Expr { vec![$1] }
| Expr ',' Values { cons($1, $3) }
| Expr ',' ExprsRev { cons($1, $3) }
;
TypeVals -> Vec<TypExp>
TypeExprs -> Vec<TypExp> : TypeExprsRev { rev($1) };
TypeExprsRev -> Vec<TypExp>
: { vec![] }
| TypeExp { vec![$1] }
| TypeExp ',' TypeVals { cons($1, $3) }
| TypeExp ',' TypeExprsRev { cons($1, $3) }
;
Expr -> Expr
......@@ -75,6 +102,8 @@ Expr -> Expr
| Expr '<=' Expr { Expr::BinOp { span : $span, lhs : Box::new($1), op : BinOp::Le, rhs : Box::new($3) }}
| Expr '>' Expr { Expr::BinOp { span : $span, lhs : Box::new($1), op : BinOp::Gt, rhs : Box::new($3) }}
| Expr '>=' Expr { Expr::BinOp { span : $span, lhs : Box::new($1), op : BinOp::Ge, rhs : Box::new($3) }}
| Expr '&&' Expr { Expr::BinOp { span : $span, lhs : Box::new($1), op : BinOp::And, rhs : Box::new($3) }}
| Expr '||' Expr { Expr::BinOp { span : $span, lhs : Box::new($1), op : BinOp::Or, rhs : Box::new($3) }}
;
TypeExp -> TypExp
......@@ -93,7 +122,7 @@ TypeExp -> TypExp
| 'f32' { TypExp::Primitive { span : $span, typ : Primitive::F32 }}
| 'f64' { TypExp::Primitive { span : $span, typ : Primitive::F64 }}
| 'void' { TypExp::Primitive { span : $span, typ : Primitive::Void }}
| '(' TypeVals ')' { TypExp::Tuple { span : $span, elems : rev($2) }}
| '(' TypeExprs ')' { TypExp::Tuple { span : $span, elems : $2 }}
| '{' 'ID' '|' Expr '}' { TypExp::Set { span : $span, nm : span_of_tok($2), cond : $4 }}
;
......@@ -113,19 +142,26 @@ fn cons<A>(hd : A, mut tl : Vec<A>) -> Vec<A> {
tl
}
fn snoc<A>(mut hd : Vec<A>, tl : A) -> Vec<A> {
hd.push(tl);
hd
}
fn rev<A>(mut lst : Vec<A>) -> Vec<A> {
lst.reverse();
lst
}
pub struct Inst { pub span : Span, pub base : Base, pub commands : Vec<Command>, }
pub struct Command { pub span : Span, pub name : Span, pub args : Vec<Expr>, }
pub struct Partition {
pub span : Span,
pub func : Func,
pub labels : Vec<Span>,
pub directs : Vec<Directive>,
}
pub struct Func { pub span : Span, pub name : Span, pub args : Option<Vec<TypExp>>, }
pub struct Device { pub span : Span, pub name : Span, pub args : Vec<Expr>, }
pub struct Command { pub span : Span, pub name : Span, pub args : Vec<Expr>, }
pub enum Base {
Function { span : Span, func : Func },
Label { span : Span, func : Func, label : Span },
}
pub enum Expr {
Id { span : Span },
Int { span : Span, base : IntBase },
......@@ -139,7 +175,12 @@ pub enum TypExp {
Tuple { span : Span, elems : Vec<TypExp> },
Set { span : Span, nm : Span, cond : Expr },
}
pub enum Directive {
OnDevice { span : Span, device : Device, directs : Vec<Directive> },
IfExpr { span : Span, cond : Expr, directs : Vec<Directive> },
Command { span : Span, label : Span, commands : Vec<Command> },
}
pub enum IntBase { Bin, Oct, Dec, Hex }
pub enum BinOp { Add, Sub, Mul, Div, Mod, Eq, Ne, Lt, Le, Gt, Ge }
pub enum BinOp { Add, Sub, Mul, Div, Mod, Eq, Ne, Lt, Le, Gt, Ge, And, Or }
pub enum Primitive { Bool, I8, I16, I32, I64, U8, U16, U32, U64, USize, F32, F64, Void }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment