private Identifier DeserializeArgument(ArgumentSerializer argser, Argument_v1 sArg) { Identifier arg; if (sArg.Kind != null) return sArg.Kind.Accept(argser); var dtArg = sArg.Type.Accept(TypeLoader); var prim = dtArg as PrimitiveType; //if (prim != null && prim.Domain == Domain.Real) //{ // if (this.fr > 8) // { // arg = argser.Deserialize(sArg, new StackVariable_v1()); // } // else // { // arg = argser.Deserialize(sArg, new Register_v1("f" + this.fr)); // ++this.fr; // } // return arg; //} if (dtArg.Size <= 4) { if (this.gr > 3) { arg = argser.Deserialize(sArg, new StackVariable_v1()); } else { arg = argser.Deserialize(sArg, new Register_v1("r" + gr)); ++this.gr; } return arg; } if (dtArg.Size <= 8) { if (this.gr > 9) { arg = argser.Deserialize(sArg, new StackVariable_v1()); } else { if ((gr & 1) == 0) ++gr; arg = argser.Deserialize(sArg, new SerializedSequence { Registers = new Register_v1[] { new Register_v1("r" + gr), new Register_v1("r" + (gr+1)) } }); gr += 2; } return arg; } throw new NotImplementedException(); }
public void SargWriteNamelessRegisterArgument() { Argument_v1 sarg = new Argument_v1 { Type = new SerializedTypeReference("int"), Kind = new Register_v1("eax"), }; Verify(sarg, "Core/SargWriteNamelessRegisterArgument.txt"); }
public void SargWriteStackArgument() { Argument_v1 sarg = new Argument_v1 { Name = "bar", Type = new SerializedTypeReference("int"), Kind = new StackVariable_v1() }; Verify(sarg, "Core/SargWriteStackArgument.txt"); }
public void ArgSer_DeserializeRegister() { Register_v1 reg = new Register_v1("eax"); Argument_v1 arg = new Argument_v1 { Name = "eax", Kind = reg, }; Identifier id = argser.Deserialize(arg); Assert.AreEqual("eax", id.Name); Assert.AreEqual(32, id.DataType.BitSize); }
public void SseqBuildSequence() { Frame f = arch.CreateFrame(); Identifier head = f.EnsureRegister(Registers.dx); Identifier tail = f.EnsureRegister(Registers.ax); Identifier seq = f.EnsureSequence(head, tail, PrimitiveType.Word32); SerializedSequence sq = new SerializedSequence((SequenceStorage) seq.Storage); Argument_v1 sa = new Argument_v1(); sa.Kind = sq; SerializedSignature ssig = new SerializedSignature(); ssig.Arguments = new Argument_v1[] { sa }; Given_X86ProcedureSerializer(); ProcedureSignature ps = ser.Deserialize(ssig, f); Assert.AreEqual("void foo(Sequence word32 dx_ax)", ps.ToString("foo")); }
public Identifier DeserializeArgument(Argument_v1 arg, int idx, string convention) { if (arg.Kind != null) { return argser.Deserialize(arg, arg.Kind); } if (convention == null) return argser.Deserialize(arg, new StackVariable_v1()); switch (convention) { case "": case "stdapi": case "__cdecl": case "__stdcall": return argser.Deserialize(arg, new StackVariable_v1 { }); case "__thiscall": if (idx == 0) return argser.Deserialize(arg, new Register_v1("ecx")); else return argser.Deserialize(arg, new StackVariable_v1()); } throw new NotSupportedException(string.Format("Unsupported calling convention '{0}'.", convention)); }
public static SerializedSignature BuildSsigAxBxCl() { SerializedSignature ssig = new SerializedSignature(); Argument_v1 sarg = new Argument_v1(); sarg.Type = new PrimitiveType_v1(Domain.SignedInt, 2); sarg.Kind = new Register_v1("ax"); ssig.ReturnValue = sarg; ssig.Arguments = new Argument_v1[] { new Argument_v1 { Kind = new Register_v1("bx") }, new Argument_v1 { Kind = new Register_v1("cl") }, }; return ssig; }
public abstract Storage GetReturnRegister(Argument_v1 sArg, int bitSize);
public override Storage GetReturnRegister(Argument_v1 sArg, int bitSize) { switch (bitSize) { case 32: if (Architecture.WordWidth.BitSize == 16) return new SequenceStorage( new Identifier("dx", PrimitiveType.Word16, Architecture.GetRegister("dx")), new Identifier("ax", PrimitiveType.Word16, Architecture.GetRegister("ax"))); break; case 64: if (Architecture.WordWidth.BitSize == 32) return new SequenceStorage( new Identifier("edx", PrimitiveType.Word16, Architecture.GetRegister("edx")), new Identifier("eax", PrimitiveType.Word16, Architecture.GetRegister("eax"))); break; } return Architecture.GetRegister("rax").GetSubregister(0, bitSize); }
public void ArgSet_DerserializeReturnRegisterWithType() { var arg = new Argument_v1 { Kind = new Register_v1("eax"), Type = new PointerType_v1 { DataType = new PrimitiveType_v1 { ByteSize = 1, Domain = Domain.Character } } }; var id = argser.DeserializeReturnValue(arg); Assert.AreEqual("(ptr char)", id.DataType.ToString()); }
private Argument_v1 ParseArg() { var w = GetNextWord(); if (w == null) return null; RegisterStorage reg; string type = null; if (!arch.TryGetRegister(w, out reg)) { type = w; w = GetNextWord(); if (w == null) return null; if (w.Contains("_")) { var retval = ParseRegisterSequenceWithUnderscore(w); if (retval != null) return retval; } if (!arch.TryGetRegister(w, out reg)) { return ParseStackArgument(type, w); } } if (PeekChar(':') || PeekChar('_')) { return ParseRegisterSequence(reg, type); } var arg = new Argument_v1() { Name = reg.Name, Kind = new Register_v1(reg.Name), OutParameter = false, Type = new SerializedTypeReference { TypeName = type }, }; return arg; }
public void SsigDeserializeOutArgument() { Argument_v1 arg = new Argument_v1 { Kind = new Register_v1("bp"), OutParameter = true }; SerializedSignature sig = new SerializedSignature(); sig.Arguments = new Argument_v1[] { arg }; Given_X86ProcedureSerializer(); ProcedureSignature ps = sser.Deserialize(sig, arch.CreateFrame()); Assert.AreEqual("void foo(Register out ptr16 bpOut)", ps.ToString("foo")); }
public override Storage GetReturnRegister(Argument_v1 sArg, int bitSize) { var prim = sArg.Type as PrimitiveType_v1; if (prim != null) { if (prim.Domain == Domain.Real) return arch.GetRegister("f1"); } return arch.GetRegister(3); }
public override Storage GetReturnRegister(Argument_v1 sArg, int bitSize) { return A32Registers.r0; }
private void Verify(Argument_v1 sarg, string outputFilename) { using (FileUnitTester fut = new FileUnitTester(outputFilename)) { XmlTextWriter x = new FilteringXmlWriter(fut.TextWriter); x.Formatting = Formatting.Indented; XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(sarg.GetType()); ser.Serialize(x, sarg); fut.AssertFilesEqual(); } }
public Identifier Deserialize(Argument_v1 arg, SerializedKind kind) { argCur = arg; return kind.Accept(this); }
public Identifier Deserialize(Argument_v1 arg) { argCur = arg; return arg.Kind.Accept(this); }
public Identifier DeserializeReturnValue(Argument_v1 arg) { argCur = arg; DataType dt = null; if (this.argCur.Type != null) dt = this.argCur.Type.Accept(procSer.TypeLoader); if (dt is VoidType) return null; Identifier id; if (arg.Kind != null) { id = arg.Kind.Accept(this); id.DataType = dt ?? id.DataType; } else { var reg = procSer.GetReturnRegister(arg, dt.BitSize); id = new Identifier(reg.ToString() + "@<>", dt, reg); } return id; }
private Argument_v1 ParseStackArgument(string typeName, string argName) { PrimitiveType p; int sizeInWords; int wordSize = arch.WordWidth.Size; if (PrimitiveType.TryParse(typeName, out p)) { sizeInWords = (p.Size + (wordSize - 1))/wordSize; } else { sizeInWords = 1; // A reasonable guess, but is it a good one? } Argument_v1 arg = new Argument_v1(); arg.Name = argName; arg.Type = new SerializedTypeReference { TypeName = typeName }; arg.Kind = new StackVariable_v1(); // (sizeInWords * wordSize); return arg; }
private AmigaSystemFunction ParseLine(string line) { lex = new Lexer(line); if (!PeekAndDiscard(TokenType.HASH)) return null; Expect(TokenType.Number); // Ordinal var decOffset = (int) Expect(TokenType.Number); // offset (in decimal) var hexOffset = (int) Expect(TokenType.Number); // offset (in hex) if (decOffset != hexOffset) throw new InvalidOperationException(string.Format( "Decimal offset {0} and hexadecimal offset {1:X} do not match.", decOffset, hexOffset)); var name = (string) Expect(TokenType.Id); // fn name var parameters = new List<Argument_v1>(); Argument_v1 returnValue = null; Expect(TokenType.LPAREN); if (!PeekAndDiscard(TokenType.RPAREN)) { do { var argName = (string) Expect(TokenType.Id); Expect(TokenType.SLASH); var regName = (string)Expect(TokenType.Id); parameters.Add(new Argument_v1 { Kind = new Register_v1 { Name = regName }, Name = argName, }); } while (PeekAndDiscard(TokenType.COMMA)); if (PeekAndDiscard(TokenType.SEMI)) { var argName = (string) Expect(TokenType.Id); Expect(TokenType.SLASH); var regName = (string) Expect(TokenType.Id); returnValue = new Argument_v1 { Kind = new Register_v1 { Name = regName } }; } Expect(TokenType.RPAREN); } return new AmigaSystemFunction { Offset = -decOffset, Name = name, Signature = new SerializedSignature { Arguments = parameters.ToArray(), ReturnValue = returnValue, } }; }
public Argument_v1 Serialize(Identifier arg) { if (arg == null) return null; if (arg.DataType == null) throw new ArgumentNullException("arg.DataType"); Argument_v1 sarg = new Argument_v1 { Name = arg.Name, Kind = arg.Storage.Serialize(), OutParameter = arg.Storage is OutArgumentStorage, Type = arg.DataType.Accept(new DataTypeSerializer()), }; return sarg; }
public void SargWriteOutArgument() { Argument_v1 sarg = new Argument_v1 { Name = "bxOut", Type = new SerializedTypeReference("int"), OutParameter = true, Kind = new Register_v1("bx") }; Verify(sarg, "Core/SargWriteOutArgument.txt"); }