#include "PIC16AsmPrinter.h"
#include "PIC16TargetAsmInfo.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/Mangler.h"
+#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/Module.h"
+#include "llvm/CodeGen/DwarfWriter.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
-#include "llvm/DerivedTypes.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Mangler.h"
using namespace llvm;
// Emit declarations for external globals.
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; I++) {
+ // Any variables reaching here with ".auto." in its name is a local scope
+ // variable and should not be printed in global data section.
std::string Name = Mang->getValueName(I);
+ if (Name.find(".auto.") != std::string::npos)
+ continue;
+
if (I->isDeclaration())
O << "\textern "<< Name << "\n";
- else if (I->getLinkage() == GlobalValue::CommonLinkage)
+ else if (I->hasCommonLinkage() || I->hasExternalLinkage())
O << "\tglobal "<< Name << "\n";
}
}
+
void PIC16AsmPrinter::EmitInitData (Module &M) {
SwitchToSection(TAI->getDataSection());
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
// Any variables reaching here with "." in its name is a local scope
// variable and should not be printed in global data section.
std::string name = Mang->getValueName(I);
- if (name.find(".") != std::string::npos)
+ if (name.find(".auto.") != std::string::npos)
continue;
O << name;
- EmitGlobalConstant(C);
- }
- }
-}
-
-void PIC16AsmPrinter::EmitConstantValueOnly(const Constant* CV) {
- if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
- unsigned BitWidth = CI->getBitWidth();
- int Val = CI->getZExtValue();
- if (BitWidth == 8) {
- // Expecting db directive here. In case of romdata we need to pad the
- // word with zeros.
- if (IsRomData)
- O << 0 <<", ";
- O << Val;
- }
- else if (BitWidth == 16) {
- unsigned Element1, Element2;
- Element1 = 0x00ff & Val;
- Element2 = 0x00ff & (Val >> 8);
- if (IsRomData)
- O << 0 <<", "<<Element1 <<", "<< 0 <<", "<< Element2;
- else
- O << Element1 <<", "<< Element2;
- }
- else if (BitWidth == 32) {
- unsigned Element1, Element2, Element3, Element4;
- Element1 = 0x00ff & Val;
- Element2 = 0x00ff & (Val >> 8);
- Element3 = 0x00ff & (Val >> 16);
- Element4 = 0x00ff & (Val >> 24);
- if (IsRomData)
- O << 0 <<", "<< Element1 <<", "<< 0 <<", "<< Element2 <<", "<< 0
- <<", "<< Element3 <<", "<< 0 <<", "<< Element4;
- else
- O << Element1 <<", "<< Element2 <<", "<< Element3 <<", "<< Element4;
+ EmitGlobalConstant(C, AddrSpace);
}
- return;
}
- AsmPrinter::EmitConstantValueOnly(CV);
}
void PIC16AsmPrinter::EmitRomData (Module &M)
continue;
O << name;
- EmitGlobalConstant(C);
+ EmitGlobalConstant(C, AddrSpace);
O << "\n";
}
}
// The variables of a function are of form FuncName.* . If this variable
// does not belong to this function then continue.
- if (!(VarName.find(FuncName + ".") == 0 ? true : false))
+ // Static local varilabes of a function does not have .auto. in their
+ // name. They are not printed as part of function data but module
+ // level global data.
+ if (!(VarName.find(FuncName + ".auto.") == 0 ? true : false))
continue;
-
+
Constant *C = I->getInitializer();
const Type *Ty = C->getType();
unsigned Size = TD->getTypePaddedSize(Ty);
// Emit memory reserve directive.
O << VarName << " RES " << Size << "\n";
}
- emitFunctionTempData(MF, FrameSize);
+
+ // Return value can not overlap with temp data, becasue a temp slot
+ // may be read/written after a return value is calculated and saved
+ // within the function.
if (RetSize > FrameSize)
- O << CurrentFnName << ".dummy" << "RES" << (RetSize - FrameSize);
+ O << CurrentFnName << ".dummy" << " RES " << (RetSize - FrameSize) << "\n";
+
+ emitFunctionTempData(MF, FrameSize);
}
void PIC16AsmPrinter::emitFunctionTempData(MachineFunction &MF,