Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
fbshipit-source-id: dcaf44c5cbdcd8e429efecdf573a19cbccc52aa7
  • Loading branch information
facebook-github-bot committed Jul 6, 2019
0 parents commit 4a912a6
Show file tree
Hide file tree
Showing 4,960 changed files with 648,529 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
87 changes: 87 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
AccessModifierOffset: -1
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [ FOR_EACH_RANGE, FOR_EACH, ]
IncludeCategories:
- Regex: '^<.*\.h(pp)?>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...
8 changes: 8 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
Checks: '*,clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,-readability-named-parameter,-misc-unused-parameters,-google-runtime-references,-google-build-using-namespace,-cppcoreguidelines-pro-type-union-access,-google-readability-casting,-readability-implicit-bool-cast,-google-readability-todo,-readability-braces-around-statements,-google-readability-braces-around-statements,-performance-unnecessary-value-param,-misc-unused-using-decls,-modernize-pass-by-value,-modernize-raw-string-literal,-readability-else-after-return'
WarningsAsErrors: ''
HeaderFilterRegex: 'include/hermes'
AnalyzeTemporaryDtors: false
CheckOptions:
...

15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*~
*#
TAGS

# Howtoeven
.howtoeven

# in-tree llvm for buck
hermes/facebook/llvm/llvm
hermes/facebook/llvm/llvm_build*

# buck
buck-out
.buckd
.buckconfig.local
13 changes: 13 additions & 0 deletions API/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the LICENSE
# file in the root directory of this source tree.

set(LLVM_REQUIRES_EH ON)
set(LLVM_REQUIRES_RTTI ON)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${HERMES_JSI_DIR})

add_subdirectory(hermes)

81 changes: 81 additions & 0 deletions API/hermes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the LICENSE
# file in the root directory of this source tree.

set(LLVM_OPTIONAL_SOURCES
hermes.cpp
hermes_tracing.cpp
DebuggerAPI.cpp
SynthTrace.cpp
TraceInterpreter.cpp
TracingRuntime.cpp
CompileJS.cpp
)

set(api_sources
hermes.cpp
DebuggerAPI.cpp
hermes_tracing.cpp
)

if (HERMESVM_SYNTH_REPLAY)
list(APPEND api_sources
SynthTrace.cpp
TraceInterpreter.cpp
TracingRuntime.cpp
)
endif()

add_llvm_library(hermesapi
${api_sources}
LINK_LIBS jsi hermesVMRuntime)

set(hermesapi_compile_flags "")
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
string(APPEND hermesapi_compile_flags " -Wno-non-virtual-dtor")
endif()

set_property(TARGET hermesapi PROPERTY
CXX_STANDARD 14)
set_property(TARGET hermesapi APPEND_STRING PROPERTY
COMPILE_FLAGS ${hermesapi_compile_flags})
set_property(TARGET hermesapi APPEND_STRING PROPERTY
COMPILE_DEFINITIONS "JSI_CREATE_SHARED_LIBRARY")

set(LLVM_LINK_COMPONENTS
Core
Support
)

# Disable EH and RTTI for compileJS
set(LLVM_REQUIRES_EH OFF)
set(LLVM_REQUIRES_RTTI OFF)

add_llvm_library(compileJS STATIC CompileJS.cpp)

# Restore EH and RTTI (Note: At the time of writing, there is no usage of
# add_llvm_library either after this line in this file or in a sub directory.
# However, the values are restored anyways for the sake of sanity.)
set(LLVM_REQUIRES_EH ON)
set(LLVM_REQUIRES_RTTI ON)

add_library(libhermes SHARED ${api_sources})
target_link_libraries(libhermes
jsi
hermesVMRuntime
${CORE_FOUNDATION}
)
set_target_properties(libhermes PROPERTIES
# Declare our dependency on std::make_unique, and export all API symbols
COMPILE_FLAGS "-std=c++14 -fvisibility=default"
# The linker doesn't support -flto -Os, so make sure it's linked with -O3.
# This only affects linking, not compilation, so without -flto it's a no-op.
# In other words, if the compiler flags are -O0 -fno-lto, then the resulting
# library will be -O0 in spite of setting -O3 here.
LINK_FLAGS "-O3 ${OPTIONAL_GC_SECTIONS} ${OPTIONAL_JNI_ONLOAD}"
# Avoid becoming liblibhermes (and there's already a target called 'hermes')
OUTPUT_NAME hermes
)
hermes_link_icu(libhermes)
54 changes: 54 additions & 0 deletions API/hermes/CompileJS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/
#include "CompileJS.h"

#include "hermes/BCGen/HBC/BytecodeProviderFromSrc.h"
#include "hermes/Support/Algorithms.h"

#include "llvm/Support/SHA1.h"

namespace hermes {

bool compileJS(
const std::string &str,
const std::string &sourceURL,
std::string &bytecode,
bool optimize) {
hbc::CompileFlags flags{};
flags.optimize = optimize;

// Note that we are relying the zero termination provided by str.data(),
// because the parser requires it.
auto res = hbc::BCProviderFromSrc::createBCProviderFromSrc(
hermes::make_unique<hermes::Buffer>(
(const uint8_t *)str.data(), str.size()),
sourceURL,
flags);
if (!res.first)
return false;

llvm::raw_string_ostream bcstream(bytecode);

BytecodeGenerationOptions opts(::hermes::EmitBundle);
opts.optimizationEnabled = optimize;

hbc::BytecodeSerializer BS{bcstream, opts};
BS.serialize(
*res.first->getBytecodeModule(),
llvm::SHA1::hash(llvm::makeArrayRef(
reinterpret_cast<const uint8_t *>(str.data()), str.size())));

// Flush to string.
bcstream.flush();
return true;
}

bool compileJS(const std::string &str, std::string &bytecode, bool optimize) {
return compileJS(str, "", bytecode, optimize);
}

} // namespace hermes
34 changes: 34 additions & 0 deletions API/hermes/CompileJS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/
#ifndef HERMES_COMPILEJS_H
#define HERMES_COMPILEJS_H

#include <string>

namespace hermes {

/// Compiles JS source \p str and if compilation is successful, returns true
/// and outputs to \p bytecode otherwise returns false.
/// \param sourceURL this will be used as the "file name" of the buffer for
/// errors, stack traces, etc.
/// NOTE: Doesn't throw any exceptions. It's up to the caller to report failure.
///
/// TODO(30388684): Return opaque object that can be run or serialized.
bool compileJS(
const std::string &str,
const std::string &sourceURL,
std::string &bytecode,
bool optimize = true);

bool compileJS(
const std::string &str,
std::string &bytecode,
bool optimize = true);

} // namespace hermes

#endif
Loading

0 comments on commit 4a912a6

Please sign in to comment.