是否存在用于移植 C++ 的自动转换工具?代码转为64位?
我正在研究将大量(> 10M 行)C++ 代码移植到 64 位的方法。我已经研究了静态代码分析器和编译器标志,现在正在研究可以进行常见、重复性更改的宏或其他工具。
我写了一些正则表达式来看看它们在实践中的效果如何,正如预测的那样,它们非常有效。也就是说,首先构建表达式需要一段时间,所以我想看看是否有此类表达式的列表或可以自动执行更改的软件工具。
以下几行是要匹配和修复的代码的原型示例。 (澄清一下,这些行并不代表单个代码块,而是从不同位置提取的行。)
int i = 0;
long objcount;
int count = channels.count(ch);
for (int k = 0; k < n; k++) { /*...*/ }
目标不是将代码彻底移植到 64 位,而是对代码执行第一次传递以减少需要手动检查的代码量。错过一些必要的更改是可以接受的,进行一些错误的更改可能也可以,但应该尽量减少这些更改。
Visual Studio 是用于转换工作的 IDE,因此与 VS 配合良好的东西是一个优势。成本不是问题。
I'm researching methods to port a large (>10M lines) amount of C++ code to 64-bit. I have looked at static code analyzers and compiler flags, and I am now looking at macros or other tools that can make common, repetitive changes.
I've written a few regular expressions to see how well they work in practice, and as predicted, they're quite effective. That said, it takes a while to build the expressions in the first place, so I'd like to see if there are any lists of such expressions or software tools that can perform changes automatically.
The following lines are prototypical examples of code to be matched and fixed. (To clarify, these lines are not meant to represent a single block of code, but instead are lines pulled from different places.)
int i = 0;
long objcount;
int count = channels.count(ch);
for (int k = 0; k < n; k++) { /*...*/ }
The objective is not to thoroughly port code to 64-bit, but instead to perform a first pass over the code to reduce the amount of code that needs to be manually inspected. It's okay for some needed changes to be missed, and it's probably okay for some wrong changes to be made, but those should be minimized.
Visual Studio is the IDE that will be used for conversion work, so something that works well with VS is a plus. Cost is not an issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Rexexp 的误报率很高;根据定义,“正则表达式”无法解析上下文无关的语言,例如 C++。此外,正则表达式不能考虑
账户类型信息; ?
对于某些类型定义的 fooT 来说可以吗 最后,正则表达式无法更改代码;您可能会考虑 Perl 或 SED(使用正则表达式来驱动更改),但由于正则表达式的误报,您会得到错误的更改。在 10M SLOC 下,这可不是什么有趣的事; 5% 的错误率意味着可能需要手动修复 50,000 行代码。
您可以考虑使用程序转换工具。这样的引擎在语言结构上运行,而不是文本,并且更复杂的版本知道符号的范围、类型和含义(例如, fooT 到底是什么?)。它们使您能够使用目标语言的表面语法编写特定于语言和上下文的模式,并提出结构正确的代码更改。这使得大规模代码更改的可靠应用成为可能。
我们的 DMS 软件重组工具包及其 C++ 前端 已用于对大型 C++ 系统进行大规模更改语法和类型准确的方式。 (参见 Akers, R.、Baxter, I.、Mehlich, M.、Ellis, B.、Luecke, K.,案例研究:通过自动程序转换重新设计 C++ 组件模型、信息和软件技术 49(3) :275-291 2007 年。)
Rexexps suffer from a high false positive rate; by definition, a "regular expression" cannot parse a context free langauge such as C++. Futhermore, regexps cannot take into
account type information; is
ok, for some typedef'd fooT? Finally, a regexp cannot change code; you might consider Perl or SED (using regexps to drive changes), but you'll get erroneous changes due to the false positives of regexps. At 10M SLOC, that can't be fun; a 5% error rate means possibly 50,000 lines of code to fix by hand.
You might consider a program transformation tool. Such engines operate on language structures, not text, and more sophisticated versions know scopes, types, and the meaning of symbol (e.g., what is fooT, exactly?). They offer you the ability to write langauge- and context-specific patterns, and propose structurally correct code changes, using the surface syntax of the target language. This enables the reliable application of code changes on scale.
Our DMS Software Reengineering Toolkit with its C++ Front End has been used to carry out massive changes to large C++ systems in a syntax- and type-accurate way. (See Akers, R., Baxter, I., Mehlich, M. , Ellis, B. , Luecke, K., Case Study: Re-engineering C++ Component Models Via Automatic Program Transformation, Information & Software Technology 49(3):275-291 2007.)
您使用什么版本的编译器?您是否尝试使用 /Wp64 标志运行编译器来检测 64 位的可移植性问题?
来自微软网站:
“/Wp64 检测也标有 __w64 关键字的类型的 64 位可移植性问题。/Wp64 在 Visual C++ 32 位编译器中默认关闭,在 Visual C++ 64 位编译器中默认打开。”
http://msdn.microsoft.com/en -us/library/yt4xw8fh%28v=vs.71%29.aspx
What version of the compiler are you using? Did you try running the compiler with the /Wp64 flag to detect portability to 64 bit issues?
From the MS website:
"/Wp64 detects 64-bit portability problems on types that are also marked with the __w64 keyword. /Wp64 is off by default in the Visual C++ 32-bit compiler and on by default in the Visual C++ 64-bit compiler."
http://msdn.microsoft.com/en-us/library/yt4xw8fh%28v=vs.71%29.aspx