SHELL := bash
NAME := codea
CFLAGS := -ansi -pedantic -D_GNU_SOURCE
-OBJS := scanner.o parser.o symtable.o code.o
+OBJS := scanner.o parser.o symtable.o code.o chelper.o
all: $(NAME)
@echo " FLEX $<"
@flex -o$@ $<
-%.o: %.c parser.h symtable.h
+#dirty deps ;)
+%.o: %.c parser.h symtable.h chelper.h
@echo " CC $<"
@gcc -c $(CFLAGS) $< #-Wall
-parser.c: oxout.y
+parser.c: oxout.y chelper.h
@echo " YACC $<"
@yacc -t -v -d $< -o $@
@echo " OX $^"
@ox $^
-%.c: %.bfe
+%.c: %.bfe chelper.h
@echo " IBURG $<"
@bfe < $< | iburg > $@
--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#include "chelper.h"
+
+void func_header(char *s)
+{
+ printf("\t.globl %1$s\n\t.type %1$s, @function\n%1$s:\n", s);
+}
+
+void move(char *src, char *dst)
+{
+ if(strcmp(src,dst) != 0) {
+ printf("\tmovq %%%s, %%%s\n", src, dst);
+ }
+}
+
+void ret(void)
+{
+ printf("\tret\n");
+}
+
+char *next_reg(char *s, short skip)
+{
+ char *regs[] = {"rax", "r10", "r11", "r9", "r8", "rcx", "rdx", "rsi", "rdi"};
+ int i=0;
+ if (s != (char*) NULL) {
+ for(; i < 9;) {
+ if(!strcmp(s, regs[i++])) {
+ break;
+ }
+ }
+ }
+ if(skip) {
+ i++;
+ }
+ return regs[i];
+}
+
+char *param_reg(int num)
+{
+ char *regs[] = {"rdi", "rsi", "rdx", "rcx", "r8", "r9"};
+ return regs[num-1];
+}
+
--- /dev/null
+#ifndef __CHELPER_H
+#define __CHELPER_H
+void func_header(char *s);
+char *next_reg(char *s, short skip);
+char *param_reg(int num);
+void ret(void);
+void move(char *src, char *dest);
+#endif