Skip to content

Commit 5c412d7

Browse files
mshinwellpoechsel
authored andcommitted
Hack to print OCaml values as pointers or integers (#3)
1 parent a4458c7 commit 5c412d7

21 files changed

+400
-0
lines changed

clang/include/clang/AST/ASTContext.h

+1
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
11491149
CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
11501150
CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
11511151
CanQualType ObjCBuiltinBoolTy;
1152+
CanQualType OCamlValueTy;
11521153
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
11531154
CanQualType SingletonId;
11541155
#include "clang/Basic/OpenCLImageTypes.def"

clang/include/clang/AST/BuiltinTypes.def

+3
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ FLOATING_TYPE(Ibm128, Ibm128Ty)
226226
// This is the type of C++0x 'nullptr'.
227227
BUILTIN_TYPE(NullPtr, NullPtrTy)
228228

229+
// OCaml values
230+
BUILTIN_TYPE(OCamlValue, OCamlValueTy)
231+
229232
// The primitive Objective C 'id' type. The user-visible 'id'
230233
// type is a typedef of an ObjCObjectPointerType to an
231234
// ObjCObjectType with this as its base. In fact, this only ever

clang/lib/AST/ASTContext.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,8 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
14271427

14281428
ObjCSuperType = QualType();
14291429

1430+
InitBuiltinType(OCamlValueTy, BuiltinType::OCamlValue);
1431+
14301432
// void * type
14311433
if (LangOpts.OpenCLGenericAddressSpace) {
14321434
auto Q = VoidTy.getQualifiers();
@@ -2003,6 +2005,10 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
20032005
case Type::Builtin:
20042006
switch (cast<BuiltinType>(T)->getKind()) {
20052007
default: llvm_unreachable("Unknown builtin type!");
2008+
case BuiltinType::OCamlValue:
2009+
Width = 64;
2010+
Align = 64;
2011+
break;
20062012
case BuiltinType::Void:
20072013
// GCC extension: alignof(void) = 8 bits.
20082014
Width = 0;
@@ -3359,6 +3365,7 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,
33593365
llvm_unreachable("should never get here");
33603366
case BuiltinType::AMDGPUBufferRsrc:
33613367
case BuiltinType::WasmExternRef:
3368+
case BuiltinType::OCamlValue:
33623369
#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
33633370
#include "clang/Basic/RISCVVTypes.def"
33643371
llvm_unreachable("not yet implemented");
@@ -8509,6 +8516,9 @@ static char getObjCEncodingForPrimitiveType(const ASTContext *C,
85098516
return ' ';
85108517
}
85118518

8519+
case BuiltinType::OCamlValue:
8520+
llvm_unreachable("@encoding OCaml value type");
8521+
85128522
case BuiltinType::ObjCId:
85138523
case BuiltinType::ObjCClass:
85148524
case BuiltinType::ObjCSel:

clang/lib/AST/ExprConstant.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -11849,6 +11849,7 @@ GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
1184911849

1185011850
case BuiltinType::NullPtr:
1185111851

11852+
case BuiltinType::OCamlValue:
1185211853
case BuiltinType::ObjCId:
1185311854
case BuiltinType::ObjCClass:
1185411855
case BuiltinType::ObjCSel:

clang/lib/AST/ItaniumMangle.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3329,6 +3329,9 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
33293329
Out << "Dn";
33303330
break;
33313331

3332+
case BuiltinType::OCamlValue:
3333+
llvm_unreachable("mangling an OCaml value type");
3334+
33323335
#define BUILTIN_TYPE(Id, SingletonId)
33333336
#define PLACEHOLDER_TYPE(Id, SingletonId) \
33343337
case BuiltinType::Id:

clang/lib/AST/MicrosoftMangle.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2635,6 +2635,9 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
26352635
case BuiltinType::Dependent:
26362636
llvm_unreachable("placeholder types shouldn't get to name mangling");
26372637

2638+
case BuiltinType::OCamlValue:
2639+
llvm_unreachable("cannot mangle OCaml value types");
2640+
26382641
case BuiltinType::ObjCId:
26392642
mangleArtificialTagType(TagTypeKind::Struct, "objc_object");
26402643
break;

clang/lib/AST/NSAPI.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ NSAPI::getNSNumberFactoryMethodKind(QualType T) const {
429429
case BuiltinType::Float128:
430430
case BuiltinType::Ibm128:
431431
case BuiltinType::NullPtr:
432+
case BuiltinType::OCamlValue:
432433
case BuiltinType::ObjCClass:
433434
case BuiltinType::ObjCId:
434435
case BuiltinType::ObjCSel:

clang/lib/AST/Type.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3402,6 +3402,8 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
34023402
return "<ARC unbridged cast type>";
34033403
case BuiltinFn:
34043404
return "<builtin fn type>";
3405+
case OCamlValue:
3406+
return "ocaml_value";
34053407
case ObjCId:
34063408
return "id";
34073409
case ObjCClass:
@@ -4760,6 +4762,7 @@ bool Type::canHaveNullability(bool ResultIfUnknown) const {
47604762
return ResultIfUnknown;
47614763

47624764
case BuiltinType::Void:
4765+
case BuiltinType::OCamlValue:
47634766
case BuiltinType::ObjCId:
47644767
case BuiltinType::ObjCClass:
47654768
case BuiltinType::ObjCSel:

clang/lib/AST/TypeLoc.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const {
404404
case BuiltinType::UnknownAny:
405405
case BuiltinType::ARCUnbridgedCast:
406406
case BuiltinType::PseudoObject:
407+
case BuiltinType::OCamlValue:
407408
case BuiltinType::ObjCId:
408409
case BuiltinType::ObjCClass:
409410
case BuiltinType::ObjCSel:

clang/lib/CodeGen/CGDebugInfo.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
903903
case BuiltinType::Long:
904904
case BuiltinType::WChar_S:
905905
case BuiltinType::LongLong:
906+
case BuiltinType::OCamlValue:
906907
Encoding = llvm::dwarf::DW_ATE_signed;
907908
break;
908909
case BuiltinType::Bool:

clang/lib/CodeGen/CodeGenTypes.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
446446
case BuiltinType::SatUShortFract:
447447
case BuiltinType::SatUFract:
448448
case BuiltinType::SatULongFract:
449+
case BuiltinType::OCamlValue:
449450
ResultType = llvm::IntegerType::get(getLLVMContext(),
450451
static_cast<unsigned>(Context.getTypeSize(T)));
451452
break;

clang/lib/CodeGen/ItaniumCXXABI.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -3658,6 +3658,7 @@ static bool TypeInfoIsInStandardLibrary(const BuiltinType *Ty) {
36583658
case BuiltinType::SatUFract:
36593659
case BuiltinType::SatULongFract:
36603660
case BuiltinType::BFloat16:
3661+
case BuiltinType::OCamlValue:
36613662
return false;
36623663

36633664
case BuiltinType::Dependent:

clang/lib/Index/USRGeneration.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,8 @@ void USRGenerator::VisitType(QualType T) {
843843
Out << 'O'; break;
844844
case BuiltinType::ObjCSel:
845845
Out << 'e'; break;
846+
case BuiltinType::OCamlValue:
847+
Out << "@BT@OCamlValue"; break;
846848
#define BUILTIN_TYPE(Id, SingletonId)
847849
#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
848850
#include "clang/AST/BuiltinTypes.def"

clang/lib/Serialization/ASTCommon.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ serialization::TypeIdxFromBuiltin(const BuiltinType *BT) {
281281
case BuiltinType::BFloat16:
282282
ID = PREDEF_TYPE_BFLOAT16_ID;
283283
break;
284+
case BuiltinType::OCamlValue:
285+
llvm_unreachable("not implemented");
284286
}
285287

286288
return TypeIdx(0, ID);

clang/tools/libclang/CIndex.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,7 @@ bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
16251625
case BuiltinType::Void:
16261626
case BuiltinType::NullPtr:
16271627
case BuiltinType::Dependent:
1628+
case BuiltinType::OCamlValue:
16281629
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
16291630
case BuiltinType::Id:
16301631
#include "clang/Basic/OpenCLImageTypes.def"

lldb/include/lldb/lldb-enumerations.h

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ enum Format {
200200
eFormatInstruction, ///< Disassemble an opcode
201201
eFormatVoid, ///< Do not print this
202202
eFormatUnicode8,
203+
eFormatOCamlValue,
203204
kNumFormats
204205
};
205206

@@ -826,6 +827,7 @@ enum BasicType {
826827
eBasicTypeObjCClass,
827828
eBasicTypeObjCSel,
828829
eBasicTypeNullPtr,
830+
eBasicTypeOCamlValue,
829831
eBasicTypeOther
830832
};
831833

lldb/source/Commands/CommandObjectMemory.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
13491349
case eFormatVectorOfFloat32:
13501350
case eFormatVectorOfFloat64:
13511351
case eFormatVectorOfUInt128:
1352+
case eFormatOCamlValue:
13521353
case eFormatOSType:
13531354
case eFormatComplexInteger:
13541355
case eFormatAddressInfo:

0 commit comments

Comments
 (0)