我正在研究LLVM编译器的新后端。后端很顺利,但我到达的地方我想验证代码生成器是否正常运行。我有一个处理器模拟器可用,非常准确,我想用于验证。
使用LLVM-lit对我来说似乎不是一个好选择,因为无法在测试过程中集成模拟器。
目前,我的测试策略涉及编写测试程序,我尝试使用该程序检查尽可能多的语句。以下是检查算术的示例。
c = a + a;
if (c != 6) return 4;
c = a + a + a;
if (c != 9) return 5;
// etc
我已经注意到很难找到尽可能多的角落情况。
这是验证代码生成器的明智方法吗?如果是这样,是否有人知道包含这些测试的预先存在的项目?
答案 0 :(得分:3)
您可以通过制作自己的lit.cfg脚本以及其他定义来执行您想要的操作。例如,我为我的项目ELLCC交叉构建不同目标的东西。我使用QEMU来运行测试。我修改过的lit.site.cfg的一部分看起来像是:
config.substitutions.append( ('%microblazeecc', ' ' + config.ecc + ' ' +
'-target microblaze-ellcc-linux ') )
config.substitutions.append( ('%microblazeexx', ' ' + config.ecc + '++ ' +
'-target microblaze-ellcc-linux ') )
config.substitutions.append( ('%microblazerun', ' ' + ellcc + '/bin/qemu-microblaze ') )
典型的测试案例如下:
// Compile and run for every target.
// RUN: %armexx -o %t %s && %armrun %t | FileCheck -check-prefix=CHECK %s
// RUN: %armebexx -o %t %s && %armebrun %t | FileCheck -check-prefix=CHECK %s
// RUN: %i386exx -o %t %s && %i386run %t | FileCheck -check-prefix=CHECK %s
// RUN: %microblazeexx -o %t %s && %microblazerun %t | FileCheck -check-prefix=CHECK %s
// RUN: %mipsexx -o %t %s && %mipsrun %t | FileCheck -check-prefix=CHECK %s
// RUN: %mipselexx -o %t %s && %mipselrun %t | FileCheck -check-prefix=CHECK %s
// RUN: %ppcexx -o %t %s && %ppcrun %t | FileCheck -check-prefix=CHECK %s
// FAIL: %ppc64exx -o %t %s && %ppc64run %t | FileCheck -check-prefix=CHECK %s
// RUN: %x86_64exx -o %t %s && %x86_64run %t | FileCheck -check-prefix=CHECK %s
// CHECK: foo.i = 10
// CHECK: bye
#include <cstdio>
class Foo {
int i;
public:
Foo(int i) : i(i) { }
int get() { return i; }
~Foo() { printf("bye\n"); }
};
int main(int argc, char** argv)
{
Foo foo(10);
printf("foo.i = %d\n", foo.get());
}
您可以使用FileCheck查找您感兴趣的输出。
答案 1 :(得分:1)
您可能需要查看LLVM test suite - 一组“完整程序”,这些程序首先使用本机平台编译器(例如gcc
)进行编译,然后使用LLVM进行编译,结果为比较。
因此,如果您的CPU已经有一些能够为其生成代码的编译器,那么这是一个不错的选择。如果没有,您可以对其进行装配,以便在开发计算机上生成预期输出,并与使用后端编译的代码生成的输出进行比较。