Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Let Sodium code refer to C constants.

  • Loading branch information...
commit 4ff2a4010154bd995b101b84369615dfd3c9910f 1 parent 68cfaeb
@kr authored
Showing with 18 additions and 4 deletions.
  1. +10 −4 ir.py
  2. +8 −0 lx.py
View
14 ir.py
@@ -319,6 +319,8 @@ def get_labels(self, datums):
elif symbolp(s.d):
real_instrs.append(OP_DATUM_OFFSET(String(s.d.s)))
symbol_offsets.append(i)
+ elif isinstance(s.d, str):
+ real_instrs.append(PACKED(s.d))
else:
raise "unsupported data type: %s %r" % (type(s.d), s.d)
i += 1
@@ -519,8 +521,14 @@ def bprim(reg, label): return OP_RL(bprim.name, reg, label)
@reg_instr
def load_imm(target_reg, val):
if isinstance(val, String): return load_off(target_reg, val)
+ if not referencable_from_code(val):
+ raise AssemblingError('val cannot be referenced from code: %r' % val)
return OP_RD(load_imm.name, target_reg, val)
+@reg_instr
+def load_cint(target_reg, name):
+ return OP_RD(load_imm.name, target_reg, '((%s) << 1) | 1' % name)
+
# Three register instructions
@reg_instr
@@ -878,16 +886,14 @@ def __init__(self, op, r, d):
OP.__init__(self, op)
self.reg = r
self.r = lookup_reg(r)
- if not referencable_from_code(d):
- raise AssemblingError('d cannot be referenced from code: %r' % d)
self.d = d
def get_body(self, index, labels, datums):
- i = lookup_dat(self.d, datums)
- return pack((5, self.r), (22, i))
+ return pack((5, self.r), (22, 0))
def se_datums_and_symbols(self):
if symbolp(self.d): return self.d, String(self.d.s)
+ if isinstance(self.d, str): return ()
return (self.d,)
def __repr__(self):
View
8 lx.py
@@ -46,6 +46,7 @@ def annotate_or_report(self, exp):
do_s = S('do')
inline_s = S('inline')
asm_s = S('asm')
+cint_s = S('cint')
assign_s = S('=')
def compile(exp, target, linkage, cenv, pop_all_symbol, **kwargs):
try:
@@ -63,6 +64,7 @@ def compile(exp, target, linkage, cenv, pop_all_symbol, **kwargs):
if tagged_list(exp, do_s): return compile_do(exp, target, linkage, cenv, pop_all_symbol)
if tagged_list(exp, inline_s): return compile_inline(exp)
if tagged_list(exp, return_s): return compile_return(exp, target, linkage, cenv, pop_all_symbol)
+ if tagged_list(exp, cint_s): return compile_cint(exp, target, linkage, cenv, pop_all_symbol)
if tagged_list2(exp, assign_s): return compile(assign2prefix(exp, set__s), target, linkage, cenv, pop_all_symbol)
if simple_macrop(exp): return compile(expand_simple_macros(exp),
target, linkage, cenv, pop_all_symbol)
@@ -157,6 +159,12 @@ def compile_literal(exp, target, linkage, cenv, pop_all_symbol):
pop_all_symbol)), pop_all_symbol)
raise CompileError(exp, "Can't compile literal")
+def compile_cint(exp, target, linkage, cenv, pop_all_symbol):
+ name = exp.cadr()
+ return end_with_linkage(linkage,
+ make_ir_seq((), (target,), load_cint(target, str(name))),
+ pop_all_symbol)
+
def compile_quoted(exp, target, linkage, cenv, pop_all_symbol):
return compile_literal(exp.cadr(), target, linkage, cenv, pop_all_symbol)
Please sign in to comment.
Something went wrong with that request. Please try again.