[Beignet] [PATCH V2 1/4] Add the string format support for gbe_bin_generater
junyan.he at inbox.com
junyan.he at inbox.com
Wed Oct 9 00:55:23 PDT 2013
From: Junyan He <junyan.he at linux.intel.com>
The string format of kernel serializaion will be useful for
generating the code for internal kernel binary load in.
Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
backend/src/gbe_bin_generater.cpp | 47 ++++++++++++++++++++++++++++++++++---
1 file changed, 44 insertions(+), 3 deletions(-)
diff --git a/backend/src/gbe_bin_generater.cpp b/backend/src/gbe_bin_generater.cpp
index afe86f2..37e61e2 100644
--- a/backend/src/gbe_bin_generater.cpp
+++ b/backend/src/gbe_bin_generater.cpp
@@ -33,6 +33,9 @@
#include <deque>
#include <vector>
#include <algorithm>
+#include <stdlib.h>
+#include <stdio.h>
+
#include "backend/program.h"
#include "backend/program.hpp"
@@ -49,6 +52,7 @@ protected:
string prog_path;
string build_opt;
static string bin_path;
+ static bool str_fmt_out;
int fd;
int file_len;
const char* code;
@@ -100,7 +104,6 @@ public:
return *this;
}
-
const char* file_map_open (void) throw (int);
const char* get_code (void) {
@@ -125,6 +128,10 @@ public:
print_file();
}
+ static void set_str_fmt_out (bool flag) {
+ str_fmt_out = flag;
+ }
+
static int set_bin_path (const char* path) {
if (bin_path.size())
return 0;
@@ -138,14 +145,43 @@ public:
};
string program_build_instance::bin_path;
+bool program_build_instance::str_fmt_out = false;
void program_build_instance::serialize_program(void) throw(int)
{
ofstream ofs;
ostringstream oss;
+ size_t sz;
ofs.open(bin_path, ofstream::out | ofstream::app | ofstream::binary);
- size_t sz = gbe_prog->serializeToBin(ofs);
+ if (str_fmt_out) {
+ string array_name = "Unkown_name_array";
+ unsigned long last_slash = bin_path.rfind("/");
+ unsigned long last_dot = bin_path.rfind(".");
+
+ if (last_slash != string::npos && last_dot != string::npos)
+ array_name = bin_path.substr(last_slash + 1, last_dot - 1 - last_slash);
+
+ ofs << "char " << array_name << "[] = {" << "\n";
+
+ sz = gbe_prog->serializeToBin(oss);
+
+ for (size_t i = 0; i < sz; i++) {
+ unsigned char c = oss.str().c_str()[i];
+ char asic_str[9];
+ sprintf(asic_str, "%2.2x", c);
+ ofs << "0x";
+ ofs << asic_str << ((i == sz - 1) ? "" : ", ");
+ }
+
+ ofs << "};\n";
+
+ string array_size = array_name + "_size";
+ ofs << "int " << array_size << " = " << sz << ";" << "\n";
+ } else {
+ sz = gbe_prog->serializeToBin(ofs);
+ }
+
ofs.close();
if (!sz) {
@@ -211,7 +247,7 @@ int main (int argc, const char **argv)
argv_saved.push_back(string(argv[i]));
}
- while ( (oc = getopt(argc, (char * const *)argv, "o:p:")) != -1 ) {
+ while ( (oc = getopt(argc, (char * const *)argv, "o:p:s")) != -1 ) {
switch (oc) {
case 'p':
{
@@ -245,6 +281,11 @@ int main (int argc, const char **argv)
used_index[optind-1] = 1;
break;
+ case 's':
+ program_build_instance::set_str_fmt_out(true);
+ used_index[optind-1] = 1;
+ break;
+
case ':':
cout << "Miss the file option argument" << endl;
return 1;
--
1.7.9.5
More information about the Beignet
mailing list