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.
4169 4170 4171 4172 4173 4174 4175 4176 |
# File 'lib/idl/ast.rb', line 4169 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
4167 |
# File 'lib/idl/ast.rb', line 4167 def bits_expression = @children[0] |
#freeze_tree(symtab) ⇒ Object
4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 |
# File 'lib/idl/ast.rb', line 4196 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)
4245 4246 4247 4248 4249 4250 4251 |
# File 'lib/idl/ast.rb', line 4245 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
4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 |
# File 'lib/idl/ast.rb', line 4214 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
4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 |
# File 'lib/idl/ast.rb', line 4179 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.archdef.fully_configured? end end unless ["Bits", "String", "XReg", "Boolean", "U32", "U64"].include?(@type_name) type_error "Unimplemented builtin type #{text_value}" end end |