Due: before class on Wednesday 03 September
Looking back
Remember, try hard to solve these on your own first, without looking things up. Then check and correct your work after the fact, to know where you need to focus your studying later.
-
Which of the following aspects of LLVM IR are due to the fact that it is a 3AC language? Circle all that apply.
- All memory allocations must be aligned
- You can’t add up three values in a single instruction
- Each register can only be assigned once
- Literal strings must be declared outside of functions
- Most instructions have two source and one destination register
-
Consider the following program in LLVM IR:
target triple = "x86_64-pc-linux-gnu" declare i32 @printf(ptr, ...) declare i32 @scanf(ptr, ...) @prompt = constant [17 x i8] c"Enter a number: " @scan_fmt = constant [4 x i8] c" %d\00" @print_fmt = constant [4 x i8] c"%d\0A\00" define i32 @foo(i32 %a) { %sqr = mul i32 %a, %a ret i32 %sqr } define dso_local i32 @main() { %xaddr = alloca i32 %ignore = call i32 (ptr, ...) @printf(ptr @prompt) %scanned = call i32 (ptr, ...) @scanf(ptr @scan_fmt, ptr %xaddr) %x = load i32, ptr %xaddr %xp3 = add i32 %x, 3 %xp3sq = call i32 @foo(i32 %xp3) %ignore = call i32 (ptr, ...) @printf(ptr @print_fmt, i32 %xp3sq) ret i32 0 }-
There are two small errors in this code. Identify and fix them both. (Look carefully!)
-
Write a short C program which is equivalent to (the fixed version of) this code.
-
Looking ahead
-
This should actually be review from your CS Theory class, SI342.
Write regular expressions for each of the following languages, using Java regular expressions syntax.
- A single
charliteral in C++ like'a'or'!'or'\n' - A valid floating-point constant in Python like
3.5or.7or123.or-15.2(not including scientific notation) - A valid variable name in Java, which is a sequence of letters, digits, underscores, and dollar signs that does not begin with a digit.
- A single