Skip to content

Commit f5dcd1e

Browse files
committed
fix: lab8 no angr
1 parent a624259 commit f5dcd1e

File tree

3 files changed

+6
-115
lines changed

3 files changed

+6
-115
lines changed

.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 & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,5 @@
1-
const { describe, it, beforeEach } = 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-
let calculator;
7-
beforeEach(() => {
8-
calculator = new Calculator();
9-
});
10-
11-
describe('exp method', () => {
12-
it('unsupported operand type', () => {
13-
const testcases = [
14-
{ param: [Infinity], expected: 'unsupported operand type' },
15-
{ param: [-Infinity], expected: 'unsupported operand type' },
16-
{ param: [NaN], expected: 'unsupported operand type' },
17-
];
18-
19-
for (const tc of testcases) {
20-
assert.throws(() => calculator.exp(...tc.param), new RegExp(tc.expected));
21-
}
22-
});
23-
24-
it('overflow', () => {
25-
const testcases = [
26-
{ param: [710], expected: 'overflow' },
27-
];
28-
29-
for (const tc of testcases) {
30-
assert.throws(() => calculator.exp(...tc.param), new RegExp(tc.expected));
31-
}
32-
});
33-
34-
it('normal', () => {
35-
const testcases = [
36-
{ param: [0], expected: Math.exp(0) },
37-
{ param: [1], expected: Math.exp(1) },
38-
{ param: [2], expected: Math.exp(2) },
39-
{ param: [-1], expected: Math.exp(-1) },
40-
{ param: [-2], expected: Math.exp(-2) },
41-
];
42-
43-
for (const tc of testcases) {
44-
const result = calculator.exp(...tc.param);
45-
assert.strictEqual(result, tc.expected);
46-
}
47-
});
48-
});
49-
50-
describe('log method', () => {
51-
it('unsupported operand type', () => {
52-
const testcases = [
53-
{ param: [Infinity], expected: 'unsupported operand type' },
54-
{ param: [-Infinity], expected: 'unsupported operand type' },
55-
{ param: [NaN], expected: 'unsupported operand type' },
56-
];
57-
58-
for (const tc of testcases) {
59-
assert.throws(() => calculator.log(...tc.param), new RegExp(tc.expected));
60-
}
61-
});
62-
63-
it('math domain error (1)', () => {
64-
const testcases = [
65-
{ param: [0], expected: 'math domain error \\(1\\)' },
66-
];
67-
68-
for (const tc of testcases) {
69-
assert.throws(() => calculator.log(...tc.param), new RegExp(tc.expected));
70-
}
71-
});
72-
73-
it('math domain error (2)', () => {
74-
const testcases = [
75-
{ param: [-1], expected: 'math domain error \\(2\\)' },
76-
{ param: [-2], expected: 'math domain error \\(2\\)' },
77-
];
78-
79-
for (const tc of testcases) {
80-
assert.throws(() => calculator.log(...tc.param), new RegExp(tc.expected));
81-
}
82-
});
83-
84-
it('normal', () => {
85-
const testcases = [
86-
{ param: [1], expected: Math.log(1) },
87-
{ param: [2], expected: Math.log(2) },
88-
];
89-
90-
for (const tc of testcases) {
91-
const result = calculator.log(...tc.param);
92-
assert.strictEqual(result, tc.expected);
93-
}
94-
});
95-
});
96-
});
5+
// TODO: write your tests here

lab6/llvm-pass.so.cc

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,13 @@ struct LLVMPass : public PassInfoMixin<LLVMPass> {
1010

1111
PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) {
1212
LLVMContext &Ctx = M.getContext();
13-
IRBuilder<> Builder(Ctx);
14-
1513
IntegerType *Int32Ty = IntegerType::getInt32Ty(Ctx);
16-
PointerType *I8PtrTy = Type::getInt8PtrTy(Ctx); // for argv
17-
1814
FunctionCallee debug_func = M.getOrInsertFunction("debug", Int32Ty);
1915
ConstantInt *debug_arg = ConstantInt::get(Int32Ty, 48763);
20-
Constant *StrGlobal = Builder.CreateGlobalStringPtr("hayaku... motohayaku!", "",
21-
0, &M); // for argv
2216

2317
for (auto &F : M) {
24-
if (F.getName() == "main"){
25-
// insert debug
26-
BasicBlock &Entry = F.getEntryBlock();
27-
Builder.SetInsertPoint(&*Entry.getFirstInsertionPt());
28-
Builder.CreateCall(debug_func, {debug_arg});
18+
errs() << "func: " << F.getName() << "\n";
2919

30-
// insert argc, argv
31-
auto ArgIter = F.arg_begin();
32-
Argument *Argc = &*ArgIter++;
33-
Argument *Argv = &*ArgIter;
34-
// replace argc -> i8, hayaku... motohayaku!
35-
Value *Idx1 = Builder.getInt32(1);
36-
Value *Argv1Ptr= Builder.CreateGEP(I8PtrTy, Argv, Idx1);
37-
Builder.CreateStore(StrGlobal, Argv1Ptr);
38-
// replace argv -> debug_arg 48763
39-
if (!Argc->use_empty()) Argc->replaceAllUsesWith(debug_arg);
40-
}
4120
}
4221
return PreservedAnalyses::none();
4322
}

0 commit comments

Comments
 (0)