Fixing arm instructions
This commit is contained in:
parent
5bd793e07e
commit
b09a06d07a
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,4 @@
|
||||
compiler/config.mk
|
||||
compiler/build/
|
||||
compiler/generated/
|
||||
ifcc-test-output/
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "CodeGenVisitor.h"
|
||||
|
||||
antlrcpp::Any CodeGenVisitor::visitProg(ifccParser::ProgContext *ctx)
|
||||
antlrcpp::Any CodeGenVisitor::visitProg(ifccParser::ProgContext *ctx)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
std::cout<< ".globl _main\n" ;
|
||||
@ -11,7 +11,7 @@ antlrcpp::Any CodeGenVisitor::visitProg(ifccParser::ProgContext *ctx)
|
||||
#endif
|
||||
|
||||
this->visit( ctx->return_stmt() );
|
||||
|
||||
|
||||
std::cout << " ret\n";
|
||||
|
||||
return 0;
|
||||
@ -22,7 +22,11 @@ antlrcpp::Any CodeGenVisitor::visitReturn_stmt(ifccParser::Return_stmtContext *c
|
||||
{
|
||||
int retval = stoi(ctx->CONST()->getText());
|
||||
|
||||
std::cout << " movl $"<<retval<<", %eax\n" ;
|
||||
#ifdef __APPLE__
|
||||
std::cout << " mov w0, #"<<retval<<"\n" ;
|
||||
#else
|
||||
std::cout << " movl $"<<retval<<", %eax\n" ;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ default: all
|
||||
all: ifcc
|
||||
|
||||
##########################################
|
||||
# link together all pieces of our compiler
|
||||
# link together all pieces of our compiler
|
||||
OBJECTS=build/ifccBaseVisitor.o \
|
||||
build/ifccLexer.o \
|
||||
build/ifccVisitor.o \
|
||||
@ -28,13 +28,13 @@ ifcc: $(OBJECTS)
|
||||
# compile our hand-writen C++ code: main(), CodeGenVisitor, etc.
|
||||
build/%.o: %.cpp generated/ifccParser.cpp
|
||||
@mkdir -p build
|
||||
$(CC) $(CCFLAGS) -MMD -o $@ $<
|
||||
$(CC) $(CCFLAGS) -MMD -o $@ $<
|
||||
|
||||
##########################################
|
||||
# compile all the antlr-generated C++
|
||||
build/%.o: generated/%.cpp
|
||||
@mkdir -p build
|
||||
$(CC) $(CCFLAGS) -MMD -o $@ $<
|
||||
$(CC) $(CCFLAGS) -MMD -o $@ $<
|
||||
|
||||
# automagic dependency management: `gcc -MMD` generates all the .d files for us
|
||||
-include build/*.d
|
||||
@ -50,7 +50,7 @@ generated/ifccParser.cpp: ifcc.g4
|
||||
java -jar $(ANTLRJAR) -visitor -no-listener -Dlanguage=Cpp -o generated ifcc.g4
|
||||
|
||||
# prevent automatic cleanup of "intermediate" files like ifccLexer.cpp etc
|
||||
.PRECIOUS: generated/ifcc%.cpp
|
||||
.PRECIOUS: generated/ifcc%.cpp
|
||||
|
||||
##########################################
|
||||
# view the parse tree in a graphical window
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
# these values work with the "install-antlr.sh" script provided for the PLD
|
||||
ANTLRJAR=../antlr/jar/antlr-4.9.2-complete.jar
|
||||
ANTLRINC=../antlr/include
|
||||
ANTLRLIB=../antlr/lib/libantlr4-runtime.a
|
||||
@ -1,3 +0,0 @@
|
||||
ANTLRJAR=/home/$(USER)/antlr4-install/antlr-4.13.2-complete.jar
|
||||
ANTLRINC=/usr/local/include/antlr4-runtime/
|
||||
ANTLRLIB=/usr/local/lib/libantlr4-runtime.a
|
||||
3
compiler/config.example.mk
Normal file
3
compiler/config.example.mk
Normal file
@ -0,0 +1,3 @@
|
||||
ANTLRJAR=$(shell brew --prefix antlr)/antlr-4.13.2-complete.jar
|
||||
ANTLRINC=$(shell brew --prefix antlr4-cpp-runtime)/include/antlr4-runtime
|
||||
ANTLRLIB=$(shell brew --prefix antlr4-cpp-runtime)/lib/libantlr4-runtime.a
|
||||
Loading…
x
Reference in New Issue
Block a user