Commit 2a5b509c authored by Axel Simon's avatar Axel Simon

make C89 a real option, improve x86 pretty printer

parent 509f35aa
......@@ -130,7 +130,7 @@ GDSLC_SML_FILES = \
JAR=jgdsl.jar
GDSLC_DEP = detail/codegen/c1/runtime.c detail/codegen/c1/runtime.h
GDSLFLAGS = --runtime=$(srcdir)/detail/codegen --target=C89
GDSLFLAGS = --runtime=$(srcdir)/detail/codegen @EXTRA_GDSL_FLAGS@
if HAVE_MLTON
......
......@@ -16,13 +16,20 @@ AC_PROG_LN_S()
AC_PROG_LIBTOOL()
AC_PROG_INSTALL()
dnl check if the compiler understand C99
AC_PROG_CC_C99()
AC_ARG_VAR(EXTRA_GDSL_FLAGS)
if test [x$ac_cv_prog_cc_c99 == "xno"]; then
EXTRA_GDSL_FLAGS="--target=C89";
fi
AC_ARG_VAR(SMLNJ)
AC_PATH_PROG(SMLNJ, sml, ["not-found"])
AC_ARG_VAR(MLTON)
AC_PATH_PROG(MLTON, mlton, ["not-found"])
if test [$SMLNJ == "not-found" -a $MLTON == "not-found"]; then
if test [x$SMLNJ == "xnot-found" -a x$MLTON == "xnot-found"]; then
echo "You must install either SML/NJ or mlton."
exit 1
fi
......
......@@ -571,6 +571,7 @@ structure C1 = struct
val recs = (ListMergeSort.sort (fn (r1,r2) => (#riSequenceNo r1)>(#riSequenceNo r2))
(AtomMap.listItems (!recordTypeMap)))
fun genStructCon ({ riBoxed = boxed, riFieldDecls = args, riTypeName = tyName, ... } : recordInfo) =
if tyName="monad" then seq [] else
align [
seq [str "static INLINE_ATTR", space, str tyName, str "_t", space,
str "__", str tyName, par (seq (separate (str "state_t s" ::
......@@ -725,7 +726,7 @@ structure C1 = struct
seq [str "static INLINE_ATTR ", emitStringFunType s (retTy,funName,(OBJvtype,"closure") :: args), str " {"],
indent 2 (seq [
if isVOIDvtype retTy then seq [] else str "return ",
str "((", emitTypeDecl s ([],FUNvtype (retTy,false,OBJvtype::argTys)), str ") closure)",
str "((struct {", emitTypeDecl s ([str "func"],FUNvtype (retTy,false,OBJvtype::argTys)), str ";}*) closure)->func",
fArgs (str "closure" :: map (str o #2) args), str ";"
]),
str "}"
......@@ -1066,6 +1067,7 @@ structure C1 = struct
val preDecl = !(#preDeclEmit s)
val _ = (#preDeclEmit s) := []
in
if #emitStructCons s then
align (
preDecl @ [
seq [str "static INLINE_ATTR", space, fTy, space, str "{"],
......@@ -1076,7 +1078,16 @@ structure C1 = struct
seq [str "return (obj_t) ", emitAllocCon s argTy, fArgs [str "adt"], str ";"]
]),
str "}"
])
])
else
align (
preDecl @ [
seq [str "static INLINE_ATTR", space, fTy, space, str "{"],
seq [str " return ", emitAllocCon s argTy,
fArgs [seq [str "(", emitConType s argTy, str "){",
str (getConTag s tag), str ", ", emitSym s argName, str "}"]], str ";"],
str "}"
])
end
end
| emitDecl s (inSCC,CLOSUREdecl {
......
......@@ -57,6 +57,8 @@ typedef unsigned int field_tag_t;
#define NO_INLINE_ATTR __attribute__((noinline))
#elif __GNUC__
#define NO_INLINE_ATTR __attribute__((noinline))
#elif _MSC_VER
#define NO_INLINE_ATTR __declspec(noinline)
#else
#define NO_INLINE_ATTR
#endif
......@@ -65,6 +67,8 @@ typedef unsigned int field_tag_t;
#define MALLOC_ATTR __attribute__((malloc))
#elif __GNUC__
#define MALLOC_ATTR __attribute__((malloc))
#elif _MSC_VER
#define MALLOC_ATTR __declspec(restrict)
#else
#define MALLOC_ATTR
#endif
......@@ -300,28 +304,19 @@ static INLINE_ATTR vec_t vec_concat(state_t s, vec_t v1, vec_t v2) {
}
static string_t int_to_string(state_t s, int_t v) {
if(v == LLONG_MIN)
return "(-9223372036854775807)";
else {
char *str = (char*) alloc(s, 23)+22;
int negate = v<0;
int_t r;
*str = 0;
if (negate) {
v = -v;
*--str = ')';
};
do {
r = v % 10;
v = v / 10;
*--str = '0'+(unsigned char) r;
} while (v!=0);
if (negate) {
*--str = '-';
*--str = '(';
}
return alloc_string(s,str);
char *str = (char*) alloc(s, 23)+22;
int negate = v<0;
int r;
*str = 0;
do {
r = v % 10;
v = v / 10;
*--str = "9876543210123456789"[r+9];
} while (v!=0);
if (negate) {
*--str = '-';
}
return alloc_string(s,str);
};
void
......@@ -438,6 +433,7 @@ int main (int argc, char** argv) {
int_t translate_options = 0;
int_t base_address = 0;
int_t start_address = 0;
int print_addr = 0;
unsigned int i,c;
obj_t config;
state_t s = gdsl_init();
......@@ -470,6 +466,7 @@ int main (int argc, char** argv) {
#endif
if (strncmp(arg,"base=",5)==0) {
sscanf(arg+5,"%lli",&base_address);
print_addr=1;
continue;
}
if (strncmp(arg,"start=",6)==0) {
......@@ -513,7 +510,7 @@ int main (int argc, char** argv) {
buf_size = i;
}; break;
case 0: {
fprintf(stderr, "invalid input; should be in hex form: '0f 0b ..'");
fprintf(stderr, "invalid input; should be in hex form: '0f 0b ..'.\n");
return 1;
}
}
......@@ -530,17 +527,18 @@ int main (int argc, char** argv) {
while (gdsl_get_ip_offset(s)<buf_size) {
int_t size;
int_t address=0;
if (setjmp(*gdsl_err_tgt(s))==0) {
if (run_translate) {
#ifdef HAVE_TRANS
int_t address = gdsl_get_ip_offset(s);
address = gdsl_get_ip_offset(s);
obj_t rreil = gdsl_decode_translate_block_optimized(s,
decode_options,
gdsl_int_max(s),
2);
obj_t res = gdsl_rreil_pretty(s,rreil);
string_t str = gdsl_merge_rope(s,res);
printf("0x%llx:\n",address);
if (print_addr) printf("0x%016llx:\n",address);
fputs(str,stdout);
#else
fputs("GDSL modules contain no semantic translation\n",stdout);
......@@ -548,9 +546,11 @@ int main (int argc, char** argv) {
#endif
} else {
#ifdef HAVE_DECODE
address = gdsl_get_ip_offset(s);
obj_t instr = gdsl_decode(s, decode_options);
obj_t res = gdsl_pretty(s,instr);
string_t str = gdsl_merge_rope(s,res);
if (print_addr) printf("%016llx ",address);
fputs(str,stdout);
#else
fputs("GDSL modules contain no decoder function\n",stdout);
......@@ -558,9 +558,8 @@ int main (int argc, char** argv) {
#endif
}
} else {
int_t address = gdsl_get_ip_offset(s);
fprintf(stdout,"exception at address 0x%llx: %s\n", address, gdsl_get_error_message(s));
return 1;
fprintf(stdout,"exception at address 0x%llx: %s", address, gdsl_get_error_message(s));
gdsl_seek(s,address+abs(s->token_addr_inv)+1);
}
fputs("\n",stdout);
size = gdsl_heap_residency(s);
......
......@@ -127,7 +127,7 @@ structure Error :> sig
| Repair.FailureAt tok => ["syntax error at ", tok2str tok]
(* end case *))
in
addErr (es, SOME{file=sourceMap es,span=(pos,pos)}, String.concat msg)
addErr (es, SOME{file=sourceMap es,span=(pos,pos)}, String.concat msg ^ "\n")
end
(* add error messages to the error stream *)
......
......@@ -243,12 +243,12 @@ val show/segment s =
end
end
val show/scale s =
val show/scale s arg =
case s of
'00': ""
| '01': "2*"
| '10': "4*"
| '11': "8*"
'00': arg
| '01': "2*" +++ "(" +++ arg +++ ")"
| '10': "4*" +++ "(" +++ arg +++ ")"
| '11': "8*" +++ "(" +++ arg +++ ")"
end
val show/operand ext op =
......@@ -263,20 +263,26 @@ val show/operand ext op =
| IMM64 x: show-int (case ext of '0': zx x.imm | '1': sx x.imm end)
| REG x: show/x86-register x
| MEM x: show/memsz x.sz -++ show/segment x.segment +++ "[" +++ show/operand '1' x.opnd +++ "]"
| X86_SUM x: show/operand ext x.a +++ "+" +++ show/operand ext x.b
| X86_SCALE x: show/scale x.imm +++ show/operand ext x.opnd
| X86_SUM x: show/operand ext x.a +++ (if ext then case x.b of
IMM8 c: (if sx c.imm<0 then "" else "+") +++ show/operand ext x.b
| IMM16 c: (if sx c.imm<0 then "" else "+") +++ show/operand ext x.b
| IMM32 c: (if sx c.imm<0 then "" else "+") +++ show/operand ext x.b
| IMM64 c: (if sx c.imm<0 then "" else "+") +++ show/operand ext x.b
| _ : "+" +++ show/operand ext x.b
end else "+" +++ show/operand ext x.b)
| X86_SCALE x: show/scale x.imm (show/operand ext x.opnd)
end
val show/flowoperand op =
case op of
REL8 x: "(IP + " +++ show-int (sx x) +++ ")"
| REL16 x: "(IP + " +++ show-int (sx x) +++ ")"
| REL32 x: "(IP + " +++ show-int (sx x) +++ ")"
| REL64 x: "(IP + " +++ show-int (sx x) +++ ")"
REL8 x: "IP" +++ (if sx x<0 then "" else "+") +++ show-int (sx x)
| REL16 x: "IP" +++ (if sx x<0 then "" else "+") +++ show-int (sx x)
| REL32 x: "IP" +++ (if sx x<0 then "" else "+") +++ show-int (sx x)
| REL64 x: "IP" +++ (if sx x<0 then "" else "+") +++ show-int (sx x)
| PTR16/16 x: "[16/16: " +++ show-int (sx x) +++ "]"
| PTR16/32 x: "[16/32: " +++ show-int (sx x) +++ "]"
| NEARABS x: show/operand '1' x
| FARABS x: show/operand '1' x
| NEARABS x: show/operand '0' x
| FARABS x: show/operand '0' x
end
val show/instruction insn = let
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment