Skip to content

Commit

Permalink
Merge branch 'master' into feature/variable-renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusluizfb authored Jun 8, 2021
2 parents 5da3143 + f5e9d8f commit 35477ef
Show file tree
Hide file tree
Showing 24 changed files with 2,481 additions and 1,645 deletions.
1 change: 1 addition & 0 deletions META-INF/RASCAL.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Project-Name: JimpleFramework
Courses: courses
Main-Module: Plugin
Source: src/main/rascal,src/test/rascal
Require-Libraries: |lib://rascal_eclipse|
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,20 @@ A Rascal implementation of the Jimple framework. The current version supports:
* parsing Java Byte Code into a JIMPLE representation.
* JIMPLE code optmization constructs.
* a framework for dataflow analysis.


### Requirements

* Java ?
* Maven
* Rascal
* Eclipse IDE
* Lombok

### Setting up your requirements

1. Make sure Eclipse is running on Java ?. Also, you need to setup your PATH to use Java ? when using Maven.
2. Install Lombok into Eclipse IDE. https://projectlombok.org/setup/eclipse

### Installation Procedure


108 changes: 89 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/rascal"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="src/test/rascal"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.unb.cic</groupId>
<artifactId>JimpleFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>

<repositories>
<repository>
<id>usethesource</id>
<name>your custom repo</name>
<url>https://nexus.usethesource.io/content/repositories/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>usethesource</id>
<url>https://nexus.usethesource.io/content/repositories/public/</url>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>org.rascalmpl</groupId>
<artifactId>rascal</artifactId>
<version>0.18.0</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>

</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.rascalmpl</groupId>
<artifactId>rascal-maven-plugin</artifactId>
<version>0.3.4</version>
<configuration>
<bin>${project.build.outputDirectory}</bin>
<errorsAsWarnings>true</errorsAsWarnings>
<enableStandardLibrary>true</enableStandardLibrary>
<srcs>
<src>${project.basedir}/src/main/rascal</src>
</srcs>
<srcIgnores>
<ignore>${project.basedir}/src/main/rascal/lang/jimple/toolkit/GraphUtil.rsc</ignore>
<ignore>${project.basedir}/src/main/rascal/lang/jimple/toolkit/CallGraph.rsc</ignore>
</srcIgnores>
</configuration>
<executions>
<execution>
<id>it-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

</project>
130 changes: 130 additions & 0 deletions src/main/java/lang/jimple/internal/BranchInstructionFlow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package lang.jimple.internal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import lang.jimple.internal.generated.Expression;
import lang.jimple.internal.generated.Statement;

public class BranchInstructionFlow implements InstructionFlow {

private Environment left;
private Environment right;

private Expression condition;

private String targetStatement;
private String mergeStatement;

private BranchState status;

private Statement gotoMergeStmt;

enum BranchState {
LEFT,
RIGHT,
ReadyToMerge
}

public BranchInstructionFlow(Expression condition, String target) {
this.condition = condition;
this.targetStatement = target;
left = new Environment();
right = new Environment();
status = BranchState.LEFT;
}


@Override
public Collection<Statement> merge() {
List<Statement> res = new ArrayList<>();

res.add(Statement.ifStmt(condition, targetStatement));
res.addAll(left.instructions);

if(gotoMergeStmt != null) {
res.add(gotoMergeStmt);
}

res.add(Statement.label(targetStatement));
res.addAll(right.instructions);

if(mergeStatement != null) {
res.add(Statement.label(mergeStatement));
}

return res;
}

@Override
public boolean matchMergePoint(String label) {
if(status.equals(BranchState.LEFT)) {
return this.targetStatement.equals(label);
}
else if(status.equals(BranchState.RIGHT)) {
return this.mergeStatement.equals(label);
}
return false;
}

@Override
public List<Environment> environments() {
List<Environment> res = new ArrayList<>();
switch(status) {
case LEFT: res.add(left); break;
case RIGHT: res.add(right); break;
case ReadyToMerge:
if(mergeStatement != null) {
res.add(left);
res.add(right);
}
else {
res.add(left);
}
}
return res;
}

@Override
public void notifyGotoStmt(Statement stmt, String label) {
if(status.equals(BranchState.LEFT)) {
mergeStatement = label;
gotoMergeStmt = stmt;
}
else if(status.equals(BranchState.RIGHT)) {
right.instructions.add(stmt);
}
else if(status.equals(BranchState.ReadyToMerge)) {
left.instructions.add(stmt);
right.instructions.add(stmt);
}
}

@Override
public void nextBranch() {
switch(status) {
case LEFT:
if(mergeStatement != null) {
status = BranchState.RIGHT;
}
else {
left.instructions.add(Statement.label(targetStatement));
status = BranchState.ReadyToMerge;
}
break;
case RIGHT: status = BranchState.ReadyToMerge; break;
case ReadyToMerge: //
}
}

@Override
public boolean isBranch() {
return true;
}

@Override
public boolean readyToMerge(String label) {
return status.equals(BranchState.ReadyToMerge);
}
}
Loading

0 comments on commit 35477ef

Please sign in to comment.