本文整理汇总了C++中Prog类的典型用法代码示例。如果您正苦于以下问题:C++ Prog类的具体用法?C++ Prog怎么用?C++ Prog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Prog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
fprintf(stderr, "Syntakticky analyzator\n");
if (argc == 1) {
fprintf(stderr, "Vstup z klavesnice, zadejte zdrojovy text\n");
jmeno = NULL;
} else {
jmeno = argv[1];
fprintf(stderr, "Vstupni soubor %s\n", jmeno);
}
InitLexan(jmeno);
CtiSymb();
Prog *prog = Program();
prog->printNode();
fprintf(stderr, "\n\n");
if (argc > 2) {
if (strncmp(argv[2], "-O", 2) == 0) {
prog = (Prog*)(prog->Optimize());
}
}
fprintf(stderr, "\nlast version:\n");
prog->printNode();
fprintf(stderr, "\n\n");
prog->Translate();
}
示例2: CPPUNIT_ASSERT
/*==============================================================================
* FUNCTION: CfgTest::testRenameVars
* OVERVIEW: Test the renaming of variables
*============================================================================*/
void CfgTest::testRenameVars ()
{
BinaryFileFactory bff;
BinaryFile* pBF = bff.Load(FRONTIER_PENTIUM);
CPPUNIT_ASSERT(pBF != 0);
Prog* prog = new Prog;
FrontEnd* pFE = new PentiumFrontEnd(pBF, prog, &bff);
Type::clearNamedTypes();
prog->setFrontEnd(pFE);
pFE->decode(prog);
UserProc* pProc = (UserProc*) prog->getProc(0);
Cfg* cfg = pProc->getCFG();
DataFlow* df = pProc->getDataFlow();
// Simplify expressions (e.g. m[ebp + -8] -> m[ebp - 8]
prog->finishDecode();
df->dominators(cfg);
df->placePhiFunctions(pProc);
pProc->numberStatements(); // After placing phi functions!
df->renameBlockVars(pProc, 0, 1); // Block 0, mem depth 1
// MIKE: something missing here?
delete pFE;
}
示例3: Prog
/*==============================================================================
* FUNCTION: ProcTest::testName
* OVERVIEW: Test setting and reading name, constructor, native address
*============================================================================*/
void ProcTest::testName ()
{
Prog* prog = new Prog();
BinaryFile *pBF = new BinaryFileStub();
CPPUNIT_ASSERT(pBF != 0);
std::string nm("default name");
BinaryFileFactory bff;
pBF = bff.Load(HELLO_PENTIUM);
FrontEnd *pFE = new PentiumFrontEnd(pBF, prog, &bff);
CPPUNIT_ASSERT(pFE != 0);
prog->setFrontEnd(pFE);
CPPUNIT_ASSERT(prog);
pFE->readLibraryCatalog(); // Since we are not decoding
m_proc = new UserProc(prog, nm, 20000); // Will print in decimal if error
std::string actual(m_proc->getName());
CPPUNIT_ASSERT_EQUAL(std::string("default name"), actual);
std::string name("printf");
LibProc lp(prog, name, 30000);
actual = lp.getName();
CPPUNIT_ASSERT_EQUAL(name, actual);
ADDRESS a = lp.getNativeAddress();
ADDRESS expected = 30000;
CPPUNIT_ASSERT_EQUAL(expected, a);
a = m_proc->getNativeAddress();
expected = 20000;
CPPUNIT_ASSERT_EQUAL(expected, a);
delete prog;
delete m_proc;
// delete pFE; // No! Deleting the prog deletes the pFE already (which deletes the BinaryFileFactory)
}
示例4: Prog
Prog* Parser::prog(){
Prog* myProg = new Prog();
myProg->addNode(decls());
if (!error) {
myProg->addNode(statements());
}
return myProg;
}
示例5: CPPUNIT_ASSERT
/*==============================================================================
* FUNCTION: RtlTest::testIsCompare
* OVERVIEW: Test the isCompare function
*============================================================================*/
void RtlTest::testIsCompare ()
{
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(SWITCH_SPARC);
CPPUNIT_ASSERT(pBF != 0);
CPPUNIT_ASSERT(pBF->GetMachine() == MACHINE_SPARC);
Prog* prog = new Prog;
FrontEnd *pFE = new SparcFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
// Decode second instruction: "sub %i0, 2, %o1"
int iReg;
Exp* eOperand = NULL;
DecodeResult inst = pFE->decodeInstruction(0x10910);
CPPUNIT_ASSERT(inst.rtl != NULL);
CPPUNIT_ASSERT(inst.rtl->isCompare(iReg, eOperand) == false);
// Decode fifth instruction: "cmp %o1, 5"
inst = pFE->decodeInstruction(0x1091c);
CPPUNIT_ASSERT(inst.rtl != NULL);
CPPUNIT_ASSERT(inst.rtl->isCompare(iReg, eOperand) == true);
CPPUNIT_ASSERT_EQUAL(9, iReg);
std::string expected("5");
std::ostringstream ost1;
eOperand->print(ost1);
std::string actual(ost1.str());
CPPUNIT_ASSERT_EQUAL(expected, actual);
pBF->UnLoad();
delete pBF;
delete pFE;
pBF = bff.Load(SWITCH_PENT);
CPPUNIT_ASSERT(pBF != 0);
CPPUNIT_ASSERT(pBF->GetMachine() == MACHINE_PENTIUM);
pFE = new PentiumFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
// Decode fifth instruction: "cmp $0x5,%eax"
inst = pFE->decodeInstruction(0x80488fb);
CPPUNIT_ASSERT(inst.rtl != NULL);
CPPUNIT_ASSERT(inst.rtl->isCompare(iReg, eOperand) == true);
CPPUNIT_ASSERT_EQUAL(24, iReg);
std::ostringstream ost2;
eOperand->print(ost2);
actual = ost2.str();
CPPUNIT_ASSERT_EQUAL(expected, actual);
// Decode instruction: "add $0x4,%esp"
inst = pFE->decodeInstruction(0x804890c);
CPPUNIT_ASSERT(inst.rtl != NULL);
CPPUNIT_ASSERT(inst.rtl->isCompare(iReg, eOperand) == false);
pBF->UnLoad();
delete pFE;
}
示例6: find_prog
samplv1_programs::Prog *samplv1_programs::Bank::add_prog (
uint16_t prog_id, const QString& prog_name )
{
Prog *prog = find_prog(prog_id);
if (prog) {
prog->set_name(prog_name);
} else {
prog = new Prog(prog_id, prog_name);
m_progs.insert(prog_id, prog);
}
return prog;
}
示例7: Prog
/*==============================================================================
* FUNCTION: ProgTest::testName
* OVERVIEW: Test setting and reading name
*============================================================================*/
void ProgTest::testName ()
{
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(HELLO_PENTIUM); // Don't actually use it
Prog* prog = new Prog();
FrontEnd *pFE = new PentiumFrontEnd(pBF, prog, &bff);
// We need a Prog object with a pBF (for getEarlyParamExp())
prog->setFrontEnd(pFE);
std::string actual(prog->getName());
std::string expected(HELLO_PENTIUM);
CPPUNIT_ASSERT_EQUAL(expected, actual);
std::string name("Happy prog");
prog->setName(name.c_str());
actual = prog->getName();
CPPUNIT_ASSERT_EQUAL(name, actual);
delete pFE;
}
示例8: BinaryFileStub
/*==============================================================================
* FUNCTION: FrontPentTest::test1
* OVERVIEW: Test decoding some pentium instructions
*============================================================================*/
void FrontPentTest::test1 ()
{
std::ostringstream ost;
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(HELLO_PENT);
if (pBF == NULL)
pBF = new BinaryFileStub();
CPPUNIT_ASSERT(pBF != 0);
CPPUNIT_ASSERT(pBF->GetMachine() == MACHINE_PENTIUM);
Prog* prog = new Prog;
FrontEnd *pFE = new PentiumFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
bool gotMain;
ADDRESS addr = pFE->getMainEntryPoint(gotMain);
CPPUNIT_ASSERT (addr != NO_ADDRESS);
// Decode first instruction
DecodeResult inst = pFE->decodeInstruction(addr);
inst.rtl->print(ost);
std::string expected(
"08048328 0 *32* m[r28 - 4] := r29\n"
" 0 *32* r28 := r28 - 4\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(ost.str()));
std::ostringstream o2;
addr += inst.numBytes;
inst = pFE->decodeInstruction(addr);
inst.rtl->print(o2);
expected = std::string("08048329 0 *32* r29 := r28\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o2.str()));
std::ostringstream o3;
addr = 0x804833b;
inst = pFE->decodeInstruction(addr);
inst.rtl->print(o3);
expected = std::string(
"0804833b 0 *32* m[r28 - 4] := 0x80483fc\n"
" 0 *32* r28 := r28 - 4\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o3.str()));
delete pFE;
// delete pBF;
}
示例9: BinaryFileStub
void FrontSparcTest::test2() {
DecodeResult inst;
std::string expected;
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(HELLO_SPARC);
if (pBF == NULL)
pBF = new BinaryFileStub(); // fallback on stub
CPPUNIT_ASSERT(pBF != 0);
CPPUNIT_ASSERT(pBF->GetMachine() == MACHINE_SPARC);
Prog* prog = new Prog;
FrontEnd *pFE = new SparcFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
std::ostringstream o1;
inst = pFE->decodeInstruction(0x10690);
inst.rtl->print(o1);
// This call is to out of range of the program's text limits (to the Program Linkage Table (PLT), calling printf)
// This is quite normal.
expected = std::string("00010690 0 CALL printf(\n"
" )\n"
" Reaching definitions: \n"
" Live variables: \n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o1.str()));
std::ostringstream o2;
inst = pFE->decodeInstruction(0x10694);
inst.rtl->print(o2);
expected = std::string("00010694\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o2.str()));
std::ostringstream o3;
inst = pFE->decodeInstruction(0x10698);
inst.rtl->print(o3);
expected = std::string("00010698 0 *32* r8 := 0\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o3.str()));
std::ostringstream o4;
inst = pFE->decodeInstruction(0x1069c);
inst.rtl->print(o4);
expected = std::string("0001069c 0 *32* r24 := r8\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o4.str()));
delete pFE;
// delete pBF;
}
示例10: CPPUNIT_ASSERT
void FrontPentTest::testFindMain()
{
// Test the algorithm for finding main, when there is a call to __libc_start_main
// Also tests the loader hack
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(FEDORA2_TRUE);
CPPUNIT_ASSERT(pBF != NULL);
Prog *prog = new Prog;
FrontEnd *pFE = new PentiumFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
CPPUNIT_ASSERT(pFE != NULL);
bool found;
ADDRESS addr = pFE->getMainEntryPoint(found);
ADDRESS expected = 0x8048b10;
CPPUNIT_ASSERT_EQUAL(expected, addr);
pBF->Close();
bff.UnLoad();
pBF = bff.Load(FEDORA3_TRUE);
CPPUNIT_ASSERT(pBF != NULL);
pFE = new PentiumFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
CPPUNIT_ASSERT(pFE != NULL);
addr = pFE->getMainEntryPoint(found);
expected = 0x8048c4a;
CPPUNIT_ASSERT_EQUAL(expected, addr);
pBF->Close();
bff.UnLoad();
pBF = bff.Load(SUSE_TRUE);
CPPUNIT_ASSERT(pBF != NULL);
pFE = new PentiumFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
CPPUNIT_ASSERT(pFE != NULL);
addr = pFE->getMainEntryPoint(found);
expected = 0x8048b60;
CPPUNIT_ASSERT_EQUAL(expected, addr);
pBF->Close();
delete pFE;
}
示例11: main
int main(int argc, char **argv)
{
Prog prog;
prog.init();
prog.add_sample("data/haiku/air_0.ogg");
prog.add_sample("data/haiku/air_1.ogg");
prog.add_sample("data/haiku/earth_0.ogg");
prog.add_sample("data/haiku/earth_1.ogg");
prog.add_sample("data/haiku/earth_2.ogg");
prog.add_sample("data/haiku/fire_0.ogg");
prog.add_sample("data/haiku/fire_1.ogg");
prog.add_sample("data/haiku/water_0.ogg");
prog.add_sample("data/haiku/water_1.ogg");
prog.add_stream_path("../demos/cosmic_protector/data/sfx/game_music.ogg");
prog.add_stream_path("../demos/cosmic_protector/data/sfx/title_music.ogg");
prog.initial_config();
prog.run();
/* Let Allegro handle the cleanup. */
return 0;
(void)argc;
(void)argv;
}
示例12: testDataIntervalOverlaps
/*==============================================================================
* FUNCTION: TypeTest::testDataIntervalOverlaps
* OVERVIEW: Test the DataIntervalMap class with overlapping addItems
*============================================================================*/
void TypeTest::testDataIntervalOverlaps() {
DataIntervalMap dim;
Prog* prog = new Prog;
UserProc* proc = (UserProc*) prog->newProc("test", 0x123);
std::string name("test");
proc->setSignature(Signature::instantiate(PLAT_PENTIUM, CONV_C, name.c_str()));
dim.setProc(proc);
dim.addItem(0x1000, "firstInt", new IntegerType(32, 1));
dim.addItem(0x1004, "firstFloat", new FloatType(32));
dim.addItem(0x1008, "secondInt", new IntegerType(32, 1));
dim.addItem(0x100C, "secondFloat", new FloatType(32));
CompoundType ct;
ct.addType(new IntegerType(32, 1), "int3");
ct.addType(new FloatType(32), "float3");
dim.addItem(0x1010, "existingStruct", &ct);
// First insert a new struct over the top of the existing middle pair
CompoundType ctu;
ctu.addType(new IntegerType(32, 0), "newInt"); // This int has UNKNOWN sign
ctu.addType(new FloatType(32), "newFloat");
dim.addItem(0x1008, "replacementStruct", &ctu);
DataIntervalEntry* pdie = dim.find(0x1008);
std::string expected = "struct { int newInt; float newFloat; }";
std::string actual = pdie->second.type->getCtype();
CPPUNIT_ASSERT_EQUAL(expected, actual);
// Attempt a weave; should fail
CompoundType ct3;
ct3.addType(new FloatType(32), "newFloat3");
ct3.addType(new IntegerType(32, 0), "newInt3");
dim.addItem(0x1004, "weaveStruct1", &ct3);
pdie = dim.find(0x1004);
expected = "firstFloat";
actual = pdie->second.name;
CPPUNIT_ASSERT_EQUAL(expected, actual);
// Totally unaligned
dim.addItem(0x1001, "weaveStruct2", &ct3);
pdie = dim.find(0x1001);
expected = "firstInt";
actual = pdie->second.name;
CPPUNIT_ASSERT_EQUAL(expected, actual);
dim.addItem(0x1004, "firstInt", new IntegerType(32, 1)); // Should fail
pdie = dim.find(0x1004);
expected = "firstFloat";
actual = pdie->second.name;
CPPUNIT_ASSERT_EQUAL(expected, actual);
// Set up three ints
dim.deleteItem(0x1004);
dim.addItem(0x1004, "firstInt", new IntegerType(32, 1)); // Definately signed
dim.deleteItem(0x1008);
dim.addItem(0x1008, "firstInt", new IntegerType(32, 0)); // Unknown signedess
// then, add an array over the three integers
ArrayType at(new IntegerType(32, 0), 3);
dim.addItem(0x1000, "newArray", &at);
pdie = dim.find(0x1005); // Check middle element
expected = "newArray";
actual = pdie->second.name;
CPPUNIT_ASSERT_EQUAL(expected, actual);
pdie = dim.find(0x1000); // Check first
actual = pdie->second.name;
CPPUNIT_ASSERT_EQUAL(expected, actual);
pdie = dim.find(0x100B); // Check last
actual = pdie->second.name;
CPPUNIT_ASSERT_EQUAL(expected, actual);
// Already have an array of 3 ints at 0x1000. Put a new array completely before, then with only one word overlap
dim.addItem(0xF00, "newArray2", &at);
pdie = dim.find(0x1000); // Shouyld still be newArray at 0x1000
actual = pdie->second.name;
CPPUNIT_ASSERT_EQUAL(expected, actual);
pdie = dim.find(0xF00);
expected = "newArray2";
actual = pdie->second.name;
CPPUNIT_ASSERT_EQUAL(expected, actual);
dim.addItem(0xFF8, "newArray3", &at); // Should fail
pdie = dim.find(0xFF8);
unsigned ue = 0; // Expect NULL
unsigned ua = (unsigned)pdie;
CPPUNIT_ASSERT_EQUAL(ue, ua);
}
示例13: testDataInterval
/*==============================================================================
* FUNCTION: TypeTest::testDataInterval
* OVERVIEW: Test the DataIntervalMap class
*============================================================================*/
void TypeTest::testDataInterval() {
DataIntervalMap dim;
Prog* prog = new Prog;
UserProc* proc = (UserProc*) prog->newProc("test", 0x123);
std::string name("test");
proc->setSignature(Signature::instantiate(PLAT_PENTIUM, CONV_C, name.c_str()));
dim.setProc(proc);
dim.addItem(0x1000, "first", new IntegerType(32, 1));
dim.addItem(0x1004, "second", new FloatType(64));
std::string actual(dim.prints());
std::string expected("0x1000 first int\n"
"0x1004 second double\n");
CPPUNIT_ASSERT_EQUAL(expected, actual);
DataIntervalEntry* pdie = dim.find(0x1000);
expected = "first";
CPPUNIT_ASSERT(pdie);
actual = pdie->second.name;
CPPUNIT_ASSERT_EQUAL(expected, actual);
pdie = dim.find(0x1003);
CPPUNIT_ASSERT(pdie);
actual = pdie->second.name;
CPPUNIT_ASSERT_EQUAL(expected, actual);
pdie = dim.find(0x1004);
CPPUNIT_ASSERT(pdie);
expected = "second";
actual = pdie->second.name;
CPPUNIT_ASSERT_EQUAL(expected, actual);
pdie = dim.find(0x1007);
CPPUNIT_ASSERT(pdie);
actual = pdie->second.name;
CPPUNIT_ASSERT_EQUAL(expected, actual);
CompoundType ct;
ct.addType(new IntegerType(16, 1), "short1");
ct.addType(new IntegerType(16, 1), "short2");
ct.addType(new IntegerType(32, 1), "int1");
ct.addType(new FloatType(32), "float1");
dim.addItem(0x1010, "struct1", &ct);
ComplexTypeCompList& ctcl = ct.compForAddress(0x1012, dim);
unsigned ua = ctcl.size();
unsigned ue = 1;
CPPUNIT_ASSERT_EQUAL(ue, ua);
ComplexTypeComp& ctc = ctcl.front();
ue = 0;
ua = ctc.isArray;
CPPUNIT_ASSERT_EQUAL(ue, ua);
expected = "short2";
actual = ctc.u.memberName;
CPPUNIT_ASSERT_EQUAL(expected, actual);
// An array of 10 struct1's
ArrayType at(&ct, 10);
dim.addItem(0x1020, "array1", &at);
ComplexTypeCompList& ctcl2 = at.compForAddress(0x1020+0x3C+8, dim);
// Should be 2 components: [5] and .float1
ue = 2;
ua = ctcl2.size();
CPPUNIT_ASSERT_EQUAL(ue, ua);
ComplexTypeComp& ctc0 = ctcl2.front();
ComplexTypeComp& ctc1 = ctcl2.back();
ue = 1;
ua = ctc0.isArray;
CPPUNIT_ASSERT_EQUAL(ue, ua);
ue = 5;
ua = ctc0.u.index;
CPPUNIT_ASSERT_EQUAL(ue, ua);
ue = 0;
ua = ctc1.isArray;
CPPUNIT_ASSERT_EQUAL(ue, ua);
expected = "float1";
actual = ctc1.u.memberName;
CPPUNIT_ASSERT_EQUAL(expected, actual);
}
示例14: GetRoomTemp
float GetRoomTemp (long int day, float t_comf, float t_eco)
{
switch (day_prog[day-1]) // 0 index refer to MON, 1 to TU, etc
{
case PROG1:
return P1.SetRoomTempr(t_comf, t_eco);
break;
case PROG2:
return P2.SetRoomTempr(t_comf, t_eco);
break;
case PROG3:
return P3.SetRoomTempr(t_comf, t_eco);
break;
case PROG4:
return P4.SetRoomTempr(t_comf, t_eco);
break;
case PROG5:
return P5.SetRoomTempr(t_comf, t_eco);
break;
case PROG6:
return P6.SetRoomTempr(t_comf, t_eco);
break;
case PROG7:
return P7.SetRoomTempr(t_comf, t_eco);
break;
case PROG8:
return P8.SetRoomTempr(t_comf, t_eco);
break;
case PROG9:
return P9.SetRoomTempr(t_comf, t_eco);
break;
default:
return P1.SetRoomTempr(t_comf, t_eco);
}
}