Skip to content

Commit

Permalink
Squashed 'NativeJIT/' content from commit 04dd240
Browse files Browse the repository at this point in the history
git-subtree-dir: NativeJIT
git-subtree-split: 04dd240282ebe92a3b0271a0c6725cbfc3bded15
  • Loading branch information
danluu committed Nov 7, 2016
0 parents commit 7bd8a00
Show file tree
Hide file tree
Showing 434 changed files with 236,024 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .gitignore
@@ -0,0 +1,24 @@
# Emacs
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

# Other
.DS_Store
build/
build-*/
Debug/
Release/
ipch
*.obj
*.opensdf
*.sdf
*.suo
*.user
*.db

45 changes: 45 additions & 0 deletions .travis.yml
@@ -0,0 +1,45 @@
# sudo required and trusty used as a hack to get a newer cmake.

# sudo: required
# dist: trusty
# language: generic

# cache:
# apt: true


# matrix:
# include:
# - os: linux
# env: CXX=g++-5 CC=gcc-5
# addons:
# apt:
# packages:
# - cmake
# - g++-5
# sources: &sources
# - ubuntu-toolchain-r-test
# - llvm-toolchain-precise-3.8
# - os: linux
# env: CXX=clang++-3.8 CC=clang-3.8
# addons:
# apt:
# packages:
# - cmake
# - clang-3.8
# sources: *sources

# # The build scripts.
# script:
# - uname -a
# - ulimit -a
# - ./Configure_Make.sh
# - cd build-make
# - make -j2
# - make check

# notifications:
# email:
# - mhop@microsoft.com
# - aclemmer@microsoft.com
# - danluu@microsoft.com
78 changes: 78 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,78 @@
# NativeJIT

cmake_minimum_required(VERSION 2.6)

# Remove the warning that WIN32 is not defined in Cygwin any more.
set(CMAKE_LEGACY_CYGWIN_WIN32 0)

# Project-wide settings for NativeJIT
project(NativeJIT CXX C)

###############################################################################

# gtest

add_subdirectory(googletest)

include_directories(
${gtest_SOURCE_DIR}/include
)

###############################################################################

if (WIN32 OR CYGWIN)
set(NATIVEJIT_PLATFORM_POSIX 0)
set(NATIVEJIT_PLATFORM_WINDOWS 1)
else()
set(NATIVEJIT_PLATFORM_POSIX 1)
set(NATIVEJIT_PLATFORM_WINDOWS 0)
endif()

if(NATIVEJIT_PLATFORM_WINDOWS)
# Note: -D works for both MSVC and GCC/Clang.
set(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} -DNATIVEJIT_PLATFORM_WINDOWS")
else()
set(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} -DNATIVEJIT_PLATFORM_POSIX")
endif()


set(GTEST_REQUIRED_FLAGS "-Wno-shift-sign-overflow -Wno-missing-noreturn -Wno-used-but-marked-unused -Wno-deprecated -Wno-missing-variable-declarations -Wno-global-constructors -Wno-weak-vtables")
set(WEVERYTHING_FLAGS "-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic ${GTEST_REQUIRED_FLAGS}")

if(MSVC)
set(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /W4 /WX")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COMMON_CXX_FLAGS} /MTd")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COMMON_CXX_FLAGS} /MT")
elseif(CMAKE_COMPILER_IS_GNUCXX)
# Need gnu++ instead of c++ so that GTest can access fdopen() etc.
set(CMAKE_CXX_FLAGS "-march=native -std=gnu++14 -Wall -Wextra -Werror -Wold-style-cast -fstrict-aliasing -Wstrict-aliasing")
else()
# TODO: define a target for -Weverything.
# set(CMAKE_CXX_FLAGS "-msse4.2 -std=c++14 -Wall -Wextra -Werror -Wold-style-cast ${WEVERYTHING_FLAGS}")
set(CMAKE_CXX_FLAGS "-march=native -std=c++14 -Wall -Wextra -Werror -Wold-style-cast")
endif()


# This allows the solution to group projects into folders like src and test.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

enable_testing()

include_directories(inc)
add_subdirectory(src/CodeGen)
add_subdirectory(src/NativeJIT)
add_subdirectory(test/CodeGen)
add_subdirectory(test/NativeJIT)
add_subdirectory(test/Shared)
add_subdirectory(Examples)

add_custom_target(TOPLEVEL_NATIVEJIT SOURCES
Configure_Make.bat
Configure_Make.sh
Configure_MSVC.bat
LICENSE.txt
README.md
)

set(ENV{GTEST_COLOR} 1)
# add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
28 changes: 28 additions & 0 deletions Configure_MSVC.bat
@@ -0,0 +1,28 @@
rem The MIT License (MIT)

rem Copyright (c) 2016, Microsoft

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

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

rem THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
rem IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
rem FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
rem AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
rem LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
rem OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
rem THE SOFTWARE.

setlocal

mkdir build-msvc
pushd build-msvc
cmake -G "Visual Studio 14 2015 Win64" ..
popd
28 changes: 28 additions & 0 deletions Configure_Make.bat
@@ -0,0 +1,28 @@
rem The MIT License (MIT)

rem Copyright (c) 2016, Microsoft

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

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

rem THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
rem IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
rem FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
rem AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
rem LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
rem OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
rem THE SOFTWARE.

setlocal

mkdir build-make
pushd build-make
cmake -G "MinGW Makefiles" ..
popd
28 changes: 28 additions & 0 deletions Configure_Make.sh
@@ -0,0 +1,28 @@
# The MIT License (MIT)

# Copyright (c) 2016, Microsoft

# 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.

#!/bin/sh

echo "Configuring CMake for make."
mkdir build-make
cd build-make
cmake -G "Unix Makefiles" ..
29 changes: 29 additions & 0 deletions Configure_XCode.sh
@@ -0,0 +1,29 @@
# The MIT License (MIT)

# Copyright (c) 2016, Microsoft

# 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.

#!/bin/sh

echo "Configuring CMake for XCode."
mkdir build-osx-xcode
cd build-osx-xcode
cmake -G Xcode ..

72 changes: 72 additions & 0 deletions Examples/AreaOfCircle/AreaOfCircle.cpp
@@ -0,0 +1,72 @@
#include "NativeJIT/CodeGen/ExecutionBuffer.h"
#include "NativeJIT/CodeGen/FunctionBuffer.h"
#include "NativeJIT/Function.h"
#include "Temporary/Allocator.h"

#include <iostream>

using NativeJIT::Allocator;
using NativeJIT::ExecutionBuffer;
using NativeJIT::Function;
using NativeJIT::FunctionBuffer;

///////////////////////////////////////////////////////////////////////////////
//
// This example JITs a function that computes the area of a circle, given
// its radius.
//
// Here is a disassembly of the generated code.
//
//
// PI_CONSTANT:
// db 0f 49 40 ; PI constant is stored in memory.
// ENTRY_POINT:
// sub rsp, 28h ; Standard function prolog
// mov qword ptr[rsp], rbp
// movaps xmmword ptr[rsp + 10h], xmm15
// lea rbp, [rsp + 28h]
//
// movss xmm15, xmm0 ; Load radius from first parameter register.
// mulss xmm15, xmm0 ; Multiply by radius.
// mulss xmm15, dword ptr[PI_CONSTANT] ; Multiply by PI.
// movss xmm0, xmm15 ; Return value goes in xmm0.
//
// movaps xmm15, xmmword ptr[rsp + 10h] ; Standard function epilog.
// mov rbp, qword ptr[rsp]
// add rsp, 28h
// ret
//
// TODO: There seems to be a bug in the regster allocator. The generated
// code never should have used xmm15. It should have been
// mulss xmm0, xmm0
// mulss xmm0, dword ptr[PI_CONSTANT]
//
///////////////////////////////////////////////////////////////////////////////
int main()
{
// Create allocator and buffers for pre-compiled and post-compiled code.
ExecutionBuffer codeAllocator(8192);
Allocator allocator(8192);
FunctionBuffer code(codeAllocator, 8192);

// Create the factory for expression nodes.
// Our area expression will take a single float parameter and return a float.
Function<float, float> expression(allocator, code);

// Multiply input parameter by itself to get radius squared.
auto & rsquared = expression.Mul(expression.GetP1(), expression.GetP1());

// Multiply by PI.
const float PI = 3.14159265358979f;
auto & area = expression.Mul(rsquared, expression.Immediate(PI));

// Compile expression into a function.
auto function = expression.Compile(area);

// Now run our expression!
float radius = 2.0;
std::cout << "The area of a circle with radius " << radius
<< " is " << function(radius) << "." << std::endl;

return 0;
}
22 changes: 22 additions & 0 deletions Examples/AreaOfCircle/CMakeLists.txt
@@ -0,0 +1,22 @@
# NativeJIT/Examples/AreaOfCircle

set(CPPFILES
AreaOfCircle.cpp
)

set(PRIVATE_HFILES
)

# This include_directories is redundant because the root CMakeLists.txt
# for NativeJIT sets it correctly. If you build this example outside of
# the NativeJIT project, be sure to update the include_directories to
# point to the inc subdirectory of NativeJIT.
include_directories(${PROJECT_SOURCE_DIR}/inc)

add_executable(AreaOfCircle ${CPPFILES} ${PRIVATE_HFILES})
target_link_libraries (AreaOfCircle CodeGen NativeJIT)

# This line makes AreaOfCircle appear in the correct VS solution
# folder in the NativeJIT project. Delete this line if building
# outside of NativeJIT.
set_property(TARGET AreaOfCircle PROPERTY FOLDER "Examples")
2 changes: 2 additions & 0 deletions Examples/CMakeLists.txt
@@ -0,0 +1,2 @@
add_subdirectory(AreaOfCircle)
add_subdirectory(Parser)
22 changes: 22 additions & 0 deletions Examples/Parser/CMakeLists.txt
@@ -0,0 +1,22 @@
# NativeJIT/Examples/Parser.cpp

set(CPPFILES
Parser.cpp
)

set(PRIVATE_HFILES
)

# This include_directories is redundant because the root CMakeLists.txt
# for NativeJIT sets it correctly. If you build this example outside of
# the NativeJIT project, be sure to update the include_directories to
# point to the inc subdirectory of NativeJIT.
include_directories(${PROJECT_SOURCE_DIR}/inc)

add_executable(Parser ${CPPFILES} ${PRIVATE_HFILES})
target_link_libraries (Parser CodeGen NativeJIT)

# This line makes AreaOfCircle appear in the correct VS solution
# folder in the NativeJIT project. Delete this line if building
# outside of NativeJIT.
set_property(TARGET Parser PROPERTY FOLDER "Examples")

0 comments on commit 7bd8a00

Please sign in to comment.