From 73e86dfddc6c4375afc1b73cf9b47f13f73a1973 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Thu, 22 Apr 2010 16:21:20 +0200 Subject: [PATCH] codea: chelper aka 'code helper' ... hilfsfunktionen zur registerwahl und aufbaufkts fuer assemblerfile --- codea/Makefile | 9 +++++---- codea/chelper.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ codea/chelper.h | 8 ++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 codea/chelper.c create mode 100644 codea/chelper.h diff --git a/codea/Makefile b/codea/Makefile index 1553b6b..2b0df7d 100644 --- a/codea/Makefile +++ b/codea/Makefile @@ -1,7 +1,7 @@ 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) @@ -13,11 +13,12 @@ scanner.c: oxout.l @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 $@ @@ -27,7 +28,7 @@ oxout.y oxout.l: parser.y scanner.lex @echo " OX $^" @ox $^ -%.c: %.bfe +%.c: %.bfe chelper.h @echo " IBURG $<" @bfe < $< | iburg > $@ diff --git a/codea/chelper.c b/codea/chelper.c new file mode 100644 index 0000000..c590232 --- /dev/null +++ b/codea/chelper.c @@ -0,0 +1,44 @@ +#include +#include +#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]; +} + diff --git a/codea/chelper.h b/codea/chelper.h new file mode 100644 index 0000000..9336fd6 --- /dev/null +++ b/codea/chelper.h @@ -0,0 +1,8 @@ +#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 -- 2.25.1