本文整理汇总了C#中Reko.UnitTests.Mocks.ProcedureBuilder.Assign方法的典型用法代码示例。如果您正苦于以下问题:C# ProcedureBuilder.Assign方法的具体用法?C# ProcedureBuilder.Assign怎么用?C# ProcedureBuilder.Assign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reko.UnitTests.Mocks.ProcedureBuilder
的用法示例。
在下文中一共展示了ProcedureBuilder.Assign方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertSmallConst
private void AssertSmallConst(string sExp, int shift, uint mult)
{
var m = new ProcedureBuilder();
var c = Constant.Int32((int)mult);
var r1 = m.Reg32("r1", 1);
var r2 = m.Reg32("r2", 2);
var r2_r1 = m.Frame.EnsureSequence(r2.Storage, r1.Storage, PrimitiveType.Word64);
var ass = m.Assign(r2_r1, m.SMul(r1, c));
m.Emit(new AliasAssignment(r2, m.Slice(PrimitiveType.Word32, r2_r1, 32)));
if (shift != 0)
m.Assign(r2, m.Sar(r2, shift));
var proc = m.Procedure;
var ssa = new SsaTransform(
null,
proc,
null,
proc.CreateBlockDominatorGraph(),
new HashSet<RegisterStorage>()).Transform();
var ctx = new SsaEvaluationContext(null, ssa.Identifiers);
var rule = new ConstDivisionImplementedByMultiplication(ssa);
ctx.Statement = proc.EntryBlock.Succ[0].Statements[0];
Assert.IsTrue(rule.Match(ass));
ass = rule.TransformInstruction();
Assert.AreEqual(sExp, ass.Src.ToString());
}
示例2: WriteProcedure_Max
public void WriteProcedure_Max()
{
var m = new ProcedureBuilder("proc");
var r1 = m.Register("r1");
var r2 = m.Register("r2");
var r3 = m.Register("r3");
m.BranchIf(m.Gt(r1, r2), "greaterthan");
m.Assign(r3,r2);
m.Assign(r2, r1);
m.Assign(r1, r3);
m.Label("greaterthan");
m.Return(r1);
hcf.Write(m.Procedure);
var sExp = @"void proc()<br />
{<br />
proc_entry:<br />
<span class=""kw"">goto</span> l1<br />
greaterthan:<br />
<span class=""kw"">return</span> r1<br />
l1:<br />
<span class=""kw"">branch</span> r1 > r2 greaterthan<br />
l2:<br />
r3 = r2<br />
r2 = r1<br />
r1 = r3<br />
<span class=""kw"">goto</span> greaterthan<br />
proc_exit:<br />
}<br />
";
Debug.Write(sb.ToString());
Assert.AreEqual(sExp, sb.ToString());
}
示例3: BuildProgram
/// <summary>
/// Mutually recursive functions that jump into each other's bodies.
/// </summary>
/// <returns></returns>
public static Program BuildProgram()
{
var prog = new ProgramBuilder();
var m = new ProcedureBuilder("even");
var r1 = m.Register(1);
m.BranchIf(m.Eq0(r1), "done");
m.Assign(r1, m.ISub(r1, 1));
m.Call("odd", 4);
m.Assign(r1, m.Not(r1));
m.Return();
m.Label("done");
m.Assign(r1, true);
m.Return();
prog.Add(m);
m = new ProcedureBuilder("odd");
r1 = m.Register(1);
m.BranchIf(m.Eq(r1, 1), "done");
m.Assign(r1, m.ISub(r1, 1));
m.Call("event", 4);
m.Assign(r1, m.Not(r1));
m.Return();
m.Label("done");
m.Assign(r1, true);
m.Return();
prog.Add(m);
return prog.BuildProgram();
}
示例4: BuildScc
/// <summary>
/// Builds a strongly connected component corresponding to:
/// a1 = 0
/// a2 = phi(a1, a3)
/// while (a2 != 10)
/// {
/// a3 = a2 + 4
/// }
/// </summary>
private List<SsaIdentifier> BuildScc()
{
var m = new ProcedureBuilder("test");
Identifier a = new Identifier("a", PrimitiveType.Word32, null);
m.Label("b1");
m.Assign(a, Constant.Word32(0));
m.Label("b2");
m.Assign(a, m.IAdd(a, 4));
m.BranchIf(m.Ne(a, 10), "b2");
m.Label("b3");
m.Return();
this.dom = m.Procedure.CreateBlockDominatorGraph();
var ssa = new SsaTransform(
new ProgramDataFlow(),
m.Procedure,
null,
dom,
new HashSet<RegisterStorage>());
/*
proc = new Procedure("test", new Frame(PrimitiveType.Word32));
Block b1 = proc.AddBlock("b1");
Block b2 = proc.AddBlock("b2");
Identifier a2 = new Identifier("a2", PrimitiveType.Word32, null);
Identifier a3 = new Identifier("a3", PrimitiveType.Word32, null);
PhiFunction phi = new PhiFunction(a1.DataType, new Expression [] { a1, a3 });
Statement stm_a1 = new Statement(0, new Assignment(a1, Constant.Word32(0)), null);
Statement stm_a2 = new Statement(0, new PhiAssignment(a2, new PhiFunction(a1.DataType, a1, a3 )), null);
Statement stm_ex = new Statement(0, new Branch(new BinaryExpression(Operator.Ne, PrimitiveType.Bool, a2, Constant.Word32(10)), b2), null);
Statement stm_a3 = new Statement(0, new Assignment(a3, new BinaryExpression(Operator.IAdd, a3.DataType, a2, Constant.Word32(4))), null);
b1.Statements.Add(stm_a1);
b2.Statements.Add(stm_a2);
b2.Statements.Add(stm_a3);
SsaIdentifier sid_a1 = new SsaIdentifier(a1, a1, stm_a1, ((Assignment)stm_a1.Instruction).Src, false);
SsaIdentifier sid_a2 = new SsaIdentifier(a2, a2, stm_a2, ((PhiAssignment) stm_a2.Instruction).Src, false);
SsaIdentifier sid_a3 = new SsaIdentifier(a3, a3, stm_a3, ((Assignment) stm_a3.Instruction).Src, false);
sid_a1.Uses.Add(stm_a2);
ssaIds = new SsaIdentifierCollection();
ssaIds.Add(a1, sid_a1);
ssaIds.Add(a2, sid_a2);
ssaIds.Add(a3, sid_a3);
*/
ssaIds = ssa.SsaState.Identifiers;
List<SsaIdentifier> list = new List<SsaIdentifier> {
ssaIds.Where(i => i.Identifier.Name == "a_0").Single(),
ssaIds.Where(i => i.Identifier.Name == "a_1").Single(),
ssaIds.Where(i => i.Identifier.Name == "a_2").Single(),
};
return list;
}
示例5: Pdg_PostDominateIfElse
public void Pdg_PostDominateIfElse()
{
ProcedureBuilder m = new ProcedureBuilder();
m.BranchIf(m.Local32("a"), "then");
m.Assign(m.Local32("b"), m.Int32(0));
m.Jump("join");
m.Label("then");
m.Assign(m.Local32("c"), m.Int32(0));
m.Label("join");
m.Return();
FindPostDominators(m);
}
示例6: BuildSimpleLoop
private Procedure BuildSimpleLoop()
{
ProcedureBuilder m = new ProcedureBuilder();
Identifier p = m.Local32("p");
m.Assign(p, 0);
m.Label("loop");
m.BranchIf(m.Eq(p, 0x4000), "done");
m.Store(m.IAdd(p, 0x3000), m.Int32(0));
m.Assign(p, m.IAdd(p, 4));
m.Goto("loop");
m.Label("done");
m.Return();
return m.Procedure;
}
示例7: Test1
public void Test1()
{
var m = new ProcedureBuilder();
var id = m.Local32("id");
var x = m.Local32("x");
var stm = m.Assign(x, m.IAdd(m.SMul(id, 4), id));
}
示例8: DeadFnReturn
public void DeadFnReturn()
{
ProcedureBuilder m = new ProcedureBuilder("foo");
Identifier unused = m.Local32("unused");
m.Assign(unused, m.Fn("foo", Constant.Word32(1)));
m.Return();
RunTest(m, "Analysis/DeadFnReturn.txt");
}
示例9: SsaCallIndirect
public void SsaCallIndirect()
{
var m = new ProcedureBuilder("SsaCallIndirect");
var r1 = m.Reg32("r1");
var r2 = m.Reg32("r2");
m.Assign(r1, m.LoadDw(r2));
m.Call(r1, 4);
m.Return();
RunUnitTest(m, "Analysis/SsaCallIndirect.txt");
}
示例10: DpaConstantPointer
public void DpaConstantPointer()
{
ProgramBuilder prog = new ProgramBuilder();
ProcedureBuilder m = new ProcedureBuilder();
Identifier r1 = m.Register(1);
m.Assign(r1, 0x123130);
m.Store(r1, m.Int32(0x42));
prog.Add(m);
RunTest(prog.BuildProgram(), "Typing/DpaConstantPointer.txt");
}
示例11: DpaConstantMemberPointer
public void DpaConstantMemberPointer()
{
ProgramBuilder prog = new ProgramBuilder();
ProcedureBuilder m = new ProcedureBuilder();
Identifier ds = m.Local16("ds");
ds.DataType = PrimitiveType.SegmentSelector;
Identifier bx = m.Local16("bx");
m.Assign(bx, 0x1234);
m.Store(m.SegMemW(ds, bx), m.Int16(0x0042));
prog.Add(m);
RunTest(prog.BuildProgram(), "Typing/DpaConstantMemberPointer.txt");
}
示例12: OutpReplaceSimple
public void OutpReplaceSimple()
{
var m = new ProcedureBuilder();
m.Label("block");
var foo = new Identifier("foo", PrimitiveType.Word32, null);
var pfoo = new Identifier("pfoo", PrimitiveType.Pointer32, null);
m.Assign(foo, 3);
var sid = new SsaIdentifier(foo, foo, m.Block.Statements.Last, null, false);
var ssaIds = new SsaIdentifierCollection { { foo, sid } };
var opt = new OutParameterTransformer(null, ssaIds);
opt.ReplaceDefinitionsWithOutParameter(foo, pfoo);
Assert.AreEqual("*pfoo = 0x00000003", m.Block.Statements[0].ToString());
}
示例13: BlockCloner_CloneBlock
public void BlockCloner_CloneBlock()
{
var m = new ProcedureBuilder(arch, "fn1000");
var r1 = m.Register("r1");
var r2 = m.Register("r2");
var ass = m.Assign(r1, r2);
m.Return();
var block = m.Procedure.ControlGraph.Blocks[2];
m = new ProcedureBuilder(arch, "procCalling");
var blockCloner = new BlockCloner(block, m.Procedure, callgraph);
var blockNew = blockCloner.Execute();
var assNew = (Assignment) blockNew.Statements[0].Instruction;
Assert.AreNotSame(ass.Dst, assNew.Dst);
Assert.AreNotSame(ass.Src, assNew.Src);
}
示例14: TrcoCallFunctionWithArraySize
public void TrcoCallFunctionWithArraySize()
{
var m = new ProcedureBuilder();
var sig = new ProcedureSignature(null,
m.Frame.EnsureStackArgument(0, PrimitiveType.Word32));
var ex = new ExternalProcedure("malloc", sig, new ProcedureCharacteristics
{
Allocator = true,
ArraySize = new ArraySizeCharacteristic
{
Argument = "r",
Factors = new ArraySizeFactor[]
{
new ArraySizeFactor { Constant = "1" }
}
}
});
Identifier eax = m.Local32("eax");
var call = m.Assign(eax, m.Fn(new ProcedureConstant(PrimitiveType.Word32, ex), m.Word32(3)));
coll = CreateCollector();
call.Accept(eqb);
call.Accept(coll);
StringWriter sw = new StringWriter();
handler.Traits.Write(sw);
string sExp =
"T_1 (in malloc : word32)" + nl +
"\ttrait_func(T_4 -> T_5)" + nl +
"T_3 (in dwArg00 : word32)" + nl +
"\ttrait_primitive(word32)" + nl +
"T_4 (in 0x00000003 : word32)" + nl +
"\ttrait_primitive(word32)" + nl +
"\ttrait_equal(T_3)" + nl +
"T_5 (in malloc(0x00000003) : word32)" + nl +
"\ttrait_primitive(word32)";
Console.WriteLine(sw.ToString());
Assert.AreEqual(sExp, sw.ToString());
}
示例15: VpIndirectCall
public void VpIndirectCall()
{
var callee = CreateExternalProcedure("foo", RegArg(1, "r1"), StackArg(4), StackArg(8));
var pc = new ProcedureConstant(PrimitiveType.Pointer32, callee);
var m = new ProcedureBuilder();
var r1 = m.Reg32("r1", 1);
var sp = m.Frame.EnsureRegister(m.Architecture.StackRegister);
m.Assign(r1, pc);
m.Assign(sp, m.ISub(sp, 4));
m.Store(sp, 3);
m.Assign(sp, m.ISub(sp, 4));
m.Store(sp, m.LoadW(m.Word32(0x1231230)));
m.Call(r1, 4);
m.Return();
arch.Stub(a => a.CreateStackAccess(null, 0, null))
.IgnoreArguments()
.Do(new Func<Frame, int, DataType, Expression>((f, off, dt) => m.Load(dt, m.IAdd(sp, off))));
mr.ReplayAll();
var ssa = RunTest(m);
var sExp =
#region Expected
@"r1_0: orig: r1
def: r1_0 = foo
r63:r63
def: def r63
uses: r63_2 = r63 - 0x00000004
Mem3[r63 - 0x00000004:word32] = 0x00000003
r63_4 = r63 - 0x00000008
Mem5[r63 - 0x00000008:word16] = Mem3[0x01231230:word16]
r1_6 = foo(Mem8[r63 - 0x00000008:word32], Mem9[r63 - 0x00000004:word32])
r1_6 = foo(Mem8[r63 - 0x00000008:word32], Mem9[r63 - 0x00000004:word32])
r63_2: orig: r63
def: r63_2 = r63 - 0x00000004
Mem3: orig: Mem0
def: Mem3[r63 - 0x00000004:word32] = 0x00000003
uses: Mem5[r63 - 0x00000008:word16] = Mem3[0x01231230:word16]
r63_4: orig: r63
def: r63_4 = r63 - 0x00000008
Mem5: orig: Mem0
def: Mem5[r63 - 0x00000008:word16] = Mem3[0x01231230:word16]
r1_6: orig: r1
def: r1_6 = foo(Mem8[r63 - 0x00000008:word32], Mem9[r63 - 0x00000004:word32])
r63_7: orig: r63
Mem8: orig: Mem0
uses: r1_6 = foo(Mem8[r63 - 0x00000008:word32], Mem9[r63 - 0x00000004:word32])
Mem9: orig: Mem0
uses: r1_6 = foo(Mem8[r63 - 0x00000008:word32], Mem9[r63 - 0x00000004:word32])
// ProcedureBuilder
// Return size: 0
void ProcedureBuilder()
ProcedureBuilder_entry:
def r63
// succ: l1
l1:
r1_0 = foo
r63_2 = r63 - 0x00000004
Mem3[r63 - 0x00000004:word32] = 0x00000003
r63_4 = r63 - 0x00000008
Mem5[r63 - 0x00000008:word16] = Mem3[0x01231230:word16]
r1_6 = foo(Mem8[r63 - 0x00000008:word32], Mem9[r63 - 0x00000004:word32])
return
// succ: ProcedureBuilder_exit
ProcedureBuilder_exit:
";
#endregion
AssertStringsEqual(sExp, ssa);
}