-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
63 lines (52 loc) · 1.36 KB
/
Copy pathlambda_function.py
File metadata and controls
63 lines (52 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import io
import os
import sys
import json
import time
import struct
import glob as g
import MODEL as m
from node import OPT
from pcpp import Preprocessor
from argparse import ArgumentParser
from mnemonic import mnemonic as opc
from astConstructor import makeAST
from compile import value2hex, compile
def lambda_handler(event, context):
cpp = Preprocessor()
cpp.add_path(os.getcwd() + "/lvmxlib")
tmpf = io.StringIO("")
with open("/tmp/main.c", mode='w') as f:
f.write(event['body'])
with open("/tmp/main.c", mode="r") as f:
cpp.parse(f)
cpp.write(tmpf)
g.init("/tmp/main.c", tmpf.getvalue())
try:
dumps = compile(g.source)
except Exception as e:
return {
'statusCode': 400,
'body': g.r.report()
}
if dumps is None:
return {
'statusCode': 400,
'body': g.r.report()
}
bytecode = f".data {len(dumps['data'])}" + '\n'
for elem in dumps['data']:
bytecode += value2hex(elem) + '\n'
bytecode += f".code {len(dumps['code'])}" + '\n'
for elem in dumps['code']:
bytecode += elem.serialize() + '\n'
if g.r.hasError():
return {
'statusCode': 400,
'body': g.r.report()
}
else:
return {
'statusCode': 200,
'body': bytecode
}