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

Js-refactor #1

Merged
merged 12 commits into from
Aug 12, 2024
Merged
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
70 changes: 70 additions & 0 deletions .github/workflows/lara-js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Java CI - Lara-JS

on:
push:
branches: [ js-refactor ]
pull_request:
branches: [ js-refactor ]

# Daily at midnight
schedule:
- cron: '0 0 * * *'

permissions:
checks: write

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
# Because of scheduled runs, by default run on default branch
with:
ref: js-refactor
path: workspace/clava-examples

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Check out specs-java-libs repo
uses: actions/checkout@v4
with:
repository: specs-feup/specs-java-libs
path: workspace/specs-java-libs

- name: Check out lara-framework repo
uses: actions/checkout@v4
with:
repository: specs-feup/lara-framework
ref: feature/lara-js
path: workspace/lara-framework

- name: Check out Clava repo
uses: actions/checkout@v4
with:
repository: specs-feup/clava
ref: feature/clava-js
path: workspace/clava

# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

# Setting up gradle multi-project would be helpful
- name: InstallDist Clava
working-directory: workspace/clava/ClavaWeaver
run: gradle installDist

- name: Execute 'stress_test.clava'
working-directory: workspace/clava-examples
run: |
../clava/ClavaWeaver/build/install/ClavaWeaver/bin/ClavaWeaver --config ./2019_Stress_Test/stress_test.clava
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
**/cmake-build*/*
**/CMakeFiles/*


# Ignore Clava intermidiate files
consumer_order.txt
enum_integer_type.txt
is_temporary.txt
omp.txt
types_with_templates.txt

# Ignore weaved code folders
**/weaved_code/*
Expand Down
152 changes: 152 additions & 0 deletions 2019_Stress_Test/lara/DynamicCallGraph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
laraImport("clava.ClavaJoinPoints");
laraImport("clava.Clava");
laraImport("lara.code.Logger");
laraImport("lara.util.TupleId");
laraImport("weaver.Query");

/**
* Inserts code for increments as a comma operator,
* as suggested by Pedro Silva ([email protected])
*/
const _DCG_USE_COMMA_OPERATOR_ = true;

/**
* Instruments code in order to build a runtime call graph.
*
* If _DCG_USE_COMMA_OPERATOR_ is true, it will take into account execution
* when functions are called as part of a short-circuit operation,
* e.g., foo() || foo2(), when foo() returns true, the call to foo2() is not counted.
* However, if for any reason the comma operator cannot be used,
* set _DCG_USE_COMMA_OPERATOR_ to false (it is true by default),
* and an alternative method is used that will not take into account short-circuit operators.
*/
function DynamicCallGraph(graphFile = "dcg.dotty") {
const tupleId = new TupleId();

const dcgName = "clava_dcg_global";

/* Instrument function calls and increment the corresponding position */
for (const chain of Query.search("function").search("call").chain()) {
const $function = chain["function"];
const $call = chain["call"];

const id = tupleId.getId($function.name, $call.name);
insertIncrement($call, dcgName + "[ " + id + " ]++");
}

// Get tuples and count them
const tuples = tupleId.getTuples();
let total = 0;
for (const _key in tuples) {
total++;
}
/* Declare the array in each file */
for (const chain of Query.search("file").search("function").chain()) {
const $file = chain["file"];
const $function = chain["function"];

if ($file.hasMain) {
$function.insertBefore("int [[dcgName]][ [[total]] ] = {0};");
} else {
$function.insertBefore("extern int [[dcgName]][ [[total]] ];");
}
break;
}

// Build function to print call graph
const callgraphFunctionName = "clava_call_graph";
const $callgraph = ClavaJoinPoints.functionDecl(
callgraphFunctionName,
ClavaJoinPoints.builtinType("void")
);
$callgraph.setBody(ClavaJoinPoints.scope());

// Using a comment as a marker for log insertions
const $markerStmt = $callgraph.body.insertBegin(
ClavaJoinPoints.stmtLiteral("// MARKER")
);

// Insert function before main
for (const $function of Query.search("function", "main")) {
// Just before main declaration
if (!$function.hasDefinition) {
continue;
}

$function.insertBefore($callgraph);

// Insert only once
break;
}

const graphLogger = new Logger(false, graphFile);
graphLogger
.append("digraph dynamic_call_graph {")
.ln()
.ln()
.log($markerStmt);

let $lastStmt = graphLogger.getAfterJp();

for (const id in tuples) {
const tuple = tuples[id];
const dcgCount = dcgName + "[" + id + "]";
$lastStmt = $lastStmt.insertAfter(
ClavaJoinPoints.ifStmt(dcgCount + " != 0")
);

graphLogger
.append("\t" + tuple[0] + " -> " + tuple[1] + ' [label=\\"')
.int(dcgCount)
.append('\\"];')
.ln()
.logBefore($lastStmt.then);
}

graphLogger.append("}").ln().log($lastStmt);

// Remove marker stmt
$markerStmt.detach();

// Register function to be executed when program exits
Clava.getProgram().atexit($callgraph);

console.log("\nDynamicCallGraph done!");
}

function insertIncrement($call, code) {
// Increments using comma operator
if (_DCG_USE_COMMA_OPERATOR_) {
// First, replace call with parenthesis
const $parenthesis = $call.replaceWith(
ClavaJoinPoints.parenthesis("/* DCG TEMP */")
);

// Create comma operator
const $commaOp = ClavaJoinPoints.binaryOp(
"comma",
code,
$call,
$call.type
);

// Replace parenthesis child
$parenthesis.firstChild = $commaOp;

return;
}

// Increments using statements, add ;
code += ";";

// If call is inside a loop header (e.g., for, while),
// insert increment at the beginning of the loop body
if ($call.isInsideLoopHeader) {
const $loop = $call.ancestor("loop");
checkDefined($loop);
$loop.body.insertBegin(code);
return;
}

$call.insertBefore(code);
}
137 changes: 0 additions & 137 deletions 2019_Stress_Test/lara/DynamicCallGraph.lara

This file was deleted.

Loading