arXiv:2512.11402cs.SEcs.AI2025-12

用大模型自动转C代码为Java,发现只有少数模型能搞定。

REMODEL-LLM: Transforming C code to Java using LLMs

  • 结合语法树和规则提示,提升代码语义转换精度
  • 仅3款小模型通过超半数测试,复杂特性仍无法处理
  • 适合研究代码迁移与量化模型极限的开发者参考

将C代码自动翻译为Java代码是一项极具挑战的任务,源于过程式与面向对象范式的根本差异、内存管理方式(手动指针与垃圾回收)的不同以及数据类型不兼容。本文评估了19个小型量化大模型(参数量均低于200亿)在该任务中的表现。采用一种新型混合流水线,利用抽象语法树(AST)进行语义分解,并采用高度受限的基于规则的提示策略。结果表明性能呈现明显分层:绝大多数模型(第三层,如llama3.1、gemma3、starcoder2)在测试中失败率达100%,甚至无法生成基本可运行的Java样板代码;少数中间层模型(第二层,如mistral-nemo和mistral)虽能生成可运行代码,但存在严重语义错误与误译;仅有三款模型(第一层:phi4、deepseek-coder-v2、codeqwen)具备实用性,通过率超过50%。即便这些顶尖模型,在函数指针、sizeof及enum逻辑等复杂C语言特性上仍出现失败,揭示当前量化模型推理能力的固有瓶颈。

原文摘要 · Abstract (English)

The automated translation of C code to Java code is a notoriously difficult task, fraught with challenges stemming from fundamental paradigm shifts (procedural vs. Object Oriented), memory models (manual pointers vs. Garbage Collection), and incompatible data types. This paper investigates the efficacy of 19 small, quantized LLMs (under 20 billion parameters) for the C to Java translation task. We use a novel, hybrid pipeline that leverages Abstract Syntax Trees (ASTs) for semantic decomposition and employs a highly constrained, rule based prompting strategy. The results are stark: a clear multi tiered performance divide emerged. The vast majority of models (Tier 3, e.g., llama3.1, gemma3, starcoder2) failed 100\% of the tests, proving incapable of generating even basic, runnable Java boilerplate. A small middle tier (Tier 2, e.g., mistral-nemo and mistral) produced runnable code but was plagued by dangerous semantic failures and wrong translations. Only three models (Tier 1: phi4, deepseek-coder-v2, codeqwen) proved viable, passing over 50\% of the test suite. Even these top models failed on the most complex C concepts, such as function pointers, sizeof, and enum logic, revealing a hard ceiling for the reasoning capabilities of current quantized models.

代码转换大模型编程语言量化模型

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。