blob: 686d08084944fedc80b9fa32a953dfdcf0c4a79f [file] [log] [blame]
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +00001//===-- PIC16AsmPrinter.h - PIC16 LLVM assembly writer ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains a printer that converts from our internal representation
11// of machine-dependent LLVM code to PIC16 assembly language.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef PIC16ASMPRINTER_H
16#define PIC16ASMPRINTER_H
17
18#include "PIC16.h"
19#include "PIC16TargetMachine.h"
20#include "PIC16DebugInfo.h"
Chris Lattner621c44d2009-08-22 20:48:53 +000021#include "PIC16MCAsmInfo.h"
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000022#include "PIC16TargetObjectFile.h"
23#include "llvm/Analysis/DebugInfo.h"
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000024#include "llvm/CodeGen/AsmPrinter.h"
25#include "llvm/Support/CommandLine.h"
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000026#include "llvm/Target/TargetMachine.h"
27#include <list>
28#include <string>
29
30namespace llvm {
31 class VISIBILITY_HIDDEN PIC16AsmPrinter : public AsmPrinter {
32 public:
33 explicit PIC16AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
Chris Lattner621c44d2009-08-22 20:48:53 +000034 const MCAsmInfo *T, bool V);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000035 private:
36 virtual const char *getPassName() const {
37 return "PIC16 Assembly Printer";
38 }
39
40 PIC16TargetObjectFile &getObjFileLowering() const {
41 return (PIC16TargetObjectFile &)AsmPrinter::getObjFileLowering();
42 }
43
44 bool runOnMachineFunction(MachineFunction &F);
45 void printOperand(const MachineInstr *MI, int opNum);
46 void printCCOperand(const MachineInstr *MI, int opNum);
47 void printInstruction(const MachineInstr *MI); // definition autogenerated.
Chris Lattner213703c2009-09-13 20:19:22 +000048 static const char *getRegisterName(unsigned RegNo);
Chris Lattner92221692009-09-13 20:08:00 +000049
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000050 bool printMachineInstruction(const MachineInstr *MI);
51 void EmitFunctionDecls (Module &M);
52 void EmitUndefinedVars (Module &M);
53 void EmitDefinedVars (Module &M);
54 void EmitIData (Module &M);
55 void EmitUData (Module &M);
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000056 void EmitAllAutos (Module &M);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000057 void EmitRomData (Module &M);
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000058 void EmitUserSections (Module &M);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000059 void EmitFunctionFrame(MachineFunction &MF);
60 void printLibcallDecls();
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000061 void EmitUninitializedDataSection(const PIC16Section *S);
62 void EmitInitializedDataSection(const PIC16Section *S);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000063 protected:
64 bool doInitialization(Module &M);
65 bool doFinalization(Module &M);
66
67 /// PrintGlobalVariable - Emit the specified global variable and its
68 /// initializer to the output stream.
69 virtual void PrintGlobalVariable(const GlobalVariable *GV) {
70 // PIC16 doesn't use normal hooks for this.
71 }
72
73 private:
74 PIC16TargetObjectFile *PTOF;
75 PIC16TargetLowering *PTLI;
76 PIC16DbgInfo DbgInfo;
Chris Lattnera5ef4d32009-08-22 21:43:10 +000077 const PIC16MCAsmInfo *PMAI;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000078 std::list<const char *> LibcallDecls; // List of extern decls.
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000079 std::vector<const GlobalVariable *> ExternalVarDecls;
80 std::vector<const GlobalVariable *> ExternalVarDefs;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000081 };
82} // end of namespace
83
84#endif