Get my first test source file compiling into valid ORCA/M assembly source.

This commit is contained in:
Jeremy Rand 2016-05-13 22:56:40 -04:00
parent 4cc95195f4
commit f8d884f5f9
4 changed files with 61 additions and 13 deletions

View File

@ -27,22 +27,33 @@ to describe the registers because we dont have many) and the instruction set.
That is in reasonable shape but there is definitely work there too.
Right now, you can get the code and compile it. You will be left with a clang
binary that appears to have 65816 support. If you try to compile any C code
with it targeting the 65816 though, the compiler will crash today. But, as of
yesterday, I couldnt even get a build so that is some progress.
binary that appears to have 65816 support. The following code will compile
successfully:
What is next?
===========
My initial goal is to get the compiler to produce assembly for this C code:
int answerToTheUltimateQuestion(void)
int answer(void)
{
return 42; // The answer
}
Once that is working, then I will try to get more working until it is a usable
compiler. There are _lots_ of issues and problems waiting for me (us?).
You can compile it with this commandline:
bin/clang --target=wdc65816 -S -o answer.s answer.c
I have copied that answer.s file to my Apple //GS and can assemble it using
ORCA/M and link it into an executable that works. Of course, it compiles
two opcodes (LDA and RTL) so not very impressive.
What is next?
===========
My next goal is to get the compiler to produce assembly for this C code:
int myGlobal=42;
int answer2(void)
{
return myGlobal; // The answer
}
How to build the project?

View File

@ -59,8 +59,20 @@ void WDC65816TargetAsmStreamer::EmitKeepDirective(StringRef filename)
void WDC65816TargetAsmStreamer::EmitSegStartDirective(StringRef filename)
{
StringRef trimmedName = trimFilename(filename);
int col = 1;
OS << "~";
col++;
OS << trimFilename(filename);
OS << "seg start";
col += trimmedName.size();
while (col < indentlen) {
OS << " ";
col++;
}
OS << " start";
OS << '\n';
}
@ -73,6 +85,22 @@ void WDC65816TargetAsmStreamer::EmitSegEndDirective(void)
}
void WDC65816TargetAsmStreamer::EmitFunctionEntryLabel(StringRef function)
{
int col = 1;
OS << function;
col += function.size();
while (col < indentlen) {
OS << " ";
col++;
}
OS << " entry";
OS << '\n';
}
void WDC65816TargetAsmStreamer::EmitInstruction(StringRef instruction)
{
instruction = instruction.ltrim();

View File

@ -25,17 +25,19 @@ namespace llvm {
virtual void EmitSegStartDirective(StringRef filename) = 0;
virtual void EmitSegEndDirective(void) = 0;
virtual void EmitFunctionEntryLabel(StringRef function) = 0;
virtual void EmitInstruction(StringRef instruction) = 0;
};
class WDC65816TargetAsmStreamer : public WDC65816TargetStreamer {
formatted_raw_ostream &OS;
StringRef indent;
int indentlen;
StringRef &trimFilename(StringRef &filename);
public:
WDC65816TargetAsmStreamer(formatted_raw_ostream &OS) : OS(OS), indent(" ") {}
WDC65816TargetAsmStreamer(formatted_raw_ostream &OS) : OS(OS), indent(" "), indentlen(11) {}
virtual ~WDC65816TargetAsmStreamer();
virtual void EmitCaseDirective(void);
@ -43,6 +45,7 @@ namespace llvm {
virtual void EmitSegStartDirective(StringRef filename);
virtual void EmitSegEndDirective(void);
virtual void EmitFunctionEntryLabel(StringRef function);
virtual void EmitInstruction(StringRef instruction);
};
}

View File

@ -55,6 +55,7 @@ namespace {
virtual void EmitStartOfAsmFile(Module &module);
virtual void EmitEndOfAsmFile(Module &module);
virtual void EmitFunctionEntryLabel();
virtual void EmitInstruction(const MachineInstr *MI) {
SmallString<128> Str;
@ -134,6 +135,11 @@ bool WDC65816AsmPrinter::printGetPCX(const MachineInstr *MI, unsigned opNum,
}
void WDC65816AsmPrinter::EmitFunctionEntryLabel() {
WDC65816TargetStreamer &streamer = getTargetStreamer();
streamer.EmitFunctionEntryLabel(CurrentFnSym->getName());
}
// Force static initialization.
extern "C" void LLVMInitializeWDC65816AsmPrinter() {
RegisterAsmPrinter<WDC65816AsmPrinter> X(TheWDC65816Target);