data/full_repos/permissive/167856740/cpu/decode.v
[Errno 2] No such file or directory: 'preprocess.output'
1: b'%Error: data/full_repos/permissive/167856740/cpu/decode.v:4: Cannot find include file: general_definitions.vh\n`include "general_definitions.vh" \n         ^~~~~~~~~~~~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/167856740/cpu,data/full_repos/permissive/167856740/general_definitions.vh\n             data/full_repos/permissive/167856740/cpu,data/full_repos/permissive/167856740/general_definitions.vh.v\n             data/full_repos/permissive/167856740/cpu,data/full_repos/permissive/167856740/general_definitions.vh.sv\n             general_definitions.vh\n             general_definitions.vh.v\n             general_definitions.vh.sv\n             obj_dir/general_definitions.vh\n             obj_dir/general_definitions.vh.v\n             obj_dir/general_definitions.vh.sv\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:28: Define or directive not defined: \'`OP_LUI\'\n                {6\'b???,`OP_LUI}:                  $display("\\nThe current instruction is LUI");\n                        ^~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:28: syntax error, unexpected \'}\', expecting TYPE-IDENTIFIER\n                {6\'b???,`OP_LUI}:                  $display("\\nThe current instruction is LUI");\n                               ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:29: Define or directive not defined: \'`OP_AUIPC\'\n                {6\'b???,`OP_AUIPC}:                $display("\\nThe current instruction is AUIPC");\n                        ^~~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:29: syntax error, unexpected \'}\', expecting TYPE-IDENTIFIER\n                {6\'b???,`OP_AUIPC}:                $display("\\nThe current instruction is AUIPC");\n                                 ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:31: Define or directive not defined: \'`OP_JAL\'\n                {6\'b???,`OP_JAL}:                  $display("\\nThe current instruction is JAL");\n                        ^~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:31: syntax error, unexpected \'}\', expecting TYPE-IDENTIFIER\n                {6\'b???,`OP_JAL}:                  $display("\\nThe current instruction is JAL");\n                               ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:32: Define or directive not defined: \'`OP_JALR\'\n                {6\'b???,`OP_JALR}:                 $display("\\nThe current instruction is JALR");\n                        ^~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:32: syntax error, unexpected \'}\', expecting TYPE-IDENTIFIER\n                {6\'b???,`OP_JALR}:                 $display("\\nThe current instruction is JALR");\n                                ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:34: Define or directive not defined: \'`FUNC_BEQ\'\n                {3\'b???,`FUNC_BEQ,`OP_BEQ}:        $display("\\nThe current instruction is BEQ");\n                        ^~~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:34: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_BEQ,`OP_BEQ}:        $display("\\nThe current instruction is BEQ");\n                                 ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:34: Define or directive not defined: \'`OP_BEQ\'\n                {3\'b???,`FUNC_BEQ,`OP_BEQ}:        $display("\\nThe current instruction is BEQ");\n                                  ^~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:35: Define or directive not defined: \'`FUNC_BNE\'\n                {3\'b???,`FUNC_BNE,`OP_BNE}:        $display("\\nThe current instruction is BNE");\n                        ^~~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:35: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_BNE,`OP_BNE}:        $display("\\nThe current instruction is BNE");\n                                 ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:35: Define or directive not defined: \'`OP_BNE\'\n                {3\'b???,`FUNC_BNE,`OP_BNE}:        $display("\\nThe current instruction is BNE");\n                                  ^~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:36: Define or directive not defined: \'`FUNC_BLT\'\n                {3\'b???,`FUNC_BLT,`OP_BLT}:        $display("\\nThe current instruction is BLT");\n                        ^~~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:36: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_BLT,`OP_BLT}:        $display("\\nThe current instruction is BLT");\n                                 ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:36: Define or directive not defined: \'`OP_BLT\'\n                {3\'b???,`FUNC_BLT,`OP_BLT}:        $display("\\nThe current instruction is BLT");\n                                  ^~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:37: Define or directive not defined: \'`FUNC_BGE\'\n                {3\'b???,`FUNC_BGE,`OP_BGE}:        $display("\\nThe current instruction is BGE");\n                        ^~~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:37: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_BGE,`OP_BGE}:        $display("\\nThe current instruction is BGE");\n                                 ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:37: Define or directive not defined: \'`OP_BGE\'\n                {3\'b???,`FUNC_BGE,`OP_BGE}:        $display("\\nThe current instruction is BGE");\n                                  ^~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:38: Define or directive not defined: \'`FUNC_BLTU\'\n                {3\'b???,`FUNC_BLTU,`OP_BLTU}:      $display("\\nThe current instruction is BLTU");\n                        ^~~~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:38: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_BLTU,`OP_BLTU}:      $display("\\nThe current instruction is BLTU");\n                                  ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:38: Define or directive not defined: \'`OP_BLTU\'\n                {3\'b???,`FUNC_BLTU,`OP_BLTU}:      $display("\\nThe current instruction is BLTU");\n                                   ^~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:39: Define or directive not defined: \'`FUNC_BLTU\'\n                {3\'b???,`FUNC_BLTU,`OP_BGEU}:      $display("\\nThe current instruction is BGEU");\n                        ^~~~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:39: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_BLTU,`OP_BGEU}:      $display("\\nThe current instruction is BGEU");\n                                  ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:39: Define or directive not defined: \'`OP_BGEU\'\n                {3\'b???,`FUNC_BLTU,`OP_BGEU}:      $display("\\nThe current instruction is BGEU");\n                                   ^~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:41: Define or directive not defined: \'`FUNC_LB\'\n                {3\'b???,`FUNC_LB,`OP_LB}:          $display("\\nThe current instruction is LB");\n                        ^~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:41: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_LB,`OP_LB}:          $display("\\nThe current instruction is LB");\n                                ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:41: Define or directive not defined: \'`OP_LB\'\n                {3\'b???,`FUNC_LB,`OP_LB}:          $display("\\nThe current instruction is LB");\n                                 ^~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:42: Define or directive not defined: \'`FUNC_LH\'\n                {3\'b???,`FUNC_LH,`OP_LH}:          $display("\\nThe current instruction is LH");\n                        ^~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:42: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_LH,`OP_LH}:          $display("\\nThe current instruction is LH");\n                                ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:42: Define or directive not defined: \'`OP_LH\'\n                {3\'b???,`FUNC_LH,`OP_LH}:          $display("\\nThe current instruction is LH");\n                                 ^~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:43: Define or directive not defined: \'`FUNC_LW\'\n                {3\'b???,`FUNC_LW,`OP_LW}:          $display("\\nThe current instruction is LW");\n                        ^~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:43: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_LW,`OP_LW}:          $display("\\nThe current instruction is LW");\n                                ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:43: Define or directive not defined: \'`OP_LW\'\n                {3\'b???,`FUNC_LW,`OP_LW}:          $display("\\nThe current instruction is LW");\n                                 ^~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:44: Define or directive not defined: \'`FUNC_LBU\'\n                {3\'b???,`FUNC_LBU,`OP_LBU}:        $display("\\nThe current instruction is LBU");\n                        ^~~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:44: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_LBU,`OP_LBU}:        $display("\\nThe current instruction is LBU");\n                                 ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:44: Define or directive not defined: \'`OP_LBU\'\n                {3\'b???,`FUNC_LBU,`OP_LBU}:        $display("\\nThe current instruction is LBU");\n                                  ^~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:45: Define or directive not defined: \'`FUNC_LHU\'\n                {3\'b???,`FUNC_LHU,`OP_LHU}:        $display("\\nThe current instruction is LHU");\n                        ^~~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:45: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_LHU,`OP_LHU}:        $display("\\nThe current instruction is LHU");\n                                 ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:45: Define or directive not defined: \'`OP_LHU\'\n                {3\'b???,`FUNC_LHU,`OP_LHU}:        $display("\\nThe current instruction is LHU");\n                                  ^~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:47: Define or directive not defined: \'`FUNC_SB\'\n                {3\'b???,`FUNC_SB,`OP_SB}:          $display("\\nThe current instruction is SB");\n                        ^~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:47: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_SB,`OP_SB}:          $display("\\nThe current instruction is SB");\n                                ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:47: Define or directive not defined: \'`OP_SB\'\n                {3\'b???,`FUNC_SB,`OP_SB}:          $display("\\nThe current instruction is SB");\n                                 ^~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:48: Define or directive not defined: \'`FUNC_SH\'\n                {3\'b???,`FUNC_SH,`OP_SH}:          $display("\\nThe current instruction is SH");\n                        ^~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:48: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_SH,`OP_SH}:          $display("\\nThe current instruction is SH");\n                                ^\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:48: Define or directive not defined: \'`OP_SH\'\n                {3\'b???,`FUNC_SH,`OP_SH}:          $display("\\nThe current instruction is SH");\n                                 ^~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:49: Define or directive not defined: \'`FUNC_SW\'\n                {3\'b???,`FUNC_SW,`OP_SW}:          $display("\\nThe current instruction is SW");\n                        ^~~~~~~~\n%Error: data/full_repos/permissive/167856740/cpu/decode.v:49: syntax error, unexpected \',\', expecting TYPE-IDENTIFIER\n                {3\'b???,`FUNC_SW,`OP_SW}:          $display("\\nThe current instruction is SW");\n                                ^\n%Error: Exiting due to too many errors encountered; --error-limit=50\n'
module decode(
    input wire [31:0] I_data,
    output reg [31:0] O_pcincr,
    output reg [31:0] O_data,
    output reg O_illegalflag
    );
    
    always @(*) begin

        O_illegalflag = 0;
    

        if(I_data == 32'h00000000) begin
            O_illegalflag = 1;
        end
        

        if(I_data[1:0] == 2'b11) begin
            $display("This is a 32 bit instruction");
            

            casez({I_data[30],I_data[21:20],I_data[14:12],I_data[6:0]})
                {6'b???,`OP_LUI}:                  $display("\nThe current instruction is LUI");
                {6'b???,`OP_AUIPC}:                $display("\nThe current instruction is AUIPC");
                
                {6'b???,`OP_JAL}:                  $display("\nThe current instruction is JAL");
                {6'b???,`OP_JALR}:                 $display("\nThe current instruction is JALR");
        
                {3'b???,`FUNC_BEQ,`OP_BEQ}:        $display("\nThe current instruction is BEQ");
                {3'b???,`FUNC_BNE,`OP_BNE}:        $display("\nThe current instruction is BNE");
                {3'b???,`FUNC_BLT,`OP_BLT}:        $display("\nThe current instruction is BLT");
                {3'b???,`FUNC_BGE,`OP_BGE}:        $display("\nThe current instruction is BGE");
                {3'b???,`FUNC_BLTU,`OP_BLTU}:      $display("\nThe current instruction is BLTU");
                {3'b???,`FUNC_BLTU,`OP_BGEU}:      $display("\nThe current instruction is BGEU");
        
                {3'b???,`FUNC_LB,`OP_LB}:          $display("\nThe current instruction is LB");
                {3'b???,`FUNC_LH,`OP_LH}:          $display("\nThe current instruction is LH");
                {3'b???,`FUNC_LW,`OP_LW}:          $display("\nThe current instruction is LW");
                {3'b???,`FUNC_LBU,`OP_LBU}:        $display("\nThe current instruction is LBU");
                {3'b???,`FUNC_LHU,`OP_LHU}:        $display("\nThe current instruction is LHU");
        
                {3'b???,`FUNC_SB,`OP_SB}:          $display("\nThe current instruction is SB");
                {3'b???,`FUNC_SH,`OP_SH}:          $display("\nThe current instruction is SH");
                {3'b???,`FUNC_SW,`OP_SW}:          $display("\nThe current instruction is SW");
        
                {3'b???,`FUNC_ADDI,`OP_ADDI}:      $display("\nThe current instruction is ADDI");
                {3'b???,`FUNC_SLTI,`OP_SLTI}:      $display("\nThe current instruction is SLTI");
                {3'b???,`FUNC_SLTIU,`OP_SLTIU}:    $display("\nThe current instruction is SLTIU");
                {3'b???,`FUNC_XORI,`OP_XORI}:      $display("\nThe current instruction is XORI");
                {3'b???,`FUNC_ORI,`OP_ORI}:        $display("\nThe current instruction is ORI");
                {3'b???,`FUNC_ANDI,`OP_ANDI}:      $display("\nThe current instruction is ANDI");
                {3'b???,`FUNC_SLLI,`OP_SLLI}:      $display("\nThe current instruction is SLLI");
                {3'b???,`FUNC_SRLI,`OP_SRLI}:      $display("\nThe current instruction is SRLI");
                {3'b???,`FUNC_SRAI,`OP_SRAI}:      $display("\nThe current instruction is SRAI");
        
                {3'b???,`FUNC_AND,`OP_ADD}:        $display("\nThe current instruction is ADD");
                {3'b???,`FUNC_SUB,`OP_SUB}:        $display("\nThe current instruction is SUB");
                {3'b???,`FUNC_SLL,`OP_SLL}:        $display("\nThe current instruction is SLL");
                {3'b???,`FUNC_SLT,`OP_SLT}:        $display("\nThe current instruction is SLT");
                {3'b???,`FUNC_SLTU,`OP_SLTU}:      $display("\nThe current instruction is SLT");
                {3'b???,`FUNC_XOR,`OP_XOR}:        $display("\nThe current instruction is XOR");
                {3'b???,`FUNC_SRL,`OP_SRL}:        $display("\nThe current instruction is SRL");
                {3'b???,`FUNC_SRA,`OP_SRA}:        $display("\nThe current instruction is SRA");
                {3'b???,`FUNC_OR,`OP_OR}:          $display("\nThe current instruction is OR");
                {3'b???,`FUNC_AND,`OP_AND}:        $display("\nThe current instruction is AND");
        
                {3'b000,`FUNC_ECALL,`OP_ECALL}:    $display("\nThe current instruction is ECALL");
                {3'b001,`FUNC_EBREAK,`OP_EBREAK}:  $display("\nThe current instruction is EBREAK");
                
                {3'b???,`FUNC_CSRRW,`OP_CSRRW}:    $display("\nThe current instruction is CSRRW");
                {3'b010,`FUNC_MRET,`OP_MRET}:      $display("\nThe current instruction is MRET");
                default:                           $display("\nUNKNOWN INSTRUCTION: %b", {I_data[14:12],I_data[6:0]});
            endcase


            O_pcincr = 32'h00000004;


            if(I_data[6:0] == 7'b0001111) begin
                O_data = {12'b000000000000,`X0,`FUNC_ADDI,`X0,`OP_ADDI};
            end
            else begin
                O_data = I_data;  
            end
        end
        else begin

            O_pcincr = 32'h00000002;
            

            if(I_data[1:0] == 2'b00) begin

                if(I_data[15:13] == 3'b000) begin

                    $display("\nThe current instruction is C.ADDI4SPN");
                    O_data = {{2'b00,I_data[10:7],I_data[12:11],I_data[5],I_data[6],2'b00},`X2,`FUNC_ADDI,{2'b01,I_data[4:2]},`OP_ADDI};
                end
                else if(I_data[15:13] == 3'b010) begin

                    $display("\nThe current instruction is C.LW");
                    O_data = {{5'b00000,I_data[5],I_data[12:10],I_data[6],2'b00},{2'b01,I_data[9:7]},`FUNC_LW,{2'b01,I_data[4:2]},`OP_LW};
                end
                else if(I_data[15:13] == 3'b110) begin

                    $display("\nThe current instruction is C.SW");
                    O_data = {{5'b00000,I_data[5],I_data[12]},{2'b01,I_data[4:2]},{2'b01,I_data[9:7]},`FUNC_SW,{I_data[11:10],I_data[6],2'b00},`OP_SW};
                end                
                else begin

                    O_illegalflag = 1;

                end
                $display("Quadrant 0 - 16 bit instruction"); 
            end
            else if(I_data[1:0] == 2'b01) begin

                if(I_data[15:13] == 3'b000) begin

                    $display("\nThe current instruction is C.ADDI");
                    O_data = {{{6{I_data[12]}},I_data[12],I_data[6:2]},I_data[11:7],`FUNC_ADDI,I_data[11:7],`OP_ADDI};
                end
                else if(I_data[15:13] == 3'b001) begin

                    $display("\nThe current instruction is C.JAL");
                    O_data = {I_data[12],{I_data[8],I_data[10:9],I_data[6],I_data[7],I_data[2],I_data[11],I_data[5:3]},I_data[12],{8{I_data[12]}},`X1,`OP_JAL};
                end
                else if(I_data[15:13] == 3'b010) begin

                    $display("\nThe current instruction is C.LI");
                    O_data = {{{6{I_data[12]}},I_data[12],I_data[6:2]},`X0,`FUNC_ADDI,I_data[11:7],`OP_ADDI};
                end
                else if(I_data[15:13] == 3'b011) begin
                    if(I_data[11:7] == `X2) begin

                        $display("\nThe current instruction is C.ADDI16SP");
                        O_data = {{{2{I_data[12]}},I_data[12],I_data[4:3],I_data[5],I_data[2],I_data[6],4'b0000},`X2,`FUNC_ADDI,`X2,`OP_ADDI};
                    end
                    else begin

                        $display("\nThe current instruction is C.LUI");
                        O_data = {{{2{I_data[12]}},I_data[12],I_data[6:2],12'b000000000000},I_data[11:7],`OP_LUI};
                    end
                end
                else if(I_data[15:13] == 3'b100) begin
                    if(I_data[11:10] == 2'b00) begin

                        $display("\nThe current instruction is C.SRLI");
                        O_data = {7'b0000000,I_data[6:2],{2'b01,I_data[9:7]},`FUNC_SRLI,{2'b01,I_data[9:7]},`OP_SRLI};
                    end
                    else if(I_data[11:10] == 2'b01) begin

                        $display("\nThe current instruction is C.SRAI");
                        O_data = {7'b0100000,I_data[6:2],{2'b01,I_data[9:7]},`FUNC_SRAI,{2'b01,I_data[9:7]},`OP_SRAI};
                    end
                    else if(I_data[11:10] == 2'b10) begin

                        $display("\nThe current instruction is C.ANDI");
                        O_data = {{{6{I_data[12]}},I_data[12],I_data[6:2]},{2'b01,I_data[9:7]},`FUNC_ANDI,{2'b01,I_data[9:7]},`OP_ANDI};
                    end
                    else begin
                        if(I_data[6:5] == 2'b00) begin

                            $display("\nThe current instruction is C.SUB");
                            O_data = {7'b0100000,{2'b01,I_data[9:7]},`FUNC_SUB,{2'b01,I_data[9:7]},`OP_SUB};
                        end 
                        else if(I_data[6:5] == 2'b00) begin

                            $display("\nThe current instruction is C.XOR");
                            O_data = {7'b0000000,{2'b01,I_data[9:7]},`FUNC_XOR,{2'b01,I_data[9:7]},`OP_XOR};
                        end  
                        else if(I_data[6:5] == 2'b00) begin

                            $display("\nThe current instruction is C.OR");
                            O_data = {7'b0000000,{2'b01,I_data[9:7]},`FUNC_OR,{2'b01,I_data[9:7]},`OP_OR};
                        end 
                        else begin

                            $display("\nThe current instruction is C.AND");
                            O_data = {7'b0000000,{2'b01,I_data[9:7]},`FUNC_AND,{2'b01,I_data[9:7]},`OP_AND};
                        end  
                    end
                end
                else if(I_data[15:13] == 3'b101) begin

                    $display("\nThe current instruction is C.J");
                    O_data = {I_data[12],{I_data[8],I_data[10:9],I_data[6],I_data[7],I_data[2],I_data[11],I_data[5:3]},I_data[12],{8{I_data[12]}},`X0,`OP_JAL};
                end
                else if(I_data[15:13] == 3'b110) begin

                    $display("\nThe current instruction is C.BEQZ");
                    O_data = {{{3{I_data[12]}},I_data[12],I_data[6:5],I_data[2]},`X0,{2'b01,I_data[9:7]},`FUNC_BEQ,{I_data[11:10],I_data[4:3],1'b0},`OP_BEQ};
                end
                else if(I_data[15:13] == 3'b111) begin

                    $display("\nThe current instruction is C.BNEZ");
                    O_data = {{{3{I_data[12]}},I_data[12],I_data[6:5],I_data[2]},`X0,{2'b01,I_data[9:7]},`FUNC_BNE,{I_data[11:10],I_data[4:3],1'b0},`OP_BNE};
                end                                
                else begin

                    O_illegalflag = 1;

                end
                $display("Quadrant 1 - 16 bit instruction");
            end
            else begin

                if(I_data[15:13] == 3'b000) begin

                    $display("\nThe current instruction is C.SLLI");
                    O_data = {7'b0000000,I_data[12],I_data[6:2],I_data[11:7],`FUNC_SLLI,I_data[11:7],`OP_SLLI};
                end
                else if(I_data[15:13] == 3'b010) begin

                    $display("\nThe current instruction is C.LWSP");
                    O_data = {{4'b0000,I_data[3:2],I_data[12],I_data[6:4],2'b00},`X2,`FUNC_LW,{I_data[11:7]},`OP_LW};
                end
                else if(I_data[15:13] == 3'b100) begin
                    if(I_data[12] == 1'b0) begin
                        if(I_data[6:2] == `ZERO) begin

                            $display("\nThe current instruction is C.JR");
                            O_data = {12'b000000000000,I_data[11:7],`FUNC_JALR,`X0,`OP_JALR};
                        end
                        else begin

                            $display("\nThe current instruction is C.MV");
                            O_data = {7'b0000000,I_data[6:2],`X0,`FUNC_ADD,I_data[11:7],`OP_ADD};                      
                        end
                    end
                    else begin
                        if(I_data[6:2] == `ZERO) begin
                            if(I_data[11:7] == `ZERO) begin

                                $display("\nThe current instruction is C.EBREAK");
                                O_data = {12'b000000000001,`ZERO,`FUNC_EBREAK,`ZERO,`OP_EBREAK};        
                            end
                            else begin

                                $display("\nThe current instruction is C.JALR");
                                O_data = {12'b000000000000,I_data[11:7],`FUNC_JALR,`X1,`OP_JALR};
                            end
                        end
                        else begin

                            $display("\nThe current instruction is C.ADD");
                            O_data = {7'b0000000,I_data[6:2],I_data[11:7],`FUNC_ADD,I_data[11:7],`OP_ADD};                        
                        end
                    end
                end
                else if(I_data[15:13] == 3'b110) begin

                    $display("\nThe current instruction is C.SWSP");
                    O_data = {{4'b0000,I_data[8:7],I_data[12]},I_data[6:2],`X2,`FUNC_SW,{I_data[11:9],2'b00},`OP_SW};
                end
                else begin
                    $display("\nError instruction not found\ %b", I_data);

                    O_illegalflag = 1;

                end
                $display("Quadrant 2 - 16 bit instruction");
            end     
        end
    end
endmodule
module decode(
    input wire [31:0] I_data,
    output reg [31:0] O_pcincr,
    output reg [31:0] O_data,
    output reg O_illegalflag
    );

    
    always @(*) begin

        O_illegalflag = 0;
    

        if(I_data == 32'h00000000) begin
            O_illegalflag = 1;
        end
        

        if(I_data[1:0] == 2'b11) begin
            $display("This is a 32 bit instruction");
            

            casez({I_data[30],I_data[21:20],I_data[14:12],I_data[6:0]})
                {6'b???,`OP_LUI}:                  $display("\nThe current instruction is LUI");
                {6'b???,`OP_AUIPC}:                $display("\nThe current instruction is AUIPC");
                
                {6'b???,`OP_JAL}:                  $display("\nThe current instruction is JAL");
                {6'b???,`OP_JALR}:                 $display("\nThe current instruction is JALR");
        
                {3'b???,`FUNC_BEQ,`OP_BEQ}:        $display("\nThe current instruction is BEQ");
                {3'b???,`FUNC_BNE,`OP_BNE}:        $display("\nThe current instruction is BNE");
                {3'b???,`FUNC_BLT,`OP_BLT}:        $display("\nThe current instruction is BLT");
                {3'b???,`FUNC_BGE,`OP_BGE}:        $display("\nThe current instruction is BGE");
                {3'b???,`FUNC_BLTU,`OP_BLTU}:      $display("\nThe current instruction is BLTU");
                {3'b???,`FUNC_BLTU,`OP_BGEU}:      $display("\nThe current instruction is BGEU");
        
                {3'b???,`FUNC_LB,`OP_LB}:          $display("\nThe current instruction is LB");
                {3'b???,`FUNC_LH,`OP_LH}:          $display("\nThe current instruction is LH");
                {3'b???,`FUNC_LW,`OP_LW}:          $display("\nThe current instruction is LW");
                {3'b???,`FUNC_LBU,`OP_LBU}:        $display("\nThe current instruction is LBU");
                {3'b???,`FUNC_LHU,`OP_LHU}:        $display("\nThe current instruction is LHU");
        
                {3'b???,`FUNC_SB,`OP_SB}:          $display("\nThe current instruction is SB");
                {3'b???,`FUNC_SH,`OP_SH}:          $display("\nThe current instruction is SH");
                {3'b???,`FUNC_SW,`OP_SW}:          $display("\nThe current instruction is SW");
        
                {3'b???,`FUNC_ADDI,`OP_ADDI}:      $display("\nThe current instruction is ADDI");
                {3'b???,`FUNC_SLTI,`OP_SLTI}:      $display("\nThe current instruction is SLTI");
                {3'b???,`FUNC_SLTIU,`OP_SLTIU}:    $display("\nThe current instruction is SLTIU");
                {3'b???,`FUNC_XORI,`OP_XORI}:      $display("\nThe current instruction is XORI");
                {3'b???,`FUNC_ORI,`OP_ORI}:        $display("\nThe current instruction is ORI");
                {3'b???,`FUNC_ANDI,`OP_ANDI}:      $display("\nThe current instruction is ANDI");
                {3'b???,`FUNC_SLLI,`OP_SLLI}:      $display("\nThe current instruction is SLLI");
                {3'b???,`FUNC_SRLI,`OP_SRLI}:      $display("\nThe current instruction is SRLI");
                {3'b???,`FUNC_SRAI,`OP_SRAI}:      $display("\nThe current instruction is SRAI");
        
                {3'b???,`FUNC_AND,`OP_ADD}:        $display("\nThe current instruction is ADD");
                {3'b???,`FUNC_SUB,`OP_SUB}:        $display("\nThe current instruction is SUB");
                {3'b???,`FUNC_SLL,`OP_SLL}:        $display("\nThe current instruction is SLL");
                {3'b???,`FUNC_SLT,`OP_SLT}:        $display("\nThe current instruction is SLT");
                {3'b???,`FUNC_SLTU,`OP_SLTU}:      $display("\nThe current instruction is SLT");
                {3'b???,`FUNC_XOR,`OP_XOR}:        $display("\nThe current instruction is XOR");
                {3'b???,`FUNC_SRL,`OP_SRL}:        $display("\nThe current instruction is SRL");
                {3'b???,`FUNC_SRA,`OP_SRA}:        $display("\nThe current instruction is SRA");
                {3'b???,`FUNC_OR,`OP_OR}:          $display("\nThe current instruction is OR");
                {3'b???,`FUNC_AND,`OP_AND}:        $display("\nThe current instruction is AND");
        
                {3'b000,`FUNC_ECALL,`OP_ECALL}:    $display("\nThe current instruction is ECALL");
                {3'b001,`FUNC_EBREAK,`OP_EBREAK}:  $display("\nThe current instruction is EBREAK");
                
                {3'b???,`FUNC_CSRRW,`OP_CSRRW}:    $display("\nThe current instruction is CSRRW");
                {3'b010,`FUNC_MRET,`OP_MRET}:      $display("\nThe current instruction is MRET");
                default:                           $display("\nUNKNOWN INSTRUCTION: %b", {I_data[14:12],I_data[6:0]});
            endcase


            O_pcincr = 32'h00000004;


            if(I_data[6:0] == 7'b0001111) begin
                O_data = {12'b000000000000,`X0,`FUNC_ADDI,`X0,`OP_ADDI};
            end
            else begin
                O_data = I_data;  
            end
        end
        else begin

            O_pcincr = 32'h00000002;
            

            if(I_data[1:0] == 2'b00) begin

                if(I_data[15:13] == 3'b000) begin

                    $display("\nThe current instruction is C.ADDI4SPN");
                    O_data = {{2'b00,I_data[10:7],I_data[12:11],I_data[5],I_data[6],2'b00},`X2,`FUNC_ADDI,{2'b01,I_data[4:2]},`OP_ADDI};
                end
                else if(I_data[15:13] == 3'b010) begin

                    $display("\nThe current instruction is C.LW");
                    O_data = {{5'b00000,I_data[5],I_data[12:10],I_data[6],2'b00},{2'b01,I_data[9:7]},`FUNC_LW,{2'b01,I_data[4:2]},`OP_LW};
                end
                else if(I_data[15:13] == 3'b110) begin

                    $display("\nThe current instruction is C.SW");
                    O_data = {{5'b00000,I_data[5],I_data[12]},{2'b01,I_data[4:2]},{2'b01,I_data[9:7]},`FUNC_SW,{I_data[11:10],I_data[6],2'b00},`OP_SW};
                end                
                else begin

                    O_illegalflag = 1;

                end
                $display("Quadrant 0 - 16 bit instruction"); 
            end
            else if(I_data[1:0] == 2'b01) begin

                if(I_data[15:13] == 3'b000) begin

                    $display("\nThe current instruction is C.ADDI");
                    O_data = {{{6{I_data[12]}},I_data[12],I_data[6:2]},I_data[11:7],`FUNC_ADDI,I_data[11:7],`OP_ADDI};
                end
                else if(I_data[15:13] == 3'b001) begin

                    $display("\nThe current instruction is C.JAL");
                    O_data = {I_data[12],{I_data[8],I_data[10:9],I_data[6],I_data[7],I_data[2],I_data[11],I_data[5:3]},I_data[12],{8{I_data[12]}},`X1,`OP_JAL};
                end
                else if(I_data[15:13] == 3'b010) begin

                    $display("\nThe current instruction is C.LI");
                    O_data = {{{6{I_data[12]}},I_data[12],I_data[6:2]},`X0,`FUNC_ADDI,I_data[11:7],`OP_ADDI};
                end
                else if(I_data[15:13] == 3'b011) begin
                    if(I_data[11:7] == `X2) begin

                        $display("\nThe current instruction is C.ADDI16SP");
                        O_data = {{{2{I_data[12]}},I_data[12],I_data[4:3],I_data[5],I_data[2],I_data[6],4'b0000},`X2,`FUNC_ADDI,`X2,`OP_ADDI};
                    end
                    else begin

                        $display("\nThe current instruction is C.LUI");
                        O_data = {{{2{I_data[12]}},I_data[12],I_data[6:2],12'b000000000000},I_data[11:7],`OP_LUI};
                    end
                end
                else if(I_data[15:13] == 3'b100) begin
                    if(I_data[11:10] == 2'b00) begin

                        $display("\nThe current instruction is C.SRLI");
                        O_data = {7'b0000000,I_data[6:2],{2'b01,I_data[9:7]},`FUNC_SRLI,{2'b01,I_data[9:7]},`OP_SRLI};
                    end
                    else if(I_data[11:10] == 2'b01) begin

                        $display("\nThe current instruction is C.SRAI");
                        O_data = {7'b0100000,I_data[6:2],{2'b01,I_data[9:7]},`FUNC_SRAI,{2'b01,I_data[9:7]},`OP_SRAI};
                    end
                    else if(I_data[11:10] == 2'b10) begin

                        $display("\nThe current instruction is C.ANDI");
                        O_data = {{{6{I_data[12]}},I_data[12],I_data[6:2]},{2'b01,I_data[9:7]},`FUNC_ANDI,{2'b01,I_data[9:7]},`OP_ANDI};
                    end
                    else begin
                        if(I_data[6:5] == 2'b00) begin

                            $display("\nThe current instruction is C.SUB");
                            O_data = {7'b0100000,{2'b01,I_data[9:7]},`FUNC_SUB,{2'b01,I_data[9:7]},`OP_SUB};
                        end 
                        else if(I_data[6:5] == 2'b00) begin

                            $display("\nThe current instruction is C.XOR");
                            O_data = {7'b0000000,{2'b01,I_data[9:7]},`FUNC_XOR,{2'b01,I_data[9:7]},`OP_XOR};
                        end  
                        else if(I_data[6:5] == 2'b00) begin

                            $display("\nThe current instruction is C.OR");
                            O_data = {7'b0000000,{2'b01,I_data[9:7]},`FUNC_OR,{2'b01,I_data[9:7]},`OP_OR};
                        end 
                        else begin

                            $display("\nThe current instruction is C.AND");
                            O_data = {7'b0000000,{2'b01,I_data[9:7]},`FUNC_AND,{2'b01,I_data[9:7]},`OP_AND};
                        end  
                    end
                end
                else if(I_data[15:13] == 3'b101) begin

                    $display("\nThe current instruction is C.J");
                    O_data = {I_data[12],{I_data[8],I_data[10:9],I_data[6],I_data[7],I_data[2],I_data[11],I_data[5:3]},I_data[12],{8{I_data[12]}},`X0,`OP_JAL};
                end
                else if(I_data[15:13] == 3'b110) begin

                    $display("\nThe current instruction is C.BEQZ");
                    O_data = {{{3{I_data[12]}},I_data[12],I_data[6:5],I_data[2]},`X0,{2'b01,I_data[9:7]},`FUNC_BEQ,{I_data[11:10],I_data[4:3],1'b0},`OP_BEQ};
                end
                else if(I_data[15:13] == 3'b111) begin

                    $display("\nThe current instruction is C.BNEZ");
                    O_data = {{{3{I_data[12]}},I_data[12],I_data[6:5],I_data[2]},`X0,{2'b01,I_data[9:7]},`FUNC_BNE,{I_data[11:10],I_data[4:3],1'b0},`OP_BNE};
                end                                
                else begin

                    O_illegalflag = 1;

                end
                $display("Quadrant 1 - 16 bit instruction");
            end
            else begin

                if(I_data[15:13] == 3'b000) begin

                    $display("\nThe current instruction is C.SLLI");
                    O_data = {7'b0000000,I_data[12],I_data[6:2],I_data[11:7],`FUNC_SLLI,I_data[11:7],`OP_SLLI};
                end
                else if(I_data[15:13] == 3'b010) begin

                    $display("\nThe current instruction is C.LWSP");
                    O_data = {{4'b0000,I_data[3:2],I_data[12],I_data[6:4],2'b00},`X2,`FUNC_LW,{I_data[11:7]},`OP_LW};
                end
                else if(I_data[15:13] == 3'b100) begin
                    if(I_data[12] == 1'b0) begin
                        if(I_data[6:2] == `ZERO) begin

                            $display("\nThe current instruction is C.JR");
                            O_data = {12'b000000000000,I_data[11:7],`FUNC_JALR,`X0,`OP_JALR};
                        end
                        else begin

                            $display("\nThe current instruction is C.MV");
                            O_data = {7'b0000000,I_data[6:2],`X0,`FUNC_ADD,I_data[11:7],`OP_ADD};                      
                        end
                    end
                    else begin
                        if(I_data[6:2] == `ZERO) begin
                            if(I_data[11:7] == `ZERO) begin

                                $display("\nThe current instruction is C.EBREAK");
                                O_data = {12'b000000000001,`ZERO,`FUNC_EBREAK,`ZERO,`OP_EBREAK};        
                            end
                            else begin

                                $display("\nThe current instruction is C.JALR");
                                O_data = {12'b000000000000,I_data[11:7],`FUNC_JALR,`X1,`OP_JALR};
                            end
                        end
                        else begin

                            $display("\nThe current instruction is C.ADD");
                            O_data = {7'b0000000,I_data[6:2],I_data[11:7],`FUNC_ADD,I_data[11:7],`OP_ADD};                        
                        end
                    end
                end
                else if(I_data[15:13] == 3'b110) begin

                    $display("\nThe current instruction is C.SWSP");
                    O_data = {{4'b0000,I_data[8:7],I_data[12]},I_data[6:2],`X2,`FUNC_SW,{I_data[11:9],2'b00},`OP_SW};
                end
                else begin
                    $display("\nError instruction not found\ %b", I_data);

                    O_illegalflag = 1;

                end
                $display("Quadrant 2 - 16 bit instruction");
            end     
        end
    end
endmodule