From: Francis Russell Date: Tue, 10 Apr 2012 09:55:07 +0000 (+0100) Subject: Add if statement generation. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=d5807b8ccea36d55ff110cfe805b673200de411a;p=francis%2Fofc.git Add if statement generation. --- diff --git a/src/ofc/codegen/FortranGenerator.scala b/src/ofc/codegen/FortranGenerator.scala index 3524a29..f424243 100644 --- a/src/ofc/codegen/FortranGenerator.scala +++ b/src/ofc/codegen/FortranGenerator.scala @@ -142,6 +142,7 @@ class FortranGenerator { case (x : ProducerStatement) => processStatement(x.toConcrete) case (x : ForLoop) => processForLoop(x) case (a : Assignment) => processAssignment(a) + case (i : IfStatement) => processIf(i) case x => throw new UnimplementedException("Unknown statement type in FORTRAN generator: " + x.toString) } } @@ -245,6 +246,14 @@ class FortranGenerator { addLine("%s = %s".format(buildExpression(assignment.getLHS), buildExpression(assignment.getRHS))) } + private def processIf(ifStatement: IfStatement) { + addLine("if (%s) then".format(buildExpression(ifStatement.getPredicate))) + in + processScope(ifStatement) + out + addLine("endif") + } + private def addLine(line: String) { buffer += " "*indentLevel + line } diff --git a/src/ofc/codegen/IfStatement.scala b/src/ofc/codegen/IfStatement.scala index 84ae5b0..2c97a53 100644 --- a/src/ofc/codegen/IfStatement.scala +++ b/src/ofc/codegen/IfStatement.scala @@ -1,3 +1,5 @@ package ofc.codegen -class IfStatement(predicate: Expression[BoolType]) extends ScopeStatement +class IfStatement(predicate: Expression[BoolType]) extends ScopeStatement { + def getPredicate : Expression[BoolType] = predicate +}