How to access VHDL signal attributes in ModelSim via TCL?











up vote
1
down vote

favorite












I am developing a CPU in VHDL. I am using ModelSim for simulation and testing. In the simulation script I load a program from a binary file to the instruction memory. Now I want to automatically check if the program fits into memory and abort simulation if it doesn't. Since the memory is basically an array of std_logic_vectors, all I would have to do is read the corresponding signal attribute for use in a comparison. My problem is: How do I access a VHDL signal attribute in TCL inside ModelSim?



The closest I have gotten so far is to use the describe command:



describe sim/:tb:uut:imem:mem_array


which prints something like



# Array(0 to 255) [length 256] of
# Array(31 downto 0) [length 32] of
# VHDL standard subtype STD_LOGIC


Now, of course I could parse the length out of there via string operations. But that would not be a very generic solution. Ideally I would like to have something like this:



set mem_size [get_attribute sim/:tb:uut:imem:mem_array'length]


I have searched stackoverflow, googled up and down and searched through the commands in the command reference manual, but I could not find a solution. I am confident there must be a rather easy solution and I just lack the proper wording to successfully search for it. To me, this doesn't look overly specific and I am sure this could come in hand on many occasions when automating design testing. I am using version 10.6.



I would be very grateful if an experienced ModelSim user could help me out.










share|improve this question




























    up vote
    1
    down vote

    favorite












    I am developing a CPU in VHDL. I am using ModelSim for simulation and testing. In the simulation script I load a program from a binary file to the instruction memory. Now I want to automatically check if the program fits into memory and abort simulation if it doesn't. Since the memory is basically an array of std_logic_vectors, all I would have to do is read the corresponding signal attribute for use in a comparison. My problem is: How do I access a VHDL signal attribute in TCL inside ModelSim?



    The closest I have gotten so far is to use the describe command:



    describe sim/:tb:uut:imem:mem_array


    which prints something like



    # Array(0 to 255) [length 256] of
    # Array(31 downto 0) [length 32] of
    # VHDL standard subtype STD_LOGIC


    Now, of course I could parse the length out of there via string operations. But that would not be a very generic solution. Ideally I would like to have something like this:



    set mem_size [get_attribute sim/:tb:uut:imem:mem_array'length]


    I have searched stackoverflow, googled up and down and searched through the commands in the command reference manual, but I could not find a solution. I am confident there must be a rather easy solution and I just lack the proper wording to successfully search for it. To me, this doesn't look overly specific and I am sure this could come in hand on many occasions when automating design testing. I am using version 10.6.



    I would be very grateful if an experienced ModelSim user could help me out.










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am developing a CPU in VHDL. I am using ModelSim for simulation and testing. In the simulation script I load a program from a binary file to the instruction memory. Now I want to automatically check if the program fits into memory and abort simulation if it doesn't. Since the memory is basically an array of std_logic_vectors, all I would have to do is read the corresponding signal attribute for use in a comparison. My problem is: How do I access a VHDL signal attribute in TCL inside ModelSim?



      The closest I have gotten so far is to use the describe command:



      describe sim/:tb:uut:imem:mem_array


      which prints something like



      # Array(0 to 255) [length 256] of
      # Array(31 downto 0) [length 32] of
      # VHDL standard subtype STD_LOGIC


      Now, of course I could parse the length out of there via string operations. But that would not be a very generic solution. Ideally I would like to have something like this:



      set mem_size [get_attribute sim/:tb:uut:imem:mem_array'length]


      I have searched stackoverflow, googled up and down and searched through the commands in the command reference manual, but I could not find a solution. I am confident there must be a rather easy solution and I just lack the proper wording to successfully search for it. To me, this doesn't look overly specific and I am sure this could come in hand on many occasions when automating design testing. I am using version 10.6.



      I would be very grateful if an experienced ModelSim user could help me out.










      share|improve this question















      I am developing a CPU in VHDL. I am using ModelSim for simulation and testing. In the simulation script I load a program from a binary file to the instruction memory. Now I want to automatically check if the program fits into memory and abort simulation if it doesn't. Since the memory is basically an array of std_logic_vectors, all I would have to do is read the corresponding signal attribute for use in a comparison. My problem is: How do I access a VHDL signal attribute in TCL inside ModelSim?



      The closest I have gotten so far is to use the describe command:



      describe sim/:tb:uut:imem:mem_array


      which prints something like



      # Array(0 to 255) [length 256] of
      # Array(31 downto 0) [length 32] of
      # VHDL standard subtype STD_LOGIC


      Now, of course I could parse the length out of there via string operations. But that would not be a very generic solution. Ideally I would like to have something like this:



      set mem_size [get_attribute sim/:tb:uut:imem:mem_array'length]


      I have searched stackoverflow, googled up and down and searched through the commands in the command reference manual, but I could not find a solution. I am confident there must be a rather easy solution and I just lack the proper wording to successfully search for it. To me, this doesn't look overly specific and I am sure this could come in hand on many occasions when automating design testing. I am using version 10.6.



      I would be very grateful if an experienced ModelSim user could help me out.







      tcl vhdl modelsim






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 10:20

























      asked Nov 11 at 10:11









      programonkey

      264




      264
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          So, I actually found an easy solution. While further studying of the command reference manual brought to light that it is only possible to access a few special signal attributes and length is not one of them, I noticed that ModelSim automatically adds a size object to its object database for the memory array. So I can easily use



          set ms [examine sim/:tb:uut:imem:mem_array_size]


          to obtain the size and then check if the program fits.
          This is just perfect for me, elegant and easy.






          share|improve this answer




























            up vote
            1
            down vote













            Disclaimer: I'm not a Tcl expert, so there's probably a more optimized solution out there.



            There's a command called examine that you can use to get the value of obejcts.



            I created a similar testbench here with a 256 x 32 array, the results were



            VSIM> examine -radix hex sim/:tb:uut:imem:mem_array
            # {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} ...


            This is the value of sim/:tb:uut:imem:mem_array at the last simulation step (i.e.,
            now).



            The command return a list of values for each match (you can use wildcards), so
            in our case, it's a list with a single item. You can get the depth by counting
            the number of elements it returns:



            VSIM> llength [lindex  [examine sim/:tb:uut:imem:mem_array] 0]
            # 256


            You can get the bit width of the first element by using examine -showbase -radix hex,
            which will return 32'hFFFFFFFF, where 32'h is the part you want to parse. Wrapping
            that into a function would look like



            proc get_bit_width { signal } {
            set first_element [lindex [lindex [examine -radix hex -showbase $signal] 0] 0]
            # Replace everything after 'h, including 'h itself to return only the base
            return [regsub "'h.*" $first_element ""]
            }


            Hope this gives some pointers!






            share|improve this answer





















            • Thank you. That is actually helpful and I was about to accept this as an answer, but then I stumbled across an even easier solution.
              – programonkey
              Nov 13 at 8:28










            • No worries, that was new to me as well and actually helpful!
              – suoto
              Nov 14 at 9:10











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247685%2fhow-to-access-vhdl-signal-attributes-in-modelsim-via-tcl%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            So, I actually found an easy solution. While further studying of the command reference manual brought to light that it is only possible to access a few special signal attributes and length is not one of them, I noticed that ModelSim automatically adds a size object to its object database for the memory array. So I can easily use



            set ms [examine sim/:tb:uut:imem:mem_array_size]


            to obtain the size and then check if the program fits.
            This is just perfect for me, elegant and easy.






            share|improve this answer

























              up vote
              2
              down vote



              accepted










              So, I actually found an easy solution. While further studying of the command reference manual brought to light that it is only possible to access a few special signal attributes and length is not one of them, I noticed that ModelSim automatically adds a size object to its object database for the memory array. So I can easily use



              set ms [examine sim/:tb:uut:imem:mem_array_size]


              to obtain the size and then check if the program fits.
              This is just perfect for me, elegant and easy.






              share|improve this answer























                up vote
                2
                down vote



                accepted







                up vote
                2
                down vote



                accepted






                So, I actually found an easy solution. While further studying of the command reference manual brought to light that it is only possible to access a few special signal attributes and length is not one of them, I noticed that ModelSim automatically adds a size object to its object database for the memory array. So I can easily use



                set ms [examine sim/:tb:uut:imem:mem_array_size]


                to obtain the size and then check if the program fits.
                This is just perfect for me, elegant and easy.






                share|improve this answer












                So, I actually found an easy solution. While further studying of the command reference manual brought to light that it is only possible to access a few special signal attributes and length is not one of them, I noticed that ModelSim automatically adds a size object to its object database for the memory array. So I can easily use



                set ms [examine sim/:tb:uut:imem:mem_array_size]


                to obtain the size and then check if the program fits.
                This is just perfect for me, elegant and easy.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 at 8:25









                programonkey

                264




                264
























                    up vote
                    1
                    down vote













                    Disclaimer: I'm not a Tcl expert, so there's probably a more optimized solution out there.



                    There's a command called examine that you can use to get the value of obejcts.



                    I created a similar testbench here with a 256 x 32 array, the results were



                    VSIM> examine -radix hex sim/:tb:uut:imem:mem_array
                    # {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} ...


                    This is the value of sim/:tb:uut:imem:mem_array at the last simulation step (i.e.,
                    now).



                    The command return a list of values for each match (you can use wildcards), so
                    in our case, it's a list with a single item. You can get the depth by counting
                    the number of elements it returns:



                    VSIM> llength [lindex  [examine sim/:tb:uut:imem:mem_array] 0]
                    # 256


                    You can get the bit width of the first element by using examine -showbase -radix hex,
                    which will return 32'hFFFFFFFF, where 32'h is the part you want to parse. Wrapping
                    that into a function would look like



                    proc get_bit_width { signal } {
                    set first_element [lindex [lindex [examine -radix hex -showbase $signal] 0] 0]
                    # Replace everything after 'h, including 'h itself to return only the base
                    return [regsub "'h.*" $first_element ""]
                    }


                    Hope this gives some pointers!






                    share|improve this answer





















                    • Thank you. That is actually helpful and I was about to accept this as an answer, but then I stumbled across an even easier solution.
                      – programonkey
                      Nov 13 at 8:28










                    • No worries, that was new to me as well and actually helpful!
                      – suoto
                      Nov 14 at 9:10















                    up vote
                    1
                    down vote













                    Disclaimer: I'm not a Tcl expert, so there's probably a more optimized solution out there.



                    There's a command called examine that you can use to get the value of obejcts.



                    I created a similar testbench here with a 256 x 32 array, the results were



                    VSIM> examine -radix hex sim/:tb:uut:imem:mem_array
                    # {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} ...


                    This is the value of sim/:tb:uut:imem:mem_array at the last simulation step (i.e.,
                    now).



                    The command return a list of values for each match (you can use wildcards), so
                    in our case, it's a list with a single item. You can get the depth by counting
                    the number of elements it returns:



                    VSIM> llength [lindex  [examine sim/:tb:uut:imem:mem_array] 0]
                    # 256


                    You can get the bit width of the first element by using examine -showbase -radix hex,
                    which will return 32'hFFFFFFFF, where 32'h is the part you want to parse. Wrapping
                    that into a function would look like



                    proc get_bit_width { signal } {
                    set first_element [lindex [lindex [examine -radix hex -showbase $signal] 0] 0]
                    # Replace everything after 'h, including 'h itself to return only the base
                    return [regsub "'h.*" $first_element ""]
                    }


                    Hope this gives some pointers!






                    share|improve this answer





















                    • Thank you. That is actually helpful and I was about to accept this as an answer, but then I stumbled across an even easier solution.
                      – programonkey
                      Nov 13 at 8:28










                    • No worries, that was new to me as well and actually helpful!
                      – suoto
                      Nov 14 at 9:10













                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    Disclaimer: I'm not a Tcl expert, so there's probably a more optimized solution out there.



                    There's a command called examine that you can use to get the value of obejcts.



                    I created a similar testbench here with a 256 x 32 array, the results were



                    VSIM> examine -radix hex sim/:tb:uut:imem:mem_array
                    # {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} ...


                    This is the value of sim/:tb:uut:imem:mem_array at the last simulation step (i.e.,
                    now).



                    The command return a list of values for each match (you can use wildcards), so
                    in our case, it's a list with a single item. You can get the depth by counting
                    the number of elements it returns:



                    VSIM> llength [lindex  [examine sim/:tb:uut:imem:mem_array] 0]
                    # 256


                    You can get the bit width of the first element by using examine -showbase -radix hex,
                    which will return 32'hFFFFFFFF, where 32'h is the part you want to parse. Wrapping
                    that into a function would look like



                    proc get_bit_width { signal } {
                    set first_element [lindex [lindex [examine -radix hex -showbase $signal] 0] 0]
                    # Replace everything after 'h, including 'h itself to return only the base
                    return [regsub "'h.*" $first_element ""]
                    }


                    Hope this gives some pointers!






                    share|improve this answer












                    Disclaimer: I'm not a Tcl expert, so there's probably a more optimized solution out there.



                    There's a command called examine that you can use to get the value of obejcts.



                    I created a similar testbench here with a 256 x 32 array, the results were



                    VSIM> examine -radix hex sim/:tb:uut:imem:mem_array
                    # {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} ...


                    This is the value of sim/:tb:uut:imem:mem_array at the last simulation step (i.e.,
                    now).



                    The command return a list of values for each match (you can use wildcards), so
                    in our case, it's a list with a single item. You can get the depth by counting
                    the number of elements it returns:



                    VSIM> llength [lindex  [examine sim/:tb:uut:imem:mem_array] 0]
                    # 256


                    You can get the bit width of the first element by using examine -showbase -radix hex,
                    which will return 32'hFFFFFFFF, where 32'h is the part you want to parse. Wrapping
                    that into a function would look like



                    proc get_bit_width { signal } {
                    set first_element [lindex [lindex [examine -radix hex -showbase $signal] 0] 0]
                    # Replace everything after 'h, including 'h itself to return only the base
                    return [regsub "'h.*" $first_element ""]
                    }


                    Hope this gives some pointers!







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 12 at 16:57









                    suoto

                    18112




                    18112












                    • Thank you. That is actually helpful and I was about to accept this as an answer, but then I stumbled across an even easier solution.
                      – programonkey
                      Nov 13 at 8:28










                    • No worries, that was new to me as well and actually helpful!
                      – suoto
                      Nov 14 at 9:10


















                    • Thank you. That is actually helpful and I was about to accept this as an answer, but then I stumbled across an even easier solution.
                      – programonkey
                      Nov 13 at 8:28










                    • No worries, that was new to me as well and actually helpful!
                      – suoto
                      Nov 14 at 9:10
















                    Thank you. That is actually helpful and I was about to accept this as an answer, but then I stumbled across an even easier solution.
                    – programonkey
                    Nov 13 at 8:28




                    Thank you. That is actually helpful and I was about to accept this as an answer, but then I stumbled across an even easier solution.
                    – programonkey
                    Nov 13 at 8:28












                    No worries, that was new to me as well and actually helpful!
                    – suoto
                    Nov 14 at 9:10




                    No worries, that was new to me as well and actually helpful!
                    – suoto
                    Nov 14 at 9:10


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247685%2fhow-to-access-vhdl-signal-attributes-in-modelsim-via-tcl%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python