/*
 * Copyright 2025 Tadashi G. Takaoka
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "asm_tms320f.h"
#include "dis_tms320f.h"
#include "test_formatter_helper.h"

namespace libasm {
namespace driver {
namespace test {

void set_up() {}

void tear_down() {}

void test_asm_tms320f() {
    PREP_ASM(tms320f::AsmTms320f, IntelDirective);

    driver.setUpperHex(false);

    ASM("tms320c3x",
            R"(        .cpu  tms320c31
* comment line
        .org  1000h
        call  123456h
        addi3 *+ar1, *ar2++(ir0)b, r3
label:  .word label
        .byte 1,'''',3
        .space 1
        .string "A""B'C"
        negf  -5.0024, r0
        absf  *+ar0, r1
||      stf   r2, *-ar3
        mpyf3 *ar1, *ar2, r0
||      addf3 r4, r5, r2
)",
            R"(          0 :                            .cpu  tms320c31
          0 :                    * comment line
       1000 :                            .org  1000h
       1000 : 62123456                   call  123456h
       1001 : 2163ca01                   addi3 *+ar1, *ar2++(ir0)b, r3
       1002 : 00001002           label:  .word label
       1003 : 00000001 00000027          .byte 1,'''',3
       1005 : 00000003
       1006 :                            .space 1
       1007 : 27422241 00000043          .string "A""B'C"
       1009 : 0be02dff                   negf  -5.0024, r0
       100a : 00410001                   absf  *+ar0, r1
       100a : c8420b00           ||      stf   r2, *-ar3
       100b : 24e0c2c1                   mpyf3 *ar1, *ar2, r0
       100b : 802cc2c1           ||      addf3 r4, r5, r2
)");
}

void test_dis_tms320f() {
    PREP_DIS(tms320f::DisTms320f);

    driver.setUpperHex(false);

    DIS32("tms320c31", 0x1000,
            R"(      cpu      320c31
      org      001000h
      call     123456h
      addi3    *+ar1, *ar2++(ir0)b, r3
* test.bin: error: Unknown instruction
*     1002 : 788b0000
      negf     -0.50024, r0
      absf     *+ar0, r1
||    stf      r2, *-ar3
      mpyf3    *ar1, *ar2, r0
||    addf3    r4, r5, r2
)",
            R"(       0 :                            cpu      320c31
    1000 :                            org      001000h
    1000 : 62123456                   call     123456h
    1001 : 2163ca01                   addi3    *+ar1, *ar2++(ir0)b, r3
test.bin: error: Unknown instruction
    1002 : 788b0000
    1003 : 0be0ffff                   negf     -0.50024, r0
    1004 : c8420b00                   absf     *+ar0, r1
    1004 :                    ||      stf      r2, *-ar3
    1005 : 802cc2c1                   mpyf3    *ar1, *ar2, r0
    1005 :                    ||      addf3    r4, r5, r2
)",
          0x62123456, 0x2163CA01, 0x788B0000, 0x0BE0FFFF, 0xC8420B00, 0x802CC2C1);
}

void run_tests() {
    RUN_TEST(test_asm_tms320f);
    RUN_TEST(test_dis_tms320f);
}

}  // namespace test
}  // namespace driver
}  // namespace libasm

// Local Variables:
// mode: c++
// c-basic-offset: 4
// tab-width: 4
// End:
// vim: set ft=cpp et ts=4 sw=4:
