Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to cmake #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
86 changes: 86 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
cmake_minimum_required(VERSION 3.10)
project(vmir
DESCRIPTION "vmir project"
)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/tlsf)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)

set(SRCS
src/main.c
src/vmir.c
tlsf/tlsf.c
)

set(DEPS
src/vmir.h
src/vmir_instr.c
src/vmir_value.c
src/vmir_type.c
src/vmir_jit_arm.c
src/vmir_vm.c
src/vmir_vm.h
src/vmir_transform.c
src/vmir_bitstream.c
src/vmir_support.c
src/vmir_function.c
src/vmir_libc.c
src/vmir_bitcode_parser.c
src/vmir_bitcode_instr.c
src/vmir_wasm_parser.c
)

set(COMMON_FLAG
-std=gnu99
-Wall
-Werror
-Wmissing-prototypes
-DVMIR_USE_TLSF
)

function(add_vmir_executable a_ExeFileName a_Flags)
add_executable(${a_ExeFileName}
${SRCS}
)
target_compile_options(${a_ExeFileName} PRIVATE ${a_Flags})
target_link_libraries(${a_ExeFileName} m)
set_target_properties(${a_ExeFileName} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/")
endfunction()

set(VMIR_FLAG -O2 ${COMMON_FLAG} -g)
add_vmir_executable(vmir ${VMIR_FLAG})

set(VMIR_DBG_FLAG -Og -DVM_DONT_USE_COMPUTED_GOTO ${COMMON_FLAG} -g)
add_vmir_executable(vmir.dbg ${VMIR_DBG_FLAG})

set(VMIR_TRACE_FLAG -DVM_TRACE -Og -DVM_DONT_USE_COMPUTED_GOTO ${COMMON_FLAG} -g)
add_vmir_executable(vmir.trace ${VMIR_TRACE_FLAG})

set(VMIR_ASAN_FLAG -fno-omit-frame-pointer -fsanitize=address -O0 -DVM_DONT_USE_COMPUTED_GOTO ${COMMON_FLAG} -g)
add_vmir_executable(vmir.asan ${VMIR_ASAN_FLAG})
target_link_libraries(vmir.asan asan)

set(ARM_GCC arm-linux-gnueabihf-gcc)
find_package(${ARM_GCC})
if (${ARM_GCC}_FOUND)
set(CMAKE_C_COMPILER ${ARM_GCC})

set(VMIR_ARMV7_FLAG -O2 -static -march=armv7-a -mtune=cortex-a8 -mfpu=neon ${COMMON_FLAG} -g)
add_vmir_executable(vmir.armv7 ${VMIR_ARMV7_FLAG})
endif()

set(POWERPC64_GCC arm-linux-gnueabihf-gcc)
find_package(${POWERPC64_GCC})
if (${POWERPC64_GCC}_FOUND)
set(CMAKE_C_COMPILER ${POWERPC64_GCC})

set(VMIR_PPC64_FLAG -fno-omit-frame-pointer -fsanitize=address -O0 -DVM_DONT_USE_COMPUTED_GOTO -DVMIR_USE_TLSF ${COMMON_FLAG} -g)
add_vmir_executable(vmir.ppc64 ${VMIR_PPC64_FLAG})
endif()

enable_testing()
add_subdirectory(test)


11 changes: 11 additions & 0 deletions clean_build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Clean
cd build
make clean
#make clean_extra

# Remove build dir
cd ..
rm -rf build/

14 changes: 14 additions & 0 deletions run_build_and_test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Clean
./clean_build.bash

# Build
mkdir build
cd build
cmake ..
make -j

# Run test
ctest

9 changes: 9 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.10)
project(test
DESCRIPTION "test project"
)

enable_testing()
add_subdirectory(gcc-torture)
add_subdirectory(misc)
add_subdirectory(regress)
73 changes: 73 additions & 0 deletions test/TestFunc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
set(SYSROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../sysroot)

set(CLANG clang-3.9) # work only clang-3.9 and clang-4.0
set(CFLAGS_BC -fno-vectorize -fno-slp-vectorize -emit-llvm -target le32-unknown-nacl
--sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${CMAKE_CURRENT_SOURCE_DIR} -std=gnu99
)

function(BuildFile a_OutFile a_InputFile a_Oprimization a_Index)
set(OUT_FILE
${CMAKE_CURRENT_BINARY_DIR}/build-O${a_Oprimization}/${a_InputFile}.bc
)
set(${a_OutFile} ${OUT_FILE} PARENT_SCOPE)

get_filename_component(OUT_FILE_DIR ${OUT_FILE} DIRECTORY)
get_filename_component(OUT_FILE_NAME ${OUT_FILE} NAME)

add_custom_command(
OUTPUT ${OUT_FILE}
COMMAND mkdir -p ${OUT_FILE_DIR}
COMMAND ${CLANG} -O0 ${CFLAGS_BC} -c ${CMAKE_CURRENT_SOURCE_DIR}/${a_InputFile} -o ${OUT_FILE}
COMMENT "Compile ${SRCS_TEST_C_FILE}"
)

add_custom_target(${OUT_FILE_NAME}_${a_Index}_${a_Oprimization} ALL DEPENDS ${OUT_FILE})
endfunction()

function(BuildFile_AndTest a_FileName a_Oprimization a_Index)
BuildFile(OUT_FILE ${a_FileName} ${a_Oprimization} ${a_Index})

add_test(NAME test_${INDEX}_${a_FileName}_${a_Oprimization}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../../vmir ${OUT_FILE}
)
endfunction()

function(BuildFile_AndRegressTest a_FileName a_Oprimization a_Index)
BuildFile(OUT_FILE ${a_FileName} ${a_Oprimization} ${a_Index})

add_test(NAME test_${INDEX}_${a_FileName}_${a_Oprimization}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../run_regress_test ${CMAKE_CURRENT_SOURCE_DIR}/../../vmir ${OUT_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/${a_FileName}.expected
)
endfunction()

function(BuildVmirTest a_InputFileTemplate)
file(GLOB SRCS_TEST_C_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${a_InputFileTemplate}) #_RECURSE

set(INDEX 0)

foreach(SRCS_TEST_C_FILE ${SRCS_TEST_C_FILES})
math(EXPR INDEX "${INDEX} + 1")

BuildFile_AndTest(${SRCS_TEST_C_FILE} 0 ${INDEX})

BuildFile_AndTest(${SRCS_TEST_C_FILE} 1 ${INDEX})

BuildFile_AndTest(${SRCS_TEST_C_FILE} 2 ${INDEX})
endforeach()
endfunction()

function(BuildRegressTest a_InputFileTemplate)
file(GLOB SRCS_TEST_C_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${a_InputFileTemplate}) #_RECURSE

set(INDEX 0)

foreach(SRCS_TEST_C_FILE ${SRCS_TEST_C_FILES})
math(EXPR INDEX "${INDEX} + 1")

BuildFile_AndRegressTest(${SRCS_TEST_C_FILE} 0 ${INDEX})

BuildFile_AndRegressTest(${SRCS_TEST_C_FILE} 1 ${INDEX})

BuildFile_AndRegressTest(${SRCS_TEST_C_FILE} 2 ${INDEX})
endforeach()
endfunction()
13 changes: 13 additions & 0 deletions test/gcc-torture/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.10)
project(gcc-torture
DESCRIPTION "gcc-torture project"
)

enable_testing()

include(../TestFunc.cmake)

BuildVmirTest("src/*.c")

# vector-src - not work
#BuildVmirTest("vector-src/*.c")
10 changes: 10 additions & 0 deletions test/misc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.10)
project(test_misc
DESCRIPTION "test_misc project"
)

enable_testing()

include(../TestFunc.cmake)

BuildVmirTest("src/*.c")
13 changes: 13 additions & 0 deletions test/regress/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.10)
project(regress_test
DESCRIPTION "regress_test project"
)

enable_testing()

include(../TestFunc.cmake)

BuildRegressTest("stackl_test/*.c")

BuildRegressTest("c-testsuite/single-exec/*.c")

29 changes: 29 additions & 0 deletions test/regress/c-testsuite/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
https://github.com/c-testsuite/c-testsuite

The licenses of individual test cases can be discovered
by a test cases .otag file.

The following license is for all testing software, but
not for individual test cases. see tests/LICENSE for details.

MIT License

Copyright (c) 2018 Andrew Chambers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions test/regress/c-testsuite/single-exec/00001.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int
main()
{
return 0;
}
Empty file.
2 changes: 2 additions & 0 deletions test/regress/c-testsuite/single-exec/00001.c.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
portable
c89
5 changes: 5 additions & 0 deletions test/regress/c-testsuite/single-exec/00002.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int
main()
{
return 3-3;
}
Empty file.
4 changes: 4 additions & 0 deletions test/regress/c-testsuite/single-exec/00002.c.otags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org=www.simple-cc.org
repository=git://git.simple-cc.org/scc
version=355356a9836e487939cf5e98b5332a63e5264e27
path=tests/scc/execute/0002-expr.c
2 changes: 2 additions & 0 deletions test/regress/c-testsuite/single-exec/00002.c.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
portable
c89
8 changes: 8 additions & 0 deletions test/regress/c-testsuite/single-exec/00003.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
int
main()
{
int x;

x = 4;
return x - 4;
}
Empty file.
4 changes: 4 additions & 0 deletions test/regress/c-testsuite/single-exec/00003.c.otags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org=www.simple-cc.org
repository=git://git.simple-cc.org/scc
version=355356a9836e487939cf5e98b5332a63e5264e27
path=tests/scc/execute/0003-local.c
2 changes: 2 additions & 0 deletions test/regress/c-testsuite/single-exec/00003.c.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
portable
c89
12 changes: 12 additions & 0 deletions test/regress/c-testsuite/single-exec/00004.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
int
main()
{
int x;
int *p;

x = 4;
p = &x;
*p = 0;

return *p;
}
Empty file.
4 changes: 4 additions & 0 deletions test/regress/c-testsuite/single-exec/00004.c.otags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org=www.simple-cc.org
repository=git://git.simple-cc.org/scc
version=355356a9836e487939cf5e98b5332a63e5264e27
path=tests/scc/execute/0004-pointer.c
2 changes: 2 additions & 0 deletions test/regress/c-testsuite/single-exec/00004.c.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
portable
c89
23 changes: 23 additions & 0 deletions test/regress/c-testsuite/single-exec/00005.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
int
main()
{
int x;
int *p;
int **pp;

x = 0;
p = &x;
pp = &p;

if(*p)
return 1;
if(**pp)
return 1;
else
**pp = 1;

if(x)
return 0;
else
return 1;
}
Empty file.
4 changes: 4 additions & 0 deletions test/regress/c-testsuite/single-exec/00005.c.otags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org=www.simple-cc.org
repository=git://git.simple-cc.org/scc
version=355356a9836e487939cf5e98b5332a63e5264e27
path=tests/scc/execute/0005-ifstmt.c
2 changes: 2 additions & 0 deletions test/regress/c-testsuite/single-exec/00005.c.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
portable
c89
10 changes: 10 additions & 0 deletions test/regress/c-testsuite/single-exec/00006.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
int
main()
{
int x;

x = 50;
while (x)
x = x - 1;
return x;
}
Empty file.
4 changes: 4 additions & 0 deletions test/regress/c-testsuite/single-exec/00006.c.otags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org=www.simple-cc.org
repository=git://git.simple-cc.org/scc
version=355356a9836e487939cf5e98b5332a63e5264e27
path=tests/scc/execute/0006-whilestmt.c
2 changes: 2 additions & 0 deletions test/regress/c-testsuite/single-exec/00006.c.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
portable
c89
15 changes: 15 additions & 0 deletions test/regress/c-testsuite/single-exec/00007.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
int
main()
{
int x;

x = 1;
for(x = 10; x; x = x - 1)
;
if(x)
return 1;
x = 10;
for (;x;)
x = x - 1;
return x;
}
Empty file.
4 changes: 4 additions & 0 deletions test/regress/c-testsuite/single-exec/00007.c.otags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org=www.simple-cc.org
repository=git://git.simple-cc.org/scc
version=355356a9836e487939cf5e98b5332a63e5264e27
path=tests/scc/execute/0007-forstmt.c
Loading