tum-ei-eda / M2-ISA-R

CoreDSL2 Parser with backend to generate simulation code for the ETISS instruction set simulator
https://tum-ei-eda.github.io/M2-ISA-R/
Apache License 2.0
5 stars 6 forks source link

Memory read inside if-statement not generating correct code #15

Closed maltevonehren closed 2 years ago

maltevonehren commented 2 years ago

Hello, I have noticed that a memory access placed inside of an if statement does not generate code for actually reading the memory.

A small example: This behavior describtion generates the following code:

behavior: {
    if ((signed<32>)MEM[0] > 0)
        X[1] = 1;
}
partInit.code() += "cpu->instructionPointer = " + std::to_string(ic.current_address_ + 4U) + ";\n";
partInit.code() += "if ((etiss_int32)(mem_val_0) > 0U) {\n";
partInit.code() += "*((RV32IMACFD*)cpu)->X[" + std::to_string(1U) + "] = 1U;\n";
partInit.code() += "}\n";

Where I would have expected it to generate the code below or throw an error.

partInit.code() += "cpu->instructionPointer = " + std::to_string(ic.current_address_ + 4U) + ";\n";
partInit.code() += "etiss_uint32 mem_val_0;\n";
partInit.code() += "exception |= (*(system->dread))(system->handle, cpu, " 
                                     + std::to_string(0U) + ", (etiss_uint8*)&mem_val_0, 4);\n";
partInit.code() += "if ((etiss_int32)(mem_val_0) > 0U) {\n";
partInit.code() += "*((RV32IMACFD*)cpu)->X[" + std::to_string(1U) + "] = 1U;\n";
partInit.code() += "}\n";

Thanks

wysiwyng commented 2 years ago

Should be fixed in https://github.com/tum-ei-eda/M2-ISA-R/commit/7d6cdf8ce624504f40923e9e1532e1afa61273c6, please test and verify.

maltevonehren commented 2 years ago

Works fine now. Thanks!