Skip to content

Commit 5389a1a

Browse files
authored
Merge pull request #1461 from clasp-developers/apple-silicon
Add support for LLVM16 and Apple Silicon (via bytecode)
2 parents a91f0ce + bb10792 commit 5389a1a

File tree

18 files changed

+232
-37
lines changed

18 files changed

+232
-37
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# Version 2.3.0 (LLVM15) Pending
1+
# Version 2.3.0 (LLVM15/LLVM16) Pending
22

33
## Added
44
* Bytecode compiled images via build mode `:bytecode`.
55
* FASL magic number sniffing for CL:LOAD. This enables FASL files to be
66
loaded even if the filename extension is incorrect.
7+
* Preliminary Apple Silicon support. Must be compiled with bytecode
8+
either by specifying `--build-mode=bytecode` when invoking koga or
9+
by adding `:build-mode :bytecode` to the config.sexp file.
10+
* LLVM16 support. LLVM15 is still supported.
711

812
## Changed
913
* Updated to Eclector v0.9.0

include/clasp/core/lispCallingConvention.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ LCC_RETURN_RAW general_entry_point_redirect_7(core::T_O* closure, core::T_O* far
9292

9393

9494
/*! This is X86_64 dependent code */
95-
#if defined(X86_64) && defined(_ADDRESS_MODEL_64)
95+
#if (defined(X86_64) || defined(ARM64)) && defined(_ADDRESS_MODEL_64)
9696

9797
// This is VERY HACKISH
9898
// it's based on the System V Application Binary Interface for X86_64

include/clasp/llvmo/code.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,9 @@ class CodeBlock_O : public core::CxxObject_O {
224224
uintptr_t _HeadOffset;
225225
uintptr_t _TailOffset;
226226
uintptr_t _TotalSize;
227-
#ifdef USE_MMAP_CODEBLOCK
228227
void* _mmapBlock;
229228
uintptr_t _mmapSize;
230-
#else
231229
gctools::GCArray_moveable<uint8_t> _DataCode;
232-
#endif
233230
static constexpr size_t DefaultSize = 8*1024*1024;
234231
public:
235232
template <typename Stage>

include/clasp/llvmo/debugInfoExpose.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ namespace translate {
834834

835835

836836

837+
#if __clang_major__ < 16
837838
namespace translate {
838839
template <>
839840
struct from_object<llvm::Optional<llvm::DIFile::ChecksumInfo<llvm::StringRef>>, std::true_type> {
@@ -873,7 +874,49 @@ struct from_object<llvm::Optional<llvm::DIFile::ChecksumInfo<llvm::StringRef>>,
873874
}
874875
};
875876
};
877+
#else
878+
namespace translate {
879+
template <>
880+
struct from_object<std::optional<llvm::DIFile::ChecksumInfo<llvm::StringRef>>, std::true_type> {
881+
typedef std::optional<llvm::DIFile::ChecksumInfo<llvm::StringRef>> DeclareType;
882+
DeclareType _v;
883+
std::string _Storage;
884+
from_object(core::T_sp object) {
885+
// printf("%s:%d:%s object = %s\n", __FILE__, __LINE__, __FUNCTION__, core::_rep_(object).c_str());
886+
core::SymbolToEnumConverter_sp converter = gc::As<core::SymbolToEnumConverter_sp>(llvmo::_sym_CSKEnum->symbolValue());
887+
if (object.nilp()) {
888+
DeclareType none;
889+
this->_v = none;
890+
// printf("%s:%d:%s ChecksumInfo RESET this->_v -> %d\n", __FILE__, __LINE__, __FUNCTION__, this->_v.hasValue() );
891+
} else if (gc::IsA<core::Symbol_sp>(object)) {
892+
core::Symbol_sp sobject = gc::As<core::Symbol_sp>(object);
893+
this->_Storage = sobject->symbolNameAsString();
894+
llvm::DIFile::ChecksumKind kind = converter->enumForSymbol<llvm::DIFile::ChecksumKind>(sobject);
895+
for ( int p=0; p<this->_Storage.size(); p++ ) {
896+
if (this->_Storage[p] == '-') this->_Storage[p] = '_';
897+
}
898+
llvm::DIFile::ChecksumInfo<llvm::StringRef> checksum(kind,this->_Storage);
899+
this->_v = checksum;
900+
// printf("%s:%d:%s ChecksumInfo kind = %d str = %s \n", __FILE__, __LINE__, __FUNCTION__, kind, this->_Storage.c_str() );
901+
} else {
902+
SIMPLE_ERROR("You must pass a valid Checksum like :CSK_MD5");
903+
}
904+
}
905+
from_object(const from_object& orig) = delete;
906+
from_object(from_object&& orig) : _Storage(std::move(orig._Storage)), _v(orig._v) {
907+
if (this->_v.has_value()) {
908+
// printf("%s:%d:%s from_object move ctor\n", __FILE__, __LINE__, __FUNCTION__ );
909+
llvm::DIFile::ChecksumInfo<llvm::StringRef> checksum(this->_v->Kind,this->_Storage);
910+
this->_v = checksum;
911+
} else {
912+
// printf("%s:%d:%s from_object move ctor NIL\n", __FILE__, __LINE__, __FUNCTION__ );
913+
}
914+
}
915+
};
916+
};
917+
#endif
876918

919+
#if __clang_major__ < 16
877920
namespace translate {
878921
template <>
879922
struct from_object<llvm::Optional<llvm::StringRef>, std::true_type> {
@@ -897,6 +940,31 @@ struct from_object<llvm::Optional<llvm::StringRef>, std::true_type> {
897940
}
898941
};
899942
};
943+
#else
944+
namespace translate {
945+
template <>
946+
struct from_object<std::optional<llvm::StringRef>, std::true_type> {
947+
typedef std::optional<llvm::StringRef> DeclareType;
948+
std::string _Storage;
949+
DeclareType _v;
950+
from_object(core::T_sp object) {
951+
if (object.nilp()) {
952+
DeclareType none;
953+
_v = none;
954+
} else if (gc::IsA<core::String_sp>(object)) {
955+
_Storage = gc::As<core::String_sp>(object)->get_std_string();
956+
_v = _Storage;
957+
} else {
958+
SIMPLE_ERROR("You must pass a String or NIL");
959+
}
960+
}
961+
from_object(const from_object& orig) = delete;
962+
from_object(from_object&& orig) : _Storage(std::move(orig._Storage)), _v(orig._v) {
963+
if (_v.has_value()) _v = _Storage;
964+
}
965+
};
966+
};
967+
#endif
900968

901969
// DIContext_O
902970
namespace llvmo {

include/clasp/llvmo/llvmoExpose.h

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,7 @@ struct from_object<llvm::CodeGenOpt::Level, std::true_type> {
852852
}
853853
};
854854

855+
#if __clang_major__ < 16
855856
template <>
856857
struct from_object<llvm::Optional<llvm::Reloc::Model>, std::true_type> {
857858
typedef llvm::Optional<llvm::Reloc::Model> DeclareType;
@@ -872,6 +873,28 @@ template <>
872873
}
873874
}
874875
};
876+
#else
877+
template <>
878+
struct from_object<std::optional<llvm::Reloc::Model>, std::true_type> {
879+
typedef std::optional<llvm::Reloc::Model> DeclareType;
880+
DeclareType _v;
881+
from_object(T_P object) {
882+
if (object.nilp()) {
883+
// SIMPLE_ERROR(("You must pass a valid RelocModel"));
884+
}
885+
if (core::Symbol_sp so = object.asOrNull<core::Symbol_O>()) {
886+
if ( so == llvmo::_sym_RelocModel_undefined ) {
887+
//printf("%s:%d Leaving llvm::Reloc::Model Undefined\n", __FILE__, __LINE__ );
888+
} else {
889+
core::SymbolToEnumConverter_sp converter = gc::As<core::SymbolToEnumConverter_sp>(llvmo::_sym_RelocModel->symbolValue());
890+
this->_v = converter->enumForSymbol<llvm::Reloc::Model>(so);
891+
}
892+
} else {
893+
SIMPLE_ERROR("You must pass a valid RelocModel or {}", _rep_(llvmo::_sym_RelocModel_undefined));
894+
}
895+
}
896+
};
897+
#endif
875898

876899
template <>
877900
struct from_object<llvm::CodeModel::Model, std::true_type> {
@@ -4685,7 +4708,7 @@ ENUM_TRANSLATOR(llvm::GlobalValue::UnnamedAddr,llvmo::_sym_STARGlobalValueUnname
46854708

46864709

46874710

4688-
4711+
#if __clang_major__ < 16
46894712
namespace translate {
46904713
template <typename T>
46914714
struct from_object<llvm::Optional<T>> {
@@ -4703,6 +4726,25 @@ struct from_object<llvm::Optional<T>> {
47034726
from_object(from_object&& orig) : _v(std::move(orig._v)) {};
47044727
};
47054728
}
4729+
#else
4730+
namespace translate {
4731+
template <typename T>
4732+
struct from_object<std::optional<T>> {
4733+
typedef std::optional<T> DeclareType;
4734+
DeclareType _v;
4735+
from_object(core::T_sp o) {
4736+
if (o.unboundp()) {
4737+
return;
4738+
}
4739+
std::optional<T> val(from_object<T>(o)._v);
4740+
this->_v = val;
4741+
return;
4742+
}
4743+
from_object(const from_object& orig) = delete;
4744+
from_object(from_object&& orig) : _v(std::move(orig._v)) {};
4745+
};
4746+
}
4747+
#endif
47064748

47074749
namespace llvmo {
47084750

src/analysis/clasp_gc.sif

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,10 @@
11111111
:offset-base-ctype "llvmo::CodeBlock_O" :layout-offset-field-names ("_TailOffset")}
11121112
{fixed-field :offset-type-cxx-identifier "ctype_unsigned_long" :offset-ctype "unsigned long"
11131113
:offset-base-ctype "llvmo::CodeBlock_O" :layout-offset-field-names ("_TotalSize")}
1114+
{fixed-field :offset-type-cxx-identifier "RAW_POINTER_OFFSET" :offset-ctype "UnknownType"
1115+
:offset-base-ctype "llvmo::CodeBlock_O" :layout-offset-field-names ("_mmapBlock")}
1116+
{fixed-field :offset-type-cxx-identifier "ctype_unsigned_long" :offset-ctype "unsigned long"
1117+
:offset-base-ctype "llvmo::CodeBlock_O" :layout-offset-field-names ("_mmapSize")}
11141118
{variable-array0 :offset-base-ctype "llvmo::CodeBlock_O" :field-names ("_DataCode" "._Data")}
11151119
{variable-capacity :ctype "unsigned char" :offset-base-ctype "llvmo::CodeBlock_O"
11161120
:length-field-names ("_DataCode" "._MaybeSignedLength")

src/analysis/clasp_gc_cando.sif

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,6 +2967,10 @@
29672967
:offset-base-ctype "llvmo::CodeBlock_O" :layout-offset-field-names ("_TailOffset")}
29682968
{fixed-field :offset-type-cxx-identifier "ctype_unsigned_long" :offset-ctype "unsigned long"
29692969
:offset-base-ctype "llvmo::CodeBlock_O" :layout-offset-field-names ("_TotalSize")}
2970+
{fixed-field :offset-type-cxx-identifier "RAW_POINTER_OFFSET" :offset-ctype "UnknownType"
2971+
:offset-base-ctype "llvmo::CodeBlock_O" :layout-offset-field-names ("_mmapBlock")}
2972+
{fixed-field :offset-type-cxx-identifier "ctype_unsigned_long" :offset-ctype "unsigned long"
2973+
:offset-base-ctype "llvmo::CodeBlock_O" :layout-offset-field-names ("_mmapSize")}
29702974
{variable-array0 :offset-base-ctype "llvmo::CodeBlock_O" :field-names ("_DataCode" "._Data")}
29712975
{variable-capacity :ctype "unsigned char" :offset-base-ctype "llvmo::CodeBlock_O"
29722976
:length-field-names ("_DataCode" "._MaybeSignedLength")
@@ -12867,6 +12871,12 @@
1286712871
{variable-field :offset-type-cxx-identifier "SMART_PTR_OFFSET"
1286812872
:fixup-ctype-offset-type-key "gctools::smart_ptr<core::Symbol_O>"
1286912873
:fixup-ctype-key "chem::AtomInfo" :layout-offset-field-names ("_Type")}
12874+
{variable-field :offset-type-cxx-identifier "ctype_unsigned_long"
12875+
:fixup-ctype-offset-type-key "unsigned long" :fixup-ctype-key "chem::AtomInfo"
12876+
:layout-offset-field-names ("_MoleculeIndex")}
12877+
{variable-field :offset-type-cxx-identifier "ctype_unsigned_long"
12878+
:fixup-ctype-offset-type-key "unsigned long" :fixup-ctype-key "chem::AtomInfo"
12879+
:layout-offset-field-names ("_ResidueIndex")}
1287012880
{container-kind :stamp-name "STAMPWTAG_gctools__GCVector_moveable_gctools__smart_ptr_chem__FFVdw_O__"
1287112881
:stamp-key "gctools::GCVector_moveable<gctools::smart_ptr<chem::FFVdw_O>>"
1287212882
:parent-class "gctools::GCContainer" :lisp-class-base nil

src/asttooling/astExpose1.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,10 @@ void initialize_astExpose() {
508508
scope_Type_TemplateTypeParm.def("desugar", &clang::TemplateTypeParmType::desugar);
509509
scope_Type_SubstTemplateTypeParm.def("desugar", &clang::SubstTemplateTypeParmType::desugar);
510510
scope_Type_TemplateSpecialization.def("getTemplateName", &clang::TemplateSpecializationType::getTemplateName);
511+
#if __clang_major__ < 16
511512
scope_Type_TemplateSpecialization.def("getNumArgs", &clang::TemplateSpecializationType::getNumArgs);
512513
scope_Type_TemplateSpecialization.def("getArg", &clang::TemplateSpecializationType::getArg);
514+
#endif
513515
scope_Type_TemplateSpecialization.def("desugar", &clang::TemplateSpecializationType::desugar);
514516
scope_Type_TemplateSpecialization.def("getAliasedType", &clang::TemplateSpecializationType::getAliasedType);
515517
scope_Type_TemplateSpecialization.def("isTypeAlias", &clang::TemplateSpecializationType::isTypeAlias);

src/asttooling/clangTooling.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,17 @@ CL_DEFUN core::T_sp ast_tooling__clangVersionString() {
526526

527527
core::T_sp ast_tooling__getSingleMatcher(core::T_sp variantMatcher) {
528528
clang::ast_matchers::dynamic::VariantMatcher *vp = gc::As<core::WrappedPointer_sp>(variantMatcher)->cast<clang::ast_matchers::dynamic::VariantMatcher>();
529+
#if __clang_major__ < 16
529530
llvm::Optional<clang::ast_matchers::internal::DynTypedMatcher> dtm = vp->getSingleMatcher();
530531
if (dtm.hasValue()) {
531532
return clbind::Wrapper<clang::ast_matchers::internal::DynTypedMatcher>::make_wrapper(*dtm, reg::registered_class<clang::ast_matchers::internal::DynTypedMatcher>::id);
532533
}
534+
#else
535+
std::optional<clang::ast_matchers::internal::DynTypedMatcher> dtm = vp->getSingleMatcher();
536+
if (dtm.has_value()) {
537+
return clbind::Wrapper<clang::ast_matchers::internal::DynTypedMatcher>::make_wrapper(*dtm, reg::registered_class<clang::ast_matchers::internal::DynTypedMatcher>::id);
538+
}
539+
#endif
533540
return nil<core::T_O>();
534541
};
535542

@@ -998,8 +1005,13 @@ CL_DEFUN core::T_sp ast_tooling__parse_dynamic_matcher(const string& matcher)
9981005
// printf("%s:%d:%s got matcher %s\n", __FILE__, __LINE__, __FUNCTION__, matcher.c_str());
9991006
llvm::StringRef matchersr(matcher);
10001007
clang::ast_matchers::dynamic::Diagnostics error;
1008+
#if __clang_major__ < 16
10011009
llvm::Optional<clang::ast_matchers::dynamic::DynTypedMatcher> Matcher =
10021010
clang::ast_matchers::dynamic::Parser::parseMatcherExpression(matchersr, NULL, NULL, &error);
1011+
#else
1012+
std::optional<clang::ast_matchers::dynamic::DynTypedMatcher> Matcher =
1013+
clang::ast_matchers::dynamic::Parser::parseMatcherExpression(matchersr, NULL, NULL, &error);
1014+
#endif
10031015
if (!Matcher) {
10041016
SIMPLE_ERROR("Could not parse expression {}", matcher);
10051017
}

src/core/backtrace.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,24 @@ static T_sp getSourcePosInfoForAddress(llvmo::DWARFContext_sp dcontext, llvmo::S
135135
}
136136

137137
std::string source_path = info.FileName;
138+
#if __clang_major__ < 16
138139
if (info.Source.hasValue()) {
139140
std::smatch match;
140141
std::string source = info.Source.getValue().str();
141142
if (std::regex_search(source, match, logical_pathname_regex)) {
142143
source_path = match[1];
143144
}
144145
}
145-
146+
#else
147+
if (info.Source.has_value()) {
148+
std::smatch match;
149+
std::string source = info.Source.value().str();
150+
if (std::regex_search(source, match, logical_pathname_regex)) {
151+
source_path = match[1];
152+
}
153+
}
154+
#endif
155+
146156
return core__makeSourcePosInfo(source_path, true, 0, false, info.Line, true, info.Column, true);
147157
}
148158

0 commit comments

Comments
 (0)