Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower functions to FuTIL's invoke. #340

Merged
merged 46 commits into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a7769ed
Initial commit.
cgyurgyik Dec 28, 2020
9c54b88
Remove comment.
cgyurgyik Dec 28, 2020
9a3ba87
Use control!
cgyurgyik Dec 29, 2020
b22bad1
Progress
cgyurgyik Dec 30, 2020
2c50f04
Add signatures for invoked components.
cgyurgyik Dec 31, 2020
f4cd30a
Add TODOs to remove sqrt, exp.
cgyurgyik Dec 31, 2020
44083d3
Capital F.
cgyurgyik Dec 31, 2020
23bb273
Compile both void and returns.
cgyurgyik Dec 31, 2020
f8b5cf6
Add TODO for functionStore.
cgyurgyik Dec 31, 2020
6b74115
Working version with Enumeration. Next: Change to sealed trait.
cgyurgyik Jan 1, 2021
3b1aca3
Use sealed trait.
cgyurgyik Jan 1, 2021
7da63d8
Update comment.
cgyurgyik Jan 1, 2021
2abdb2e
Add comment.
cgyurgyik Jan 1, 2021
8ac8d3d
Add test.
cgyurgyik Jan 1, 2021
6a5815d
Merge branch 'master' into invoke
cgyurgyik Jan 1, 2021
7fb6362
Scala 3 objections.
cgyurgyik Jan 1, 2021
d6caa3b
WS
cgyurgyik Jan 1, 2021
48a3e2c
Update.
cgyurgyik Jan 1, 2021
795f840
Comments.
cgyurgyik Jan 1, 2021
df8c54a
Consistent of param vs arg.
cgyurgyik Jan 1, 2021
056af9a
Remove mutable data structure.
cgyurgyik Jan 1, 2021
3c7cf99
Shorter name.
cgyurgyik Jan 1, 2021
73c259c
Add return structure.
cgyurgyik Jan 1, 2021
12db28c
Add error for functions not assigned to let statement.
cgyurgyik Jan 1, 2021
dee4837
names
cgyurgyik Jan 1, 2021
72ef29f
namesagain
cgyurgyik Jan 1, 2021
15fbdda
NAMES
cgyurgyik Jan 1, 2021
372d564
Add todo.
cgyurgyik Jan 1, 2021
43156c5
Remove for now.
cgyurgyik Jan 1, 2021
6795524
Add underscore.
cgyurgyik Jan 1, 2021
36bf005
Add eg
cgyurgyik Jan 1, 2021
ed2a006
Add error message for memory params
cgyurgyik Jan 6, 2021
3213bd1
Merge branch 'master' into invoke
cgyurgyik Jan 28, 2021
bc09799
External.
cgyurgyik Jan 28, 2021
c1ebb37
Imports part 1
cgyurgyik Jan 28, 2021
3675547
Add import.
cgyurgyik Jan 28, 2021
f88908f
Update expected.
cgyurgyik Jan 28, 2021
dd0f45d
scala fmt
rachitnigam Jan 30, 2021
f0262ed
unnecessary check
rachitnigam Jan 30, 2021
8eb3ff6
group that reads from invoke runs in sequence
rachitnigam Jan 30, 2021
b97528f
return is a vim keyword
rachitnigam Jan 30, 2021
aebeec1
dont reimplement the same function;
rachitnigam Jan 30, 2021
12df06b
construct structure generated from arguments to functions
rachitnigam Jan 30, 2021
2836e0b
Merge branch 'master' into invoke
rachitnigam Jan 30, 2021
8b242fb
unify LibDecl and CompDecl into Cell
rachitnigam Jan 30, 2021
55a94f2
update polybench to use invokeable sqrt
rachitnigam Jan 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions file-tests/should-futil/invoke.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import "primitives/std.lib";
import "primitives/std.lib";
component foo(a: 32) -> (out: 32) {
cells {
temp_0 = std_reg(32);
}
wires {
group let3<"static"=1> {
temp_0.in = a;
temp_0.write_en = 1'd1;
let3[done] = temp_0.done;
}
out = temp_0.out;
}
control {
let3;
}
}
component main() -> () {
cells {
b_0 = std_reg(32);
c_0 = std_reg(32);
const0 = std_const(32,1);
d_0 = std_reg(32);
foo0 = foo();
std_sqrt0 = std_sqrt();
}
wires {
group let0<"static"=1> {
b_0.in = const0.out;
b_0.write_en = 1'd1;
let0[done] = b_0.done;
}
group let1 {
c_0.in = foo0.out;
c_0.write_en = 1'd1;
let1[done] = c_0.done;
}
group let2 {
d_0.in = std_sqrt0.out;
d_0.write_en = 1'd1;
let2[done] = d_0.done;
}
}
control {
seq {
let0;
invoke foo0(a=b_0.out)();
let1;
invoke std_sqrt0(in=c_0.out)();
let2;
}
}
}
10 changes: 10 additions & 0 deletions file-tests/should-futil/invoke.fuse
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import futil("primitives/std.lib") { def std_sqrt(in: ubit<32>): ubit<32>; }

def foo(a: ubit<32>): ubit<32> = {
let temp: ubit<32> = a;
return temp;
}

let b: ubit<32> = (1 as ubit<32>);
let c: ubit<32> = foo(b);
let d: ubit<32> = std_sqrt(c);
49 changes: 25 additions & 24 deletions src/main/scala/backends/futil/FutilAst.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Futil {
def emitCompStructure(structs: List[Structure]): Doc = {
val (cells, connections) = structs.partition(st =>
st match {
case _: LibDecl | _: CompDecl => true
case _: Cell => true
case _ => false
}
)
Expand All @@ -31,7 +31,7 @@ object Futil {
}
}
case class PortDef(id: CompVar, width: Int) extends Emitable {
override def doc(): Doc = parens(text("port") <+> id.doc() <+> value(width))
override def doc(): Doc = id.doc() <> colon <+> value(width)
}

/**** definition statements *****/
Expand All @@ -48,9 +48,9 @@ object Futil {
case Component(name, inputs, outputs, structure, control) => {
text("component") <+>
text(name) <>
parens(hsep(inputs.map(_.doc()))) <+>
parens(commaSep(inputs.map(_.doc()))) <+>
text("->") <+>
parens(hsep(outputs.map(_.doc()))) <+>
parens(commaSep(outputs.map(_.doc()))) <+>
scope(
emitCompStructure(structure) <@>
text("control") <+> scope(control.doc())
Expand Down Expand Up @@ -102,11 +102,9 @@ object Futil {

sealed trait Structure extends Emitable with Ordered[Structure] {
override def doc(): Doc = this match {
case CompDecl(id, comp) =>
id.doc() <+> equal <+> comp.doc() <> text("()") <> semi
case LibDecl(id, comp, true) =>
case Cell(id, comp, true) =>
text("@external(1)") <+> id.doc() <+> equal <+> comp.doc() <> semi
case LibDecl(id, comp, false) =>
case Cell(id, comp, false) =>
id.doc() <+> equal <+> comp.doc() <> semi
case Connect(src, dest, Some(guard)) =>
dest.doc() <+> equal <+> guard.doc() <+> text("?") <+> src.doc() <> semi
Expand All @@ -123,9 +121,7 @@ object Futil {

def compare(that: Structure): Int = {
(this, that) match {
case (LibDecl(thisId, _, _), LibDecl(thatId, _, _)) =>
thisId.compare(thatId)
case (CompDecl(thisId, _), CompDecl(thatId, _)) =>
case (Cell(thisId, _, _), Cell(thatId, _, _)) =>
thisId.compare(thatId)
case (Group(thisId, _, _), Group(thatId, _, _)) =>
thisId.compare(thatId)
Expand All @@ -136,18 +132,15 @@ object Futil {
thisSrc.compare(thatSrc)
}
}
case (LibDecl(_, _, _), _) => -1
case (_, LibDecl(_, _, _)) => 1
case (CompDecl(_, _), _) => -1
case (_, CompDecl(_, _)) => 1
case (Cell(_, _, _), _) => -1
case (_, Cell(_, _, _)) => 1
case (Group(_, _, _), _) => -1
case (_, Group(_, _, _)) => 1
}
}
}
case class LibDecl(id: CompVar, ci: CompInst, external: Boolean)
case class Cell(id: CompVar, ci: CompInst, external: Boolean)
extends Structure
case class CompDecl(id: CompVar, comp: CompVar) extends Structure
case class Group(
id: CompVar,
connections: List[Connect],
Expand All @@ -170,7 +163,6 @@ object Futil {
}
case class Connect(src: Port, dest: Port, guard: Option[GuardExpr] = None)
extends Structure

case class CompInst(id: String, args: List[Int]) extends Emitable {
override def doc(): Doc = {
val strList = args.map((x: Int) => text(x.toString()))
Expand Down Expand Up @@ -231,6 +223,16 @@ object Futil {
case Print(_) =>
throw Impossible("Futil does not support print")
case Enable(id) => id.doc() <> semi
case Invoke(id, arguments, parameters) => {
val argsDoc = arguments.map(p => p.doc())
val paramsDoc = parameters.map(decl => decl.doc())
val definitions = (paramsDoc zip argsDoc).map({
case (param, arg) => param <> equal <> arg
})
text("invoke") <+> id.doc() <> parens(commaSep(definitions)) <> text(
"()"
) <> semi
}
case Empty => text("empty")
}
}
Expand All @@ -241,6 +243,11 @@ object Futil {
case class While(port: Port, cond: CompVar, body: Control) extends Control
case class Print(id: CompVar) extends Control
case class Enable(id: CompVar) extends Control
case class Invoke(
id: CompVar,
arguments: List[Port],
parameters: List[CompVar]
) extends Control
case object Empty extends Control
}

Expand Down Expand Up @@ -320,12 +327,6 @@ object Stdlib {
)
)

def sqrt(): Futil.CompInst =
Futil.CompInst("std_sqrt", List())

def exp(): Futil.CompInst =
Futil.CompInst("std_exp", List())

// Extended AST to support fixed point constant and operations
def fixed_point(
width: Int,
Expand Down
Loading