1
2
3
4
5
6 #include <cmajor/cmsxbe/Emitter.hpp>
7 #include <cmajor/cmsxi/Context.hpp>
8 #include <cmajor/cmsxi/Type.hpp>
9
10 namespace cmsxbe {
11
12 Emitter::Emitter(cmsxbe::EmittingContext* emittingContext_) :
13 cmajor::ir::Emitter(&stack), emittingContext(emittingContext_), emittingDelegate(nullptr), context(nullptr), compileUnit(nullptr), currentFunction(nullptr),
14 objectPointer(nullptr)
15 {
16 }
17
18 void Emitter::SetEmittingDelegate(cmajor::ir::EmittingDelegate* emittingDelegate_)
19 {
20 emittingDelegate = emittingDelegate_;
21 }
22
23 void* Emitter::GetIrTypeForBool()
24 {
25 return context->GetBoolType();
26 }
27
28 void* Emitter::GetIrTypeForSByte()
29 {
30 return context->GetSByteType();
31 }
32
33 void* Emitter::GetIrTypeForByte()
34 {
35 return context->GetByteType();
36 }
37
38 void* Emitter::GetIrTypeForShort()
39 {
40 return context->GetShortType();
41 }
42
43 void* Emitter::GetIrTypeForUShort()
44 {
45 return context->GetUShortType();
46 }
47
48 void* Emitter::GetIrTypeForInt()
49 {
50 return context->GetIntType();
51 }
52
53 void* Emitter::GetIrTypeForUInt()
54 {
55 return context->GetUIntType();
56 }
57
58 void* Emitter::GetIrTypeForLong()
59 {
60 return context->GetLongType();
61 }
62
63 void* Emitter::GetIrTypeForULong()
64 {
65 return context->GetULongType();
66 }
67
68 void* Emitter::GetIrTypeForFloat()
69 {
70 return context->GetFloatType();
71 }
72
73 void* Emitter::GetIrTypeForDouble()
74 {
75 return context->GetDoubleType();
76 }
77
78 void* Emitter::GetIrTypeForChar()
79 {
80 return context->GetByteType();
81 }
82
83 void* Emitter::GetIrTypeForWChar()
84 {
85 return context->GetUShortType();
86 }
87
88 void* Emitter::GetIrTypeForUChar()
89 {
90 return context->GetUIntType();
91 }
92
93 void* Emitter::GetIrTypeForVoid()
94 {
95 return context->GetVoidType();
96 }
97
98 void* Emitter::GetIrTypeForFunction(void* retType, const std::std::vector<void*>¶mTypes)
99 {
100 std::vector<cmsxi::Type*> parameterTypes;
101 for (void* paramType : paramTypes)
102 {
103 parameterTypes.push_back(static_cast<cmsxi::Type*>(paramType));
104 }
105 return context->GetFunctionType(static_cast<cmsxi::Type*>(retType), parameterTypes);
106 }
107
108 void* Emitter::GetIrTypeForVariableParamFunction(void* retType)
109 {
110
111 return nullptr;
112 }
113
114 void* Emitter::GetIrTypeByTypeId(const boost::uuids::uuid& typeId)
115 {
116 auto it = irTypeTypeIdMap.find(typeId);
117 if (it != irTypeTypeIdMap.cend())
118 {
119 return it->second;
120 }
121 else
122 {
123 return nullptr;
124 }
125 }
126
127 void Emitter::SetIrTypeByTypeId(const boost::uuids::uuid& typeId, void* irType)
128 {
129 irTypeTypeIdMap[typeId] = static_cast<cmsxi::Type*>(irType);
130 }
131
132 void* Emitter::GetIrTypeForArrayType(void* elementType, int64_t size)
133 {
134 return context->GetArrayType(static_cast<cmsxi::Type*>(elementType), size);
135 }
136
137 void* Emitter::GetIrTypeForClassType(const std::std::vector<void*>&elementTypes)
138 {
139 std::vector<cmsxi::Type*> memberTypes;
140 for (void* elementType : elementTypes)
141 {
142 memberTypes.push_back(static_cast<cmsxi::Type*>(elementType));
143 }
144 return context->GetStructureType(memberTypes);
145 }
146
147 void* Emitter::CreateFwdIrTypeForClassType()
148 {
149 return context->CreateStructureType();
150 }
151
152 void Emitter::SetFwdIrTypeBody(void* forwardDeclaredType, const std::std::vector<void*>&elementTypes)
153 {
154 std::vector<cmsxi::Type*> memberTypes;
155 for (void* elementType : elementTypes)
156 {
157 memberTypes.push_back(static_cast<cmsxi::Type*>(elementType));
158 }
159 cmsxi::StructureType* structureType = static_cast<cmsxi::StructureType*>(forwardDeclaredType);
160 structureType->SetMemberTypes(memberTypes);
161 }
162
163 void* Emitter::GetIrTypeForDelegateType(void* retType, const std::std::vector<void*>¶mTypes)
164 {
165 std::vector<cmsxi::Type*> parameterTypes;
166 for (void* paramType : paramTypes)
167 {
168 parameterTypes.push_back(static_cast<cmsxi::Type*>(paramType));
169 }
170 return context->GetPtrType(context->GetFunctionType(static_cast<cmsxi::Type*>(retType), parameterTypes));
171 }
172
173 void* Emitter::GetIrTypeForVoidPtrType()
174 {
175 return context->GetPtrType(context->GetVoidType());
176 }
177
178 void* Emitter::GetIrTypeForStructType(const std::std::vector<void*>&elementTypes)
179 {
180 std::vector<cmsxi::Type*> memberTypes;
181 for (void* elementType : elementTypes)
182 {
183 memberTypes.push_back(static_cast<cmsxi::Type*>(elementType));
184 }
185 return context->GetStructureType(memberTypes);
186 }
187
188 void* Emitter::GetIrTypeForPtrType(void* baseIrType)
189 {
190 return context->GetPtrType(static_cast<cmsxi::Type*>(baseIrType));
191 }
192
193 std::string Emitter::GetIrTypeName(void* irType)
194 {
195 return std::string();
196 }
197
198 std::string Emitter::MakeVmtVariableName(const std::string& vmtObjectName)
199 {
200 return std::string();
201 }
202
203 void* Emitter::CreateDefaultIrValueForArrayType(void* arrayIrType, const std::std::vector<void*>&arrayOfDefaults)
204 {
205 std::vector<cmsxi::ConstantValue*> arrayOfConstants;
206 for (void* constant : arrayOfDefaults)
207 {
208 arrayOfConstants.push_back(static_cast<cmsxi::ConstantValue*>(constant));
209 }
210 cmsxi::Type* arrayType = static_cast<cmsxi::Type*>(arrayIrType);
211 return context->GetArrayValue(arrayType, arrayOfConstants, std::string());
212 }
213
214 void* Emitter::CreateDefaultIrValueForBool()
215 {
216 return context->GetDefaultBoolValue();
217 }
218
219 void* Emitter::CreateDefaultIrValueForSByte()
220 {
221 return context->GetDefaultSByteValue();
222 }
223
224 void* Emitter::CreateDefaultIrValueForByte()
225 {
226 return context->GetDefaultByteValue();
227 }
228
229 void* Emitter::CreateDefaultIrValueForShort()
230 {
231 return context->GetDefaultShortValue();
232 }
233
234 void* Emitter::CreateDefaultIrValueForUShort()
235 {
236 return context->GetDefaultUShortValue();
237 }
238
239 void* Emitter::CreateDefaultIrValueForInt()
240 {
241 return context->GetDefaultIntValue();
242 }
243
244 void* Emitter::CreateDefaultIrValueForUInt()
245 {
246 return context->GetDefaultUIntValue();
247 }
248
249 void* Emitter::CreateDefaultIrValueForLong()
250 {
251 return context->GetDefaultLongValue();
252 }
253
254 void* Emitter::CreateDefaultIrValueForULong()
255 {
256 return context->GetDefaultULongValue();
257 }
258
259 void* Emitter::CreateDefaultIrValueForFloat()
260 {
261 return context->GetDefaultDoubleValue();
262
263 }
264
265 void* Emitter::CreateDefaultIrValueForDouble()
266 {
267 return context->GetDefaultDoubleValue();
268 }
269
270 void* Emitter::CreateDefaultIrValueForChar()
271 {
272 return context->GetDefaultByteValue();
273 }
274
275 void* Emitter::CreateDefaultIrValueForWChar()
276 {
277 return context->GetDefaultUShortValue();
278 }
279
280 void* Emitter::CreateDefaultIrValueForUChar()
281 {
282 return context->GetDefaultUIntValue();
283 }
284
285 void* Emitter::CreateDefaultIrValueForStruct(void* irType, const std::std::vector<void*>&defaultMembers)
286 {
287 std::vector<cmsxi::ConstantValue*> arrayOfDefaults;
288 for (void* constant : defaultMembers)
289 {
290 arrayOfDefaults.push_back(static_cast<cmsxi::ConstantValue*>(constant));
291 }
292 return context->GetStructureValue(static_cast<cmsxi::StructureType*>(irType), arrayOfDefaults);
293 }
294
295 void* Emitter::CreateDefaultIrValueForDelegateType(void* irType)
296 {
297 return context->GetNullValue(static_cast<cmsxi::PtrType*>(irType));
298 }
299
300 void* Emitter::CreateDefaultIrValueForVoidPtrType()
301 {
302 return context->GetNullValue(static_cast<cmsxi::PtrType*>(context->GetPtrType(context->GetVoidType())));
303 }
304
305 void* Emitter::CreateDefaultIrValueForDerivedType(void* irType)
306 {
307 return static_cast<cmsxi::Type*>(irType)->DefaultValue();
308 }
309
310 void* Emitter::CreateDefaultIrValueForPtrType(void* irType)
311 {
312 return context->GetNullValue(static_cast<cmsxi::PtrType*>(irType));
313 }
314
315 void* Emitter::CreateIrValueForBool(bool value)
316 {
317 return context->GetBoolValue(value);
318 }
319
320 void* Emitter::CreateIrValueForSByte(int8_t value)
321 {
322 return context->GetSByteValue(value);
323 }
324
325 void* Emitter::CreateIrValueForByte(uint8_t value)
326 {
327 return context->GetByteValue(value);
328 }
329
330 void* Emitter::CreateIrValueForShort(int16_t value)
331 {
332 return context->GetShortValue(value);
333 }
334
335 void* Emitter::CreateIrValueForUShort(uint16_t value)
336 {
337 return context->GetUShortValue(value);
338 }
339
340 void* Emitter::CreateIrValueForInt(int32_t value)
341 {
342 return context->GetIntValue(value);
343 }
344
345 void* Emitter::CreateIrValueForUInt(uint32_t value)
346 {
347 return context->GetUIntValue(value);
348 }
349
350 void* Emitter::CreateIrValueForLong(int64_t value)
351 {
352 return context->GetLongValue(value);
353 }
354
355 void* Emitter::CreateIrValueForULong(uint64_t value)
356 {
357 return context->GetULongValue(value);
358 }
359
360 void* Emitter::CreateIrValueForFloat(float value)
361 {
362 return context->GetDoubleValue(value);
363
364 }
365
366 void* Emitter::CreateIrValueForDouble(double value)
367 {
368 return context->GetDoubleValue(value);
369 }
370
371 void* Emitter::CreateIrValueForChar(uint8_t value)
372 {
373 return context->GetByteValue(value);
374 }
375
376 void* Emitter::CreateIrValueForWChar(uint16_t value)
377 {
378 return context->GetUShortValue(value);
379 }
380
381 void* Emitter::CreateIrValueForUChar(uint32_t value)
382 {
383 return context->GetUIntValue(value);
384 }
385
386 void* Emitter::CreateIrValueForWString(void* wstringConstant)
387 {
388 return static_cast<cmsxi::Value*>(wstringConstant);
389 }
390
391 void* Emitter::CreateIrValueForUString(void* ustringConstant)
392 {
393 return static_cast<cmsxi::Value*>(ustringConstant);
394 }
395
396 void* Emitter::CreateIrValueForConstantArray(void* arrayIrType, const std::std::vector<void*>&elementConstants, conststd::string&prefix)
397 {
398 std::vector<cmsxi::ConstantValue*> elements;
399 for (void* elementConstant : elementConstants)
400 {
401 elements.push_back(static_cast<cmsxi::ConstantValue*>(elementConstant));
402 }
403 return context->GetArrayValue(static_cast<cmsxi::ArrayType*>(arrayIrType), elements, prefix);
404 }
405
406 void* Emitter::CreateIrValueForConstantStruct(void* structIrType, const std::std::vector<void*>&elementConstants)
407 {
408 std::vector<cmsxi::ConstantValue*> memberConstants;
409 for (void* elementConstant : elementConstants)
410 {
411 memberConstants.push_back(static_cast<cmsxi::ConstantValue*>(elementConstant));
412 }
413 return context->GetStructureValue(static_cast<cmsxi::StructureType*>(structIrType), memberConstants);
414 }
415
416 void* Emitter::CreateIrValueForUuid(void* uuidConstant)
417 {
418 cmsxi::Value* arg = context->CreatePtrOffset(static_cast<cmsxi::Value*>(uuidConstant), context->GetLongValue(0));
419 return context->CreateBitCast(arg, context->GetPtrType(context->GetVoidType()));
420 }
421
422 void* Emitter::GetConversionValue(void* type, void* from)
423 {
424 return context->GetConversionValue(static_cast<cmsxi::Type*>(type), static_cast<cmsxi::ConstantValue*>(from));
425 }
426
427 void* Emitter::CreateGlobalStringPtr(const std::string& stringValue)
428 {
429 return context->CreateGlobalStringPtr(stringValue);
430 }
431
432 void* Emitter::CreateGlobalWStringPtr(const std::u16string& stringValue)
433 {
434 return nullptr;
435 }
436
437 void* Emitter::CreateGlobalUStringPtr(const std::u32string& stringValue)
438 {
439 return nullptr;
440 }
441
442 void* Emitter::GetGlobalStringPtr(int stringId)
443 {
444 return emittingDelegate->GetGlobalStringPtr(stringId);
445 }
446
447 void* Emitter::GetGlobalWStringConstant(int stringId)
448 {
449 return emittingDelegate->GetGlobalWStringConstant(stringId);
450 }
451
452 void* Emitter::GetGlobalUStringConstant(int stringId)
453 {
454 return emittingDelegate->GetGlobalUStringConstant(stringId);
455 }
456
457 void* Emitter::GetGlobalUuidConstant(int uuidId)
458 {
459 return emittingDelegate->GetGlobalUuidConstant(uuidId);
460 }
461
462 void* Emitter::CreateDITypeForBool()
463 {
464
465 return nullptr;
466 }
467
468 void* Emitter::CreateDITypeForSByte()
469 {
470
471 return nullptr;
472 }
473
474 void* Emitter::CreateDITypeForByte()
475 {
476
477 return nullptr;
478 }
479
480 void* Emitter::CreateDITypeForShort()
481 {
482
483 return nullptr;
484 }
485
486 void* Emitter::CreateDITypeForUShort()
487 {
488
489 return nullptr;
490 }
491
492 void* Emitter::CreateDITypeForInt()
493 {
494
495 return nullptr;
496 }
497
498 void* Emitter::CreateDITypeForUInt()
499 {
500
501 return nullptr;
502 }
503
504 void* Emitter::CreateDITypeForLong()
505 {
506
507 return nullptr;
508 }
509
510 void* Emitter::CreateDITypeForULong()
511 {
512
513 return nullptr;
514 }
515
516 void* Emitter::CreateDITypeForFloat()
517 {
518
519 return nullptr;
520 }
521
522 void* Emitter::CreateDITypeForDouble()
523 {
524
525 return nullptr;
526 }
527
528 void* Emitter::CreateDITypeForChar()
529 {
530
531 return nullptr;
532 }
533
534 void* Emitter::CreateDITypeForWChar()
535 {
536
537 return nullptr;
538 }
539
540 void* Emitter::CreateDITypeForUChar()
541 {
542
543 return nullptr;
544 }
545
546 void* Emitter::CreateDITypeForVoid()
547 {
548
549 return nullptr;
550 }
551
552 void* Emitter::CreateDITypeForArray(void* elementDIType, const std::std::vector<void*>&elements)
553 {
554
555 return nullptr;
556 }
557
558 void* Emitter::CreateDITypeForEnumConstant(const std::string& name, int64_t value)
559 {
560
561 return nullptr;
562 }
563
564 void* Emitter::CreateDITypeForEnumType(const std::string& name, const std::string& mangledName, const Span& span, const boost::uuids::uuid& moduleId, const std::std::vector<void*>&enumConstantElements,
565 uint64_t sizeInBits, uint32_t alignInBits, void* underlyingDIType)
566 {
567
568 return nullptr;
569 }
570
571 void* Emitter::CreateIrDIForwardDeclaration(void* irType, const std::string& name, const std::string& mangledName, const Span& span, const boost::uuids::uuid& moduleId)
572 {
573
574 return nullptr;
575 }
576
577 uint64_t Emitter::GetOffsetInBits(void* classIrType, int layoutIndex)
578 {
579
580 return uint64_t();
581 }
582
583 void* Emitter::CreateDITypeForClassType(void* irType, const std::std::vector<void*>&memberVariableElements, constSpan&classSpan, constboost::uuids::uuid&moduleId, const std::string& name, void* vtableHolderClass,
584 const std::string& mangledName, void* baseClassDIType)
585 {
586
587 return nullptr;
588 }
589
590 void Emitter::MapFwdDeclaration(void* fwdDeclaration, const boost::uuids::uuid& typeId)
591 {
592
593 }
594
595 void* Emitter::GetDITypeByTypeId(const boost::uuids::uuid& typeId) const
596 {
597
598 return nullptr;
599 }
600
601 void Emitter::SetDITypeByTypeId(const boost::uuids::uuid& typeId, void* diType, const std::string& typeName)
602 {
603
604 }
605
606 void* Emitter::GetDIMemberType(const std::std::pair<boost::uuids::uuid, int32_t>&memberVariableId)
607 {
608
609 return nullptr;
610 }
611
612 void Emitter::SetDIMemberType(const std::std::pair<boost::uuids::uuid, int32_t>&memberVariableId, void*diType)
613 {
614
615 }
616
617 void* Emitter::CreateDIMemberType(void* scope, const std::string& name, const Span& span, const boost::uuids::uuid& moduleId, uint64_t sizeInBits, uint64_t alignInBits, uint64_t offsetInBits, void* diType)
618 {
619
620 return nullptr;
621 }
622
623 void* Emitter::CreateConstDIType(void* diType)
624 {
625
626 return nullptr;
627 }
628
629 void* Emitter::CreateLValueRefDIType(void* diType)
630 {
631
632 return nullptr;
633 }
634
635 void* Emitter::CreateRValueRefDIType(void* diType)
636 {
637
638 return nullptr;
639 }
640
641 void* Emitter::CreatePointerDIType(void* diType)
642 {
643
644 return nullptr;
645 }
646
647 void* Emitter::CreateUnspecifiedDIType(const std::string& name)
648 {
649
650 return nullptr;
651 }
652
653 void Emitter::MapClassPtr(const boost::uuids::uuid& typeId, void* classPtr, const std::string& className)
654 {
655
656 }
657
658 uint64_t Emitter::GetSizeInBits(void* irType)
659 {
660
661 return 0;
662
663 }
664
665 uint64_t Emitter::GetAlignmentInBits(void* irType)
666 {
667
668 return 0;
669
670 }
671
672 void Emitter::SetCurrentDebugLocation(const Span& span)
673 {
674
675 }
676
677 void* Emitter::GetArrayBeginAddress(void* arrayPtr)
678 {
679 return context->CreateElemAddr(static_cast<cmsxi::Value*>(arrayPtr), context->GetLongValue(0));
680 }
681
682 void* Emitter::GetArrayEndAddress(void* arrayPtr, uint64_t size)
683 {
684 return context->CreateElemAddr(static_cast<cmsxi::Value*>(arrayPtr), context->GetLongValue(size));
685 }
686
687 void* Emitter::CreateBasicBlock(const std::string& name)
688 {
689 if (name == "cleanup")
690 {
691 return currentFunction->CreateCleanupBasicBlock();
692 }
693 else
694 {
695 return currentFunction->CreateBasicBlock();
696 }
697 }
698
699 void* Emitter::CreateIncludeBasicBlockInstruction(void* basicBlock)
700 {
701 return nullptr;
702 }
703
704 void Emitter::PushParentBlock()
705 {
706 }
707
708 void Emitter::PopParentBlock()
709 {
710 }
711
712 void Emitter::SetHandlerBlock(void* tryBlock, void* catchBlock)
713 {
714 }
715
716 void Emitter::SetCleanupBlock(void* cleanupBlock)
717 {
718 }
719
720 int Emitter::GetBasicBlockId(void* basicBlock)
721 {
722 return static_cast<cmsxi::BasicBlock*>(basicBlock)->Id();
723 }
724
725 void Emitter::CreateBr(void* targetBasicBlock)
726 {
727 context->CreateJump(static_cast<cmsxi::BasicBlock*>(targetBasicBlock));
728 }
729
730 void* Emitter::CurrentBasicBlock() const
731 {
732 return context->GetCurrentBasicBlock();
733 }
734
735 void Emitter::SetCurrentBasicBlock(void* basicBlock)
736 {
737 context->SetCurrentBasicBlock(static_cast<cmsxi::BasicBlock*>(basicBlock));
738 }
739
740 void Emitter::CreateCondBr(void* cond, void* trueBasicBlock, void* falseBasicBlock)
741 {
742 context->CreateBranch(static_cast<cmsxi::Value*>(cond), static_cast<cmsxi::BasicBlock*>(trueBasicBlock), static_cast<cmsxi::BasicBlock*>(falseBasicBlock));
743 }
744
745 void* Emitter::CreateArrayIndexAddress(void* arrayPtr, void* index)
746 {
747 return context->CreateElemAddr(static_cast<cmsxi::Value*>(arrayPtr), static_cast<cmsxi::Value*>(index));
748 }
749
750 void Emitter::CreateStore(void* value, void* ptr)
751 {
752 context->CreateStore(static_cast<cmsxi::Value*>(value), static_cast<cmsxi::Value*>(ptr));
753 }
754
755 void* Emitter::CreateLoad(void* ptr)
756 {
757 return context->CreateLoad(static_cast<cmsxi::Value*>(ptr));
758 }
759
760 void* Emitter::CreateAdd(void* left, void* right)
761 {
762 return context->CreateAdd(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
763 }
764
765 void* Emitter::CreateFAdd(void* left, void* right)
766 {
767 return context->CreateAdd(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
768 }
769
770 void* Emitter::CreateSub(void* left, void* right)
771 {
772 return context->CreateSub(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
773 }
774
775 void* Emitter::CreateFSub(void* left, void* right)
776 {
777 return context->CreateSub(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
778 }
779
780 void* Emitter::CreateMul(void* left, void* right)
781 {
782 return context->CreateMul(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
783 }
784
785 void* Emitter::CreateFMul(void* left, void* right)
786 {
787 return context->CreateMul(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
788 }
789
790 void* Emitter::CreateUDiv(void* left, void* right)
791 {
792 return context->CreateDiv(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
793 }
794
795 void* Emitter::CreateSDiv(void* left, void* right)
796 {
797 return context->CreateDiv(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
798 }
799
800 void* Emitter::CreateFDiv(void* left, void* right)
801 {
802 return context->CreateDiv(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
803 }
804
805 void* Emitter::CreateURem(void* left, void* right)
806 {
807 return context->CreateMod(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
808 }
809
810 void* Emitter::CreateSRem(void* left, void* right)
811 {
812 return context->CreateMod(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
813 }
814
815 void* Emitter::CreateAnd(void* left, void* right)
816 {
817 return context->CreateAnd(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
818 }
819
820 void* Emitter::CreateOr(void* left, void* right)
821 {
822 return context->CreateOr(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
823 }
824
825 void* Emitter::CreateXor(void* left, void* right)
826 {
827 return context->CreateXor(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
828 }
829
830 void* Emitter::CreateShl(void* left, void* right)
831 {
832 return context->CreateShl(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
833 }
834
835 void* Emitter::CreateAShr(void* left, void* right)
836 {
837 return context->CreateShr(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
838 }
839
840 void* Emitter::CreateLShr(void* left, void* right)
841 {
842 return context->CreateShr(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
843 }
844
845 void* Emitter::CreateICmpEQ(void* left, void* right)
846 {
847 return context->CreateEqual(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
848 }
849
850 void* Emitter::CreateFCmpOEQ(void* left, void* right)
851 {
852 return context->CreateEqual(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
853 }
854
855 void* Emitter::CreateICmpULT(void* left, void* right)
856 {
857 return context->CreateLess(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
858 }
859
860 void* Emitter::CreateICmpSLT(void* left, void* right)
861 {
862 return context->CreateLess(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
863 }
864
865 void* Emitter::CreateFCmpOLT(void* left, void* right)
866 {
867 return context->CreateLess(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
868 }
869
870 void* Emitter::CreateSExt(void* operand, void* destinationType)
871 {
872 return context->CreateSignExtend(static_cast<cmsxi::Value*>(operand), static_cast<cmsxi::Type*>(destinationType));
873 }
874
875 void* Emitter::CreateZExt(void* operand, void* destinationType)
876 {
877 return context->CreateZeroExtend(static_cast<cmsxi::Value*>(operand), static_cast<cmsxi::Type*>(destinationType));
878 }
879
880 void* Emitter::CreateFPExt(void* operand, void* destinationType)
881 {
882 return operand;
883 }
884
885 void* Emitter::CreateTrunc(void* operand, void* destinationType)
886 {
887 return context->CreateTruncate(static_cast<cmsxi::Value*>(operand), static_cast<cmsxi::Type*>(destinationType));
888 }
889
890 void* Emitter::CreateFPTrunc(void* operand, void* destinationType)
891 {
892 return context->CreateBitCast(static_cast<cmsxi::Value*>(operand), static_cast<cmsxi::Type*>(destinationType));
893 }
894
895 void* Emitter::CreateBitCast(void* operand, void* destinationType)
896 {
897 return context->CreateBitCast(static_cast<cmsxi::Value*>(operand), static_cast<cmsxi::Type*>(destinationType));
898 }
899
900 void* Emitter::CreateUIToFP(void* operand, void* destinationType)
901 {
902 return context->CreateIntToFloat(static_cast<cmsxi::Value*>(operand), static_cast<cmsxi::Type*>(destinationType));
903 }
904
905 void* Emitter::CreateSIToFP(void* operand, void* destinationType)
906 {
907 return context->CreateIntToFloat(static_cast<cmsxi::Value*>(operand), static_cast<cmsxi::Type*>(destinationType));
908 }
909
910 void* Emitter::CreateFPToUI(void* operand, void* destinationType)
911 {
912 return context->CreateFloatToInt(static_cast<cmsxi::Value*>(operand), static_cast<cmsxi::Type*>(destinationType));
913 }
914
915 void* Emitter::CreateFPToSI(void* operand, void* destinationType)
916 {
917 return context->CreateFloatToInt(static_cast<cmsxi::Value*>(operand), static_cast<cmsxi::Type*>(destinationType));
918 }
919
920 void* Emitter::CreateIntToPtr(void* intValue, void* destinationType)
921 {
922 return context->CreateIntToPtr(static_cast<cmsxi::Value*>(intValue), static_cast<cmsxi::Type*>(destinationType));
923 }
924
925 void* Emitter::CreatePtrToInt(void* ptrValue, void* destinationType)
926 {
927 return context->CreatePtrToInt(static_cast<cmsxi::Value*>(ptrValue), static_cast<cmsxi::Type*>(destinationType));
928 }
929
930 void* Emitter::CreateNot(void* value)
931 {
932 return context->CreateNot(static_cast<cmsxi::Value*>(value));
933 }
934
935 void* Emitter::CreateNeg(void* value)
936 {
937 return context->CreateNeg(static_cast<cmsxi::Value*>(value));
938 }
939
940 void* Emitter::CreateFNeg(void* value)
941 {
942 cmsxi::Value* val = static_cast<cmsxi::Value*>(value);
943 if (val->GetType(*context)->Id() == cmsxi::doubleTypeId)
944 {
945 cmsxi::ConstantValue* minusOne = context->GetDoubleValue(-1.0);
946 return context->CreateMul(minusOne, val);
947 }
948 else if (val->GetType(*context)->Id() == cmsxi::floatTypeId)
949 {
950 cmsxi::ConstantValue* minusOne = context->GetFloatValue(-1.0f);
951 return context->CreateMul(minusOne, val);
952 }
953 else
954 {
955 throw std::runtime_error("invalid FNeg operand type");
956 }
957 }
958
959 void* Emitter::CreateNop()
960 {
961 return context->CreateNop();
962 }
963
964 void* Emitter::CreateSave()
965 {
966 return context->CreateSave();
967 }
968
969 void* Emitter::CreateBeginTry()
970 {
971 return nullptr;
972 }
973
974 void* Emitter::CreateEndTry(void* nextDest)
975 {
976 return nullptr;
977 }
978
979 void* Emitter::CreateBeginCatch()
980 {
981 return nullptr;
982 }
983
984 void* Emitter::CreateEndCatch(void* nextDest)
985 {
986 return nullptr;
987 }
988
989 std::string Emitter::GetVmtObjectName(void* symbol) const
990 {
991
992 return std::string();
993 }
994
995 void Emitter::SetVmtObjectName(void* symbol, const std::string& vmtObjectName)
996 {
997
998 }
999
1000 std::string Emitter::GetImtArrayObjectName(void* symbol) const
1001 {
1002
1003 return std::string();
1004 }
1005
1006 void Emitter::SetImtArrayObjectName(void* symbol, const std::string& imtArrayObjectName)
1007 {
1008
1009 }
1010
1011 void* Emitter::GetVmtObjectType(void* symbol) const
1012 {
1013
1014 return nullptr;
1015 }
1016
1017 void Emitter::SetVmtObjectType(void* symbol, void* vmtObjectType)
1018 {
1019
1020 }
1021
1022 void* Emitter::GetStaticObjectType(void* symbol) const
1023 {
1024 auto it = staticTypeMap.find(symbol);
1025 if (it != staticTypeMap.cend())
1026 {
1027 return it->second;
1028 }
1029 else
1030 {
1031 return nullptr;
1032 }
1033 }
1034
1035 void Emitter::SetStaticObjectType(void* symbol, void* type)
1036 {
1037 staticTypeMap[symbol] = static_cast<cmsxi::StructureType*>(type);
1038 }
1039
1040 std::string Emitter::GetStaticObjectName(void* symbol) const
1041 {
1042 auto it = staticObjectNameMap.find(symbol);
1043 if (it != staticObjectNameMap.cend())
1044 {
1045 return it->second;
1046 }
1047 else
1048 {
1049 return std::string();
1050 }
1051 }
1052
1053 void Emitter::SetStaticObjectName(void* symbol, const std::string& staticObjectName)
1054 {
1055 staticObjectNameMap[symbol] = staticObjectName;
1056 }
1057
1058 void* Emitter::GetOrInsertGlobal(const std::string& name, void* type)
1059 {
1060 return context->GetOrInsertGlobal(name, static_cast<cmsxi::Type*>(type));
1061 }
1062
1063 void* Emitter::GetOrInsertAnyComdat(const std::string& name, void* global)
1064 {
1065 static_cast<cmsxi::GlobalVariable*>(global)->SetLinkOnce();
1066 return nullptr;
1067 }
1068
1069 void* Emitter::GetOrInsertAnyFunctionComdat(const std::string& name, void* function)
1070 {
1071 static_cast<cmsxi::Function*>(function)->SetLinkOnce();
1072 return nullptr;
1073 }
1074
1075 void* Emitter::GetOrInsertFunction(const std::string& name, void* type, bool nothrow)
1076 {
1077 return compileUnit->GetOrInsertFunction(name, static_cast<cmsxi::FunctionType*>(type));
1078 }
1079
1080 void Emitter::SetInitializer(void* global, void* initializer)
1081 {
1082 cmsxi::GlobalVariable* globalVar = static_cast<cmsxi::GlobalVariable*>(global);
1083 globalVar->SetInitializer(static_cast<cmsxi::ConstantValue*>(initializer));
1084 }
1085
1086 void Emitter::SetPrivateLinkage(void* global)
1087 {
1088
1089 }
1090
1091 bool Emitter::IsVmtObjectCreated(void* symbol) const
1092 {
1093 return vmtObjectCreatedSet.find(symbol) != vmtObjectCreatedSet.cend();
1094 }
1095
1096 void Emitter::SetVmtObjectCreated(void* symbol)
1097 {
1098 vmtObjectCreatedSet.insert(symbol);
1099 }
1100
1101 bool Emitter::IsStaticObjectCreated(void* symbol) const
1102 {
1103 return staticObjectCreatedSet.find(symbol) != staticObjectCreatedSet.cend();
1104 }
1105
1106 void Emitter::SetStaticObjectCreated(void* symbol)
1107 {
1108 staticObjectCreatedSet.insert(symbol);
1109 }
1110
1111 void* Emitter::HandlerBlock()
1112 {
1113 return emittingDelegate->HandlerBlock();
1114 }
1115
1116 void* Emitter::CleanupBlock()
1117 {
1118 return emittingDelegate->CleanupBlock();
1119 }
1120
1121 bool Emitter::NewCleanupNeeded()
1122 {
1123 return emittingDelegate->NewCleanupNeeded();
1124 }
1125
1126 void Emitter::CreateCleanup()
1127 {
1128 return emittingDelegate->CreateCleanup();
1129 }
1130
1131 cmajor::ir::Pad* Emitter::CurrentPad()
1132 {
1133
1134 return nullptr;
1135 }
1136
1137 void* Emitter::CreateCleanupPadWithParent(void* parentPad, const std::std::vector<void*>&args)
1138 {
1139
1140 return nullptr;
1141 }
1142
1143 void* Emitter::CreateCleanupPad(const std::std::vector<void*>&args)
1144 {
1145
1146 return nullptr;
1147 }
1148
1149 void* Emitter::CreateCleanupRet(void* cleanupPad, void* unwindTarget)
1150 {
1151
1152 return nullptr;
1153 }
1154
1155 void* Emitter::CreateCatchRet(void* catchPad, void* returnTarget)
1156 {
1157
1158 return nullptr;
1159 }
1160
1161 void* Emitter::CreateCatchSwitch(void* unwindBlock)
1162 {
1163
1164 return nullptr;
1165 }
1166
1167 void* Emitter::CreateCatchSwitchWithParent(void* parentPad, void* unwindBlock)
1168 {
1169
1170 return nullptr;
1171 }
1172
1173 void Emitter::AddHandlerToCatchSwitch(void* catchSwitch, void* target)
1174 {
1175
1176 }
1177
1178 void* Emitter::CreateCatchPad(void* parentPad, const std::std::vector<void*>&args)
1179 {
1180
1181 return nullptr;
1182 }
1183
1184 void* Emitter::CreateClassDIType(void* classPtr)
1185 {
1186
1187 return nullptr;
1188 }
1189
1190 void* Emitter::CreateCall(void* callee, const std::std::vector<void*>&args)
1191 {
1192 for (void* arg : args)
1193 {
1194 cmsxi::Value* argument = static_cast<cmsxi::Value*>(arg);
1195 context->CreateArg(argument);
1196 }
1197 cmsxi::Value* calleeValue = static_cast<cmsxi::Value*>(callee);
1198 return context->CreateCall(calleeValue);
1199 }
1200
1201 void* Emitter::CreateCallInst(void* callee, const std::std::vector<void*>&args, conststd::std::vector<void*>&bundles, constSpan&span)
1202 {
1203 for (void* arg : args)
1204 {
1205 cmsxi::Value* argument = static_cast<cmsxi::Value*>(arg);
1206 context->CreateArg(argument);
1207 }
1208 cmsxi::Value* calleeValue = static_cast<cmsxi::Value*>(callee);
1209 return context->CreateCall(calleeValue);
1210 }
1211
1212 void* Emitter::CreateCallInstToBasicBlock(void* callee, const std::std::vector<void*>&args, conststd::std::vector<void*>&bundles, void*basicBlock, constSpan&span)
1213 {
1214 void* prevBasicBlock = context->GetCurrentBasicBlock();
1215 SetCurrentBasicBlock(basicBlock);
1216 for (void* arg : args)
1217 {
1218 cmsxi::Value* argument = static_cast<cmsxi::Value*>(arg);
1219 context->CreateArg(argument);
1220 }
1221 cmsxi::Value* calleeValue = static_cast<cmsxi::Value*>(callee);
1222 cmsxi::Instruction* callInst = context->CreateCall(calleeValue);
1223 SetCurrentBasicBlock(prevBasicBlock);
1224 return callInst;
1225 }
1226
1227 void* Emitter::CreateInvoke(void* callee, void* normalBlock, void* unwindBlock, const std::std::vector<void*>&args)
1228 {
1229 void* cleanupBlock = CleanupBlock();
1230 if (unwindBlock == cleanupBlock)
1231 {
1232 void* nop1 = CreateNop();
1233 void* beginCleanup = CreateMDStruct();
1234 AddMDItem(beginCleanup, "nodeType", CreateMDLong(cmsxi::beginCleanupNodeType));
1235 AddMDItem(beginCleanup, "cleanupBlockId", CreateMDBasicBlockRef(cleanupBlock));
1236 if (emittingDelegate->InTryBlock())
1237 {
1238 AddMDItem(beginCleanup, "tryBlockId", CreateMDLong(emittingDelegate->CurrentTryBlockId()));
1239 }
1240 int beginCleanupId = GetMDStructId(beginCleanup);
1241 void* beginCleanupMdRef = CreateMDStructRef(beginCleanupId);
1242 SetMetadataRef(nop1, beginCleanupMdRef);
1243 }
1244 void* call = CreateCall(callee, args);
1245 if (unwindBlock == cleanupBlock)
1246 {
1247 void* nop2 = CreateNop();
1248 void* endCleanup = CreateMDStruct();
1249 AddMDItem(endCleanup, "nodeType", CreateMDLong(cmsxi::endCleanupNodeType));
1250 AddMDItem(endCleanup, "cleanupBlockId", CreateMDBasicBlockRef(cleanupBlock));
1251 int endCleanupId = GetMDStructId(endCleanup);
1252 void* endCleanupMdRef = CreateMDStructRef(endCleanupId);
1253 SetMetadataRef(nop2, endCleanupMdRef);
1254 }
1255 return call;
1256 }
1257
1258 void* Emitter::CreateInvokeInst(void* callee, void* normalBlock, void* unwindBlock, const std::std::vector<void*>&args, conststd::std::vector<void*>&bundles, constSpan&span)
1259 {
1260 return CreateInvoke(callee, normalBlock, unwindBlock, args);
1261 }
1262
1263 void* Emitter::DIBuilder()
1264 {
1265
1266 return nullptr;
1267 }
1268
1269 void Emitter::SetCurrentDIBuilder(void* diBuilder_)
1270 {
1271
1272 }
1273
1274 void* Emitter::GetObjectFromClassDelegate(void* classDelegatePtr)
1275 {
1276 return context->CreateElemAddr(static_cast<cmsxi::Value*>(classDelegatePtr), context->GetLongValue(0));
1277 }
1278
1279 void* Emitter::GetDelegateFromClassDelegate(void* classDelegatePtr)
1280 {
1281 return context->CreateElemAddr(static_cast<cmsxi::Value*>(classDelegatePtr), context->GetLongValue(1));
1282 }
1283
1284 void* Emitter::GetObjectFromInterface(void* interfaceTypePtr)
1285 {
1286 cmsxi::Value* addr = context->CreateElemAddr(static_cast<cmsxi::Value*>(interfaceTypePtr), context->GetLongValue(0));
1287 return context->CreateLoad(addr);
1288 }
1289
1290 void* Emitter::GetObjectPtrFromInterface(void* interfaceTypePtr)
1291 {
1292 return context->CreateElemAddr(static_cast<cmsxi::Value*>(interfaceTypePtr), context->GetLongValue(0));
1293 }
1294
1295 void* Emitter::GetImtPtrFromInterface(void* interfaceTypePtr)
1296 {
1297 cmsxi::Value* interfacePtrAddr = context->CreateElemAddr(static_cast<cmsxi::Value*>(interfaceTypePtr), context->GetLongValue(1));
1298 cmsxi::Value* interfacePtr = context->CreateLoad(interfacePtrAddr);
1299 return context->CreateBitCast(interfacePtr, context->GetPtrType(context->GetVoidType()));
1300 }
1301
1302 void* Emitter::GetInterfaceMethod(void* imtPtr, int32_t methodIndex, void* interfaceMethodType)
1303 {
1304 cmsxi::Value* methodPtrPtr = context->CreatePtrOffset(static_cast<cmsxi::Value*>(imtPtr), context->GetLongValue(methodIndex));
1305 cmsxi::Value* methodPtr = context->CreateLoad(methodPtrPtr);
1306 cmsxi::Value* callee = context->CreateBitCast(methodPtr, context->GetPtrType(static_cast<cmsxi::Type*>(interfaceMethodType)));
1307 return callee;
1308 }
1309
1310 void* Emitter::GetFunctionIrType(void* functionSymbol) const
1311 {
1312 auto it = functionIrTypeMap.find(functionSymbol);
1313 if (it != functionIrTypeMap.cend())
1314 {
1315 return it->second;
1316 }
1317 else
1318 {
1319 return nullptr;
1320 }
1321 }
1322
1323 void Emitter::SetFunctionIrType(void* symbol, void* irType)
1324 {
1325 functionIrTypeMap[symbol] = static_cast<cmsxi::FunctionType*>(irType);
1326 }
1327
1328 void* Emitter::GetVmtPtr(void* thisPtr, int32_t vmtPtrIndex, void* vmtPtrType)
1329 {
1330 cmsxi::Value* vmtPtrPtr = context->CreateElemAddr(static_cast<cmsxi::Value*>(thisPtr), context->GetLongValue(vmtPtrIndex));
1331 cmsxi::Value* vmtPtr = context->CreateLoad(vmtPtrPtr);
1332 return context->CreateBitCast(vmtPtr, static_cast<cmsxi::Type*>(vmtPtrType));
1333 }
1334
1335 void* Emitter::GetMethodPtr(void* vmtPtr, int32_t vmtIndex)
1336 {
1337 cmsxi::Value* funPtrPtr = context->CreateElemAddr(static_cast<cmsxi::Value*>(vmtPtr), context->GetLongValue(vmtIndex));
1338 return context->CreateLoad(funPtrPtr);
1339 }
1340
1341 void* Emitter::GetImtArray(void* vmtObjectPtr, int32_t imtsVmtIndexOffset)
1342 {
1343 cmsxi::Value* imtsArrayPtrPtr = context->CreateElemAddr(static_cast<cmsxi::Value*>(vmtObjectPtr), context->GetLongValue(imtsVmtIndexOffset));
1344 cmsxi::Value* imtsArrayPtr = context->CreateBitCast(imtsArrayPtrPtr, context->GetPtrType(context->GetPtrType(context->GetVoidType())));
1345 return context->CreateLoad(imtsArrayPtr);
1346 }
1347
1348 void* Emitter::GetImt(void* imtArray, int32_t interfaceIndex)
1349 {
1350 cmsxi::Value* imtArrayPtr = context->CreatePtrOffset(static_cast<cmsxi::Value*>(imtArray), context->GetLongValue(interfaceIndex));
1351 return context->CreateLoad(imtArrayPtr);
1352 }
1353
1354 void* Emitter::GetIrObject(void* symbol) const
1355 {
1356 auto it = irObjectMap.find(symbol);
1357 if (it != irObjectMap.cend())
1358 {
1359 return it->second;
1360 }
1361 else
1362 {
1363 throw std::runtime_error("emitter: IR object not found");
1364 }
1365 }
1366
1367 void Emitter::SetIrObject(void* symbol, void* irObject)
1368 {
1369 irObjectMap[symbol] = static_cast<cmsxi::Value*>(irObject);
1370 }
1371
1372 void* Emitter::GetMemberVariablePtr(void* classPtr, int32_t memberVariableLayoutIndex)
1373 {
1374 cmsxi::Value* clsPtr = static_cast<cmsxi::Value*>(classPtr);
1375 return context->CreateElemAddr(clsPtr, context->GetLongValue(memberVariableLayoutIndex));
1376 }
1377
1378 void* Emitter::SizeOf(void* ptrType)
1379 {
1380 cmsxi::Value* nullPtr = context->GetNullValue(static_cast<cmsxi::PtrType*>(ptrType));
1381 cmsxi::Value* one = context->CreatePtrOffset(nullPtr, context->GetLongValue(1));
1382 cmsxi::Value* size = context->CreatePtrToInt(one, context->GetLongType());
1383 return size;
1384 }
1385
1386 void Emitter::SetLineNumber(int32_t lineNumber)
1387 {
1388
1389 }
1390
1391 void Emitter::SaveObjectPointer(void* objectPointer_)
1392 {
1393 if (objectPointer == nullptr)
1394 {
1395 objectPointer = static_cast<cmsxi::Value*>(objectPointer_);
1396 }
1397 }
1398
1399 void Emitter::SetObjectPointer(void* objectPointer_)
1400 {
1401 objectPointer = static_cast<cmsxi::Value*>(objectPointer_);
1402 }
1403
1404 void* Emitter::GetObjectPointer()
1405 {
1406 return objectPointer;
1407 }
1408
1409 void* Emitter::GetClassIdPtr(void* vmtPtr, int32_t classIdVmtIndexOffset)
1410 {
1411 cmsxi::Value* classIdPtr = context->CreateElemAddr(static_cast<cmsxi::Value*>(vmtPtr), context->GetLongValue(0));
1412 return classIdPtr;
1413 }
1414
1415 void* Emitter::GetClassName(void* vmtPtr, int32_t classNameVmtIndexOffset)
1416 {
1417 cmsxi::Value* classNamePtrPtr = context->CreateElemAddr(static_cast<cmsxi::Value*>(vmtPtr), context->GetLongValue(classNameVmtIndexOffset));
1418 cmsxi::Value* classNamePtr = context->CreateLoad(classNamePtrPtr);
1419 cmsxi::Value* classNameCharPtr = context->CreateBitCast(classNamePtr, context->GetPtrType(context->GetPtrType(context->GetByteType())));
1420 cmsxi::Value* className = context->CreateLoad(classNameCharPtr);
1421 return className;
1422 }
1423
1424 void* Emitter::ComputeAddress(void* ptr, void* index)
1425 {
1426 return context->CreatePtrOffset(static_cast<cmsxi::Value*>(ptr), static_cast<cmsxi::Value*>(index));
1427 }
1428
1429 void* Emitter::CreatePtrDiff(void* left, void* right)
1430 {
1431 return context->CreatePtrDiff(static_cast<cmsxi::Value*>(left), static_cast<cmsxi::Value*>(right));
1432 }
1433
1434 uint32_t Emitter::GetPrivateFlag()
1435 {
1436
1437 return uint32_t();
1438 }
1439
1440 uint32_t Emitter::GetProtectedFlag()
1441 {
1442
1443 return uint32_t();
1444 }
1445
1446 uint32_t Emitter::GetPublicFlag()
1447 {
1448
1449 return uint32_t();
1450 }
1451
1452 uint32_t Emitter::GetNoFlags()
1453 {
1454
1455 return uint32_t();
1456 }
1457
1458 void* Emitter::CreateModule(const std::string& moduleName)
1459 {
1460 return new cmsxi::CompileUnit(moduleName);
1461 }
1462
1463 void Emitter::DestroyModule(void* module)
1464 {
1465 delete static_cast<cmsxi::CompileUnit*>(module);
1466 }
1467
1468 void Emitter::SetModule(void* module_)
1469 {
1470 compileUnit = static_cast<cmsxi::CompileUnit*>(module_);
1471 context = compileUnit->GetContext();
1472 }
1473
1474 void Emitter::SetTargetTriple(const std::string& targetTriple)
1475 {
1476
1477 }
1478
1479 void Emitter::SetDataLayout(void* dataLayout_)
1480 {
1481
1482 }
1483
1484 void Emitter::SetSourceFileName(const std::string& sourceFileName)
1485 {
1486
1487 }
1488
1489 void Emitter::SetDICompileUnit(void* diCompileUnit_)
1490 {
1491
1492 }
1493
1494 void Emitter::SetDIFile(void* diFile_)
1495 {
1496
1497 }
1498
1499 void Emitter::SetColumnSpanProvider(cmajor::common::ColumnSpanProvider* columnSpanProvider_)
1500 {
1501
1502 }
1503
1504 void Emitter::ResetCurrentDebugLocation()
1505 {
1506
1507 }
1508
1509 void Emitter::StartDebugInfo(const std::string& sourceFilePath, const std::string& compilerVersion, bool optimized, cmajor::common::ColumnSpanProvider* columnSpanProvider_)
1510 {
1511
1512 }
1513
1514 void Emitter::FinalizeDebugInfo()
1515 {
1516
1517 }
1518
1519 void Emitter::EndDebugInfo()
1520 {
1521
1522 }
1523
1524 void Emitter::EmitIrText(const std::string& filePath)
1525 {
1526
1527 }
1528
1529 void Emitter::EmitIrFile(const std::string& filePath)
1530 {
1531
1532 }
1533
1534 void Emitter::Optimize(const std::string& bcFilePath, const std::string& optBCFilePath, const std::string& optimizationFlags)
1535 {
1536
1537 }
1538
1539 void Emitter::Disassemble(const std::string& bcFilePath, const std::string& filePath)
1540 {
1541
1542 }
1543
1544 void Emitter::Compile(const std::string& bcFilePath, const std::string& objectFilePath, int optimizationLevel)
1545 {
1546
1547 }
1548
1549 void Emitter::VerifyModule()
1550 {
1551
1552 }
1553
1554 void Emitter::EmitObjectCodeFile(const std::string& objectFilePath)
1555 {
1556
1557 }
1558
1559 void* Emitter::CreateDebugInfoForNamespace(void* scope, const std::string& name)
1560 {
1561
1562 return nullptr;
1563 }
1564
1565 void* Emitter::GetDebugInfoForFile(const Span& span, const boost::uuids::uuid& moduleId)
1566 {
1567
1568 return nullptr;
1569 }
1570
1571 void Emitter::PushScope(void* scope)
1572 {
1573
1574 }
1575
1576 void Emitter::PopScope()
1577 {
1578
1579 }
1580
1581 void* Emitter::CurrentScope()
1582 {
1583
1584 return nullptr;
1585 }
1586
1587 uint64_t Emitter::GetClassTypeSizeInBits(void* classIrType)
1588 {
1589
1590 return uint64_t();
1591 }
1592
1593 uint64_t Emitter::GetClassTypeAlignmentInBits(void* classIrType)
1594 {
1595
1596 return uint64_t();
1597 }
1598
1599 void Emitter::AddInlineFunctionAttribute(void* function)
1600 {
1601
1602 }
1603
1604 void Emitter::SetFunctionLinkage(void* function, bool setInline)
1605 {
1606
1607 }
1608
1609 void Emitter::SetFunctionLinkageToLinkOnceODRLinkage(void* function)
1610 {
1611
1612
1613 }
1614
1615 void Emitter::SetFunctionCallConventionToStdCall(void* function)
1616 {
1617
1618 }
1619
1620 void Emitter::SetFunction(void* function_, int32_t fileIndex, const boost::uuids::uuid& sourceModuleId, const boost::uuids::uuid& functionId)
1621 {
1622 currentFunction = static_cast<cmsxi::Function*>(function_);
1623 }
1624
1625 void Emitter::SetFunctionName(const std::string& functionName)
1626 {
1627 }
1628
1629 void Emitter::BeginScope()
1630 {
1631 }
1632
1633 void Emitter::EndScope()
1634 {
1635 }
1636
1637 int16_t Emitter::GetCurrentScopeId() const
1638 {
1639 return 0;
1640 }
1641
1642 void Emitter::SetCurrentScopeId(int16_t scopeId)
1643 {
1644 }
1645
1646 int32_t Emitter::AddControlFlowGraphNode()
1647 {
1648 return -1;
1649 }
1650
1651 void Emitter::SetCurrentControlFlowGraphNodeId(int32_t controlFlowGraphNodeId)
1652 {
1653 }
1654
1655 void Emitter::AddControlFlowGraphEdge(int32_t startNodeId, int32_t endNodeId)
1656 {
1657 }
1658
1659 void Emitter::AddLocalVariable(const std::string& localVariableName, const boost::uuids::uuid& typeId, void* irObject)
1660 {
1661 }
1662
1663 void Emitter::BeginInstructionFlag(int16_t flag)
1664 {
1665 }
1666
1667 void Emitter::EndInstructionFlag(int16_t flag)
1668 {
1669 }
1670
1671 void Emitter::SetInPrologue(bool inPrologue_)
1672 {
1673
1674 }
1675
1676 void* Emitter::CreateSubroutineType(const std::std::vector<void*>&elementTypes)
1677 {
1678
1679 return nullptr;
1680 }
1681
1682 unsigned Emitter::GetPureVirtualVirtuality()
1683 {
1684
1685 return unsigned();
1686 }
1687
1688 unsigned Emitter::GetVirtualVirtuality()
1689 {
1690
1691 return unsigned();
1692 }
1693
1694 unsigned Emitter::GetFunctionFlags(bool isStatic, unsigned accessFlags, bool isExplicit)
1695 {
1696
1697 return unsigned();
1698 }
1699
1700 void* Emitter::CreateDIMethod(const std::string& name, const std::string& mangledName, const Span& span, const boost::uuids::uuid& moduleId, void* subroutineType, unsigned virtuality, unsigned vtableIndex, void* vtableHolder,
1701 unsigned flags)
1702 {
1703
1704 return nullptr;
1705 }
1706
1707 void* Emitter::CreateDIFunction(const std::string& name, const std::string& mangledName, const Span& span, const boost::uuids::uuid& moduleId, void* subroutineType, unsigned flags)
1708 {
1709
1710 return nullptr;
1711 }
1712
1713 void Emitter::SetDISubprogram(void* function, void* subprogram)
1714 {
1715
1716 }
1717
1718 void* Emitter::CreateAlloca(void* irType)
1719 {
1720 return context->CreateLocal(static_cast<cmsxi::Type*>(irType));
1721 }
1722
1723 void* Emitter::CreateDIParameterVariable(const std::string& name, int index, const Span& span, const boost::uuids::uuid& moduleId, void* irType, void* allocaInst)
1724 {
1725
1726 return nullptr;
1727 }
1728
1729 void* Emitter::CreateDIAutoVariable(const std::string& name, const Span& span, const boost::uuids::uuid& moduleId, void* irType, void* allocaInst)
1730 {
1731
1732 return nullptr;
1733 }
1734
1735 void* Emitter::GetFunctionArgument(void* function, int argumentIndex)
1736 {
1737 return static_cast<cmsxi::Function*>(function)->GetParam(argumentIndex);
1738 }
1739
1740 void Emitter::SetDebugLoc(void* callInst)
1741 {
1742
1743 }
1744
1745 void* Emitter::CreateRet(void* value)
1746 {
1747 return context->CreateRet(static_cast<cmsxi::Value*>(value));
1748 }
1749
1750 void* Emitter::CreateRetVoid()
1751 {
1752 return context->CreateRet(nullptr);
1753 }
1754
1755 void Emitter::SetPersonalityFunction(void* function, void* personalityFunction)
1756 {
1757
1758 }
1759
1760 void Emitter::AddNoUnwindAttribute(void* function)
1761 {
1762
1763 }
1764
1765 void Emitter::AddUWTableAttribute(void* function)
1766 {
1767
1768 }
1769
1770 void* Emitter::CreateLexicalBlock(const Span& span, const boost::uuids::uuid& moduleId)
1771 {
1772
1773 return nullptr;
1774 }
1775
1776 void* Emitter::CreateSwitch(void* condition, void* defaultDest, unsigned numCases)
1777 {
1778 return context->CreateSwitch(static_cast<cmsxi::Value*>(condition), static_cast<cmsxi::BasicBlock*>(defaultDest));
1779 }
1780
1781 void Emitter::AddCase(void* switchInst, void* caseValue, void* caseDest)
1782 {
1783 cmsxi::SwitchInstruction* inst = static_cast<cmsxi::SwitchInstruction*>(switchInst);
1784 inst->AddCase(static_cast<cmsxi::Value*>(caseValue), static_cast<cmsxi::BasicBlock*>(caseDest));
1785 }
1786
1787 void* Emitter::GenerateTrap(const std::std::vector<void*>&args)
1788 {
1789 std::vector<cmsxi::Value*> arguments;
1790 for (void* arg : args)
1791 {
1792 arguments.push_back(static_cast<cmsxi::Value*>(arg));
1793 }
1794 return context->CreateTrap(arguments);
1795 }
1796
1797 void Emitter::SetCompileUnitId(const std::string& compileUnitId)
1798 {
1799 context->SetCompileUnitId(compileUnitId);
1800 }
1801
1802 void* Emitter::GetClsIdValue(const std::string& typeId)
1803 {
1804 return context->GetClsIdValue(typeId);
1805 }
1806
1807 void* Emitter::CreateMDBool(bool value)
1808 {
1809 return context->CreateMDBool(value);
1810 }
1811
1812 void* Emitter::CreateMDLong(int64_t value)
1813 {
1814 return context->CreateMDLong(value);
1815 }
1816
1817 void* Emitter::CreateMDString(const std::string& value)
1818 {
1819 return context->CreateMDString(value);
1820 }
1821
1822 void* Emitter::CreateMDStructRef(int id)
1823 {
1824 return context->CreateMDStructRef(id);
1825 }
1826
1827 int Emitter::GetMDStructId(void* mdStruct)
1828 {
1829 return static_cast<cmsxi::MDStruct*>(mdStruct)->Id();
1830 }
1831
1832 void* Emitter::CreateMDStruct()
1833 {
1834 return context->CreateMDStruct();
1835 }
1836
1837 void* Emitter::CreateMDBasicBlockRef(void* bb)
1838 {
1839 return context->CreateMDBasicBlockRef(bb);
1840 }
1841
1842 void Emitter::AddMDItem(void* mdStruct, const std::string& fieldName, void* mdItem)
1843 {
1844 context->AddMDStructItem(static_cast<cmsxi::MDStruct*>(mdStruct), fieldName, static_cast<cmsxi::MDItem*>(mdItem));
1845 }
1846
1847 void Emitter::SetFunctionMdId(void* function, int mdId)
1848 {
1849 static_cast<cmsxi::Function*>(function)->SetMdId(mdId);
1850 }
1851
1852 void Emitter::SetCurrentSourceSpan(int32_t line, int16_t scol, int16_t ecol)
1853 {
1854 context->SetCurrentLineNumber(line);
1855 }
1856
1857 void* Emitter::GetMDStructRefForSourceFile(const std::string& sourceFileName)
1858 {
1859 return context->GetMDStructRefForSourceFile(sourceFileName);
1860 }
1861
1862 void Emitter::SetMetadataRef(void* inst, void* mdStructRef)
1863 {
1864 context->SetMetadataRef(static_cast<cmsxi::Instruction*>(inst), static_cast<cmsxi::MDStructRef*>(mdStructRef));
1865 }
1866
1867 void Emitter::FinalizeFunction(void* function, bool hasCleanup)
1868 {
1869 static_cast<cmsxi::Function*>(function)->Finalize();
1870 }
1871
1872 int Emitter::Install(const std::string& str)
1873 {
1874 return emittingDelegate->Install(str);
1875 }
1876
1877 int Emitter::Install(const std::u16string& str)
1878 {
1879 return emittingDelegate->Install(str);
1880 }
1881
1882 int Emitter::Install(const std::u32string& str)
1883 {
1884 return emittingDelegate->Install(str);
1885 }
1886
1887 void* Emitter::CreateLandingPad(void* lpType)
1888 {
1889 return nullptr;
1890 }
1891
1892 void Emitter::SetLandindPadAsCleanup(void* landingPad)
1893 {
1894 }
1895
1896 void Emitter::MoveAllocaIntoBasicBlock(void* allocaInst, void* lastAlloca, void* basicBlock)
1897 {
1898 }
1899
1900 void Emitter::AddClauseToLangdingPad(void* landingPad, void* exceptionTypeId)
1901 {
1902 }
1903
1904 void* Emitter::CreateExtractValue(void* aggregate, const std::std::vector<unsigned int>&indeces)
1905 {
1906 return nullptr;
1907 }
1908
1909 void* Emitter::CreateInsertValue(void* aggregate, void* value, const std::std::vector<unsigned int>&indeces)
1910 {
1911 return nullptr;
1912 }
1913
1914 void* Emitter::CreateUndefValue(void* type)
1915 {
1916 return nullptr;
1917 }
1918
1919 void Emitter::CreateResume(void* exception)
1920 {
1921 }
1922
1923 void Emitter::DebugPrintDebugInfo(const std::string& filePath)
1924 {
1925 }
1926
1927 void Emitter::BeginSubstituteLineNumber(int32_t lineNumber)
1928 {
1929 }
1930
1931 void Emitter::EndSubstituteLineNumber()
1932 {
1933 }
1934
1935 }