case TEMPS_LABEL: return ".temp.";
case ARGS_LABEL: return ".args.";
case RET_LABEL: return ".ret.";
- case LIBCALL: return ".lib.";
+ case LIBCALL: return "__intrinsics";
case FRAME_SECTION: return ".fpdata.";
case AUTOS_SECTION: return ".fadata.";
case CODE_SECTION: return "code";
return o.str();
}
+ static std::string getDeclSectionName(void) {
+ std::string dsname = "decl_section.1";
+ dsname = addPrefix(dsname);
+ return dsname;
+ }
+
inline static bool isLocalName (const std::string &Name) {
if (getSymbolTag(Name) == AUTOS_LABEL)
return true;
CurLine = line;
}
}
+
// Print the assembly for the instruction.
printMachineInstruction(II);
}
return new PIC16AsmPrinter(o, tm, tm.getTargetAsmInfo(), OptLevel, verbose);
}
+
+// printOperand - print operand of insn.
void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
const MachineOperand &MO = MI->getOperand(opNum);
break;
}
case MachineOperand::MO_ExternalSymbol: {
- std::string Name = MO.getSymbolName();
- O << MO.getSymbolName();
+ const char *Sname = MO.getSymbolName();
+
+ // If its a libcall name, record it to decls section.
+ if (PAN::getSymbolTag(Sname) == PAN::LIBCALL) {
+ Decls.push_back(Sname);
+ }
+
+ O << Sname;
break;
}
case MachineOperand::MO_MachineBasicBlock:
O << PIC16CondCodeToString((PIC16CC::CondCodes)CC);
}
+void PIC16AsmPrinter::printDecls(void) {
+ // If no libcalls used, return.
+ if (Decls.empty()) return;
+
+ const Section *S = TAI->getNamedSection(PAN::getDeclSectionName().c_str());
+ SwitchToSection(S);
+ // Remove duplicate entries.
+ Decls.sort();
+ Decls.unique();
+ for (std::list<const char*>::const_iterator I = Decls.begin();
+ I != Decls.end(); I++) {
+ O << TAI->getExternDirective() << *I << "\n";
+ // FIXME: Use PAN::getXXXLabel() funtions hrer.
+ O << TAI->getExternDirective() << *I << ".args." << "\n";
+ O << TAI->getExternDirective() << *I << ".ret." << "\n";
+ }
+}
bool PIC16AsmPrinter::doInitialization (Module &M) {
bool Result = AsmPrinter::doInitialization(M);
// Emit header file to include declaration of library functions
// FIXME: find out libcall names.
- O << "\t#include C16IntrinsicCalls.INC\n";
+ // O << "\t#include C16IntrinsicCalls.INC\n";
// Emit declarations for external variable declarations and definitions.
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
void PIC16AsmPrinter::EmitRomData (Module &M)
{
SwitchToSection(TAI->getReadOnlySection());
- IsRomData = true;
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
if (!I->hasInitializer()) // External global require no code.
O << "\n";
}
}
- IsRomData = false;
}
bool PIC16AsmPrinter::doFinalization(Module &M) {
+ printDecls();
O << "\t" << "END\n";
bool Result = AsmPrinter::doFinalization(M);
return Result;
#include "llvm/Support/CommandLine.h"
#include "llvm/Target/TargetAsmInfo.h"
#include "llvm/Target/TargetMachine.h"
+#include <list>
+#include <string>
namespace llvm {
struct VISIBILITY_HIDDEN PIC16AsmPrinter : public AsmPrinter {
const TargetAsmInfo *T, CodeGenOpt::Level OL,
bool V)
: AsmPrinter(O, TM, T, OL, V) {
- FunctionLabelBegin = '@';
- IsRomData = false;
PTLI = TM.getTargetLowering();
}
private :
void EmitGlobalData (Module &M);
void EmitRomData (Module &M);
void emitFunctionData(MachineFunction &MF);
+ void printDecls(void);
protected:
bool doInitialization(Module &M);
private:
PIC16TargetLowering *PTLI;
- bool IsRomData;
- char FunctionLabelBegin;
+ std::list<const char *> Decls; // List of extern decls.
};
} // end of namespace