writeProcComments is now member of Function, at it has an ostream based overload, also added gmock framework to dependencies

This commit is contained in:
Artur K
2012-03-13 00:16:09 +01:00
parent bc395da6ab
commit d39449124a
40 changed files with 3660 additions and 72 deletions

View File

@@ -1,27 +1,7 @@
SET(SOURCES ast.cpp backend.cpp bundle.cpp chklib.cpp
comwrite.cpp control.cpp dataflow.cpp dcc.cpp
disassem.cpp error.cpp fixwild.cpp frontend.cpp
graph.cpp hlicode.cpp icode.cpp
idioms.cpp locident.cpp parser.cpp
perfhlib.cpp procs.cpp proplong.cpp reducible.cpp
scanner.cpp symtab.cpp udm.cpp)
SET(dc_INCLUDES
${PROJECT_SOURCE_DIR}/include/ast.h
${PROJECT_SOURCE_DIR}/include/bundle.h
${PROJECT_SOURCE_DIR}/include/dcc.h
${PROJECT_SOURCE_DIR}/include/disassem.h
${PROJECT_SOURCE_DIR}/include/dosdcc.h
${PROJECT_SOURCE_DIR}/include/error.h
${PROJECT_SOURCE_DIR}/include/graph.h
${PROJECT_SOURCE_DIR}/include/hlicode.h
${PROJECT_SOURCE_DIR}/include/icode.h
${PROJECT_SOURCE_DIR}/include/locident.h
${PROJECT_SOURCE_DIR}/include/perfhlib.h
${PROJECT_SOURCE_DIR}/include/scanner.h
${PROJECT_SOURCE_DIR}/include/state.h
${PROJECT_SOURCE_DIR}/include/symtab.h
${PROJECT_SOURCE_DIR}/include/types.h
)
SOURCE_GROUP(Source FILES ${SOURCES})
SOURCE_GROUP(Headers FILES ${dc_INCLUDES})
ADD_EXECUTABLE(dcc_oo ${SOURCES} ${dc_INCLUDES})
SET(dcc_test_SOURCES tests/comwrite.cpp)
include_directories(${GMOCK_INCLUDE_DIRS} ${GMOCK_ROOT}/gtest/include)
enable_testing()
add_executable(tester ${dcc_test_SOURCES})
target_link_libraries(tester
${GMOCK_BOTH_LIBRARIES} ${REQ_LLVM_LIBRARIES})
add_test(dcc-tests tester)

View File

@@ -50,8 +50,6 @@ static void writeStrTab (std::ostream &ios, strTable &strTab)
void writeBundle (std::ostream &ios, bundle procCode)
{
writeStrTab (ios, procCode.decl);
if (procCode.decl[procCode.decl.size() - 1][0] != ' ')
ios << "\n";
writeStrTab (ios, procCode.code);
}

View File

@@ -184,6 +184,13 @@ void LLInst::writeIntComment (std::ostringstream &s)
//, &cCode.decl
void Function::writeProcComments()
{
std::ostringstream ostr;
writeProcComments(ostr);
cCode.appendDecl(ostr.str());
}
void Function::writeProcComments(std::ostream &ostr)
{
int i;
ID *id; /* Pointer to register argument identifier */
@@ -191,79 +198,82 @@ void Function::writeProcComments()
/* About the parameters */
if (this->cbParam)
cCode.appendDecl("/* Takes %d bytes of parameters.\n",this->cbParam);
ostr << "/* Takes "<<this->cbParam<<" bytes of parameters.\n";
else if (this->flg & REG_ARGS)
{
cCode.appendDecl("/* Uses register arguments:\n");
ostr << "/* Uses register arguments:\n";
for (i = 0; i < this->args.numArgs; i++)
{
psym = &this->args.sym[i];
ostr << " * "<<psym->name<<" = ";
if (psym->regs->expr.ident.idType == REGISTER)
{
id = &this->localId.id_arr[psym->regs->expr.ident.idNode.regiIdx];
cCode.appendDecl(" * %s = %s.\n", psym->name,
Machine_X86::regName(id->id.regi).c_str());
ostr << Machine_X86::regName(id->id.regi);
}
else /* long register */
{
id = &this->localId.id_arr[psym->regs->expr.ident.idNode.longIdx];
cCode.appendDecl(" * %s = %s:%s.\n", psym->name,
Machine_X86::regName(id->id.longId.h).c_str(),
Machine_X86::regName(id->id.longId.l).c_str());
ostr << Machine_X86::regName(id->id.longId.h) << ":";
ostr << Machine_X86::regName(id->id.longId.l);
}
ostr << ".\n";
}
}
else
cCode.appendDecl("/* Takes no parameters.\n");
ostr << "/* Takes no parameters.\n";
/* Type of procedure */
if (this->flg & PROC_RUNTIME)
cCode.appendDecl(" * Runtime support routine of the compiler.\n");
ostr << " * Runtime support routine of the compiler.\n";
if (this->flg & PROC_IS_HLL)
cCode.appendDecl(" * High-level language prologue code.\n");
ostr << " * High-level language prologue code.\n";
if (this->flg & PROC_ASM)
{
cCode.appendDecl(" * Untranslatable routine. Assembler provided.\n");
ostr << " * Untranslatable routine. Assembler provided.\n";
if (this->flg & PROC_IS_FUNC)
switch (this->retVal.type) {
switch (this->retVal.type) { // TODO: Functions return value in various regs
case TYPE_BYTE_SIGN: case TYPE_BYTE_UNSIGN:
cCode.appendDecl(" * Return value in register al.\n");
ostr << " * Return value in register al.\n";
break;
case TYPE_WORD_SIGN: case TYPE_WORD_UNSIGN:
cCode.appendDecl(" * Return value in register ax.\n");
ostr << " * Return value in register ax.\n";
break;
case TYPE_LONG_SIGN: case TYPE_LONG_UNSIGN:
cCode.appendDecl(" * Return value in registers dx:ax.\n");
ostr << " * Return value in registers dx:ax.\n";
break;
} /* eos */
}
/* Calling convention */
if (this->flg & CALL_PASCAL)
cCode.appendDecl(" * Pascal calling convention.\n");
ostr << " * Pascal calling convention.\n";
else if (this->flg & CALL_C)
cCode.appendDecl(" * C calling convention.\n");
ostr << " * C calling convention.\n";
else if (this->flg & CALL_UNKNOWN)
cCode.appendDecl(" * Unknown calling convention.\n");
ostr << " * Unknown calling convention.\n";
/* Other flags */
if (this->flg & (PROC_BADINST | PROC_IJMP))
cCode.appendDecl(" * Incomplete due to an %s.\n",
(this->flg & PROC_BADINST)? "untranslated opcode":
"indirect JMP");
{
ostr << " * Incomplete due to an ";
if(this->flg & PROC_BADINST)
ostr << "untranslated opcode.\n";
else
ostr << "indirect JMP.\n";
}
if (this->flg & PROC_ICALL)
cCode.appendDecl(" * Indirect call procedure.\n");
ostr << " * Indirect call procedure.\n";
if (this->flg & IMPURE)
cCode.appendDecl(" * Contains impure code.\n");
ostr << " * Contains impure code.\n";
if (this->flg & NOT_HLL)
cCode.appendDecl(" * Contains instructions not normally used by compilers.\n");
ostr << " * Contains instructions not normally used by compilers.\n";
if (this->flg & FLOAT_OP)
cCode.appendDecl(" * Contains coprocessor instructions.\n");
ostr << " * Contains coprocessor instructions.\n";
/* Graph reducibility */
if (this->flg & GRAPH_IRRED)
cCode.appendDecl(" * Irreducible control flow graph.\n");
cCode.appendDecl(" */\n{\n");
ostr << " * Irreducible control flow graph.\n";
ostr << " */\n{\n";
}

14
src/tests/comwrite.cpp Normal file
View File

@@ -0,0 +1,14 @@
#include "dcc.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
TEST(CowriteTest, HandlesZeroInput) {
EXPECT_EQ(1, 1);
}
int main(int argc, char** argv) {
// The following line must be executed to initialize Google Mock
// (and Google Test) before running the tests.
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}