Skip to content

Commit

Permalink
Fix tests and README.
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasHeneka committed Aug 9, 2023
1 parent 5a8baa1 commit 1b17ea8
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 9 deletions.
3 changes: 2 additions & 1 deletion languages/llvmir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ If the grammar is updated to a more recent<a href="#footnote-1"><sup>1</sup></a>

### Token Extraction

TODO
The choice of tokens includes nesting tokens for functions and basic blocks and separate tokens for various elements.
These include binary and bitwise instructions (like addition and or), memory operations (like load and store), terminator instructions (like branches), conversions, global variables, type definitions, constants and others.


### Usage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
package de.jplag.llvmir;

import org.junit.jupiter.api.Disabled;

import de.jplag.testutils.LanguageModuleTest;
import de.jplag.testutils.datacollector.TestDataCollector;
import de.jplag.testutils.datacollector.TestSourceIgnoredLinesCollector;

/**
* Provides tests for the llvmir language module
*/
@Disabled
class LLVMIRLanguageTest extends LanguageModuleTest {
public LLVMIRLanguageTest() {
super(new LLVMIRLanguage(), LLVMIRTokenType.class);
}

@Override
protected void collectTestData(TestDataCollector collector) {
collector.testFile("Complete.ll").testCoverages();
// All Tokens except: [CATCH_SWITCH, CATCH_RETURN, CLEAN_UP_RETURN, CATCH_PAD, CLEAN_UP_PAD]
collector.testFile("Complete.ll").testSourceCoverage().testContainedTokens(LLVMIRTokenType.FILENAME, LLVMIRTokenType.FUNCTION_BODY_BEGIN,
LLVMIRTokenType.FUNCTION_BODY_END, LLVMIRTokenType.BASIC_BLOCK_BEGIN, LLVMIRTokenType.BASIC_BLOCK_END,
LLVMIRTokenType.FUNCTION_DECLARATION, LLVMIRTokenType.FUNCTION_DEFINITION, LLVMIRTokenType.GLOBAL_VARIABLE, LLVMIRTokenType.ASSEMBLY,
LLVMIRTokenType.TYPE_DEFINITION, LLVMIRTokenType.STRUCTURE, LLVMIRTokenType.ARRAY, LLVMIRTokenType.VECTOR, LLVMIRTokenType.RETURN,
LLVMIRTokenType.BRANCH, LLVMIRTokenType.SWITCH, LLVMIRTokenType.CASE, LLVMIRTokenType.CONDITIONAL_BRANCH, LLVMIRTokenType.INVOKE,
LLVMIRTokenType.CALL_BRANCH, LLVMIRTokenType.RESUME, LLVMIRTokenType.ADDITION, LLVMIRTokenType.SUBTRACTION,
LLVMIRTokenType.MULTIPLICATION, LLVMIRTokenType.DIVISION, LLVMIRTokenType.REMAINDER, LLVMIRTokenType.SHIFT, LLVMIRTokenType.AND,
LLVMIRTokenType.OR, LLVMIRTokenType.XOR, LLVMIRTokenType.EXTRACT_ELEMENT, LLVMIRTokenType.INSERT_ELEMENT,
LLVMIRTokenType.SHUFFLE_VECTOR, LLVMIRTokenType.EXTRACT_VALUE, LLVMIRTokenType.INSERT_VALUE, LLVMIRTokenType.ALLOCATION,
LLVMIRTokenType.LOAD, LLVMIRTokenType.STORE, LLVMIRTokenType.FENCE, LLVMIRTokenType.COMPARE_EXCHANGE,
LLVMIRTokenType.ATOMIC_READ_MODIFY_WRITE, LLVMIRTokenType.ATOMIC_ORDERING, LLVMIRTokenType.GET_ELEMENT_POINTER,
LLVMIRTokenType.BITCAST, LLVMIRTokenType.CONVERSION, LLVMIRTokenType.COMPARISON, LLVMIRTokenType.PHI, LLVMIRTokenType.SELECT,
LLVMIRTokenType.CALL, LLVMIRTokenType.VARIABLE_ARGUMENT, LLVMIRTokenType.LANDING_PAD, LLVMIRTokenType.CLAUSE);
}

@Override
protected void configureIgnoredLines(TestSourceIgnoredLinesCollector collector) {
// TODO
collector.ignoreLinesByPrefix("; ModuleID");
collector.ignoreLinesByPrefix("target datalayout");
collector.ignoreLinesByPrefix("target triple");
collector.ignoreLinesByPrefix("; Function Attrs:");
collector.ignoreLinesByPrefix("unreachable");
}
}
71 changes: 68 additions & 3 deletions languages/llvmir/src/test/resources/de/jplag/llvmir/Complete.ll
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ target triple = "arm64-apple-macosx13.0.0"
@struct.const = private constant {i32, double} {i32 4, double 8.12}

%struct.Struct = type { i32 }
@_ZTIi = external constant ptr

; Function Attrs: noinline nounwind optnone ssp uwtable
define i32 @main() #0 {
Expand Down Expand Up @@ -46,6 +47,7 @@ define i32 @main() #0 {
%24 = xor i32 %23, 5
store i32 %24, ptr %3, align 4
%25 = call i32 (ptr, ...) @printf(ptr noundef @Global_Var)
%cast = bitcast i8 255 to i8
br label %vectors

vectors:
Expand All @@ -57,15 +59,15 @@ vectors:
aggregates:
%struc = insertvalue {i32} undef, i32 1, 0
%27 = extractvalue {i32} %struc, 0
callbr void asm "", "r,!i"(i32 0)
to label %memory [label %aggregates]
callbr void asm "", "r,!i"(i32 0) to label %memory [label %aggregates]

memory:
fence acquire
br label %entry

entry:
%28 = getelementptr inbounds %struct.Struct, ptr %5, i32 0, i32 0
%tmp = va_arg ptr %28, i32
store i32 1, ptr %28, align 4
%old = atomicrmw add ptr %28, i32 1 acquire
%orig = load atomic i32, ptr %28 unordered, align 4
Expand All @@ -82,6 +84,7 @@ loop:
done:
%false = icmp eq i32 4, 5
%first = select i1 true, i8 17, i8 42
call void @Exception()
ret i32 0
}

Expand All @@ -92,5 +95,67 @@ define i32 @vector(<4 x i32> %v1, <4 x i32> %v2) {
ret i32 %elem
}

; Function Attrs: mustprogress noinline norecurse optnone ssp uwtable
define noundef i32 @Exception() personality ptr @__gxx_personality_v0 {
%1 = alloca i32, align 4
%2 = alloca ptr, align 8
%3 = alloca i32, align 4
%4 = alloca i32, align 4
store i32 0, ptr %1, align 4
%5 = call ptr @__cxa_allocate_exception(i64 4)
store i32 5, ptr %5, align 16
invoke void @__cxa_throw(ptr %5, ptr @_ZTIi, ptr null) to label %25 unwind label %6

6:
%7 = landingpad { ptr, i32 }
catch ptr @_ZTIi
%8 = extractvalue { ptr, i32 } %7, 0
store ptr %8, ptr %2, align 8
%9 = extractvalue { ptr, i32 } %7, 1
store i32 %9, ptr %3, align 4
br label %10

10:
%11 = load i32, ptr %3, align 4
%12 = call i32 @llvm.eh.typeid.for(ptr @_ZTIi)
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %20

14:
%15 = load ptr, ptr %2, align 8
%16 = call ptr @__cxa_begin_catch(ptr %15)
%17 = load i32, ptr %16, align 4
store i32 %17, ptr %4, align 4
store i32 0, ptr %1, align 4
call void @__cxa_end_catch()
br label %18

18:
%19 = load i32, ptr %1, align 4
ret i32 %19

20:
%21 = load ptr, ptr %2, align 8
%22 = load i32, ptr %3, align 4
%23 = insertvalue { ptr, i32 } undef, ptr %21, 0
%24 = insertvalue { ptr, i32 } %23, i32 %22, 1
resume { ptr, i32 } %24

25:
unreachable
}

declare i32 @printf(ptr noundef, ...)

declare ptr @__cxa_allocate_exception(i64)

declare void @__cxa_throw(ptr, ptr, ptr)

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind readnone
declare i32 @llvm.eh.typeid.for(ptr)

declare ptr @__cxa_begin_catch(ptr)

declare i32 @printf(ptr noundef, ...) #1
declare void @__cxa_end_catch()

0 comments on commit 1b17ea8

Please sign in to comment.