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
918
923
928
933
935 yoi::wstr r;
936 r += yoi::wstr(indent, L' ') + L"interface " + name + L" {\n";
937 for (auto &i : methodMap) {
938 r += i.second->to_string(indent + 4) + L"\n";
939 }
940 r += yoi::wstr(indent, L' ') + L"}\n";
941 return r;
942 }
943
945 yoi::wstr r;
946 r += yoi::wstr(indent, L' ') + L"impl " + name + L" for " +
947 yoi::string2wstring(std::string{magic_enum::enum_name(std::get<0>(implStructIndex))}) + L"#" +
948 std::to_wstring(std::get<1>(implStructIndex)) + L"#" + std::to_wstring(std::get<2>(implStructIndex)) + L" {\n";
949
950 for (auto &i : virtualMethods) {
951 r += yoi::wstr(indent + 4, L' ') + L"virtual " + i->to_string() + L"\n";
952 }
953 r += yoi::wstr(indent, L' ') + L"}\n";
954 return r;
955 }
956
957 IRTemplateBuilder::Argument::Argument(const std::shared_ptr<IRValueType> &templateType) : templateType(templateType) {}
958
959 IRFunctionTemplate::IRFunctionTemplate(const std::shared_ptr<IRFunctionDefinition> &templateDefinition,
961 : templateDefinition(templateDefinition), templateArguments(templateArguments) {}
962
963 IRFunctionTemplate::Builder &IRFunctionTemplate::Builder::setTemplateDefinition(const std::shared_ptr<IRFunctionDefinition> &templateDefinition) {
964 this->templateDefinition = templateDefinition;
965 return *this;
966 }
967
968 std::shared_ptr<IRFunctionTemplate> IRFunctionTemplate::Builder::yield() {
969 return std::make_shared<IRFunctionTemplate>(templateDefinition, templateArguments);
970 }
971
973 this->templateDefinition = templateDefinition;
974 return *this;
975 }
976
977 std::shared_ptr<IRStructTemplate> IRStructTemplate::Builder::yield() {
978 return std::make_shared<IRStructTemplate>(IRStructTemplate{templateDefinition, templateMethods, templateArguments});
979 }
980
984
986 IRInterfaceInstanceTemplate::Builder::setTemplateDefinition(const std::shared_ptr<IRInterfaceInstanceDefinition> &templateDefinition) {
987 this->templateDefinition = templateDefinition;
988 return *this;
989 }
990
991 std::shared_ptr<IRInterfaceInstanceTemplate> IRInterfaceInstanceTemplate::Builder::yield() {
992 return std::make_shared<IRInterfaceInstanceTemplate>(templateDefinition, templateArguments);
993 }
994
999
1001 const std::shared_ptr<IRInterfaceImplementationDefinition> &templateDefinition) {
1002 this->templateDefinition = templateDefinition;
1003 return *this;
1004 }
1005
1006 std::shared_ptr<IRInterfaceImplementationTemplate> IRInterfaceImplementationTemplate::Builder::yield() {
1007 return std::make_shared<IRInterfaceImplementationTemplate>(templateDefinition, templateArguments);
1008 }
1009
1011 const std::shared_ptr<IRValueType> &templateType,
1012 const yoi::vec<externModuleAccessExpression *> &satisfyConditions) {
1013 templateArguments.put_create(templateName, {templateType, satisfyConditions});
1014 return *this;
1015 }
1016
1018 const std::shared_ptr<IRFunctionTemplate> &methodTemplate) {
1019 // templateMethods[methodName] = methodTemplate;
1020 templateMethods.put_create(methodName, methodTemplate);
1021 return *this;
1022 }
1023
1027
1028 std::map<yoi::indexT, yoi::wstr> &IRVariableTable::getReversedVariableNameMap() {
1029 return reversedVariableNameMap;
1030 }
1031
1032 IRStructTemplate::IRStructTemplate(const std::shared_ptr<IRStructDefinition> &templateDefinition,
1033 const yoi::indexTable<yoi::wstr, std::shared_ptr<IRFunctionTemplate>> &templateMethods,
1035 : templateDefinition(templateDefinition), templateMethods(templateMethods), templateArguments(templateArguments) {}
1036
1037 IRFFITable::ImportLibrary::ImportLibrary(const yoi::wstr &libraryPath) : libraryPath(libraryPath) {}
1038
1040 const yoi::wstr &functionName,
1041 const std::shared_ptr<IRFunctionDefinition> &functionDefinition) {
1042 if (!importedLibraries.contains(libraryName)) {
1043 importedLibraries.put_create(libraryName, {libraryName});
1044 }
1045
1046 return importedLibraries[libraryName].importedFunctionTable.put(functionName, functionDefinition);
1047 }
1048
1050 yoi::indexT moduleIndex,
1051 yoi::indexT functionIndex,
1052 const std::set<IRFunctionDefinition::FunctionAttrs> &attrs) {
1053 exportedFunctionTable.put_create(exportName, std::make_tuple(moduleIndex, functionIndex, attrs));
1054 }
1055
1056 void IRFFITable::addForeignType(const yoi::wstr &foreignTypeName, const std::shared_ptr<IRValueType> &structType) {
1057 foreignTypeTable.put_create(foreignTypeName, structType);
1058 }
1059
1061 this->searchPaths = searchPaths;
1062 return *this;
1063 }
1064
1066 searchPaths.push_back(searchPath);
1067 return *this;
1068 }
1069
1071 yoi::indexT funcIndex,
1072 yoi::indexT funcArgsCount,
1073 const std::shared_ptr<IRValueType> &returnType) {
1074 for (yoi::indexT i = 0; i < funcArgsCount; ++i) {
1075 tempVarStack.pop_back();
1076 }
1077 tempVarStack.push_back(managedPtr(compilerCtx->normalizeForeignBasicType(returnType)));
1078
1079 // insert(IR{IR::Opcode::invoke_imported, {IROperand(IROperand::operandType::index, externIndex),
1080 // IROperand(IROperand::operandType::index, funcArgsCount)}});
1085 currentDebugInfo});
1086 }
1087
1089 return !dimensions.empty() && dimensions.back() != static_cast<yoi::indexT>(-1);
1090 }
1091
1093 yoi::indexT typeAffiliateModule,
1094 yoi::indexT objectPrototypeIndex,
1095 const yoi::vec<yoi::indexT> &dimensions)
1096 : type(type), dimensions(dimensions), typeAffiliateModule(typeAffiliateModule), typeIndex(objectPrototypeIndex) {}
1097
1099 : type(type), dimensions(dimensions), typeAffiliateModule(0), typeIndex(0) {}
1100
1104
1105 void
1106 IRBuilder::newArrayOp(const std::shared_ptr<IRValueType> &elementType, const yoi::vec<yoi::indexT> &dimensions, yoi::indexT onstackElementCount) {
1108 yoi::vec<IROperand> operands;
1109 switch (elementType->type) {
1112 break;
1115 break;
1118 break;
1121 break;
1124 break;
1127 break;
1130 break;
1133 operands.emplace_back(IROperand::operandType::index, elementType->typeAffiliateModule);
1134 operands.emplace_back(IROperand::operandType::index, elementType->typeIndex);
1135 break;
1138 operands.emplace_back(IROperand::operandType::index, elementType->typeAffiliateModule);
1139 operands.emplace_back(IROperand::operandType::index, elementType->typeIndex);
1140 break;
1141 default:
1144 "Unsupported array element type: " + yoi::wstring2string(elementType->to_string()));
1145 break;
1146 }
1147 auto size = 1;
1148 operands.emplace_back(IROperand::operandType::index, onstackElementCount);
1149 for (auto &dim : dimensions) {
1150 operands.emplace_back(IROperand::operandType::index, dim);
1151 size *= dim;
1152 }
1153 for (yoi::indexT i = 0; i < onstackElementCount; ++i) {
1154 tempVarStack.pop_back();
1155 }
1156 insert(IR{op, operands, currentDebugInfo});
1157 tempVarStack.push_back(managedPtr(elementType->getArrayType(dimensions)));
1158 }
1159
1163
1168
1170 yoi_assert(!codeBlockInsertionStates.empty(), currentDebugInfo.line, currentDebugInfo.column, "Empty code states when poping back");
1171 codeBlockInsertionStates.pop_back();
1172 }
1173
1178 "Invalid code block index");
1179 codeBlocks[currentCodeBlockIndex]->getIRArray().resize(std::get<1>(codeBlockInsertionStates.back()));
1180 tempVarStack.resize(std::get<2>(codeBlockInsertionStates.back()));
1181 yoi_assert(!codeBlockInsertionStates.empty(), currentDebugInfo.line, currentDebugInfo.column, "Empty code states when poping back");
1182 codeBlockInsertionStates.pop_back();
1183 }
1184
1185 void IRBuilder::pushTempVar(const std::shared_ptr<IRValueType> &type) {
1186 tempVarStack.push_back(type);
1187 }
1188
1191 auto elementCount = tempVarStack.back()->bracedTypes.size();
1192 for (yoi::indexT i = 0; i < elementCount; ++i) {
1193 tempVarStack.pop_back();
1195 }
1196 } else {
1197 tempVarStack.pop_back();
1199 }
1200 }
1201
1202 void IRBuilder::setDebugInfo(const IRDebugInfo &debugInfo) {
1204 this->currentDebugInfo = debugInfo;
1205 }
1206
1210
1212 this->debugInfo = debugInfo;
1213 return *this;
1214 }
1215
1217 auto rhs = tempVarStack.back();
1218 tempVarStack.pop_back();
1219 typeIdOp(rhs);
1220 }
1221
1222 void IRBuilder::typeIdOp(const std::shared_ptr<IRValueType> &type) {
1223 IR::Opcode op;
1224 vec<IROperand> operand;
1225 if (type->isArrayType() || type->isDynamicArrayType()) {
1226 yoi::indexT size = 1;
1227 for (auto &dim : type->dimensions) {
1228 size *= dim;
1229 }
1230
1232 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(type->type));
1233 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(type->typeAffiliateModule));
1234 operand.emplace_back(IROperand::operandType::index, type->typeIndex);
1235 operand.emplace_back(IROperand::operandType::index, size);
1236 } else {
1238 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(type->type));
1239 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(type->typeAffiliateModule));
1240 operand.emplace_back(IROperand::operandType::index, type->typeIndex);
1241 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(0));
1242 }
1243 insert(IR(op, operand, currentDebugInfo));
1245 }
1246
1247 void IRBuilder::dynCastOp(const std::shared_ptr<IRValueType> &type) {
1248 IR::Opcode op;
1249 vec<IROperand> operand;
1250
1252 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(type->type));
1253 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(type->typeAffiliateModule));
1254 operand.emplace_back(IROperand::operandType::index, type->typeIndex);
1255
1256 if (type->isDynamicArrayType() || type->isArrayType()) {
1257 yoi::indexT size = 1;
1258 for (auto &dim : type->dimensions) {
1259 size *= dim;
1260 }
1261
1262 operand.emplace_back(IROperand::operandType::index, size);
1263 } else {
1264 operand.emplace_back(IROperand::operandType::index, static_cast<yoi::indexT>(0));
1265 }
1266 insert(IR(op, operand, currentDebugInfo));
1267 tempVarStack.pop_back();
1268 tempVarStack.push_back(type);
1269 }
1270
1275
1277 insert(IR{IR::Opcode::pointer_cast, {}, currentDebugInfo});
1278 tempVarStack.pop_back();
1280 }
1281
1282 void IRBuilder::newDynamicArrayOp(const std::shared_ptr<IRValueType> &elementType, yoi::indexT initializerSize) {
1284 yoi::vec<IROperand> operands;
1285 switch (elementType->type) {
1288 break;
1291 break;
1294 break;
1297 break;
1300 break;
1303 break;
1306 break;
1309 operands.emplace_back(IROperand::operandType::index, elementType->typeAffiliateModule);
1310 operands.emplace_back(IROperand::operandType::index, elementType->typeIndex);
1311 break;
1314 operands.emplace_back(IROperand::operandType::index, elementType->typeAffiliateModule);
1315 operands.emplace_back(IROperand::operandType::index, elementType->typeIndex);
1316 break;
1317 default:
1318 panic(currentDebugInfo.line,
1319 currentDebugInfo.column,
1320 "Unsupported array element type: " + yoi::wstring2string(elementType->to_string()));
1321 break;
1322 }
1323 operands.emplace_back(IROperand::operandType::index, initializerSize);
1324 insert(IR{op, operands, currentDebugInfo});
1325 for (yoi::indexT i = 0; i <= initializerSize; i++) {
1326 tempVarStack.pop_back(); // size and initializer
1327 }
1328 tempVarStack.push_back(managedPtr(elementType->getDynamicArrayType()));
1329 }
1330
1332 return {type, typeAffiliateModule, typeIndex, {static_cast<yoi::indexT>(-1)}};
1333 }
1334
1336 return dimensions.size() == 1 && dimensions.back() == static_cast<yoi::indexT>(-1);
1337 }
1338
1340 tempVarStack.pop_back();
1341 tempVarStack.push_back(compilerCtx->getIntObjectType());
1342 insert(IR{IR::Opcode::array_length, {}, currentDebugInfo});
1343 }
1344
1346 tempVarStack.pop_back();
1347 tempVarStack.pop_back();
1348 tempVarStack.push_back(compilerCtx->getBoolObjectType());
1349 insert(IR{IR::Opcode::interfaceof, {}, currentDebugInfo});
1350 }
1351
1353 return attributes.count(attr) > 0;
1354 }
1355
1357 attributes.erase(attr);
1358 return *this;
1359 }
1360
1362 attributes.insert(attr);
1363 return *this;
1364 }
1365
1366 IRValueType::IRValueType(valueType type, yoi::indexT typeAffiliateModule, yoi::indexT objectPrototypeIndex, const std::set<ValueAttr> &attributes)
1367 : type(type), typeAffiliateModule(typeAffiliateModule), typeIndex(objectPrototypeIndex), dimensions(), attributes(attributes) {}
1368
1373
1375 IRValueType result = *this;
1376 switch (type) {
1378 result.type = valueType::integerRaw;
1379 break;
1381 result.type = valueType::decimalRaw;
1382 break;
1384 result.type = valueType::booleanRaw;
1385 break;
1387 result.type = valueType::charRaw;
1388 break;
1391 break;
1394 break;
1397 break;
1398 default:
1399 break;
1400 }
1401 return result;
1402 }
1403
1424
1426 return std::find(attrs.begin(), attrs.end(), attr) != attrs.end();
1427 }
1428
1430 this->shortV = shortV;
1431 }
1432
1434 auto current = codeBlockInsertionStates.back();
1435 yoi_assert(currentCodeBlockIndex == std::get<0>(current), currentDebugInfo.line, currentDebugInfo.column, "Invalid code block index");
1436 tempStateCodeBlock = std::vector<IR>(codeBlocks[currentCodeBlockIndex]->getIRArray().begin() + std::get<1>(current),
1437 codeBlocks[currentCodeBlockIndex]->getIRArray().end());
1438 tempStateTempVarStack = std::vector<std::shared_ptr<IRValueType>>(tempVarStack.begin() + std::get<2>(current), tempVarStack.end());
1439
1440 codeBlocks[currentCodeBlockIndex]->getIRArray().resize(std::get<1>(current));
1441 tempVarStack.resize(std::get<2>(current));
1442 }
1443
1445 for (auto &block : tempStateCodeBlock) {
1446 codeBlocks[currentCodeBlockIndex]->getIRArray().push_back(block);
1447 }
1448 for (auto &type : tempStateTempVarStack) {
1449 tempVarStack.push_back(type);
1450 }
1451 tempStateCodeBlock.clear();
1452 tempStateTempVarStack.clear();
1453 discardState();
1454 }
1455
1457 while (codeBlockInsertionStates.size() > stateIndex) {
1458 discardState();
1459 }
1460 }
1461
1463 if (!codeBlocks[currentCodeBlockIndex]->getIRArray().empty()) {
1464 switch (codeBlocks[currentCodeBlockIndex]->getIRArray().back().opcode) {
1465 case IR::Opcode::ret:
1467 case IR::Opcode::jump:
1468 return true;
1469 default:
1470 break;
1471 }
1472 }
1473 return false;
1474 }
1475
1477 marcos[name] = value;
1478 return *this;
1479 }
1480
1482 return variableScopeMap[varIndex];
1483 }
1484
1486 loopContext.pop_back();
1487 }
1488
1490 yoi_assert(!loopContext.empty(), currentDebugInfo.line, currentDebugInfo.column, "break statement outside a `while` or `for` loop");
1491 jumpOp(loopContext.back().breakTarget);
1492 }
1493
1495 yoi_assert(!loopContext.empty(), currentDebugInfo.line, currentDebugInfo.column, "continue statement outside a `while` or `for` loop");
1496 jumpOp(loopContext.back().continueTarget);
1497 }
1498
1499 void IRBuilder::bindElementsOp(yoi::indexT extractElementCount, ExtractType extractType) {
1500 auto rhs = tempVarStack.back();
1501 tempVarStack.pop_back();
1502 for (yoi::indexT i = 0; i < extractElementCount; i++) {
1503 tempVarStack.push_back(managedPtr(rhs->getElementType()));
1504 }
1505
1506 insert(IR{extractType == ExtractType::First ? IR::Opcode::bind_elements_post : IR::Opcode::bind_elements_pred,
1507 {{IROperand::operandType::index, extractElementCount}},
1508 currentDebugInfo});
1509 }
1510
1511 void IRBuilder::bindFieldsOp(yoi::indexT extractFieldCount, ExtractType extractType) {
1512 auto rhs = tempVarStack.back();
1513 auto structDef = compilerCtx->getImportedModule(rhs->typeAffiliateModule)->structTable[rhs->typeIndex];
1514 yoi::indexT startPos = (extractType == ExtractType::First ? 0 : structDef->fieldTypes.size() - extractFieldCount);
1515
1516 for (auto curPos = startPos; curPos < startPos + extractFieldCount; curPos++) {
1517 tempVarStack.push_back(structDef->fieldTypes[curPos]);
1518 }
1519 insert(IR{extractType == ExtractType::First ? IR::Opcode::bind_fields_post : IR::Opcode::bind_fields_pred,
1520 {{IROperand::operandType::index, extractFieldCount}},
1521 currentDebugInfo});
1522 }
1523
1524 void IRBuilder::pushLoopContext(yoi::indexT breakTarget, yoi::indexT continueTarget) {
1525 loopContext.push_back({breakTarget, continueTarget});
1526 }
1527
1528 IRValueType::IRValueType() : type(valueType::none), typeAffiliateModule(0), typeIndex(0), dimensions() {}
1529
1531 yoi::indexT funcArgsCount,
1532 const std::shared_ptr<IRValueType> &returnType,
1533 bool externalInvocation,
1534 yoi::indexT moduleIndex) {
1535 for (yoi::indexT i = 0; i < funcArgsCount; i++) {
1536 tempVarStack.pop_back();
1537 }
1538 tempVarStack.push_back(returnType);
1540 {{IROperand::operandType::index, moduleIndex == -1 ? currentModule->identifier : moduleIndex},
1541 {IROperand::operandType::index, funcIndex},
1542 {IROperand::operandType::index, funcArgsCount}},
1544 }
1545
1547 this->additionalLinkingFiles = additionalLinkingFiles;
1548 return *this;
1549 }
1550
1552 : name(name), valueToIndexMap(valueToIndexMap) {}
1553
1555 yoi::indexT maxIndex = 0;
1556
1557 for (auto &entry : valueToIndexMap)
1558 maxIndex = std::max(maxIndex, entry.second);
1559
1560 if (maxIndex <= 255)
1561 return UnderlyingType::I8;
1562 else if (maxIndex <= 65535)
1563 return UnderlyingType::I16;
1564 else
1565 return UnderlyingType::I64;
1566 }
1567
1569 this->name = name;
1570 return *this;
1571 }
1572
1574 this->valueToIndexMap.put_create(valueName, valueIndex);
1575 return *this;
1576 }
1577
1579 if (metadata.count(key)) {
1580 metadata.erase(key);
1581 }
1582 }
1583
1584 bool IRMetadata::hasMetadata(const yoi::wstr &key) const {
1585 return metadata.find(key) != metadata.end();
1586 }
1587
1589 std::wstringstream ss;
1590 for (auto &entry : metadata) {
1591 if (entry.first == L"regressed_interface_impl") {
1592 auto &implIndex = getMetadata<std::pair<yoi::indexT, yoi::indexT>>(L"regressed_interface_impl");
1593 ss << L"!" << entry.first << "{" << implIndex.first << "," << implIndex.second << "}" << ' ';
1594 } else if (entry.first == L"delayed_interface_impl") {
1595 auto &implIndex = getMetadata<std::pair<yoi::indexT, yoi::indexT>>(L"delayed_interface_impl");
1596 ss << L"!" << entry.first << "{" << implIndex.first << "," << implIndex.second << "}" << ' ';
1597 } else if (entry.first == L"from_local") {
1598 auto localIndex = getMetadata<yoi::indexT>(L"from_local");
1599 ss << L"!" << entry.first << "{" << localIndex << "}" << ' ';
1600 }
1601 }
1602 if (!ss.str().empty())
1603 ss.unget();
1604 return ss.str();
1605 }
1606
1607 std::shared_ptr<IREnumerationType> IREnumerationType::Builder::yield() {
1608 return std::make_shared<IREnumerationType>(name, valueToIndexMap);
1609 }
1610
1611 IRValueType::IRValueType(valueType type, const yoi::vec<yoi::IRValueType> &bracedTypes) : type(type), bracedTypes(bracedTypes) {}
1612
1614 if (!buildCachePath.empty()) {
1615 this->buildCachePath = buildCachePath;
1616 }
1617 return *this;
1618 }
1619
1624
1626 if (dimensions.empty()) {
1627 return 1;
1628 }
1629 yoi::indexT size = 1;
1630 for (auto &dimension : dimensions) {
1631 size *= dimension;
1632 }
1633 return size;
1634 }
1635
1637 const yoi::vec<std::shared_ptr<IRValueType>> &fieldTypes,
1638 const std::map<yoi::wstr, yoi::indexT> &fields,
1639 yoi::indexT linkedModuleId)
1640 : name(name), fieldTypes(fieldTypes), fields(fields), linkedModuleId(linkedModuleId) {}
1641
1643 this->name = name;
1644 return *this;
1645 }
1646
1648 const std::shared_ptr<IRValueType> &fieldType) {
1649 this->fieldTypes.push_back(fieldType);
1650 this->fields[fieldName] = this->fieldTypes.size() - 1;
1651 return *this;
1652 }
1653
1658
1659 std::shared_ptr<IRDataStructDefinition> IRDataStructDefinition::Builder::yield() {
1660 return std::make_shared<IRDataStructDefinition>(name, fieldTypes, fields, linkedModuleId);
1661 }
1662
1664 std::wstringstream ss;
1665 ss << yoi::wstr(indent, L' ') << L"datastruct " << name << L" {\n";
1666 for (auto &field : fieldTypes) {
1667 ss << yoi::wstr(indent + 4, L' ') << field->to_string() << L'\n';
1668 }
1669 ss << yoi::wstr(indent, L' ') << L'}' << L'\n';
1670 return ss.str();
1671 }
1672
1674 for (yoi::indexT i = 0; i < parameterCount; i++) {
1675 popFromTempVarStack();
1676 }
1677 insert(IR{IR::Opcode::initialize_field, {{IROperand::operandType::index, parameterCount}}, currentDebugInfo});
1678 }
1679
1681 const std::shared_ptr<IRValueType> &expectedType) {
1682 popFromTempVarStack();
1683 insert(IR{IR::Opcode::load_field, accessors, currentDebugInfo});
1684 pushTempVar(expectedType);
1685 }
1686
1688 popFromTempVarStack();
1689 insert(IR{IR::Opcode::store_field, accessors, currentDebugInfo});
1690 popFromTempVarStack();
1691 }
1692
1694 popFromTempVarStack();
1695 insert(IR{IR::Opcode::resume, {}, currentDebugInfo});
1696 }
1697
1698 void IRBuilder::yieldOp(bool yieldNone) {
1699 if (!yieldNone)
1700 popFromTempVarStack();
1701 popFromTempVarStack();
1702 insert(IR{IR::Opcode::yield, {}, currentDebugInfo});
1703 }
1704
1705 void IRVariableTable::set(yoi::indexT index, const std::shared_ptr<IRValueType> &type) {
1706 variables[index] = type;
1707 }
1708
1709 IRTemplateBuilder::Argument::Argument(const std::shared_ptr<IRValueType> &templateType,
1710 const yoi::vec<externModuleAccessExpression *> &satisfyConditions) : templateType(templateType), satisfyCondition(satisfyConditions) {
1711
1712 }
1713} // namespace yoi
void pushLoopContext(yoi::indexT breakTarget, yoi::indexT continueTarget)
Definition IR.cpp:1524
std::vector< std::shared_ptr< IRCodeBlock > > codeBlocks
Definition IR.h:881
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:1462
yoi::indexT saveState()
Definition IR.cpp:1164
void continueOp()
Definition IR.cpp:1494
std::shared_ptr< IRModule > currentModule
Definition IR.h:879
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:1207
std::shared_ptr< IRFunctionDefinition > currentFunction
Definition IR.h:880
void popOp()
Definition IR.cpp:1189
void yieldOp(bool yieldNone=false)
Definition IR.cpp:1698
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:884
void interfaceOfOp()
Definition IR.cpp:1345
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:1216
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:1489
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:1680
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:1185
void newArrayOp(const std::shared_ptr< IRValueType > &elementType, const yoi::vec< yoi::indexT > &dimensions, yoi::indexT onstackElementCount)
Definition IR.cpp:1106
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:1687
void invokeImportedOp(yoi::indexT libIndex, yoi::indexT funcIndex, yoi::indexT funcArgsCount, const std::shared_ptr< IRValueType > &returnType)
Definition IR.cpp:1070
void newStructOp(yoi::indexT structIndex, bool isExternal=false, yoi::indexT moduleIndex=-1)
Definition IR.cpp:453
yoi::indexT currentCodeBlockIndex
Definition IR.h:883
yoi::indexT switchCodeBlock(yoi::indexT index)
Definition IR.cpp:492
void discardState()
Definition IR.cpp:1169
void discardStateUntil(yoi::indexT stateIndex)
Definition IR.cpp:1456
void bindElementsOp(yoi::indexT extractElementCount, ExtractType extractType)
Definition IR.cpp:1499
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:1276
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:1339
void popLoopContext()
Definition IR.cpp:1485
void commitState()
Definition IR.cpp:1444
IRCodeBlock & getCurrentCodeBlock()
Definition IR.cpp:138
void initializeFieldsOp(yoi::indexT parameterCount)
Definition IR.cpp:1673
void resumeOp()
Definition IR.cpp:1693
IRBuilder()=delete
void jumpOp(yoi::indexT target)
Definition IR.cpp:286
IRDebugInfo currentDebugInfo
Definition IR.h:887
void bindFieldsOp(yoi::indexT extractFieldCount, ExtractType extractType)
Definition IR.cpp:1511
void restoreState()
Definition IR.cpp:1174
void jumpIfOp(IR::Opcode op, yoi::indexT target)
Definition IR.cpp:292
yoi::indexT getCurrentInsertionPoint()
Definition IR.cpp:484
void restoreStateTemporarily()
Definition IR.cpp:1433
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:1530
void newDynamicArrayOp(const std::shared_ptr< IRValueType > &elementType, yoi::indexT initializerSize=0)
Definition IR.cpp:1282
std::shared_ptr< compilerContext > compilerCtx
Definition IR.h:878
std::vector< std::shared_ptr< yoi::IRValueType > > tempVarStack
Definition IR.h:882
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:1247
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:1202
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:410
yoi::vec< std::shared_ptr< IRValueType > > fieldTypes
Definition IR.h:569
std::map< yoi::wstr, yoi::indexT > fields
Definition IR.h:571
yoi::wstr to_string(yoi::indexT indent=0)
Definition IR.cpp:1663
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:1636
yoi::indexT linkedModuleId
Definition IR.h:573
Builder & addValue(const yoi::wstr &valueName, yoi::indexT valueIndex)
Definition IR.cpp:1573
std::shared_ptr< IREnumerationType > yield()
Definition IR.cpp:1607
Builder & setName(const yoi::wstr &name)
Definition IR.cpp:1568
UnderlyingType getUnderlyingType()
Definition IR.cpp:1554
IREnumerationType(const yoi::wstr &name, const yoi::indexTable< yoi::wstr, yoi::indexT > &valueToIndexMap)
Definition IR.cpp:1551
yoi::indexTable< yoi::wstr, yoi::indexT > valueToIndexMap
Definition IR.h:388
yoi::wstr name
Definition IR.h:387
externType getExternType() const
Definition IR.cpp:886
enum yoi::IRExternEntry::externType type
IRExternEntry()=default
ImportLibrary(const yoi::wstr &libraryPath)
Definition IR.cpp:1037
void addForeignType(const yoi::wstr &foreignTypeName, const std::shared_ptr< IRValueType > &structType)
Definition IR.cpp:1056
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:1049
yoi::indexT addImportedFunction(const yoi::wstr &libraryName, const yoi::wstr &functionName, const std::shared_ptr< IRFunctionDefinition > &functionDefinition)
Definition IR.cpp:1039
yoi::indexTable< yoi::wstr, std::tuple< yoi::indexT, yoi::indexT, std::set< IRFunctionDefinition::FunctionAttrs > > > exportedFunctionTable
Definition IR.h:1106
yoi::indexTable< yoi::wstr, std::shared_ptr< IRValueType > > foreignTypeTable
Definition IR.h:1108
yoi::indexTable< yoi::wstr, ImportLibrary > importedLibraries
Definition IR.h:1110
yoi::vec< std::shared_ptr< IRValueType > > argumentTypes
Definition IR.h:480
std::shared_ptr< IRValueType > returnType
Definition IR.h:481
IRDebugInfo debugInfo
Definition IR.h:485
IRVariableTable variableTable
Definition IR.h:483
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:1425
std::set< FunctionAttrs > attrs
Definition IR.h:484
IRVariableTable & getVariableTable()
Definition IR.cpp:619
std::shared_ptr< IRFunctionDefinition > templateDefinition
Definition IR.h:556
std::shared_ptr< IRFunctionTemplate > yield()
Definition IR.cpp:968
Builder & setTemplateDefinition(const std::shared_ptr< IRFunctionDefinition > &templateDefinition)
Definition IR.cpp:963
std::shared_ptr< IRFunctionDefinition > templateDefinition
Definition IR.h:548
yoi::indexTable< yoi::wstr, IRTemplateBuilder::Argument > templateArguments
Definition IR.h:549
IRFunctionTemplate(const std::shared_ptr< IRFunctionDefinition > &templateDefinition, const yoi::indexTable< yoi::wstr, IRTemplateBuilder::Argument > &templateArguments)
Definition IR.cpp:959
yoi::wstr to_string(yoi::indexT indent=0)
Definition IR.cpp:944
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:788
std::shared_ptr< IRInterfaceImplementationTemplate > yield()
Definition IR.cpp:1006
Builder & setTemplateDefinition(const std::shared_ptr< IRInterfaceImplementationDefinition > &templateDefinition)
Definition IR.cpp:1000
std::shared_ptr< IRInterfaceImplementationDefinition > templateDefinition
Definition IR.h:783
IRInterfaceImplementationTemplate(const std::shared_ptr< IRInterfaceImplementationDefinition > &templateDefinition, const yoi::indexTable< yoi::wstr, IRTemplateBuilder::Argument > &templateArguments)
Definition IR.cpp:995
yoi::indexTable< yoi::wstr, IRTemplateBuilder::Argument > templateArguments
Definition IR.h:784
yoi::wstr to_string(yoi::indexT indent=0)
Definition IR.cpp:934
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:991
Builder & setTemplateDefinition(const std::shared_ptr< IRInterfaceInstanceDefinition > &templateDefinition)
Definition IR.cpp:986
std::shared_ptr< IRInterfaceInstanceDefinition > templateDefinition
Definition IR.h:768
yoi::indexTable< yoi::wstr, IRTemplateBuilder::Argument > templateArguments
Definition IR.h:764
IRInterfaceInstanceTemplate(const std::shared_ptr< IRInterfaceInstanceDefinition > &templateDefinition, const yoi::indexTable< yoi::wstr, IRTemplateBuilder::Argument > &templateArguments)
Definition IR.cpp:981
std::shared_ptr< IRInterfaceInstanceDefinition > templateDefinition
Definition IR.h:763
yoi::indexTable< yoi::wstr, std::shared_ptr< IRInterfaceInstanceDefinition > > interfaceTable
Definition IR.h:854
yoi::wstr to_string(yoi::indexT indent=0)
Definition IR.cpp:99
yoi::indexTable< yoi::wstr, std::shared_ptr< IRStructDefinition > > structTable
Definition IR.h:850
yoi::indexTable< yoi::wstr, std::shared_ptr< IRFunctionDefinition > > functionTable
Definition IR.h:849
yoi::indexTable< yoi::wstr, std::shared_ptr< IRInterfaceImplementationDefinition > > interfaceImplementationTable
Definition IR.h:855
enum yoi::IROperand::operandType type
std::shared_ptr< IRValueType > lvalueType
Definition IR.h:251
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:603
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:612
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:602
std::map< yoi::wstr, yoi::structDefInnerPair * > templateMethodDecls
Definition IR.h:613
std::map< yoi::wstr, nameInfo > nameIndexMap
Definition IR.h:609
std::map< yoi::wstr, yoi::implInnerPair * > templateMethodDefs
Definition IR.h:614
yoi::vec< yoi::wstr > templateParamNames
Definition IR.h:611
Builder & setTemplateDefinition(const std::shared_ptr< IRStructDefinition > &templateDefinition)
Definition IR.cpp:972
Builder & setTemplateMethod(const yoi::wstr &methodName, const std::shared_ptr< IRFunctionTemplate > &methodTemplate)
Definition IR.cpp:1017
std::shared_ptr< IRStructTemplate > yield()
Definition IR.cpp:977
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:1032
yoi::indexTable< yoi::wstr, Argument > templateArguments
Definition IR.h:537
IRTemplateBuilder & addTemplateArgument(const yoi::wstr &templateName, const std::shared_ptr< IRValueType > &templateType, const yoi::vec< externModuleAccessExpression * > &satisfyConditions={})
Definition IR.cpp:1010
bool isArrayType() const
Definition IR.cpp:1088
IRMetadata metadata
Definition IR.h:147
IRValueType getNormalizedForeignBasicType()
Definition IR.cpp:643
IRValueType getArrayType(const yoi::vec< yoi::indexT > &dimensions)
Definition IR.cpp:1160
IRValueType getBasicRawType() const
Definition IR.cpp:1374
bool isForeignBasicType() const
Definition IR.cpp:635
yoi::indexT calculateDimensionSize() const
Definition IR.cpp:1625
IRValueType & removeAttribute(ValueAttr attr)
Definition IR.cpp:1356
bool is1ByteType() const
Definition IR.cpp:639
IRValueType getElementType()
Definition IR.cpp:1101
enum yoi::IRValueType::valueType type
bool isDynamicArrayType() const
Definition IR.cpp:1335
IRValueType getBasicObjectType() const
Definition IR.cpp:1404
IRValueType getDynamicArrayType()
Definition IR.cpp:1331
bool hasAttribute(ValueAttr attr) const
Definition IR.cpp:1352
yoi::wstr to_string(bool showAttributes=false) const
Definition IR.cpp:661
std::set< ValueAttr > attributes
Definition IR.h:145
yoi::vec< yoi::indexT > dimensions
Definition IR.h:141
IRValueType & addAttribute(ValueAttr attr)
Definition IR.cpp:1361
bool operator==(const yoi::IRValueType &rhs) const
Definition IR.cpp:753
yoi::indexT typeIndex
Definition IR.h:139
bool isBasicRawType() const
Definition IR.cpp:1369
bool isBasicType() const
Definition IR.cpp:628
yoi::indexT typeAffiliateModule
Definition IR.h:138
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:1705
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:1028
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:1024
yoi::indexT scopeIndex(yoi::indexT varIndex)
Definition IR.cpp:1481
Definition IR.h:264
Opcode
Definition IR.h:266
IR()=default
yoi::vec< IROperand > operands
Definition IR.h:367
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:171
constexpr auto enum_name() noexcept -> detail::enable_if_t< decltype(V), string_view >
std::string wstring2string(const std::wstring &v)
Definition def.cpp:184
std::shared_ptr< T > managedPtr(const T &v)
Definition def.hpp:324
wstr::value_type wchar
Definition def.hpp:49
std::vector< t > vec
Definition def.hpp:53
std::wstring string2wstring(const std::string &v)
Definition def.cpp:178
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:171
void set_current_file_path(const std::wstring &path)
Definition def.cpp:113
std::wstring wstr
Definition def.hpp:48
uint64_t indexT
Definition def.hpp:51
void panic(yoi::indexT line, yoi::indexT col, const std::string &msg)
Definition def.cpp:131
Builder & addSearchPath(const yoi::wstr &searchPath)
Definition IR.cpp:1065
yoi::vec< yoi::wstr > additionalLinkingFiles
Definition IR.h:41
Builder & setImmediatelyClearupCache(bool immediatelyClearupCache)
Definition IR.cpp:1620
BuildType buildType
Definition IR.h:34
Builder & setBuildType(BuildType buildType)
Definition IR.cpp:890
Builder & setBuildCachePath(const yoi::wstr &buildCachePath)
Definition IR.cpp:1613
std::shared_ptr< IRBuildConfig > yield()
Definition IR.cpp:905
Builder & setAdditionalLinkingFiles(const yoi::vec< yoi::wstr > &additionalLinkingFiles)
Definition IR.cpp:1546
Builder & setPreserveIntermediateFiles(bool preserveIntermediateFiles)
Definition IR.cpp:929
Builder & setBuildMode(BuildMode buildMode)
Definition IR.cpp:919
Builder & setBuildPlatform(const yoi::wstr &buildPlatform)
Definition IR.cpp:895
Builder & setBuildArch(const yoi::wstr &buildArch)
Definition IR.cpp:900
yoi::wstr buildCachePath
Definition IR.h:43
Builder & setSearchPaths(const yoi::vec< yoi::wstr > &searchPaths)
Definition IR.cpp:1060
Builder & setMarco(const yoi::wstr &name, const yoi::wstr &value)
Definition IR.cpp:1476
Builder & setUseObjectLinker(UseObjectLinker useObjectLinker)
Definition IR.cpp:924
enum yoi::IRBuildConfig::BuildMode buildMode
bool preserveIntermediateFiles
Definition IR.h:26
yoi::vec< yoi::wstr > additionalLinkingFiles
Definition IR.h:28
yoi::wstr buildArch
Definition IR.h:25
std::map< yoi::wstr, yoi::wstr > marcos
Definition IR.h:29
enum yoi::IRBuildConfig::BuildType buildType
yoi::wstr buildCachePath
Definition IR.h:30
yoi::wstr buildPlatform
Definition IR.h:24
enum yoi::IRBuildConfig::UseObjectLinker useObjectLinker
yoi::vec< yoi::wstr > searchPaths
Definition IR.h:27
bool immediatelyClearupCache
Definition IR.h:31
Builder & addField(const yoi::wstr &fieldName, const std::shared_ptr< IRValueType > &fieldType)
Definition IR.cpp:1647
std::shared_ptr< IRDataStructDefinition > yield()
Definition IR.cpp:1659
Builder & setLinkedModuleId(yoi::indexT linkedModuleId)
Definition IR.cpp:1654
Builder & setName(const yoi::wstr &name)
Definition IR.cpp:1642
yoi::indexT column
Definition IR.h:81
yoi::indexT line
Definition IR.h:80
yoi::wstr sourceFile
Definition IR.h:79
Builder & setDebugInfo(const IRDebugInfo &debugInfo)
Definition IR.cpp:1211
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:1271
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:1588
void eraseMetadata(const yoi::wstr &key)
Definition IR.cpp:1578
bool hasMetadata(const yoi::wstr &key) const
Definition IR.cpp:1584
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:1709
yoi::indexT symbolIndex
Definition IR.h:231
yoi::indexT stringLiteralIndex
Definition IR.h:230
yoi::indexT codeBlockIndex
Definition IR.h:232