Class: Idl::SignCastAst
- Includes:
- Rvalue
- Defined in:
- lib/idlc/ast.rb,
lib/idlc/passes/gen_adoc.rb
Constant Summary
Constants inherited from AstNode
AstNode::Bits1Type, AstNode::Bits32Type, AstNode::Bits64Type, AstNode::BoolType, AstNode::ConstBoolType, AstNode::PossiblyUnknownBits1Type, AstNode::PossiblyUnknownBits32Type, AstNode::PossiblyUnknownBits64Type, AstNode::ReachableFunctionCacheType, AstNode::StringType, AstNode::VoidType
Instance Attribute Summary
Attributes inherited from AstNode
#children, #input, #interval, #parent
Class Method Summary collapse
Instance Method Summary collapse
- #const_eval?(symtab) ⇒ Boolean
- #expression ⇒ Object
- #gen_adoc(indent = 0, indent_spaces: 2) ⇒ Object
-
#initialize(input, interval, exp) ⇒ SignCastAst
constructor
A new instance of SignCastAst.
- #to_h ⇒ Object
- #to_idl ⇒ Object
-
#type(symtab) ⇒ Type
Given a specific symbol table, return the type of this node.
-
#type_check(symtab, strict:) ⇒ void
type check this node and all children.
-
#value(symtab) ⇒ Object
Return the compile-time-known value of the node.
Methods included from Rvalue
#max_value, #min_value, #truncate, #values
Methods inherited from AstNode
#always_terminates?, #declaration?, #executable?, extract_base_var_name, #find_ancestor, #find_dst_registers, #find_referenced_csrs, #find_src_registers, #freeze_tree, #gen_option_adoc, #input_file, input_from_source_yaml, #inspect, #internal_error, interval_from_source_yaml, #lineno, #lines_around, #nullify_assignments, #pass_find_return_values, #path, #print_ast, #prune, #reachable_exceptions, #reachable_functions, #set_input_file, #set_input_file_unless_already_set, #source_line_file_offsets, #source_starting_offset, #source_yaml, #starting_line, #text_value, #truncation_warn, #type_error, #unindent, value_else, #value_else, value_error, #value_error, value_try, #value_try, write_back_nested
Constructor Details
#initialize(input, interval, exp) ⇒ SignCastAst
Returns a new instance of SignCastAst.
4358 |
# File 'lib/idlc/ast.rb', line 4358 def initialize(input, interval, exp) = super(input, interval, [exp]) |
Class Method Details
.from_h(yaml, source_mapper) ⇒ Object
4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 |
# File 'lib/idlc/ast.rb', line 4395 def self.from_h(yaml, source_mapper) raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "sign_cast" input = input_from_source_yaml(yaml.fetch("source"), source_mapper) interval = interval_from_source_yaml(yaml.fetch("source")) SignCastAst.new( input, interval, T.cast(AstNode.from_h(yaml.fetch("expr"), source_mapper), RvalueAst) ) end |
Instance Method Details
#const_eval?(symtab) ⇒ Boolean
4354 |
# File 'lib/idlc/ast.rb', line 4354 def const_eval?(symtab) = true |
#expression ⇒ Object
4356 |
# File 'lib/idlc/ast.rb', line 4356 def expression = @children[0] |
#gen_adoc(indent = 0, indent_spaces: 2) ⇒ Object
168 169 170 |
# File 'lib/idlc/passes/gen_adoc.rb', line 168 def gen_adoc(indent = 0, indent_spaces: 2) "#{' ' * indent}$signed+++(+++#{expression.gen_adoc(0, indent_spaces:)})" end |
#to_h ⇒ Object
4388 4389 4390 4391 4392 |
# File 'lib/idlc/ast.rb', line 4388 def to_h = { "kind" => "sign_cast", "expr" => expression.to_h, "source" => source_yaml } |
#to_idl ⇒ Object
4385 |
# File 'lib/idlc/ast.rb', line 4385 def to_idl = "$signed(#{expression.to_idl})" |
#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
4367 |
# File 'lib/idlc/ast.rb', line 4367 def type(symtab) = expression.type(symtab).clone.make_signed |
#type_check(symtab, strict:) ⇒ void
4361 4362 4363 4364 |
# File 'lib/idlc/ast.rb', line 4361 def type_check(symtab, strict:) expression.type_check(symtab, strict:) type_error "$signed cast only works on Bits types" unless expression.type(symtab).kind == :bits end |
#value(symtab) ⇒ Object
Return the compile-time-known value of the node
4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 |
# File 'lib/idlc/ast.rb', line 4370 def value(symtab) t = expression.type(symtab) internal_error "Expecting a bits type" unless t.kind == :bits v = expression.value(symtab) if ((v >> (t.width - 1)) & 1) == 1 # twos compliment negate the value -(2**t.width - v) else v end end |