Skip to content

Commit

Permalink
Added a run last test only flag (tests are getting too long now). Sto…
Browse files Browse the repository at this point in the history
…pped non-main functions from printing their return value
  • Loading branch information
chutasano committed Apr 7, 2018
1 parent ad8b2b2 commit f1ac8f6
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 262 deletions.
13 changes: 11 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#include "rep/r0.h"
#include "test.h"
#include <cstring>

int main()
int main(int argc, char* argv[])
{
test_all();
bool last_test_only = false;
for (int i=argc; i>1; i--)
{
if (!strcmp("--last_test_only", argv[i-1]))
{
last_test_only = true;
}
}
test_all(last_test_only);
}
50 changes: 27 additions & 23 deletions rep/x0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,32 +116,36 @@ string IRet::to_asm()
// this should be processed by the callee of the program
// in automated tests
stringstream ss;
ss << "MOVQ\t%rax, %rdi\n";
type ty = static_cast<type>(t);
switch (ty)
if (print)
{
case TNUM:
ss << " CALLQ\t_lang_print_num\n";
break;
case TBOOL:
ss << " CALLQ\t_lang_print_bool\n";
break;
case TVOID:
ss << " CALLQ\t_lang_print_void\n";
break;
default:
if (t > TVEC && t < TFUN)
{
ss << " CALLQ\t_lang_print_vec\n";
ss << "MOVQ\t%rax, %rdi\n";
type ty = static_cast<type>(t);
switch (ty)
{
case TNUM:
ss << " CALLQ\t_lang_print_num\n";
break;
}
else
{
cerr <<"WTF??? got unknown type: " << t << "\n";
exit(2);
}
case TBOOL:
ss << " CALLQ\t_lang_print_bool\n";
break;
case TVOID:
ss << " CALLQ\t_lang_print_void\n";
break;
default:
if (t > TVEC && t < TFUN)
{
ss << " CALLQ\t_lang_print_vec\n";
break;
}
else
{
cerr <<"WTF??? got unknown type: " << t << "\n";
exit(2);
}
}
ss << " ";
}
ss << " RETQ";
ss << "RETQ";
return ss.str();
}

Expand Down
3 changes: 2 additions & 1 deletion rep/x0.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ namespace x0

struct IRet : I
{
IRet(int ty) : t(ty) { }
IRet(int ty, bool print) : t(ty), print(print) { }
int t;
bool print;
std::string to_asm();
};

Expand Down
14 changes: 11 additions & 3 deletions rep/x0s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ list<x0::I*> F::assign(bool is_default, int heap_size)
total_offset = 8*(worst_stack - regs.size() + 1);
ins.push_back(new x0::ISrcDst(SUBQ, new x0::Con(total_offset), new x0::Reg("rsp")));
}
if (worst_rootstack >= regs.size())
if (worst_rootstack >= regs.size() && is_default) //FIXME, use highest worst_rootstack
// across all functions
{
ICall a("_lang_init_rootstack", { new Con((worst_rootstack - regs.size() + 1))}, new Reg("r12"));
ins.splice(ins.end(), a.assign(vmap));
Expand All @@ -208,7 +209,14 @@ list<x0::I*> F::assign(bool is_default, int heap_size)
}
// can't use map to get type because simple programs may optimize
// the ret part such that it's returning a non-variable (ie: constant)
ins.push_back(new x0::IRet(fun_type.at(this->t).back()));
if (is_default)
{
ins.push_back(new x0::IRet(fun_type.at(this->t).back(), true));
}
else
{
ins.push_back(new x0::IRet(fun_type.at(this->t).back(), false));
}
}
else
{
Expand Down Expand Up @@ -481,7 +489,7 @@ list<x0::I*> ILabel::assign(const s2vmap &vmap)
list<x0::I*> IRet::assign(const s2vmap &vmap)
{
// TODO fix
return { new x0::IRet(TBOOL) };
return { new x0::IRet(TBOOL, false) };
}

list<string> INoArg::get_vars()
Expand Down
Loading

0 comments on commit f1ac8f6

Please sign in to comment.