Commit c89ea725 authored by Brice Videau's avatar Brice Videau
Browse files

Generate dispatcher and callbacks from babeltrace model.

parent b1f78dc2
Pipeline #12883 canceled with stage
...@@ -151,10 +151,10 @@ tmplib_LTLIBRARIES = libBabeltraceCL.la libDust.la libTestingCLProf.la ...@@ -151,10 +151,10 @@ tmplib_LTLIBRARIES = libBabeltraceCL.la libDust.la libTestingCLProf.la
install-data-hook:: install-data-hook::
$(RM) -r $(DESTDIR)$(tmplibdir) $(RM) -r $(DESTDIR)$(tmplibdir)
babeltrace_cl_callbacks.h: $(srcdir)/gen_babeltrace_cl_callbacks.rb opencl_model.yaml babeltrace_cl_callbacks.h: $(srcdir)/gen_babeltrace_cl_callbacks.rb opencl_babeltrace_model.yaml
SRC_DIR=$(srcdir) $(RUBY) $(srcdir)/gen_babeltrace_cl_callbacks.rb > babeltrace_cl_callbacks.h SRC_DIR=$(srcdir) $(RUBY) $(srcdir)/gen_babeltrace_cl_callbacks.rb > babeltrace_cl_callbacks.h
babeltrace_cl_dispatchers.c: $(srcdir)/gen_babeltrace_cl_dispatchers.rb opencl_model.yaml opencl_babeltrace_model.yaml babeltrace_cl_dispatchers.c: $(srcdir)/gen_babeltrace_cl_dispatchers.rb opencl_babeltrace_model.yaml
SRC_DIR=$(srcdir) $(RUBY) $(srcdir)/gen_babeltrace_cl_dispatchers.rb > babeltrace_cl_dispatchers.c SRC_DIR=$(srcdir) $(RUBY) $(srcdir)/gen_babeltrace_cl_dispatchers.rb > babeltrace_cl_dispatchers.c
nodist_libBabeltraceCL_la_SOURCES = \ nodist_libBabeltraceCL_la_SOURCES = \
......
require 'yaml' require 'yaml'
opencl_model = YAML::load_file("opencl_model.yaml") opencl_babeltrace_model = YAML::load_file("opencl_babeltrace_model.yaml")
puts <<EOF puts <<EOF
#ifndef _HEADER_CALLBACKS_H #ifndef _HEADER_CALLBACKS_H
...@@ -21,21 +21,18 @@ puts <<EOF ...@@ -21,21 +21,18 @@ puts <<EOF
EOF EOF
opencl_model["events"].each { |name, fields| opencl_babeltrace_model[:event_classes].each { |klass|
name = klass[:name]
fields = klass[:payload]
decls = []
fields.each { |f|
decls.push ['size_t', "_#{f[:name]}_length"] if f[:class] == 'array_static'
decls.push [f[:cast_type], f[:name]]
}
puts <<EOF puts <<EOF
typedef void (#{name.gsub(":","_")}_cb)( typedef void (#{name.gsub(":","_")}_cb)(
#{(["const bt_event *bt_evt", "const bt_clock_snapshot *bt_clock"]+fields.each.collect { |n, f| #{(["const bt_event *bt_evt", "const bt_clock_snapshot *bt_clock"]+
s = "#{f["type"].gsub("cl_errcode", "cl_int")}" decls.collect { |t, n| "#{t} #{n}" }).join(",\n ")});
s << " *" if f["pointer"]
s << " *" if f["array"]
s << " *" if f["string"]
s << " #{n}"
if f["array"]
["size_t _#{n}_length", s]
else
s
end
}).flatten.join(",\n ")});
EOF EOF
} }
......
require 'yaml' require 'yaml'
opencl_model = YAML::load_file("opencl_model.yaml") opencl_babeltrace_model = YAML::load_file("opencl_babeltrace_model.yaml")
puts <<EOF puts <<EOF
#include "babeltrace_cl.h" #include "babeltrace_cl.h"
...@@ -7,54 +7,75 @@ puts <<EOF ...@@ -7,54 +7,75 @@ puts <<EOF
EOF EOF
def print_field_member_access(lttng, type, name, i) def print_field_member_access(f, i)
klass = f[:class]
name = f[:name]
type = f[:cast_type]
puts <<EOF puts <<EOF
{ {
const bt_field *_field = NULL; const bt_field *_field = NULL;
_field = bt_field_structure_borrow_member_field_by_index_const(payload_field, #{i}); _field = bt_field_structure_borrow_member_field_by_index_const(payload_field, #{i});
EOF EOF
case lttng case klass
when "ctf_integer", "ctf_integer_hex", "ctf_enum" when 'signed', 'enumeration_signed'
puts <<EOF puts <<EOF
bt_field_class_type _type = bt_field_get_class_type(_field);
if (bt_field_class_type_is(_type, BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER))
#{name} = (#{type})bt_field_integer_unsigned_get_value(_field);
else
#{name} = (#{type})bt_field_integer_signed_get_value(_field); #{name} = (#{type})bt_field_integer_signed_get_value(_field);
EOF EOF
when "ctf_array" when 'unsigned', 'enumeration_unsigned'
puts <<EOF
#{name} = (#{type})bt_field_integer_unsigned_get_value(_field);
EOF
when 'array_static'
scalar_type = type.gsub("const","").sub("*", "") scalar_type = type.gsub("const","").sub("*", "")
puts <<EOF puts <<EOF
_#{name}_length = bt_field_array_get_length(_field); _#{name}_length = bt_field_array_get_length(_field);
if (_#{name}_length > 0) { if (_#{name}_length > 0) {
bt_field_class_type _type = bt_field_get_class_type(bt_field_array_borrow_element_field_by_index_const(_field, 0));
#{name} = (#{type})malloc(_#{name}_length*sizeof(#{scalar_type})); #{name} = (#{type})malloc(_#{name}_length*sizeof(#{scalar_type}));
for (uint64_t _i = 0; _i < _#{name}_length; _i++) { for (uint64_t _i = 0; _i < _#{name}_length; _i++) {
if (bt_field_class_type_is(_type, BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER)) EOF
case f[:field][:class]
when 'unsigned'
puts <<EOF
#{name}[_i] = (#{scalar_type})bt_field_integer_unsigned_get_value(bt_field_array_borrow_element_field_by_index_const(_field, _i)); #{name}[_i] = (#{scalar_type})bt_field_integer_unsigned_get_value(bt_field_array_borrow_element_field_by_index_const(_field, _i));
else EOF
when 'signed'
puts <<EOF
#{name}[_i] = (#{scalar_type})bt_field_integer_signed_get_value(bt_field_array_borrow_element_field_by_index_const(_field, _i)); #{name}[_i] = (#{scalar_type})bt_field_integer_signed_get_value(bt_field_array_borrow_element_field_by_index_const(_field, _i));
EOF
else
raise "unsupported array element #{f[:field][:class]}"
end
puts <<EOF
} }
} else } else
#{name} = NULL; #{name} = NULL;
EOF EOF
when "ctf_sequence", "ctf_sequence_hex" when 'array_dynamic'
scalar_type = type.gsub("const","").sub("*", "") scalar_type = type.gsub("const","").sub("*", "")
puts <<EOF puts <<EOF
uint64_t _sz = bt_field_array_get_length(_field); uint64_t _sz = bt_field_array_get_length(_field);
if (_sz > 0) { if (_sz > 0) {
bt_field_class_type _type = bt_field_get_class_type(bt_field_array_borrow_element_field_by_index_const(_field, 0));
#{name} = (#{type})malloc(_sz*sizeof(#{scalar_type})); #{name} = (#{type})malloc(_sz*sizeof(#{scalar_type}));
for (uint64_t _i = 0; _i < _sz; _i++) { for (uint64_t _i = 0; _i < _sz; _i++) {
if (bt_field_class_type_is(_type, BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER)) EOF
case f[:field][:class]
when 'unsigned'
puts <<EOF
#{name}[_i] = (#{scalar_type})bt_field_integer_unsigned_get_value(bt_field_array_borrow_element_field_by_index_const(_field, _i)); #{name}[_i] = (#{scalar_type})bt_field_integer_unsigned_get_value(bt_field_array_borrow_element_field_by_index_const(_field, _i));
else EOF
when 'signed'
puts <<EOF
#{name}[_i] = (#{scalar_type})bt_field_integer_signed_get_value(bt_field_array_borrow_element_field_by_index_const(_field, _i)); #{name}[_i] = (#{scalar_type})bt_field_integer_signed_get_value(bt_field_array_borrow_element_field_by_index_const(_field, _i));
EOF
else
raise "unsupported array element #{f[:field][:class]}"
end
puts <<EOF
} }
} else } else
#{name} = NULL; #{name} = NULL;
EOF EOF
when "ctf_sequence_text", "ctf_string" when 'string'
puts <<EOF puts <<EOF
#{name} = (#{type})bt_field_string_get_value(_field); #{name} = (#{type})bt_field_string_get_value(_field);
EOF EOF
...@@ -65,28 +86,22 @@ EOF ...@@ -65,28 +86,22 @@ EOF
end end
def print_field_members_access(fields) def print_field_members_access(fields)
arr = [] puts <<EOF unless fields.empty?
fields.each.collect { |n, f|
lttng = f["lttng"]
type = "#{f["type"].gsub("cl_errcode", "cl_int")}"
type << " *" if f["pointer"]
type << " *" if f["array"]
type << " *" if f["string"]
name = n
if f["array"] and f["lttng"].match("ctf_sequence")
arr.push ["ctf_integer", "size_t", "_#{n}_length"]
end
arr.push [lttng, type, name]
}
puts <<EOF unless arr.empty?
const bt_field *payload_field = bt_event_borrow_payload_field_const(bt_evt); const bt_field *payload_field = bt_event_borrow_payload_field_const(bt_evt);
EOF EOF
arr.each_with_index { |(lttng, type, name), i| fields.each_with_index { |f, i|
print_field_member_access(lttng, type, name, i) print_field_member_access(f, i)
} }
end end
opencl_model["events"].each { |name, fields| opencl_babeltrace_model[:event_classes].each { |klass|
name = klass[:name]
fields = klass[:payload]
decls = []
fields.each { |f|
decls.push ['size_t', "_#{f[:name]}_length"] if f[:class] == 'array_static'
decls.push [f[:cast_type], f[:name]]
}
puts <<EOF puts <<EOF
static void static void
#{name.gsub(":","_")}_dispatcher( #{name.gsub(":","_")}_dispatcher(
...@@ -94,36 +109,18 @@ static void ...@@ -94,36 +109,18 @@ static void
struct opencl_callbacks *callbacks, struct opencl_callbacks *callbacks,
const bt_event *bt_evt, const bt_event *bt_evt,
const bt_clock_snapshot *bt_clock) { const bt_clock_snapshot *bt_clock) {
#{fields.each.collect { |n, f| #{decls.each.collect { |f| "#{f[0]} #{f[1]}" }.join(";\n ")};
s = "#{f["type"].gsub("cl_errcode", "cl_int")}"
s << " *" if f["pointer"]
s << " *" if f["array"]
s << " *" if f["string"]
s << " #{n}"
if f["array"]
["size_t _#{n}_length", s]
else
s
end
}.flatten.join(";\n ")};
EOF EOF
print_field_members_access(fields) print_field_members_access(fields)
puts <<EOF puts <<EOF
void **p = NULL; void **p = NULL;
while( (p = utarray_next(callbacks->callbacks, p)) ) { while( (p = utarray_next(callbacks->callbacks, p)) ) {
((#{name.gsub(":","_")}_cb *)*p)( ((#{name.gsub(":","_")}_cb *)*p)(
#{(["bt_evt", "bt_clock"] + fields.each.collect { |n, f| #{(["bt_evt", "bt_clock"] + decls.collect { |f| f[1] }).join(",\n ")});
s = "#{n}"
if f["array"]
["_#{n}_length", s]
else
s
end
}).flatten.join(",\n ")});
} }
#{fields.each.collect { |n, f| #{fields.each.collect { |f|
if f["array"] && f["lttng"] != "ctf_sequence_text" if f[:class].match('array')
"if (#{n}) free((void *)#{n})" "if (#{f[:name]}) free((void *)#{f[:name]})"
else else
nil nil
end end
...@@ -136,7 +133,8 @@ EOF ...@@ -136,7 +133,8 @@ EOF
puts <<EOF puts <<EOF
void init_dispatchers(struct opencl_dispatch *opencl_dispatch) { void init_dispatchers(struct opencl_dispatch *opencl_dispatch) {
EOF EOF
opencl_model["events"].each_key { |name| opencl_babeltrace_model[:event_classes].each { |klass|
name = klass[:name]
puts <<EOF puts <<EOF
opencl_register_dispatcher(opencl_dispatch, "#{name}", &#{name.gsub(":","_")}_dispatcher); opencl_register_dispatcher(opencl_dispatch, "#{name}", &#{name.gsub(":","_")}_dispatcher);
EOF EOF
......
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