aboutsummaryrefslogtreecommitdiff
path: root/source/Symbol/OCamlASTContext.cpp
blob: d459be3c23d248dc0934bf8b23ad7fcb66601304 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
//===-- OCamlASTContext.cpp ----------------------------------------*- C++
//-*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lldb/Symbol/OCamlASTContext.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/Type.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Target.h"

#include "Plugins/SymbolFile/DWARF/DWARFASTParserOCaml.h"

using namespace lldb;
using namespace lldb_private;

namespace lldb_private {
class OCamlASTContext::OCamlType {
public:
  enum LLVMCastKind {
    eKindPrimitive,
    eKindObject,
    eKindReference,
    eKindArray,
    kNumKinds
  };

  OCamlType(LLVMCastKind kind) : m_kind(kind) {}

  virtual ~OCamlType() = default;

  virtual ConstString GetName() = 0;

  virtual void Dump(Stream *s) = 0;

  virtual bool IsCompleteType() = 0;

  LLVMCastKind getKind() const { return m_kind; }

private:
  LLVMCastKind m_kind;
};

} // end of namespace lldb_private

namespace {

class OCamlPrimitiveType : public OCamlASTContext::OCamlType {
public:
  enum TypeKind {
    eTypeInt,
  };

  OCamlPrimitiveType(TypeKind type_kind, uint32_t byte_size)
      : OCamlType(OCamlType::eKindPrimitive), m_type_kind(type_kind),
        m_type(ConstString()), m_byte_size(byte_size) {}

  OCamlPrimitiveType(TypeKind type_kind, ConstString s, uint32_t byte_size)
      : OCamlType(OCamlType::eKindPrimitive), m_type_kind(type_kind), m_type(s),
        m_byte_size(byte_size) {}

  ConstString GetName() override {
    switch (m_type_kind) {
    case eTypeInt:
      return m_type;
    }
    return ConstString();
  }

  TypeKind GetTypeKind() { return m_type_kind; }

  void Dump(Stream *s) override { s->Printf("%s\n", GetName().GetCString()); }

  bool IsCompleteType() override { return true; }

  static bool classof(const OCamlType *ot) {
    return ot->getKind() == OCamlType::eKindPrimitive;
  }

  uint64_t GetByteSize() const { return m_byte_size; }

private:
  const TypeKind m_type_kind;
  const ConstString m_type;
  uint64_t m_byte_size;
};
}

OCamlASTContext::OCamlASTContext()
    : TypeSystem(eKindOCaml), m_pointer_byte_size(0) {}

OCamlASTContext::~OCamlASTContext() {}

ConstString OCamlASTContext::GetPluginNameStatic() {
  return ConstString("ocaml");
}

ConstString OCamlASTContext::GetPluginName() {
  return OCamlASTContext::GetPluginNameStatic();
}

uint32_t OCamlASTContext::GetPluginVersion() { return 1; }

lldb::TypeSystemSP OCamlASTContext::CreateInstance(lldb::LanguageType language,
                                                   Module *module,
                                                   Target *target) {
  Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_LANGUAGE));

  if (language == lldb::eLanguageTypeOCaml) {
    std::shared_ptr<OCamlASTContext> ocaml_ast_sp;
    ArchSpec arch;

    if (module) {
      arch = module->GetArchitecture();

      ObjectFile *objfile = module->GetObjectFile();
      ArchSpec object_arch;

      if (!objfile || !objfile->GetArchitecture(object_arch))
        return lldb::TypeSystemSP();

      ocaml_ast_sp = std::shared_ptr<OCamlASTContext>(new OCamlASTContext);

      if (log) {
        log->Printf(
            "((Module*)%p) [%s]->GetOCamlASTContext() = %p", (void *)module,
            module->GetFileSpec().GetFilename().AsCString("<anonymous>"),
            (void *)ocaml_ast_sp.get());
      }

    } else if (target) {
      arch = target->GetArchitecture();
      ocaml_ast_sp = std::shared_ptr<OCamlASTContextForExpr>(
          new OCamlASTContextForExpr(target->shared_from_this()));

      if (log) {
        log->Printf("((Target*)%p)->GetOCamlASTContext() = %p", (void *)target,
                    (void *)ocaml_ast_sp.get());
      }
    }

    if (arch.IsValid()) {
      ocaml_ast_sp->SetAddressByteSize(arch.GetAddressByteSize());
      return ocaml_ast_sp;
    }
  }

  return lldb::TypeSystemSP();
}

void OCamlASTContext::EnumerateSupportedLanguages(
    std::set<lldb::LanguageType> &languages_for_types,
    std::set<lldb::LanguageType> &languages_for_expressions) {
  static std::vector<lldb::LanguageType> s_supported_languages_for_types(
      {lldb::eLanguageTypeOCaml});
  static std::vector<lldb::LanguageType> s_supported_languages_for_expressions(
      {});

  languages_for_types.insert(s_supported_languages_for_types.begin(),
                             s_supported_languages_for_types.end());
  languages_for_expressions.insert(
      s_supported_languages_for_expressions.begin(),
      s_supported_languages_for_expressions.end());
}

void OCamlASTContext::Initialize() {
  PluginManager::RegisterPlugin(GetPluginNameStatic(),
                                "OCaml AST context plug-in", CreateInstance,
                                EnumerateSupportedLanguages);
}

void OCamlASTContext::Terminate() {
  PluginManager::UnregisterPlugin(CreateInstance);
}

DWARFASTParser *OCamlASTContext::GetDWARFParser() {
  if (!m_dwarf_ast_parser_ap) {
    m_dwarf_ast_parser_ap.reset(new DWARFASTParserOCaml(*this));
  }

  return m_dwarf_ast_parser_ap.get();
}

bool OCamlASTContext::IsArrayType(lldb::opaque_compiler_type_t type,
                                  CompilerType *element_type, uint64_t *size,
                                  bool *is_incomplete) {
  return false;
}

bool OCamlASTContext::IsVectorType(lldb::opaque_compiler_type_t type,
                                   CompilerType *element_type, uint64_t *size) {
  return false;
}

bool OCamlASTContext::IsAggregateType(lldb::opaque_compiler_type_t type) {
  return false;
}

bool OCamlASTContext::IsBeingDefined(lldb::opaque_compiler_type_t type) {
  return false;
}

bool OCamlASTContext::IsCharType(lldb::opaque_compiler_type_t type) {
  return false;
}

bool OCamlASTContext::IsCompleteType(lldb::opaque_compiler_type_t type) {
  return static_cast<OCamlPrimitiveType *>(type)->IsCompleteType();
}

bool OCamlASTContext::IsConst(lldb::opaque_compiler_type_t type) {
  return false;
}

bool OCamlASTContext::IsCStringType(lldb::opaque_compiler_type_t type,
                                    uint32_t &length) {
  return false;
}

bool OCamlASTContext::IsDefined(lldb::opaque_compiler_type_t type) {
  return type != nullptr;
}

bool OCamlASTContext::IsFloatingPointType(lldb::opaque_compiler_type_t type,
                                          uint32_t &count, bool &is_complex) {
  return false;
}

bool OCamlASTContext::IsFunctionType(lldb::opaque_compiler_type_t type,
                                     bool *is_variadic_ptr) {
  return false;
}

uint32_t
OCamlASTContext::IsHomogeneousAggregate(lldb::opaque_compiler_type_t type,
                                        CompilerType *base_type_ptr) {
  return false;
}

size_t OCamlASTContext::GetNumberOfFunctionArguments(
    lldb::opaque_compiler_type_t type) {
  return 0;
}

CompilerType
OCamlASTContext::GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type,
                                            const size_t index) {
  return CompilerType();
}

bool OCamlASTContext::IsFunctionPointerType(lldb::opaque_compiler_type_t type) {
  return IsFunctionType(type);
}

bool OCamlASTContext::IsBlockPointerType(
    lldb::opaque_compiler_type_t type,
    CompilerType *function_pointer_type_ptr) {
  return false;
}

bool OCamlASTContext::IsIntegerType(lldb::opaque_compiler_type_t type,
                                    bool &is_signed) {
  if (OCamlPrimitiveType *ptype =
          llvm::dyn_cast<OCamlPrimitiveType>(static_cast<OCamlType *>(type))) {
    switch (ptype->GetTypeKind()) {
    case OCamlPrimitiveType::eTypeInt:
      is_signed = true;
      return true;
    }
  }

  is_signed = false;
  return false;
}

bool OCamlASTContext::IsPolymorphicClass(lldb::opaque_compiler_type_t type) {
  return false;
}

bool OCamlASTContext::IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
                                            CompilerType *target_type,
                                            bool check_cplusplus,
                                            bool check_objc) {
  return false;
}

bool OCamlASTContext::IsRuntimeGeneratedType(
    lldb::opaque_compiler_type_t type) {
  return false;
}

bool OCamlASTContext::IsPointerType(lldb::opaque_compiler_type_t type,
                                    CompilerType *pointee_type) {
  if (pointee_type)
    pointee_type->Clear();
  return false;
}

bool OCamlASTContext::IsPointerOrReferenceType(
    lldb::opaque_compiler_type_t type, CompilerType *pointee_type) {
  return IsPointerType(type, pointee_type);
}

bool OCamlASTContext::IsReferenceType(lldb::opaque_compiler_type_t type,
                                      CompilerType *pointee_type,
                                      bool *is_rvalue) {
  return false;
}

bool OCamlASTContext::IsScalarType(lldb::opaque_compiler_type_t type) {
  return llvm::isa<OCamlPrimitiveType>(static_cast<OCamlType *>(type));
}

bool OCamlASTContext::IsTypedefType(lldb::opaque_compiler_type_t type) {
  return false;
}

bool OCamlASTContext::IsVoidType(lldb::opaque_compiler_type_t type) {
  return false;
}

bool OCamlASTContext::SupportsLanguage(lldb::LanguageType language) {
  return language == lldb::eLanguageTypeOCaml;
}

bool OCamlASTContext::GetCompleteType(lldb::opaque_compiler_type_t type) {
  if (IsCompleteType(type))
    return true;

  return false;
}

uint32_t OCamlASTContext::GetPointerByteSize() { return m_pointer_byte_size; }

ConstString OCamlASTContext::GetTypeName(lldb::opaque_compiler_type_t type) {
  if (type)
    return static_cast<OCamlPrimitiveType *>(type)->GetName();

  return ConstString();
}

uint32_t
OCamlASTContext::GetTypeInfo(lldb::opaque_compiler_type_t type,
                             CompilerType *pointee_or_element_compiler_type) {
  if (pointee_or_element_compiler_type)
    pointee_or_element_compiler_type->Clear();
  if (!type)
    return 0;

  if (OCamlPrimitiveType *ptype =
          llvm::dyn_cast<OCamlPrimitiveType>(static_cast<OCamlType *>(type))) {
    switch (ptype->GetTypeKind()) {
    case OCamlPrimitiveType::eTypeInt:
      return eTypeHasValue | eTypeIsBuiltIn | eTypeIsScalar | eTypeIsInteger |
             eTypeIsSigned;
    }
  }

  return 0;
}

lldb::TypeClass
OCamlASTContext::GetTypeClass(lldb::opaque_compiler_type_t type) {
  if (llvm::isa<OCamlPrimitiveType>(static_cast<OCamlType *>(type)))
    return eTypeClassBuiltin;

  return lldb::eTypeClassInvalid;
}

lldb::BasicType
OCamlASTContext::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) {
  return lldb::eBasicTypeInvalid;
}

lldb::LanguageType
OCamlASTContext::GetMinimumLanguage(lldb::opaque_compiler_type_t type) {
  return lldb::eLanguageTypeOCaml;
}

unsigned OCamlASTContext::GetTypeQualifiers(lldb::opaque_compiler_type_t type) {
  return 0;
}

//----------------------------------------------------------------------
// Creating related types
//----------------------------------------------------------------------

CompilerType
OCamlASTContext::GetArrayElementType(lldb::opaque_compiler_type_t type,
                                     uint64_t *stride) {
  return CompilerType();
}

CompilerType
OCamlASTContext::GetCanonicalType(lldb::opaque_compiler_type_t type) {
  return CompilerType(this, type);
}

CompilerType
OCamlASTContext::GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) {
  return CompilerType(this, type);
}

int OCamlASTContext::GetFunctionArgumentCount(
    lldb::opaque_compiler_type_t type) {
  return GetNumberOfFunctionArguments(type);
}

CompilerType OCamlASTContext::GetFunctionArgumentTypeAtIndex(
    lldb::opaque_compiler_type_t type, size_t idx) {
  return GetFunctionArgumentAtIndex(type, idx);
}

CompilerType
OCamlASTContext::GetFunctionReturnType(lldb::opaque_compiler_type_t type) {
  return CompilerType();
}

size_t
OCamlASTContext::GetNumMemberFunctions(lldb::opaque_compiler_type_t type) {
  return 0;
}

TypeMemberFunctionImpl
OCamlASTContext::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type,
                                          size_t idx) {
  return TypeMemberFunctionImpl();
}

CompilerType
OCamlASTContext::GetNonReferenceType(lldb::opaque_compiler_type_t type) {
  return CompilerType(this, type);
}

CompilerType
OCamlASTContext::GetPointeeType(lldb::opaque_compiler_type_t type) {
  return CompilerType();
}

CompilerType
OCamlASTContext::GetPointerType(lldb::opaque_compiler_type_t type) {
  return CompilerType();
}

CompilerType
OCamlASTContext::GetTypedefedType(lldb::opaque_compiler_type_t type) {
  return CompilerType();
}

CompilerType OCamlASTContext::GetBasicTypeFromAST(lldb::BasicType basic_type) {
  return CompilerType();
}

CompilerType
OCamlASTContext::GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding,
                                                     size_t bit_size) {
  return CompilerType();
}

uint64_t OCamlASTContext::GetBitSize(lldb::opaque_compiler_type_t type,
                                     ExecutionContextScope *exe_scope) {
  if (OCamlPrimitiveType *ptype =
          llvm::dyn_cast<OCamlPrimitiveType>(static_cast<OCamlType *>(type))) {
    switch (ptype->GetTypeKind()) {
    case OCamlPrimitiveType::eTypeInt:
      return ptype->GetByteSize() * 8;
    }
  }
  return 0;
}

lldb::Encoding OCamlASTContext::GetEncoding(lldb::opaque_compiler_type_t type,
                                            uint64_t &count) {
  count = 1;
  bool is_signed;
  if (IsIntegerType(type, is_signed))
    return is_signed ? lldb::eEncodingSint : lldb::eEncodingUint;
  bool is_complex;
  uint32_t complex_count;
  if (IsFloatingPointType(type, complex_count, is_complex)) {
    count = complex_count;
    return lldb::eEncodingIEEE754;
  }
  if (IsPointerType(type))
    return lldb::eEncodingUint;
  return lldb::eEncodingInvalid;
}

lldb::Format OCamlASTContext::GetFormat(lldb::opaque_compiler_type_t type) {
  if (!type)
    return lldb::eFormatDefault;
  return lldb::eFormatBytes;
}

size_t OCamlASTContext::GetTypeBitAlign(lldb::opaque_compiler_type_t type) {
  return 0;
}

uint32_t OCamlASTContext::GetNumChildren(lldb::opaque_compiler_type_t type,
                                         bool omit_empty_base_classes) {
  if (!type || !GetCompleteType(type))
    return 0;

  return GetNumFields(type);
}

uint32_t OCamlASTContext::GetNumFields(lldb::opaque_compiler_type_t type) {
  if (!type || !GetCompleteType(type))
    return 0;
  return 0;
}

CompilerType OCamlASTContext::GetFieldAtIndex(lldb::opaque_compiler_type_t type,
                                              size_t idx, std::string &name,
                                              uint64_t *bit_offset_ptr,
                                              uint32_t *bitfield_bit_size_ptr,
                                              bool *is_bitfield_ptr) {
  if (bit_offset_ptr)
    *bit_offset_ptr = 0;
  if (bitfield_bit_size_ptr)
    *bitfield_bit_size_ptr = 0;
  if (is_bitfield_ptr)
    *is_bitfield_ptr = false;

  if (!type || !GetCompleteType(type))
    return CompilerType();

  return CompilerType();
}

CompilerType OCamlASTContext::GetChildCompilerTypeAtIndex(
    lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx,
    bool transparent_pointers, bool omit_empty_base_classes,
    bool ignore_array_bounds, std::string &child_name,
    uint32_t &child_byte_size, int32_t &child_byte_offset,
    uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
    bool &child_is_base_class, bool &child_is_deref_of_parent,
    ValueObject *valobj, uint64_t &language_flags) {
  child_name.clear();
  child_byte_size = 0;
  child_byte_offset = 0;
  child_bitfield_bit_size = 0;
  child_bitfield_bit_offset = 0;
  child_is_base_class = false;
  child_is_deref_of_parent = false;
  language_flags = 0;

  if (!type || !GetCompleteType(type))
    return CompilerType();

  return CompilerType();
}

uint32_t
OCamlASTContext::GetIndexOfChildWithName(lldb::opaque_compiler_type_t type,
                                         const char *name,
                                         bool omit_empty_base_classes) {
  if (!type || !GetCompleteType(type))
    return UINT_MAX;

  return UINT_MAX;
}

size_t OCamlASTContext::GetIndexOfChildMemberWithName(
    lldb::opaque_compiler_type_t type, const char *name,
    bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) {
  uint32_t index = GetIndexOfChildWithName(type, name, omit_empty_base_classes);
  if (index == UINT_MAX)
    return 0;
  child_indexes.push_back(index);
  return 1;
}

size_t
OCamlASTContext::ConvertStringToFloatValue(lldb::opaque_compiler_type_t type,
                                           const char *s, uint8_t *dst,
                                           size_t dst_size) {
  assert(false);
  return 0;
}
//----------------------------------------------------------------------
// Dumping types
//----------------------------------------------------------------------

void OCamlASTContext::DumpValue(
    lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, Stream *s,
    lldb::Format format, const DataExtractor &data,
    lldb::offset_t data_byte_offset, size_t data_byte_size,
    uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, bool show_types,
    bool show_summary, bool verbose, uint32_t depth) {
  if (!type) {
    s->Printf("no type\n");
    return;
  }

  s->Printf("no value\n");

  if (show_summary)
    DumpSummary(type, exe_ctx, s, data, data_byte_offset, data_byte_size);
}

bool OCamlASTContext::DumpTypeValue(
    lldb::opaque_compiler_type_t type, Stream *s, lldb::Format format,
    const DataExtractor &data, lldb::offset_t byte_offset, size_t byte_size,
    uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
    ExecutionContextScope *exe_scope) {
  if (!type) {
    s->Printf("no type value\n");
    return false;
  }

  if (IsScalarType(type)) {
    return data.Dump(s, byte_offset, format, byte_size, 1, SIZE_MAX,
                     LLDB_INVALID_ADDRESS, bitfield_bit_size,
                     bitfield_bit_offset, exe_scope);
  }

  return false;
}

void OCamlASTContext::DumpSummary(lldb::opaque_compiler_type_t type,
                                  ExecutionContext *exe_ctx, Stream *s,
                                  const DataExtractor &data,
                                  lldb::offset_t data_offset,
                                  size_t data_byte_size) {
  s->Printf("no summary\n");
}

void OCamlASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type) {
  StreamFile s(stdout, false);
  DumpTypeDescription(type, &s);
}

void OCamlASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type,
                                          Stream *s) {
  static_cast<OCamlType *>(type)->Dump(s);
}

CompilerType OCamlASTContext::CreateBaseType(const ConstString &name,
                                             uint64_t byte_size) {
  if (m_base_type_map.empty()) {
    OCamlPrimitiveType *type = new OCamlPrimitiveType(
        OCamlPrimitiveType::eTypeInt, ConstString("ocaml_int"), byte_size);
    m_base_type_map.emplace(type->GetName(),
                            std::unique_ptr<OCamlASTContext::OCamlType>(type));
  }

  auto it = m_base_type_map.find(name);
  if (it == m_base_type_map.end()) {
    OCamlPrimitiveType *type =
        new OCamlPrimitiveType(OCamlPrimitiveType::eTypeInt, name, byte_size);
    it = m_base_type_map
             .emplace(name, std::unique_ptr<OCamlASTContext::OCamlType>(type))
             .first;
  }

  return CompilerType(this, it->second.get());
}