MCPcopy Create free account
hub / github.com/csyonghe/Spire / PrintBinaryInstr

Method PrintBinaryInstr

Source/SpireCore/SpirVCodeGen.cpp:3724–4035  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3722 }
3723
3724 void PrintBinaryInstr(BinaryInstruction * instr)
3725 {
3726 auto op0 = instr->Operands[0].Ptr();
3727 auto op1 = instr->Operands[1].Ptr();
3728
3729 //-------------------------------------Store Instruction------------------------------------------
3730 if (instr->Is<StoreInstruction>())
3731 {
3732 if (auto structType = dynamic_cast<ILStructType*>(op0->Type.Ptr()))
3733 {
3734 int op0ID = ctx.FindVariableID(op0);
3735 int op1ID = ctx.FindVariableID(op1);
3736 int index = 0;
3737 for (int i = 0; i < structType->Members.Count(); i++)
3738 {
3739 int indexID = ctx.AddInstrConstantInt(index);
3740 int dest = ctx.AddInstrAccessChain_StructMember(0, op0ID, indexID, index);
3741 int pSrc = ctx.AddInstrAccessChain_StructMember(0, op1ID, indexID, index);
3742 int vSrc = ctx.AddInstrLoad(pSrc, MemoryAccess::None);
3743 ctx.AddInstrStore(0, dest, vSrc);
3744 index++;
3745 }
3746 return;
3747 }
3748
3749 int op0ID = ctx.FindVariableID(op0); // should be a pointer
3750 int op1ID = GetOperandValue(op1);
3751 op1ID = ctx.ConvertBasicType(op1ID, ctx.IDInfos[op1ID]().GetILType(), ctx.IDInfos[op0ID]().GetILType());
3752 ctx.AddInstrStore(instr, op0ID, op1ID); //TO FIX
3753 return;
3754 }
3755
3756 //----------------------------------Member Load Instruction---------------------------------------
3757 if (instr->Is<MemberLoadInstruction>())
3758 {
3759 int fatherID = GetOperandPointer(op0);
3760 if (op0->Type->IsVector())
3761 {
3762 if (auto c = dynamic_cast<ILConstOperand*>(op1))
3763 {
3764 //if op1 is constant, take that as index of vector
3765 int memberID = ctx.AddInstrAccessChain_VectorMember((ILOperand*)instr, fatherID, -1, c->IntValues[0]);
3766 int retID = ctx.AddInstrLoad(memberID, MemoryAccess::None);
3767 ctx.UpdateValue((ILOperand*)instr, retID);
3768 return;
3769 }
3770 else
3771 {
3772 //if op1 is not constant, compute it
3773 int memberID = ctx.AddInstrAccessChain_VectorMember((ILOperand*)instr, fatherID, GetOperandValue(op1), -1);
3774 int retID = ctx.AddInstrLoad(memberID, MemoryAccess::None);
3775 ctx.UpdateValue((ILOperand*)instr, retID);
3776 return;
3777 }
3778 }
3779 else if (auto structType = dynamic_cast<ILStructType*>(op0->Type.Ptr()))
3780 {
3781 if (auto c = dynamic_cast<ILConstOperand*>(op1))

Callers

nothing calls this directly

Calls 15

SwapFunction · 0.85
GetTypeFromStringFunction · 0.85
FindVariableIDMethod · 0.80
AddInstrConstantIntMethod · 0.80
AddInstrLoadMethod · 0.80
AddInstrStoreMethod · 0.80
ConvertBasicTypeMethod · 0.80
GetILTypeMethod · 0.80
IsVectorMethod · 0.80

Tested by

no test coverage detected