Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Commit 6042f565 authored by Ary Borenszweig's avatar Ary Borenszweig
Browse files

Inline globals that have a constant value but are computed from other globals

parent 2b54e293
Branches
Tags
No related merge requests found
......@@ -874,19 +874,23 @@ module Crystal
def visit(node : Path)
if const = node.target_const
global_name = const.llvm_name
if initializer = const.initializer
@last = initializer
else
global_name = const.llvm_name
global = @main_mod.globals[global_name]?
unless global
node.raise "Bug: global not found for #{const}"
end
global = @main_mod.globals[global_name]?
unless global
node.raise "Bug: global not found for #{const}"
end
if @llvm_mod != @main_mod
global = @llvm_mod.globals[global_name]?
global ||= @llvm_mod.globals.add(llvm_type(const.value.type), global_name)
end
if @llvm_mod != @main_mod
global = @llvm_mod.globals[global_name]?
global ||= @llvm_mod.globals.add(llvm_type(const.value.type), global_name)
end
@last = to_lhs global, const.value.type
@last = to_lhs global, const.value.type
end
elsif replacement = node.syntax_replacement
accept replacement
else
......@@ -922,6 +926,7 @@ module Crystal
if @last.constant?
global.initializer = @last
global.global_constant = true
const.initializer = @last if const.value.type.is_a?(PrimitiveType)
else
if const.value.type.passed_by_value?
global.initializer = llvm_type(const.value.type).undef
......
......@@ -43,4 +43,8 @@ module Crystal
typedef.llvm_name(io)
end
end
class Const
property initializer
end
end
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment