Class: Idl::BuiltinTypeNameAst
Overview
represents a type name of one of the builtin types:
* Bits<N>
* Boolean
* String
And their aliases:
* XReg (Bits<XLEN>)
* U32 (Bits<32>)
* U64 (Bits<64>)
Instance Method Summary collapse
- #bits_expression ⇒ Object
- #freeze_tree(symtab) ⇒ Object
-
#initialize(input, interval, type_name, bits_expression) ⇒ BuiltinTypeNameAst
constructor
A new instance of BuiltinTypeNameAst.
-
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree).
-
#type(symtab) ⇒ Type
Given a specific symbol table, return the type of this node.
-
#type_check(symtab) ⇒ void
type check this node and all children.
Constructor Details
#initialize(input, interval, type_name, bits_expression) ⇒ BuiltinTypeNameAst
Returns a new instance of BuiltinTypeNameAst.
4192 4193 4194 4195 4196 4197 4198 4199 |
# File 'lib/idl/ast.rb', line 4192 def initialize(input, interval, type_name, bits_expression) if bits_expression.nil? super(input, interval, EMPTY_ARRAY) else super(input, interval, [bits_expression]) end @type_name = type_name end |
Instance Method Details
#bits_expression ⇒ Object
4190 |
# File 'lib/idl/ast.rb', line 4190 def bits_expression = @children[0] |
#freeze_tree(symtab) ⇒ Object
4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 |
# File 'lib/idl/ast.rb', line 4219 def freeze_tree(symtab) return if frozen? if @type_name == "Bits" # precalculate size if possible begin value_try do @bits_type = Type.new(:bits, width: bits_expression.value(symtab)) end rescue TypeError # ok, probably in a function template end bits_expression.freeze_tree(symtab) end freeze end |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
4268 4269 4270 4271 4272 4273 4274 |
# File 'lib/idl/ast.rb', line 4268 def to_idl if @type_name == "Bits" "Bits<#{bits_expression.to_idl}>" else @type_name end end |
#type(symtab) ⇒ Type
Given a specific symbol table, return the type of this node.
Should not be called until #type_check is called with the same arguments
4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 |
# File 'lib/idl/ast.rb', line 4237 def type(symtab) case @type_name when "XReg" if symtab.mxlen == 32 Bits32Type else Bits64Type end when "Boolean" BoolType when "U32" Bits32Type when "U64" Bits64Type when "String" StringType when "Bits" return @bits_type unless @bits_type.nil? value_result = value_try do return Type.new(:bits, width: bits_expression.value(symtab)) end value_else(value_result) do return Type.new(:bits, width: :unknown) end else internal_error "TODO: #{text_value}" end end |
#type_check(symtab) ⇒ void
This method returns an undefined value.
type check this node and all children
Calls to #type and/or #value may depend on type_check being called first with the same symtab. If not, those functions may raise an AstNode::InternalError
4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 |
# File 'lib/idl/ast.rb', line 4202 def type_check(symtab) if @type_name == "Bits" bits_expression.type_check(symtab) value_result = value_try do unless bits_expression.value(symtab).positive? type_error "Bits width (#{bits_expression.value(symtab)}) must be positive" end end value_else(value_result) do type_error "Bit width must be known at compile time" if symtab.cfg_arch.fully_configured? end end unless ["Bits", "String", "XReg", "Boolean", "U32", "U64"].include?(@type_name) type_error "Unimplemented builtin type #{text_value}" end end |