计算机科学 ›› 2017, Vol. 44 ›› Issue (4): 16-20.doi: 10.11896/j.issn.1002-137X.2017.04.004

• NASAC 2015 • 上一篇    下一篇

CCodeExtractor:一种针对C程序自动化的函数提取方法

张其良,张昱,周坤   

  1. 中国科学技术大学计算机科学与技术学院 合肥230026,中国科学技术大学计算机科学与技术学院 合肥230026,中国科学技术大学计算机科学与技术学院 合肥230026
  • 出版日期:2018-11-13 发布日期:2018-11-13
  • 基金资助:
    本文受国家863高技术研究发展计划项目基金(2012AA010901),国家自然科学基金(61170018)资助

CCodeExtractor:Automatic Approach of Function Extraction for C Programs

ZHANG Qi-liang, ZHANG Yu and ZHOU Kun   

  • Online:2018-11-13 Published:2018-11-13

摘要: 随着程序规模和复杂性的增加,代码重构在改善软件质量、性能以及提高软件的扩展性和维护性等方面至关重要。目前的Eclipse中,C源代码重构工具的函数提取只能处理一些简单的代码,且处理过程需要人工参与,不能自动化处理。为此,提出一种C源代码级别自动化的函数提取方法(CCodeExtractor),它通过指定提取条件,在保证语义一致的前提下,将符合条件的代码片段自动分离成一个单独的函数,并将其放到新文件中,而原代码片段替换成了一个函数调用。为了验证CCodeExtractor的有效性,结合循环分析和优化在实际应用中的广泛应用,在LLVM上实现了一个提取循环的工具,将程序中满足条件的for循环封装成单独的函数。在实验中,使用该工具对6个不同规模的程序进行了测试并且对比了变换前后程序运行的结果。实验结果表明,CCodeExtractor代码提取方法在保证程序语义不变的前提下,适用于不同规模的程序。

关键词: C程序重构,程序变换,程序理解,代码提取,循环分析,LLVM

Abstract: As program complexity increases,code refactoring plays an important role in improving quality and perfor-mance of software,and is also essential for improving the maintainability and extensibility of programs.Current code extraction approach for C code in Eclipse,can only deal with some simple code,and cannot refactor the code automatically.In this paper,we proposed a code extraction approach for C code,CCodeExtractor.It can extract the C code fragments that meet the specified conditions into new functions,and replace the fragments with these new functions calls automatically.The refactored code has the same program semantics as the original code.In order to verify the validity of CCodeExtractor,we implemented it in LLVM to extract some for statements in C programs into new functions since loop ana-lysis and optimization has been widely explored in recent years.Our experiments evaluated CCodeExtractor using six actual applications of different size,and compared the outcomes of the original and transformed programs.Experimental results show that CCodeExtractor can provide correct source-level transformation for programs of different size.

Key words: C program refactoring,Program transformation,Program comprehension,Code extraction,Loop analysis,LLVM

[1] FOWLER M.Refactoring:improving the design of existing code[M].Pearson Education India,1999.
[2] Code refactoring.http://en.wikipedia.org/wiki/Code_re-factoring.
[3] HAFIZ M,OVERBEY J.OpenRefactory/C:An infrastructurefor developing program transformations for C programs[C]∥Proceedings of the 3rd annual conference on Systems,programming,and applications:software for humanity.ACM,2012:27-28.
[4] HAFIZ M,OVERBEY J,BEHRANG F,et al.OpenRefactory/C:An infrastructure for building correct and complex C transformations[C]∥Proceedings of the 2013 ACM Workshop on Refactoring Tools.ACM,2013:1-4.
[5] Microsoft Visual Studio.http://www.wholetomato.com/features/ feature-refactoring.asp#extract.
[6] Extract method In Eclipse.https://sourcemaking.com/re-factoring/ extract-method.
[7] JEFFREY L.Overbey,Farnaz Behrang,and Munawar Hafiz.A foundation for refactoring C with macros[C]∥22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering (FSE).New York,NY,USA,2014:75-85.
[8] LATTNER C,ADVE V.LLVM:A compilation framework for lifelong program analysis & transformation[C]∥ International Symposium on Code Generation and Optimization,2004(CGO 2004).IEEE,2004:75-86.
[9] LATTNER C.LLVM and Clang:Next generation compiler tech-nology[C]∥The BSD Conference.2008:1-2.
[10] LLVM extractCode.http://llvm.org/docs/doxygen/html/CodeExtractor 8cpp _source.html.
[11] PROKAJ J.C code for SIFT feature point extraction.http://www.pudn.com/downloads93/sourcecode/graph/texture_mapping/detail365370.html.

No related articles found!
Viewed
Full text


Abstract

Cited

  Shared   
  Discussed   
No Suggested Reading articles found!