HiTech/Microchip C 的免费静态检查器?

发布于 2024-08-19 17:19:21 字数 1555 浏览 5 评论 0原文

我正在为 HiTech C 编译器编写大量代码。我确信我的代码会受益于像 splint 这样的静态检查器,但 splint 本身会在某些情况下出错HiTech 的扩展,如 cp0 和 sfr 声明。不过,我不能只是告诉 splint 跳过 HiTech 标头,因为那样它就不知道我的大部分标识符来自哪里。

有谁知道可以解决这个问题的静态检查器?

添加:扩展示例: 大多数情况下,它只是新类型限定符和绝对寻址,例如。

extern volatile cp0 unsigned int cp0_Config @ __REGADDR(16,0);
extern volatile sfr unsigned long OC2R @ 0xBF803210;

(还有persistent类型限定符。)

还有函数的interruptfast限定符:

void interrupt ExceptionHandler(void) @GENERAL_EXCEPTION
{
    ...
}

添加:

我终于开始尝试下面 Doug Currie 的方法。我使用带有 SED 的 shell 脚本来删除任何尾随的“... @ ...;”绝对定位声明,并运行 split

splint -D__32MX460F512L__ -Dsfr= -Dcp0= -Dmips32r2= -I ~/HiTechStripped mymodule.c

取决于模块,夹板抱怨:

< Location unknown >: Field name reused: 
  Code cannot be parsed.  For help on parse errors, see splint -help
  parseerrors. (Use -syntax to inhibit warning)
< Location unknown >: Previous use of 
< Location unknown >: Previous use of 
< Location unknown >: Previous use of
[this goes on for about 100 lines...]

在其他模块上,我得到:

../../../../HiTechStripped/stdlib.h:140:39: mismatched parentheses in #if
  Preprocessing error. (Use -preproc to inhibit warning)

据我所知,这是错误的:

#if defined(_XA_) && sizeof(double) == 8

我认为也许我应该放弃静态检查。感谢您的回答。

I'm writing a lot of code for the HiTech C compiler. I'm sure that my code would benefit from a static checker like splint, but splint itself trips up on some of HiTech's extensions, like cp0 and sfr declarations. I can't just tell splint to skip the HiTech headers, though, because then it has no idea where most of my identifiers are from.

Does anyone know of a static checker that can cope with this?

Added: examples of extensions:
Mostly it's just new type qualifiers and absolute addressing, eg.

extern volatile cp0 unsigned int cp0_Config @ __REGADDR(16,0);
extern volatile sfr unsigned long OC2R @ 0xBF803210;

(There's also the persistent type qualifier.)

There are also the interrupt and fast qualifiers for functions:

void interrupt ExceptionHandler(void) @GENERAL_EXCEPTION
{
    ...
}

Added:

I finally got around to trying Doug Currie's approach below. I used a shell script with SED to strip out any trailing "... @ ...;" absolute positioning declarations, and ran split with

splint -D__32MX460F512L__ -Dsfr= -Dcp0= -Dmips32r2= -I ~/HiTechStripped mymodule.c

Depending on the module, splint complains:

< Location unknown >: Field name reused: 
  Code cannot be parsed.  For help on parse errors, see splint -help
  parseerrors. (Use -syntax to inhibit warning)
< Location unknown >: Previous use of 
< Location unknown >: Previous use of 
< Location unknown >: Previous use of
[this goes on for about 100 lines...]

On other modules, I get:

../../../../HiTechStripped/stdlib.h:140:39: mismatched parentheses in #if
  Preprocessing error. (Use -preproc to inhibit warning)

It's wrong about this, as far as I can tell:

#if defined(_XA_) && sizeof(double) == 8

I think perhaps I should give up on the static checking. Thanks for the answers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

依 靠 2024-08-26 17:19:21

一种解决方法是创建新的头文件,声明 HiTech 头中的标识符,并且仅与夹板一起使用。这对于我使用 HiTech PIC18 编译器很有用。一旦找到需要进行的替换,您应该能够自动生成备用标头。

One workaround is to create new header files that declare the identifiers from the HiTech headers, and that are only used with splint. This worked for me with the HiTech PIC18 compiler. You should be able to automate the generation of the alternate headers once you find the substitutions you need to make.

画▽骨i 2024-08-26 17:19:21

我相信Cppcheck应该能够分析代码。

I believe Cppcheck should be able to analyse the code.

z祗昰~ 2024-08-26 17:19:21

对于所有静态检查器,您必须指定要定义哪些命令行宏,因此您可以通过在运行检查器时定义宏(例如 STATIC_ANLAYSIS)来通过条件编译来解决扩展问题,然后使用它来阻止违规构造或提供替代品。您可以简单地在静态分析器命令行上将某些扩展重新定义为可以通过检查器的扩展。

我不熟悉编译器或它提供的扩展;也许如果您举几个例子,可以建议具体的解决方法吗?

With all static checkers you have to specify which command line macros are to be defined, so you can work-around extensions with conditional compilation by defining a macro when running the checker, say STATIC_ANLAYSIS, and then using that to block out offending constructs or provide replacements. Some extensions you could simply redefine on the static analyser command line to something that will pass the checker.

I am not familiar with the compiler or what extensions it provides; perhaps if you gave a few examples, specific work arounds could be suggested?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文