Sha256: 3e89ea9e4313f89e3eb63d9a2c48de705b5deffffe8919b07114a4ab87b3b7a1
Contents?: true
Size: 1.54 KB
Versions: 2
Compression:
Stored size: 1.54 KB
Contents
# encoding: utf-8 # frozen_string_literal: true module Carbon module Core module Main class << self def define_main_function(mod, index, pass) main_params = [LLVM::Int32.type, LLVM::Int8.type.pointer.pointer] main = mod.functions.add("main", main_params, LLVM::Int32.type) define_main_definition(mod, main, index, pass) end private def define_main_definition(mod, func, index, pass) if pass.function.parameters.size == 2 define_main_definition_params(mod, func, index, pass) else define_main_definition_noparams(mod, func, index, pass) end end def define_main_definition_params(mod, func, index, pass) argc, argv = func.params argc.name, argv.name = "argc", "argv" func.basic_blocks.append("entry").build do |b| if index.fetch(pass).first.return != Carbon::Void b.ret(b.call(mod.functions[pass.to_s], argc, argv)) else b.call(mod.function[pass.to_s], argc, argv) b.ret(LLVM::Int(0)) end end end def define_main_definition_noparams(mod, func, index, pass) func.basic_blocks.append("entry").build do |b| if index.fetch(pass).first.return != Carbon::Void b.ret(b.call(mod.functions[pass.to_s])) else b.call(mod.function[pass.to_s]) b.ret(LLVM::Int(0)) end end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
carbon-core-0.2.1 | lib/carbon/core/main.rb |
carbon-core-0.2.0 | lib/carbon/core/main.rb |