Skip to content

yosys_import can create invalid Cryptol field names #2841

Description

@podhrmic

yosys_import currently accepts any string in the cell name, even though it is not a valid Cryptol field name. For example "type": "full_default(fullarch)", in the JSON below is illegal. I can simply preprocess the JSON file, but wanted to raise this in case you wanted to at least throw an error/warning when importing illegal cell names into SAW.

Original comment from @RyanGlScott below:

Details
$ jq '.modules.["full_default(fullarch)"]' adder_tabby.json
{
  "attributes": {
    "architecture": "fullarch",
    "library": "work",
    "hdlname": "full",
    "src_entity": "adder.vhd:22.8-22.12",
    "src": "adder.vhd:32.14-32.22"
  },
  "ports": {
    "a": {
      "direction": "input",
      "bits": [
        2
      ]
    },
    "b": {
      "direction": "input",
      "bits": [
        3
      ]
    },
    "cin": {
      "direction": "input",
      "bits": [
        4
      ]
    },
    "cout": {
      "direction": "output",
      "bits": [
        5
      ]
    },
    "s": {
      "direction": "output",
      "bits": [
        6
      ]
    }
  },
  "cells": {
    "$verific$i4$adder.vhd:39$32": {
      "hide_name": 1,
      "type": "$or",
      "parameters": {
        "A_SIGNED": "00000000000000000000000000000000",
        "A_WIDTH": "00000000000000000000000000000001",
        "B_SIGNED": "00000000000000000000000000000000",
        "B_WIDTH": "00000000000000000000000000000001",
        "Y_WIDTH": "00000000000000000000000000000001"
      },
      "attributes": {
        "src": "adder.vhd:39.11-39.27"
      },
      "port_directions": {
        "A": "input",
        "B": "input",
        "Y": "output"
      },
      "connections": {
        "A": [
          7
        ],
        "B": [
          8
        ],
        "Y": [
          9
        ]
      }
    },
    "$verific$i5$adder.vhd:39$33": {
      "hide_name": 1,
      "type": "$_BUF_",
      "parameters": {},
      "attributes": {},
      "port_directions": {
        "A": "input",
        "Y": "output"
      },
      "connections": {
        "A": [
          9
        ],
        "Y": [
          5
        ]
      }
    },
    "half0": {
      "hide_name": 0,
      "type": "half_default(halfarch)",
      "parameters": {},
      "attributes": {
        "src": "adder.vhd:37.3-37.8"
      },
      "port_directions": {
        "a": "input",
        "b": "input",
        "c": "output",
        "s": "output"
      },
      "connections": {
        "a": [
          2
        ],
        "b": [
          3
        ],
        "c": [
          7
        ],
        "s": [
          10
        ]
      }
    },
    "half1": {
      "hide_name": 0,
      "type": "half_default(halfarch)",
      "parameters": {},
      "attributes": {
        "src": "adder.vhd:38.3-38.8"
      },
      "port_directions": {
        "a": "input",
        "b": "input",
        "c": "output",
        "s": "output"
      },
      "connections": {
        "a": [
          10
        ],
        "b": [
          4
        ],
        "c": [
          8
        ],
        "s": [
          6
        ]
      }
    }
  },
  "netnames": {
    "$verific$half0$adder.vhd:37$24": {
      "hide_name": 1,
      "bits": [
        11
      ],
      "attributes": {}
    },
    "$verific$half0$adder.vhd:37$25": {
      "hide_name": 1,
      "bits": [
        12
      ],
      "attributes": {}
    },
    "$verific$half0$adder.vhd:37$26": {
      "hide_name": 1,
      "bits": [
        13
      ],
      "attributes": {}
    },
    "$verific$half0$adder.vhd:37$27": {
      "hide_name": 1,
      "bits": [
        14
      ],
      "attributes": {}
    },
    "$verific$half1$adder.vhd:38$28": {
      "hide_name": 1,
      "bits": [
        15
      ],
      "attributes": {}
    },
    "$verific$half1$adder.vhd:38$29": {
      "hide_name": 1,
      "bits": [
        16
      ],
      "attributes": {}
    },
    "$verific$half1$adder.vhd:38$30": {
      "hide_name": 1,
      "bits": [
        17
      ],
      "attributes": {}
    },
    "$verific$half1$adder.vhd:38$31": {
      "hide_name": 1,
      "bits": [
        18
      ],
      "attributes": {}
    },
    "$verific$n12$23": {
      "hide_name": 1,
      "bits": [
        9
      ],
      "attributes": {}
    },
    "a": {
      "hide_name": 0,
      "bits": [
        2
      ],
      "attributes": {
        "src": "adder.vhd:24.5-24.6"
      }
    },
    "b": {
      "hide_name": 0,
      "bits": [
        3
      ],
      "attributes": {
        "src": "adder.vhd:25.5-25.6"
      }
    },
    "cin": {
      "hide_name": 0,
      "bits": [
        4
      ],
      "attributes": {
        "src": "adder.vhd:26.5-26.8"
      }
    },
    "cout": {
      "hide_name": 0,
      "bits": [
        5
      ],
      "attributes": {
        "src": "adder.vhd:27.5-27.9"
      }
    },
    "half0c": {
      "hide_name": 0,
      "bits": [
        7
      ],
      "attributes": {
        "src": "adder.vhd:33.10-33.16"
      }
    },
    "half0s": {
      "hide_name": 0,
      "bits": [
        10
      ],
      "attributes": {
        "src": "adder.vhd:34.10-34.16"
      }
    },
    "half1c": {
      "hide_name": 0,
      "bits": [
        8
      ],
      "attributes": {
        "src": "adder.vhd:35.10-35.16"
      }
    },
    "s": {
      "hide_name": 0,
      "bits": [
        6
      ],
      "attributes": {
        "src": "adder.vhd:28.5-28.6"
      }
    }
  }
}

This doesn't cause cause problems for the yosys_import command per se, but it does result in a Term with Cryptol fields that have inaccessible names:

sawscript> m <- yosys_import "adder_tabby.json"
sawscript> print (type m)
[19:56:59.559] {add4 : {a : [4], b : [4]} -> {res : [4]},
 full_default(fullarch) : {a : [1], b : [1], cin : [1]} ->
 {cout : [1], s : [1]},
 half_default(halfarch) : {a : [1], b : [1]} -> {c : [1], s : [1]}}
sawscript> print (type {{ m.full_default(fullarch) }})

Stack trace:
   (builtin) (at top level)
Cryptol error:
[error] at <stdin>:1:31--1:39
    Value not in scope: fullarch

Perhaps we should escape characters with special meaning in Cryptol, such as parentheses?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    subsystem: hardwareIssues related to verification of hardwaretype: bugIssues reporting bugs or unexpected/unwanted behaviorusabilityAn issue that impedes efficient understanding and use

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions