Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 49ece6a12a37
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0e7294db8d10
Choose a head ref
  • 4 commits
  • 2 files changed
  • 1 contributor

Commits on Jul 21, 2015

  1. Mark string constants as unnamed_addr.

    As a result they will be merged when possible.
    whitequark committed Jul 21, 2015
    Copy the full SHA
    7301a76 View commit details
  2. Copy the full SHA
    8c9d9cb View commit details
  3. Copy the full SHA
    9d20080 View commit details
  4. Null-terminate all string literals.

    whitequark committed Jul 21, 2015
    Copy the full SHA
    0e7294d View commit details
Showing with 14 additions and 3 deletions.
  1. +10 −2 artiq/compiler/testbench/llvmgen.py
  2. +4 −1 artiq/compiler/transforms/llvm_ir_generator.py
12 changes: 10 additions & 2 deletions artiq/compiler/testbench/llvmgen.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys, fileinput
from pythonparser import diagnostic
from llvmlite import ir as ll
from .. import Module

def main():
@@ -11,8 +12,15 @@ def process_diagnostic(diag):
engine = diagnostic.Engine()
engine.process = process_diagnostic

mod = Module.from_string("".join(fileinput.input()).expandtabs(), engine=engine)
print(mod.llvm_ir)
llmod = Module.from_string("".join(fileinput.input()).expandtabs(), engine=engine).llvm_ir

# Add main so that the result can be executed with lli
llmain = ll.Function(llmod, ll.FunctionType(ll.VoidType(), []), "main")
llbuilder = ll.IRBuilder(llmain.append_basic_block("entry"))
llbuilder.call(llmod.get_global(llmod.name + ".__modinit__"), [])
llbuilder.ret_void()

print(llmod)

if __name__ == "__main__":
main()
5 changes: 4 additions & 1 deletion artiq/compiler/transforms/llvm_ir_generator.py
Original file line number Diff line number Diff line change
@@ -78,11 +78,13 @@ def llconst_of_const(self, const):
elif isinstance(const.value, (int, float)):
return ll.Constant(llty, const.value)
elif isinstance(const.value, str):
as_bytes = const.value.encode('utf-8')
as_bytes = (const.value + '\0').encode('utf-8')
llstrty = ll.ArrayType(ll.IntType(8), len(as_bytes))
llconst = ll.GlobalVariable(self.llmodule, llstrty,
name=self.llmodule.get_unique_name("str"))
llconst.global_constant = True
llconst.unnamed_addr = True
llconst.linkage = 'internal'
llconst.initializer = ll.Constant(llstrty, bytearray(as_bytes))
return llconst.bitcast(ll.IntType(8).as_pointer())
else:
@@ -117,6 +119,7 @@ def process_function(self, func):
llfunty = ll.FunctionType(args=llargtys,
return_type=self.llty_of_type(func.type.ret, for_return=True))
self.llfunction = ll.Function(self.llmodule, llfunty, func.name)
self.llfunction.linkage = 'internal'

self.llmap = {}
self.llbuilder = ll.IRBuilder()