hoshi-lang dev
Yet another programming language
Loading...
Searching...
No Matches
IR.cpp
Go to the documentation of this file.
1//
2// Created by XIaokang00010 on 2024/9/6.
3//
4
5#include "IR.h"
6
9#include "share/def.hpp"
10#include "share/magic_enum.h"
11#include <memory>
12#include <ranges>
13
15#include <stdexcept>
16#include <string>
17
18namespace yoi {
19 IROperand::operandValue::operandValue() : stringLiteralIndex(0) {}
20
22
23 IROperand::operandValue::operandValue(yoi::indexT indexV) : stringLiteralIndex(indexV) {}
24
26
28
30
32
33 IROperand::IROperand(IROperand::operandType type, IROperand::operandValue value) : type(type), value(value) {}
34
35 IROperand::IROperand(IROperand::operandType type, std::shared_ptr<IRValueType> lvalueType) : type(type), lvalueType(lvalueType) {}
36
37 std::shared_ptr<IRValueType> IROperand::getLvalueType() {
38 return lvalueType;
39 }
40
42 switch (type) {
44 return L"int(" + std::to_wstring(value.integer) + L")";
46 return L"double(" + std::to_wstring(value.decimal) + L")";
48 return L"bool(" + yoi::wstr(value.boolean ? L"true" : L"false") + L")";
50 return L"char(" + yoi::wstr(1, value.character) + L")";
52 return L"string_const#" + std::to_wstring(value.stringLiteralIndex);
54 return L"codeBlock#" + std::to_wstring(value.codeBlockIndex);
56 return L"index(" + std::to_wstring(value.symbolIndex) + L")";
58 return L"localVar#" + std::to_wstring(value.symbolIndex);
60 return L"globalVar#" + std::to_wstring(value.symbolIndex);
62 return L"externVar#" + std::to_wstring(value.symbolIndex);
64 return L"short(" + std::to_wstring(value.shortV) + L")";
66 return L"unsigned(" + std::to_wstring(value.unsignedV) + L")";
67 default:
68 return L"unknown";
69 }
70 }
71
72 IR::IR(IR::Opcode opcode, const vec<IROperand> &operands, IRDebugInfo debugInfo) : opcode(opcode), operands(operands), debugInfo(debugInfo) {}
73
75 yoi::wstr r;
76 r += string2wstring(magic_enum::enum_name<>(opcode).data());
77 r += L" ";
78 for (auto &operand : operands) {
79 r += operand.to_string();
80 r += L" ";
81 }
82 return r;
83 }
84
86 const yoi::wstr &name,
87 std::tuple<IRValueType::valueType, yoi::indexT, yoi::indexT> implStructIndex,
88 const std::pair<yoi::indexT, yoi::indexT> &implInterfaceIndex,
89 const yoi::vec<std::shared_ptr<IRValueType>> &virtualMethods,
90 const std::map<yoi::wstr, yoi::indexT> &virtualMethodIndexMap)
91 : name(name), implStructIndex(implStructIndex), virtualMethods(virtualMethods), virtualMethodIndexMap(virtualMethodIndexMap),
92 implInterfaceIndex(implInterfaceIndex) {}
93
95 const std::map<yoi::wstr, yoi::vec<yoi::indexT>> &functionOverloadIndexies,
96 const yoi::indexTable<yoi::wstr, std::shared_ptr<IRFunctionDefinition>> &methodMap)
97 : name(name), functionOverloadIndexies(functionOverloadIndexies), methodMap(methodMap) {}
98
100 yoi::wstr r;
101 r += yoi::wstr(indent, L' ') + L"Module#" + std::to_wstring(identifier) + L" {\n";
102 for (auto &function : functionTable) {
103 r += function.second->to_string(indent + 4);
104 }
105 for (auto &structType : structTable) {
106 r += structType.second->to_string(indent + 4);
107 }
108 for (auto &interfaceType : interfaceTable) {
109 r += interfaceType.second->to_string(indent + 4);
110 }
111 for (auto &interfaceImpl : interfaceImplementationTable) {
112 r += interfaceImpl.second->to_string(indent + 4);
113 }
114 r += yoi::wstr(indent, L' ') + L"}\n";
115 return r;
116 }
117
118 IRBuilder::IRBuilder(std::shared_ptr<compilerContext> compilerCtx,
119 std::shared_ptr<IRModule> currentModule,
120 std::shared_ptr<IRFunctionDefinition> currentFunction)
121 : compilerCtx(compilerCtx), currentModule(currentModule), currentFunction(currentFunction), currentCodeBlockIndex(0), currentDebugInfo() {}
122
124 codeBlocks.emplace_back(std::make_shared<IRCodeBlock>(IRCodeBlock{}));
125 return (yoi::indexT)codeBlocks.size() - 1;
126 }
127
129 return *codeBlocks[index];
130 }
131
134 currentFunction = nullptr;
135 codeBlocks.clear();
136 }
137
141
142 yoi::IROperand IRBuilder::createLocalVar(const yoi::wstr &varName, const std::shared_ptr<IRValueType> &type) {
143 auto idx = currentFunction->getVariableTable().put(varName, type);
144 return {IROperand::operandType::localVar, {idx}};
145 }
146
147 void IRBuilder::insert(const IR &ir, yoi::indexT insertionPoint) {
148 if (insertionPoint == 0xffffffff) {
149 getCurrentCodeBlock().getIRArray().push_back(ir);
150 } else {
151 auto insPoint = getCurrentCodeBlock().getIRArray().begin() + insertionPoint;
152 // if (insPoint != getCurrentCodeBlock().getIRArray().end()) {
153 // insPoint++;
154 // }
155 getCurrentCodeBlock().getIRArray().insert(insPoint, ir);
156 }
157 }
158
159 std::shared_ptr<IRValueType> &IRBuilder::getLhsFromTempVarStack() {
160 yoi_assert(tempVarStack.size() > 1, currentDebugInfo.line, currentDebugInfo.column, "tempVarStack is empty.");
161 return tempVarStack[tempVarStack.size() - 2];
162 }
163
164 std::shared_ptr<IRValueType> &IRBuilder::getRhsFromTempVarStack() {
165 yoi_assert(tempVarStack.size() > 0, currentDebugInfo.line, currentDebugInfo.column, "tempVarStack is empty.");
166 return tempVarStack[tempVarStack.size() - 1];
167 }
168
169 void IRBuilder::basicCast(const std::shared_ptr<IRValueType> &valType, yoi::indexT insertionPoint, bool lhs) {
170 auto &target = tempVarStack.at(lhs ? tempVarStack.size() - 2 : tempVarStack.size() - 1);
171 switch (valType->type) {
176 "Type mismatch in basicCast.");
177 insert({IR::Opcode::basic_cast_int, {}, currentDebugInfo}, insertionPoint);
178 target = compilerCtx->getIntObjectType();
179 break;
184 "Type mismatch in basicCast.");
186 target = compilerCtx->getDeciObjectType();
187 break;
192 "Type mismatch in basicCast.");
194 target = compilerCtx->getCharObjectType();
195 break;
200 "Type mismatch in basicCast.");
202 target = compilerCtx->getBoolObjectType();
203 break;
205 insert({IR::Opcode::pointer_cast, {}, currentDebugInfo}, insertionPoint);
207 break;
212 "Type mismatch in basicCast.");
214 target = compilerCtx->getShortObjectType();
215 break;
220 "Type mismatch in basicCast.");
222 target = compilerCtx->getUnsignedObjectType();
223 break;
224 default: {
227 "Unsupported type for basicCast: " + std::string{magic_enum::enum_name<>(valType->type)});
228 break;
229 }
230 }
231 }
232
234 // fetch lhs from tempVarStack
235 auto left = tempVarStack.back();
236 tempVarStack.pop_back();
237 // push result to tempVarStack
238 tempVarStack.emplace_back(left);
239 insert({op, {}, currentDebugInfo});
240 }
241
243 // fetch lhs and rhs from tempVarStack
244 auto right = tempVarStack.back();
245 tempVarStack.pop_back();
246 auto left = tempVarStack.back();
247 tempVarStack.pop_back();
248 yoi_assert(left->type == right->type,
251 "Type mismatch in arithmetic operation: " + wstring2string(left->to_string()) + " " + std::string{magic_enum::enum_name<>(op)} +
252 " " + wstring2string(right->to_string()));
253 // push result to tempVarStack
254 switch (op) {
255 case IR::Opcode::add:
256 case IR::Opcode::sub:
257 case IR::Opcode::mul:
258 case IR::Opcode::div:
259 case IR::Opcode::mod:
266 tempVarStack.emplace_back(left);
267 break;
268 }
275 tempVarStack.emplace_back(compilerCtx->getBoolObjectType());
276 break;
277 }
278 default: {
279 panic(currentDebugInfo.line, currentDebugInfo.column, "Unsupported type for arithmetic operation.");
280 break;
281 }
282 }
283 insert({op, {}, currentDebugInfo});
284 }
285
291
293 // fetch condition from tempVarStack
294 auto condition = tempVarStack.back();
295 tempVarStack.pop_back();
296 if (hasTerminated())
297 return;
298 yoi_assert(condition->type == IRValueType::valueType::booleanObject, 0, 0, "Type mismatch in jumpIf operation.");
299 // insert jumpIf operation
301 }
302
304 if (op == IR::Opcode::push_null) {
306 } else if (constV.type == IROperand::operandType::integer) {
307 // tempVarStack.push_back()
308 tempVarStack.emplace_back(compilerCtx->getIntObjectType());
309 } else if (constV.type == IROperand::operandType::boolean) {
310 tempVarStack.emplace_back(compilerCtx->getBoolObjectType());
311 } else if (constV.type == IROperand::operandType::character) {
312 tempVarStack.emplace_back(compilerCtx->getCharObjectType());
313 } else if (constV.type == IROperand::operandType::decimal) {
314 tempVarStack.emplace_back(compilerCtx->getDeciObjectType());
315 } else if (constV.type == IROperand::operandType::stringLiteral) {
316 tempVarStack.emplace_back(compilerCtx->getStrObjectType());
318 return;
319 } else if (constV.type == IROperand::operandType::shortInt) {
320 tempVarStack.emplace_back(compilerCtx->getShortObjectType());
321 } else if (constV.type == IROperand::operandType::unsignedInt) {
322 tempVarStack.emplace_back(compilerCtx->getUnsignedObjectType());
323 } else {
324 panic(currentDebugInfo.line, currentDebugInfo.column, "Unsupported constant type for pushOp");
325 }
326 insert({op, {constV}, currentDebugInfo});
327 }
328
329 void IRBuilder::loadOp(IR::Opcode op, const yoi::IROperand &source, const std::shared_ptr<IRValueType> &expectedType, yoi::indexT moduleIndex) {
331 insert({op, {source}, currentDebugInfo});
332 } else if (op == IR::Opcode::load_element) {
333 tempVarStack.pop_back();
334 tempVarStack.pop_back();
335 insert({op, {}, currentDebugInfo});
336 } else if (moduleIndex == -1) {
338 } else {
339 insert({op, {{IROperand::operandType::index, moduleIndex}, source}, currentDebugInfo});
340 }
341 tempVarStack.emplace_back(expectedType);
342 }
343
344 void IRBuilder::loadMemberOp(const yoi::IROperand &memberIndex, const std::shared_ptr<IRValueType> &memberType) {
345 tempVarStack.pop_back();
346 tempVarStack.emplace_back(memberType);
348 }
349
350 void IRBuilder::storeOp(IR::Opcode op, const yoi::IROperand &operand, yoi::indexT moduleIndex) {
351 switch (op) {
356 // fetch rhs from tempVarStack
357 tempVarStack.pop_back();
358 insert({op, {operand}, currentDebugInfo});
359 break;
360 }
362 // fetch rhs from tempVarStack
363 tempVarStack.pop_back();
364 insert(
365 {op, {{IROperand::operandType::index, moduleIndex == -1 ? currentModule->identifier : moduleIndex}, operand}, currentDebugInfo});
366 break;
367 }
368 default: {
369 panic(currentDebugInfo.line, currentDebugInfo.column, "Unsupported operand type for storeOp");
370 break;
371 }
372 }
373 }
374
375 void IRBuilder::storeMemberOp(const yoi::IROperand &memberIndex) {
376 // pop rhs and lhs from tempVarStack
377 tempVarStack.pop_back();
378 tempVarStack.pop_back();
380 }
381
383 yoi::indexT funcArgsCount,
384 const std::shared_ptr<IRValueType> &returnType,
385 bool externalInvocation,
386 yoi::indexT moduleIndex) {
387 for (yoi::indexT i = 0; i < funcArgsCount; i++) {
388 tempVarStack.pop_back();
389 }
390 tempVarStack.push_back(returnType);
392 {{IROperand::operandType::index, externalInvocation ? moduleIndex : currentModule->identifier},
394 {IROperand::operandType::index, funcArgsCount}},
396 }
397
399 yoi::indexT methodArgsCount,
400 const std::shared_ptr<IRValueType> &returnType,
401 bool isStatic,
402 bool externalInvocation,
403 yoi::indexT moduleIndex) {
404 // this pointer is popped from tempVarStack
405 for (yoi::indexT i = 0; i < methodArgsCount + 1; i++) {
406 tempVarStack.pop_back();
407 }
408 // pop this pointer from tempVarStack, the instructions related to `this` pointer should be eradicated during IROptimizer.
409 if (isStatic)
411
412 tempVarStack.push_back(returnType);
414 {{IROperand::operandType::index, externalInvocation ? moduleIndex : currentModule->identifier},
416 {IROperand::operandType::index, methodArgsCount + 1 - isStatic}},
418 }
419
421 yoi::indexT interfaceIndex,
422 yoi::indexT methodArgsCount,
423 const std::shared_ptr<IRValueType> &returnType,
424 bool externalInvocation,
425 yoi::indexT moduleIndex) {
426 for (yoi::indexT i = 0; i < methodArgsCount + 1; i++) {
427 tempVarStack.pop_back();
428 }
429 tempVarStack.push_back(returnType);
431 {{IROperand::operandType::index, externalInvocation ? moduleIndex : currentModule->identifier},
432 {IROperand::operandType::index, interfaceIndex},
434 {IROperand::operandType::index, methodArgsCount + 1}},
436 }
437
438 void IRBuilder::retOp(bool returnWithNone) {
439 // fetch return value from tempVarStack
440 if (returnWithNone) {
441 if (hasTerminated())
442 return;
444 return;
445 }
446 auto retValue = tempVarStack.back();
447 tempVarStack.pop_back();
448 if (hasTerminated())
449 return;
451 }
452
453 void IRBuilder::newStructOp(yoi::indexT structIndex, bool isExternal, yoi::indexT moduleIndex) {
455 {IROperand(IROperand::operandType::index, isExternal ? moduleIndex : currentModule->identifier),
458 tempVarStack.emplace_back(
459 managedPtr(IRValueType{IRValueType::valueType::structObject, isExternal ? moduleIndex : currentModule->identifier, structIndex}));
460 }
461
462 void IRBuilder::newDataStructOp(yoi::indexT structIndex, bool isExternal, yoi::indexT moduleIndex) {
464 {IROperand(IROperand::operandType::index, isExternal ? moduleIndex : currentModule->identifier),
467 tempVarStack.emplace_back(
468 managedPtr(IRValueType{IRValueType::valueType::datastructObject, isExternal ? moduleIndex : currentModule->identifier, structIndex}));
469 }
470
471 void IRBuilder::constructInterfaceImplOp(const std::pair<yoi::indexT, yoi::indexT> &interfaceId,
472 yoi::indexT interfaceImplIndex,
473 bool isExternal,
474 yoi::indexT moduleIndex) {
475 auto rhs = managedPtr(IRValueType{IRValueType::valueType::interfaceObject, interfaceId.first, interfaceId.second});
476 this->tempVarStack.pop_back(); // remove structObject from tempVarStack
477 tempVarStack.push_back(rhs);
479 {IROperand(IROperand::operandType::index, moduleIndex == -1 ? currentModule->identifier : moduleIndex),
480 IROperand(IROperand::operandType::index, interfaceImplIndex)},
482 }
483
487
489 tempVarStack.pop_back();
490 }
491
493 auto res = currentCodeBlockIndex;
494 currentCodeBlockIndex = index;
495 return res;
496 }
497
501
502 std::shared_ptr<IRFunctionDefinition> IRBuilder::irFuncDefinition() {
503 return currentFunction;
504 }
505
506 void IRCodeBlock::insert(const IR &ir) {
507 codeBlock.emplace_back(ir);
508 }
509
511 yoi::wstr r;
512 for (auto &ir : codeBlock) {
513 r += yoi::wstr(indent, L' ') + ir.to_string() + L"\n";
514 }
515 return r;
516 }
517
521
523 yoi::wstr r;
524 r += yoi::wstr(indent, L' ') + L"func " + name + L"(";
525 if (!argumentTypes.empty()) {
526 for (auto it = argumentTypes.begin(); it != argumentTypes.end() - 1; ++it) {
527 r += (*it)->to_string(true) + L", ";
528 }
529 r += argumentTypes.back()->to_string(true);
530 }
531 r += L") : " + returnType->to_string(true) + L" {\n";
532 r += variableTable.to_string(indent + 4);
533 for (auto idx = 0; idx < codeBlock.size(); ++idx) {
534 r += yoi::wstr(indent + 4, L' ') + L"block#" + std::to_wstring(idx) + L":\n";
535 r += codeBlock[idx]->to_string(indent + 8);
536 }
537 r += yoi::wstr(indent, L' ') + L"}\n";
538 return r;
539 }
540
542 this->name = name;
543 return *this;
544 }
545
547 this->name = interfaceName;
548 return *this;
549 }
550
552 IRInterfaceImplementationDefinition::Builder::setImplStructIndex(std::tuple<IRValueType::valueType, yoi::indexT, yoi::indexT> implStructIndex) {
553 this->implStructIndex = implStructIndex;
554 return *this;
555 }
556
558 IRInterfaceImplementationDefinition::Builder::setImplInterfaceIndex(const std::pair<yoi::indexT, yoi::indexT> &implInterfaceIndex) {
559 this->implInterfaceIndex = implInterfaceIndex;
560 return *this;
561 }
562
564 IRInterfaceImplementationDefinition::Builder::addVirtualMethod(const yoi::wstr &methodName, const std::shared_ptr<IRValueType> &methodType) {
565 this->virtualMethods.emplace_back(methodType);
566 this->virtualMethodIndexMap[methodName] = this->virtualMethods.size() - 1;
567 return *this;
568 }
569
570 std::shared_ptr<IRInterfaceImplementationDefinition> IRInterfaceImplementationDefinition::Builder::yield() {
571 return std::make_shared<IRInterfaceImplementationDefinition>(IRInterfaceImplementationDefinition{
572 std::move(name), implStructIndex, implInterfaceIndex, std::move(virtualMethods), std::move(virtualMethodIndexMap)});
573 }
574
576 this->name = interfaceName;
577 return *this;
578 }
579
581 const yoi::wstr &methodNameOri, const yoi::wstr &methodName, const std::shared_ptr<IRFunctionDefinition> &methodSignature) {
582 this->functionOverloadIndexies[methodNameOri].push_back(this->methodMap.put_create(methodName, methodSignature));
583 return *this;
584 }
585
586 std::shared_ptr<IRInterfaceInstanceDefinition> IRInterfaceInstanceDefinition::Builder::yield() {
587 return std::make_shared<IRInterfaceInstanceDefinition>(std::move(name), std::move(functionOverloadIndexies), std::move(methodMap));
588 }
589
591 const std::shared_ptr<IRValueType> &argumentType) {
592 this->argumentTypes.emplace_back(argumentName, argumentType);
593 return *this;
594 }
595
597 this->returnType = returnType;
598 return *this;
599 }
600
601 std::shared_ptr<IRFunctionDefinition> IRFunctionDefinition::Builder::yield() {
603 }
604
606 const yoi::vec<std::pair<yoi::wstr, std::shared_ptr<IRValueType>>> &argumentTypes,
607 const std::shared_ptr<IRValueType> &returnType,
608 const yoi::vec<std::shared_ptr<IRCodeBlock>> &codeBlock,
609 const std::set<FunctionAttrs> &attrs,
610 const IRDebugInfo &debugInfo)
613 for (auto &i : argumentTypes) {
614 variableTable.put(i.first, i.second);
615 this->argumentTypes.push_back(i.second);
616 }
617 }
618
622
623 IRValueType::IRValueType(IRValueType::valueType type, yoi::indexT typeAffiliateModule, yoi::indexT objectPrototypeIndex)
624 : type(type), typeAffiliateModule(typeAffiliateModule), typeIndex(objectPrototypeIndex), dimensions() {}
625
626 IRValueType::IRValueType(IRValueType::valueType type) : type(type), typeIndex(0), typeAffiliateModule(0), dimensions() {}
627
634
638
642
644 auto res = *this;
645 switch (type) {
648 break;
650 res.type = valueType::integerObject;
651 break;
653 res.type = valueType::unsignedObject;
654 break;
655 default:
656 break;
657 }
658 return res;
659 }
660
661 yoi::wstr IRValueType::to_string(bool showAttributes) const {
662 yoi::wstr res;
663 switch (type) {
665 res = L"int_literal";
666 break;
668 res = L"deci_literal";
669 break;
671 res = L"bool_literal";
672 break;
674 res = L"short_literal";
675 break;
677 res = L"unsigned_literal";
678 break;
680 res = L"char";
681 break;
683 res = L"string";
684 break;
686 res = L"struct#" + std::to_wstring(typeAffiliateModule) + L"#" + std::to_wstring(typeIndex);
687 break;
688 case valueType::null:
689 res = L"null";
690 break;
692 res = L"int";
693 break;
695 res = L"bool";
696 break;
698 res = L"decimal";
699 break;
701 res = L"short";
702 break;
704 res = L"unsigned";
705 break;
707 res = L"string";
708 break;
709 case valueType::none:
710 res = L"none";
711 break;
713 res = L"interface#" + std::to_wstring(typeAffiliateModule) + L"#" + std::to_wstring(typeIndex);
714 break;
716 res = L"pointerObject";
717 break;
719 res = L"pointer";
720 break;
722 res = L"virtual_method#" + std::to_wstring(typeAffiliateModule) + L"#" + std::to_wstring(typeIndex);
723 break;
725 res = L"incomplete_template_type#" + std::to_wstring(typeIndex);
726 break;
728 res = L"datastruct#" + std::to_wstring(typeAffiliateModule) + L"#" + std::to_wstring(typeIndex);
729 break;
730 default:
731 res = L"unknown";
732 break;
733 }
734
735 if (!dimensions.empty()) {
736 if (dimensions.back() == -1)
737 res += L"[]";
738 else
739 for (auto d : dimensions)
740 res += L"[" + std::to_wstring(d) + L"]";
741 }
742
743 if (showAttributes)
744 for (auto &i : attributes)
745 res += L" @" + string2wstring(std::string{magic_enum::enum_name(i)});
746
747 if (showAttributes)
748 res += L" " + metadata.to_string();
749
750 return res;
751 }
752
754 return type == rhs.type && typeIndex == rhs.typeIndex && typeAffiliateModule == rhs.typeAffiliateModule &&
755 dimensions.size() == rhs.dimensions.size();
756 }
757
759 const std::map<yoi::wstr, nameInfo> &nameInfoMap,
760 const vec<std::shared_ptr<IRValueType>> &fieldTypes,
761 const yoi::vec<yoi::wstr> &templateParamNames,
762 const yoi::vec<std::shared_ptr<IRValueType>> &storedTemplateArgs,
763 const std::map<yoi::wstr, yoi::structDefInnerPair *> &templateMethodDecls,
764 const std::map<yoi::wstr, yoi::implInnerPair *> &templateMethodDefs)
765 : name(name), nameIndexMap(nameInfoMap), fieldTypes(fieldTypes), templateParamNames(templateParamNames),
766 storedTemplateArgs(storedTemplateArgs), templateMethodDecls(templateMethodDecls), templateMethodDefs(templateMethodDefs) {}
767
769 yoi::wstr r;
770 r += yoi::wstr(indent, L' ') + L"struct " + name + L" {\n";
771 for (auto &i : nameIndexMap) {
772 if (i.second.type == nameInfo::nameType::field) {
773 r += yoi::wstr(indent + 4, L' ') + i.first + L" " + fieldTypes[i.second.index]->to_string(true) + L"\n";
774 }
775 }
776 r += yoi::wstr(indent, L' ') + L"}\n";
777 return r;
778 }
779
781 try {
782 return nameIndexMap.at(name);
783 } catch (std::out_of_range &e) {
784 throw std::out_of_range("Undefined field: " + yoi::wstring2string(name));
785 }
786 }
787
789 this->name = name;
790 return *this;
791 }
792
793 IRStructDefinition::Builder &IRStructDefinition::Builder::addField(const yoi::wstr &fieldName, const std::shared_ptr<IRValueType> &fieldType) {
794 this->fieldTypes.push_back(fieldType);
795 nameIndexMap[fieldName] = nameInfo{nameInfo::nameType::field, this->fieldTypes.size() - 1};
796 return *this;
797 }
798
803
805 const yoi::vec<std::shared_ptr<IRValueType>> &args) {
806 this->templateParamNames = paramNames;
807 this->storedTemplateArgs = args;
808 return *this;
809 }
810
815
820
821 std::shared_ptr<IRStructDefinition> IRStructDefinition::Builder::yield() {
822 return std::make_shared<IRStructDefinition>(std::move(name),
823 std::move(nameIndexMap),
824 std::move(fieldTypes),
825 std::move(templateParamNames),
826 std::move(storedTemplateArgs),
827 std::move(templateMethodDecls),
828 std::move(templateMethodDefs));
829 }
830
832 return pool.put(str);
833 }
834
836 return pool[index];
837 }
838
840 for (auto &it : std::ranges::reverse_view(variableNameIndexMap)) {
841 if (auto item = it.find(name); item != it.end()) {
842 return item->second;
843 }
844 }
845 throw std::out_of_range("Undefined variable: " + yoi::wstring2string(name));
846 }
847
849 variableNameIndexMap.emplace_back();
850 return (yoi::indexT)variableNameIndexMap.size() - 1;
851 }
852
854 variableNameIndexMap.pop_back();
855 }
856
858 yoi::wstr r;
859 r += yoi::wstr(indent, L' ') + L"Variables {\n";
860 for (int64_t i = 0; i < variables.size(); ++i) {
861 r += yoi::wstr(indent + 4, L' ') + L"#" + std::to_wstring(i) + L" " + reversedVariableNameMap[i] + L"(scope#" +
862 std::to_wstring(variableScopeMap[i]) + L") : " + variables[i]->to_string(true) + L"\n";
863 }
864 return r + yoi::wstr(indent, L' ') + L"}\n";
865 }
866
867 std::shared_ptr<IRValueType> IRVariableTable::get(yoi::indexT index) {
868 return variables[index];
869 }
870
871 std::shared_ptr<IRValueType> IRVariableTable::operator[](const wstr &name) {
872 return variables[lookup(name)];
873 }
874
875 yoi::indexT IRVariableTable::put(const wstr &name, const std::shared_ptr<IRValueType> &type) {
876 variables.emplace_back(type);
877 variableNameIndexMap.back()[name] = variables.size() - 1;
878 variableScopeMap[variables.size() - 1] = variableNameIndexMap.size() - 1;
879 reversedVariableNameMap[variables.size() - 1] = name;
880 return variables.size() - 1;
881 }
882
884 : type(type), name(name), affiliateModule(affiliateModule), itemIndex(itemIndex) {}
885
889
891 this->buildType = buildType;
892 return *this;
893 }
894
896 this->buildPlatform = buildPlatform;
897 return *this;
898 }
899
901 this->buildArch = buildArch;
902 return *this;
903 }
904
920
925
930
935
937 yoi::wstr r;
938 r += yoi::wstr(indent, L' ') + L"interface " + name + L" {\n";
939 for (auto &i : methodMap) {
940 r += i.second->to_string(indent + 4) + L"\n";
941 }
942 r += yoi::wstr(indent, L' ') + L"}\n";
943 return r;
944 }
945
947 yoi::wstr r;
948 r += yoi::wstr(indent, L' ') + L"impl " + name + L" for " +
949 yoi::string2wstring(std::string{magic_enum::enum_name(std::get<0>(implStructIndex))}) + L"#" +
950 std::to_wstring(std::get<1>(implStructIndex)) + L"#" + std::to_wstring(std::get<2>(implStructIndex)) + L" {\n";
951
952 for (auto &i : virtualMethods) {
953 r += yoi::wstr(indent + 4, L' ') + L"virtual " + i->to_string() + L"\n";
954 }
955 r += yoi::wstr(indent, L' ') + L"}\n";
956 return r;
957 }
958
959 IRTemplateBuilder::Argument::Argument(const std::shared_ptr<IRValueType> &templateType) : templateType(templateType) {}
960
961 IRFunctionTemplate::IRFunctionTemplate(const std::shared_ptr<IRFunctionDefinition> &templateDefinition,
963 : templateDefinition(templateDefinition), templateArguments(templateArguments) {}
964
965 IRFunctionTemplate::Builder &IRFunctionTemplate::Builder::setTemplateDefinition(const std::shared_ptr<IRFunctionDefinition> &templateDefinition) {
966 this->templateDefinition = templateDefinition;
967 return *this;
968 }
969
970 std::shared_ptr<IRFunctionTemplate> IRFunctionTemplate::Builder::yield() {
971 return std::make_shared<IRFunctionTemplate>(templateDefinition, templateArguments);
972 }
973
975 this->templateDefinition = templateDefinition;
976 return *this;
977 }
978
979 std::shared_ptr<IRStructTemplate> IRStructTemplate::Builder::yield() {
980 return std::make_shared<IRStructTemplate>(IRStructTemplate{templateDefinition, templateMethods, templateArguments});
981 }
982
986
988 IRInterfaceInstanceTemplate::Builder::setTemplateDefinition(const std::shared_ptr<IRInterfaceInstanceDefinition> &templateDefinition) {
989 this->templateDefinition = templateDefinition;
990 return *this;
991 }
992
993 std::shared_ptr<IRInterfaceInstanceTemplate> IRInterfaceInstanceTemplate::Builder::yield() {
994 return std::make_shared<IRInterfaceInstanceTemplate>(templateDefinition, templateArguments);
995 }
996
1001
1003 const std::shared_ptr<IRInterfaceImplementationDefinition> &templateDefinition) {
1004 this->templateDefinition = templateDefinition;
1005 return *this;
1006 }
1007
1008 std::shared_ptr<IRInterfaceImplementationTemplate> IRInterfaceImplementationTemplate::Builder::yield() {
1009 return std::make_shared<IRInterfaceImplementationTemplate>(templateDefinition, templateArguments);
1010 }
1011
1013 const std::shared_ptr<IRValueType> &templateType,
1014 const yoi::vec<externModuleAccessExpression *> &satisfyConditions) {
1015 templateArguments.put_create(templateName, {templateType, satisfyConditions});
1016 return *this;
1017 }
1018
1020 const std::shared_ptr<IRFunctionTemplate> &methodTemplate) {
1021 // templateMethods[methodName] = methodTemplate;
1022 templateMethods.put_create(methodName, methodTemplate);
1023 return *this;
1024 }
1025
1029
1030 std::map<yoi::indexT, yoi::wstr> &IRVariableTable::getReversedVariableNameMap() {
1031 return reversedVariableNameMap;
1032 }
1033
1034 IRStructTemplate::IRStructTemplate(const std::shared_ptr<IRStructDefinition> &templateDefinition,
1035 const yoi::indexTable<yoi::wstr, std::shared_ptr<IRFunctionTemplate>> &templateMethods,
1037 : templateDefinition(templateDefinition), templateMethods(templateMethods), templateArguments(templateArguments) {}
1038
1039 IRFFITable::ImportLibrary::ImportLibrary(const yoi::wstr &libraryPath) : libraryPath(libraryPath) {}
1040
1042 const yoi::wstr &functionName,
1043 const std::shared_ptr<IRFunctionDefinition> &functionDefinition) {
1044 if (!importedLibraries.contains(libraryName)) {
1045 importedLibraries.put_create(libraryName, {libraryName});
1046 }
1047
1048 return importedLibraries[libraryName].importedFunctionTable.put(functionName, functionDefinition);
1049 }
1050
1052 yoi::indexT moduleIndex,
1053 yoi::indexT functionIndex,
1054 const std::set<IRFunctionDefinition::FunctionAttrs> &attrs) {
1055 exportedFunctionTable.put_create(exportName, std::make_tuple(moduleIndex, functionIndex, attrs));
1056 }
1057
1058 void IRFFITable::addForeignType(const yoi::wstr &foreignTypeName, const std::shared_ptr<IRValueType> &structType) {
1059 foreignTypeTable.put_create(foreignTypeName, structType);
1060 }
1061
1063 this->searchPaths = searchPaths;
1064 return *this;
1065 }
1066
1068 searchPaths.push_back(searchPath);
1069 return *this;
1070 }
1071
1073 yoi::indexT funcIndex,
1074 yoi::indexT funcArgsCount,
1075 const std::shared_ptr<IRValueType> &returnType) {
1076 for (yoi::indexT i = 0; i < funcArgsCount; ++i) {
1077 tempVarStack.pop_back();
1078 }
1079 tempVarStack.push_back(managedPtr(compilerCtx->normalizeForeignBasicType(returnType)));
1080
1081 // insert(IR{IR::Opcode::invoke_imported, {IROperand(IROperand::operandType::index, externIndex),
1082 // IROperand(IROperand::operandType::index, funcArgsCount)}});
1087 currentDebugInfo});
1088 }
1089
1091 return !dimensions.empty() && dimensions.back() != static_cast<yoi::indexT>(-1);
1092 }
1093
1095 yoi::indexT typeAffiliateModule,
1096 yoi::indexT objectPrototypeIndex,
1097 const yoi::vec<yoi::indexT> &dimensions)
1098 : type(type), dimensions(dimensions), typeAffiliateModule(typeAffiliateModule), typeIndex(objectPrototypeIndex) {}
1099
1101 : type(type), dimensions(dimensions), typeAffiliateModule(0), typeIndex(0) {}
1102
1106
1107 void
1108 IRBuilder::newArrayOp(const std::shared_ptr<IRValueType> &elementType, const yoi::vec<yoi::indexT> &dimensions, yoi::indexT onstackElementCount) {
1110 yoi::vec<IROperand> operands;
1111 switch (elementType->type) {
1114 break;
1117 break;
1120 break;
1123 break;
1126 break;
1129 break;
1132 break;
1135 operands.emplace_back(IROperand::operandType::index, elementType->typeAffiliateModule);
1136 operands.emplace_back(IROperand::operandType::index, elementType->typeIndex);
1137 break;
1140 operands.emplace_back(IROperand::operandType::index, elementType->typeAffiliateModule);
1141 operands.emplace_back(IROperand::operandType::index, elementType->typeIndex);
1142 break;
1143 default:
1146 "Unsupported array element type: " + yoi::wstring2string(elementType->to_string()));
1147 break;
1148 }
1149 auto size = 1;
1150 operands.emplace_back(IROperand::operandType::index, onstackElementCount);
1151 for (auto &dim : dimensions) {
1152 operands.emplace_back(IROperand::operandType::index, dim);
1153 size *= dim;
1154 }
1155 for (yoi::indexT i = 0; i < onstackElementCount; ++i) {
1156 tempVarStack.pop_back();
1157 }
1158 insert(IR{op, operands, currentDebugInfo});
1159 tempVarStack.push_back(managedPtr(elementType->getArrayType(dimensions)));
1160 }
1161
1165
1170
1172 yoi_assert(!codeBlockInsertionStates.empty(), currentDebugInfo.line, currentDebugInfo.column, "Empty code states when poping back");
1173 codeBlockInsertionStates.pop_back();
1174 }
1175
1180 "Invalid code block index");
1181 codeBlocks[currentCodeBlockIndex]->getIRArray().resize(std::get<1>(codeBlockInsertionStates.back()));
1182 tempVarStack.resize(std::get<2>(codeBlockInsertionStates.back()));
1183 yoi_assert(!codeBlockInsertionStates.empty(), currentDebugInfo.line, currentDebugInfo.column, "Empty code states when poping back");
1184 codeBlockInsertionStates.pop_back();
1185 }
1186
1187 void IRBuilder::pushTempVar(const std::shared_ptr<IRValueType> &type) {
1188 tempVarStack.push_back(type);
1189 }
1190
1193 auto elementCount = tempVarStack.back()->bracedTypes.size();
1194 for (yoi::indexT i = 0; i < elementCount; ++i) {
1195 tempVarStack.pop_back();
1197 }
1198 } else {
1199 tempVarStack.pop_back();
1201 }
1202 }
1203
1204 void IRBuilder::setDebugInfo(const IRDebugInfo &debugInfo) {
1206 this->currentDebugInfo = debugInfo;
1207 }
1208
1212
1214 this->debugInfo = debugInfo;
1215 return *this;
1216 }
1217
1219 auto rhs = tempVarStack.back();
1220 tempVarStack.pop_back();
1221 typeIdOp(rhs);
1222 }
1223
1224 void IRBuilder::typeIdOp(const std::shared_ptr<IRValueType> &type) {
1225 IR::Opcode op;
1226 vec<IROperand> operand;
1227 if (type->isArrayType() || type->isDynamicArrayType()) {
1228 yoi::indexT size = 1;
1229 for (auto &dim : type->dimensions) {
1230 size *= dim;
1231 }
1232
1234 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(type->type));
1235 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(type->typeAffiliateModule));
1236 operand.emplace_back(IROperand::operandType::index, type->typeIndex);
1237 operand.emplace_back(IROperand::operandType::index, size);
1238 } else {
1240 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(type->type));
1241 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(type->typeAffiliateModule));
1242 operand.emplace_back(IROperand::operandType::index, type->typeIndex);
1243 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(0));
1244 }
1245 insert(IR(op, operand, currentDebugInfo));
1247 }
1248
1249 void IRBuilder::dynCastOp(const std::shared_ptr<IRValueType> &type) {
1250 IR::Opcode op;
1251 vec<IROperand> operand;
1252
1254 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(type->type));
1255 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(type->typeAffiliateModule));
1256 operand.emplace_back(IROperand::operandType::index, type->typeIndex);
1257
1258 if (type->isDynamicArrayType() || type->isArrayType()) {
1259 yoi::indexT size = 1;
1260 for (auto &dim : type->dimensions) {
1261 size *= dim;
1262 }
1263
1264 operand.emplace_back(IROperand::operandType::index, size);
1265 } else {
1266 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(0));
1267 }
1268 insert(IR(op, operand, currentDebugInfo));
1269 tempVarStack.pop_back();
1270 tempVarStack.push_back(type);
1271 }
1272
1277
1279 insert(IR{IR::Opcode::pointer_cast, {}, currentDebugInfo});
1280 tempVarStack.pop_back();
1282 }
1283
1284 void IRBuilder::newDynamicArrayOp(const std::shared_ptr<IRValueType> &elementType, yoi::indexT initializerSize) {
1286 yoi::vec<IROperand> operands;
1287 switch (elementType->type) {
1290 break;
1293 break;
1296 break;
1299 break;
1302 break;
1305 break;
1308 break;
1311 operands.emplace_back(IROperand::operandType::index, elementType->typeAffiliateModule);
1312 operands.emplace_back(IROperand::operandType::index, elementType->typeIndex);
1313 break;
1316 operands.emplace_back(IROperand::operandType::index, elementType->typeAffiliateModule);
1317 operands.emplace_back(IROperand::operandType::index, elementType->typeIndex);
1318 break;
1319 default:
1320 panic(currentDebugInfo.line,
1321 currentDebugInfo.column,
1322 "Unsupported array element type: " + yoi::wstring2string(elementType->to_string()));
1323 break;
1324 }
1325 operands.emplace_back(IROperand::operandType::index, initializerSize);
1326 insert(IR{op, operands, currentDebugInfo});
1327 for (yoi::indexT i = 0; i <= initializerSize; i++) {
1328 tempVarStack.pop_back(); // size and initializer
1329 }
1330 tempVarStack.push_back(managedPtr(elementType->getDynamicArrayType()));
1331 }
1332
1334 return {type, typeAffiliateModule, typeIndex, {static_cast<yoi::indexT>(-1)}};
1335 }
1336
1338 return dimensions.size() == 1 && dimensions.back() == static_cast<yoi::indexT>(-1);
1339 }
1340
1342 tempVarStack.pop_back();
1343 tempVarStack.push_back(compilerCtx->getIntObjectType());
1344 insert(IR{IR::Opcode::array_length, {}, currentDebugInfo});
1345 }
1346
1348 tempVarStack.pop_back();
1349 tempVarStack.pop_back();
1350 tempVarStack.push_back(compilerCtx->getBoolObjectType());
1351 insert(IR{IR::Opcode::interfaceof, {}, currentDebugInfo});
1352 }
1353
1355 return attributes.count(attr) > 0;
1356 }
1357
1359 attributes.erase(attr);
1360 return *this;
1361 }
1362
1364 attributes.insert(attr);
1365 return *this;
1366 }
1367
1368 IRValueType::IRValueType(valueType type, yoi::indexT typeAffiliateModule, yoi::indexT objectPrototypeIndex, const std::set<ValueAttr> &attributes)
1369 : type(type), typeAffiliateModule(typeAffiliateModule), typeIndex(objectPrototypeIndex), dimensions(), attributes(attributes) {}
1370
1375
1377 IRValueType result = *this;
1378 switch (type) {
1380 result.type = valueType::integerRaw;
1381 break;
1383 result.type = valueType::decimalRaw;
1384 break;
1386 result.type = valueType::booleanRaw;
1387 break;
1389 result.type = valueType::charRaw;
1390 break;
1393 break;
1396 break;
1399 break;
1400 default:
1401 break;
1402 }
1403 return result;
1404 }
1405
1426
1428 return std::find(attrs.begin(), attrs.end(), attr) != attrs.end();
1429 }
1430
1432 this->shortV = shortV;
1433 }
1434
1436 auto current = codeBlockInsertionStates.back();
1437 yoi_assert(currentCodeBlockIndex == std::get<0>(current), currentDebugInfo.line, currentDebugInfo.column, "Invalid code block index");
1438 tempStateCodeBlock = std::vector<IR>(codeBlocks[currentCodeBlockIndex]->getIRArray().begin() + std::get<1>(current),
1439 codeBlocks[currentCodeBlockIndex]->getIRArray().end());
1440 tempStateTempVarStack = std::vector<std::shared_ptr<IRValueType>>(tempVarStack.begin() + std::get<2>(current), tempVarStack.end());
1441
1442 codeBlocks[currentCodeBlockIndex]->getIRArray().resize(std::get<1>(current));
1443 tempVarStack.resize(std::get<2>(current));
1444 }
1445
1447 for (auto &block : tempStateCodeBlock) {
1448 codeBlocks[currentCodeBlockIndex]->getIRArray().push_back(block);
1449 }
1450 for (auto &type : tempStateTempVarStack) {
1451 tempVarStack.push_back(type);
1452 }
1453 tempStateCodeBlock.clear();
1454 tempStateTempVarStack.clear();
1455 discardState();
1456 }
1457
1459 while (codeBlockInsertionStates.size() > stateIndex) {
1460 discardState();
1461 }
1462 }
1463
1465 if (!codeBlocks[currentCodeBlockIndex]->getIRArray().empty()) {
1466 switch (codeBlocks[currentCodeBlockIndex]->getIRArray().back().opcode) {
1467 case IR::Opcode::ret:
1469 case IR::Opcode::jump:
1470 return true;
1471 default:
1472 break;
1473 }
1474 }
1475 return false;
1476 }
1477
1479 marcos[name] = value;
1480 return *this;
1481 }
1482
1484 return variableScopeMap[varIndex];
1485 }
1486
1488 loopContext.pop_back();
1489 }
1490
1492 yoi_assert(!loopContext.empty(), currentDebugInfo.line, currentDebugInfo.column, "break statement outside a `while` or `for` loop");
1493 jumpOp(loopContext.back().breakTarget);
1494 }
1495
1497 yoi_assert(!loopContext.empty(), currentDebugInfo.line, currentDebugInfo.column, "continue statement outside a `while` or `for` loop");
1498 jumpOp(loopContext.back().continueTarget);
1499 }
1500
1501 void IRBuilder::bindElementsOp(yoi::indexT extractElementCount, ExtractType extractType) {
1502 auto rhs = tempVarStack.back();
1503 tempVarStack.pop_back();
1504 for (yoi::indexT i = 0; i < extractElementCount; i++) {
1505 tempVarStack.push_back(managedPtr(rhs->getElementType()));
1506 }
1507
1508 insert(IR{extractType == ExtractType::First ? IR::Opcode::bind_elements_post : IR::Opcode::bind_elements_pred,
1509 {{IROperand::operandType::index, extractElementCount}},
1510 currentDebugInfo});
1511 }
1512
1513 void IRBuilder::bindFieldsOp(yoi::indexT extractFieldCount, ExtractType extractType) {
1514 auto rhs = tempVarStack.back();
1515 auto structDef = compilerCtx->getImportedModule(rhs->typeAffiliateModule)->structTable[rhs->typeIndex];
1516 yoi::indexT startPos = (extractType == ExtractType::First ? 0 : structDef->fieldTypes.size() - extractFieldCount);
1517
1518 for (auto curPos = startPos; curPos < startPos + extractFieldCount; curPos++) {
1519 tempVarStack.push_back(structDef->fieldTypes[curPos]);
1520 }
1521 insert(IR{extractType == ExtractType::First ? IR::Opcode::bind_fields_post : IR::Opcode::bind_fields_pred,
1522 {{IROperand::operandType::index, extractFieldCount}},
1523 currentDebugInfo});
1524 }
1525
1526 void IRBuilder::pushLoopContext(yoi::indexT breakTarget, yoi::indexT continueTarget) {
1527 loopContext.push_back({breakTarget, continueTarget});
1528 }
1529
1530 IRValueType::IRValueType() : type(valueType::none), typeAffiliateModule(0), typeIndex(0), dimensions() {}
1531
1533 yoi::indexT funcArgsCount,
1534 const std::shared_ptr<IRValueType> &returnType,
1535 bool externalInvocation,
1536 yoi::indexT moduleIndex) {
1537 for (yoi::indexT i = 0; i < funcArgsCount; i++) {
1538 tempVarStack.pop_back();
1539 }
1540 tempVarStack.push_back(returnType);
1542 {{IROperand::operandType::index, moduleIndex == -1 ? currentModule->identifier : moduleIndex},
1543 {IROperand::operandType::index, funcIndex},
1544 {IROperand::operandType::index, funcArgsCount}},
1546 }
1547
1549 this->additionalLinkingFiles = additionalLinkingFiles;
1550 return *this;
1551 }
1552
1557
1559 : name(name), valueToIndexMap(valueToIndexMap) {}
1560
1562 yoi::indexT maxIndex = 0;
1563
1564 for (auto &entry : valueToIndexMap)
1565 maxIndex = std::max(maxIndex, entry.second);
1566
1567 if (maxIndex <= 255)
1568 return UnderlyingType::I8;
1569 else if (maxIndex <= 65535)
1570 return UnderlyingType::I16;
1571 else
1572 return UnderlyingType::I64;
1573 }
1574
1576 this->name = name;
1577 return *this;
1578 }
1579
1581 this->valueToIndexMap.put_create(valueName, valueIndex);
1582 return *this;
1583 }
1584
1586 if (metadata.count(key)) {
1587 metadata.erase(key);
1588 }
1589 }
1590
1591 bool IRMetadata::hasMetadata(const yoi::wstr &key) const {
1592 return metadata.find(key) != metadata.end();
1593 }
1594
1596 std::wstringstream ss;
1597 for (auto &entry : metadata) {
1598 if (entry.first == L"regressed_interface_impl") {
1599 auto &implIndex = getMetadata<std::pair<yoi::indexT, yoi::indexT>>(L"regressed_interface_impl");
1600 ss << L"!" << entry.first << "{" << implIndex.first << "," << implIndex.second << "}" << ' ';
1601 } else if (entry.first == L"delayed_interface_impl") {
1602 auto &implIndex = getMetadata<std::pair<yoi::indexT, yoi::indexT>>(L"delayed_interface_impl");
1603 ss << L"!" << entry.first << "{" << implIndex.first << "," << implIndex.second << "}" << ' ';
1604 } else if (entry.first == L"from_local") {
1605 auto localIndex = getMetadata<yoi::indexT>(L"from_local");
1606 ss << L"!" << entry.first << "{" << localIndex << "}" << ' ';
1607 }
1608 }
1609 if (!ss.str().empty())
1610 ss.unget();
1611 return ss.str();
1612 }
1613
1614 std::shared_ptr<IREnumerationType> IREnumerationType::Builder::yield() {
1615 return std::make_shared<IREnumerationType>(name, valueToIndexMap);
1616 }
1617
1618 IRValueType::IRValueType(valueType type, const yoi::vec<yoi::IRValueType> &bracedTypes) : type(type), bracedTypes(bracedTypes) {}
1619
1621 if (!buildCachePath.empty()) {
1622 this->buildCachePath = buildCachePath;
1623 }
1624 return *this;
1625 }
1626
1631
1633 if (dimensions.empty()) {
1634 return 1;
1635 }
1636 yoi::indexT size = 1;
1637 for (auto &dimension : dimensions) {
1638 size *= dimension;
1639 }
1640 return size;
1641 }
1642
1644 const yoi::vec<std::shared_ptr<IRValueType>> &fieldTypes,
1645 const std::map<yoi::wstr, yoi::indexT> &fields,
1646 yoi::indexT linkedModuleId)
1647 : name(name), fieldTypes(fieldTypes), fields(fields), linkedModuleId(linkedModuleId) {}
1648
1650 this->name = name;
1651 return *this;
1652 }
1653
1655 const std::shared_ptr<IRValueType> &fieldType) {
1656 this->fieldTypes.push_back(fieldType);
1657 this->fields[fieldName] = this->fieldTypes.size() - 1;
1658 return *this;
1659 }
1660
1665
1666 std::shared_ptr<IRDataStructDefinition> IRDataStructDefinition::Builder::yield() {
1667 return std::make_shared<IRDataStructDefinition>(name, fieldTypes, fields, linkedModuleId);
1668 }
1669
1671 std::wstringstream ss;
1672 ss << yoi::wstr(indent, L' ') << L"datastruct " << name << L" {\n";
1673 for (auto &field : fieldTypes) {
1674 ss << yoi::wstr(indent + 4, L' ') << field->to_string() << L'\n';
1675 }
1676 ss << yoi::wstr(indent, L' ') << L'}' << L'\n';
1677 return ss.str();
1678 }
1679
1681 for (yoi::indexT i = 0; i < parameterCount; i++) {
1682 popFromTempVarStack();
1683 }
1684 insert(IR{IR::Opcode::initialize_field, {{IROperand::operandType::index, parameterCount}}, currentDebugInfo});
1685 }
1686
1688 const std::shared_ptr<IRValueType> &expectedType) {
1689 popFromTempVarStack();
1690 insert(IR{IR::Opcode::load_field, accessors, currentDebugInfo});
1691 pushTempVar(expectedType);
1692 }
1693
1695 popFromTempVarStack();
1696 insert(IR{IR::Opcode::store_field, accessors, currentDebugInfo});
1697 popFromTempVarStack();
1698 }
1699
1701 popFromTempVarStack();
1702 insert(IR{IR::Opcode::resume, {}, currentDebugInfo});
1703 }
1704
1705 void IRBuilder::yieldOp(bool yieldNone) {
1706 if (!yieldNone)
1707 popFromTempVarStack();
1708 popFromTempVarStack();
1709 insert(IR{IR::Opcode::yield, {}, currentDebugInfo});
1710 }
1711
1712 void IRVariableTable::set(yoi::indexT index, const std::shared_ptr<IRValueType> &type) {
1713 variables[index] = type;
1714 }
1715
1716 IRTemplateBuilder::Argument::Argument(const std::shared_ptr<IRValueType> &templateType,
1717 const yoi::vec<externModuleAccessExpression *> &satisfyConditions) : templateType(templateType), satisfyCondition(satisfyConditions) {
1718
1719 }
1720
1722 this->targetTriple = targetTriple;
1723 return *this;
1724 }
1725} // namespace yoi
void pushLoopContext(yoi::indexT breakTarget, yoi::indexT continueTarget)
Definition IR.cpp:1526
std::vector< std::shared_ptr< IRCodeBlock > > codeBlocks
Definition IR.h:889
void invokeOp(yoi::indexT funcIndex, yoi::indexT funcArgsCount, const std::shared_ptr< IRValueType > &returnType, bool externalInvocation=false, yoi::indexT moduleIndex=-1)
Invoke a function with the given arguments.
Definition IR.cpp:382
bool hasTerminated()
Definition IR.cpp:1464
yoi::indexT saveState()
Definition IR.cpp:1166
void continueOp()
Definition IR.cpp:1496
std::shared_ptr< IRModule > currentModule
Definition IR.h:887
std::shared_ptr< IRValueType > & getLhsFromTempVarStack()
Definition IR.cpp:159
void newDataStructOp(yoi::indexT structIndex, bool isExternal=false, yoi::indexT moduleIndex=-1)
Definition IR.cpp:462
const IRDebugInfo & getCurrentDebugInfo()
Definition IR.cpp:1209
std::shared_ptr< IRFunctionDefinition > currentFunction
Definition IR.h:888
void popOp()
Definition IR.cpp:1191
void yieldOp(bool yieldNone=false)
Definition IR.cpp:1705
void invokeVirtualOp(yoi::indexT funcIndex, yoi::indexT interfaceIndex, yoi::indexT methodArgsCount, const std::shared_ptr< IRValueType > &returnType, bool externalInvocation=false, yoi::indexT moduleIndex=-1)
Definition IR.cpp:420
void pushOp(IR::Opcode op, const yoi::IROperand &constV)
Definition IR.cpp:303
yoi::vec< std::tuple< yoi::indexT, yoi::indexT, yoi::indexT > > codeBlockInsertionStates
Definition IR.h:892
void interfaceOfOp()
Definition IR.cpp:1347
IRCodeBlock & getCodeBlock(yoi::indexT index)
Definition IR.cpp:128
void storeOp(IR::Opcode op, const yoi::IROperand &operand, yoi::indexT moduleIndex=-1)
Definition IR.cpp:350
void typeIdOp()
Definition IR.cpp:1218
void basicCast(const std::shared_ptr< IRValueType > &valType, yoi::indexT insertionPoint, bool lhs=false)
Definition IR.cpp:169
yoi::indexT createCodeBlock()
Definition IR.cpp:123
void breakOp()
Definition IR.cpp:1491
void constructInterfaceImplOp(const std::pair< yoi::indexT, yoi::indexT > &interfaceId, yoi::indexT interfaceImplIndex, bool isExternal=false, yoi::indexT moduleIndex=-1)
Definition IR.cpp:471
void loadFieldOp(yoi::vec< yoi::IROperand > &accessors, const std::shared_ptr< IRValueType > &expectedType)
Definition IR.cpp:1687
void yield()
Definition IR.cpp:132
std::shared_ptr< IRFunctionDefinition > irFuncDefinition()
Definition IR.cpp:502
void pushTempVar(const std::shared_ptr< IRValueType > &type)
Definition IR.cpp:1187
void newArrayOp(const std::shared_ptr< IRValueType > &elementType, const yoi::vec< yoi::indexT > &dimensions, yoi::indexT onstackElementCount)
Definition IR.cpp:1108
void loadOp(IR::Opcode op, const yoi::IROperand &source, const std::shared_ptr< IRValueType > &expectedType, yoi::indexT moduleIndex=-1)
Definition IR.cpp:329
void storeFieldOp(yoi::vec< yoi::IROperand > &accessors)
Definition IR.cpp:1694
void invokeImportedOp(yoi::indexT libIndex, yoi::indexT funcIndex, yoi::indexT funcArgsCount, const std::shared_ptr< IRValueType > &returnType)
Definition IR.cpp:1072
void newStructOp(yoi::indexT structIndex, bool isExternal=false, yoi::indexT moduleIndex=-1)
Definition IR.cpp:453
yoi::indexT currentCodeBlockIndex
Definition IR.h:891
yoi::indexT switchCodeBlock(yoi::indexT index)
Definition IR.cpp:492
void discardState()
Definition IR.cpp:1171
void discardStateUntil(yoi::indexT stateIndex)
Definition IR.cpp:1458
void bindElementsOp(yoi::indexT extractElementCount, ExtractType extractType)
Definition IR.cpp:1501
void insert(const IR &ir, yoi::indexT insertionPoint=0xffffffff)
Definition IR.cpp:147
void invokeMethodOp(yoi::indexT funcIndex, yoi::indexT methodArgsCount, const std::shared_ptr< IRValueType > &returnType, bool isStatic, bool externalInvocation=false, yoi::indexT moduleIndex=-1)
Definition IR.cpp:398
void uniqueArithmeticOp(IR::Opcode op)
Definition IR.cpp:233
void pointerCastOp()
Definition IR.cpp:1278
yoi::IROperand createLocalVar(const yoi::wstr &varName, const std::shared_ptr< IRValueType > &type)
Definition IR.cpp:142
void loadMemberOp(const yoi::IROperand &memberIndex, const std::shared_ptr< IRValueType > &memberType)
Definition IR.cpp:344
void arrayLengthOp()
Definition IR.cpp:1341
void popLoopContext()
Definition IR.cpp:1487
void commitState()
Definition IR.cpp:1446
IRCodeBlock & getCurrentCodeBlock()
Definition IR.cpp:138
void initializeFieldsOp(yoi::indexT parameterCount)
Definition IR.cpp:1680
void resumeOp()
Definition IR.cpp:1700
IRBuilder()=delete
void jumpOp(yoi::indexT target)
Definition IR.cpp:286
IRDebugInfo currentDebugInfo
Definition IR.h:895
void bindFieldsOp(yoi::indexT extractFieldCount, ExtractType extractType)
Definition IR.cpp:1513
void restoreState()
Definition IR.cpp:1176
void jumpIfOp(IR::Opcode op, yoi::indexT target)
Definition IR.cpp:292
yoi::indexT getCurrentInsertionPoint()
Definition IR.cpp:484
void restoreStateTemporarily()
Definition IR.cpp:1435
void invokeDanglingOp(yoi::indexT funcIndex, yoi::indexT funcArgsCount, const std::shared_ptr< IRValueType > &returnType, bool externalInvocation=false, yoi::indexT moduleIndex=-1)
invoke a function with the given arguments, but the last param will be taken as the first param.
Definition IR.cpp:1532
void newDynamicArrayOp(const std::shared_ptr< IRValueType > &elementType, yoi::indexT initializerSize=0)
Definition IR.cpp:1284
std::shared_ptr< compilerContext > compilerCtx
Definition IR.h:886
std::vector< std::shared_ptr< yoi::IRValueType > > tempVarStack
Definition IR.h:890
void popFromTempVarStack()
Definition IR.cpp:488
void storeMemberOp(const yoi::IROperand &memberIndex)
Definition IR.cpp:375
void arithmeticOp(IR::Opcode op)
Definition IR.cpp:242
yoi::indexT getCurrentCodeBlockIndex()
Definition IR.cpp:498
void dynCastOp(const std::shared_ptr< IRValueType > &type)
Definition IR.cpp:1249
std::shared_ptr< IRValueType > & getRhsFromTempVarStack()
Definition IR.cpp:164
void retOp(bool returnWithNone=false)
Definition IR.cpp:438
void setDebugInfo(const IRDebugInfo &debugInfo)
Definition IR.cpp:1204
yoi::vec< IR > & getIRArray()
Definition IR.cpp:518
void insert(const IR &ir)
Definition IR.cpp:506
yoi::wstr to_string(yoi::indexT indent=0)
Definition IR.cpp:510
yoi::vec< IR > codeBlock
Definition IR.h:418
yoi::vec< std::shared_ptr< IRValueType > > fieldTypes
Definition IR.h:577
std::map< yoi::wstr, yoi::indexT > fields
Definition IR.h:579
yoi::wstr to_string(yoi::indexT indent=0)
Definition IR.cpp:1670
IRDataStructDefinition(const yoi::wstr &name, const yoi::vec< std::shared_ptr< IRValueType > > &fieldTypes, const std::map< yoi::wstr, yoi::indexT > &fields, yoi::indexT linkedModuleId)
Definition IR.cpp:1643
yoi::indexT linkedModuleId
Definition IR.h:581
Builder & addValue(const yoi::wstr &valueName, yoi::indexT valueIndex)
Definition IR.cpp:1580
std::shared_ptr< IREnumerationType > yield()
Definition IR.cpp:1614
Builder & setName(const yoi::wstr &name)
Definition IR.cpp:1575
UnderlyingType getUnderlyingType()
Definition IR.cpp:1561
IREnumerationType(const yoi::wstr &name, const yoi::indexTable< yoi::wstr, yoi::indexT > &valueToIndexMap)
Definition IR.cpp:1558
yoi::indexTable< yoi::wstr, yoi::indexT > valueToIndexMap
Definition IR.h:396
yoi::wstr name
Definition IR.h:395
externType getExternType() const
Definition IR.cpp:886
enum yoi::IRExternEntry::externType type
IRExternEntry()=default
ImportLibrary(const yoi::wstr &libraryPath)
Definition IR.cpp:1039
void addForeignType(const yoi::wstr &foreignTypeName, const std::shared_ptr< IRValueType > &structType)
Definition IR.cpp:1058
void addExportedFunction(const yoi::wstr &exportName, yoi::indexT moduleIndex, yoi::indexT functionIndex, const std::set< IRFunctionDefinition::FunctionAttrs > &attrs)
Add an exported function to the FFI table.
Definition IR.cpp:1051
yoi::indexT addImportedFunction(const yoi::wstr &libraryName, const yoi::wstr &functionName, const std::shared_ptr< IRFunctionDefinition > &functionDefinition)
Definition IR.cpp:1041
yoi::indexTable< yoi::wstr, std::tuple< yoi::indexT, yoi::indexT, std::set< IRFunctionDefinition::FunctionAttrs > > > exportedFunctionTable
Definition IR.h:1114
yoi::indexTable< yoi::wstr, std::shared_ptr< IRValueType > > foreignTypeTable
Definition IR.h:1116
yoi::indexTable< yoi::wstr, ImportLibrary > importedLibraries
Definition IR.h:1118
yoi::vec< std::shared_ptr< IRValueType > > argumentTypes
Definition IR.h:488
std::shared_ptr< IRValueType > returnType
Definition IR.h:489
IRDebugInfo debugInfo
Definition IR.h:493
IRVariableTable variableTable
Definition IR.h:491
yoi::wstr to_string(yoi::indexT indent=0)
Definition IR.cpp:522
IRFunctionDefinition(const yoi::wstr &name, const yoi::vec< std::pair< yoi::wstr, std::shared_ptr< IRValueType > > > &argumentTypes, const std::shared_ptr< IRValueType > &returnType, const yoi::vec< std::shared_ptr< IRCodeBlock > > &codeBlock, const std::set< FunctionAttrs > &attrs, const IRDebugInfo &debugInfo)
Definition IR.cpp:605
bool hasAttribute(const FunctionAttrs &attr)
Definition IR.cpp:1427
std::set< FunctionAttrs > attrs
Definition IR.h:492
IRVariableTable & getVariableTable()
Definition IR.cpp:619
std::shared_ptr< IRFunctionDefinition > templateDefinition
Definition IR.h:564
std::shared_ptr< IRFunctionTemplate > yield()
Definition IR.cpp:970
Builder & setTemplateDefinition(const std::shared_ptr< IRFunctionDefinition > &templateDefinition)
Definition IR.cpp:965
std::shared_ptr< IRFunctionDefinition > templateDefinition
Definition IR.h:556
yoi::indexTable< yoi::wstr, IRTemplateBuilder::Argument > templateArguments
Definition IR.h:557
IRFunctionTemplate(const std::shared_ptr< IRFunctionDefinition > &templateDefinition, const yoi::indexTable< yoi::wstr, IRTemplateBuilder::Argument > &templateArguments)
Definition IR.cpp:961
yoi::wstr to_string(yoi::indexT indent=0)
Definition IR.cpp:946
IRInterfaceImplementationDefinition(const yoi::wstr &name, std::tuple< IRValueType::valueType, yoi::indexT, yoi::indexT > implStructIndex, const std::pair< yoi::indexT, yoi::indexT > &implInterfaceIndex, const yoi::vec< std::shared_ptr< IRValueType > > &virtualMethods, const std::map< yoi::wstr, yoi::indexT > &virtualMethodIndexMap)
Definition IR.cpp:85
std::shared_ptr< IRInterfaceImplementationDefinition > templateDefinition
Definition IR.h:796
std::shared_ptr< IRInterfaceImplementationTemplate > yield()
Definition IR.cpp:1008
Builder & setTemplateDefinition(const std::shared_ptr< IRInterfaceImplementationDefinition > &templateDefinition)
Definition IR.cpp:1002
std::shared_ptr< IRInterfaceImplementationDefinition > templateDefinition
Definition IR.h:791
IRInterfaceImplementationTemplate(const std::shared_ptr< IRInterfaceImplementationDefinition > &templateDefinition, const yoi::indexTable< yoi::wstr, IRTemplateBuilder::Argument > &templateArguments)
Definition IR.cpp:997
yoi::indexTable< yoi::wstr, IRTemplateBuilder::Argument > templateArguments
Definition IR.h:792
yoi::wstr to_string(yoi::indexT indent=0)
Definition IR.cpp:936
IRInterfaceInstanceDefinition(const yoi::wstr &name, const std::map< yoi::wstr, yoi::vec< yoi::indexT > > &functionOverloadIndexies, const yoi::indexTable< yoi::wstr, std::shared_ptr< IRFunctionDefinition > > &methodMap)
Definition IR.cpp:94
std::shared_ptr< IRInterfaceInstanceTemplate > yield()
Definition IR.cpp:993
Builder & setTemplateDefinition(const std::shared_ptr< IRInterfaceInstanceDefinition > &templateDefinition)
Definition IR.cpp:988
std::shared_ptr< IRInterfaceInstanceDefinition > templateDefinition
Definition IR.h:776
yoi::indexTable< yoi::wstr, IRTemplateBuilder::Argument > templateArguments
Definition IR.h:772
IRInterfaceInstanceTemplate(const std::shared_ptr< IRInterfaceInstanceDefinition > &templateDefinition, const yoi::indexTable< yoi::wstr, IRTemplateBuilder::Argument > &templateArguments)
Definition IR.cpp:983
std::shared_ptr< IRInterfaceInstanceDefinition > templateDefinition
Definition IR.h:771
yoi::indexTable< yoi::wstr, std::shared_ptr< IRInterfaceInstanceDefinition > > interfaceTable
Definition IR.h:862
yoi::wstr to_string(yoi::indexT indent=0)
Definition IR.cpp:99
yoi::indexTable< yoi::wstr, std::shared_ptr< IRStructDefinition > > structTable
Definition IR.h:858
yoi::indexTable< yoi::wstr, std::shared_ptr< IRFunctionDefinition > > functionTable
Definition IR.h:857
yoi::indexTable< yoi::wstr, std::shared_ptr< IRInterfaceImplementationDefinition > > interfaceImplementationTable
Definition IR.h:863
enum yoi::IROperand::operandType type
std::shared_ptr< IRValueType > lvalueType
Definition IR.h:259
union yoi::IROperand::operandValue value
std::shared_ptr< IRValueType > getLvalueType()
Definition IR.cpp:37
yoi::wstr to_string() const
Definition IR.cpp:41
yoi::wstr & getStringLiteral(yoi::indexT index)
Definition IR.cpp:835
yoi::indexT addStringLiteral(const yoi::wstr &str)
Definition IR.cpp:831
yoi::vec< std::shared_ptr< IRValueType > > fieldTypes
Definition IR.h:611
IRStructDefinition(const yoi::wstr &name, const std::map< yoi::wstr, nameInfo > &nameIndexMap, const vec< std::shared_ptr< IRValueType > > &fieldTypes, const yoi::vec< yoi::wstr > &templateParamNames={}, const yoi::vec< std::shared_ptr< IRValueType > > &storedTemplateArgs={}, const std::map< yoi::wstr, yoi::structDefInnerPair * > &templateMethodDecls={}, const std::map< yoi::wstr, yoi::implInnerPair * > &templateMethodDefs={})
Definition IR.cpp:758
yoi::vec< std::shared_ptr< IRValueType > > storedTemplateArgs
Definition IR.h:620
yoi::wstr to_string(yoi::indexT indent=0)
Definition IR.cpp:768
const nameInfo & lookupName(const yoi::wstr &name)
Lookup a name in the struct definition, returning the index of the field or method and its type.
Definition IR.cpp:780
yoi::wstr name
Definition IR.h:610
std::map< yoi::wstr, yoi::structDefInnerPair * > templateMethodDecls
Definition IR.h:621
std::map< yoi::wstr, nameInfo > nameIndexMap
Definition IR.h:617
std::map< yoi::wstr, yoi::implInnerPair * > templateMethodDefs
Definition IR.h:622
yoi::vec< yoi::wstr > templateParamNames
Definition IR.h:619
Builder & setTemplateDefinition(const std::shared_ptr< IRStructDefinition > &templateDefinition)
Definition IR.cpp:974
Builder & setTemplateMethod(const yoi::wstr &methodName, const std::shared_ptr< IRFunctionTemplate > &methodTemplate)
Definition IR.cpp:1019
std::shared_ptr< IRStructTemplate > yield()
Definition IR.cpp:979
IRStructTemplate(const std::shared_ptr< IRStructDefinition > &templateDefinition, const yoi::indexTable< yoi::wstr, std::shared_ptr< IRFunctionTemplate > > &templateMethods, const yoi::indexTable< yoi::wstr, IRTemplateBuilder::Argument > &templateArguments)
Definition IR.cpp:1034
yoi::indexTable< yoi::wstr, Argument > templateArguments
Definition IR.h:545
IRTemplateBuilder & addTemplateArgument(const yoi::wstr &templateName, const std::shared_ptr< IRValueType > &templateType, const yoi::vec< externModuleAccessExpression * > &satisfyConditions={})
Definition IR.cpp:1012
bool isArrayType() const
Definition IR.cpp:1090
IRMetadata metadata
Definition IR.h:155
IRValueType getNormalizedForeignBasicType()
Definition IR.cpp:643
IRValueType getArrayType(const yoi::vec< yoi::indexT > &dimensions)
Definition IR.cpp:1162
IRValueType getBasicRawType() const
Definition IR.cpp:1376
bool isForeignBasicType() const
Definition IR.cpp:635
yoi::indexT calculateDimensionSize() const
Definition IR.cpp:1632
IRValueType & removeAttribute(ValueAttr attr)
Definition IR.cpp:1358
bool is1ByteType() const
Definition IR.cpp:639
IRValueType getElementType()
Definition IR.cpp:1103
enum yoi::IRValueType::valueType type
bool isDynamicArrayType() const
Definition IR.cpp:1337
IRValueType getBasicObjectType() const
Definition IR.cpp:1406
IRValueType getDynamicArrayType()
Definition IR.cpp:1333
bool hasAttribute(ValueAttr attr) const
Definition IR.cpp:1354
yoi::wstr to_string(bool showAttributes=false) const
Definition IR.cpp:661
std::set< ValueAttr > attributes
Definition IR.h:153
yoi::vec< yoi::indexT > dimensions
Definition IR.h:149
IRValueType & addAttribute(ValueAttr attr)
Definition IR.cpp:1363
bool operator==(const yoi::IRValueType &rhs) const
Definition IR.cpp:753
yoi::indexT typeIndex
Definition IR.h:147
bool isBasicRawType() const
Definition IR.cpp:1371
bool isBasicType() const
Definition IR.cpp:628
yoi::indexT typeAffiliateModule
Definition IR.h:146
std::shared_ptr< IRValueType > operator[](const yoi::wstr &name)
Definition IR.cpp:871
void set(yoi::indexT index, const std::shared_ptr< IRValueType > &type)
Definition IR.cpp:1712
yoi::indexT put(const yoi::wstr &name, const std::shared_ptr< IRValueType > &type)
Definition IR.cpp:875
std::shared_ptr< IRValueType > get(yoi::indexT index)
Definition IR.cpp:867
std::map< yoi::indexT, yoi::wstr > & getReversedVariableNameMap()
Definition IR.cpp:1030
yoi::wstr to_string(yoi::indexT indent=0)
Definition IR.cpp:857
yoi::indexT createScope()
Definition IR.cpp:848
yoi::indexT lookup(const yoi::wstr &name)
Look up a variable by name in the current scope. If the variable is not found in the current scope,...
Definition IR.cpp:839
yoi::vec< std::shared_ptr< IRValueType > > & getVariables()
Definition IR.cpp:1026
yoi::indexT scopeIndex(yoi::indexT varIndex)
Definition IR.cpp:1483
Definition IR.h:272
Opcode
Definition IR.h:274
IR()=default
yoi::vec< IROperand > operands
Definition IR.h:375
enum yoi::IR::Opcode opcode
yoi::wstr to_string() const
Definition IR.cpp:74
yoi::indexT put_create(const A &a, const B &b)
Definition def.hpp:182
constexpr auto enum_name() noexcept -> detail::enable_if_t< decltype(V), string_view >
std::string wstring2string(const std::wstring &v)
Definition def.cpp:230
std::shared_ptr< T > managedPtr(const T &v)
Definition def.hpp:335
wstr::value_type wchar
Definition def.hpp:52
std::vector< t > vec
Definition def.hpp:56
std::wstring string2wstring(const std::string &v)
Definition def.cpp:224
void yoi_assert(bool condition, yoi::indexT line, yoi::indexT col, const std::string &msg)
Asserts a condition that would be true and throws a runtime_error if it is false.
Definition def.cpp:217
void set_current_file_path(const std::wstring &path)
Definition def.cpp:123
std::wstring wstr
Definition def.hpp:51
uint64_t indexT
Definition def.hpp:54
void panic(yoi::indexT line, yoi::indexT col, const std::string &msg)
Definition def.cpp:141
Builder & addSearchPath(const yoi::wstr &searchPath)
Definition IR.cpp:1067
yoi::vec< yoi::wstr > additionalLinkingFiles
Definition IR.h:44
Builder & setImmediatelyClearupCache(bool immediatelyClearupCache)
Definition IR.cpp:1627
BuildType buildType
Definition IR.h:36
Builder & setBuildType(BuildType buildType)
Definition IR.cpp:890
Builder & setBuildCachePath(const yoi::wstr &buildCachePath)
Definition IR.cpp:1620
std::shared_ptr< IRBuildConfig > yield()
Definition IR.cpp:905
Builder & setAdditionalLinkingFiles(const yoi::vec< yoi::wstr > &additionalLinkingFiles)
Definition IR.cpp:1548
Builder & setPreserveIntermediateFiles(bool preserveIntermediateFiles)
Definition IR.cpp:931
Builder & setBuildMode(BuildMode buildMode)
Definition IR.cpp:921
Builder & setBuildPlatform(const yoi::wstr &buildPlatform)
Definition IR.cpp:895
Builder & setTargetTriple(const yoi::wstr &targetTriple)
Definition IR.cpp:1721
Builder & setBuildArch(const yoi::wstr &buildArch)
Definition IR.cpp:900
yoi::wstr buildCachePath
Definition IR.h:47
Builder & setAdditionalLinkerOptions(const yoi::vec< yoi::wstr > &additionalLinkerOptions)
Definition IR.cpp:1553
Builder & setSearchPaths(const yoi::vec< yoi::wstr > &searchPaths)
Definition IR.cpp:1062
Builder & setMarco(const yoi::wstr &name, const yoi::wstr &value)
Definition IR.cpp:1478
Builder & setUseObjectLinker(UseObjectLinker useObjectLinker)
Definition IR.cpp:926
enum yoi::IRBuildConfig::BuildMode buildMode
yoi::wstr targetTriple
Definition IR.h:26
bool preserveIntermediateFiles
Definition IR.h:27
yoi::vec< yoi::wstr > additionalLinkingFiles
Definition IR.h:29
yoi::wstr buildArch
Definition IR.h:25
yoi::vec< yoi::wstr > additionalLinkerOptions
Definition IR.h:30
std::map< yoi::wstr, yoi::wstr > marcos
Definition IR.h:31
enum yoi::IRBuildConfig::BuildType buildType
yoi::wstr buildCachePath
Definition IR.h:32
yoi::wstr buildPlatform
Definition IR.h:24
enum yoi::IRBuildConfig::UseObjectLinker useObjectLinker
yoi::vec< yoi::wstr > searchPaths
Definition IR.h:28
bool immediatelyClearupCache
Definition IR.h:33
Builder & addField(const yoi::wstr &fieldName, const std::shared_ptr< IRValueType > &fieldType)
Definition IR.cpp:1654
std::shared_ptr< IRDataStructDefinition > yield()
Definition IR.cpp:1666
Builder & setLinkedModuleId(yoi::indexT linkedModuleId)
Definition IR.cpp:1661
Builder & setName(const yoi::wstr &name)
Definition IR.cpp:1649
yoi::indexT column
Definition IR.h:89
yoi::indexT line
Definition IR.h:88
yoi::wstr sourceFile
Definition IR.h:87
Builder & setDebugInfo(const IRDebugInfo &debugInfo)
Definition IR.cpp:1213
std::shared_ptr< IRFunctionDefinition > yield()
Definition IR.cpp:601
Builder & setName(const yoi::wstr &name)
Definition IR.cpp:541
Builder & addArgument(const yoi::wstr &argumentName, const std::shared_ptr< IRValueType > &argumentType)
Definition IR.cpp:590
Builder & setReturnType(const std::shared_ptr< IRValueType > &returnType)
Definition IR.cpp:596
Builder & addAttr(FunctionAttrs attr)
Definition IR.cpp:1273
std::shared_ptr< IRInterfaceImplementationDefinition > yield()
Definition IR.cpp:570
Builder & setImplStructIndex(std::tuple< IRValueType::valueType, yoi::indexT, yoi::indexT > implStructIndex)
Definition IR.cpp:552
Builder & setImplInterfaceIndex(const std::pair< yoi::indexT, yoi::indexT > &implInterfaceIndex)
Definition IR.cpp:558
Builder & addVirtualMethod(const yoi::wstr &methodName, const std::shared_ptr< IRValueType > &methodType)
Definition IR.cpp:564
Builder & setName(const yoi::wstr &name)
Definition IR.cpp:546
std::shared_ptr< IRInterfaceInstanceDefinition > yield()
Definition IR.cpp:586
Builder & setName(const yoi::wstr &name)
Definition IR.cpp:575
Builder & addMethod(const yoi::wstr &methodNameOri, const yoi::wstr &methodName, const std::shared_ptr< IRFunctionDefinition > &methodSignature)
Definition IR.cpp:580
yoi::wstr to_string() const
Definition IR.cpp:1595
void eraseMetadata(const yoi::wstr &key)
Definition IR.cpp:1585
bool hasMetadata(const yoi::wstr &key) const
Definition IR.cpp:1591
std::shared_ptr< IRStructDefinition > yield()
Definition IR.cpp:821
Builder & setStoredTemplateArgs(const yoi::vec< yoi::wstr > &paramNames, const yoi::vec< std::shared_ptr< IRValueType > > &args)
Definition IR.cpp:804
Builder & addMethod(const yoi::wstr &methodName, yoi::indexT index)
Definition IR.cpp:799
Builder & addTemplateMethodDef(const yoi::wstr &name, yoi::implInnerPair *def)
Definition IR.cpp:816
Builder & addField(const yoi::wstr &fieldName, const std::shared_ptr< IRValueType > &fieldType)
Definition IR.cpp:793
Builder & addTemplateMethodDecl(const yoi::wstr &name, yoi::structDefInnerPair *decl)
Definition IR.cpp:811
Builder & setName(const yoi::wstr &name)
Definition IR.cpp:788
Argument(const std::shared_ptr< IRValueType > &templateType, const yoi::vec< externModuleAccessExpression * > &satisfyConditions)
Definition IR.cpp:1716
yoi::indexT symbolIndex
Definition IR.h:239
yoi::indexT stringLiteralIndex
Definition IR.h:238
yoi::indexT codeBlockIndex
Definition IR.h:240