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.