blob: 77b6e634710168c38a3fd29d9eabd4a7a73761c7 [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 Lattner8d2970b2010-02-02 23:37:42 +000034 MCContext &Ctx, MCStreamer &Streamer,
35 const MCAsmInfo *T);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000036 private:
37 virtual const char *getPassName() const {
38 return "PIC16 Assembly Printer";
39 }
40
41 PIC16TargetObjectFile &getObjFileLowering() const {
42 return (PIC16TargetObjectFile &)AsmPrinter::getObjFileLowering();
43 }
44
45 bool runOnMachineFunction(MachineFunction &F);
46 void printOperand(const MachineInstr *MI, int opNum);
47 void printCCOperand(const MachineInstr *MI, int opNum);
48 void printInstruction(const MachineInstr *MI); // definition autogenerated.
Chris Lattner213703c2009-09-13 20:19:22 +000049 static const char *getRegisterName(unsigned RegNo);
Chris Lattner92221692009-09-13 20:08:00 +000050
Chris Lattnercec64dd2010-02-03 01:41:03 +000051 void EmitInstruction(const MachineInstr *MI);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000052 void EmitFunctionDecls (Module &M);
53 void EmitUndefinedVars (Module &M);
54 void EmitDefinedVars (Module &M);
55 void EmitIData (Module &M);
56 void EmitUData (Module &M);
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000057 void EmitAllAutos (Module &M);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000058 void EmitRomData (Module &M);
Sanjiv Gupta27e801c2009-10-25 08:14:11 +000059 void EmitSharedUdata(Module &M);
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000060 void EmitUserSections (Module &M);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000061 void EmitFunctionFrame(MachineFunction &MF);
62 void printLibcallDecls();
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000063 void EmitUninitializedDataSection(const PIC16Section *S);
64 void EmitInitializedDataSection(const PIC16Section *S);
Sanjiv Gupta018db662009-10-16 08:58:34 +000065 void EmitSingleSection(const PIC16Section *S);
66 void EmitSectionList(Module &M,
67 const std::vector< PIC16Section *> &SList);
Sanjiv Gupta00e8f5a2009-10-21 10:42:44 +000068 void ColorAutoSection(const Function *F);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000069 protected:
70 bool doInitialization(Module &M);
71 bool doFinalization(Module &M);
72
Chris Lattner410c9472010-01-19 05:38:33 +000073 /// EmitGlobalVariable - Emit the specified global variable and its
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000074 /// initializer to the output stream.
Chris Lattner410c9472010-01-19 05:38:33 +000075 virtual void EmitGlobalVariable(const GlobalVariable *GV) {
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000076 // PIC16 doesn't use normal hooks for this.
77 }
78
79 private:
80 PIC16TargetObjectFile *PTOF;
81 PIC16TargetLowering *PTLI;
82 PIC16DbgInfo DbgInfo;
Chris Lattnera5ef4d32009-08-22 21:43:10 +000083 const PIC16MCAsmInfo *PMAI;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000084 std::list<const char *> LibcallDecls; // List of extern decls.
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000085 std::vector<const GlobalVariable *> ExternalVarDecls;
86 std::vector<const GlobalVariable *> ExternalVarDefs;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000087 };
88} // end of namespace
89
90#endif