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

File tree

21 files changed

+400
-0
lines changed

21 files changed

+400
-0
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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:

0 commit comments

Comments
 (0)