From 39ecba0032be794a1f4d66f61e09e4910270330f Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 13 Mar 2019 21:05:34 -0400 Subject: migrate to gitlab --- as/Makefile | 11 +++++++++++ as/as.l | 25 +++++++++++++++++++++++++ as/as.y | 36 ++++++++++++++++++++++++++++++++++++ as/x86.h | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 as/Makefile create mode 100644 as/as.l create mode 100644 as/as.y create mode 100644 as/x86.h (limited to 'as') diff --git a/as/Makefile b/as/Makefile new file mode 100644 index 0000000..99fe9de --- /dev/null +++ b/as/Makefile @@ -0,0 +1,11 @@ +as: as.yy.o as.tab.o + c99 -o $@ as.yy.o as.tab.o -ly -ll + +as.yy.c: as.l as.tab.h + lex -t as.l > $@ + +as.tab.h as.tab.c: as.y + yacc -d -b as as.y + +clean: + rm -f as *.o as.yy.c as.tab.c as.tab.h diff --git a/as/as.l b/as/as.l new file mode 100644 index 0000000..059b7c3 --- /dev/null +++ b/as/as.l @@ -0,0 +1,25 @@ +%{ +#include +#include "as.tab.h" +%} + +NONDIGIT [_a-zA-Z] +DIGIT [0-9] +IDENTIFIERS [_a-zA-Z0-9] + +%x COMMENT + +%% + +{DIGIT}+ { yylval.n = strtoumax(yytext, NULL, 10); return NUMBER; } + +{NONDIGIT}{IDENTIFIERS}* { yylval.s = yytext; return TOKEN; } + +:|,|\. { return yytext[0]; } +\n { return NEWLINE; } + +; { BEGIN COMMENT; } +. ; +\n { BEGIN INITIAL; return NEWLINE; } + +. ; diff --git a/as/as.y b/as/as.y new file mode 100644 index 0000000..ed8714f --- /dev/null +++ b/as/as.y @@ -0,0 +1,36 @@ +%{ +#include +%} + +%union { + char *s; + uintmax_t n; +}; + +%token NUMBER +%token TOKEN +%token NEWLINE + +%% + +program + : /* empty */ + | instruction NEWLINE +; + +instruction + : bare_instruction + | TOKEN ':' bare_instruction +; + +bare_instruction + : TOKEN + | TOKEN operand + | TOKEN operand ',' operand + | TOKEN operand ',' operand ',' operand +; + +operand + : TOKEN + | NUMBER +; diff --git a/as/x86.h b/as/x86.h new file mode 100644 index 0000000..56bf639 --- /dev/null +++ b/as/x86.h @@ -0,0 +1,38 @@ +struct { +const char *mnemonic; +const char *opcode; +char x32; +char x64; +} x86_opcodes[] = { +{ "aaa", "37", 1, 0 }, + +{ "aad", "d5 0a", 1, 0 }, +{ "aad imm8", "db ib", 1, 0 }, + +{ "aam", "d4 0a", 1, 0 }, +{ "aam imm8", "d4 ib", 1, 0 }, + +{ "aas", "3f" , 1, 0 }, + +{ "adc al, imm8", "14 ib", 1, 1 }, +{ "adc ax, immm16", "15 iw", 1, 1 }, +{ "adc eax, imm32", "15 id", 1, 1 }, +{ "adc rax, imm32", "rex.w 15 id", 0, 1 }, +{ "adc r/m8, imm8", "80 /2 ib", 1, 1 }, +{ "adc r/m8*, imm8", "rex 80 /2 ib", 0, 1 }, +{ "adc r/m16, imm16", "81 /2 iw", 1, 1 }, +{ "adc r/m32, imm32", "81 /2 id", 1, 1 }, +{ "adc r/m64, imm32", "rex.w 81 /2 id", 0, 1 }, +{ "adc r/m16, imm8", "83 /2 ib", 1, 1 }, +{ "adc r/m32, imm8", "83 /2 ib", 1, 1 }, +{ "adc r/m64, imm8", "rex.w 83 /2 ib", 0, 1 }, +{ "adc r/m8, r8", "10 /r", 1, 1 }, +{ "adc r/m8*, r8*", "rex 10 /r", 0, 1 }, +{ "adc r/m16, r16", "11 /r", 1, 1 }, +{ "adc r/m32, r32", "11 /r", 1, 1 }, +{ "adc r/m64, r64", "rex.w 11 /r", 0, 1 }, +{ "adc r8, r/m8", "12 /r", 1, 1 }, +{ "adc r8*, r/m8*", "rex 12 /r", 0, 1 }, +{ "adc r16, r/m16", "13 /r", 1, 1 }, +{ "adc r32, r/m32", "13 /r", 1, 1 }, +{ "adc r64, r/m64", "rex.w 13 /r", 0, 1 }, -- cgit v1.2.1