There is a way to create more functions and call them using call(const
Label&), but you can do this by using single pass, creating more
functions using single AsmJit::Compiler instance.
If you create a EFunction object using
AsmJit::Compiler::newFunction(), then you can call getEntryLabel() to
get the function entry-point.
For example:
Compiler c;
ECall* ctx;
EFunction* funcA = c.newFunction(CALL_CONV_DEFAULT,
FunctionBuilder1<int, int>());
funcA->getEntryLabel();
// ...
But I see the problem here that you want to generate some function
after the funcA is serialized, in this case there is quite hacky way
how the another function can be called,
for example:
Compiler c;
Label bLabel;
// Generate funcA.
EFunction* funcA = c.newFunction(CALL_CONV_DEFAULT,
FunctionBuilder1<int, int>());
// Call a function b which will be generated later.
c.call(bLabel);
// ...
c.endFunction();
// Generate funcB, I'm going to use custom label bLabel which points
to the entry-point.
c.align(16);
c.bind(bLabel);
EFunction* funcB = c.newFunction(CALL_CONV_DEFAULT,
FunctionBuilder1<int, int>());
// ...
c.endFunction();
// ...
c.make();
I'm going to evaluate this issue and to propose a better solution.
Hope that helps.
BTW: I'm going to create a shader engine too for the Fog-Framework,
but it will be 2d only, maibe we can share some ideas in the future;)
Best regards
Petr Kobalicek
please always use AsmJit mailing list to ask for questions about
AsmJit, this will help others and minimize asking of questions which
has been already answered. I'm available on gmail chat quite often, so
if you need something really important, you can find me there.
And reply for Hainz:
Currently the declaration reduncancy can be avoided by using
setCurrentEmittable(), but I'd like to warn you, because it's not well
tested (personally, I had never used this). If you want to experiment,
try to use something like this:
Compiler c;
EFunction* funcA = c.newFunction(CALL_CONV_DEFAULT, ...);
EFunction* funcB = c.newFunction(CALL_CONV_DEFAULT, ...);
// Generate function A.
c.setCurrentEmittable(funcA);
// ...
ECall* ctx = c.call(funcB->getEntryLabel());
// ...
// Generate function B.
c.setCurrentEmittable(funcB);
By using this technique you can combine it with hash table so you get
"symbol" -> EFunction mapping. This technique generally uses the
design of AsmJit::Compiler which allows to add/remove instructions
before the c.make() is called. You can post-process the generated code
by using this technique to optimize or reorder it. It should be
probably more highlighted in the documentation.
Note, a new emittable (instruction, label, call) is always added after
the current emittable. The list is implemented as double-linked list
so you shouldn't worry about performance, it's O(1).
Best regards
Petr Kobalicek
I'm going to evaluate this and to improve the mechanism to get the
function pointer/offset.
Best regards
Petr Kobalicek
calling recursively one function is actually easy, please take look at
the test file called testfuncrecursive1.cpp, svn version here:
http://code.google.com/p/asmjit/source/browse/trunk/AsmJit-1.0/Test/testfuncrecursive1.cpp
Hope that helps
Petr Kobalicek