diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 12f9d243c..38d788750 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1081,15 +1081,31 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg, bool found_end = false; while (getline(istr, line)) { - ret << "\n"; if (line.compare(0, 14, "#pragma endasm") == 0) { found_end = true; break; } + + ret << "\n"; } if (!found_end) break; + + if (line.find("=") != std::string::npos) + { + Tokenizer tokenizer; + line.erase(0, sizeof("#pragma endasm")); + std::istringstream istr(line.c_str()); + tokenizer.tokenize(istr, ""); + if (Token::Match(tokenizer.tokens(), "( %var% = %any% )")) + { + ret << "asm(" << tokenizer.tokens()->strAt(1) << ");"; + } + } + + ret << "\n"; + continue; } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 41f91037b..3256ca87b 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -157,7 +157,8 @@ private: TEST_CASE(stringify5); TEST_CASE(ifdefwithfile); TEST_CASE(pragma); - TEST_CASE(pragma_asm); + TEST_CASE(pragma_asm_1); + TEST_CASE(pragma_asm_2); TEST_CASE(endifsemicolon); TEST_CASE(missing_doublequote); TEST_CASE(handle_error); @@ -1518,7 +1519,7 @@ private: ASSERT_EQUALS("\nvoid f()\n{\n}\n", actual[""]); } - void pragma_asm() + void pragma_asm_1() { const char filedata[] = "#pragma asm\n" " mov r1, 11\n" @@ -1540,6 +1541,24 @@ private: ASSERT_EQUALS("\n\n\naaa\n\n\n\nbbb\n", actual[""]); } + void pragma_asm_2() + { + const char filedata[] = "#pragma asm\n" + " mov @w1, 11\n" + "#pragma endasm ( temp=@w1 )\n" + "bbb"; + + // Preprocess => actual result.. + std::istringstream istr(filedata); + std::map actual; + Preprocessor preprocessor; + preprocessor.preprocess(istr, actual, "file.c"); + + // Compare results.. + ASSERT_EQUALS(1, static_cast(actual.size())); + ASSERT_EQUALS("\n\nasm(temp);\nbbb\n", actual[""]); + } + void endifsemicolon() { const char filedata[] = "void f()\n"