Question

I want to have a file that imports two other files. The first imported file actually creates the second file to be imported, and so must execute immediately after being imported. Is this possible in Specman? I thought I read in one of the manuals that there are certain built-in functions that run immediately after the file is loaded.

The follow on is that I am assuming that this first file can use Specman's Reflection to access other previously-imported structs/units to decide what to generate. More info on using Reflection: StackOverflow - Using Reflection in Specman

Example:

File1.e:
<'
  // Function that runs immediately after this file is loaded
  // and generates File2.e
  on_load???(){
    ...
  };
'>

File2.e:
<'
// This file was generated by File1.e
'>

top.e:
<'
import File1;
import File2;
'>
Was it helpful?

Solution

This almost works, but it looks like newer versions of specman don't allow #ifdef around imports.. if you can figure out the ifdef usage then this would work...

               top.e
       +--------/| \----------+
      /          |             \
macro.e    macro_call.e     generated_loader.e
                                 |
                             generated.e

top.e has:

<'
import macro;
import macro_call;
import generated_loader;
'>

macro.e has:

<'
define <GENERATOR'statement> "GENERATOR" as computed {
    compute system("printf \"<'\\nextend sys{run() is first { print \\\"in generated.e\\\"; }; };\\n'>\\n\">generated.e");
};
#define ENABLE_GENERATOR_LOADER 1;
'>

macro_call.e has:

<'
GENERATOR;
'>

generated_loader.e has:

<'
#ifdef ENABLE_GENERATOR_LOADER {
import generated.e;
};
'>

And then generated.e should have the following after the GENERATOR macro is run:

<'
extend sys{run() is first { print "in generated.e"; }; };
'>

However, version 10 of Specman doesn't like the import statement inside the #ifdef, even though that is an example of #ifdef usage in Specman 6.1 documentation:

specman -c 'load top; test'

yields:

[...]
Loading generated_loader.e   (imported by top.e) ...
read...parse...update...
   *** Error: Import Statements should be placed at the top of the file -
please change the statements order, pay attention to the imported module
'generated.e'.
                at line 4 in generated_loader.e
import generated.e;

EDIT

On second thought, you probably just want define as computed, which would generate code to be parsed in place, without going through the hassle of generating a new file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top