Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/cup/parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ term ::=

factor ::=
LITNUM:x {: RESULT = new ExpNum(x); :}
| MINUS factor:x {: RESULT = new ExpNegate(x); :}
| LPAREN exp:x RPAREN {: RESULT = x; :}
;
28 changes: 28 additions & 0 deletions src/main/java/absyn/ExpNegate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package absyn;

import javaslang.collection.Tree;
import static org.bytedeco.javacpp.LLVM.*;

/**
* Created by mvosouza on 19.10.16.
*/
public class ExpNegate extends Exp{

public final Exp arg;

public ExpNegate(Exp arg) {
this.arg = arg;
}

@Override
public LLVMValueRef codegen(LLVMModuleRef module, LLVMBuilderRef builder) {
final LLVMValueRef v_arg = arg.codegen(module,builder);
final LLVMValueRef zero = LLVMConstReal(LLVMDoubleType(), 0);
return LLVMBuildFSub(builder, zero, v_arg, "subtmp");
}

@Override
public Tree.Node<String> toTree() {
return Tree.of("ExpNegate", arg.toTree());
}
}