private void Expand(XILSInstr xilsi) { var preds = RemapPreds(xilsi.Preds); var expansion = Pattern.Expand(xilsi, preds); if (expansion == null) { ProcessDefault(xilsi); } else { foreach (XILSInstr xilsix in expansion) { Emit(xilsix); } if (xilsi.ResultTypes.Length > 0 && !TypeStack.Peek().Equals(xilsi.ResultTypes.Last())) { Emit( DefaultInstructionSet.Instance.Convert() .CreateStk(1, TypeStack.Peek(), xilsi.ResultTypes.Last())); } } }
private void CompilePop(GMLToken _tok, eVM_Type _type) { switch (_tok.Token) { case eToken.eVariable: case eToken.eDot: if (_tok.Children.Count >= 2) { int num = 0; CompileExpression(_tok.Children[0]); if (TypeStack.Peek() != eVM_Type.eVMT_Int) { Emit(eVM_Instruction.eVMI_CONV, TypeStack.Pop(), eVM_Type.eVMT_Int); TypeStack.Push(eVM_Type.eVMT_Int); } if (_tok.Children[1].Children.Count > 0) { CompileExpression(_tok.Children[1].Children[0]); if (TypeStack.Peek() != eVM_Type.eVMT_Int) { Emit(eVM_Instruction.eVMI_CONV, TypeStack.Pop(), eVM_Type.eVMT_Int); TypeStack.Push(eVM_Type.eVMT_Int); } if (_tok.Children[1].Children.Count > 1) { EmitI(eVM_Instruction.eVMI_PUSH, 32000); Emit(eVM_Instruction.eVMI_MUL, eVM_Type.eVMT_Int, eVM_Type.eVMT_Int); CompileExpression(_tok.Children[1].Children[1]); if (TypeStack.Peek() != eVM_Type.eVMT_Int) { Emit(eVM_Instruction.eVMI_CONV, TypeStack.Pop(), eVM_Type.eVMT_Int); TypeStack.Push(eVM_Type.eVMT_Int); } Emit(eVM_Instruction.eVMI_ADD, eVM_Type.eVMT_Int, eVM_Type.eVMT_Int); TypeStack.Pop(); } TypeStack.Pop(); } else { num |= int.MinValue; } TypeStack.Pop(); EmitIVar(eVM_Instruction.eVMI_POP, _tok.Children[1].Id | num, _type); TypeStack.Push(eVM_Type.eVMT_Variable); } else { Error("Malformed variable reference", _tok); } break; case eToken.eConstant: Error("Unsure where these come from", _tok); break; } }
private void BinaryTypeCoercion(GMLToken _tok, int _parmNum) { eVM_Type eVM_Type = TypeStack.Peek(); switch (_tok.Children[1].Token) { case eToken.eNot: case eToken.eLess: case eToken.eLessEqual: case eToken.eEqual: case eToken.eNotEqual: case eToken.eGreaterEqual: case eToken.eGreater: case eToken.eBitNegate: break; case eToken.ePlus: case eToken.eMinus: case eToken.eTime: case eToken.eDivide: case eToken.eDiv: case eToken.eMod: if (eVM_Type == eVM_Type.eVMT_Bool) { TypeStack.Pop(); Emit(eVM_Instruction.eVMI_CONV, eVM_Type, eVM_Type.eVMT_Int); TypeStack.Push(eVM_Type.eVMT_Int); } break; case eToken.eAnd: case eToken.eOr: case eToken.eXor: if (eVM_Type != eVM_Type.eVMT_Bool) { TypeStack.Pop(); Emit(eVM_Instruction.eVMI_CONV, eVM_Type, eVM_Type.eVMT_Bool); TypeStack.Push(eVM_Type.eVMT_Bool); } break; case eToken.eBitOr: case eToken.eBitAnd: case eToken.eBitXor: case eToken.eBitShiftLeft: case eToken.eBitShiftRight: if (eVM_Type == eVM_Type.eVMT_Int) { TypeStack.Pop(); Emit(eVM_Instruction.eVMI_CONV, eVM_Type, eVM_Type.eVMT_Int); TypeStack.Push(eVM_Type.eVMT_Int); } break; } }
private void CompileUnary(GMLToken _tok) { CompileExpression(_tok.Children[0]); eVM_Type eVM_Type = TypeStack.Peek(); switch (_tok.Id) { case 203: switch (eVM_Type) { case eVM_Type.eVMT_String: case eVM_Type.eVMT_Error: Error("Unable to Not a string", _tok); break; case eVM_Type.eVMT_Double: case eVM_Type.eVMT_Float: case eVM_Type.eVMT_Int: case eVM_Type.eVMT_Long: case eVM_Type.eVMT_Variable: TypeStack.Pop(); Emit(eVM_Instruction.eVMI_CONV, eVM_Type, eVM_Type.eVMT_Bool); TypeStack.Push(eVM_Type.eVMT_Bool); eVM_Type = eVM_Type.eVMT_Bool; break; } Emit(eVM_Instruction.eVMI_NOT, eVM_Type); break; case 211: Emit(eVM_Instruction.eVMI_NEG, eVM_Type); break; case 220: switch (eVM_Type) { case eVM_Type.eVMT_String: case eVM_Type.eVMT_Error: Error("Unable to Negate a string", _tok); break; case eVM_Type.eVMT_Double: case eVM_Type.eVMT_Float: case eVM_Type.eVMT_Variable: TypeStack.Pop(); Emit(eVM_Instruction.eVMI_CONV, eVM_Type, eVM_Type.eVMT_Int); TypeStack.Push(eVM_Type.eVMT_Int); eVM_Type = eVM_Type.eVMT_Int; break; } Emit(eVM_Instruction.eVMI_NOT, eVM_Type); break; } }
private void AnalyzeUsage(INamedTypeSymbol symbol) { if (!ValidateUsage(symbol)) { return; } if (symbol.ContainingAssembly != Assembly) { if (!SolutionAssemblyNames.Contains(symbol.ContainingAssembly.MetadataName)) { // filter out target types from outside of our solution assemblies return; } ExternalTypesUsed.Add(symbol); if (TypeStack.Count > 0) { var dependentSet = GetDependentsSet(symbol); dependentSet.Add(TypeStack.Peek()); } } }
private void ProcessStoreVariable(XILSInstr i) { var lit = (IStorableLiteral)i.StaticOperand; var local = lit as Variable; IStorableLiteral newLit; if (local != null) { Variable newLocal; if (!_localDic.TryGetValue(local.Name, out newLocal)) { newLocal = new Variable(TypeStack.Peek()) { Name = local.Name }; _localDic[local.Name] = newLocal; } newLit = newLocal; } else { newLit = lit; } var preds = RemapPreds(i.Preds); if (!TypeStack.Peek().Equals(newLit.Type)) { Convert(preds, TypeStack.Peek(), newLit.Type); preds = new InstructionDependency[0]; } var inew = new XILSInstr( DefaultInstructionSet.Instance.StoreVar(newLit), preds, new TypeDescriptor[] { newLit.Type }, new TypeDescriptor[0]); Emit(inew); }
private void Swap(InstructionDependency[] preds) { Emit(DefaultInstructionSet.Instance.Dig(1).CreateStk(preds, 2, TypeStack.ElementAt(1), TypeStack.Peek(), TypeStack.Peek(), TypeStack.ElementAt(1))); }
private void EmitIndexComputation(Array array) { MemoryMappedStorage mms = GetDataLayout(array); ArrayMemoryLayout layout = mms.Layout as ArrayMemoryLayout; if (layout.ElementsPerWord > 1) { throw new NotImplementedException("Multiple elements per word not yet implemented"); } MemoryRegion region = mms.Region; IMarshalInfo minfo = region.MarshalInfo; int shiftWidth = MathExt.CeilLog2(mms.Region.AddressWidth); TypeDescriptor indexType = TypeDescriptor.GetTypeOf(mms.BaseAddress); for (int i = 0; i < layout.Strides.Length; i++) { TypeDescriptor orgIndexType; if (i > 0) { orgIndexType = TypeStack.Skip(1).First(); Emit(_iset.Swap().CreateStk(2, orgIndexType, indexType, indexType, orgIndexType)); } else { orgIndexType = TypeStack.Peek(); } ulong stride = layout.Strides[layout.Strides.Length - i - 1]; if (MathExt.IsPow2(stride)) { Emit(_iset.Convert().CreateStk(1, orgIndexType, indexType)); int ishift = MathExt.CeilLog2(stride); if (ishift > 0) { Unsigned shift = Unsigned.FromULong((ulong)ishift, shiftWidth); TypeDescriptor shiftType = TypeDescriptor.GetTypeOf(shift); Emit(_iset.LdConst(shift).CreateStk(0, shiftType)); Emit(_iset.LShift().CreateStk(2, indexType, shiftType, indexType)); } } else { throw new NotImplementedException("Stride ain't a power of 2"); } if (i > 0) { Emit(_iset.Or().CreateStk(2, indexType, indexType, indexType)); } } if (mms.BaseAddress.ULongValue != 0) { Emit(_iset.LdConst(mms.BaseAddress).CreateStk(0, indexType)); if (minfo.UseStrongPow2Alignment) { Emit(_iset.Or().CreateStk(2, indexType, indexType, indexType)); } else { Emit(_iset.Add().CreateStk(2, indexType, indexType, indexType)); } } }