From 2870cdf0eecbffeb3010c9f7b44cd09282cdbf16 Mon Sep 17 00:00:00 2001 From: Hugo Guerrier Date: Fri, 12 Jan 2024 14:26:59 +0100 Subject: [PATCH] Adapt LKQL JIT to the new Langkit Java API --- .../passes/TranslationPass.java | 44 ++++++++----------- .../node_patterns/NodeKindPattern.java | 5 ++- lkql_jit/native/make.py | 2 +- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/lkql_jit/language/src/main/java/com/adacore/lkql_jit/langkit_translator/passes/TranslationPass.java b/lkql_jit/language/src/main/java/com/adacore/lkql_jit/langkit_translator/passes/TranslationPass.java index e845dcb12..bd4d7953a 100644 --- a/lkql_jit/language/src/main/java/com/adacore/lkql_jit/langkit_translator/passes/TranslationPass.java +++ b/lkql_jit/language/src/main/java/com/adacore/lkql_jit/langkit_translator/passes/TranslationPass.java @@ -529,31 +529,23 @@ public LKQLNode visit(Liblkqllang.BinOp binOp) { final SourceLocation location = loc(binOp); // Create the binary operator by switching on the operator type - return switch (binOp.fOp().getKindName()) { - case Liblkqllang.OpPlus.kindName -> BinPlusNodeGen.create( + return switch (binOp.fOp().getKind()) { + case OP_PLUS -> BinPlusNodeGen.create( location, leftLocation, rightLocation, left, right); - case Liblkqllang.OpMinus.kindName -> BinMinusNodeGen.create( + case OP_MINUS -> BinMinusNodeGen.create( location, leftLocation, rightLocation, left, right); - case Liblkqllang.OpMul.kindName -> BinMulNodeGen.create( - location, leftLocation, rightLocation, left, right); - case Liblkqllang.OpDiv.kindName -> BinDivNodeGen.create( - location, leftLocation, rightLocation, left, right); - case Liblkqllang.OpAnd.kindName -> new BinAnd(location, left, right); - case Liblkqllang.OpOr.kindName -> new BinOr(location, left, right); - case Liblkqllang.OpEq.kindName -> BinEqNodeGen.create( - location, leftLocation, rightLocation, left, right); - case Liblkqllang.OpNeq.kindName -> BinNeqNodeGen.create( - location, leftLocation, rightLocation, left, right); - case Liblkqllang.OpConcat.kindName -> BinConcatNodeGen.create( - location, leftLocation, rightLocation, left, right); - case Liblkqllang.OpLt.kindName -> BinLtNodeGen.create( - location, leftLocation, rightLocation, left, right); - case Liblkqllang.OpLeq.kindName -> BinLeqNodeGen.create( - location, leftLocation, rightLocation, left, right); - case Liblkqllang.OpGt.kindName -> BinGtNodeGen.create( - location, leftLocation, rightLocation, left, right); - case Liblkqllang.OpGeq.kindName -> BinGeqNodeGen.create( + case OP_MUL -> BinMulNodeGen.create(location, leftLocation, rightLocation, left, right); + case OP_DIV -> BinDivNodeGen.create(location, leftLocation, rightLocation, left, right); + case OP_AND -> new BinAnd(location, left, right); + case OP_OR -> new BinOr(location, left, right); + case OP_EQ -> BinEqNodeGen.create(location, leftLocation, rightLocation, left, right); + case OP_NEQ -> BinNeqNodeGen.create(location, leftLocation, rightLocation, left, right); + case OP_CONCAT -> BinConcatNodeGen.create( location, leftLocation, rightLocation, left, right); + case OP_LT -> BinLtNodeGen.create(location, leftLocation, rightLocation, left, right); + case OP_LEQ -> BinLeqNodeGen.create(location, leftLocation, rightLocation, left, right); + case OP_GT -> BinGtNodeGen.create(location, leftLocation, rightLocation, left, right); + case OP_GEQ -> BinGeqNodeGen.create(location, leftLocation, rightLocation, left, right); default -> null; }; } @@ -600,10 +592,10 @@ public LKQLNode visit(Liblkqllang.UnOp unOp) { new SourceLocation(this.source, unOp.getSourceLocationRange()); // Create the unary operator by switching on the operator type - return switch (unOp.fOp().getKindName()) { - case Liblkqllang.OpNot.kindName -> UnNotNodeGen.create(location, argLocation, arg); - case Liblkqllang.OpPlus.kindName -> UnPlusNodeGen.create(location, argLocation, arg); - case Liblkqllang.OpMinus.kindName -> UnMinusNodeGen.create(location, argLocation, arg); + return switch (unOp.fOp().getKind()) { + case OP_NOT -> UnNotNodeGen.create(location, argLocation, arg); + case OP_PLUS -> UnPlusNodeGen.create(location, argLocation, arg); + case OP_MINUS -> UnMinusNodeGen.create(location, argLocation, arg); default -> null; }; } diff --git a/lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/patterns/node_patterns/NodeKindPattern.java b/lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/patterns/node_patterns/NodeKindPattern.java index 6b183064b..4d60d49e2 100644 --- a/lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/patterns/node_patterns/NodeKindPattern.java +++ b/lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/patterns/node_patterns/NodeKindPattern.java @@ -50,10 +50,11 @@ public final class NodeKindPattern extends NodePattern { */ public NodeKindPattern(SourceLocation location, String kindName) { super(location); - this.nodeClazz = Libadalang.NODE_CLASS_MAP.get(kindName); - if (this.nodeClazz == null) { + final var description = Libadalang.NODE_DESCRIPTION_MAP.get(kindName); + if (description == null) { throw LKQLRuntimeException.invalidKindName(this); } + this.nodeClazz = description.clazz; } // ----- Execution methods ----- diff --git a/lkql_jit/native/make.py b/lkql_jit/native/make.py index 45f3e4e79..d329948aa 100644 --- a/lkql_jit/native/make.py +++ b/lkql_jit/native/make.py @@ -67,7 +67,7 @@ "--macro:truffle", "--no-fallback", "--language:regex", - "--initialize-at-build-time=com.adacore.lkql_jit", + "--initialize-at-build-time=com.adacore.lkql_jit,com.adacore.liblkqllang", ] # Handle the dev and debug build mode