Skip to content

Commit 4f27109

Browse files
author
Derek Hower
committed
Add constexpr IDL pass
1 parent e3a6986 commit 4f27109

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# frozen_string_literal: true
2+
3+
module Idl
4+
class AstNode
5+
def constexpr?(symtab)
6+
if children.empty?
7+
true
8+
else
9+
children.all? { |child| child.constexpr?(symtab) }
10+
end
11+
end
12+
end
13+
class IdAst
14+
def constexpr?(symtab)
15+
sym = symtab.get(name)
16+
return true if sym.nil? # assuming undefined syms are local (be sure to type check first!!)
17+
return true if sym.is_a?(Type)
18+
19+
!sym.type.global?
20+
end
21+
end
22+
class PcAssignmentAst
23+
def constexpr?(symtab) = false
24+
end
25+
class FunctionCallExpressionAst
26+
def constexpr?(symtab) = false # conservative, can do better...
27+
end
28+
class CsrFieldReadExpressionAst
29+
def constexpr?(symtab) = false
30+
end
31+
class CsrReadExpressionAst
32+
def constexpr?(symtab) = false
33+
end
34+
class CsrSoftwareWriteAst
35+
def constexpr?(symtab) = false
36+
end
37+
class CsrFunctionCallAst
38+
def constexpr?(symtab) = function_name == "address"
39+
end
40+
class CsrWriteAst
41+
def constexpr?(symtab) = false
42+
end
43+
class FunctionDefAst
44+
# @return [Boolean] If the function is possibly C++ constexpr (does not access CSRs or registers)
45+
def constexpr?(symtab)
46+
return false if builtin?
47+
48+
body.constexpr?(symtab)
49+
end
50+
end
51+
end

0 commit comments

Comments
 (0)