Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Generate a .h file for each builtin module.

  • Loading branch information...
commit 5a26f81973a4c2c9de15e20f149403aad0c9b22e 1 parent 3983955
@kr authored
Showing with 29 additions and 6 deletions.
  1. +4 −1 Makefile
  2. +3 −2 bin/gen-mod-index
  3. +13 −2 ir.py
  4. +9 −1 lx1c
View
5 Makefile
@@ -41,6 +41,9 @@ index.c: $(namodules) bin/gen-mod-index
%.na.c: %.na *.py lx1c
$(NAC) $(NAFLAGS) --generate-c $<
+%.na.h: %.na *.py lx1c
+ $(NAC) $(NAFLAGS) --generate-h $<
+
# This one is special.
prelude.na.c: export NAFLAGS += --bare
@@ -51,7 +54,7 @@ clean:
rm -f vm *.o core core.* gmon.out sh-tests/*.out *.d *.pyc
rm -f *.lxc ad-hoc-tests/*.lxc lib/*.lxc tests/*.lxc
rm -f *.nac ad-hoc-tests/*.nac lib/*.nac tests/*.nac
- rm -f *.na.c index.c
+ rm -f *.na.h *.na.c index.c
# .DELETE_ON_ERROR:
.PHONY: all clean distclean reallyclean check
View
5 bin/gen-mod-index
@@ -30,9 +30,10 @@ print >>outfd
print >>outfd, '#include "lxc.h"'
print >>outfd, '#include "index.h"'
for module in modules:
- module = tr(module, '/-.', '___')
+ #module = tr(module, '/-.', '___')
if match('.*[^-_/A-Za-z0-9]', module): raise 'bad module name', module
- print >>outfd, 'extern struct lxc_module lxc_module_%s;' % (module,)
+ #print >>outfd, 'extern struct lxc_module lxc_module_%s;' % (module,)
+ print >>outfd, '#include "%s.na.h"' % module
print >>outfd
View
15 ir.py
@@ -157,6 +157,18 @@ def find_mtab_offset(self, name, insts):
if tag is name: return i
return None
+ def gen_h(self, name, fd):
+ cname = tr(name, '/-.', '___')
+
+ print >>fd, '/* This file is automatically generated. */'
+ print >>fd, '#ifndef %s_na_h' % cname
+ print >>fd, '#define %s_na_h' % cname
+
+ print >>fd, '#include "lxc.h"'
+ print >>fd, 'extern struct lxc_module lxc_module_%s;' % (cname,)
+
+ print >>fd, '#endif /* %s_na_h */' % cname
+
def gen_c(self, name, fd):
datums, labels, real_instrs, symbol_offsets = self.extract()
cname = tr(name, '/-.', '___')
@@ -165,9 +177,8 @@ def gen_c(self, name, fd):
print >>fd
print >>fd, '#include "symbol.h"'
print >>fd, '#include "vm.h"'
- print >>fd, '#include "lxc.h"'
+ print >>fd, '#include "%s.na.h"' % name
print >>fd
- print >>fd, 'extern struct lxc_module lxc_module_%s;' % (cname,)
print >>fd, 'static uint instr_array[];'
print >>fd, '#define lxc_module_instr_array (instr_array + 2)'
View
10 lx1c
@@ -15,21 +15,25 @@ def basename(name):
def read_file(n):
return reader.read(open(n).read(), n)
-opts, args = getopt(sys.argv[1:], 'btco:', [
+opts, args = getopt(sys.argv[1:], 'btcho:', [
'bare',
'thunk',
'generate-c',
+ 'generate-h',
'output=',
])
infile = args[0]
outfile = None
gen_c = False
+gen_h = False
use_thunk = True
for opt, val in opts:
if opt in ('--generate-c', '-c'):
gen_c = True
+ if opt in ('--generate-h', '-h'):
+ gen_h = True
elif opt in ('--thunk', '-t'):
use_thunk = True
elif opt in ('--bare', '-b'):
@@ -40,6 +44,8 @@ for opt, val in opts:
if outfile is None:
if gen_c:
outfile = infile + '.c'
+ elif gen_h:
+ outfile = infile + '.h'
else:
outfile = infile + 'c'
@@ -61,6 +67,8 @@ try:
if gen_c:
if not outfile.endswith('.c'): raise 'bad output file name', outfile
code.gen_c(basename(infile), outfd)
+ elif gen_h:
+ code.gen_h(basename(infile), outfd)
else:
code.assemble(outfd)
except lx.CompileError, err:
Please sign in to comment.
Something went wrong with that request. Please try again.