Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
12aebb0
Fixed escaped character lexical interpretation
higgsch Mar 1, 2018
94042ad
Fixed improper acceptance of single backslash string
higgsch Mar 1, 2018
0dece39
Added '?' to String literals and simplified regex
higgsch Mar 1, 2018
13db328
Disallowed tab and single backslash in character literals
higgsch Mar 1, 2018
8cbda3d
Allowed escaped spaces in string literals
higgsch Mar 1, 2018
61ec4e1
Added backspace and formfeed as character literals
higgsch Mar 1, 2018
61eb436
Fixed escaped 0 in string -> null-terminator bug
higgsch Mar 1, 2018
b55d08a
Removed extra whitespace
higgsch Mar 1, 2018
f147a28
Fixed Scanner build issues with certain versions of flex
higgsch Jan 17, 2019
3c76c92
Fixed build issue with std::function
higgsch Jan 17, 2019
10321b9
Fixed sporadic errors in using tester.sh due to lack of strdup
higgsch Jan 17, 2019
df896e7
Fixed source commenting (file:line) vs (line:file)
higgsch Jan 17, 2019
ad059bd
Replaced deprecated -std=c++0x switch with -std=c++11
higgsch Jan 17, 2019
1424030
Fixed extra nullptr statement in main, functs, and procs bug
higgsch Jan 17, 2019
ca6ae12
Fixed CPSL true and false being typed as integers bug
higgsch Jan 17, 2019
97af345
Fixed CPSL not operator: pseudoinst not is a bitwise not across all b…
higgsch Jan 17, 2019
2eab6f4
Brought tests within spec: logical not operator is only defined for b…
higgsch Jan 17, 2019
8e2b1d5
Fixed double return statement bug
higgsch Jan 17, 2019
07af0c6
There is no reason to traverse the last node in the list because it h…
higgsch Jan 17, 2019
62399b1
Fixed duplicate basic blocks on branches
higgsch Jan 17, 2019
6114907
Added code to update the pointer to the last block in a flowgraph
higgsch Jan 17, 2019
39a145d
I missed a couple traverse calls
higgsch Jan 17, 2019
4dd5c27
Updated base instruction counts
higgsch Jan 17, 2019
52aa9cc
Fixed MARS errors not displaying
higgsch Jan 17, 2019
038872c
Added more details to tester output
higgsch Jan 17, 2019
5d180b9
Updated Not Unit Test to use xori
higgsch Jan 17, 2019
64c8d80
Fixed overlooked bitwise not useage
higgsch Mar 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AST_INC/AST/Expressions/NotExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ std::shared_ptr<cs6300::Type> cs6300::NotExpression::type() const
}
int cs6300::NotExpression::value() const
{
return ~m_expr->value();
return !m_expr->value();
}
bool cs6300::NotExpression::isConst() const
{
Expand Down
6 changes: 3 additions & 3 deletions AST_INC/AST/ThreeAddressInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ cs6300::ThreeAddressInstruction::ThreeAddressInstruction(std::string c)
}

cs6300::ThreeAddressInstruction::ThreeAddressInstruction(std::string c,
std::string line,
std::string file)
std::string file,
std::string line)
: op(Comment), dest(0), src1(0), src2(0), comment(c)
{
comment += "(" + file + ":" + line + ")";
Expand Down Expand Up @@ -112,7 +112,7 @@ std::ostream& cs6300::operator<<(std::ostream& out,
out << "\tmflo $" << i.dest;
break;
case cs6300::ThreeAddressInstruction::Not:
out << "not $" << i.dest << ", $" << i.src1;
out << "xori $" << i.dest << ", $" << i.src1 << ", 1";
break;
case cs6300::ThreeAddressInstruction::Or:
out << "or $" << i.dest << ", $" << i.src1 << ", $" << i.src2;
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ include_directories(
${WINDOWS_GNU}
)

set(EXTRA_COMPILE_FLAGS "-g -std=c++0x")
set(EXTRA_COMPILE_FLAGS "-g -std=c++11")
#set(LCOV_FLAGS "--coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_COMPILE_FLAGS} ${LCOV_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LCOV_FLAGS}")
Expand Down
12 changes: 8 additions & 4 deletions FrontEnd/FrontEnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ int appendList(FEC<T>& listSrc,
int elementIndex)
{
auto elem = elementSrc.get(elementIndex);
return appendList(listSrc, listIndex, elem);
return (elem) ? appendList(listSrc, listIndex, elem) : listIndex;
}

template <typename ExprType> int binaryOp(int a, int b)
Expand Down Expand Up @@ -750,7 +750,11 @@ void cs6300::AddFunction(int signature, int body)
state->getSymTable()->addParameter(param.first, param.second);
}
auto b = state->statementLists.get(body);
b->push_back(std::make_shared<cs6300::ReturnStatement>(nullptr));

if (b->at(b->size()-1)->ClassName().compare("Return") != 0)
{
b->push_back(std::make_shared<cs6300::ReturnStatement>(nullptr));
}
auto program = state->getProgram();
program->functions[*sig] =
std::make_shared<cs6300::Function>(sig, *b, state->getSymTable());
Expand All @@ -766,9 +770,9 @@ void cs6300::AddMain(int body)
std::copy(b->begin(), b->end(), std::back_inserter(program->main));

int t =
state->expressions.add(std::make_shared<cs6300::LiteralExpression>(1));
state->expressions.add(std::make_shared<cs6300::LiteralExpression>(true));
int f =
state->expressions.add(std::make_shared<cs6300::LiteralExpression>(0));
state->expressions.add(std::make_shared<cs6300::LiteralExpression>(false));
AddLiteral("true", t);
AddLiteral("TRUE", t);
AddLiteral("false", f);
Expand Down
40 changes: 37 additions & 3 deletions FrontEnd/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
#include "parser.hpp"
#include "ProcessLog.hpp"
#include "logger.h"

char* replaceAllNullWithZero(char*);
%}

%option nounput
%option never-interactive
%option noyywrap

%%

Expand Down Expand Up @@ -73,15 +77,45 @@ write|WRITE {return WRITESY;}
[0-9]+[0-9]* {yylval.int_val = strtol(yytext,nullptr,0);return INTSY;}

'\\n' {yylval.char_val = '\n';return CHARCONSTSY;}
'\\t' {yylval.char_val = '\t';return CHARCONSTSY;}
'\\r' {yylval.char_val = '\r';return CHARCONSTSY;}
'\\?.' {yylval.char_val = yytext[1];return CHARCONSTSY;}
'\\b' {yylval.char_val = '\b';return CHARCONSTSY;}
'\\t' {yylval.char_val = '\t';return CHARCONSTSY;}
'\\f' {yylval.char_val = '\f';return CHARCONSTSY;}
'[ !-\[\]-~]' {yylval.char_val = yytext[1];return CHARCONSTSY;}
'\\[ !-~]' {yylval.char_val = yytext[2];return CHARCONSTSY;}

\"[a-zA-Z0-9~`!@'#$%^&*()_+=\-\[\]{}\\\/><,.:;| ]*\" {yylval.str_val = strdup(yytext); return STRINGSY;}
\"([ !#-~]|\\[ !-~])*\" {yylval.str_val = replaceAllNullWithZero(yytext); return STRINGSY;}

\$.*$ {ProcessLog::getInstance()->nextLine();}
\n {ProcessLog::getInstance()->nextLine();}
[ \t]+ {}
. {LOG(ERROR) << std::string("Unexpected token ")+yytext;}

%%

char* replaceAllNullWithZero(char* str)
{
char* s = strdup(str);

int str_i = 0;
int s_i = 0;
while (str[str_i])
{
if (str[str_i] == '\\' && str[str_i+1] == '0')
{
s[s_i++] = str[++str_i];
str_i++;
}
else if (str[str_i] == '\\')
{
s[s_i++] = str[str_i++];
s[s_i++] = str[str_i++];
}
else
s[s_i++] = str[str_i++];
}

s[s_i++] = 0;
return s;
}

1 change: 1 addition & 0 deletions Optimizations/FlowGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __cpsl__TraverseBasicBlock__

#include "AST/BasicBlock.hpp"
#include <functional>

namespace cs6300
{
Expand Down
40 changes: 28 additions & 12 deletions Optimizations/MaximizeBlocks/MaximizeBlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,55 @@
#include "VisitedBlocks.hpp"
#include "NumParents.hpp"

void cs6300::maximizeBlocks(cs6300::FlowGraph original)
void cs6300::maximizeBlocks(cs6300::FlowGraph& original)
{
// traverse the blocks
cs6300::traverse(original.first);
cs6300::traverse(original.second);
auto vb = VisitedBlocks::instance();
vb->reset();
buildParentCounts(original.first);
vb->reset();
combineBlocks(original.first, original);
}

void cs6300::traverse(std::shared_ptr<BasicBlock> block)
void cs6300::buildParentCounts(std::shared_ptr<BasicBlock> block)
{
auto vb = VisitedBlocks::instance();
auto np = NumParents::instance();

if (vb->isVisited(block))
{
return;
}
if (vb->isVisited(block)) return;

if (block->branchTo != nullptr)
{
// add parents on the way down...
np->addParent(block->branchTo);
traverse(block->branchTo);
buildParentCounts(block->branchTo);
}
if (block->jumpTo != nullptr)
{
// add parents on the way down...
np->addParent(block->jumpTo);
traverse(block->jumpTo);
buildParentCounts(block->jumpTo);
}
}

void cs6300::combineBlocks(std::shared_ptr<BasicBlock> block, FlowGraph& graph)
{
auto vb = VisitedBlocks::instance();
auto np = NumParents::instance();

if (vb->isVisited(block)) return;

if (block->branchTo) combineBlocks(block->branchTo, graph);
if (block->jumpTo) combineBlocks(block->jumpTo, graph);

// determine if they can be merged on the way back up...
if (block->jumpTo != nullptr && block->branchTo == nullptr &&
np->getNumParents(block->jumpTo) == 1)
{
//Redirect the end of the graph
if (block->jumpTo == graph.second)
{
graph.second = block;
}

// merge jumpTo to this block
for (auto inst : block->jumpTo->instructions)
{
Expand Down
5 changes: 3 additions & 2 deletions Optimizations/MaximizeBlocks/MaximizeBlocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

namespace cs6300
{
void maximizeBlocks(cs6300::FlowGraph);
void maximizeBlocks(FlowGraph&);

void traverse(std::shared_ptr<BasicBlock> block);
void buildParentCounts(std::shared_ptr<BasicBlock> block);
void combineBlocks(std::shared_ptr<BasicBlock>, FlowGraph&);
}

#endif
2 changes: 1 addition & 1 deletion Testing/UnitTests/ExpressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ TEST_CASE("NotExpression", "[expression]")

auto exp = R"(BB1:
li $1, 15
not $2, $1
xori $2, $1, 1
)";
REQUIRE(s == exp);
}
Expand Down
6 changes: 3 additions & 3 deletions log/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ INITIALIZE_EASYLOGGINGPP

const char* cpsl_log::getLine()
{
return std::to_string(ProcessLog::getInstance()->line()).c_str();
return strdup(std::to_string(ProcessLog::getInstance()->line()).c_str());
}

const char* cpsl_log::getFile()
{
return boost::filesystem::basename(&ProcessLog::getInstance()->file()[0])
.c_str();
return strdup(boost::filesystem::basename(&ProcessLog::getInstance()->file()[0])
.c_str());
}

const std::string defaultLogFile = "log/log.conf";
Expand Down
2 changes: 1 addition & 1 deletion tester/Base/count_mix_control.cpsl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2825
2839
2 changes: 1 addition & 1 deletion tester/Base/count_mix_expressions.cpsl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1095
1098
2 changes: 1 addition & 1 deletion tester/Base/count_nested_if.cpsl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
43
45
2 changes: 1 addition & 1 deletion tester/Base/count_personnel.cpsl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19209
19221
2 changes: 1 addition & 1 deletion tester/Base/count_simple_else.cpsl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
87
89
2 changes: 1 addition & 1 deletion tester/Base/count_simple_elseif.cpsl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
47
48
2 changes: 1 addition & 1 deletion tester/Base/count_simple_if.cpsl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
29
30
2 changes: 1 addition & 1 deletion tester/Base/count_simple_recursion.cpsl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2753
2754
2 changes: 1 addition & 1 deletion tester/Base/count_swap.cpsl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
254585
254949
4 changes: 2 additions & 2 deletions tester/Base/mix_expressions.cpsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ d
2<=2=1
2<>2=0
2 8
~-5=4
~5=-6
~true=0
~false=1
Setting A to 5:
Setting B to 8:
5 8
Expand Down
4 changes: 2 additions & 2 deletions tester/TestFiles/mix_expressions.cpsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ BEGIN
write(a,' ',b,'\n');
a := 5;
b := 15;
write("~-5=",~-5,'\n');
write("~5=",~5,'\n');
write("~true=",~true,'\n');
write("~false=",~false,'\n');
write("Setting A to 5:");
a := 5;
write("\nSetting B to 8:");
Expand Down
34 changes: 33 additions & 1 deletion tester/tester.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ trap on_die TERM

ret=0

baseTotal=0
outTotal=0
totalPerc=0
count=0
best=900
worst=0

for file in ${files}; do

file=$(basename ${file})
Expand All @@ -49,7 +56,7 @@ for file in ${files}; do

echo -n "Executing: ${file}..."
java -Djava.awt.headless=true -jar ${MARSDIR}${MARSJAR} me ic nc 1000000 ${ASM}${file} 2> stderr.txt > ${RESULTS}${file}
if [ $? -ne 0 ]; then
if [ ! -s ${RESULTS}${file} ]; then
echo " Error running: java -jar nc 1000000 ${MARSDIR}${MARSJAR} ${ASM}${file} > ${RESULTS}${file}"
cat stderr.txt
ret=1
Expand Down Expand Up @@ -82,7 +89,32 @@ for file in ${files}; do
echo " diff ${RESULTS}${file} ${BASE}${file}"
echo ${diff}
echo
ret=1
fi

baseTotal=$((baseTotal + be))
outTotal=$((outTotal + le))
totalPerc=$((totalPerc + div))
count=$((count + 1))
worst=$((worst<div?div:worst))
best=$((best>div?div:best))

done
rm -f stderr.txt

if [ $ret -ne 1 ]; then
echo
echo "No Errors Found"
echo
totalDiv=$(((outTotal*100)/baseTotal))
echo "Total Instructions: ${outTotal}/${baseTotal} ${totalDiv}%"
avgPerc=$((totalPerc/count))
echo "Average of Percentages: ${totalPerc}%/${count} ${avgPerc}%"
echo "Best Improvement Percentage: ${best}%"
echo "Worst Improvement Percentage: ${worst}%"
else
echo
echo "Errors Found"
fi

exit ${ret}