blob: 312c54e56fbe61f45096cc4f1a08c95652fd8e57 [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>
Benjamin Kramer84399042010-03-20 17:41:18 +000028#include <set>
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000029#include <string>
30
31namespace llvm {
32 class VISIBILITY_HIDDEN PIC16AsmPrinter : public AsmPrinter {
33 public:
34 explicit PIC16AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
Chris Lattnerf4853452010-03-13 20:55:24 +000035 MCStreamer &Streamer);
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);
Chris Lattner4e972532010-04-04 04:47:45 +000046 void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
47 void printCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
48 void printInstruction(const MachineInstr *MI, raw_ostream &O);
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;
Benjamin Kramer84399042010-03-20 17:41:18 +000084 std::set<std::string> LibcallDecls; // Sorted & uniqued set 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