• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14require 'delegate'
15
16class Intrinsic < SimpleDelegator
17
18  TYPES = {
19    "u1"  => "BOOL",
20    "i8" => "INT8",
21    "u8" => "UINT8",
22    "i16" => "INT16",
23    "u16" => "UINT16",
24    "i32" => "INT32",
25    "u32" => "UINT32",
26    "i64" => "INT64",
27    "u64" => "UINT64",
28    "f32"  => "FLOAT32",
29    "f64"  => "FLOAT64",
30    "void" => "VOID"
31  }
32
33  def enum_name
34    res = name.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
35    res.gsub(/([a-z\d])([A-Z])/,'\1_\2').upcase
36  end
37
38  def entrypoint_name
39    'INTRINSIC_' + enum_name
40  end
41
42  def return_type
43    TYPES[signature.ret] || "REFERENCE"
44  end
45
46  def arguments
47    (signature.args.length() < impl_signature.args.length() ? ["REFERENCE"] : []) +
48        signature.args.map {|arg| TYPES[arg] || "REFERENCE" }
49  end
50
51  def has_impl?
52    respond_to?(:impl)
53  end
54
55  def is_irtoc?
56    class_name == 'Irtoc'
57  end
58
59  def is_dynamic?
60    signature.ret == "any" || signature.args.include?("any")
61  end
62end
63
64module Compiler
65  module_function
66
67  def intrinsics
68    @exclude_list = [
69    ]
70
71    @data.intrinsics.select { |i| !@exclude_list.include?(i.name) }.map do |intrinsic|
72      Intrinsic.new(intrinsic)
73    end
74  end
75
76  def wrap_data(data)
77    @data = data
78    @ext_intrinsic_spaces = Compiler::intrinsics.collect {|intrinsic| intrinsic.space}.select {|space| space != 'core'}.uniq
79  end
80
81  def ext_intrinsic_spaces
82    @ext_intrinsic_spaces
83  end
84end
85
86def Gen.on_require(data)
87  Compiler.wrap_data(data)
88end
89