Skip to content

Commit

Permalink
Compiler doesn't generates debug info for regular running
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Mar 1, 2018
1 parent 8d5be0a commit b90f21e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
9 changes: 5 additions & 4 deletions aheui/aheui.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_location(pc, stackok, is_queue, program):
get_printable_location=get_location)


DEBUG = False
DEBUG = False # debug flag for `rpaheui`


class Link(object):
Expand Down Expand Up @@ -515,14 +515,14 @@ def open_w(filename):
return os.open(filename, os.O_WRONLY | os.O_CREAT, 0o644)


def prepare_compiler(contents, opt_level=2, source='code', aheuic_output=None):
def prepare_compiler(contents, opt_level=2, source='code', aheuic_output=None, add_debug_info=False):
compiler = compile.Compiler()
if source == 'bytecode':
compiler.read_bytecode(contents)
elif source == 'asm':
compiler.read_asm(contents.decode('utf-8'))
else:
compiler.compile(contents.decode('utf-8'))
compiler.compile(contents.decode('utf-8'), add_debug_info=add_debug_info)

if opt_level == 0:
pass
Expand Down Expand Up @@ -553,7 +553,8 @@ def entry_point(argv):
except SystemExit:
return 1

compiler = prepare_compiler(contents, int(str_opt_level), source, aheuic_output)
add_debug_info = DEBUG or target != 'run' # debug flag for user program
compiler = prepare_compiler(contents, int(str_opt_level), source, aheuic_output, add_debug_info)
outfp = 1 if output == '-' else open_w(output)
if target == 'run':
program = Program(compiler.lines, compiler.label_map)
Expand Down
14 changes: 4 additions & 10 deletions aheui/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@

from __future__ import absolute_import

try:
import settings
DEBUG = settings.DEBUG
except ImportError:
DEBUG = False

import os
import aheui.const as c
from aheui._compat import unichr, _unicode
Expand Down Expand Up @@ -75,7 +69,6 @@ def read(fp=0):


class Debug(object):
ENABLED = DEBUG

def __init__(self, lines, comments=None):
self.lines = lines
Expand Down Expand Up @@ -238,12 +231,13 @@ def __init__(self):
self.debug = None
self.label_map = {}

def compile(self, program):
def compile(self, program, add_debug_info=False):
"""Compile to aheui-assembly representation."""
self.primitive = PrimitiveProgram(program)
self.lines, self.label_map, code_map = self.serialize(self.primitive)
self.debug = Debug(self.lines)
self.debug.build_comments(self.primitive, code_map)
if add_debug_info:
self.debug = Debug(self.lines)
self.debug.build_comments(self.primitive, code_map)

def serialize(self, primitive):
"""Serialize Aheui primitive codes.
Expand Down

0 comments on commit b90f21e

Please sign in to comment.