将数据块写入内存的模型

时间:2017-08-06 12:35:30

标签: alloy

我创建了一个将数据块写入固定大小的内存的Alloy模型。见下文。合金分析器生成的实例都包含大小为1的块(即,具有一个数据的块)或更少。我希望Alloy Analyzer使用大小为2的块生成实例。所以,我将其添加到writeBlock谓词:#block = 2。这是更新的谓词:

pred writeBlock (m, m': Memory, block: set Data) {
    some addrs: set m.data.Data {
        #addrs = #block
        #block = 2   // I added this
        m'.data = m.data ++ (addrs -> block)
    }
}

然后分析师说“找不到实例”。

为什么呢?

为什么没有实例?

module fixedSizeMemory [Addr, Data]

sig Memory {
    data: Addr -> one Data
}

// Write a block of data to memory.
pred writeBlock (m, m': Memory, block: set Data) {
    some addrs: set m.data.Data {
        #addrs = #block
        m'.data = m.data ++ (addrs -> block)
    }
}

pred Show {}
run writeBlock

更新:我弄清楚为什么在添加#block = 2时没有实例。问题出在(addrs -> block)上。这就是说:取addrs个值和block值的所有排列。因此,如果有2个addrs值和2个block值,则会有4个排列。 data关系表示每个Addr值映射到一个Data值。但这四种排列将违反这一限制。唯一不违反关系的blocks是尺寸为1或0的blocks

更新#2 :我解决了这个问题。这是写一块内存的Alloy代码:

// Write a block of data to memory. That is,
// overwrite the data at a set of addresses
// with values in block.
pred writeBlock (m, m': Memory, block: set Data) {
       // Non-deterministically select a subset 
       // of m's addresses to be overwritten.
       some addresses: set m.data.Data {
           // The chunk of memory overwritten
           // matches the size of the block.
           #addresses = #block
           // Create a temporary relation, mapping.
           // It defines a mapping from each address
           // selected above to a block value. The
           // relation is 1:1. That is, each address is
           // assigned a value from block, and each
           // value in block is associated to an address.
           some mapping: addresses one -> one block {
               // Overwrite the selected portion of memory
               // with mapping.
               m'.data = m.data ++ mapping
              // This is so cool!
         }
    }
}

0 个答案:

没有答案