但在inline assembly 中使用到register pair
可能會讓你有點混淆
unsigned long long
swap (unsigned long long i1, unsigned i2)
{
unsigned long long i1_return_value;
__asm__ ("swap\t%0, %2"
: "=r" (i1_return_value)
: "0" (i1), "r" (i2)
);
return i1_return_value;
}
def bork { // Value
bit isMod = 1;
bit isRef = 0;
}
def hork { // Value
bit isMod = 1;
bit isRef = 1;
}
def zork { // Value
bit isMod = 0;
bit isRef = 1;
}
def ADD_rr : rrinst<0b111, "add">; def ADD_ri : riinst<0b111, "add">; def SUB_rr : rrinst<0b101, "sub">; def SUB_ri : riinst<0b101, "sub">; def MUL_rr : rrinst<0b100, "mul">; def MUL_ri : riinst<0b100, "mul">;
介紹兩個用在macro 的運算子
## : 把macro 裡的參數,跟其他string 串接起來
# : 把macro 裡的參數,當作string
#define w(n) "imm"#n
#define w2(n) imm##n
int main()
{
int imm5 = 10;
printf("%s\n", w(10));
printf("%d\n", w2(5));
return 0;
}
第一個printf 我想要一個string 當參數 所以用#
第二個printf 我想要一個變數 所以用##
Reference
cmake 可以產生不同的build file (ex: unix makefile)
cmake –help
最後面會列出在你平台環境上可以產生的makefile 種類
cmake –G “Unix Makefiles”
指令產生"Unix Makefiles”
如果不指定,也會自動偵測。
所以build LLVM 最簡單的命令就是在build directory
cmake PATH/TO/LLVM/SRC
make
其它variable 請參考
http://llvm.org/docs/CMake.html#options-and-variables
cmake -DLLVM_TARGETS_TO_BUILD="X86” # only build x86 target
-DCMAKE_INSTALL_PREFIX="$PWD/../install" # specify installation path
../llvm-3.4.1.src/
always_inline 下面 網頁列出 –O –O1 情況下,有打開的optimization,可以試試看到底是那些optimizations 才可以。
#include "gtest/gtest.h"class myClass {public: myClass() : init(1) {} int get() { return init;} void set(int i) { init = i;}private: int init;};
// To use a test fixture, derive a class from testing::Test.class myClassTest : public testing::Test { protected: // You should make the members protected s.t. they can be virtual void SetUp() { }
// Declares the variables your tests want to use. myClass mc1;};
// When you have a test fixture, you define a test using TEST_F// instead of TEST.TEST_F(myClassTest, test1) { mc1.set(10); EXPECT_EQ(10, mc1.get());}TEST_F(myClassTest, test2) { EXPECT_EQ(1, mc1.get());
}
可以看到一個testCase 內有兩個tests (test1, test2),如果沒有fixture, 則每個test 都要去宣告myClass, 還有setup function. 現在建立了一個共用的myClassTest來共用code的部分. 但前面有提到為了保持test 之間的獨立, data 是不共用的.為了證明這點, 可以看到test1 將init 設成10之後, 在test2 init 還是剛初始化之後的 1.
所以fixture 會1. 替每個test 配置一份新的fixture class (因此有一份新的資料, 但code 依然是共享的)2 .呼叫setup3. teardown