如何在tcl中的tcl中作为一行语句给出和操作,其中pcieDeviceControlRegister是一个在代码中给出的函数:
代码:
public class Categories {
//solution 1
List<Category> data;//object name must match with the json response
//solution 2
@SerializedName("data")
List<Category> items;
}
pcieDeviceControlRegister函数的参考是:
pcieDeviceControlRegister = cfgSpace.pcieDeviceControlRegister & (~((uint)0xF));
答案 0 :(得分:1)
您必须安排将ReadDW
和WriteDW
映射到Tcl,可能是通过编写一些C或C ++代码来生成那些命令(具有相同名称)操作。我假设你已经这样做了。 (如果需要,SWIG可以生成胶水代码。)
然后,我们定义一个这样的命令:
proc pcieDeviceControlRegister {{newValue ""}} {
global pcieCapabilityOffset
# Filter the bogus setup case early; if this is really an error case though,
# it is better to actually throw an error instead of struggling on badly.
if {$pcieCapabilityOffset == 0} {
return 0
# error "PCIE capability offset is zero"
}
set offset [expr {($pcieCapabilityOffset + 8) / 4}]
if {$newValue eq ""} {
# This is a read operation
return [expr {[ReadDW $offset 0xF] & 0xFFFF}]
} else {
# This is a write operation
set val [expr {[ReadDW $offset 0xF] & 0xFFFF0000}]
# Note that we do the bit filtering HERE
set val [expr {$val | ($newValue & 0xFFFF)}]
WriteDW $offset $val 0xF
return
}
}
有了这个,你应该能看到的是一个非常简单的C#属性代码的翻译(稍微重构一下),然后你可以像这样编写你的调用代码:
pcieDeviceControlRegister [expr {[pcieDeviceControlRegister] & ~0xF}]
使用Tcl,你不会将强制转换写入不同类型的整数:Tcl只有数字(理论上无限宽度),所以你需要再做几个掩码在关键的地方。
将上述代码转换为对象上的方法作为练习。它没有太大变化......