public void DtbBuildEqClassDataTypes() { TypeVariable tv1 = store.CreateTypeVariable(factory); tv1.OriginalDataType = PrimitiveType.Word32; TypeVariable tv2 = store.CreateTypeVariable(factory); tv2.OriginalDataType = PrimitiveType.Real32; store.MergeClasses(tv1, tv2); dtb.BuildEquivalenceClassDataTypes(); Assert.AreEqual(PrimitiveType.Real32, tv1.Class.DataType); }
/// <summary> /// Assert that there is an array field at offset <paramref name="offset"/> /// of the structure pointed at by <paramref name="expStruct"/>. /// </summary> /// <param name="expBase"></param> /// <param name="expStruct"></param> /// <param name="structPtrSize"></param> /// <param name="offset"></param> /// <param name="elementSize"></param> /// <param name="length"></param> /// <param name="tvField"></param> /// <returns>A type variable for the array type of the field.</returns> private TypeVariable ArrayField(Expression expBase, Expression expStruct, int structPtrSize, int offset, int elementSize, int length, TypeVariable tvField) { var dtElement = factory.CreateStructureType(null, elementSize); dtElement.Fields.Add(0, tvField); var tvElement = store.CreateTypeVariable(factory); tvElement.DataType = dtElement; tvElement.OriginalDataType = dtElement; DataType dtArray = factory.CreateArrayType(tvElement, length); MemoryAccessCommon(expBase, expStruct, offset, dtArray, structPtrSize); return(tvElement); }
public void ExdSeqWithSelector() { RunTest( m.Seq( Id("ds", PrimitiveType.SegmentSelector), Constant.Word16(4)), PointerTo(store.CreateTypeVariable(factory))); }
public void Setup() { program = new Program(); program.Architecture = new FakeArchitecture(new ServiceContainer()); program.Platform = new DefaultPlatform(program.Architecture.Services, program.Architecture); store = program.TypeStore; factory = program.TypeFactory; globals = program.Globals; StructureType point = new StructureType("Point", 0) { Fields = { { 0, PrimitiveType.Word32, null }, { 4, PrimitiveType.Word32, null } } }; TypeVariable tvPoint = store.CreateTypeVariable(factory); EquivalenceClass eq = new EquivalenceClass(tvPoint) { DataType = point }; tvPoint.DataType = eq; ptrPoint = new Pointer(eq, 32); UnionType u = new UnionType("RealInt", null) { Alternatives = { new UnionAlternative("w", PrimitiveType.Word32, 0), new UnionAlternative("r", PrimitiveType.Real32, 1), } }; TypeVariable tvUnion = store.CreateTypeVariable(factory); eq = new EquivalenceClass(tvUnion) { DataType = u }; tvUnion.DataType = eq; ptrUnion = new Pointer(eq, 32); ptrInt = new Pointer(PrimitiveType.Int32, 32); ptrWord = new Pointer(PrimitiveType.Word32, 32); m = new ExpressionEmitter(); }
public void TystCopyClassToTypes() { TypeVariable tv1 = store.CreateTypeVariable(factory); TypeVariable tv2 = store.CreateTypeVariable(factory); Assert.IsNotNull(tv1.Class, "Expected store.EnsureTypeVariable to create an equivalence class"); Assert.IsNotNull(tv2.Class, "Expected store.EnsureTypeVariable to create an equivalence class"); EquivalenceClass e = store.MergeClasses(tv1, tv2); e.DataType = PrimitiveType.Word16; store.CopyClassDataTypesToTypeVariables(); foreach (TypeVariable tv in store.TypeVariables) { Assert.IsNotNull(tv.DataType); } }
private void CreateSegmentTypeVariable(ImageSegment seg) { var store = new TypeStore(); var factory = new TypeFactory(); seg.Identifier.TypeVariable = store.CreateTypeVariable(factory); seg.Identifier.TypeVariable.Class.DataType = seg.Fields; }
public EquivalenceClass CreateEquivalenceClass(DataType dt) { TypeVariable tv = store.CreateTypeVariable(factory); tv.Class.DataType = dt; tv.DataType = tv.Class; return(tv.Class); }
private void Given_Program(StructureFieldCollection globalVariables) { this.program = pb.BuildProgram(); program.Globals.TypeVariable = store.CreateTypeVariable(factory); var globalStructure = new StructureType(); globalStructure.Fields.AddRange(globalVariables); program.Globals.TypeVariable.Class.DataType = globalStructure; }
public void Setup() { store = new TypeStore(); factory = new TypeFactory(); globals = new Identifier("globals", PrimitiveType.Word32, null); StructureType point = new StructureType("Point", 0) { Fields = { { 0, PrimitiveType.Word32, null }, { 4, PrimitiveType.Word32, null } } }; TypeVariable tvPoint = store.CreateTypeVariable(factory); EquivalenceClass eq = new EquivalenceClass(tvPoint) { DataType = point }; tvPoint.DataType = eq; ptrPoint = new Pointer(eq, 32); UnionType u = new UnionType("RealInt", null) { Alternatives = { new UnionAlternative("w", PrimitiveType.Word32, 0), new UnionAlternative("r", PrimitiveType.Real32, 1), } }; TypeVariable tvUnion = store.CreateTypeVariable(factory); eq = new EquivalenceClass(tvUnion) { DataType = u }; tvUnion.DataType = eq; ptrUnion = new Pointer(eq, 32); ptrInt = new Pointer(PrimitiveType.Int32, 32); ptrWord = new Pointer(PrimitiveType.Word32, 32); m = new ExpressionEmitter(); }
public void ArrayOfStructures() { StructureType s = new StructureType(); s.Fields.Add(0, PrimitiveType.Word32); s.Fields.Add(4, PrimitiveType.Real64); ArrayType a = new ArrayType(s, 0); TypeVariable tv = store.CreateTypeVariable(factory); tv.Class.DataType = a; Assert.AreEqual(1, store.UsedEquivalenceClasses.Count); tv.Class.DataType.Accept(nct); Assert.AreEqual(2, store.UsedEquivalenceClasses.Count); Assert.AreEqual("(arr Eq_2)", store.UsedEquivalenceClasses[0].DataType.ToString()); Assert.AreEqual("(struct (0 word32 dw0000) (4 real64 r0004))", store.UsedEquivalenceClasses[1].DataType.ToString()); }
public void PprReplaceInts() { var arch = new FakeArchitecture(); var program = new Program { Architecture = arch, Platform = new DefaultPlatform(null, arch) }; TypeFactory factory = new TypeFactory(); store = new TypeStore(); TypeVariable tv1 = store.CreateTypeVariable(factory); TypeVariable tv2 = store.CreateTypeVariable(factory); Assert.IsNotNull(tv1.Class, "Expected store.EnsureTypeVariable to create equivalence class"); Assert.IsNotNull(tv2.Class, "Expected store.EnsureTypeVariable to create equivalence class"); tv1.Class.DataType = PrimitiveType.Word32; tv2.Class.DataType = PrimitiveType.Word16; program.Globals.TypeVariable = store.CreateTypeVariable(factory); program.Globals.DataType = factory.CreateStructureType(); TypeVariable tv3 = store.CreateTypeVariable(factory); Assert.IsNotNull(tv3.Class, "Expected store.EnsureTypeVariable to create equivalence class"); StructureType mem = factory.CreateStructureType(null, 0); mem.Fields.Add(0, tv1); mem.Fields.Add(4, tv2); tv3.Class.DataType = factory.CreatePointer(mem, 4); store.CopyClassDataTypesToTypeVariables(); TypeVariableReplacer tvr = new TypeVariableReplacer(store); tvr.ReplaceTypeVariables(); var ppr = new PtrPrimitiveReplacer(factory, store, program); ppr.ReplaceAll(); Verify(null, "Typing/PprReplaceInts.txt"); }
public void NameStructure() { var store = new TypeStore(); var factory = new TypeFactory(); var tv1 = store.CreateTypeVariable(factory); tv1.Class.DataType = new StructureType(null, 0); tv1.DataType = tv1.Class.DataType; var ctn = new ComplexTypeNamer(); ctn.RenameAllTypes(store); Assert.AreEqual("Eq_1", tv1.Class.DataType.Name); }
/// <subject> /// Make sure fields are present for all the image symbols. /// </subject> public void CollectImageSymbols() { foreach (var sym in program.ImageSymbols.Values) { if (sym != null && sym.DataType != null && sym.Address != null && sym.Type == SymbolType.Data && !(sym.DataType is UnknownType)) { DataType dtField; if (sym.DataType.IsWord) { var tvField = store.CreateTypeVariable(factory); tvField.OriginalDataType = sym.DataType; tvField.DataType = sym.DataType; dtField = tvField; } else { dtField = sym.DataType; } AddGlobalField(dtField, sym.Address, sym.Name); } } }