mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Initial cut at an asm writer emitter. So far, this only handles emission of
instructions, and only instructions that take no operands at that! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15386 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ec3524064c
commit
2e1f51b8a5
48
utils/TableGen/AsmWriterEmitter.cpp
Normal file
48
utils/TableGen/AsmWriterEmitter.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
//===- AsmWriterEmitter.cpp - Generate an assembly writer -----------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file was developed by the LLVM research group and is distributed under
|
||||||
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This tablegen backend is emits an assembly printer for the current target.
|
||||||
|
// Note that this is currently fairly skeletal, but will grow over time.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "AsmWriterEmitter.h"
|
||||||
|
#include "CodeGenTarget.h"
|
||||||
|
#include <ostream>
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
void AsmWriterEmitter::run(std::ostream &O) {
|
||||||
|
EmitSourceFileHeader("Assembly Writer Source Fragment", O);
|
||||||
|
|
||||||
|
CodeGenTarget Target;
|
||||||
|
O <<
|
||||||
|
"/// printInstruction - This method is automatically generated by tablegen\n"
|
||||||
|
"/// from the instruction set description. This method returns true if the\n"
|
||||||
|
"/// machine instruction was sufficiently described to print it, otherwise\n"
|
||||||
|
"/// it returns false.\n"
|
||||||
|
"bool " << Target.getName()
|
||||||
|
<< "AsmPrinter::printInstruction(const MachineInstr *MI) {\n";
|
||||||
|
O << " switch (MI->getOpcode()) {\n"
|
||||||
|
" default: return false;\n";
|
||||||
|
|
||||||
|
std::string Namespace = Target.inst_begin()->second.Namespace;
|
||||||
|
|
||||||
|
for (CodeGenTarget::inst_iterator I = Target.inst_begin(),
|
||||||
|
E = Target.inst_end(); I != E; ++I)
|
||||||
|
if (!I->second.AsmString.empty()) {
|
||||||
|
const std::string &AsmString = I->second.AsmString;
|
||||||
|
O << " case " << Namespace << "::" << I->first << ": O << \""
|
||||||
|
<< AsmString << "\" << '\\n'; break;\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
O << " }\n"
|
||||||
|
" return true;\n"
|
||||||
|
"}\n";
|
||||||
|
EmitSourceFileTail(O);
|
||||||
|
}
|
31
utils/TableGen/AsmWriterEmitter.h
Normal file
31
utils/TableGen/AsmWriterEmitter.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
//===- AsmWriterEmitter.h - Generate an assembly writer ---------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file was developed by the LLVM research group and is distributed under
|
||||||
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This tablegen backend is responsible for emitting an assembly printer for the
|
||||||
|
// code generator.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef ASMWRITER_EMITTER_H
|
||||||
|
#define ASMWRITER_EMITTER_H
|
||||||
|
|
||||||
|
#include "TableGenBackend.h"
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
|
||||||
|
class AsmWriterEmitter : public TableGenBackend {
|
||||||
|
RecordKeeper &Records;
|
||||||
|
public:
|
||||||
|
AsmWriterEmitter(RecordKeeper &R) : Records(R) {}
|
||||||
|
|
||||||
|
// run - Output the asmwriter, returning true on failure.
|
||||||
|
void run(std::ostream &o);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
@ -122,14 +122,23 @@ CodeGenInstruction::CodeGenInstruction(Record *R) : TheDef(R) {
|
|||||||
Namespace = R->getValueAsString("Namespace");
|
Namespace = R->getValueAsString("Namespace");
|
||||||
AsmString = R->getValueAsString("AsmString");
|
AsmString = R->getValueAsString("AsmString");
|
||||||
|
|
||||||
//TODO: Parse OperandList
|
|
||||||
|
|
||||||
isReturn = R->getValueAsBit("isReturn");
|
isReturn = R->getValueAsBit("isReturn");
|
||||||
isBranch = R->getValueAsBit("isBranch");
|
isBranch = R->getValueAsBit("isBranch");
|
||||||
isBarrier = R->getValueAsBit("isBarrier");
|
isBarrier = R->getValueAsBit("isBarrier");
|
||||||
isCall = R->getValueAsBit("isCall");
|
isCall = R->getValueAsBit("isCall");
|
||||||
isTwoAddress = R->getValueAsBit("isTwoAddress");
|
isTwoAddress = R->getValueAsBit("isTwoAddress");
|
||||||
isTerminator = R->getValueAsBit("isTerminator");
|
isTerminator = R->getValueAsBit("isTerminator");
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: Parse OperandList
|
||||||
|
try {
|
||||||
|
DagInit *DI = R->getValueAsDag("OperandList");
|
||||||
|
|
||||||
|
// Cannot handle instructions with operands yet.
|
||||||
|
if (DI->getNumArgs())
|
||||||
|
AsmString.clear();
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "CodeEmitterGen.h"
|
#include "CodeEmitterGen.h"
|
||||||
#include "RegisterInfoEmitter.h"
|
#include "RegisterInfoEmitter.h"
|
||||||
#include "InstrInfoEmitter.h"
|
#include "InstrInfoEmitter.h"
|
||||||
|
#include "AsmWriterEmitter.h"
|
||||||
#include "InstrSelectorEmitter.h"
|
#include "InstrSelectorEmitter.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@ -32,7 +33,7 @@ enum ActionType {
|
|||||||
PrintRecords,
|
PrintRecords,
|
||||||
GenEmitter,
|
GenEmitter,
|
||||||
GenRegisterEnums, GenRegister, GenRegisterHeader,
|
GenRegisterEnums, GenRegister, GenRegisterHeader,
|
||||||
GenInstrEnums, GenInstrs, GenInstrSelector,
|
GenInstrEnums, GenInstrs, GenAsmWriter, GenInstrSelector,
|
||||||
PrintEnums,
|
PrintEnums,
|
||||||
Parse
|
Parse
|
||||||
};
|
};
|
||||||
@ -54,6 +55,8 @@ namespace {
|
|||||||
"Generate enum values for instructions"),
|
"Generate enum values for instructions"),
|
||||||
clEnumValN(GenInstrs, "gen-instr-desc",
|
clEnumValN(GenInstrs, "gen-instr-desc",
|
||||||
"Generate instruction descriptions"),
|
"Generate instruction descriptions"),
|
||||||
|
clEnumValN(GenAsmWriter, "gen-asm-writer",
|
||||||
|
"Generate assembly writer"),
|
||||||
clEnumValN(GenInstrSelector, "gen-instr-selector",
|
clEnumValN(GenInstrSelector, "gen-instr-selector",
|
||||||
"Generate an instruction selector"),
|
"Generate an instruction selector"),
|
||||||
clEnumValN(PrintEnums, "print-enums",
|
clEnumValN(PrintEnums, "print-enums",
|
||||||
@ -454,6 +457,11 @@ int main(int argc, char **argv) {
|
|||||||
case GenInstrs:
|
case GenInstrs:
|
||||||
InstrInfoEmitter(Records).run(*Out);
|
InstrInfoEmitter(Records).run(*Out);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GenAsmWriter:
|
||||||
|
AsmWriterEmitter(Records).run(*Out);
|
||||||
|
break;
|
||||||
|
|
||||||
case GenInstrSelector:
|
case GenInstrSelector:
|
||||||
InstrSelectorEmitter(Records).run(*Out);
|
InstrSelectorEmitter(Records).run(*Out);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user