data/full_repos/permissive/187199324/stannel/Alu_tb.v
 line:202: before: "("
1: b'%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:1: Cannot find include file: defaults.vh\n`include "defaults.vh" \n         ^~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/187199324/stannel,data/full_repos/permissive/187199324/defaults.vh\n             data/full_repos/permissive/187199324/stannel,data/full_repos/permissive/187199324/defaults.vh.v\n             data/full_repos/permissive/187199324/stannel,data/full_repos/permissive/187199324/defaults.vh.sv\n             defaults.vh\n             defaults.vh.v\n             defaults.vh.sv\n             obj_dir/defaults.vh\n             obj_dir/defaults.vh.v\n             obj_dir/defaults.vh.sv\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:2: Cannot find include file: opcodes.vh\n`include "opcodes.vh" \n         ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:11: Define or directive not defined: \'`OP_CONDITION_ALWAYS\'\n  reg[3:0] condition = `OP_CONDITION_ALWAYS;\n                       ^~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:11: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n  reg[3:0] condition = `OP_CONDITION_ALWAYS;\n                                           ^\n%Warning-STMTDLY: data/full_repos/permissive/187199324/stannel/Alu_tb.v:17: Unsupported: Ignoring delay on this delayed statement.\n  always #1 clk <= ~clk;\n         ^\n                  ... Use "/* verilator lint_off STMTDLY */" and lint_on around source to disable this message.\n%Warning-STMTDLY: data/full_repos/permissive/187199324/stannel/Alu_tb.v:45: Unsupported: Ignoring delay on this delayed statement.\n      #2 updateFlags <= 0;\n      ^\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:57: Unsupported or unknown PLI call: $dumpfile\n    $dumpfile("Alu_tb.vcd");\n    ^~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:58: Unsupported or unknown PLI call: $dumpvars\n    $dumpvars(0, Alu_tb);\n    ^~~~~~~~~\n%Warning-STMTDLY: data/full_repos/permissive/187199324/stannel/Alu_tb.v:60: Unsupported: Ignoring delay on this delayed statement.\n    #1 reset <= 1;\n    ^\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:63: Define or directive not defined: \'`OP_ALU_ADD\'\n    #1 aluFunc <= `OP_ALU_ADD;\n                  ^~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:63: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n    #1 aluFunc <= `OP_ALU_ADD;\n                             ^\n%Warning-STMTDLY: data/full_repos/permissive/187199324/stannel/Alu_tb.v:63: Unsupported: Ignoring delay on this delayed statement.\n    #1 aluFunc <= `OP_ALU_ADD;\n    ^\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:65: Define or directive not defined: \'`OP_ALU_SUB\'\n    aluFunc <= `OP_ALU_SUB;\n               ^~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:65: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n    aluFunc <= `OP_ALU_SUB;\n                          ^\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:67: Define or directive not defined: \'`OP_ALU_NOT\'\n    aluFunc <= `OP_ALU_NOT;\n               ^~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:67: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n    aluFunc <= `OP_ALU_NOT;\n                          ^\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:69: Define or directive not defined: \'`OP_ALU_OR\'\n    aluFunc <= `OP_ALU_OR;\n               ^~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:69: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n    aluFunc <= `OP_ALU_OR;\n                         ^\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:71: Define or directive not defined: \'`OP_ALU_AND\'\n    aluFunc <= `OP_ALU_AND;\n               ^~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:71: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n    aluFunc <= `OP_ALU_AND;\n                          ^\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:73: Define or directive not defined: \'`OP_ALU_XOR\'\n    aluFunc <= `OP_ALU_XOR;\n               ^~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:73: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n    aluFunc <= `OP_ALU_XOR;\n                          ^\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:77: Define or directive not defined: \'`OP_ALU_COMPARE\'\n    aluFunc <= `OP_ALU_COMPARE;\n               ^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:77: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n    aluFunc <= `OP_ALU_COMPARE;\n                              ^\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:79: Define or directive not defined: \'`OP_CONDITION_ZERO_EQUAL\'\n    check(255, 255, `OP_CONDITION_ZERO_EQUAL, 1, "==");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:80: Define or directive not defined: \'`OP_CONDITION_ZERO_EQUAL\'\n    check(255, 253, `OP_CONDITION_ZERO_EQUAL, 0, "==");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:81: Define or directive not defined: \'`OP_CONDITION_NOT_ZERO_NOT_EQUAL\'\n    check(255, 255, `OP_CONDITION_NOT_ZERO_NOT_EQUAL, 0, "!=");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:82: Define or directive not defined: \'`OP_CONDITION_NOT_ZERO_NOT_EQUAL\'\n    check(255, 254, `OP_CONDITION_NOT_ZERO_NOT_EQUAL, 1, "!=");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:83: Define or directive not defined: \'`OP_CONDITION_NEGATIVE\'\n    check(000, 001, `OP_CONDITION_NEGATIVE, 1, "-");\n                    ^~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:84: Define or directive not defined: \'`OP_CONDITION_NEGATIVE\'\n    check(002, 001, `OP_CONDITION_NEGATIVE, 0, "-");\n                    ^~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:85: Define or directive not defined: \'`OP_CONDITION_UNSIGNED_GREATER\'\n    check(127, 126, `OP_CONDITION_UNSIGNED_GREATER, 1, ">u");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:86: Define or directive not defined: \'`OP_CONDITION_UNSIGNED_GREATER\'\n    check(126, 127, `OP_CONDITION_UNSIGNED_GREATER, 0, ">u");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:87: Define or directive not defined: \'`OP_CONDITION_UNSIGNED_GREATER\'\n    check(225, 031, `OP_CONDITION_UNSIGNED_GREATER, 1, ">u");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:88: Define or directive not defined: \'`OP_CONDITION_UNSIGNED_GREATER\'\n    check(031, 225, `OP_CONDITION_UNSIGNED_GREATER, 0, ">u");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:89: Define or directive not defined: \'`OP_CONDITION_UNSIGNED_LESS_OR_EQUAL\'\n    check(126, 127, `OP_CONDITION_UNSIGNED_LESS_OR_EQUAL, 1, "<=u");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:90: Define or directive not defined: \'`OP_CONDITION_UNSIGNED_LESS_OR_EQUAL\'\n    check(127, 126, `OP_CONDITION_UNSIGNED_LESS_OR_EQUAL, 0, "<=u");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:91: Define or directive not defined: \'`OP_CONDITION_UNSIGNED_LESS_OR_EQUAL\'\n    check(126, 126, `OP_CONDITION_UNSIGNED_LESS_OR_EQUAL, 1, "<=u");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:92: Define or directive not defined: \'`OP_CONDITION_UNSIGNED_GREATER_OR_EQUAL\'\n    check(127, 126, `OP_CONDITION_UNSIGNED_GREATER_OR_EQUAL, 1, ">=u");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:93: Define or directive not defined: \'`OP_CONDITION_UNSIGNED_GREATER_OR_EQUAL\'\n    check(127, 127, `OP_CONDITION_UNSIGNED_GREATER_OR_EQUAL, 1, ">=u");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:94: Define or directive not defined: \'`OP_CONDITION_UNSIGNED_GREATER_OR_EQUAL\'\n    check(126, 127, `OP_CONDITION_UNSIGNED_GREATER_OR_EQUAL, 0, ">=u");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:95: Define or directive not defined: \'`OP_CONDITION_UNSIGNED_LESS\'\n    check(126, 127, `OP_CONDITION_UNSIGNED_LESS, 1, "<u");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:96: Define or directive not defined: \'`OP_CONDITION_UNSIGNED_LESS\'\n    check(126, 126, `OP_CONDITION_UNSIGNED_LESS, 0, "<u");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:97: Define or directive not defined: \'`OP_CONDITION_UNSIGNED_LESS\'\n    check(127, 126, `OP_CONDITION_UNSIGNED_LESS, 0, "<u");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:98: Define or directive not defined: \'`OP_CONDITION_SIGNED_GREATER\'\n    check(100, 050, `OP_CONDITION_SIGNED_GREATER, 1, ">s");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:99: Define or directive not defined: \'`OP_CONDITION_SIGNED_GREATER\'\n    check(100, 100, `OP_CONDITION_SIGNED_GREATER, 0, ">s");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:100: Define or directive not defined: \'`OP_CONDITION_SIGNED_GREATER\'\n    check(050, 100, `OP_CONDITION_SIGNED_GREATER, 0, ">s");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:101: Define or directive not defined: \'`OP_CONDITION_SIGNED_GREATER\'\n    check(150, 175, `OP_CONDITION_SIGNED_GREATER, 0, ">s");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:102: Define or directive not defined: \'`OP_CONDITION_SIGNED_GREATER\'\n    check(175, 150, `OP_CONDITION_SIGNED_GREATER, 1, ">s");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:103: Define or directive not defined: \'`OP_CONDITION_SIGNED_GREATER\'\n    check(200, 010, `OP_CONDITION_SIGNED_GREATER, 0, ">s");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:104: Define or directive not defined: \'`OP_CONDITION_SIGNED_LESS_OR_EQUAL\'\n    check(001, 002, `OP_CONDITION_SIGNED_LESS_OR_EQUAL, 1, "<=s");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:105: Define or directive not defined: \'`OP_CONDITION_SIGNED_LESS_OR_EQUAL\'\n    check(127, 127, `OP_CONDITION_SIGNED_LESS_OR_EQUAL, 1, "<=s");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:106: Define or directive not defined: \'`OP_CONDITION_SIGNED_LESS_OR_EQUAL\'\n    check(128, 127, `OP_CONDITION_SIGNED_LESS_OR_EQUAL, 1, "<=s");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:107: Define or directive not defined: \'`OP_CONDITION_SIGNED_LESS_OR_EQUAL\'\n    check(128, 128, `OP_CONDITION_SIGNED_LESS_OR_EQUAL, 1, "<=s");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/187199324/stannel/Alu_tb.v:108: Define or directive not defined: \'`OP_CONDITION_SIGNED_GREATER_OR_EQUAL\'\n    check(100, 050, `OP_CONDITION_SIGNED_GREATER_OR_EQUAL, 1, ">=s");\n                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: Exiting due to too many errors encountered; --error-limit=50\n'
module Alu_tb();
  localparam dataBits = 8;
  reg[dataBits-1:0] aluA = 8'b01110100;
  reg[dataBits-1:0] aluB = 8'b00001100;
  reg[3:0] aluFunc;
  reg[3:0] condition = `OP_CONDITION_ALWAYS;
  wire[dataBits-1:0] aluOut;
  reg conditionHolds;
  reg reset = 0;

  reg clk = 0;
  always #1 clk <= ~clk;

  reg updateFlags = 0;

  Alu #(.dataBits(dataBits)) alu(
    .clk(clk),
    .reset(reset),
    .aluA(aluA),
    .aluB(aluB),
    .func(aluFunc),
    .condition(condition),
    .updateFlags(updateFlags),
    .aluOut(aluOut),
    .conditionHolds(conditionHolds),
    .loadFlagsFromSavedState(1'b0),
    .savedFlags(4'b0)
  );

  task check;
    input[dataBits-1:0] a, b;
    input[3:0] cond;
    input e;
    input[1024*8-1:0] s;
    begin
      aluA <= a;
      aluB <= b;
      condition <= cond;
      updateFlags <= 1;
      #2 updateFlags <= 0;
      if (conditionHolds != e)
        begin
          $error("[FAIL]\t%0d %0s %0d (expected %d, got %d, ZF=%0d,OF=%0d,SF=%0d,CF=%0d)",
            a, s, b, e, conditionHolds,
            alu.zeroFlag, alu.overflowFlag, alu.signFlag, alu.carryFlag);
          $finish;
        end
    end
  endtask

  initial begin
    $dumpfile("Alu_tb.vcd");
    $dumpvars(0, Alu_tb);

    #1 reset <= 1;


    #1 aluFunc <= `OP_ALU_ADD;
    if (aluOut != 128) $error("%d != 116 + 12", aluOut);
    aluFunc <= `OP_ALU_SUB;
    if (aluOut != 104) $error("%d != 116 - 12", aluOut);
    aluFunc <= `OP_ALU_NOT;
    if (aluOut != 139) $error("%d != ~116", aluOut);
    aluFunc <= `OP_ALU_OR;
    if (aluOut != 124) $error("%d != 116 | 12", aluOut);
    aluFunc <= `OP_ALU_AND;
    if (aluOut != 4) $error("%d != 116 & 12", aluOut);
    aluFunc <= `OP_ALU_XOR;
    if (aluOut != 120) $error("%d != 116 ^ 12", aluOut);


    aluFunc <= `OP_ALU_COMPARE;

    check(255, 255, `OP_CONDITION_ZERO_EQUAL, 1, "==");
    check(255, 253, `OP_CONDITION_ZERO_EQUAL, 0, "==");
    check(255, 255, `OP_CONDITION_NOT_ZERO_NOT_EQUAL, 0, "!=");
    check(255, 254, `OP_CONDITION_NOT_ZERO_NOT_EQUAL, 1, "!=");
    check(000, 001, `OP_CONDITION_NEGATIVE, 1, "-");
    check(002, 001, `OP_CONDITION_NEGATIVE, 0, "-");
    check(127, 126, `OP_CONDITION_UNSIGNED_GREATER, 1, ">u");
    check(126, 127, `OP_CONDITION_UNSIGNED_GREATER, 0, ">u");
    check(225, 031, `OP_CONDITION_UNSIGNED_GREATER, 1, ">u");
    check(031, 225, `OP_CONDITION_UNSIGNED_GREATER, 0, ">u");
    check(126, 127, `OP_CONDITION_UNSIGNED_LESS_OR_EQUAL, 1, "<=u");
    check(127, 126, `OP_CONDITION_UNSIGNED_LESS_OR_EQUAL, 0, "<=u");
    check(126, 126, `OP_CONDITION_UNSIGNED_LESS_OR_EQUAL, 1, "<=u");
    check(127, 126, `OP_CONDITION_UNSIGNED_GREATER_OR_EQUAL, 1, ">=u");
    check(127, 127, `OP_CONDITION_UNSIGNED_GREATER_OR_EQUAL, 1, ">=u");
    check(126, 127, `OP_CONDITION_UNSIGNED_GREATER_OR_EQUAL, 0, ">=u");
    check(126, 127, `OP_CONDITION_UNSIGNED_LESS, 1, "<u");
    check(126, 126, `OP_CONDITION_UNSIGNED_LESS, 0, "<u");
    check(127, 126, `OP_CONDITION_UNSIGNED_LESS, 0, "<u");
    check(100, 050, `OP_CONDITION_SIGNED_GREATER, 1, ">s");
    check(100, 100, `OP_CONDITION_SIGNED_GREATER, 0, ">s");
    check(050, 100, `OP_CONDITION_SIGNED_GREATER, 0, ">s");
    check(150, 175, `OP_CONDITION_SIGNED_GREATER, 0, ">s");
    check(175, 150, `OP_CONDITION_SIGNED_GREATER, 1, ">s");
    check(200, 010, `OP_CONDITION_SIGNED_GREATER, 0, ">s");
    check(001, 002, `OP_CONDITION_SIGNED_LESS_OR_EQUAL, 1, "<=s");
    check(127, 127, `OP_CONDITION_SIGNED_LESS_OR_EQUAL, 1, "<=s");
    check(128, 127, `OP_CONDITION_SIGNED_LESS_OR_EQUAL, 1, "<=s");
    check(128, 128, `OP_CONDITION_SIGNED_LESS_OR_EQUAL, 1, "<=s");
    check(100, 050, `OP_CONDITION_SIGNED_GREATER_OR_EQUAL, 1, ">=s");
    check(050, 100, `OP_CONDITION_SIGNED_GREATER_OR_EQUAL, 0, ">=s");
    check(128, 128, `OP_CONDITION_SIGNED_GREATER_OR_EQUAL, 1, ">=s");
    check(130, 150, `OP_CONDITION_SIGNED_GREATER_OR_EQUAL, 0, ">=s");
    check(150, 130, `OP_CONDITION_SIGNED_GREATER_OR_EQUAL, 1, ">=s");
    check(128, 127, `OP_CONDITION_SIGNED_LESS, 1, "<s");
    check(127, 128, `OP_CONDITION_SIGNED_LESS, 0, "<s");
    check(100, 050, `OP_CONDITION_SIGNED_LESS, 0, "<s");
    check(100, 100, `OP_CONDITION_SIGNED_LESS, 0, "<s");
    check(050, 100, `OP_CONDITION_SIGNED_LESS, 1, "<s");
    check(150, 175, `OP_CONDITION_SIGNED_LESS, 1, "<s");
    check(175, 150, `OP_CONDITION_SIGNED_LESS, 0, "<s");
    check(200, 010, `OP_CONDITION_SIGNED_LESS, 1, "<s");

    aluFunc = `OP_ALU_ADD;
    check(127, 127, `OP_CONDITION_OVERFLOW, 1, "+overflow");
    check(10, 10, `OP_CONDITION_OVERFLOW, 0, "+overflow");
    check(127, 127, `OP_CONDITION_NO_OVERFLOW, 0, "+overflow");
    check(10, 10, `OP_CONDITION_NO_OVERFLOW, 1, "+overflow");

    check(0, 0, `OP_CONDITION_ALWAYS, 1, "always");
    check(0, 0, `OP_CONDITION_NEVER, 0, "never");

    $finish;
  end
endmodule
module Alu_tb();

  localparam dataBits = 8;
  reg[dataBits-1:0] aluA = 8'b01110100;
  reg[dataBits-1:0] aluB = 8'b00001100;
  reg[3:0] aluFunc;
  reg[3:0] condition = `OP_CONDITION_ALWAYS;
  wire[dataBits-1:0] aluOut;
  reg conditionHolds;
  reg reset = 0;

  reg clk = 0;
  always #1 clk <= ~clk;

  reg updateFlags = 0;

  Alu #(.dataBits(dataBits)) alu(
    .clk(clk),
    .reset(reset),
    .aluA(aluA),
    .aluB(aluB),
    .func(aluFunc),
    .condition(condition),
    .updateFlags(updateFlags),
    .aluOut(aluOut),
    .conditionHolds(conditionHolds),
    .loadFlagsFromSavedState(1'b0),
    .savedFlags(4'b0)
  );

  task check;
    input[dataBits-1:0] a, b;
    input[3:0] cond;
    input e;
    input[1024*8-1:0] s;
    begin
      aluA <= a;
      aluB <= b;
      condition <= cond;
      updateFlags <= 1;
      #2 updateFlags <= 0;
      if (conditionHolds != e)
        begin
          $error("[FAIL]\t%0d %0s %0d (expected %d, got %d, ZF=%0d,OF=%0d,SF=%0d,CF=%0d)",
            a, s, b, e, conditionHolds,
            alu.zeroFlag, alu.overflowFlag, alu.signFlag, alu.carryFlag);
          $finish;
        end
    end
  endtask

  initial begin
    $dumpfile("Alu_tb.vcd");
    $dumpvars(0, Alu_tb);

    #1 reset <= 1;


    #1 aluFunc <= `OP_ALU_ADD;
    if (aluOut != 128) $error("%d != 116 + 12", aluOut);
    aluFunc <= `OP_ALU_SUB;
    if (aluOut != 104) $error("%d != 116 - 12", aluOut);
    aluFunc <= `OP_ALU_NOT;
    if (aluOut != 139) $error("%d != ~116", aluOut);
    aluFunc <= `OP_ALU_OR;
    if (aluOut != 124) $error("%d != 116 | 12", aluOut);
    aluFunc <= `OP_ALU_AND;
    if (aluOut != 4) $error("%d != 116 & 12", aluOut);
    aluFunc <= `OP_ALU_XOR;
    if (aluOut != 120) $error("%d != 116 ^ 12", aluOut);


    aluFunc <= `OP_ALU_COMPARE;

    check(255, 255, `OP_CONDITION_ZERO_EQUAL, 1, "==");
    check(255, 253, `OP_CONDITION_ZERO_EQUAL, 0, "==");
    check(255, 255, `OP_CONDITION_NOT_ZERO_NOT_EQUAL, 0, "!=");
    check(255, 254, `OP_CONDITION_NOT_ZERO_NOT_EQUAL, 1, "!=");
    check(000, 001, `OP_CONDITION_NEGATIVE, 1, "-");
    check(002, 001, `OP_CONDITION_NEGATIVE, 0, "-");
    check(127, 126, `OP_CONDITION_UNSIGNED_GREATER, 1, ">u");
    check(126, 127, `OP_CONDITION_UNSIGNED_GREATER, 0, ">u");
    check(225, 031, `OP_CONDITION_UNSIGNED_GREATER, 1, ">u");
    check(031, 225, `OP_CONDITION_UNSIGNED_GREATER, 0, ">u");
    check(126, 127, `OP_CONDITION_UNSIGNED_LESS_OR_EQUAL, 1, "<=u");
    check(127, 126, `OP_CONDITION_UNSIGNED_LESS_OR_EQUAL, 0, "<=u");
    check(126, 126, `OP_CONDITION_UNSIGNED_LESS_OR_EQUAL, 1, "<=u");
    check(127, 126, `OP_CONDITION_UNSIGNED_GREATER_OR_EQUAL, 1, ">=u");
    check(127, 127, `OP_CONDITION_UNSIGNED_GREATER_OR_EQUAL, 1, ">=u");
    check(126, 127, `OP_CONDITION_UNSIGNED_GREATER_OR_EQUAL, 0, ">=u");
    check(126, 127, `OP_CONDITION_UNSIGNED_LESS, 1, "<u");
    check(126, 126, `OP_CONDITION_UNSIGNED_LESS, 0, "<u");
    check(127, 126, `OP_CONDITION_UNSIGNED_LESS, 0, "<u");
    check(100, 050, `OP_CONDITION_SIGNED_GREATER, 1, ">s");
    check(100, 100, `OP_CONDITION_SIGNED_GREATER, 0, ">s");
    check(050, 100, `OP_CONDITION_SIGNED_GREATER, 0, ">s");
    check(150, 175, `OP_CONDITION_SIGNED_GREATER, 0, ">s");
    check(175, 150, `OP_CONDITION_SIGNED_GREATER, 1, ">s");
    check(200, 010, `OP_CONDITION_SIGNED_GREATER, 0, ">s");
    check(001, 002, `OP_CONDITION_SIGNED_LESS_OR_EQUAL, 1, "<=s");
    check(127, 127, `OP_CONDITION_SIGNED_LESS_OR_EQUAL, 1, "<=s");
    check(128, 127, `OP_CONDITION_SIGNED_LESS_OR_EQUAL, 1, "<=s");
    check(128, 128, `OP_CONDITION_SIGNED_LESS_OR_EQUAL, 1, "<=s");
    check(100, 050, `OP_CONDITION_SIGNED_GREATER_OR_EQUAL, 1, ">=s");
    check(050, 100, `OP_CONDITION_SIGNED_GREATER_OR_EQUAL, 0, ">=s");
    check(128, 128, `OP_CONDITION_SIGNED_GREATER_OR_EQUAL, 1, ">=s");
    check(130, 150, `OP_CONDITION_SIGNED_GREATER_OR_EQUAL, 0, ">=s");
    check(150, 130, `OP_CONDITION_SIGNED_GREATER_OR_EQUAL, 1, ">=s");
    check(128, 127, `OP_CONDITION_SIGNED_LESS, 1, "<s");
    check(127, 128, `OP_CONDITION_SIGNED_LESS, 0, "<s");
    check(100, 050, `OP_CONDITION_SIGNED_LESS, 0, "<s");
    check(100, 100, `OP_CONDITION_SIGNED_LESS, 0, "<s");
    check(050, 100, `OP_CONDITION_SIGNED_LESS, 1, "<s");
    check(150, 175, `OP_CONDITION_SIGNED_LESS, 1, "<s");
    check(175, 150, `OP_CONDITION_SIGNED_LESS, 0, "<s");
    check(200, 010, `OP_CONDITION_SIGNED_LESS, 1, "<s");

    aluFunc = `OP_ALU_ADD;
    check(127, 127, `OP_CONDITION_OVERFLOW, 1, "+overflow");
    check(10, 10, `OP_CONDITION_OVERFLOW, 0, "+overflow");
    check(127, 127, `OP_CONDITION_NO_OVERFLOW, 0, "+overflow");
    check(10, 10, `OP_CONDITION_NO_OVERFLOW, 1, "+overflow");

    check(0, 0, `OP_CONDITION_ALWAYS, 1, "always");
    check(0, 0, `OP_CONDITION_NEVER, 0, "never");

    $finish;
  end
endmodule