Commit daa80424 authored by Administrator's avatar Administrator
Browse files

added starter c++ sample and toolchain

parent 9fe2f614
...@@ -271,10 +271,13 @@ set(SAMPLES ...@@ -271,10 +271,13 @@ set(SAMPLES
while-bigger-steps while-bigger-steps
while-neg while-neg
example-1 example-1
A # A
B # B
C # C
D # D
)
set(CPPSAMPLES
classes
) )
# Older CMake version do not support list transformations # Older CMake version do not support list transformations
...@@ -297,11 +300,17 @@ list_transform_append(SAMPLES ".bc" SAMPLES_BC) ...@@ -297,11 +300,17 @@ list_transform_append(SAMPLES ".bc" SAMPLES_BC)
list_transform_append(SAMPLES ".ll" SAMPLES_LL) list_transform_append(SAMPLES ".ll" SAMPLES_LL)
list_transform_prepend(SAMPLES_LL "${CMAKE_SOURCE_DIR}/output/") list_transform_prepend(SAMPLES_LL "${CMAKE_SOURCE_DIR}/output/")
list_transform_prepend(SAMPLES_BC "${CMAKE_SOURCE_DIR}/output/") list_transform_prepend(SAMPLES_BC "${CMAKE_SOURCE_DIR}/output/")
list_transform_prepend(SAMOLES_C "${CMAKE_SOURCE_DIR}/samples/") list_transform_prepend(SAMPLES_C "${CMAKE_SOURCE_DIR}/samples/")
list_transform_append(CPPSAMPLES ".cpp" CPPSAMPLES_CPP)
list_transform_append(CPPSAMPLES ".bc" CPPSAMPLES_BC)
list_transform_append(CPPSAMPLES ".ll" CPPSAMPLES_LL)
list_transform_prepend(CPPSAMPLES_LL "${CMAKE_SOURCE_DIR}/output/")
list_transform_prepend(CPPSAMPLES_BC "${CMAKE_SOURCE_DIR}/output/")
list_transform_prepend(CPPSAMPLES_CPP "${CMAKE_SOURCE_DIR}/samples/")
add_custom_target(irgen add_custom_target(irgen
DEPENDS ${SAMPLES_LL} ${SAMPLES_BC} DEPENDS ${SAMPLES_LL} ${SAMPLES_BC} ${CPPSAMPLES_LL} ${CPPSAMPLES_BC}
) )
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/output) file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/output)
...@@ -313,7 +322,17 @@ foreach(src ${SAMPLES}) ...@@ -313,7 +322,17 @@ foreach(src ${SAMPLES})
COMMAND clang --sysroot ${CMAKE_OSX_SYSROOT} -O0 -emit-llvm ${CMAKE_SOURCE_DIR}/samples/${src}.c -Xclang -disable-O0-optnone -c -o ${CMAKE_SOURCE_DIR}/output/${src}.bc COMMAND clang --sysroot ${CMAKE_OSX_SYSROOT} -O0 -emit-llvm ${CMAKE_SOURCE_DIR}/samples/${src}.c -Xclang -disable-O0-optnone -c -o ${CMAKE_SOURCE_DIR}/output/${src}.bc
COMMAND opt -S -mem2reg ${CMAKE_SOURCE_DIR}/output/${src}.bc -o ${CMAKE_SOURCE_DIR}/output/${src}.ll COMMAND opt -S -mem2reg ${CMAKE_SOURCE_DIR}/output/${src}.bc -o ${CMAKE_SOURCE_DIR}/output/${src}.ll
DEPENDS clang opt ${CMAKE_SOURCE_DIR}/samples/${src}.c DEPENDS clang opt ${CMAKE_SOURCE_DIR}/samples/${src}.c
COMMENT "Generating LLVM IR for example ${src}" COMMENT "Generating LLVM IR for example ${src}.c"
)
endforeach(src)
foreach(src ${CPPSAMPLES})
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/output/${src}.ll
COMMAND clang++ --sysroot ${CMAKE_OSX_SYSROOT} -O0 -emit-llvm ${CMAKE_SOURCE_DIR}/samples/${src}.cpp -Xclang -disable-O0-optnone -c -o ${CMAKE_SOURCE_DIR}/output/${src}.bc
COMMAND opt -S -mem2reg ${CMAKE_SOURCE_DIR}/output/${src}.bc -o ${CMAKE_SOURCE_DIR}/output/${src}.ll
DEPENDS clang opt ${CMAKE_SOURCE_DIR}/samples/${src}.cpp
COMMENT "Generating LLVM IR for example ${src}.cpp"
) )
endforeach(src) endforeach(src)
...@@ -325,10 +344,21 @@ foreach(src ${SAMPLES}) ...@@ -325,10 +344,21 @@ foreach(src ${SAMPLES})
COMMAND clang -O0 -emit-llvm ${CMAKE_SOURCE_DIR}/samples/${src}.c -Xclang -disable-O0-optnone -c -o ${CMAKE_SOURCE_DIR}/output/${src}.bc COMMAND clang -O0 -emit-llvm ${CMAKE_SOURCE_DIR}/samples/${src}.c -Xclang -disable-O0-optnone -c -o ${CMAKE_SOURCE_DIR}/output/${src}.bc
COMMAND opt -S -mem2reg ${CMAKE_SOURCE_DIR}/output/${src}.bc -o ${CMAKE_SOURCE_DIR}/output/${src}.ll COMMAND opt -S -mem2reg ${CMAKE_SOURCE_DIR}/output/${src}.bc -o ${CMAKE_SOURCE_DIR}/output/${src}.ll
DEPENDS clang opt ${CMAKE_SOURCE_DIR}/samples/${src}.c DEPENDS clang opt ${CMAKE_SOURCE_DIR}/samples/${src}.c
COMMENT "Generating LLVM IR for example ${src}" COMMENT "Generating LLVM IR for example ${src}.c"
) )
endforeach(src) endforeach(src)
foreach(src ${CPPSAMPLES})
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/output/${src}.ll
COMMAND clang++ -O0 -emit-llvm ${CMAKE_SOURCE_DIR}/samples/${src}.cpp -Xclang -disable-O0-optnone -c -o ${CMAKE_SOURCE_DIR}/output/${src}.bc
COMMAND opt -S -mem2reg ${CMAKE_SOURCE_DIR}/output/${src}.bc -o ${CMAKE_SOURCE_DIR}/output/${src}.ll
DEPENDS clang opt ${CMAKE_SOURCE_DIR}/samples/${src}.cpp
COMMENT "Generating LLVM IR for example ${src}.cpp"
)
endforeach(src)
endif() endif()
configure_file(.lldbinit.in .lldbinit) configure_file(.lldbinit.in .lldbinit)
\ No newline at end of file
class A {
public:
int a;
virtual int f(){ return 0; };
virtual int g(){ return 0; };
};
class B: public A {
public:
int b;
virtual int f() { return 42; };
};
class D : public A {
public:
int d;
virtual int g(){ return 4711; };
};
class C: public B, public D {
public:
int c;
};
int main (void)
{
int res = 0;
A *a;
if (a==0)
a=new A();
else
a = new B();
res += a->f();
a = dynamic_cast<D*>(new C());
res += a->g();
return res;
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment