Skip to content

Commit 66bdd6f

Browse files
authored
Merge pull request #1575 from clasp-developers/fasl-native
Fasl native (preliminaries)
2 parents ff86964 + 434dbf2 commit 66bdd6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2476
-5140
lines changed

include/clasp/core/bytecode.h

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,53 +24,52 @@ class BytecodeModule_O : public core::CxxObject_O {
2424
LISP_CLASS(core, CorePkg, BytecodeModule_O, "BytecodeModule", core::CxxObject_O);
2525

2626
public:
27-
void initialize();
28-
29-
public:
30-
typedef T_O Literals_O_Type;
31-
typedef T_O Bytecode_O_Type;
32-
typedef T_sp Literals_sp_Type;
33-
typedef T_sp Bytecode_sp_Type;
34-
35-
public:
36-
Literals_sp_Type _Literals;
37-
Bytecode_sp_Type _Bytecode;
38-
// A simple-vector of BytecodeDebugInfo_sp (below)
39-
// ordered by start index
40-
T_sp _DebugInfo = nil<T_O>();
27+
// The actual bytecode.
28+
SimpleVector_byte8_t_sp _Bytecode;
29+
// A simple vector of literal objects referred to by the bytecode.
30+
// During loadltv, this will be default-initialized for a bit, hence
31+
// why it's not a SimpleVector_sp.
32+
T_sp _Literals = nil<T_O>();
4133
// A list of literal indices.
4234
// This indicates the constant at that index is a mutable
4335
// load-time-value (i.e. from (load-time-value foo [nil]))
4436
// which is important to know for BTB compilation.
4537
// Some kind of bit vector could be used instead, but it's
4638
// expected that these load time values will be rare.
4739
T_sp _MutableLiterals = nil<T_O>();
40+
// A simple-vector of BytecodeDebugInfo_sp (below)
41+
// ordered by start index
42+
T_sp _DebugInfo = nil<T_O>();
43+
// If this bytecode has been native-compiled, this can be
44+
// the corresponding JITDylib_sp.
45+
T_sp _NativeModule = nil<T_O>();
4846

4947
public:
50-
BytecodeModule_O(){};
48+
BytecodeModule_O(SimpleVector_byte8_t_sp bytecode)
49+
: _Bytecode(bytecode) {};
5150
CL_LISPIFY_NAME(BytecodeModule/make)
5251
CL_DEF_CLASS_METHOD
53-
static BytecodeModule_sp make() {
52+
static BytecodeModule_sp make(SimpleVector_byte8_t_sp bytecode) {
5453
// When we can gc code allocate entire block in GC memory
55-
BytecodeModule_sp codeblock = gctools::GC<BytecodeModule_O>::allocate<gctools::RuntimeStage>();
54+
BytecodeModule_sp codeblock = gctools::GC<BytecodeModule_O>::allocate<gctools::RuntimeStage>(bytecode);
5655
// Register the new module for the debugger
5756
codeblock->register_for_debug();
5857
return codeblock;
5958
};
6059

61-
Literals_sp_Type literals() const;
62-
void setf_literals(T_sp obj);
63-
Bytecode_sp_Type bytecode() const;
64-
void setf_bytecode(T_sp obj);
65-
Bytecode_sp_Type compileInfo() const;
66-
void setf_compileInfo(T_sp obj);
60+
CL_DEFMETHOD T_sp literals() const { return this->_Literals; }
61+
CL_DEFMETHOD void setf_literals(SimpleVector_sp obj) { this->_Literals = obj; }
62+
CL_DEFMETHOD SimpleVector_byte8_t_sp bytecode() const { return this->_Bytecode; }
6763
CL_LISPIFY_NAME(BytecodeModule/debugInfo)
6864
CL_DEFMETHOD T_sp debugInfo() const { return this->_DebugInfo; }
6965
CL_LISPIFY_NAME(BytecodeModule/setfDebugInfo)
7066
CL_DEFMETHOD void setf_debugInfo(T_sp info) { this->_DebugInfo = info; }
7167
CL_LISPIFY_NAME(BytecodeModule/mutableLiterals)
7268
CL_DEFMETHOD T_sp mutableLiterals() const { return this->_MutableLiterals; }
7369
void setf_mutableLiterals(T_sp indices) { this->_MutableLiterals = indices; }
70+
CL_LISPIFY_NAME(BytecodeModule/nativeModule)
71+
CL_DEFMETHOD T_sp nativeModule() const { return this->_NativeModule; }
72+
void setf_nativeModule(T_sp mod) { this->_NativeModule = mod; }
7473

7574
// Add the module to *all-bytecode-modules* for the debugger.
7675
void register_for_debug();

include/clasp/core/bytecode_compiler.h

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -635,18 +635,18 @@ class JumpIfSuppliedFixup_O : public LabelFixup_O {
635635
LISP_CLASS(comp, CompPkg, JumpIfSuppliedFixup_O, "JumpIfSuppliedFixup", LabelFixup_O);
636636

637637
public:
638-
uint8_t _index;
638+
uint16_t _index;
639639

640640
public:
641-
JumpIfSuppliedFixup_O(Label_sp label, uint8_t index) : LabelFixup_O(label, 3), _index(index) {}
641+
JumpIfSuppliedFixup_O(Label_sp label, uint16_t index) : LabelFixup_O(label, 3), _index(index) {}
642642
CL_LISPIFY_NAME(JumpIfSuppliedFixup/make)
643643
CL_DEF_CLASS_METHOD
644-
static JumpIfSuppliedFixup_sp make(Label_sp label, uint8_t nindex) {
644+
static JumpIfSuppliedFixup_sp make(Label_sp label, uint16_t nindex) {
645645
return gctools::GC<JumpIfSuppliedFixup_O>::allocate<gctools::RuntimeStage>(label, nindex);
646646
}
647647

648648
public:
649-
uint8_t iindex() { return this->_index; }
649+
uint16_t iindex() { return this->_index; }
650650
virtual void emit(size_t position, SimpleVector_byte8_t_sp code);
651651
virtual size_t resize();
652652
};
@@ -816,6 +816,8 @@ class LoadTimeValueInfo_O : public General_O {
816816
bool _read_only_p;
817817

818818
public:
819+
CL_LISPIFY_NAME(LoadTimeValueInfo/make)
820+
CL_DEF_CLASS_METHOD
819821
static LoadTimeValueInfo_sp make(T_sp form, bool read_only_p) {
820822
return gctools::GC<LoadTimeValueInfo_O>::allocate<gctools::RuntimeStage>(form, read_only_p);
821823
}
@@ -843,6 +845,8 @@ class ConstantInfo_O : public General_O {
843845
public:
844846
T_sp _value; // the value of the constant.
845847
public:
848+
CL_LISPIFY_NAME(ConstantInfo/make)
849+
CL_DEF_CLASS_METHOD
846850
static ConstantInfo_sp make(T_sp value) { return gctools::GC<ConstantInfo_O>::allocate<gctools::RuntimeStage>(value); }
847851

848852
public:
@@ -863,6 +867,8 @@ class FunctionCellInfo_O : public General_O {
863867
public:
864868
T_sp _fname; // Name of the function being looked up.
865869
public:
870+
CL_LISPIFY_NAME(FunctionCellInfo/make)
871+
CL_DEF_CLASS_METHOD
866872
static FunctionCellInfo_sp make(T_sp fname) { return gctools::GC<FunctionCellInfo_O>::allocate<gctools::RuntimeStage>(fname); }
867873

868874
public:
@@ -881,6 +887,8 @@ class VariableCellInfo_O : public General_O {
881887
public:
882888
Symbol_sp _vname; // Name of the variable being looked up.
883889
public:
890+
CL_LISPIFY_NAME(VariableCellInfo/make)
891+
CL_DEF_CLASS_METHOD
884892
static VariableCellInfo_sp make(Symbol_sp vname) {
885893
return gctools::GC<VariableCellInfo_O>::allocate<gctools::RuntimeStage>(vname);
886894
}
@@ -898,6 +906,8 @@ class EnvInfo_O : public General_O {
898906
public:
899907
EnvInfo_O() {}
900908
public:
909+
CL_LISPIFY_NAME(EnvInfo/make)
910+
CL_DEF_CLASS_METHOD
901911
static EnvInfo_sp make() {
902912
return gctools::GC<EnvInfo_O>::allocate<gctools::RuntimeStage>();
903913
}
@@ -1000,59 +1010,64 @@ class Cfunction_O : public General_O {
10001010
}
10011011
CL_DEFMETHOD Module_sp module() { return _module; }
10021012
CL_LISPIFY_NAME(cfunction/bytecode)
1003-
CL_DEFMETHOD ComplexVector_byte8_t_sp bytecode() { return _bytecode; }
1004-
CL_DEFMETHOD ComplexVector_T_sp annotations() { return _annotations; }
1013+
CL_DEFMETHOD ComplexVector_byte8_t_sp bytecode() const { return _bytecode; }
1014+
CL_DEFMETHOD ComplexVector_T_sp annotations() const { return _annotations; }
10051015
CL_LISPIFY_NAME(cfunction/debug-info)
1006-
CL_DEFMETHOD ComplexVector_T_sp debug_info() { return _debug_info; }
1007-
CL_DEFMETHOD size_t nlocals() { return _nlocals; }
1016+
CL_DEFMETHOD ComplexVector_T_sp debug_info() const { return _debug_info; }
1017+
CL_DEFMETHOD size_t nlocals() const { return _nlocals; }
10081018
CL_LISPIFY_NAME(Cfunction/setf-nlocals)
10091019
CL_DEFMETHOD size_t setNlocals(size_t new_nlocals) {
10101020
this->_nlocals = new_nlocals;
10111021
return new_nlocals;
10121022
}
1013-
CL_DEFMETHOD ComplexVector_T_sp closed() { return _closed; }
1023+
CL_DEFMETHOD ComplexVector_T_sp closed() const { return _closed; }
10141024
CL_LISPIFY_NAME(Cfunction/entry-point)
1015-
CL_DEFMETHOD Label_sp entry_point() { return _entry_point; }
1025+
CL_DEFMETHOD Label_sp entry_point() const { return _entry_point; }
10161026
CL_LISPIFY_NAME(Cfunction/position)
1017-
CL_DEFMETHOD size_t pposition() { return _position; }
1027+
CL_DEFMETHOD size_t pposition() const { return _position; }
10181028
CL_LISPIFY_NAME(Cfunction/setf-position)
10191029
CL_DEFMETHOD size_t setPosition(size_t npos) {
10201030
this->_position = npos;
10211031
return npos;
10221032
}
1023-
CL_DEFMETHOD size_t extra() { return _extra; }
1033+
CL_DEFMETHOD size_t extra() const { return _extra; }
10241034
CL_LISPIFY_NAME(Cfunction/setf-extra)
10251035
CL_LAMBDA(cfunction new) // avoid name conflict with next
10261036
CL_DEFMETHOD size_t setExtra(size_t next) {
10271037
this->_extra = next;
10281038
return next;
10291039
}
10301040
CL_LISPIFY_NAME(Cfunction/final_size)
1031-
CL_DEFMETHOD size_t final_size() { return this->bytecode()->length() + this->extra(); }
1041+
CL_DEFMETHOD size_t final_size() const { return this->bytecode()->length() + this->extra(); }
10321042
CL_LISPIFY_NAME(Cfunction/index)
1033-
CL_DEFMETHOD size_t iindex() { return _index; }
1043+
CL_DEFMETHOD size_t iindex() const { return _index; }
10341044
CL_LISPIFY_NAME(Cfunction/setf-index)
10351045
CL_DEFMETHOD size_t setIndex(size_t nindex) {
10361046
this->_index = nindex;
10371047
return nindex;
10381048
}
1039-
CL_DEFMETHOD BytecodeSimpleFun_sp info() { return _info; }
1049+
CL_DEFMETHOD BytecodeSimpleFun_sp info() const { return _info; }
10401050
CL_LISPIFY_NAME(Cfunction/setf-info)
10411051
CL_DEFMETHOD BytecodeSimpleFun_sp setInfo(BytecodeSimpleFun_sp gbep) {
10421052
this->_info = gbep;
10431053
return gbep;
10441054
}
10451055
CL_LISPIFY_NAME(Cfunction/name)
1046-
CL_DEFMETHOD T_sp nname() { return _name; }
1047-
CL_DEFMETHOD T_sp doc() { return _doc; }
1056+
CL_DEFMETHOD T_sp nname() const { return _name; }
1057+
CL_DEFMETHOD T_sp doc() const { return _doc; }
10481058
CL_LISPIFY_NAME(Cfunction/lambda-list)
1049-
CL_DEFMETHOD T_sp lambda_list() { return _lambda_list; }
1050-
T_sp sourcePosInfo() { return _source_pos_info; }
1059+
CL_DEFMETHOD T_sp lambda_list() const { return _lambda_list; }
1060+
CL_LISPIFY_NAME(Cfunction/source-pos-info)
1061+
CL_DEFMETHOD T_sp sourcePosInfo() const { return _source_pos_info; }
10511062

10521063
public:
10531064
// Convenience method to link the module and return the new bytecode function
10541065
// corresponding to this cfunction. Good for cl:compile.
10551066
CL_DEFMETHOD Function_sp link_function();
1067+
public:
1068+
// For use as a BytecodeDebugInfo.
1069+
T_sp start() const;
1070+
T_sp end() const;
10561071
};
10571072

10581073
// Main entry point

include/clasp/core/function.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ class SimpleCoreFun_O : public SimpleFun_O {
334334
public:
335335
// Accessors
336336
SimpleCoreFun_O(FunctionDescription_sp fdesc, const ClaspXepTemplate& entry_point, T_sp code, CoreFun_sp localFun);
337+
static SimpleCoreFun_sp make(FunctionDescription_sp fdesc, ClaspCoreFunction main, ClaspXepAnonymousFunction* xep);
337338

338339
public:
339340
virtual Pointer_sp defaultEntryAddress() const;

include/clasp/llvmo/code.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ class ObjectFile_O : public LibraryBase_O {
9393
size_t _FasoIndex;
9494
//
9595
// Code data
96-
gctools::GCRootsInModule* _gcRoots;
9796
void* _TextSectionStart;
9897
void* _TextSectionEnd;
9998
uintptr_t _TextSectionId;
@@ -109,16 +108,16 @@ class ObjectFile_O : public LibraryBase_O {
109108
ObjectFile_O(core::SimpleBaseString_sp codename, std::unique_ptr<llvm::MemoryBuffer> buffer, size_t objectId,
110109
JITDylib_sp jitdylib, core::SimpleBaseString_sp fasoName, size_t fasoIndex)
111110
: _State(RunState), _CodeName(codename), _MemoryBuffer(std::move(buffer)), _ObjectId(objectId), _TheJITDylib(jitdylib),
112-
_FasoName(fasoName), _FasoIndex(fasoIndex), _gcRoots(NULL), _CodeBlock(unbound<CodeBlock_O>()) {
111+
_FasoName(fasoName), _FasoIndex(fasoIndex), _CodeBlock(unbound<CodeBlock_O>()) {
113112
DEBUG_OBJECT_FILES_PRINT(("%s:%d:%s objectId = %lu\n", __FILE__, __LINE__, __FUNCTION__, objectId));
114113
};
115114
ObjectFile_O(core::SimpleBaseString_sp codename, JITDylib_sp jitdylib, size_t objectId)
116-
: _State(RunState), _CodeName(codename), _ObjectId(objectId), _TheJITDylib(jitdylib), _gcRoots(NULL),
115+
: _State(RunState), _CodeName(codename), _ObjectId(objectId), _TheJITDylib(jitdylib),
117116
_CodeBlock(unbound<CodeBlock_O>()) {
118117
DEBUG_OBJECT_FILES_PRINT(("%s:%d:%s codename = %s\n", __FILE__, __LINE__, __FUNCTION__, _rep_(codename).c_str()));
119118
};
120119
ObjectFile_O(core::SimpleBaseString_sp codename, CodeBlock_sp codeBlock, JITDylib_sp dylib, size_t objectId)
121-
: _State(RunState), _CodeName(codename), _ObjectId(objectId), _TheJITDylib(dylib), _gcRoots(NULL), _TextSectionStart(0),
120+
: _State(RunState), _CodeName(codename), _ObjectId(objectId), _TheJITDylib(dylib), _TextSectionStart(0),
122121
_TextSectionEnd(0), _CodeBlock(codeBlock) {
123122
DEBUG_OBJECT_FILES_PRINT(("%s:%d:%s created with CodeBlock_sp codename = %s CodeBlock = %s\n", __FILE__, __LINE__,
124123
__FUNCTION__, _rep_(codename).c_str(), core::_rep_(codeBlock).c_str()));

0 commit comments

Comments
 (0)