* [PATCH] intel-gen4asm: have a C-like binary output
@ 2011-03-18 2:29 Ben Widawsky
2011-03-18 2:37 ` Ben Widawsky
2011-03-18 18:32 ` Eric Anholt
0 siblings, 2 replies; 3+ messages in thread
From: Ben Widawsky @ 2011-03-18 2:29 UTC (permalink / raw)
To: intel-gfx
From: Ben Widawsky <bwidawsk@gmail.com>
Have the assembler support creating a byte array for binary blob-like
inclusion. In my case, to write some exception handler which is not
jit'd.
I don't have push access, so if anyone thinks this is useful, please
push
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
---
src/main.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 47 insertions(+), 6 deletions(-)
diff --git a/src/main.c b/src/main.c
index def2655..785cce8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -40,10 +40,13 @@ extern int errors;
long int gen_level = 4;
int advanced_flag = 0; /* 0: in unit of type, 1: in unit of data element size */
+int binary_like_output = 0; /* 0: default type, 1: nice c like output */
int need_export = 0;
char *input_filename = "<stdin>";
char *export_filename = NULL;
+const char const *binary_prepend = "static const char gen4_bytes[] = {\n";
+
struct brw_program compiled_program;
struct program_defaults program_defaults;
@@ -53,6 +56,7 @@ static struct declared_register *declared_register_table[HASHSZ];
static const struct option longopts[] = {
{"advanced", no_argument, 0, 'a'},
+ {"binary", no_argument, 0, 'b'},
{"export", required_argument, 0, 'e'},
{"input_list", required_argument, 0, 'l'},
{"output", required_argument, 0, 'o'},
@@ -65,6 +69,7 @@ static void usage(void)
fprintf(stderr, "usage: intel-gen4asm [options] inputfile\n");
fprintf(stderr, "OPTIONS:\n");
fprintf(stderr, "\t-a, --advanced Set advanced flag\n");
+ fprintf(stderr, "\t-b, --binary C style binary output\n");
fprintf(stderr, "\t-e, --export {exportfile} Export label file\n");
fprintf(stderr, "\t-l, --input_list {entrytablefile} Input entry_table_list file\n");
fprintf(stderr, "\t-o, --output {outputfile} Specify output file\n");
@@ -168,6 +173,38 @@ static int is_entry_point(char *s)
return 0;
}
+static void
+print_instruction(FILE *output, struct brw_program_instruction *entry)
+{
+ if (binary_like_output) {
+ fprintf(output, "\t0x%02x, 0x%02x, 0x%02x, 0x%02x,"
+ "0x%02x, 0x%02x, 0x%02x, 0x%02x,"
+ "0x%02x, 0x%02x, 0x%02x, 0x%02x,"
+ "0x%02x, 0x%02x, 0x%02x, 0x%02x,\n",
+ ((unsigned char *)(&entry->instruction))[0],
+ ((unsigned char *)(&entry->instruction))[1],
+ ((unsigned char *)(&entry->instruction))[2],
+ ((unsigned char *)(&entry->instruction))[3],
+ ((unsigned char *)(&entry->instruction))[4],
+ ((unsigned char *)(&entry->instruction))[5],
+ ((unsigned char *)(&entry->instruction))[6],
+ ((unsigned char *)(&entry->instruction))[7],
+ ((unsigned char *)(&entry->instruction))[8],
+ ((unsigned char *)(&entry->instruction))[9],
+ ((unsigned char *)(&entry->instruction))[10],
+ ((unsigned char *)(&entry->instruction))[11],
+ ((unsigned char *)(&entry->instruction))[12],
+ ((unsigned char *)(&entry->instruction))[13],
+ ((unsigned char *)(&entry->instruction))[14],
+ ((unsigned char *)(&entry->instruction))[15]);
+ } else {
+ fprintf(output, " { 0x%08x, 0x%08x, 0x%08x, 0x%08x },\n",
+ ((int *)(&entry->instruction))[0],
+ ((int *)(&entry->instruction))[1],
+ ((int *)(&entry->instruction))[2],
+ ((int *)(&entry->instruction))[3]);
+ }
+}
int main(int argc, char **argv)
{
char *output_file = NULL;
@@ -177,7 +214,7 @@ int main(int argc, char **argv)
struct brw_program_instruction *entry, *entry1, *tmp_entry;
int err, inst_offset;
char o;
- while ((o = getopt_long(argc, argv, "e:l:o:g:a", longopts, NULL)) != -1) {
+ while ((o = getopt_long(argc, argv, "e:l:o:g:ab", longopts, NULL)) != -1) {
switch (o) {
case 'o':
if (strcmp(optarg, "-") != 0)
@@ -198,6 +235,9 @@ int main(int argc, char **argv)
case 'a':
advanced_flag = 1;
break;
+ case 'b':
+ binary_like_output = 1;
+ break;
case 'e':
need_export = 1;
@@ -317,20 +357,21 @@ int main(int argc, char **argv)
}
+ if (binary_like_output)
+ fprintf(output, "%s", binary_prepend);
+
for (entry = compiled_program.first;
entry != NULL;
entry = entry1) {
entry1 = entry->next;
if (!entry->islabel)
- fprintf(output, " { 0x%08x, 0x%08x, 0x%08x, 0x%08x },\n",
- ((int *)(&entry->instruction))[0],
- ((int *)(&entry->instruction))[1],
- ((int *)(&entry->instruction))[2],
- ((int *)(&entry->instruction))[3]);
+ print_instruction(output, entry);
else
free(entry->string);
free(entry);
}
+ if (binary_like_output)
+ fprintf(output, "};");
free_register_table();
fflush (output);
--
1.7.3.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] intel-gen4asm: have a C-like binary output
2011-03-18 2:29 [PATCH] intel-gen4asm: have a C-like binary output Ben Widawsky
@ 2011-03-18 2:37 ` Ben Widawsky
2011-03-18 18:32 ` Eric Anholt
1 sibling, 0 replies; 3+ messages in thread
From: Ben Widawsky @ 2011-03-18 2:37 UTC (permalink / raw)
To: intel-gfx
On Thu, Mar 17, 2011 at 07:29:03PM -0700, Ben Widawsky wrote:
> From: Ben Widawsky <bwidawsk@gmail.com>
>
> Have the assembler support creating a byte array for binary blob-like
> inclusion. In my case, to write some exception handler which is not
> jit'd.
I just noticed that the spacing is a little messed up in this one. If someone
wants to push this, but doesn't want to fix it, send me an email and I'll
resubmit.
Here's sample output. It should be shorter lines, with proper spacing...
static const char gen4_bytes[] = {
0x05, 0x02, 0x00, 0x00,0x00, 0x1c, 0x00, 0x30,0x00, 0x10, 0x00, 0x00,0xf9, 0xff, 0xff, 0xff,
0x08, 0x02, 0x00, 0x00,0x1d, 0x1d, 0x04, 0x20,0x00, 0x0e, 0x00, 0x00,0x06, 0x00, 0x00, 0x00,
0x40, 0x02, 0x00, 0x00,0xbd, 0x43, 0x04, 0x20,0x04, 0x00, 0x00, 0x00,0x00, 0x0e, 0x00, 0x00,
0x41, 0x02, 0x00, 0x00,0xbd, 0x1f, 0x04, 0x20,0x04, 0x00, 0x00, 0x00,0x00, 0x10, 0x00, 0x00,
0x01, 0x02, 0x60, 0x00,0xbe, 0x03, 0x00, 0x20,0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
0x01, 0x22, 0x80, 0x00,0xbe, 0x03, 0x00, 0x20,0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
0x40, 0x02, 0x00, 0x00,0xbe, 0x1f, 0x02, 0x20,0x04, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
0x31, 0x00, 0x60, 0x00,0x1e, 0x1c, 0x00, 0x20,0x00, 0x00, 0x00, 0x50,0x00, 0x00, 0x18, 0x10,
0x01, 0x00, 0x60, 0x00,0xbe, 0x03, 0xe0, 0x20,0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
0x40, 0x02, 0x00, 0x00,0xbe, 0x1f, 0xe2, 0x20,0x04, 0x00, 0x00, 0x00,0x00, 0x01, 0x00, 0x00,
0x31, 0x00, 0x60, 0x00,0x1e, 0x1c, 0xe0, 0x20,0x00, 0x00, 0x00, 0x50,0x00, 0x00, 0x18, 0x12,
};
Ben
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] intel-gen4asm: have a C-like binary output
2011-03-18 2:29 [PATCH] intel-gen4asm: have a C-like binary output Ben Widawsky
2011-03-18 2:37 ` Ben Widawsky
@ 2011-03-18 18:32 ` Eric Anholt
1 sibling, 0 replies; 3+ messages in thread
From: Eric Anholt @ 2011-03-18 18:32 UTC (permalink / raw)
To: Ben Widawsky, intel-gfx
[-- Attachment #1.1: Type: text/plain, Size: 428 bytes --]
On Thu, 17 Mar 2011 19:29:03 -0700, Ben Widawsky <ben@bwidawsk.net> wrote:
> From: Ben Widawsky <bwidawsk@gmail.com>
>
> Have the assembler support creating a byte array for binary blob-like
> inclusion. In my case, to write some exception handler which is not
> jit'd.
>
> I don't have push access, so if anyone thinks this is useful, please
> push
Seems useful to have around.
You should have access already.
[-- Attachment #1.2: Type: application/pgp-signature, Size: 197 bytes --]
[-- Attachment #2: Type: text/plain, Size: 159 bytes --]
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-03-18 18:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-18 2:29 [PATCH] intel-gen4asm: have a C-like binary output Ben Widawsky
2011-03-18 2:37 ` Ben Widawsky
2011-03-18 18:32 ` Eric Anholt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox