Skip to content

Commit b1211c6

Browse files
author
Killian Perlin
committed
add tests for nanopass framework
1 parent c951736 commit b1211c6

File tree

17 files changed

+1852
-12
lines changed

17 files changed

+1852
-12
lines changed

lkql_jit/language/src/main/java/com/adacore/lkql_jit/langkit_translator/passes/TranslationPass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ public LKQLNode visit(Liblkqllang.PassDecl passDecl) {
20102010
new Expr[Constants.PASS_FAKE_ARGS.length],
20112011
docstring.isNone() ? "" : parseStringLiteral(docstring),
20122012
passExpr,
2013-
"<anonymous>"
2013+
"<pass:" + name + ">"
20142014
);
20152015

20162016
// Cleanup

lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/pass/RunPass.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ public Object executeGeneric(VirtualFrame frame) {
5858
final var roots = ctx.allUnitsRoots();
5959
final var units = new Object[roots.length];
6060
for (int i = 0; i < roots.length; i++) {
61-
if (ctx.isVerbose()) {
62-
debugAST(i, roots[i].dumpTree());
63-
}
61+
debugAST(i, roots[i].dumpTree());
6462
units[i] = AdaNodeProxy.convertAST(roots[i]);
6563
}
6664

@@ -69,9 +67,7 @@ public Object executeGeneric(VirtualFrame frame) {
6967
do {
7068
final var pass = callChain.poll();
7169

72-
if (ctx.isVerbose()) {
73-
ctx.println(ObjectUtils.toString(pass));
74-
}
70+
ctx.println(ObjectUtils.toString(pass));
7571

7672
for (int i = 0; i < units.length; i++) {
7773
try {
@@ -82,9 +78,7 @@ public Object executeGeneric(VirtualFrame frame) {
8278
LKQLRuntimeException.fromJavaException(e, this);
8379
}
8480

85-
if (ctx.isVerbose()) {
86-
debugAST(i, units[i]);
87-
}
81+
debugAST(i, units[i]);
8882
}
8983
} while (!callChain.isEmpty());
9084

@@ -97,7 +91,7 @@ public int getSlot() {
9791

9892
@TruffleBoundary
9993
private void debugAST(int num, Object ast) {
100-
System.out.println(num + ")\n" + ast);
94+
System.out.println(ast);
10195
}
10296

10397
@Override

lkql_jit/language/src/main/java/com/adacore/lkql_jit/runtime/values/AdaNodeProxy.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ private AdaNodeProxy(NodeInterface root) {
4646
for (int i = 0; i < root.getChildrenCount(); i++) {
4747
children.put("item_" + i, new AdaNodeProxy(root.getChild(i)));
4848
}
49+
} else if (root.isTokenNode()) {
50+
fields.put("value", root.getText());
4951
} else {
5052
final var fieldNames = root.getFieldNames();
5153
for (int i = 0; i < fieldNames.length; i++) {

testsuite/drivers/base_driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ def _define_lkql_executables(self) -> None:
531531
self.lkql_checker_exe = [*self.command_base, "check"]
532532
self.lkql_fix_exe = [*self.command_base, "fix"]
533533
self.gnatcheck_worker_exe = [*self.command_base, "gnatcheck_worker"]
534+
self.lkql_pass_exe = [*self.command_base, "run-passes"]
534535

535536
@classmethod
536537
def locate_on_path(cls, exec_name: str) -> str | None:

testsuite/drivers/interpreter_driver.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ class InterpreterDriver(BaseDriver):
2121
perf_supported = True
2222
flag_checking_supported = False
2323

24+
def base_args(self):
25+
return self.lkql_exe
26+
2427
def run(self) -> None:
2528
# Build the process's arguments list
26-
args = [*self.lkql_exe, '--script-path', 'script.lkql']
29+
args = [*self.base_args(), '--script-path', 'script.lkql']
2730

2831
input_sources = self.test_env.get('input_sources', None)
2932
project = self.test_env.get('project', None)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from drivers.interpreter_driver import InterpreterDriver
2+
3+
4+
class NanopassDriver(InterpreterDriver):
5+
"""
6+
This driver runs the interpreter in nanopass mode with the given arguments
7+
and compares the interpreter's output to the provided output file.
8+
9+
The LKQL script to run must be placed in a file called `script`.
10+
The expected output must be written in a file called `output`.
11+
12+
Test arguments:
13+
- project: GPR build file to use (if any)
14+
- input_sources: A list of Ada sources to run analyze with LKQL
15+
- lkql_path: A list of directories forwarded to the `LKQL_PATH`
16+
variable when the test is run.
17+
"""
18+
19+
def base_args(self):
20+
return self.lkql_pass_exe
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pass test1 { del {} add {} rewrite {} }
2+
pass test2 : test1 { del {} add {} rewrite {} }
3+
pass test3 : test2 { del {} add {} rewrite {} }
4+
5+
run_pass test3

0 commit comments

Comments
 (0)