summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-09-20 23:23:50 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2022-09-23 06:44:28 +0900
commit4c6e1556b109367f598e276f72feacefc72805fc (patch)
tree4e8411d731b3447998f9d0ae924ddc2775583399 /lib
parent280ff1707e1e0e5f06d9819dc5f8d8deb38b3f6c (diff)
Bindgen immediate types with builtin
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6418
Diffstat (limited to 'lib')
-rw-r--r--lib/mjit/c_type.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/mjit/c_type.rb b/lib/mjit/c_type.rb
index be93b36e90..8ccdfcc4d3 100644
--- a/lib/mjit/c_type.rb
+++ b/lib/mjit/c_type.rb
@@ -27,7 +27,7 @@ module RubyVM::MJIT
end
module Immediate
- # @param fiddle_type [Integer] Fiddle::TYPE_*
+ # @param fiddle_type [Integer]
def self.new(fiddle_type)
name = Fiddle.constants.find do |const|
const.start_with?('TYPE_') && Fiddle.const_get(const) == fiddle_type.abs
@@ -40,6 +40,20 @@ module RubyVM::MJIT
CPointer::Immediate.define(fiddle_type)
end
end
+
+ # @param type [String]
+ def self.parse(ctype)
+ new(Fiddle::Importer.parse_ctype(ctype))
+ end
+
+ def self.find(size, unsigned)
+ fiddle_type = TYPE_MAP.fetch(size)
+ fiddle_type = -fiddle_type if unsigned
+ new(fiddle_type)
+ end
+
+ TYPE_MAP = Fiddle::PackInfo::SIZE_MAP.map { |type, size| [size, type.abs] }.to_h
+ private_constant :TYPE_MAP
end
module Bool