本文整理汇总了C#中Reko.UnitTests.Mocks.ProcedureBuilder类的典型用法代码示例。如果您正苦于以下问题:C# ProcedureBuilder类的具体用法?C# ProcedureBuilder怎么用?C# ProcedureBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProcedureBuilder类属于Reko.UnitTests.Mocks命名空间,在下文中一共展示了ProcedureBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例2: 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());
}
示例3: RunTest
private void RunTest(string sExp, Action<ProcedureBuilder> builder)
{
var pb = new ProcedureBuilder(this.pb.Program.Architecture);
builder(pb);
var proc = pb.Procedure;
var dg = new DominatorGraph<Block>(proc.ControlGraph, proc.EntryBlock);
// Perform the initial transformation
var ssa = new SsaTransform(programFlow, proc, dg);
// Propagate values and simplify the results.
// We hope the the sequence
// esp = fp - 4
// mov [esp-4],eax
// will become
// esp_2 = fp - 4
// mov [fp - 8],eax
var vp = new ValuePropagator(ssa.SsaState.Identifiers, proc);
vp.Transform();
ssa.RenameFrameAccesses = true;
ssa.AddUseInstructions = true;
ssa.Transform();
var writer = new StringWriter();
proc.Write(false, writer);
var sActual = writer.ToString();
if (sActual != sExp)
Debug.Print(sActual);
Assert.AreEqual(sExp, sActual);
}
示例4: Given_Procedure
private void Given_Procedure(uint address)
{
var m = new ProcedureBuilder("fnTest");
m.Return();
this.proc = m.Procedure;
this.program.Procedures[Address.Ptr32(address)] = this.proc;
}
示例5: OutpReplaceManyUses
public void OutpReplaceManyUses()
{
ProcedureBuilder m = new ProcedureBuilder();
Identifier foo = new Identifier("foo", PrimitiveType.Word32, null);
Identifier bar = new Identifier("bar", PrimitiveType.Word32, null);
Identifier pfoo = new Identifier("pfoo", PrimitiveType.Pointer32, null);
Block block = m.Label("block");
m.Assign(foo, 1);
Statement stmFoo = m.Block.Statements.Last;
m.Assign(bar, foo);
Statement stmBar = m.Block.Statements.Last;
SsaIdentifier ssaFoo = new SsaIdentifier(foo, foo, stmFoo, ((Assignment) stmFoo.Instruction).Src, false);
ssaFoo.Uses.Add(stmBar);
SsaIdentifier ssaBar = new SsaIdentifier(bar, bar, stmBar, ((Assignment) stmBar.Instruction).Src, false);
SsaIdentifierCollection ssaIds = new SsaIdentifierCollection();
ssaIds.Add(foo, ssaFoo);
ssaIds.Add(bar, ssaBar);
OutParameterTransformer opt = new OutParameterTransformer(m.Procedure, ssaIds);
opt.ReplaceDefinitionsWithOutParameter(foo, pfoo);
Assert.AreEqual(3, block.Statements.Count);
Assert.AreEqual("foo = 0x00000001", block.Statements[0].Instruction.ToString());
Assert.AreEqual("*pfoo = foo", block.Statements[1].Instruction.ToString());
Assert.AreEqual("bar = foo", block.Statements[2].Instruction.ToString());
}
示例6: Setup
public void Setup()
{
m = new ProcedureBuilder();
ssaState = new SsaState(m.Procedure, null);
ssaIds = ssaState.Identifiers;
freg = new FlagRegister("flags", 32, PrimitiveType.Word32);
}
示例7: 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();
}
示例8: FindPostDominators
private void FindPostDominators(ProcedureBuilder m)
{
ProcedureStructureBuilder graphs = new ProcedureStructureBuilder(m.Procedure);
h = graphs.Build();
sw = new StringWriter();
graphs.AnalyzeGraph().Write(sw);
}
示例9: Setup
public void Setup()
{
this.sc = new ServiceContainer();
this.x86 = new X86ArchitectureFlat32();
this.ppc = new PowerPcArchitecture32();
this.m = new ProcedureBuilder();
this.printfChr = new ProcedureCharacteristics()
{
VarargsParserClass =
"Reko.Libraries.Libc.PrintfFormatParser,Reko.Libraries.Libc"
};
this.x86PrintfSig = new FunctionType(
null,
StackId(null, 4, CStringType()),
StackId("...", 8, new UnknownType()));
this.x86SprintfSig = new FunctionType(
null,
StackId(null, 4, CStringType()),
StackId(null, 8, CStringType()),
StackId("...", 12, new UnknownType()));
this.ppcPrintfSig = new FunctionType(
null,
RegId(null, ppc, "r3", CStringType()),
RegId("...", ppc, "r4", new UnknownType()));
this.addrInstr = Address.Ptr32(0x123400);
}
示例10: RunTest
private void RunTest(string sExp, Action<ProcedureBuilder> builder)
{
var pb = new ProcedureBuilder(this.pb.Program.Architecture);
builder(pb);
var proc = pb.Procedure;
var dg = new DominatorGraph<Block>(proc.ControlGraph, proc.EntryBlock);
var project = new Project
{
Programs = { this.pb.Program }
};
var importResolver = new ImportResolver(
project,
this.pb.Program,
new FakeDecompilerEventListener());
var arch = new FakeArchitecture();
var platform = new FakePlatform(null, arch);
// Register r1 is assumed to always be implicit when calling
// another procedure.
var implicitRegs = new HashSet<RegisterStorage>
{
arch.GetRegister(1)
};
Debug.Print("GetRegister(1) {0}", arch.GetRegister(1));
this.pb.Program.Platform = platform;
this.pb.Program.Platform = new FakePlatform(null, new FakeArchitecture());
this.pb.Program.SegmentMap = new SegmentMap(
Address.Ptr32(0x0000),
new ImageSegment(
".text",
Address.Ptr32(0),
0x40000,
AccessMode.ReadWriteExecute));
// Perform the initial transformation
var ssa = new SsaTransform(programFlow, proc, importResolver, dg, implicitRegs);
// Propagate values and simplify the results.
// We hope the the sequence
// esp = fp - 4
// mov [esp-4],eax
// will become
// esp_2 = fp - 4
// mov [fp - 8],eax
var vp = new ValuePropagator(this.pb.Program.Architecture, ssa.SsaState);
vp.Transform();
ssa.RenameFrameAccesses = true;
ssa.AddUseInstructions = true;
ssa.Transform();
var writer = new StringWriter();
proc.Write(false, writer);
var sActual = writer.ToString();
if (sActual != sExp)
Debug.Print(sActual);
Assert.AreEqual(sExp, sActual);
}
示例11: 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));
}
示例12: Fstsw_Setup
public void Fstsw_Setup()
{
arch = new IntelArchitecture(ProcessorMode.Protected32);
asm = new X86Assembler(arch, Address.Ptr32(0x10000), new List<EntryPoint>());
Procedure proc = new Procedure("test", arch.CreateFrame());
orw = new OperandRewriter32(arch, proc.Frame, null);
emitter = new ProcedureBuilder();
}
示例13: 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");
}
示例14: RunTest
protected virtual void RunTest(ProcedureBuilder pm)
{
ProcedureStructureBuilder g = new ProcedureStructureBuilder(pm.Procedure);
g.BuildNodes();
g.DefineEdges();
proc = g.CreateProcedureStructure();
g.SetTimeStamps();
}
示例15: CompileTest
private void CompileTest(ProcedureBuilder mock)
{
proc = mock.Procedure;
StructureAnalysis sa = new StructureAnalysis(mock.Procedure);
sa.BuildProcedureStructure();
sa.FindStructures();
curProc = sa.ProcedureStructure;
}