public class LLVMGenerator
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
code
Main String code of the generated LLVM IR.
|
private java.lang.String |
currentLabel |
private boolean |
firstLabel
First label is called 'entry'
|
private int |
ifThenCount
Count to automatically increment the section name
|
private boolean |
inCondition
Says whether we are inside an if statement or not.
|
private java.lang.String |
toAppend
Code to append, like conditions and such.
|
private int |
unamedVal
Unnamed variable
|
private java.lang.String |
val1 |
private java.lang.String |
val2 |
Constructor and Description |
---|
LLVMGenerator() |
Modifier and Type | Method and Description |
---|---|
void |
arthimOperation(java.lang.String opType)
Performs one of the four basic arithmetic operations:
addition, subtraction, multiplication or division.
|
void |
compute() |
void |
condition(java.lang.String condType,
java.lang.String left,
java.lang.String right)
Different condition types.
|
void |
declareVariable(java.lang.String name,
java.lang.String value,
java.lang.String maxDigits)
Declares a global variable
|
void |
display(java.lang.String output)
Display the String argument on the standard output
using @putchar(i32).
|
void |
elseStatement() |
void |
endIfStatement() |
void |
finalizeCode()
Merge the two code Strings.
|
void |
ifStatement()
Needs to create a new section in order to handle
the result of the condition.
|
void |
jumpTo(java.lang.String label) |
private int |
maxNumbFromMaxDigits(int maxDigits) |
void |
newComment(java.lang.String comment) |
void |
newLabel(java.lang.String lab) |
void |
newLine() |
void |
newLocalVariable(java.lang.String var)
Local temporary variable.
|
void |
newProcedure(java.lang.String proc) |
void |
newVariable(java.lang.String val)
LLVM handles at most two variables at the same time.
|
void |
notOperation()
The not operation simply operates a xor with 1
on the variable.
|
void |
oppositeOperation()
Computing the opposite of a number is subtracting its
value to zero and storing the result in itself.
|
void |
readInput(java.lang.String toId)
Read an integer on the standard input.
|
void |
resetVars() |
void |
store() |
void |
subtract()
Separated from the
arthimOperation(String)
because S-COBOL handles the two forms of the subtraction differently. |
void |
toFile(java.lang.String filename)
Write the code to a file.
|
void |
untilCondition()
Do nothing if true, loop if false.
|
private java.lang.String code
private java.lang.String toAppend
private boolean firstLabel
private int ifThenCount
private boolean inCondition
private java.lang.String currentLabel
private int unamedVal
private java.lang.String val1
private java.lang.String val2
public void declareVariable(java.lang.String name, java.lang.String value, java.lang.String maxDigits)
name
- Name of the variablevalue
- Value of the variablemaxDigits
- Maximum digits of the variable.
Used to determine the number of bits needed for
its representation.public void newLocalVariable(java.lang.String var)
var
- Variable to store.public void compute()
private int maxNumbFromMaxDigits(int maxDigits)
public void newProcedure(java.lang.String proc)
public void newLabel(java.lang.String lab)
public void newLine()
public void newVariable(java.lang.String val)
val
- name or value of the variablepublic void resetVars()
public void newComment(java.lang.String comment)
public void notOperation()
public void oppositeOperation()
public void arthimOperation(java.lang.String opType)
opType
- public void subtract()
arthimOperation(String)
because S-COBOL handles the two forms of the subtraction differently.
sub i32 %a, %b is a-b, but subtract a from b is b-a.
This methods handles the second sort.public void store()
public void condition(java.lang.String condType, java.lang.String left, java.lang.String right)
condType
- left
- Left operandright
- Right operandpublic void ifStatement()
public void elseStatement()
public void endIfStatement()
public void jumpTo(java.lang.String label)
public void untilCondition()
public void display(java.lang.String output)
output
- String to displaypublic void readInput(java.lang.String toId)
toId
- Variable in which store the input.public void finalizeCode()
public void toFile(java.lang.String filename)
filename
- File name.