Re: [Gems-users] Writing new get function for opal, to put value in variable


Date: Thu, 4 Feb 2010 10:45:18 -0600
From: sparsh mittal ISU <sparsh@xxxxxxxxxxx>
Subject: Re: [Gems-users] Writing new get function for opal, to put value in variable
Hello All,
Thanks Dan for the reply.

Yes, once I write the command for opal0.instructions, I can assign the value:
simics> @U = conf.opal0.instructions

however, the value to be returned by opal0.instructions is an integer, and the its scope is in a separate C file (hfa.C in opal), not in the python file (commands.py).
For such functions, GEMS code uses SIM_get_attribute to separately define the function in the C file (hfa.C). So, for this case, the code would be
In commands.py=================
def opal_sim_instructions(obj):
    SIM_get_attribute( obj, "instructions" )

new_command("instructions", opal_sim_instructions,
            [],
            alias = "",
            type  = "hfa commands",
            short = "returns the current instructions",
            namespace = "opal",
            doc = """
Returns the current instructions of the simulator.<br/>
""")

and in hfa.C=======================
attr_value_t hfa_dispatch_get( void *id, conf_object_t *obj,
                               attr_value_t *idx )
{
  attr_value_t ret;
  ret.kind = Sim_Val_Integer;
  ret.u.integer = 0;
  const char *attr_fn = (const char *) id;
  // obj is the hfa0 object

  if (!strcmp(attr_fn, "sim-flag")) {
    ret.kind = Sim_Val_Integer;
    ret.u.integer = system_t::inst->isSimulating();

  }
 ......
 else if (!strcmp(attr_fn, "instructions")) {
     printf("   %lld\n",system_t::inst->m_seq[0]->m_stat_committed[0]);
     ret.u.integer = system_t::inst->m_seq[0]->m_stat_committed[0];
 }
else {
    ERROR_OUT( "error: hfa: hfa_dispatch_get: unknown command: %s\n", attr_fn );
  }

  return ret;
}

Now my question is that the function in the hfa.C returns a attr_value_t variable. Whether it can be used in the commands.py file or can the scope of (system_t::inst->m_seq[0]->m_stat_committed[0]) be accessed in the commands.py file? I would be thankful for the reply.
Sparsh

On Thu, Feb 4, 2010 at 10:41 AM, Dan Gibson <degibson@xxxxxxxx> wrote:
The Simics CLI is a fully-functional python interpreter. Therefore, you can write whatever you like in Python.

Regards,
Dan

On Thu, Feb 4, 2010 at 10:09 AM, sparsh mittal ISU <sparsh@xxxxxxxxxxx> wrote:

Hello All
I want to write a script for opal, where the value of instructions committed will be read in a variable, such as
simics> $U=opal0.instructions
Or
opal0.instructions => $U
If it were a file I could have used
pipe opal0.instructions "cat >> file.txt"

I will write a new command opal0.instructions, but I am not sure, how to write a function, which returns a value, which can be put in a variable (not just printed).

I would very much appreciate any help.


--
Thanks and Regards
Sparsh Mittal
Graduate Student
Electrical and Computer Engineering
Iowa State University, Iowa, USA

_______________________________________________
Gems-users mailing list
Gems-users@xxxxxxxxxxx
https://lists.cs.wisc.edu/mailman/listinfo/gems-users
Use Google to search the GEMS Users mailing list by adding "site:https://lists.cs.wisc.edu/archive/gems-users/" to your search.





--
http://www.cs.wisc.edu/~gibson [esc]:wq!



--
Thanks and Regards
Sparsh Mittal
Graduate Student
Electrical and Computer Engineering
Iowa State University, Iowa, USA
[← Prev in Thread] Current Thread [Next in Thread→]