本文整理汇总了C#中Reko.UnitTests.Mocks.ProgramBuilder.BuildProgram方法的典型用法代码示例。如果您正苦于以下问题:C# ProgramBuilder.BuildProgram方法的具体用法?C# ProgramBuilder.BuildProgram怎么用?C# ProgramBuilder.BuildProgram使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reko.UnitTests.Mocks.ProgramBuilder
的用法示例。
在下文中一共展示了ProgramBuilder.BuildProgram方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CrossJump
/// <summary>
/// This program has a cross procedural jump
/// that should result in a new procedure, at Real_entry,since the jumped-to code
/// is not a simple linear block but a branch.
/// </summary>
/// <returns></returns>
public static Program CrossJump()
{
var b = new ProgramBuilder();
b.Add("bob", m =>
{
var r1 = m.Reg32("r1", 1);
var r2 = m.Reg32("r2", 2);
m.Label("bob_1");
m.Assign(r1, 0);
// Fall through should be promoted to call/return pair.
m.Label("Real_entry"); // Cross jump target: should become a new function entry point.
m.Store(r2, r1);
m.BranchIf(r2, "Real_entry");
m.Return();
});
b.Add("ext", m =>
{
var r1 = m.Reg32("r1", 1);
m.Label("ext_1");
m.Assign(r1, 4);
m.Goto("Real_entry");
});
return b.BuildProgram();
}
示例2: Dfa2_CallProc
public void Dfa2_CallProc()
{
pb = new ProgramBuilder();
pb.Add("test", m =>
{
var sp = m.Register(m.Architecture.StackRegister);
var fooProc = GivenFunction("foo", m.Architecture.GetRegister(1), 4, 8);
m.Assign(sp, m.ISub(sp, 4));
m.Store(sp, 2);
m.Assign(sp, m.ISub(sp, 4));
m.Store(sp, 1);
m.Call(fooProc, 4);
m.Assign(sp, m.IAdd(sp, 8));
m.Return();
});
var dfa = new DataFlowAnalysis(pb.BuildProgram(), new FakeDecompilerEventListener());
dfa.UntangleProcedures2();
var sExp = @"// test
// Return size: 0
void test()
test_entry:
// succ: l1
l1:
Mem9[0x00010008:word32] = Mem0[fp + 0x00000004:word32] + Mem0[fp + 0x00000008:word32]
return
// succ: test_exit
test_exit:
";
AssertProgram(sExp, pb);
}
示例3: Dfa2_Simple
public void Dfa2_Simple()
{
var pb = new ProgramBuilder(new FakeArchitecture());
pb.Add("test", m=>
{
var r1 = m.Reg32("r1", 1);
var r2 = m.Reg32("r2", 2);
m.Assign(r1, m.LoadDw(m.Word32(0x010000)));
m.Assign(r2, m.LoadDw(m.Word32(0x010004)));
m.Store(m.Word32(0x010008), m.IAdd(r1, r2));
m.Return();
});
var dfa = new DataFlowAnalysis(pb.BuildProgram(), new FakeDecompilerEventListener());
dfa.AnalyzeProgram2();
var sExp = @"// test
// Return size: 0
void test()
test_entry:
// succ: l1
l1:
Mem3[0x00010008:word32] = Mem0[0x00010000:word32] + Mem0[0x00010004:word32]
return
// succ: test_exit
test_exit:
";
AssertProgram(sExp, pb.Program);
}
示例4: 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();
}
示例5: CompileTest
protected Program CompileTest(Action<ProcedureBuilder> m)
{
var mock = new ProcedureBuilder();
m(mock);
var pmock = new ProgramBuilder();
pmock.Add(mock);
return pmock.BuildProgram();
}
示例6: PprMemberVars
public void PprMemberVars()
{
ProgramBuilder mock = new ProgramBuilder();
ProcedureBuilder p = new ProcedureBuilder();
Identifier cs = p.Frame.EnsureRegister(Registers.cs);
p.Store(p.SegMemW(cs, p.Word32(0x0001)), Constant.Create(PrimitiveType.SegmentSelector, 0x0800));
mock.Add(p);
RunTest(mock.BuildProgram(), "Typing/PprMemberVars.txt");
}
示例7: PprMemberPointers
public void PprMemberPointers()
{
ProgramBuilder mock = new ProgramBuilder();
ProcedureBuilder m = new ProcedureBuilder();
Identifier ds = m.Local(PrimitiveType.SegmentSelector, "ds");
m.SegStore(ds, m.Word32(7000), m.SegMemW(ds, m.SegMemW(ds, m.Word32(0x5321))));
mock.Add(m);
RunTest(mock.BuildProgram(), "Typing/PprMemberPointers.txt");
}
示例8: Simple
//$TODO: translate to RtlTraces
/// <summary>
/// Simple program consisting of a single procedure.
/// </summary>
/// <returns></returns>
public Program Simple()
{
var b = new ProgramBuilder();
b.Add("bob", m =>
{
m.Label("Zlon");
m.Return();
});
return b.BuildProgram();
}
示例9: CpaSimple
public void CpaSimple()
{
var program = new ProgramBuilder();
program.Add("test", m=>
{
var r1 = m.Register(1);
m.Assign(r1, m.Load(PrimitiveType.Real32, m.Word32(0x10000000)));
});
RunTest(program.BuildProgram(), "Typing/CpaSimple.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: EP_TestCondition
public void EP_TestCondition()
{
var p = new ProgramBuilder();
p.Add("main", (m) =>
{
m.Label("foo");
m.BranchCc(ConditionCode.EQ, "foo");
m.Return();
});
var proc = p.BuildProgram().Procedures.Values.First();
var ctx = new SymbolicEvaluationContext(new IntelArchitecture(ProcessorMode.Protected32), proc.Frame);
var simplifier = new ExpressionSimplifier(ctx);
var ep = new ExpressionPropagator(null, simplifier, ctx, new ProgramDataFlow());
var newInstr = proc.EntryBlock.Succ[0].Statements[0].Instruction.Accept(ep);
Assert.AreEqual("branch Test(EQ,Z) foo", newInstr.ToString());
}
示例13: BuildSample
public static Program BuildSample()
{
var pb = new ProgramBuilder();
pb.Add("fact", m =>
{
var sp = m.Register(m.Architecture.StackRegister);
var r1 = m.Register(1);
var r2 = m.Register(2);
var r3 = m.Register(3);
var cc = m.Flags("cc");
m.Assign(sp, m.Frame.FramePointer);
m.Assign(r2, r1);
m.Assign(r1, 1);
m.Assign(cc, m.Cond(m.ISub(r2, r1)));
m.BranchIf(m.Test(ConditionCode.LE, cc), "m_done");
m.Assign(sp, m.ISub(sp, 4));
m.Store(sp, r2);
m.Assign(r1, m.ISub(r2, r1));
m.Call("fact", 0);
m.Assign(r2, m.LoadDw(sp));
m.Assign(sp, m.IAdd(sp, 4));
m.Assign(r1, m.IMul(r1, r2));
m.Label("m_done");
m.Return();
});
pb.Add("main", m =>
{
var r1 = m.Register(1);
m.Assign(r1, 10);
m.Call("fact", 0);
m.Store(m.Word32(0x400000), r1);
});
return pb.BuildProgram();
}
示例14: TerCallTable
public void TerCallTable()
{
var pb = new ProgramBuilder();
pb.Add(new IndirectCallFragment());
RunTest(pb.BuildProgram(), "Typing/TerCallTable.txt");
}
示例15: TerIntelIndexedAddressingMode
public void TerIntelIndexedAddressingMode()
{
ProgramBuilder m = new ProgramBuilder();
m.Add(new IntelIndexedAddressingMode());
RunTest(m.BuildProgram(), "Typing/TerIntelIndexedAddressingMode.txt");
}