Skip to content

Commit aff31a2

Browse files
authored
Merge pull request GaijinEntertainment#2095 from aleksisch/feature/standalone-executable
Feature/standalone executable
2 parents d76a0c9 + bfc6f12 commit aff31a2

23 files changed

Lines changed: 1331 additions & 283 deletions

doc/reflections/das2rst.das

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ def document_module_ast(root : string) {
259259
group_by_regex("Evaluations", mod, %regex~(eval_single_expression)%%),
260260
group_by_regex("Error reporting", mod, %regex~(macro_error)%%),
261261
group_by_regex("Location and context", mod, %regex~(force_at|collect_dependencies|get_ast_context)%%),
262-
// hide_group(group_by_regex("Jit support",mod,%regex~(make_interop_node|get_builtin_function_address)%%));
263262
group_by_regex("Use queries", mod, %regex~(get_use_global_variables|get_use_functions)%%),
264263
group_by_regex("Log", mod, %regex~(to_compilation_log)%%),
265264
group_by_regex("Removal", mod, %regex~(remove.*)%%),

include/daScript/ast/ast.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,9 +1577,10 @@ namespace das
15771577
// todo: add this params to serialization?
15781578
bool jit_jit_all_functions = true; // JIT all functions by default
15791579
bool jit_debug_info = false; // Add debug info to generate binary code
1580-
bool jit_use_dll_mode = true; // Create if missing and reuse DLL or JIT compile
1581-
bool jit_emit_prologue = false; // Emit prologue for all functions and blocks
1582-
string jit_output_folder; // Folder to store compiled dll's. By default it'll be _das_root_/jitted_scripts
1580+
bool jit_dll_mode = true; // Create if missing and reuse DLL or JIT compile
1581+
bool jit_exe_mode = false; // Create executable
1582+
bool jit_emit_prologue = false; // Emit prologue for all functions and blocks
1583+
string jit_output_path; // Folder to store compiled dll's. By default it'll be _das_root_/jitted_scripts
15831584
int32_t jit_opt_level = 3u; // Opt level for LLVM to codegen and IR optimizations
15841585
int32_t jit_size_level = 3u; // Opt level for LLVM for binary size
15851586
string jit_path_to_shared_lib; // Path to libDaScript. Optional, we'll try to find it in _das_root_/lib/ if not provided.

include/daScript/simulate/aot_builtin_jit.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
#pragma once
22

3-
#include "daScript/ast/ast.h"
4-
#include "daScript/ast/ast_expressions.h"
5-
#include "daScript/ast/ast_visitor.h"
3+
#include "daScript/misc/vectypes.h"
4+
#include "daScript/misc/arraytype.h"
5+
#include "daScript/misc/smart_ptr.h"
66

77
namespace das {
8+
9+
class Context;
10+
class LineInfo;
11+
class LineInfoArg;
12+
class Function;
13+
class ExprCallFunc;
14+
class ExprStringBuilder;
15+
16+
struct TypeDecl;
17+
typedef smart_ptr<TypeDecl> TypeDeclPtr;
18+
819
float4 das_invoke_code ( void * pfun, vec4f anything, void * cmres, Context * context );
920
bool das_is_jit_function ( const Func func );
1021
bool das_remove_jit ( const Func func );
@@ -40,8 +51,6 @@ namespace das {
4051
void * das_get_jit_iterator_first();
4152
void * das_get_jit_iterator_next();
4253
void * das_get_builtin_function_address ( Function * fn, Context * context, LineInfoArg * at );
43-
void * das_make_interop_node ( Context & ctx, ExprCallFunc * call, Context * context, LineInfoArg * at );
44-
void * das_sb_make_interop_node ( Context & ctx, ExprStringBuilder * call, Context * context, LineInfoArg * at );
4554
void * das_get_jit_new ( TypeDeclPtr htype, Context * context, LineInfoArg * at );
4655
void * das_get_jit_delete ( TypeDeclPtr htype, Context * context, LineInfoArg * at );
4756
void * das_get_jit_debug_enter ();

include/daScript/simulate/simulate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ namespace das
436436
return (uint32_t(index)<uint32_t(totalVariables)) ? globalVariables[index].debugInfo : nullptr;;
437437
}
438438

439+
__forceinline const GlobalVariable getGlobalVariable( int index ) const {
440+
return globalVariables[index];
441+
}
442+
439443
__forceinline void simEnd() {
440444
thisHelper = nullptr;
441445
}

include/daScript/simulate/simulate_nodes.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -482,37 +482,6 @@ namespace das {
482482
};
483483

484484

485-
typedef vec4f ( * JitFunction ) ( Context * , vec4f *, void * );
486-
487-
struct SimNode_Jit : SimNode {
488-
SimNode_Jit ( const LineInfo & at, JitFunction eval )
489-
: SimNode(at), func(eval) {}
490-
virtual SimNode * visit ( SimVisitor & vis ) override;
491-
DAS_EVAL_ABI virtual vec4f eval ( Context & context ) override;
492-
virtual bool rtti_node_isJit() const override { return true; }
493-
JitFunction func = nullptr;
494-
// saved original node
495-
SimNode * saved_code = nullptr;
496-
bool saved_aot = false;
497-
void * saved_aot_function = nullptr;
498-
};
499-
500-
struct SimNode_JitBlock;
501-
502-
struct JitBlock : Block {
503-
vec4f node[10];
504-
};
505-
506-
struct SimNode_JitBlock : SimNode_ClosureBlock {
507-
SimNode_JitBlock ( const LineInfo & at, JitBlockFunction eval, Block * bptr, uint64_t ad )
508-
: SimNode_ClosureBlock(at,false,false,ad), func(eval), blockPtr(bptr) {}
509-
virtual SimNode * visit ( SimVisitor & vis ) override;
510-
DAS_EVAL_ABI virtual vec4f eval ( Context & context ) override;
511-
JitBlockFunction func = nullptr;
512-
Block * blockPtr = nullptr;
513-
};
514-
static_assert(sizeof(SimNode_JitBlock)<=sizeof(JitBlock().node),"jit block node must fit under node size");
515-
516485
struct SimNode_SourceBase : SimNode {
517486
SimNode_SourceBase ( const LineInfo & at ) : SimNode(at) {}
518487
virtual bool rtti_node_isSourceBase() const override { return true; }

modules/dasLLVM/.das_module

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ require fio
66
def initialize(project_path : string) {
77
let daslib_paths = [
88
"llvm_boost", "llvm_debug", "llvm_jit", "llvm_targets",
9-
"llvm_jit_intrin", "llvm_jit_common", "llvm_dll_utils"
9+
"llvm_jit_intrin", "llvm_jit_common", "llvm_dll_utils",
10+
"llvm_exe"
1011
]
1112
let bindings_paths = [
1213
"llvm_const", "llvm_enum", "llvm_func", "llvm_struct",

modules/dasLLVM/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ code, and saves it as a dynamic (shared) library.
6262
- **Subsequent Runs:** Checks if the source code has changed. If unchanged, loads the
6363
cached DLL for instant execution.
6464
### DLL location
65-
- By default, the `dll` is stored in `get_das_root()/jitted_scripts`.
66-
- This can be changed using `jit_output_folder` (not exposed to `CLI` yet).
65+
- By default, the `dll` is stored in `jitted_scripts/`.
66+
- This can be changed using `jit_output_path`.

modules/dasLLVM/daslib/llvm_boost.das

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ class PrimitiveTypes {
9292
return LLVMPointerType(t_int8, 0u)
9393
}
9494

95+
def ConstI1(val : bool) {
96+
return LLVMConstInt(t_int1, uint64(val ? 1 : 0), 0);
97+
}
98+
9599
def ConstI8(val : int8) {
96100
return LLVMConstInt(t_int8, val |> uint64(), 0);
97101
}
@@ -437,6 +441,26 @@ def describe(blk : LLVMOpaqueBasicBlock?) {
437441
return st
438442
}
439443

444+
def isExprOp2_Func(expr : smart_ptr<ExprOp2>) {
445+
if (!expr.func.flags.builtIn) {
446+
return true
447+
}
448+
if (expr.left._type.isHandle || expr.right._type.isHandle) {
449+
return true
450+
}
451+
return false
452+
}
453+
454+
def isExprOp1_Func(expr : smart_ptr<ExprOp1>) {
455+
if (!expr.func.flags.builtIn) {
456+
return true
457+
}
458+
if (expr.subexpr._type.isHandle) {
459+
return true
460+
}
461+
return false
462+
}
463+
440464
def LLVMSetFunctionCallConv(ofunc : LLVMOpaqueValue?; conv : LLVMCallConv) {
441465
LLVMSetFunctionCallConv(ofunc, uint(conv))
442466
}

modules/dasLLVM/daslib/llvm_dll_utils.das

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ class public UidNodes {
145145
return get_base(get_ptr(expr), "tinfo_{expr.typeexpr.get_mnh}")
146146
}
147147

148-
def get_ascend_tinfo(expr : smart_ptr<ExprAscend>) {
149-
assert(expr.ascendFlags.needTypeInfo)
150-
return get_base(get_ptr(expr), "tinfo_{expr.subexpr._type.get_mnh}")
151-
}
152-
153148
def get_ctor(expr : smart_ptr<ExprMakeStruct>) {
154149
return get_base(get_ptr(expr), "ctor_{expr.constructor}")
155150
}
@@ -158,10 +153,6 @@ class public UidNodes {
158153
return get_base(get_ptr(expr), "call_{get_mangled_name(expr.func)}")
159154
}
160155

161-
def get_string_builder(expr : smart_ptr<ExprStringBuilder>) {
162-
return get_base(get_ptr(expr), "string_builder")
163-
}
164-
165156
def public get_block_name_ptr(blk : ExprBlock?) : DllName {
166157
return get_base(blk, "block_{get_mangled_name(blk)}")
167158
}
@@ -269,6 +260,10 @@ def public add_dll_extension(path : string) {
269260
return "{path}.dll"
270261
}
271262

263+
def public add_exe_extension(path : string) {
264+
return "{path}.exe"
265+
}
266+
272267
def public get_dll_by_path(path : string) : DLLHandle? {
273268
return new DLLHandle(handle = load_dynamic_library(add_dll_extension(path)))
274269
}

0 commit comments

Comments
 (0)