Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c63afae875cf
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e94a9236aa25
Choose a head ref
  • 4 commits
  • 22 files changed
  • 1 contributor

Commits on Feb 15, 2016

  1. Remove lognonl(); rename log() to core_log() to avoid math.h conflict.

    Also, make core_log() exactly equivalent to printf(), since the lack
    of a drop-in universally usable printf() equivalent annoys me.
    
    Note that this breaks compiled experiments. They'll be fixed in
    the following commits.
    whitequark committed Feb 15, 2016
    Copy the full SHA
    cd7f12e View commit details
  2. Make rtio_log() accept variable number of arguments.

    whitequark committed Feb 15, 2016
    Copy the full SHA
    b9448c0 View commit details
  3. Add rtio_log() and make print() an RPC (#206).

    whitequark committed Feb 15, 2016
    Copy the full SHA
    74a7584 View commit details
  4. Add workaround for analyzer core bug (#206).

    whitequark committed Feb 15, 2016
    7
    Copy the full SHA
    e94a923 View commit details
3 changes: 3 additions & 0 deletions artiq/compiler/builtins.py
Original file line number Diff line number Diff line change
@@ -177,6 +177,9 @@ def fn_mu_to_seconds():
def fn_seconds_to_mu():
return types.TBuiltinFunction("seconds_to_mu")

def fn_rtio_log():
return types.TBuiltinFunction("rtio_log")

# Accessors

def is_none(typ):
8 changes: 7 additions & 1 deletion artiq/compiler/embedding.py
Original file line number Diff line number Diff line change
@@ -18,6 +18,9 @@
from .transforms import ASTTypedRewriter, Inferencer, IntMonomorphizer


def coredevice_print(x): print(x)


class ObjectMap:
def __init__(self):
self.current_key = 0
@@ -264,7 +267,9 @@ def visit_Name(self, node):
loc=node.loc)
else:
# Try to find this value in the host environment and quote it.
if node.id in self.host_environment:
if node.id == "print":
return self.quote(coredevice_print, node.loc)
elif node.id in self.host_environment:
return self.quote(self.host_environment[node.id], node.loc)
else:
names = set()
@@ -450,6 +455,7 @@ def __init__(self, engine=None):
self.typedtree = []
self.inject_at = 0
self.prelude = prelude.globals()
self.prelude.pop("print")
self.globals = {}

self.functions = {}
3 changes: 3 additions & 0 deletions artiq/compiler/prelude.py
Original file line number Diff line number Diff line change
@@ -43,4 +43,7 @@ def globals():
"at_mu": builtins.fn_at_mu(),
"mu_to_seconds": builtins.fn_mu_to_seconds(),
"seconds_to_mu": builtins.fn_seconds_to_mu(),

# ARTIQ utility functions
"rtio_log": builtins.fn_rtio_log(),
}
2 changes: 0 additions & 2 deletions artiq/compiler/targets.py
Original file line number Diff line number Diff line change
@@ -61,7 +61,6 @@ class Target:
triple = "unknown"
data_layout = ""
features = []
print_function = "printf"


def __init__(self):
@@ -176,4 +175,3 @@ class OR1KTarget(Target):
triple = "or1k-linux"
data_layout = "E-m:e-p:32:32-i64:32-f64:32-v64:32-v128:32-a:0:32-n32"
features = ["mul", "div", "ffl1", "cmov", "addc"]
print_function = "lognonl"
27 changes: 17 additions & 10 deletions artiq/compiler/transforms/artiq_ir_generator.py
Original file line number Diff line number Diff line change
@@ -1608,9 +1608,10 @@ def body_gen(index):
return self.append(ir.Builtin("round", [arg], node.type))
else:
assert False
elif types.is_builtin(typ, "print"):
elif types.is_builtin(typ, "print") or types.is_builtin(typ, "rtio_log"):
self.polymorphic_print([self.visit(arg) for arg in node.args],
separator=" ", suffix="\n")
separator=" ", suffix="\n",
as_rtio=types.is_builtin(typ, "rtio_log"))
return ir.Constant(None, builtins.TNone())
elif types.is_builtin(typ, "now"):
if len(node.args) == 0 and len(node.keywords) == 0:
@@ -1822,14 +1823,21 @@ def visit_Assert(self, node):
tail = self.current_block = self.add_block()
self.append(ir.BranchIf(cond, tail, if_failed), block=head)

def polymorphic_print(self, values, separator, suffix="", as_repr=False):
def polymorphic_print(self, values, separator, suffix="", as_repr=False, as_rtio=False):
def printf(format_string, *args):
format = ir.Constant(format_string, builtins.TStr())
if as_rtio:
now_mu = self.append(ir.Builtin("now_mu", [], builtins.TInt64()))
self.append(ir.Builtin("rtio_log", [now_mu, format, *args], builtins.TNone()))
else:
self.append(ir.Builtin("printf", [format, *args], builtins.TNone()))

format_string = ""
args = []
def flush():
nonlocal format_string, args
if format_string != "":
format_arg = [ir.Constant(format_string, builtins.TStr())]
self.append(ir.Builtin("printf", format_arg + args, builtins.TNone()))
printf(format_string, *args)
format_string = ""
args = []

@@ -1841,7 +1849,7 @@ def flush():
format_string += "("; flush()
self.polymorphic_print([self.append(ir.GetAttr(value, index))
for index in range(len(value.type.elts))],
separator=", ", as_repr=True)
separator=", ", as_repr=True, as_rtio=as_rtio)
if len(value.type.elts) == 1:
format_string += ",)"
else:
@@ -1882,13 +1890,12 @@ def flush():
last = self.append(ir.Arith(ast.Sub(loc=None), length, ir.Constant(1, length.type)))
def body_gen(index):
elt = self.iterable_get(value, index)
self.polymorphic_print([elt], separator="", as_repr=True)
self.polymorphic_print([elt], separator="", as_repr=True, as_rtio=as_rtio)
is_last = self.append(ir.Compare(ast.Lt(loc=None), index, last))
head = self.current_block

if_last = self.current_block = self.add_block()
self.append(ir.Builtin("printf",
[ir.Constant(", ", builtins.TStr())], builtins.TNone()))
printf(", ")

tail = self.current_block = self.add_block()
if_last.append(ir.Branch(tail))
@@ -1907,7 +1914,7 @@ def body_gen(index):
start = self.append(ir.GetAttr(value, "start"))
stop = self.append(ir.GetAttr(value, "stop"))
step = self.append(ir.GetAttr(value, "step"))
self.polymorphic_print([start, stop, step], separator=", ")
self.polymorphic_print([start, stop, step], separator=", ", as_rtio=as_rtio)

format_string += ")"
elif builtins.is_exception(value.type):
2 changes: 1 addition & 1 deletion artiq/compiler/transforms/inferencer.py
Original file line number Diff line number Diff line change
@@ -753,7 +753,7 @@ def makenotes(printer, typea, typeb, loca, locb):
node.loc, None)
else:
diagnose(valid_forms())
elif types.is_builtin(typ, "print"):
elif types.is_builtin(typ, "print") or types.is_builtin(typ, "rtio_log"):
valid_forms = lambda: [
valid_form("print(args...) -> None"),
]
8 changes: 5 additions & 3 deletions artiq/compiler/transforms/llvm_ir_generator.py
Original file line number Diff line number Diff line change
@@ -358,8 +358,10 @@ def llbuiltin(self, name):
llty = ll.FunctionType(llptr, [])
elif name == "llvm.stackrestore":
llty = ll.FunctionType(llvoid, [llptr])
elif name == self.target.print_function:
elif name == "printf":
llty = ll.FunctionType(llvoid, [llptr], var_arg=True)
elif name == "rtio_log":
llty = ll.FunctionType(llvoid, [lli64, llptr], var_arg=True)
elif name == "__artiq_personality":
llty = ll.FunctionType(lli32, [], var_arg=True)
elif name == "__artiq_raise":
@@ -892,10 +894,10 @@ def get_outer(llenv, env_ty):
elif insn.op == "len":
lst, = insn.operands
return self.llbuilder.extract_value(self.map(lst), 0)
elif insn.op == "printf":
elif insn.op in ("printf", "rtio_log"):
# We only get integers, floats, pointers and strings here.
llargs = map(self.map, insn.operands)
return self.llbuilder.call(self.llbuiltin(self.target.print_function), llargs,
return self.llbuilder.call(self.llbuiltin(insn.op), llargs,
name=insn.name)
elif insn.op == "exncast":
# This is an identity cast at LLVM IR level.
2 changes: 1 addition & 1 deletion artiq/runtime/analyzer.c
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ void analyzer_end(void)

int analyzer_input(void *data, int length)
{
log("no input should be received by analyzer, dropping connection");
core_log("no input should be received by analyzer, dropping connection\n");
return -1;
}

2 changes: 1 addition & 1 deletion artiq/runtime/clock.c
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ int watchdog_set(int ms)
break;
}
if(id < 0) {
log("WARNING: Failed to add watchdog");
core_log("WARNING: Failed to add watchdog\n");
return id;
}

2 changes: 1 addition & 1 deletion artiq/runtime/dds.c
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ static void dds_set_one(long long int now, long long int ref_time, unsigned int
unsigned int channel_enc;

if(channel >= CONFIG_DDS_CHANNEL_COUNT) {
log("Attempted to set invalid DDS channel");
core_log("Attempted to set invalid DDS channel\n");
return;
}
#ifdef CONFIG_DDS_ONEHOT_SEL
16 changes: 10 additions & 6 deletions artiq/runtime/flash_storage.c
Original file line number Diff line number Diff line change
@@ -63,21 +63,24 @@ static int record_iter_next(struct iter_state *is, struct record *record, int *f
return 0;

if(record->size < 6) {
log("flash_storage might be corrupted: record size is %u (<6) at address %08x", record->size, record->raw_record);
core_log("flash_storage might be corrupted: record size is %u (<6) at address %08x\n",
record->size, record->raw_record);
if(fatal)
*fatal = 1;
return 0;
}

if(is->seek > is->buf_len - sizeof(record->size) - 2) { /* 2 is the minimum key length */
log("flash_storage might be corrupted: END_MARKER missing at the end of the storage sector");
core_log("flash_storage might be corrupted: END_MARKER missing at the end of "
"the storage sector\n");
if(fatal)
*fatal = 1;
return 0;
}

if(record->size > is->buf_len - is->seek) {
log("flash_storage might be corrupted: invalid record_size %d at address %08x", record->size, record->raw_record);
core_log("flash_storage might be corrupted: invalid record_size %d at address %08x\n",
record->size, record->raw_record);
if(fatal)
*fatal = 1;
return 0;
@@ -87,7 +90,8 @@ static int record_iter_next(struct iter_state *is, struct record *record, int *f
record->key_len = strnlen(record->key, record->size - sizeof(record->size)) + 1;

if(record->key_len == record->size - sizeof(record->size) + 1) {
log("flash_storage might be corrupted: invalid key length at address %08x", record->raw_record);
core_log("flash_storage might be corrupted: invalid key length at address %08x\n",
record->raw_record);
if(fatal)
*fatal = 1;
return 0;
@@ -261,7 +265,7 @@ int fs_write(const char *key, const void *buffer, unsigned int buf_len)
return 0; // Storage is definitely full.

fatal_error:
log("fatal error: flash storage might be corrupted");
core_log("fatal error: flash storage might be corrupted\n");
return 0;
}

@@ -292,7 +296,7 @@ unsigned int fs_read(const char *key, void *buffer, unsigned int buf_len, unsign
}

if(fatal)
log("fatal error: flash storage might be corrupted");
core_log("fatal error: flash storage might be corrupted\n");

return read_length;
}
16 changes: 6 additions & 10 deletions artiq/runtime/kloader.c
Original file line number Diff line number Diff line change
@@ -45,12 +45,12 @@ static int load_or_start_kernel(const void *library, int run_kernel)
mailbox_acknowledge();

if(reply->type != MESSAGE_TYPE_LOAD_REPLY) {
log("BUG: unexpected reply to load/run request");
core_log("BUG: unexpected reply to load/run request\n");
return 0;
}

if(reply->error != NULL) {
log("cannot load kernel: %s", reply->error);
core_log("cannot load kernel: %s\n", reply->error);
return 0;
}

@@ -60,7 +60,7 @@ static int load_or_start_kernel(const void *library, int run_kernel)
int kloader_load_library(const void *library)
{
if(!kernel_cpu_reset_read()) {
log("BUG: attempted to load kernel library while kernel CPU is running");
core_log("BUG: attempted to load kernel library while kernel CPU is running\n");
return 0;
}

@@ -99,7 +99,7 @@ static int kloader_start_flash_kernel(char *key)
return 0;

if(remain) {
log("ERROR: kernel %s is too large", key);
core_log("ERROR: kernel %s is too large\n", key);
return 0;
}

@@ -129,7 +129,7 @@ int kloader_validate_kpointer(void *p)
{
unsigned int v = (unsigned int)p;
if((v < KERNELCPU_EXEC_ADDRESS) || (v > KERNELCPU_LAST_ADDRESS)) {
log("Received invalid pointer from kernel CPU: 0x%08x", v);
core_log("Received invalid pointer from kernel CPU: 0x%08x\n", v);
return 0;
}
return 1;
@@ -178,11 +178,7 @@ void kloader_service_essential_kmsg(void)
case MESSAGE_TYPE_LOG: {
struct msg_log *msg = (struct msg_log *)umsg;

if(msg->no_newline) {
lognonl_va(msg->fmt, msg->args);
} else {
log_va(msg->fmt, msg->args);
}
core_log_va(msg->fmt, msg->args);
mailbox_acknowledge();
break;
}
Loading