How do you determine whether a function is defined externally ?
Basically I want a list of external functions but cannot seem to get one.
e.g. I want to create the following list for a module
EXTERN _printf : NEAR
EXTERN _malloc : NEAR
EXTERN _an_external_fn : NEAR
I have tried all the obvious permutations but cannot seem to get only the extrnally defined symbols.
Help,
Aaron
Something like this should work:
for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F)
if (F->isExternal())
... Function* F is external! ...
If you take a look at the PowerPC asm printer, it has to do some special things for external functions as well, it might give you some ideas.
-Chris
Something like this should work:
for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F)
if (F->isExternal())
... Function* F is external! ...
This is not working. For some reason there is a BasicBlock present on undefined functions !
I am compiling the examples from llvm/test/feature, about 28 out of 34 assemble fine. Just cannot seem to get the externals listed, been trying for several hours
If you take a look at the PowerPC asm printer, it has to do some special things for external functions as well, it might give you some ideas.
I will have a look at this then.
Aaron
If you take a look at the PowerPC asm printer, it has to do some special things for external functions as well, it might give you some ideas.
I will have a look at this then.
AFAICS there is nothing special here (PowerPCAsmPrinter.cpp).
Aaron
I have tried the following :-
if (!M.empty())
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if ( !I->getIntrinsicID() && I->getEntryBlock().empty())
O << “EXTERN " << Mang->getValueName(I) << " : NEAR” << “\n”;
Based upon :-
virtual bool Function::isExternal() const { return BasicBlocks.empty(); }
But it does not work either.
Which means there must be a BasicBlock occuring on undefined/external functions.
Anyway no hurry I am off to do other tasks for a day or so.
Aaron
I must be doing something basic wrong with LLVM.
To be more precise the question should be probably be :-
“How do you get a list of all called functions that are external to the current module ?”
This is probably somewhat different from the list of module functions ???
Aaron
Something like this should work:
for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F)
if (F->isExternal())
... Function* F is external! ...
This is not working. For some reason there is a BasicBlock present on undefined functions !
Which functions in particular are you not seeing?
I am compiling the examples from llvm/test/feature, about 28 out of 34 assemble fine. Just cannot seem to get the externals listed, been trying for several hours
There are two types of external functions that the code generator deals with: external functions that are present in the LLVM program, and external functions used by the code generator. I suspect that you are hitting cases where the later are not getting printed.
If you look at the PowerPCAsmPrinter.cpp it has to do very similar things to what you are doing. Note that it uses a "FnStubs" set to collect references to external functions as they are emitted. Once it builds this set, it emits a stub for each external function at the bottom of the file. I think you should do something similar to this.
-Chris
Which functions in particular are you not seeing?
_alloc and _free
I am compiling the examples from llvm/test/feature, about 28 out of 34
assemble fine. Just cannot seem to get the externals listed, been trying for
several hours
There are two types of external functions that the code generator deals
with: external functions that are present in the LLVM program, and
external functions used by the code generator. I suspect that you are
hitting cases where the later are not getting printed.
If you look at the PowerPCAsmPrinter.cpp it has to do very similar things
to what you are doing. Note that it uses a “FnStubs” set to collect
references to external functions as they are emitted. Once it builds this
set, it emits a stub for each external function at the bottom of the file.
I think you should do something similar to this.
I was getting confused by the feature test cases. So am now writting my own.
Sorry It was late and I have just not been looking at things quite properly and so have been getting confused.
if (!M.empty())
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
if ( !F->getIntrinsicID() && F->isExternal())
O << “EXTERN " << Mang->getValueName(F) << " : NEAR” << “\n”;
The above works fine with normal external functions.
Regarding _alloc and _free they do not seem to be added to the external functions when they are used in the test case “feature/testmemory.ll”, so should I include such cases in an include file or add them to the head of the generated file or something like that.
Doing quite well now.
I have just got to deal with STRUC’s as the MASM assembler requires some level of typing.
And then produce some conclusive purpose written test cases.
I should take a rest and then perservere a bit more before panicing and asking for help !
Cheers,
Aaron