Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
244 changes: 244 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
project/target
project/.bloop/
project/metals.sbt
project/project/*
target
.env
.jvmopts
.sbtopts
.metals/
.vscode/
*/.bloop/
.bloop/

# Created by https://www.gitignore.io/api/java,linux,macos,scala,eclipse,intellij+all
# Edit at https://www.gitignore.io/?templates=java,linux,macos,scala,eclipse,intellij+all

### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# CDT- autotools
.autotools

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

# Annotation Processing
.apt_generated/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet

### Eclipse Patch ###
# Eclipse Core
.project

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Annotation Processing
.apt_generated

.sts4-cache/

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

# JetBrains templates
**___jb_tmp___

### Intellij+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

.idea/

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr

# Sonarlint plugin
.idea/sonarlint

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Scala ###
.bsp

# End of https://www.gitignore.io/api/java,linux,macos,scala,eclipse,intellij+all
2 changes: 0 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ scalaVersion := "2.13.6"

libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.0" % "test"
libraryDependencies += "org.scalatest" %% "scalatest-featurespec" % "3.2.0" % "test"

libraryDependencies += "org.scala-graph" %% "graph-core" % "1.13.2"
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.5.4
82 changes: 82 additions & 0 deletions src/main/scala/br/unb/cic/wlang/AvailableExpression.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package br.unb.cic.wlang

import br.unb.cic.wlang.CFGBuilder._
import br.unb.cic.wlang.WhileProgram._

object AvailableExpression {
def process(program: WhileProgram): Abstraction = {
val bottom = nonTrivialExpressions(program)
val initialExit =
labels(program).foldLeft(Map[Int, Set[AExp]]()) { (m, label) => m + (label -> bottom) }

val abstraction = Abstraction(Map.empty, initialExit)
process(program, abstraction)
}

private def process(program: WhileProgram, abstraction: Abstraction): Abstraction = {
val (newAbstraction, continue) = iterate(labels(program), program, abstraction)
if (continue) {
process(program, newAbstraction)
} else {
newAbstraction
}
}

private def iterate(labels: Set[Int], program: WhileProgram, abstraction: Abstraction): (Abstraction, Boolean) = {
val newAbstraction = labels.foldLeft(abstraction) { (abstraction, label) => {
val newAbstractionForLabel = generateNewAbstractionForLabel(label, program,abstraction)
val newEntry = newAbstractionForLabel._1
val newExit = newAbstractionForLabel._2
Abstraction(abstraction.entry + newEntry, abstraction.exit + newExit)
}
}
(newAbstraction, abstraction != newAbstraction)
}
private def generateNewAbstractionForLabel(label: Int, program: WhileProgram, abstraction: Abstraction): ((Int, Set[AExp]), (Int, Set[AExp])) = {
val entry = generateEntry(label, program, abstraction)
val exit = generateExit(label, program, Map(label -> entry))
(label -> entry, label -> exit)
}

private def kill(block: Block, nonTrivialExpressions: Set[AExp]): Set[AExp] = block match {
case Assignment(name, _, _) => nonTrivialExpressions.filter(exp => expHasVariable(name, exp))
case Skip(_) => Set.empty
case Condition(_, _) => Set.empty
}

private def gen(block: Block): Set[AExp] = block match {
case Assignment(name, exp, _) => nonTrivialExpressions(exp).filterNot(exp => expHasVariable(name, exp))
case Skip(_) => Set.empty
case Condition(exp, _) => nonTrivialExpressions(exp)
}

private def expHasVariable(name: String, exp: AExp): Boolean = exp match {
case Var(n) => n == name
case Const(_) => false
case OpArith(_, a1, a2) => expHasVariable(name, a1) || expHasVariable(name, a2)
}

private def generateExit(label: Int, program: WhileProgram, entry: Map[Int, Set[AExp]]) = {
val calculatedBlock = block(label, program.stmt).get
val nonTrivialExpressions = WhileProgram.nonTrivialExpressions(program)
val exit =
(entry(label) diff kill(calculatedBlock, nonTrivialExpressions)) union gen(calculatedBlock)
exit
}

private def generateEntry(label: Int, program: WhileProgram, abstraction: Abstraction): Set[AExp] = {

if (label == initLabel(program.stmt)) {
Set.empty
} else {
val sets = (for {
(from, to) <- flow(program.stmt)
if to == label
} yield abstraction.exit(from)).toList
sets.foldLeft[Set[AExp]](nonTrivialExpressions(program))((s1,s2) => s1 intersect s2)
}

}

case class Abstraction(entry: Map[Int, Set[AExp]], exit: Map[Int, Set[AExp]])
}
Loading