internal static InstructionFlags CombineBranches(InstructionFlags trueFlags, InstructionFlags falseFlags) { // the endpoint of the 'if' is only unreachable if both branches have an unreachable endpoint const InstructionFlags combineWithAnd = InstructionFlags.EndPointUnreachable; return((trueFlags & falseFlags) | ((trueFlags | falseFlags) & ~combineWithAnd)); }
private ValueRef LoadValue(StackValueType stackType, ValueRef value, InstructionFlags instructionFlags) { // Load value from local (indirect values are kept as pointer) if (stackType == StackValueType.Value) { // Option1: Make a copy // TODO: Optimize stack allocation (reuse alloca slots, with help of FunctionStack) var result = LLVM.BuildAlloca(builderAlloca, LLVM.GetElementType(LLVM.TypeOf(value)), string.Empty); var valueCopy = LLVM.BuildLoad(builder, value, string.Empty); LLVM.BuildStore(builder, valueCopy, result); SetInstructionFlags(valueCopy, instructionFlags); return result; // Option2: Return pointer as is //return value; } else { var result = LLVM.BuildLoad(builder, value, string.Empty); SetInstructionFlags(result, instructionFlags); return result; } }
private void EmitLdfld(List <StackValue> stack, Field field, InstructionFlags instructionFlags) { var @object = stack.Pop(); ValueRef value; if (@object.StackType == StackValueType.Value) { value = LLVM.BuildExtractValue(builder, @object.Value, (uint)field.StructIndex, string.Empty); } else { var objectValue = ConvertReferenceToExpectedType(@object, field.DeclaringClass.Type); // Build indices for GEP var indices = BuildFieldIndices(field, @object.StackType, field.DeclaringClass.Type); // Find field address using GEP var fieldAddress = LLVM.BuildInBoundsGEP(builder, objectValue, indices, string.Empty); // Load value from field and create "fake" local value = LLVM.BuildLoad(builder, fieldAddress, string.Empty); // Set instruction flags SetInstructionFlags(value, instructionFlags); } // Convert from local to stack value value = ConvertFromLocalToStack(field.Type, value); // Add value to stack stack.Add(new StackValue(field.Type.StackType, field.Type, value)); }
/// <summary> /// Gets whether instruction is pure: /// * must not have side effects /// * must not throw exceptions /// * must not branch /// </summary> internal static bool IsPure(InstructionFlags inst) { // ControlFlow is fine: internal control flow is pure as long as it's not an infinite loop, // and infinite loops are impossible without MayBranch. const InstructionFlags pureFlags = InstructionFlags.MayReadLocals | InstructionFlags.ControlFlow; return((inst & ~pureFlags) == 0); }
private void StoreValue(StackValueType stackType, ValueRef value, ValueRef dest, InstructionFlags instructionFlags) { if (stackType == StackValueType.Value) value = LLVM.BuildLoad(builder, value, string.Empty); var store = LLVM.BuildStore(builder, value, dest); SetInstructionFlags(store, instructionFlags); }
internal void RegisterMove(ILInstruction predecessor) { FlagsBeingMoved |= predecessor.Flags; MoveActions.Add(delegate { var v = Function.RegisterVariable(VariableKind.StackSlot, predecessor.ResultType); predecessor.ReplaceWith(new LdLoc(v)); return(new StLoc(v, predecessor)); }); }
protected override InstructionFlags ComputeFlags() { // Convert MayUnwrapNull flag to ControlFlow flag. // Also, remove EndpointUnreachable flag, because the end-point is reachable through // the implicit nullable.unwrap branch. const InstructionFlags flagsToRemove = InstructionFlags.MayUnwrapNull | InstructionFlags.EndPointUnreachable; return((Argument.Flags & ~flagsToRemove) | InstructionFlags.ControlFlow); }
internal void RegisterMove(ILInstruction predecessor) { FlagsBeingMoved |= predecessor.Flags; MoveActions.Add(delegate { var type = context.TypeSystem.FindType(predecessor.ResultType.ToKnownTypeCode()); var v = Function.RegisterVariable(VariableKind.StackSlot, type); predecessor.ReplaceWith(new LdLoc(v)); return(new StLoc(v, predecessor)); }); }
void SetFlag(InstructionFlags f, bool value) { if (value) { _flags |= f; } else { _flags &= ~f; } }
private static void SetInstructionFlags(ValueRef instruction, InstructionFlags instructionFlags) { // Set instruction flags (if necessary) if ((instructionFlags & InstructionFlags.Volatile) != 0) { LLVM.SetVolatile(instruction, true); } if ((instructionFlags & InstructionFlags.Unaligned) != 0) { LLVM.SetAlignment(instruction, 1); } }
public InstructionDefinition(Byte opcode, String name, InstructionFlags flags, Action <DisassemblyState> disassemblyfunction, params OperandType[] operandtypes) { Assert.IsValidString(name, nameof(name)); Assert.IsValidEnumeration(flags, nameof(flags), false); Assert.IsNotNull(disassemblyfunction, nameof(disassemblyfunction)); Assert.IsNotNull(operandtypes, nameof(operandtypes)); OpCode = opcode; Name = name; Flags = flags; DisassemblyFunction = disassemblyfunction; DefaultOperandTypes = operandtypes.ToReadOnlyList(); }
private void EmitStobj(List <StackValue> stack, Type type, InstructionFlags instructionFlags) { var value = stack.Pop(); var address = stack.Pop(); // Convert to local type var sourceValue = ConvertFromStackToLocal(type, value); // Store value at address var pointerCast = LLVM.BuildPointerCast(builder, address.Value, LLVM.PointerType(type.DefaultType, 0), string.Empty); var storeInst = LLVM.BuildStore(builder, sourceValue, pointerCast); SetInstructionFlags(storeInst, instructionFlags); }
public DecompilerTableEntry(Type instructionType, string name, string operand, InstructionFlags flags, CustomDecompilerDelegate customDecompiler, int?id) { if (instructionType == null) { throw new ArgumentNullException(nameof(instructionType)); } InstructionType = instructionType; Name = name; Operand = operand; Flags = flags; CustomDecompiler = customDecompiler; Id = id; }
/// <summary> /// Gets whether the instruction sequence 'inst1; inst2;' may be ordered to 'inst2; inst1;' /// </summary> internal static bool MayReorder(InstructionFlags inst1, InstructionFlags inst2) { // If both instructions perform an impure action, we cannot reorder them if (!IsPure(inst1) && !IsPure(inst2)) { return(false); } // We cannot reorder if inst2 might write what inst1 looks at if (ConflictingPair(inst1, inst2, InstructionFlags.MayReadLocals, InstructionFlags.MayWriteLocals | InstructionFlags.SideEffect)) { return(false); } return(true); }
public InstructionInfo( int opRMR, int opRMImm8, int opRMImm32, int opRImm64, int opRRM, InstructionFlags flags) { OpRMR = opRMR; OpRMImm8 = opRMImm8; OpRMImm32 = opRMImm32; OpRImm64 = opRImm64; OpRRM = opRRM; Flags = flags; }
private void EmitLdobj(List <StackValue> stack, Type type, InstructionFlags instructionFlags) { var address = stack.Pop(); // Load value at address var pointerCast = LLVM.BuildPointerCast(builder, address.Value, LLVM.PointerType(type.DefaultType, 0), string.Empty); var loadInst = LLVM.BuildLoad(builder, pointerCast, string.Empty); SetInstructionFlags(loadInst, instructionFlags); // Convert to stack type var value = ConvertFromLocalToStack(type, loadInst); // Add to stack stack.Add(new StackValue(type.StackType, type, value)); }
protected override InstructionFlags ComputeFlags() { InstructionFlags flags = InstructionFlags.ControlFlow; foreach (var block in Blocks) { flags |= block.Flags; } // The end point of the BlockContainer is only reachable if there's a leave instruction if (LeaveCount == 0) { flags |= InstructionFlags.EndPointUnreachable; } else { flags &= ~InstructionFlags.EndPointUnreachable; } return(flags); }
private void EmitStsfld(List <StackValue> stack, Field field, InstructionFlags instructionFlags) { var value = stack.Pop(); var runtimeTypeInfoGlobal = field.DeclaringClass.GeneratedRuntimeTypeInfoGlobal; // Get static field GEP indices var indices = BuildStaticFieldIndices(field); // Find static field address in runtime type info var staticFieldAddress = LLVM.BuildInBoundsGEP(builder, runtimeTypeInfoGlobal, indices, string.Empty); // Convert stack value to appropriate type var fieldValue = ConvertFromStackToLocal(field.Type, value); // Store value in static field var storeInst = LLVM.BuildStore(builder, fieldValue, staticFieldAddress); // Set instruction flags SetInstructionFlags(storeInst, instructionFlags); }
void Copy(Instruction from) { Code = from.Code; _flags = from._flags; Name = from.Name; Description = from.Description; Category = from.Category; FrameSet = from.FrameSet; FrameUse = from.FrameUse; if (from._operands != null) { int n = from._operands.Length; _operands = new Operand[n]; for (int k = 0; k < n; ++k) { _operands[k] = from._operands[k].Clone(); } } _stackPop = from._stackPop; StackPush = from.StackPush; }
private void EmitLdsfld(List <StackValue> stack, Field field, InstructionFlags instructionFlags) { var runtimeTypeInfoGlobal = field.DeclaringClass.GeneratedRuntimeTypeInfoGlobal; // Get static field GEP indices var indices = BuildStaticFieldIndices(field); // Find static field address in runtime type info var staticFieldAddress = LLVM.BuildInBoundsGEP(builder, runtimeTypeInfoGlobal, indices, string.Empty); // Load value from field and create "fake" local var value = LLVM.BuildLoad(builder, staticFieldAddress, string.Empty); // Convert from local to stack value value = ConvertFromLocalToStack(field.Type, value); // Set instruction flags SetInstructionFlags(value, instructionFlags); // Add value to stack stack.Add(new StackValue(field.Type.StackType, field.Type, value)); }
private void EmitStfld(List <StackValue> stack, Field field, InstructionFlags instructionFlags) { var value = stack.Pop(); var @object = stack.Pop(); var objectValue = ConvertReferenceToExpectedType(@object, field.DeclaringClass.Type); // Build indices for GEP var indices = BuildFieldIndices(field, @object.StackType, field.DeclaringClass.Type); // Find field address using GEP var fieldAddress = LLVM.BuildInBoundsGEP(builder, objectValue, indices, string.Empty); // Convert stack value to appropriate type var fieldValue = ConvertFromStackToLocal(field.Type, value); // Store value in field var storeInst = LLVM.BuildStore(builder, fieldValue, fieldAddress); // Set instruction flags SetInstructionFlags(storeInst, instructionFlags); }
private List<XslNode> LoadInstructions(InstructionFlags flags) { return LoadInstructions(new List<XslNode>(), flags); }
private void EmitStfld(List<StackValue> stack, Field field, InstructionFlags instructionFlags) { var value = stack.Pop(); var @object = stack.Pop(); var objectValue = ConvertReferenceToExpectedType(@object, field.DeclaringClass.Type); // Build indices for GEP var indices = BuildFieldIndices(field, @object.StackType, field.DeclaringClass.Type); // Find field address using GEP var fieldAddress = LLVM.BuildInBoundsGEP(builder, objectValue, indices, string.Empty); // Convert stack value to appropriate type var fieldValue = ConvertFromStackToLocal(field.Type, value); // Store value in field var storeInst = LLVM.BuildStore(builder, fieldValue, fieldAddress); // Set instruction flags SetInstructionFlags(storeInst, instructionFlags); }
private void EmitStobj(FunctionStack stack, Type type, InstructionFlags instructionFlags) { var value = stack.Pop(); var address = stack.Pop(); // Convert to local type var sourceValue = ConvertFromStackToLocal(type, value); // Store value at address var pointerCast = LLVM.BuildPointerCast(builder, address.Value, LLVM.PointerType(type.DefaultTypeLLVM, 0), string.Empty); StoreValue(type.StackType, sourceValue, pointerCast, instructionFlags); }
private static DecompilerTableEntry CreateCustomEntry(string name, string operand = "", InstructionFlags flags = InstructionFlags.INSTRUCTION_NONE, CustomDecompilerDelegate customDecompiler = null, int?id = null) { return(new DecompilerTableEntry(typeof(Custom), name, operand, flags, customDecompiler, id)); }
public bool HasFlag(InstructionFlags flags) { return((this.Flags & flags) != 0); }
private void EmitStsfld(FunctionStack stack, Field field, InstructionFlags instructionFlags) { var value = stack.Pop(); var runtimeTypeInfoGlobal = GetClass(field.DeclaringType).GeneratedEETypeRuntimeLLVM; // Get static field GEP indices var indices = BuildStaticFieldIndices(field); // Find static field address in runtime type info var fieldAddress = LLVM.BuildInBoundsGEP(builder, runtimeTypeInfoGlobal, indices, string.Empty); // Convert stack value to appropriate type var fieldValue = ConvertFromStackToLocal(field.Type, value); // Store value in static field StoreValue(field.Type.StackType, fieldValue, fieldAddress, instructionFlags); }
private void EmitLdsfld(FunctionStack stack, Field field, InstructionFlags instructionFlags) { var runtimeTypeInfoGlobal = GetClass(field.DeclaringType).GeneratedEETypeRuntimeLLVM; // Get static field GEP indices var indices = BuildStaticFieldIndices(field); // Find static field address in runtime type info var staticFieldAddress = LLVM.BuildInBoundsGEP(builder, runtimeTypeInfoGlobal, indices, string.Empty); // Load value from field and create "fake" local var value = LoadValue(field.Type.StackType, staticFieldAddress, instructionFlags); // Convert from local to stack value value = ConvertFromLocalToStack(field.Type, value); // Add value to stack stack.Add(new StackValue(field.Type.StackType, field.Type, value)); }
private ValueRef ComputeFieldAddress(BuilderRef builder, Field field, StackValueType objectStackType, ValueRef objectValue, ref InstructionFlags instructionFlags) { objectValue = ConvertReferenceToExpectedType(builder, objectStackType, objectValue, field.DeclaringType); Type type = field.DeclaringType; // Build indices for GEP var indices = new List<ValueRef>(3); if (objectStackType == StackValueType.Reference || objectStackType == StackValueType.Object || objectStackType == StackValueType.Value || objectStackType == StackValueType.NativeInt) { // First pointer indirection indices.Add(LLVM.ConstInt(int32LLVM, 0, false)); } bool isCustomLayout = IsCustomLayout(type.TypeDefinitionCecil); if (objectStackType == StackValueType.Object) { // Access data indices.Add(LLVM.ConstInt(int32LLVM, (int)ObjectFields.Data, false)); if (!isCustomLayout) { // For now, go through hierarchy and check that type match // Other options: // - cast // - store class depth (and just do a substraction) int depth = 0; var @class = GetClass(type); while (@class != null) { if (@class.Type == field.DeclaringType) break; @class = @class.BaseType; depth++; } if (@class == null) throw new InvalidOperationException(string.Format("Could not find field {0} in hierarchy of {1}", field.FieldDefinition, type.TypeReferenceCecil)); // Apply GEP indices to find right object (parent is always stored in first element) for (int i = 0; i < depth; ++i) indices.Add(LLVM.ConstInt(int32LLVM, 0, false)); } } // Access the appropriate field indices.Add(LLVM.ConstInt(int32LLVM, (uint)field.StructIndex, false)); // Find field address using GEP var fieldAddress = LLVM.BuildInBoundsGEP(builder, objectValue, indices.ToArray(), string.Empty); // Cast to real field type (if stored in a custom layout array) if (isCustomLayout) { fieldAddress = LLVM.BuildPointerCast(builder, fieldAddress, LLVM.PointerType(field.Type.DefaultTypeLLVM, 0), string.Empty); // Check if non aligned if (field.StructIndex % 4 != 0) instructionFlags = InstructionFlags.Unaligned; } return fieldAddress; }
private static void SetInstructionFlags(ValueRef instruction, InstructionFlags instructionFlags) { // Set instruction flags (if necessary) if ((instructionFlags & InstructionFlags.Volatile) != 0) LLVM.SetVolatile(instruction, true); if ((instructionFlags & InstructionFlags.Unaligned) != 0) LLVM.SetAlignment(instruction, 1); }
private void EmitLdfld(FunctionStack stack, Field field, InstructionFlags instructionFlags) { var @object = stack.Pop(); // Compute field address var fieldAddress = ComputeFieldAddress(builder, field, @object.StackType, @object.Value, ref instructionFlags); // Load value from field and create "fake" local var value = LoadValue(field.Type.StackType, fieldAddress, instructionFlags); // Convert from local to stack value value = ConvertFromLocalToStack(field.Type, value); // Add value to stack stack.Add(new StackValue(field.Type.StackType, field.Type, value)); }
private InstructionDescription(InstructionCode code, string name, InstructionGroup group, InstructionFlags flags, OperandFlags[] operandFlags, int opReg, int opcode0, int opcode1) { Contract.Requires(operandFlags != null); _code = code; _name = name; _group = (byte)group; _flags = (byte)flags; _operandFlags = new ReadOnlyCollection<OperandFlags>((OperandFlags[])operandFlags.Clone()); _opcodeR = (short)opReg; _opcode0 = opcode0; _opcode1 = opcode1; }
private static InstructionDescription MAKE_INST(InstructionCode code, string name, InstructionGroup group, InstructionFlags flags, OperandFlags oflags0, OperandFlags oflags1, int opReg, uint opcode0, uint opcode1) { return new InstructionDescription(code, name, group, flags, new OperandFlags[] { oflags0, oflags1 }, opReg, (int)opcode0, (int)opcode1); }
private List<XslNode> LoadInstructions(List<XslNode> content, InstructionFlags flags) { if (++_loadInstructionsDepth > MAX_LOADINSTRUCTIONS_DEPTH) { if (LocalAppContextSwitches.LimitXPathComplexity) { throw XslLoadException.Create(SR.Xslt_InputTooComplex); } } QName parentName = _input.ElementName; if (_input.MoveToFirstChild()) { bool atTop = true; int sortNumber = 0; XslNode result; do { switch (_input.NodeType) { case XmlNodeType.Element: string nspace = _input.NamespaceUri; string name = _input.LocalName; if (nspace == _atoms.UriXsl) { InstructionFlags instrFlag = ( Ref.Equal(name, _atoms.Param) ? InstructionFlags.AllowParam : Ref.Equal(name, _atoms.Sort) ? InstructionFlags.AllowSort : /*else */ InstructionFlags.None ); if (instrFlag != InstructionFlags.None) { string error = ( (flags & instrFlag) == 0 ? /*[XT_013]*/SR.Xslt_UnexpectedElement : !atTop ? /*[XT_014]*/SR.Xslt_NotAtTop : /*else*/ null ); if (error != null) { ReportError(error, _input.QualifiedName, parentName); atTop = false; _input.SkipNode(); continue; } } else { atTop = false; } result = ( Ref.Equal(name, _atoms.ApplyImports) ? XslApplyImports() : Ref.Equal(name, _atoms.ApplyTemplates) ? XslApplyTemplates() : Ref.Equal(name, _atoms.CallTemplate) ? XslCallTemplate() : Ref.Equal(name, _atoms.Copy) ? XslCopy() : Ref.Equal(name, _atoms.CopyOf) ? XslCopyOf() : Ref.Equal(name, _atoms.Fallback) ? XslFallback() : Ref.Equal(name, _atoms.If) ? XslIf() : Ref.Equal(name, _atoms.Choose) ? XslChoose() : Ref.Equal(name, _atoms.ForEach) ? XslForEach() : Ref.Equal(name, _atoms.Message) ? XslMessage() : Ref.Equal(name, _atoms.Number) ? XslNumber() : Ref.Equal(name, _atoms.ValueOf) ? XslValueOf() : Ref.Equal(name, _atoms.Comment) ? XslComment() : Ref.Equal(name, _atoms.ProcessingInstruction) ? XslProcessingInstruction() : Ref.Equal(name, _atoms.Text) ? XslText() : Ref.Equal(name, _atoms.Element) ? XslElement() : Ref.Equal(name, _atoms.Attribute) ? XslAttribute() : Ref.Equal(name, _atoms.Variable) ? XslVarPar() : Ref.Equal(name, _atoms.Param) ? XslVarPar() : Ref.Equal(name, _atoms.Sort) ? XslSort(sortNumber++) : #if XSLT2 V2 && Ref.Equal(name, atoms.AnalyzeString ) ? XslAnalyzeString() : V2 && Ref.Equal(name, "namespace" ) ? XslNamespace() : V2 && Ref.Equal(name, atoms.PerformSort ) ? XslPerformSort() : V2 && Ref.Equal(name, atoms.Document ) ? XslDocument() : V2 && Ref.Equal(name, atoms.ForEachGroup ) ? XslForEachGroup() : V2 && Ref.Equal(name, atoms.NextMatch ) ? XslNextMatch() : V2 && Ref.Equal(name, atoms.Sequence ) ? XslSequence() : V2 && Ref.Equal(name, atoms.ResultDocument ) ? XslResultDocument() : #endif /*default:*/ LoadUnknownXsltInstruction(parentName) ); } else { atTop = false; result = LoadLiteralResultElement(/*asStylesheet:*/false); } break; case XmlNodeType.SignificantWhitespace: result = SetLineInfo(f.Text(_input.Value), _input.BuildLineInfo()); break; case XmlNodeType.Whitespace: continue; default: Debug.Assert(_input.NodeType == XmlNodeType.Text); atTop = false; goto case XmlNodeType.SignificantWhitespace; } AddInstruction(content, result); } while (_input.MoveToNextSibling()); } --_loadInstructionsDepth; return content; }
/// <summary> /// Tries to disassemble a single instruction beginning at the stream's current position. /// </summary> /// <param name="data"></param> /// <param name="readLimit"></param> /// <returns></returns> private Instruction TryDisassembleInstruction(Stream data, int readLimit) { if (readLimit < 1) { return(null); // Caller doesn't want us to read anymore. } int firstByte = data.ReadByte(); if (firstByte < 0) { return(null); // Reached end of stream. } var opcode = Instruction.ParseMnemonic((byte)firstByte); if (!opcode.HasValue) { return(null); // Unrecognized opcode. } var ret = new Instruction(opcode.Value); ret.Address = (int)data.Position - 1; // Minus 1 because we already read the first byte of it. if (ret.Format == InstructionFormat.Format1) { return(ret); // Format 1 instructions need no further processing. } if (readLimit < 2) { return(null); // Caller doesn't want us to read anymore. } int secondByte = data.ReadByte(); if (secondByte < 0) { return(null); // Reached end of stream. } if (ret.Format == InstructionFormat.Format2) { ret.Operands[0].Value = (secondByte & 0xf0) >> 4; if (ret.Operation != Instruction.Mnemonic.CLEAR) // CLEAR has only one operand. { ret.Operands[1].Value = secondByte & 0xf; } return(ret); } bool format4 = false; InstructionFlags flags = 0; if ((firstByte & 0b10) != 0) { flags |= InstructionFlags.N; } if ((firstByte & 1) != 0) { flags |= InstructionFlags.I; } if ((secondByte & 0b10000000) != 0) { flags |= InstructionFlags.X; } if ((secondByte & 0b01000000) != 0) { flags |= InstructionFlags.B; } if ((secondByte & 0b00100000) != 0) { flags |= InstructionFlags.P; } if ((secondByte & 0b00010000) != 0) { flags |= InstructionFlags.E; format4 = true; } ret.Flags = flags; var debug_flagStrings = ""; if (flags.HasFlag(InstructionFlags.N)) { debug_flagStrings = "Indirect"; } if (flags.HasFlag(InstructionFlags.I)) { debug_flagStrings += " Immediate"; } if (flags.HasFlag(InstructionFlags.X)) { debug_flagStrings += " Indexed"; } if (flags.HasFlag(InstructionFlags.B)) { debug_flagStrings += " Base"; } if (flags.HasFlag(InstructionFlags.P)) { debug_flagStrings += " Program"; } if (flags.HasFlag(InstructionFlags.E)) { debug_flagStrings += " Extended"; } if (ret.Operation == Instruction.Mnemonic.RSUB) { return(ret); } // Instruction is format 3 or 4. if (readLimit < 3) { return(null); // Caller doesn't want us to read anymore. } int thirdByte = data.ReadByte(); if (thirdByte < 0) { return(null); // Reached end of stream. } // Read a fourth byte if necessary. if (format4) { if (readLimit < 4) { return(null); // Caller doesn't want us to read anymore. } int fourthByte = data.ReadByte(); if (fourthByte < 0) { return(null); // Reached end of stream. } ret.Operands[0].Value = (secondByte & 0x0f) << 16 | thirdByte << 8 | fourthByte; ret.Format = InstructionFormat.Format4; return(ret); } else { //if (ret.Operation != Instruction.Mnemonic.RSUB) // RSUB has no operands. ret.Operands[0].Value = (secondByte & 0x0f) << 8 | thirdByte; ret.Format = InstructionFormat.Format3; return(ret); } }
private List<XslNode> LoadWithParams(InstructionFlags flags) { QName parentName = _input.ElementName; List<XslNode> content = new List<XslNode>(); /* Process children */ if (_input.MoveToFirstChild()) { int sortNumber = 0; do { switch (_input.NodeType) { case XmlNodeType.Element: if (_input.IsXsltKeyword(_atoms.WithParam)) { XslNode withParam = XslVarPar(); CheckWithParam(content, withParam); AddInstruction(content, withParam); } else if (flags == InstructionFlags.AllowSort && _input.IsXsltKeyword(_atoms.Sort)) { AddInstruction(content, XslSort(sortNumber++)); } else if (flags == InstructionFlags.AllowFallback && _input.IsXsltKeyword(_atoms.Fallback)) { XslFallback(); } else { ReportError(/*[XT_016]*/SR.Xslt_UnexpectedElement, _input.QualifiedName, parentName); _input.SkipNode(); } break; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: break; default: Debug.Assert(_input.NodeType == XmlNodeType.Text); ReportError(/*[XT_016]*/SR.Xslt_TextNodesNotAllowed, parentName); break; } } while (_input.MoveToNextSibling()); } return content; }
private static bool ConflictingPair(InstructionFlags inst1, InstructionFlags inst2, InstructionFlags readFlag, InstructionFlags writeFlag) { // if one instruction has the read flag and the other the write flag, that's a conflict return((inst1 & readFlag) != 0 && (inst2 & writeFlag) != 0 || (inst2 & readFlag) != 0 && (inst1 & writeFlag) != 0); }
public bool HasDirectFlag(InstructionFlags flags) { return((this.DirectFlags & flags) != 0); }
private List<XslNode> LoadInstructions(List<XslNode> content, InstructionFlags flags) { string parentName = input.QualifiedName; if (input.MoveToFirstChild()) { bool atTop = true; XslNode result; do { switch (input.NodeType) { case XPathNodeType.Element: string nspace = input.NamespaceUri; string name = input.LocalName; if (nspace == input.Atoms.UriXsl) { bool error = false; if (Ref.Equal(name, input.Atoms.Param)) { if ((flags & InstructionFlags.AllowParam) == 0) { ReportError(/*[XT_013]*/Res.Xslt_UnexpectedElementQ, input.QualifiedName, parentName); error = true; } else if (!atTop) { // xsl:param's must precede any other children of xsl:template ReportError(/*[XT_014]*/Res.Xslt_NotAtTop, input.QualifiedName, parentName); error = true; } } else if (Ref.Equal(name, input.Atoms.Sort)) { if ((flags & InstructionFlags.AllowSort) == 0) { ReportError(/*[XT_013]*/Res.Xslt_UnexpectedElementQ, input.QualifiedName, parentName); error = true; } else if (!atTop) { // xsl:sort's must precede any other children of xsl:for-each ReportError(/*[XT_014]*/Res.Xslt_NotAtTop, input.QualifiedName, parentName); error = true; } } else { atTop = false; } if (error) { atTop = false; input.SkipNode(); continue; } result = ( Ref.Equal(name, input.Atoms.ApplyImports ) ? XslApplyImports() : Ref.Equal(name, input.Atoms.ApplyTemplates ) ? XslApplyTemplates() : Ref.Equal(name, input.Atoms.CallTemplate ) ? XslCallTemplate() : Ref.Equal(name, input.Atoms.Copy ) ? XslCopy() : Ref.Equal(name, input.Atoms.CopyOf ) ? XslCopyOf() : Ref.Equal(name, input.Atoms.Fallback ) ? XslFallback() : Ref.Equal(name, input.Atoms.If ) ? XslIf() : Ref.Equal(name, input.Atoms.Choose ) ? XslChoose() : Ref.Equal(name, input.Atoms.ForEach ) ? XslForEach() : Ref.Equal(name, input.Atoms.Message ) ? XslMessage() : Ref.Equal(name, input.Atoms.Number ) ? XslNumber() : Ref.Equal(name, input.Atoms.ValueOf ) ? XslValueOf() : Ref.Equal(name, input.Atoms.Comment ) ? XslComment() : Ref.Equal(name, input.Atoms.ProcessingInstruction) ? XslProcessingInstruction() : Ref.Equal(name, input.Atoms.Text ) ? XslText() : Ref.Equal(name, input.Atoms.Element ) ? XslElement() : Ref.Equal(name, input.Atoms.Attribute ) ? XslAttribute() : Ref.Equal(name, input.Atoms.Variable ) ? XslVarPar(XslNodeType.Variable) : Ref.Equal(name, input.Atoms.Param ) ? XslVarPar(XslNodeType.Param) : Ref.Equal(name, input.Atoms.Sort ) ? XslSort() : /*default:*/ LoadUnknownXsltInstruction(parentName) ); } else { atTop = false; result = LoadLiteralResultElement(/*asStylesheet:*/false); } break; case XPathNodeType.SignificantWhitespace: result = SetLineInfo(f.Text(input.Value), input.BuildLineInfo()); break; case XPathNodeType.Whitespace: continue; default: Debug.Assert(input.NodeType == XPathNodeType.Text); atTop = false; goto case XPathNodeType.SignificantWhitespace; } AddInstruction(content, result); } while (input.MoveToNextSibling()); input.MoveToParent(); } return content; }
private static DecompilerTableEntry CreateEntry <T>(string operand = "", InstructionFlags flags = InstructionFlags.INSTRUCTION_SWITCH, CustomDecompilerDelegate customDecompiler = null, int?id = null) where T : BaseInstruction { return(new DecompilerTableEntry(typeof(T), string.Empty, operand, flags, customDecompiler, id)); }
private void EmitStsfld(List<StackValue> stack, Field field, InstructionFlags instructionFlags) { var value = stack.Pop(); var runtimeTypeInfoGlobal = field.DeclaringClass.GeneratedRuntimeTypeInfoGlobal; // Get static field GEP indices var indices = BuildStaticFieldIndices(field); // Find static field address in runtime type info var staticFieldAddress = LLVM.BuildInBoundsGEP(builder, runtimeTypeInfoGlobal, indices, string.Empty); // Convert stack value to appropriate type var fieldValue = ConvertFromStackToLocal(field.Type, value); // Store value in static field var storeInst = LLVM.BuildStore(builder, fieldValue, staticFieldAddress); // Set instruction flags SetInstructionFlags(storeInst, instructionFlags); }
bool IsFlag(InstructionFlags f) { return((_flags & f) != 0); }
private void EmitLdfld(List<StackValue> stack, Field field, InstructionFlags instructionFlags) { var @object = stack.Pop(); ValueRef value; if (@object.StackType == StackValueType.Value) { value = LLVM.BuildExtractValue(builder, @object.Value, (uint)field.StructIndex, string.Empty); } else { var objectValue = ConvertReferenceToExpectedType(@object, field.DeclaringClass.Type); // Build indices for GEP var indices = BuildFieldIndices(field, @object.StackType, field.DeclaringClass.Type); // Find field address using GEP var fieldAddress = LLVM.BuildInBoundsGEP(builder, objectValue, indices, string.Empty); // Load value from field and create "fake" local value = LLVM.BuildLoad(builder, fieldAddress, string.Empty); // Set instruction flags SetInstructionFlags(value, instructionFlags); } // Convert from local to stack value value = ConvertFromLocalToStack(field.Type, value); // Add value to stack stack.Add(new StackValue(field.Type.StackType, field.Type, value)); }
private void EmitStfld(FunctionStack stack, Field field, InstructionFlags instructionFlags) { var value = stack.Pop(); var @object = stack.Pop(); // Compute field address var fieldAddress = ComputeFieldAddress(builder, field, @object.StackType, @object.Value, ref instructionFlags); // Convert stack value to appropriate type var fieldValue = ConvertFromStackToLocal(field.Type, value); // Store value in field StoreValue(field.Type.StackType, fieldValue, fieldAddress, instructionFlags); }
private void EmitLdobj(FunctionStack stack, Type type, InstructionFlags instructionFlags) { var address = stack.Pop(); // Load value at address var pointerCast = LLVM.BuildPointerCast(builder, address.Value, LLVM.PointerType(type.DefaultTypeLLVM, 0), string.Empty); var loadInst = LoadValue(type.StackType, pointerCast, instructionFlags); // Convert to stack type var value = ConvertFromLocalToStack(type, loadInst); // Add to stack stack.Add(new StackValue(type.StackType, type, value)); }