Skip to content

Commit

Permalink
Merge pull request #4 from bastianhagedorn/paternoster
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
mheine94 authored Mar 11, 2018
2 parents fbfe872 + 16d2b67 commit 78e91fd
Show file tree
Hide file tree
Showing 19 changed files with 1,376 additions and 302 deletions.
2 changes: 2 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[submodule "lib/ArithExpr"]
path = lib/ArithExpr
url = https://github.com/lift-project/arithexpr.git


3 changes: 3 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ libraryDependencies += "org.clapper" %% "argot" % "1.0.3"
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.1.7"
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.4.0"

// https://mvnrepository.com/artifact/org.jfree/jfreesvg
libraryDependencies += "org.jfree" % "jfreesvg" % "2.0"

scalacOptions in (Compile,doc) := Seq("-implicits", "-diagrams")

// Build ArithExpr
Expand Down
2 changes: 1 addition & 1 deletion lib/ArithExpr
2 changes: 1 addition & 1 deletion src/main/c/generator/CGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ class CGenerator extends Generator {
case l: Lambda => generateExpr(l.body, block)
case Unzip() | Transpose() | TransposeW() | asVector(_) | asScalar() |
Split(_) | Join() | Slide(_, _) | Zip(_) | Tuple(_) | Filter() |
Head() | Tail() | Scatter(_) | Gather(_) | Get(_) | Pad(_, _, _) =>
Head() | Tail() | Scatter(_) | Gather(_) | Get(_) | Pad(_, _, _) | PrintType(_,_,_) =>

}
case v: Value => generateValue(v, block)
Expand Down
2 changes: 1 addition & 1 deletion src/main/c/generator/InferOpenCLAddressSpace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ object InferOpenCLAddressSpace {

case Unzip() | Zip(_) | Transpose() | TransposeW() | asVector(_) |
asScalar() | Split(_) | Join() | Scatter(_) | Gather(_) |
Pad(_,_,_) | Tuple(_) | Slide(_,_) | Head() | Tail() =>
Pad(_,_,_) | Tuple(_) | Slide(_,_) | Head() | Tail() | PrintType(_,_,_) =>

setAddressSpaceDefault(addressSpaces)

Expand Down
4 changes: 2 additions & 2 deletions src/main/ir/ast/PrintType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import utils.paternoster.gui.TypeVisualizer
* Identity function that prints the Lift type of its input.
* Generates no OpenCL code.
*/
case class PrintType(visual: Boolean = false, render: Boolean = false) extends Pattern(arity = 1) {
case class PrintType(visual: Boolean = false, render: Boolean = false,expression:String = "") extends Pattern(arity = 1) {
override def checkType(argType: Type,
setType: Boolean): Type = {

if(visual){
TypeVisualizer(argType,render)
TypeVisualizer(argType,render,expression)
}else{
println(argType.toString)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/ir/view/InputView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ object InputView {
case Pad(left, right,boundary) => buildViewPad(left, right, boundary, argView)
case PadConstant(left, right, value) => buildViewPadConstant(left, right, value, argView)
case ArrayAccess(i) => argView.access(i)
case PrintType(_,_) | Scatter(_) | _: Tuple | Pad(_, _, _) | Id() => argView
case PrintType(_,_,_) | Scatter(_) | _: Tuple | Pad(_, _, _) | Id() => argView
case dunno => throw new NotImplementedError(s"inputView.scala: $dunno")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/ir/view/OutputView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object OutputView {
View.initialiseNewView(call.args.head.t, call.args.head.inputDepth, call.args.head.mem.variable)
case _: ArrayAccess | _: UnsafeArrayAccess | _ : CheckedArrayAccess =>
View.initialiseNewView(call.args.head.t, call.args.head.inputDepth, call.args.head.mem.variable)
case PrintType(_,_) | Get(_) | _: Tuple | Gather(_) | Filter() |
case PrintType(_,_,_) | Get(_) | _: Tuple | Gather(_) | Filter() |
Pad(_, _, _) | PadConstant(_, _, _) | Id() =>
writeView
case dunno => throw new NotImplementedError(s"OutputView.scala: $dunno")
Expand Down
2 changes: 1 addition & 1 deletion src/main/opencl/generator/OpenCLGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ class OpenCLGenerator extends Generator {
case Unzip() | Transpose() | TransposeW() | asVector(_) | asScalar() |
Split(_) | Join() | Slide(_, _) | Zip(_) | Tuple(_) | Filter() |
Head() | Tail() | Scatter(_) | Gather(_) | Get(_) | Pad(_, _, _) | PadConstant(_, _, _) |
ArrayAccess(_) | PrintType(_,_) =>
ArrayAccess(_) | PrintType(_,_,_) =>
case _ => (block: Block) += OpenCLAST.Comment("__" + call.toString + "__")
}
case v: Value => generateValue(v, block)
Expand Down
2 changes: 1 addition & 1 deletion src/main/opencl/ir/InferOpenCLAddressSpace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object InferOpenCLAddressSpace {

case Unzip() | Zip(_) | Transpose() | TransposeW() | asVector(_) |
asScalar() | Split(_) | Join() | Scatter(_) | Gather(_) |
Pad(_,_,_) | PadConstant(_, _, _) | Tuple(_) | Slide(_,_) | Head() | Tail() | PrintType(_,_) |
Pad(_,_,_) | PadConstant(_, _, _) | Tuple(_) | Slide(_,_) | Head() | Tail() | PrintType(_,_,_) |
UnsafeArrayAccess(_) | CheckedArrayAccess(_) | ArrayAccess(_) | Id() =>

setAddressSpaceDefault(addressSpaces)
Expand Down
2 changes: 1 addition & 1 deletion src/main/opencl/ir/OpenCLMemoryAllocator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ object OpenCLMemoryAllocator {

case Split(_) | Join() | asVector(_) | asScalar() |
Transpose() | Unzip() | TransposeW() | Slide(_, _) | Pad(_, _, _) | PadConstant(_, _, _) |
Head() | Tail() | Gather(_) | Scatter(_) | ArrayAccess(_) | PrintType(_,_) | Id() =>
Head() | Tail() | Gather(_) | Scatter(_) | ArrayAccess(_) | PrintType(_,_,_) | Id() =>
inMem
}
}
Expand Down
228 changes: 208 additions & 20 deletions src/main/utils/paternoster/gui/JavaFXRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ import javafx.scene.canvas.GraphicsContext
import javafx.scene.paint.Color
import javafx.scene.text.{Font, Text}

import lift.arithmetic.?
import utils.paternoster.logic.Graphics._
import utils.paternoster.logic.Scene.GridArrayNode

/**
* Created by Federico on 18-Aug-17.
*/
object JavaFXRenderer {
case class Context(gc:GraphicsContext, unitX:Double, unitY:Double, smallX:Double, smallY:Double, width:Double,height:Double)
case class Context(gc:GraphicsContext, unitX:Double, unitY:Double, smallX:Double, smallY:Double, numberFont :Font , expressionFont: Font , width:Double,height:Double)

def drawPrimitives(primitives:Iterable[GraphicalPrimitive], ctx:Context) ={
def drawPrimitives(primitives:Iterable[GraphicalPrimitive], ctx:Context):Unit ={
var newContext = adjustScaling(primitives,ctx)
newContext = adjustCanvas(primitives,newContext)
ctx.gc.clearRect(0, 0, newContext.width, newContext.height)
ctx.gc.setFill(Color.WHITE)
ctx.gc.fillRect(0,0,newContext.width,newContext.height)
primitives.foreach(drawPrimitive(_, newContext))
}

Expand All @@ -25,9 +31,11 @@ object JavaFXRenderer {
var maxheight = 0d
var minScaledHeight = 1000d
var maxScaledHeight = 0d
val MAXSCALING = 3
val MINSCALING = 1

primitives.foreach(primitive =>primitive match {
case BoxWithText(text, tx, ty, bx, by, bwidth, bheight) => {
case BoxWithText(text, bx, by, bwidth, bheight) => {
val currentScaledWidth = bwidth * ctx.unitX - 2 * ctx.smallX
if ((currentScaledWidth) > maxScaledWidth) {
maxScaledWidth = currentScaledWidth
Expand All @@ -43,23 +51,143 @@ object JavaFXRenderer {
maxheight = bheight
}
}
case Box(x, y, w, h) => {
val currentScaledWidth = w * ctx.unitX - 2 * ctx.smallX
if ((currentScaledWidth) > maxScaledWidth) {
maxScaledWidth = currentScaledWidth
maxwidth = w
}
val currentScaledHeight = h * ctx.unitY - 2 * ctx.smallY
if ((currentScaledHeight) < minScaledHeight) {
minScaledHeight = currentScaledHeight
minheight = h
}
if ((currentScaledHeight) > maxScaledHeight) {
maxScaledHeight = currentScaledHeight
maxheight = h
}
}
case CorneredClause(x, y, w, h) => {
val currentScaledWidth = w * ctx.unitX - 2 * ctx.smallX
if ((currentScaledWidth) > maxScaledWidth) {
maxScaledWidth = currentScaledWidth
maxwidth = w
}
val currentScaledHeight = h * ctx.unitY - 2 * ctx.smallY
if ((currentScaledHeight) < minScaledHeight) {
minScaledHeight = currentScaledHeight
minheight = h
}
if ((currentScaledHeight) > maxScaledHeight) {
maxScaledHeight = currentScaledHeight
maxheight = h
}
}

case _:Any =>
})

val newXScaling = (ctx.width-2*ctx.smallX)/maxwidth
var newYScaling = newXScaling*0.5
if(minScaledHeight < (ctx.height*0.5)){
newYScaling = (ctx.height*0.08- 2*ctx.smallY)/(minheight)
val newXScaling = Math.round(Math.max(MINSCALING,Math.min((ctx.width-2*ctx.smallX)/maxwidth, MAXSCALING)))
var newYScaling = Math.round(Math.max(MINSCALING,newXScaling*0.5))

Context(ctx.gc, 6, 6, ctx.smallX, ctx.smallY,ctx.numberFont,ctx.expressionFont,ctx.width,ctx.height)

}

def adjustCanvas(primitives:Iterable[GraphicalPrimitive],ctx:Context): Context ={
var maxWidth=0.0
var maxHeight=0.0
primitives.foreach(primitive=> primitive match {
case BoxWithText(_,x,y,w,h) => {
val width = x+w
val height = y+h
if(width > maxWidth) maxWidth=width
if(height > maxHeight) maxHeight = height
}
case Box(x,y,w,h)=> {
val width = x+w
val height = y+h
if(width > maxWidth) maxWidth=width
if(height > maxHeight) maxHeight = height
}
case CorneredClause(x,y,w,h)=> {
val width = x+w
val height = y+h
if(width > maxWidth) maxWidth=width
if(height > maxHeight) maxHeight = height
}
val yPercentSmaller = newYScaling/defaultYScaling
val newFontSize = Math.max(ctx.gc.getFont.getSize*yPercentSmaller,10)
ctx.gc.setFont(new Font(newFontSize))
Context(ctx.gc, newXScaling, newYScaling, ctx.smallX, ctx.smallY,ctx.width,ctx.height)
case Rectangle(x,y,w,h)=> {
val width = x+w
val height = y+h
if(width > maxWidth) maxWidth=width
if(height > maxHeight) maxHeight = height
}
case default =>
})

if(maxHeight*ctx.unitY > TypeVisualizer.getMainPane().height){
TypeVisualizer.getMainPane().setCanvasHeight(maxHeight*ctx.unitY)
}
if(maxWidth*ctx.unitX > TypeVisualizer.getMainPane().width){
TypeVisualizer.getMainPane().setCanvasWidth(maxWidth*ctx.unitX)
}
Context(TypeVisualizer.getMainPane().getGraphicsContext(), ctx.unitX, ctx.unitY, ctx.smallX, ctx.smallY,ctx.numberFont,ctx.expressionFont,TypeVisualizer.getMainPane().canvas.getWidth,TypeVisualizer.getMainPane().canvas.getHeight)
}

def drawPrimitive(primitive:GraphicalPrimitive, ctx: Context) = {

primitive match {
case BoxWithText(text,tx,ty,bx,by,bwidth,bheight)=>
case DashedBox(x,y,w,h)=>
ctx.gc.setLineDashes(2)
ctx.gc.setLineDashOffset(1)
ctx.gc.setFont(ctx.numberFont)
ctx.gc.setFill(Color.GREY)
ctx.gc.strokeRect(
x*ctx.unitX + ctx.smallX,
y*ctx.unitY + ctx.smallY,
w*ctx.unitX - 2*ctx.smallX,
h*ctx.unitY - 2*ctx.smallY
)

case ExpressionSource(text,begin,end, x,y)=>
ctx.gc.setLineDashes()
ctx.gc.setFont(ctx.expressionFont)

var beforeHightLightText = text.substring(0,begin)
var highLightText = text.substring(begin, end+1)
var afterHighLightText = text.substring(end+1,text.length)

var beforeHightLight = new Text(beforeHightLightText)
var highLight = new Text(highLightText)
var afterHighLight = new Text(afterHighLightText)
beforeHightLight.setFont(ctx.expressionFont)
highLight.setFont(ctx.expressionFont)
afterHighLight.setFont(ctx.expressionFont)

var beforeLength = beforeHightLight.getLayoutBounds.getWidth
var highLightLength = highLight.getLayoutBounds.getWidth
var afterLength = afterHighLight.getLayoutBounds.getWidth

//Paint text before highlighting
ctx.gc.strokeText(beforeHightLightText,
x,
y*ctx.unitY + ctx.smallY)

//Paint highlighted text
ctx.gc.setStroke(Color.RED)
ctx.gc.strokeText(highLightText,
(x+beforeLength),
y*ctx.unitY + ctx.smallY)

//Paint text after highlighting
ctx.gc.setStroke(Color.BLACK)
ctx.gc.strokeText(afterHighLightText,
(x+beforeLength+highLightLength),
y*ctx.unitY + ctx.smallY)

case BoxWithText(text,bx,by,bwidth,bheight)=>
ctx.gc.setLineDashes()
ctx.gc.setFont(ctx.numberFont)
ctx.gc.setFill(Color.BLACK)
ctx.gc.strokeRect(
bx*ctx.unitX + ctx.smallX,
Expand All @@ -68,19 +196,79 @@ object JavaFXRenderer {
bheight*ctx.unitY - 2*ctx.smallY
)


val textX = ((bx*ctx.unitX + ctx.smallX)+(bwidth*ctx.unitX - 2*ctx.smallX))-Math.min((ctx.gc.getFont.getSize*text.size),(bwidth*ctx.unitX - 2*ctx.smallX)/2)
val textY = ((by*ctx.unitY + ctx.smallY)+(bheight*ctx.unitY - 2*ctx.smallY))-((bheight*ctx.unitY - 2*ctx.smallY)*0.025)
val textX = ((bx*ctx.unitX + ctx.smallX)+(bwidth*ctx.unitX - 2*ctx.smallX))-(ctx.gc.getFont.getSize*text.size)/*Math.min((ctx.gc.getFont.getSize*text.size),(bwidth*ctx.unitX - 2*ctx.smallX)/2)*/
val textY = ((by*ctx.unitY + ctx.smallY)+(bheight*ctx.unitY - 2*ctx.smallY)) /*((by*ctx.unitY + ctx.smallY)+(bheight*ctx.unitY - 2*ctx.smallY))-((bheight*ctx.unitY - 2*ctx.smallY)*0.025)*/
//ctx.gc.setFont(new Font(ctx.gc.getFont.getName,10))
ctx.gc.strokeText(text,textX,textY)
case Rectangle(x, y, w, h) =>
ctx.gc.setFill(Color.GREEN)
ctx.gc.setLineDashes()
ctx.gc.setFont(ctx.numberFont)
ctx.gc.setFill(Color.DARKGREEN)
ctx.gc.fillRect(
x*ctx.unitX + ctx.smallX*2,
y*ctx.unitY + ctx.smallY*2,
w*ctx.unitX - 4*ctx.smallX,
h*ctx.unitY - 4*ctx.smallY)
Math.round(x*ctx.unitX + ctx.smallX*4),
Math.round(y*ctx.unitY + ctx.smallY*4),
Math.round(w*ctx.unitX - 2*ctx.smallX),
Math.round(h*ctx.unitY - 2*ctx.smallY))
case CorneredClause(x, y, w, h) =>
ctx.gc.setLineDashes()
ctx.gc.setFont(ctx.numberFont)
ctx.gc.setFill(Color.BLACK)
//Left line
ctx.gc.strokeLine(
x*ctx.unitX + ctx.smallX,
y*ctx.unitY + ctx.smallY,
x*ctx.unitX + ctx.smallX,
(y*ctx.unitY + ctx.smallY)+(h*ctx.unitY - 2*ctx.smallY)
)
//Left upper corner
ctx.gc.strokeLine(
x*ctx.unitX + ctx.smallX,
y*ctx.unitY + ctx.smallY,
x*ctx.unitX + ctx.smallX+(2),
y*ctx.unitY + ctx.smallY
)
//Left lower corner
ctx.gc.strokeLine(
x*ctx.unitX + ctx.smallX,
(y*ctx.unitY + ctx.smallY)+(h*ctx.unitY - 2*ctx.smallY),
x*ctx.unitX + ctx.smallX+(2),
(y*ctx.unitY + ctx.smallY)+(h*ctx.unitY - 2*ctx.smallY)
)

//Right line
ctx.gc.strokeLine(
(x*ctx.unitX + ctx.smallX)+(w*ctx.unitX - 2*ctx.smallX),
y*ctx.unitY + ctx.smallY,
(x*ctx.unitX + ctx.smallX)+(w*ctx.unitX - 2*ctx.smallX),
(y*ctx.unitY + ctx.smallY)+(h*ctx.unitY - 2*ctx.smallY)
)
//Right upper corner
ctx.gc.strokeLine(
(x*ctx.unitX + ctx.smallX)+(w*ctx.unitX - 2*ctx.smallX),
y*ctx.unitY + ctx.smallY,
(x*ctx.unitX + ctx.smallX)+(w*ctx.unitX - 2*ctx.smallX)-(2),
y*ctx.unitY + ctx.smallY
)
//Right lower corner
ctx.gc.strokeLine(
(x*ctx.unitX + ctx.smallX)+(w*ctx.unitX - 2*ctx.smallX),
(y*ctx.unitY + ctx.smallY)+(h*ctx.unitY - 2*ctx.smallY),
(x*ctx.unitX + ctx.smallX)+(w*ctx.unitX - 2*ctx.smallX)-(2),
(y*ctx.unitY + ctx.smallY)+(h*ctx.unitY - 2*ctx.smallY)
)
case Seperator(x,y)=>{
ctx.gc.setLineDashes()
ctx.gc.setFont(ctx.numberFont)
ctx.gc.setFill(Color.BLACK)
ctx.gc.strokeLine(
x*ctx.unitX + ctx.smallX,
y*ctx.unitY + ctx.smallY,
x*ctx.unitX + ctx.smallX,
y*ctx.unitY + ctx.smallY-(2))
}
case Box(x, y, w, h) =>
ctx.gc.setLineDashes()
ctx.gc.setFont(ctx.numberFont)
ctx.gc.setStroke(Color.RED)
ctx.gc.strokeRect(
x*ctx.unitX + ctx.smallX,
Expand Down
Loading

0 comments on commit 78e91fd

Please sign in to comment.