NewLang Project
Yet another programm language
Loading...
Searching...
No Matches
newlang::JIT Class Reference

#include <jit.h>

Inheritance diagram for newlang::JIT:

Public Member Functions

TermPtrConstGetAst ()
 
ContextGetCtx ()
 
 JIT (const StringArray &args={})
 
virtual ~JIT ()
 
void Clear () override
 
 JIT (const JIT &)=delete
 
const JIToperator= (const JIT &)=delete
 
bool CreateMacro (const std::string_view text)
 
ParserPtr GetParser ()
 
ObjPtr Run (const std::string_view str, Obj *args=nullptr)
 
ObjPtr Run (Module *module, Obj *args=nullptr)
 
ObjPtr RunFile (std::string file, Obj *args=nullptr)
 
bool ModuleCreate (FileModule &data, const std::string_view source)
 
std::string MakeCodeModule (const TermPtr &term, std::string_view name, bool is_main)
 
std::string MakeCodeFunction (const TermPtr &term)
 
std::string MakeFuncDeclarations_ (const TermPtr &term)
 
std::string MakeCodeRepl (const std::string_view source, const std::string_view name)
 
void MakeFunctionRecursive_ (const TermPtr &term, std::string &output, const std::string_view module)
 
std::unique_ptr< llvm::Module > MakeLLVMModule (std::string_view source, const std::vector< std::string > opts, std::string temp_dir="")
 
bool MakeObjFile (const std::string_view filename, llvm::Module &module, const std::vector< std::string > opts)
 
bool LinkObjToExec (const std::string_view filename, std::vector< std::string > objs, std::vector< std::string > opts={})
 
bool MakeCppExec (const std::string_view source, const std::string_view filename, std::vector< std::string > opts={})
 
std::string MakeApplicationSource (const TermPtr &ast)
 
- Public Member Functions inherited from newlang::RunTime
void GlobalNameBuildinRegister ()
 
bool RegisterSystemFunc (const char *source)
 
bool RegisterBuildinFunc (std::string proto, void *func)
 
ObjPtr CreateFunction (TermPtr proto, TermPtr block)
 
ObjPtr CreateFunction (TermPtr proto, void *addr)
 
 RunTime (const StringArray &args={})
 
virtual ~RunTime ()
 
void InitInternal (const StringArray args)
 
bool LoadModuleFromFile (const char *name_str, bool init)
 
ObjPtr OpLoadModule (TermPtr term)
 
ObjPtr ObjFromModule (ModulePtr module, TermPtr term)
 
bool UnLoadModule (const char *name_str, bool deinit)
 
ObjPtr ExecModule (const char *module, const char *output, bool cached, Context *ctx)
 
bool RegisterBuildinType (ObjType type, std::vector< std::string > parents)
 
ObjPtr GetTypeFromString (const std::string_view type, bool *has_error=nullptr)
 
std::vector< std::wstring > SelectPredict (std::wstring wstart, size_t overage_count=0)
 
std::vector< std::wstring > SelectPredict (std::string start, size_t overage_count=0)
 
void CreateArgs_ (ObjPtr &args, const TermPtr &term, Context *runner=nullptr)
 
ObjPtr CreateDict (const TermPtr &term, Context *runner=nullptr)
 
ObjPtr CreateTensor (const TermPtr &term, Context *runner=nullptr)
 
int RunMain ()
 
bool CompileCppSource (const std::string_view source, std::string &out, std::vector< std::string > opts={})
 
TermPtr ParseBuildin (const std::string_view src)
 
 RunTime (const RunTime &)=delete
 
const RunTimeoperator= (const RunTime &)=delete
 
- Public Member Functions inherited from newlang::GlobalObjects
bool RegisterObject (bool only_new, const std::string_view name, TermPtr term, Variable var)
 

 
VariablePairFindObject (const std::string_view name)
 
size_t size ()
 
bool AppendModule (ModulePtr module)
 
std::string Dump (const std::string_view filter="", const char delim=';')
 

Static Public Member Functions

static JITReCreate (const StringArray &args={})
 
static JITInstance (const StringArray &args={})
 
static bool LLVMInitialize ()
 
static bool LLVMInitializeJIT ()
 
static bool ModuleCreate (FileModule &data, const std::string_view module_name, const TermPtr &include, const std::string_view source, llvm::Module *bc=nullptr)
 
static std::string ExtractFunctionDecls (const TermPtr &ast, const std::string_view module)
 
static std::string ExtractStaticVars (const TermPtr &ast, const std::string_view module)
 
static std::string MakeBodyFunction (const TermPtr &ast)
 
static std::string MakeFunctionPrototype (const TermPtr &func, const std::string_view module)
 
static std::string RegExpInlineComment (const std::string_view src)
 
static std::string MakeCommentPlace (const TermPtr &term)
 
static std::string ReplaceObjectInEmbedSource (const std::string_view embed, std::vector< std::string > &include, const TermPtr args=nullptr)
 
static std::string MakeMain (const std::vector< std::string > &include)
 
static std::string MakeMainEmbed (const std::string_view embed_source, const std::vector< std::string > &include)
 
static TermPtr MainArgs ()
 
- Static Public Member Functions inherited from newlang::RunTime
static ObjPtr CreateNative (const char *proto, const char *module=nullptr, bool lazzy=false, const char *mangle_name=nullptr)
 
static ObjPtr CreateNative (TermPtr proto, const char *module=nullptr, bool lazzy=false, const char *mangle_name=nullptr)
 
static ObjPtr CreateNative (TermPtr proto, void *addr)
 
static std::string Escape (const std::string_view str)
 

 
static RuntimePtr Init (StringArray args)
 
static RuntimePtr Init (int argc=0, const char **argv=nullptr, const char **penv=nullptr)
 
static std::string NativeNameMangling (const Term *term, RunTime *rt)
 
static std::string NativeNameMangling (std::string_view name)
 
static bool ModuleSave (const FileModule &data, const std::string_view filename, const std::string_view module_name="")
 
static bool ModuleRead (FileModule &data, const std::string_view filename, const std::string_view modulename="")
 
static std::string GetLastErrorMessage ()
 
static ObjType BaseTypeFromString (RunTime *rt, const std::string_view text, bool *has_error=nullptr)
 
static bool pred_compare (const std::string &find, const std::string &str)
 
static bool ExpandFileName (std::string &filename)
 
static void * GetNativeAddress (void *handle, const std::string_view name)
 
static StringArray MakeMainArgs (int argc, const char **argv, const char **penv)
 
static ObjPtr MakeObjArgs (int argc, const char **argv)
 
static std::vector< std::string > SplitChar (std::string_view str, const std::string_view delimiter)
 
static std::vector< std::string > SplitString (const std::string_view str, const std::string_view delim)
 

Public Attributes

StorageTerm::ModuleMapType m_external
 
NameLookupStack m_stack
 
MacroPtr m_macro
 
size_t m_repl_count
 
std::vector< ModulePtrm_module
 
std::vector< std::shared_ptr< Context > > m_ctx
 
clang::IntrusiveRefCntPtr< clang::DiagnosticOptions > DiagOpts
 
clang::TextDiagnosticPrinter * textDiagPrinter
 
clang::IntrusiveRefCntPtr< clang::DiagnosticIDs > pDiagIDs
 
clang::DiagnosticsEngine * pDiagnosticsEngine
 
std::vector< std::string > m_includes
 
- Public Attributes inherited from newlang::RunTime
TermPtr m_main
 
StringArray m_module_loader
 
std::string m_work_dir
 
std::string m_exec_dir
 
std::string m_cache_dir
 
std::string m_temp_dir
 
std::string m_user_dir
 
std::vector< std::string > m_search_dir
 
bool m_assert_enable
 
bool m_load_dsl
 
bool m_embed_source
 
bool m_import_module
 
bool m_import_native
 
bool m_eval_enable
 
bool m_load_runtime
 
bool m_link_rt
 
bool m_link_jit
 
int m_typedef_limit
 
DiagPtr m_diag
 
TermPtr m_main_ast
 
- Public Attributes inherited from newlang::GlobalObjects
ModulePtr m_curr_module
 
std::map< std::string, ModulePtrm_modules
 

Static Public Attributes

static JITm_instance = nullptr
 
- Static Public Attributes inherited from newlang::RunTime
static std::string ffi_file
 
static void * m_ffi_handle = nullptr
 
static ffi_type * m_ffi_type_void = nullptr
 
static ffi_type * m_ffi_type_uint8 = nullptr
 
static ffi_type * m_ffi_type_sint8 = nullptr
 
static ffi_type * m_ffi_type_uint16 = nullptr
 
static ffi_type * m_ffi_type_sint16 = nullptr
 
static ffi_type * m_ffi_type_uint32 = nullptr
 
static ffi_type * m_ffi_type_sint32 = nullptr
 
static ffi_type * m_ffi_type_uint64 = nullptr
 
static ffi_type * m_ffi_type_sint64 = nullptr
 
static ffi_type * m_ffi_type_float = nullptr
 
static ffi_type * m_ffi_type_double = nullptr
 
static ffi_type * m_ffi_type_pointer = nullptr
 
static ffi_prep_cif_typem_ffi_prep_cif = nullptr
 
static ffi_prep_cif_var_typem_ffi_prep_cif_var = nullptr
 
static ffi_call_typem_ffi_call = nullptr
 
static ObjType m_wide_char_type
 
static ffi_type * m_wide_char_type_ffi = nullptr
 
static ObjType m_integer_type
 

Additional Inherited Members

- Public Types inherited from newlang::RunTime
typedef ffi_status ffi_prep_cif_type(ffi_cif *cif, ffi_abi abi, unsigned int nargs, ffi_type *rtype, ffi_type **atypes)
 
typedef ffi_status ffi_prep_cif_var_type(ffi_cif *cif, ffi_abi abi, unsigned int nfixedargs, unsigned int ntotalargs, ffi_type *rtype, ffi_type **atypes)
 
typedef void ffi_call_type(ffi_cif *cif, void(*fn) (void), void *rvalue, void **avalue)
 
- Public Types inherited from newlang::GlobalObjects
typedef std::pair< std::string, VariablePairPairType
 
- Protected Member Functions inherited from newlang::RunTime
bool ParseArgs (StringArray args)
 

Detailed Description

Definition at line 86 of file jit.h.

Constructor & Destructor Documentation

◆ JIT() [1/2]

◆ ~JIT()

virtual newlang::JIT::~JIT ( )
inlinevirtual

Definition at line 116 of file jit.h.

References DiagOpts, pDiagIDs, and pDiagnosticsEngine.

◆ JIT() [2/2]

newlang::JIT::JIT ( const JIT & )
delete

Member Function Documentation

◆ GetAst()

TermPtrConst & newlang::JIT::GetAst ( )
inline

Definition at line 99 of file jit.h.

References m_module.

◆ GetCtx()

Context & newlang::JIT::GetCtx ( )
inline

Definition at line 103 of file jit.h.

References ASSERT, and m_ctx.

Referenced by Run().

◆ Clear()

void newlang::JIT::Clear ( )
inlineoverridevirtual

Reimplemented from newlang::RunTime.

Definition at line 131 of file jit.h.

References newlang::RunTime::Clear(), and m_instance.

◆ ReCreate()

static JIT * newlang::JIT::ReCreate ( const StringArray & args = {})
inlinestatic

Definition at line 141 of file jit.h.

◆ Instance()

static JIT * newlang::JIT::Instance ( const StringArray & args = {})
inlinestatic

Definition at line 146 of file jit.h.

◆ operator=()

const JIT & newlang::JIT::operator= ( const JIT & )
delete

◆ CreateMacro()

bool JIT::CreateMacro ( const std::string_view text)

Definition at line 2783 of file jit.cpp.

References m_macro, and newlang::Parser::ParseTerm().

Referenced by JIT().

◆ LLVMInitialize()

static bool newlang::JIT::LLVMInitialize ( )
inlinestatic

Definition at line 183 of file jit.h.

References LOG_RUNTIME.

Referenced by JIT().

◆ LLVMInitializeJIT()

static bool newlang::JIT::LLVMInitializeJIT ( )
inlinestatic

Definition at line 191 of file jit.h.

Referenced by MakeObjFile().

◆ GetParser()

ParserPtr JIT::GetParser ( )

Definition at line 2535 of file jit.cpp.

References newlang::RunTime::m_diag, and m_macro.

Referenced by Run().

◆ Run() [1/2]

◆ Run() [2/2]

ObjPtr JIT::Run ( Module * module,
Obj * args = nullptr )

Definition at line 2605 of file jit.cpp.

References LOG_RUNTIME.

◆ RunFile()

ObjPtr JIT::RunFile ( std::string file,
Obj * args = nullptr )

Definition at line 2540 of file jit.cpp.

References newlang::RunTime::ExpandFileName(), LOG_RUNTIME, newlang::ReadFile(), and Run().

Referenced by newlang::NLC::Run().

◆ ModuleCreate() [1/2]

bool JIT::ModuleCreate ( FileModule & data,
const std::string_view source )

Definition at line 2638 of file jit.cpp.

◆ ModuleCreate() [2/2]

bool JIT::ModuleCreate ( FileModule & data,
const std::string_view module_name,
const TermPtr & include,
const std::string_view source,
llvm::Module * bc = nullptr )
static

◆ MakeCodeModule()

◆ MakeCodeFunction()

std::string JIT::MakeCodeFunction ( const TermPtr & term)

Definition at line 917 of file jit.cpp.

◆ MakeFuncDeclarations_()

std::string JIT::MakeFuncDeclarations_ ( const TermPtr & term)

Definition at line 921 of file jit.cpp.

◆ MakeCodeRepl()

std::string JIT::MakeCodeRepl ( const std::string_view source,
const std::string_view name )

Definition at line 868 of file jit.cpp.

References result.

◆ MakeFunctionRecursive_()

void JIT::MakeFunctionRecursive_ ( const TermPtr & term,
std::string & output,
const std::string_view module )

◆ MakeLLVMModule()

std::unique_ptr< llvm::Module > JIT::MakeLLVMModule ( std::string_view source,
const std::vector< std::string > opts,
std::string temp_dir = "" )

◆ MakeObjFile()

bool JIT::MakeObjFile ( const std::string_view filename,
llvm::Module & module,
const std::vector< std::string > opts )

Definition at line 584 of file jit.cpp.

References newlang::Error, LLVMInitializeJIT(), and LOG_ERROR.

◆ LinkObjToExec()

bool JIT::LinkObjToExec ( const std::string_view filename,
std::vector< std::string > objs,
std::vector< std::string > opts = {} )

Definition at line 624 of file jit.cpp.

References pDiagnosticsEngine.

◆ ExtractFunctionDecls()

std::string JIT::ExtractFunctionDecls ( const TermPtr & ast,
const std::string_view module )
static

◆ ExtractStaticVars()

std::string JIT::ExtractStaticVars ( const TermPtr & ast,
const std::string_view module )
static

Definition at line 913 of file jit.cpp.

Referenced by MakeCodeModule().

◆ MakeBodyFunction()

std::string JIT::MakeBodyFunction ( const TermPtr & ast)
static

Definition at line 925 of file jit.cpp.

Referenced by MakeCodeModule(), and MakeFunctionRecursive_().

◆ MakeFunctionPrototype()

std::string JIT::MakeFunctionPrototype ( const TermPtr & func,
const std::string_view module )
static

Definition at line 684 of file jit.cpp.

References ASSERT, NEWLANG_NS, NL_PARSER, and result.

Referenced by ExtractFunctionDecls(), MakeCodeModule(), and MakeFunctionRecursive_().

◆ RegExpInlineComment()

std::string JIT::RegExpInlineComment ( const std::string_view src)
static

Definition at line 704 of file jit.cpp.

Referenced by MakeCommentPlace().

◆ MakeCommentPlace()

std::string JIT::MakeCommentPlace ( const TermPtr & term)
static

Definition at line 695 of file jit.cpp.

References RegExpInlineComment().

Referenced by ExtractFunctionDecls(), and MakeFunctionRecursive_().

◆ ReplaceObjectInEmbedSource()

std::string JIT::ReplaceObjectInEmbedSource ( const std::string_view embed,
std::vector< std::string > & include,
const TermPtr args = nullptr )
static

Definition at line 792 of file jit.cpp.

References newlang::MakeName(), and result.

Referenced by MakeApplicationSource().

◆ MakeCppExec()

bool newlang::JIT::MakeCppExec ( const std::string_view source,
const std::string_view filename,
std::vector< std::string > opts = {} )

◆ MakeApplicationSource()

std::string JIT::MakeApplicationSource ( const TermPtr & ast)

◆ MakeMain()

std::string JIT::MakeMain ( const std::vector< std::string > & include)
static

Definition at line 749 of file jit.cpp.

References MakeMainEmbed(), NEWLANG_INDENT_OP, and result.

Referenced by MakeApplicationSource().

◆ MakeMainEmbed()

std::string JIT::MakeMainEmbed ( const std::string_view embed_source,
const std::vector< std::string > & include )
static

◆ MainArgs()

TermPtr JIT::MainArgs ( )
static

Member Data Documentation

◆ m_external

StorageTerm::ModuleMapType newlang::JIT::m_external

Definition at line 89 of file jit.h.

◆ m_stack

NameLookupStack newlang::JIT::m_stack

Definition at line 90 of file jit.h.

Referenced by Run().

◆ m_macro

MacroPtr newlang::JIT::m_macro

Definition at line 93 of file jit.h.

Referenced by CreateMacro(), and GetParser().

◆ m_repl_count

size_t newlang::JIT::m_repl_count

Definition at line 94 of file jit.h.

Referenced by JIT().

◆ m_module

std::vector<ModulePtr> newlang::JIT::m_module

Definition at line 96 of file jit.h.

Referenced by GetAst(), and Run().

◆ m_ctx

std::vector<std::shared_ptr<Context> > newlang::JIT::m_ctx

Definition at line 97 of file jit.h.

Referenced by GetCtx(), and Run().

◆ DiagOpts

clang::IntrusiveRefCntPtr<clang::DiagnosticOptions> newlang::JIT::DiagOpts

Definition at line 108 of file jit.h.

Referenced by JIT(), and ~JIT().

◆ textDiagPrinter

clang::TextDiagnosticPrinter* newlang::JIT::textDiagPrinter

Definition at line 109 of file jit.h.

Referenced by JIT(), and MakeLLVMModule().

◆ pDiagIDs

clang::IntrusiveRefCntPtr<clang::DiagnosticIDs> newlang::JIT::pDiagIDs

Definition at line 110 of file jit.h.

Referenced by JIT(), and ~JIT().

◆ pDiagnosticsEngine

clang::DiagnosticsEngine* newlang::JIT::pDiagnosticsEngine

Definition at line 111 of file jit.h.

Referenced by JIT(), LinkObjToExec(), MakeLLVMModule(), and ~JIT().

◆ m_instance

JIT * JIT::m_instance = nullptr
static

Definition at line 129 of file jit.h.

Referenced by Clear().

◆ m_includes

std::vector<std::string> newlang::JIT::m_includes

Definition at line 260 of file jit.h.

Referenced by MakeApplicationSource().


The documentation for this class was generated from the following files: