Abstract:Datalog, a declarative logic programming language, has been widely-adopted across diverse domains and experienced a surge in interest from both academia and industry in recent years. This renewed attention has led to the design and development of various Datalog engines alongside their respective dialects. However, a prevalent challenge is that code implemented in one Datalog dialect typically cannot be executed on the engine of another dialect. This limitation necessitates the translation of existing Datalog codebases when transitioning to a new Datalog engine. Traditional approaches to Datalog code translation, which include manual code rewriting and the creation of translation rules, are often time-consuming, repetitive, inflexible, and not easily scalable. This paper proposes an LLM-powered Datalog code translation technology, utilizing the powerful code understanding and generation capabilities of LLM, through a divide-and-conquer strategy, prompt engineering based on few-shot and CoT prompts, and an iterative error-correction mechanism based on check-feedback-repair, which can achieve high-precision code translation between different Datalog dialects and reduce the workload of developers in developing translation rules repeatedly. Building on this code translation technology, a general declarative incremental program analysis framework based on Datalog has been designed and implemented. The performance of the proposed LLM-powered Datalog code translation technology was evaluated on different Datalog dialects, and the evaluation results verified the effectiveness of the proposed code translation technology. We also conducted experimental evaluation on the general declarative incremental program analysis framework, verifying the speedup effect of incremental program analysis based on the proposed code translation technology.