Skip to content

Commit

Permalink
jit: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
riptl authored and ripatel-fd committed Aug 5, 2024
1 parent be3502d commit 35ef963
Show file tree
Hide file tree
Showing 9 changed files with 2,817 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
src/flamenco/types/fd_types.h linguist-generated=true
src/flamenco/types/fd_types.c linguist-generated=true
src/flamenco/vm/jit/fd_vm_jitproto.c linguist-generated=true
*.pb.h linguist-generated=true
*.pb.c linguist-generated=true
corpus/** binary
29 changes: 29 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,32 @@ 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.

=======================================================================

The dasm header files in src/flamenco/vm/jit are copied from the LuaJIT
project. https://luajit.org/ Imported ca 2024-Aug.

LuaJIT -- a Just-In-Time Compiler for Lua. https://luajit.org/

Copyright (C) 2005-2023 Mike Pall. All rights reserved.

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.

[ MIT license: https://www.opensource.org/licenses/mit-license.php ]
7 changes: 7 additions & 0 deletions deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,15 @@ fetch () {
checkout_repo zlib https://github.com/madler/zlib "v1.3.1"
checkout_repo rocksdb https://github.com/facebook/rocksdb "v9.4.0"
checkout_repo snappy https://github.com/google/snappy "1.2.1"
checkout_repo luajit https://github.com/LuaJIT/LuaJIT "v2.0.5"
fi
}

check_fedora_pkgs () {
local REQUIRED_RPMS=( perl autoconf gettext-devel automake flex bison cmake clang gmp-devel protobuf-compiler llvm-toolset lcov systemd-devel pkgconf )
if [[ $DEVMODE == 1 ]]; then
REQUIRED_RPMS+=( lua5.1 lua5.1-bitop )
fi

echo "[~] Checking for required RPM packages"

Expand All @@ -139,6 +143,9 @@ check_fedora_pkgs () {

check_debian_pkgs () {
local REQUIRED_DEBS=( perl autoconf gettext automake autopoint flex bison build-essential gcc-multilib protobuf-compiler llvm lcov libgmp-dev libudev-dev cmake libclang-dev pkgconf )
if [[ $DEVMODE == 1 ]]; then
REQUIRED_DEBS+=( lua5.1 lua5.1-bitop )
fi

echo "[~] Checking for required DEB packages"

Expand Down
3 changes: 3 additions & 0 deletions src/flamenco/vm/jit/Local.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ifdef FD_HAS_X86
$(call make-bin,fd_vm_jitproto,fd_vm_jitproto,fd_flamenco fd_disco fd_funk fd_ballet fd_util,$(SECP256K1_LIBS))
endif
14 changes: 14 additions & 0 deletions src/flamenco/vm/jit/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Run 'make vendor' to refresh dynasm headers from the latest LuaJIT checkout.

LUA ?= lua-5.1

.PHONY: generate
generate: fd_vm_jitproto.c

fd_vm_jitproto.c: fd_vm_jitproto.dasc
$(LUA) ../../../../opt/git/luajit/dynasm/dynasm.lua -o $@ $<

.PHONY: vendor
vendor:
rm -v dasm_{proto,x86}.h
cp ../../../../opt/git/luajit/dynasm/dasm_{proto,x86}.h .
83 changes: 83 additions & 0 deletions src/flamenco/vm/jit/dasm_proto.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
** DynASM encoding engine prototypes.
** Copyright (C) 2005-2017 Mike Pall. All rights reserved.
** Released under the MIT license. See dynasm.lua for full copyright notice.
*/

#ifndef _DASM_PROTO_H
#define _DASM_PROTO_H

#include <stddef.h>
#include <stdarg.h>

#define DASM_IDENT "DynASM 1.3.0"
#define DASM_VERSION 10300 /* 1.3.0 */

#ifndef Dst_DECL
#define Dst_DECL dasm_State **Dst
#endif

#ifndef Dst_REF
#define Dst_REF (*Dst)
#endif

#ifndef DASM_FDEF
#define DASM_FDEF extern
#endif

#ifndef DASM_M_GROW
#define DASM_M_GROW(ctx, t, p, sz, need) \
do { \
size_t _sz = (sz), _need = (need); \
if (_sz < _need) { \
if (_sz < 16) _sz = 16; \
while (_sz < _need) _sz += _sz; \
(p) = (t *)realloc((p), _sz); \
if ((p) == NULL) exit(1); \
(sz) = _sz; \
} \
} while(0)
#endif

#ifndef DASM_M_FREE
#define DASM_M_FREE(ctx, p, sz) free(p)
#endif

/* Internal DynASM encoder state. */
typedef struct dasm_State dasm_State;


/* Initialize and free DynASM state. */
DASM_FDEF void dasm_init(Dst_DECL, int maxsection);
DASM_FDEF void dasm_free(Dst_DECL);

/* Setup global array. Must be called before dasm_setup(). */
DASM_FDEF void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl);

/* Grow PC label array. Can be called after dasm_setup(), too. */
DASM_FDEF void dasm_growpc(Dst_DECL, unsigned int maxpc);

/* Setup encoder. */
DASM_FDEF void dasm_setup(Dst_DECL, const void *actionlist);

/* Feed encoder with actions. Calls are generated by pre-processor. */
DASM_FDEF void dasm_put(Dst_DECL, int start, ...);

/* Link sections and return the resulting size. */
DASM_FDEF int dasm_link(Dst_DECL, size_t *szp);

/* Encode sections into buffer. */
DASM_FDEF int dasm_encode(Dst_DECL, void *buffer);

/* Get PC label offset. */
DASM_FDEF int dasm_getpclabel(Dst_DECL, unsigned int pc);

#ifdef DASM_CHECKS
/* Optional sanity checker to call between isolated encoding steps. */
DASM_FDEF int dasm_checkstep(Dst_DECL, int secmatch);
#else
#define dasm_checkstep(a, b) 0
#endif


#endif /* _DASM_PROTO_H */
Loading

0 comments on commit 35ef963

Please sign in to comment.