[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Add debug stream parameter to init_jit()
From: |
Paul Cercueil |
Subject: |
[PATCH] Add debug stream parameter to init_jit() |
Date: |
Wed, 11 Oct 2023 17:47:53 +0200 |
Allow specifying where Lightning's messages and disassembly will be
printed, instead of inconditionally using the error output.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
doc/body.texi | 14 ++++++++------
doc/fact.c | 2 +-
doc/ifib.c | 2 +-
doc/incr.c | 2 +-
doc/printf.c | 2 +-
doc/rfib.c | 2 +-
doc/rpn.c | 2 +-
include/lightning.h.in | 3 ++-
include/lightning/jit_private.h | 4 ++--
lib/jit_disasm.c | 6 +++---
lib/jit_print.c | 4 ++--
lib/lightning.c | 7 +++++--
12 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/doc/body.texi b/doc/body.texi
index f71b77c..fbccabc 100644
--- a/doc/body.texi
+++ b/doc/body.texi
@@ -1225,7 +1225,7 @@ int main(int argc, char *argv[])
jit_node_t *in;
pifi incr;
- init_jit(argv[0]);
+ init_jit(argv[0], NULL);
_jit = jit_new_state();
jit_prolog(); @rem{/* @t{ prolog } */}
@@ -1272,13 +1272,15 @@ and be used as argument to @code{getarg}.
Declares a function pointer variable to a function that receives an
@code{int} and returns an @code{int}.
-@item init_jit(argv[0]);
+@item init_jit(argv[0], NULL);
You must call this function before creating a @code{jit_state_t}
object. This function does global state initialization, and may need
to detect CPU or Operating System features. It receives a string
argument that is later used to read symbols from a shared object using
GNU binutils if disassembly was enabled at configure time. If no
disassembly will be performed a NULL pointer can be used as argument.
+The second argument corresponds to the output stream where Lightning's
+messages and disassembly will be printed. If NULL, stderr will be used.
@item _jit = jit_new_state();
This call initializes a @lightning{} jit state.
@@ -1382,7 +1384,7 @@ int main(int argc, char *argv[])
jit_node_t *start, *end; @rem{/* a couple of labels */}
jit_node_t *in; @rem{/* to get the argument */}
- init_jit(argv[0]);
+ init_jit(argv[0], NULL);
_jit = jit_new_state();
start = jit_note(__FILE__, __LINE__);
@@ -1584,7 +1586,7 @@ int main(int argc, char *argv[])
pifi c2f, f2c;
int i;
- init_jit(argv[0]);
+ init_jit(argv[0], NULL);
_jit = jit_new_state();
nc = compile_rpn("32x9*5/+");
@@ -1655,7 +1657,7 @@ int main(int argc, char *argv[])
jit_node_t *ref; @rem{/* to patch the forward reference */}
jit_node_t *zero; @rem{/* to patch the forward reference */}
- init_jit(argv[0]);
+ init_jit(argv[0], NULL);
_jit = jit_new_state();
label = jit_label();
@@ -1732,7 +1734,7 @@ int main(int argc, char *argv[])
jit_node_t *jump; @rem{/* jump to start of loop */}
jit_node_t *loop; @rem{/* start of the loop */}
- init_jit(argv[0]);
+ init_jit(argv[0], NULL);
_jit = jit_new_state();
jit_prolog ();
diff --git a/doc/fact.c b/doc/fact.c
index 375905b..260aec1 100644
--- a/doc/fact.c
+++ b/doc/fact.c
@@ -17,7 +17,7 @@ int main(int argc, char *argv[])
jit_node_t *fact_entry;
jit_node_t *fact_out;
- init_jit(argv[0]);
+ init_jit(argv[0], NULL);
_jit = jit_new_state();
/* declare a forward label */
diff --git a/doc/ifib.c b/doc/ifib.c
index 745c80b..c9a06eb 100644
--- a/doc/ifib.c
+++ b/doc/ifib.c
@@ -14,7 +14,7 @@ int main(int argc, char *argv[])
jit_node_t *jump; /* jump to start of loop */
jit_node_t *loop; /* start of the loop */
- init_jit(argv[0]);
+ init_jit(argv[0], NULL);
_jit = jit_new_state();
jit_prolog ();
diff --git a/doc/incr.c b/doc/incr.c
index 88859a8..a019fbb 100644
--- a/doc/incr.c
+++ b/doc/incr.c
@@ -10,7 +10,7 @@ int main(int argc, char *argv[])
jit_node_t *in;
pifi incr;
- init_jit(argv[0]);
+ init_jit(argv[0], NULL);
_jit = jit_new_state();
jit_prolog(); /* @t{ prolog } */
diff --git a/doc/printf.c b/doc/printf.c
index b36eec0..05b3856 100644
--- a/doc/printf.c
+++ b/doc/printf.c
@@ -11,7 +11,7 @@ int main(int argc, char *argv[])
jit_node_t *start, *end; /* a couple of labels */
jit_node_t *in; /* to get the argument */
- init_jit(argv[0]);
+ init_jit(argv[0], NULL);
_jit = jit_new_state();
start = jit_note(__FILE__, __LINE__);
diff --git a/doc/rfib.c b/doc/rfib.c
index f14da42..1d1ca95 100644
--- a/doc/rfib.c
+++ b/doc/rfib.c
@@ -14,7 +14,7 @@ int main(int argc, char *argv[])
jit_node_t *ref; /* to patch the forward reference */
jit_node_t *zero; /* to patch the forward reference */
- init_jit(argv[0]);
+ init_jit(argv[0], NULL);
_jit = jit_new_state();
label = jit_label();
diff --git a/doc/rpn.c b/doc/rpn.c
index edb3d8e..ae94038 100644
--- a/doc/rpn.c
+++ b/doc/rpn.c
@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
pifi c2f, f2c;
int i;
- init_jit(argv[0]);
+ init_jit(argv[0], NULL);
_jit = jit_new_state();
nc = compile_rpn("32x9*5/+");
diff --git a/include/lightning.h.in b/include/lightning.h.in
index 6d51235..25f685b 100644
--- a/include/lightning.h.in
+++ b/include/lightning.h.in
@@ -23,6 +23,7 @@
#include <unistd.h>
#include <stdlib.h>
@MAYBE_INCLUDE_STDINT_H@
+#include <stdio.h>
#include <string.h>
#include <pthread.h>
@@ -1220,7 +1221,7 @@ typedef void (*jit_free_func_ptr) (void*);
/*
* Prototypes
*/
-extern void init_jit(const char*);
+extern void init_jit(const char*,FILE*);
extern void finish_jit(void);
extern jit_state_t *jit_new_state(void);
diff --git a/include/lightning/jit_private.h b/include/lightning/jit_private.h
index 9f8caf6..a730d73 100644
--- a/include/lightning/jit_private.h
+++ b/include/lightning/jit_private.h
@@ -873,8 +873,8 @@ _emit_ldxi_d(jit_state_t*, jit_int32_t, jit_int32_t,
jit_word_t);
extern void
_emit_stxi_d(jit_state_t*, jit_word_t, jit_int32_t, jit_int32_t);
-extern void jit_init_print(void);
-extern void jit_init_debug(const char*);
+extern void jit_init_print(FILE*);
+extern void jit_init_debug(const char*, FILE*);
extern void jit_finish_debug(void);
extern void jit_init_note(void);
diff --git a/lib/jit_disasm.c b/lib/jit_disasm.c
index 456b4f6..90d90b0 100644
--- a/lib/jit_disasm.c
+++ b/lib/jit_disasm.c
@@ -71,9 +71,9 @@ static int fprintf_styled(void * stream, enum
disassembler_style style, const ch
* Implementation
*/
void
-jit_init_debug(const char *progname)
+jit_init_debug(const char *progname, FILE *stream)
{
- jit_init_print();
+ jit_init_print(stream);
#if DISASSEMBLER
bfd_init();
@@ -89,7 +89,7 @@ jit_init_debug(const char *progname)
bfd_check_format(disasm_bfd, bfd_object);
bfd_check_format(disasm_bfd, bfd_archive);
if (!disasm_stream)
- disasm_stream = stderr;
+ disasm_stream = stream;
#if BINUTILS_2_38
INIT_DISASSEMBLE_INFO(disasm_info, disasm_stream, fprintf, fprintf_styled);
diff --git a/lib/jit_print.c b/lib/jit_print.c
index 3a16c64..079112b 100644
--- a/lib/jit_print.c
+++ b/lib/jit_print.c
@@ -75,10 +75,10 @@ static FILE *print_stream;
* Implementation
*/
void
-jit_init_print(void)
+jit_init_print(FILE *stream)
{
if (!print_stream)
- print_stream = stderr;
+ print_stream = stream;
}
void
diff --git a/lib/lightning.c b/lib/lightning.c
index 39c4fc2..fd6f5e0 100644
--- a/lib/lightning.c
+++ b/lib/lightning.c
@@ -181,10 +181,13 @@ _patch_register(jit_state_t *jit, jit_node_t *node,
jit_node_t *link,
* Implementation
*/
void
-init_jit(const char *progname)
+init_jit(const char *progname, FILE *dbg_out)
{
+ if (!dbg_out)
+ dbg_out = stderr;
+
jit_get_cpu();
- jit_init_debug(progname);
+ jit_init_debug(progname, dbg_out);
jit_init_size();
}
--
2.40.1
- [PATCH] Add debug stream parameter to init_jit(),
Paul Cercueil <=