Skip to content

Commit 2949af2

Browse files
committed
fix: lab8 no angr
1 parent 1e10a79 commit 2949af2

3 files changed

Lines changed: 11 additions & 55 deletions

File tree

.github/workflows/lab-autograding.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,7 @@ jobs:
5656
if [ ${{ steps.lab.outputs.result }} -eq 6 ]; then
5757
sudo apt install -y llvm-14
5858
fi
59+
if [ ${{ steps.lab.outputs.result }} -eq 8 ]; then
60+
python3 -m pip install angr
61+
fi
5962
./validate.sh

lab3/main_test.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
1-
const { describe, it } = require('node:test');
1+
const {describe, it} = require('node:test');
22
const assert = require('assert');
33
const { Calculator } = require('./main');
44

5-
describe('Calculator', () => {
6-
const calculator = new Calculator();
7-
8-
describe('exp()', () => {
9-
it('should return correct exponentiation results', () => {
10-
assert.strictEqual(calculator.exp(0), 1);
11-
assert.strictEqual(calculator.exp(1), Math.exp(1));
12-
assert.strictEqual(calculator.exp(-1), Math.exp(-1));
13-
assert.strictEqual(calculator.exp(5), Math.exp(5));
14-
});
15-
16-
it('should throw an error for non-finite numbers', () => {
17-
assert.throws(() => calculator.exp(Infinity), /unsupported operand type/);
18-
assert.throws(() => calculator.exp(-Infinity), /unsupported operand type/);
19-
assert.throws(() => calculator.exp(NaN), /unsupported operand type/);
20-
});
21-
22-
it('should throw an overflow error for large numbers', () => {
23-
assert.throws(() => calculator.exp(1000), /overflow/);
24-
});
25-
});
26-
});
5+
// TODO: write your tests here

lab6/llvm-pass.so.cc

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "llvm/Passes/PassPlugin.h"
22
#include "llvm/Passes/PassBuilder.h"
33
#include "llvm/IR/IRBuilder.h"
4-
#include "llvm/IR/Constants.h"
54

65
using namespace llvm;
76

@@ -12,39 +11,13 @@ struct LLVMPass : public PassInfoMixin<LLVMPass> {
1211
PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) {
1312
LLVMContext &Ctx = M.getContext();
1413
IntegerType *Int32Ty = IntegerType::getInt32Ty(Ctx);
15-
PointerType *CharPtrTy = Type::getInt8PtrTy(Ctx);
16-
17-
// Get or create debug function declaration
18-
FunctionCallee debug_func = M.getOrInsertFunction("debug",
19-
FunctionType::get(Type::getVoidTy(Ctx), {Int32Ty}, false));
20-
21-
// Create constant value for debug function argument and argc
14+
FunctionCallee debug_func = M.getOrInsertFunction("debug", Int32Ty);
2215
ConstantInt *debug_arg = ConstantInt::get(Int32Ty, 48763);
23-
16+
2417
for (auto &F : M) {
25-
// Find main function
26-
if (F.getName() == "main") {
27-
// Create IRBuilder at the beginning of the entry block
28-
IRBuilder<> Builder(&*F.getEntryBlock().getFirstInsertionPt());
29-
30-
// a. Call debug function with argument 48763
31-
Builder.CreateCall(debug_func, {debug_arg});
32-
33-
// Get function arguments
34-
Argument *argcArg = F.getArg(0);
35-
Argument *argvArg = F.getArg(1);
36-
37-
// b. Set argv[1] = "hayaku... motohayaku!"
38-
Value *index1 = ConstantInt::get(Int32Ty, 1);
39-
Value *argv1_ptr = Builder.CreateInBoundsGEP(CharPtrTy, argvArg, index1);
40-
Value *hayakuStr = Builder.CreateGlobalStringPtr("hayaku... motohayaku!");
41-
Builder.CreateStore(hayakuStr, argv1_ptr);
42-
43-
// c. Replace all uses of argc with 48763
44-
argcArg->replaceAllUsesWith(debug_arg);
45-
}
18+
errs() << "func: " << F.getName() << "\n";
19+
4620
}
47-
4821
return PreservedAnalyses::none();
4922
}
5023

@@ -57,4 +30,5 @@ llvmGetPassPluginInfo() {
5730
MPM.addPass(LLVMPass());
5831
});
5932
}};
60-
}
33+
}
34+

0 commit comments

Comments
 (0)