Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: unify names in ir and ir_cli crates #7

Merged
merged 8 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
Artifact: # Pack and publish to Github Artifact
runs-on: ubuntu-latest
container:
image: smartir/smart-ir-builder:main
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Build the Release
working-directory: ir_cli
run: |
rustup default 1.67
make release
ls _build # there should be a ir.tgz file under the ir_cli/_build directory
- name: Upload Artifact to Github Releases
uses: actions/upload-artifact@v3
with:
name: ir-linux-amd64-nightly
path: ir_cli/_build/ir.tgz

Docker: # Download from Github Artifact and build Docker image and push
runs-on: ubuntu-latest
needs: [Artifact]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Download from Artifact
uses: actions/download-artifact@v3
with:
name: ir-linux-amd64-nightly
path: tmp
- name: Check downloaded contents
run: |
mkdir -p _build/sir
tar -xf tmp/ir.tgz -C _build/sir
ls _build/sir
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract Metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: smartir/cli
- name: Build and Push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

28 changes: 28 additions & 0 deletions .github/workflows/smartir_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: SmartIR Build and Test CI

on: ["push", "pull_request"]

jobs:
smartir-build-test:
name: Test
runs-on: ubuntu-latest
container:
image: smartir/smart-ir-builder:main
steps:
- name: Check out code
uses: actions/checkout@v3
with:
submodules: "false"
# Prerequisite
- name: Code format check
working-directory: ./ir_cli
run: |
rustup default 1.67
make fmt-check
shell: bash
- name: e2e tests
working-directory: ./ir_cli
shell: bash
run: |
rustup default 1.67
make test
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM centos:centos8
COPY _build/sir /sir
COPY ir_example/hello_world.ir /sir/example/hello_world.ir

RUN chmod +x /sir/bin/ir_cli

ENV PATH="/sir/bin:${PATH}"
ENV LANG=en_US.utf8
7 changes: 0 additions & 7 deletions LEGAL.md

This file was deleted.

41 changes: 41 additions & 0 deletions docker/ir-cli-builder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## The Smart IR Builder Image

The `smartir/smart-ir-builder` image embeded a development enviroment for developers to code, build and test the project.

### Develop

To develop the `Smart-Intermediate-Representation` project with docker:

```sh
# 1. clone the project locally
git clone [email protected]:AntChainOpenLabs/Smart-Intermediate-Representation.git

# 2. start the container, note to replace the ${path-to-Smart-Intermediate-Representation-project} to your local path
docker run --platform linux/x86_64 -v ${path-to-Smart-Intermediate-Representation-project}:/home/Smart-Intermediate-Representation-project -ti smartir/smart-ir-builder:v0.1.0 bash

# 3. code, build, test in your container:
cd /home/Smart-Intermediate-Representation-project
# set up default rustup version
rustup default 1.67
make install-rustc-wasm
make run-debug
```

### Build the image locally

Under the top level of the `Smart-Intermediate-Representation` repo and run the script below, it will build a `smartir/smart-ir-builder:latest` image locally:

```sh
./docker/ir-cli-builder/docker_build.sh
```

### Notes About the Image

- For Mac Arm64 user, please explictly specify the option `--platform linux/x86_64` to `docker build` and `docker run`, to avoid the "missing /lib64/ld-linux-x86-64.so.2" error. Ref: https://stackoverflow.com/a/69075554/12110648

- Since the `ir_cli` crate depends on the `smart_ir_macro` and `smart_ir` crates and are refered with relative paths(as shown bellow), this two dependencies will be removed when building the `smartir/smart-ir-builder` image. The `docker_build.sh` script does the removing automatically.

```toml
smart_ir_macro = { path = "../smart_ir_macro", version = "0.3.0" }
smart_ir = { path = "../smart_ir" }
```
2 changes: 1 addition & 1 deletion docker/ir-cli-builder/docker_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ else
# 2. docker build
# for macOS Arm64 environment, it's required to add the `--platform linux/amd64` option to the docker build/run commands.
cd docker/ir-cli-builder
docker build . --platform linux/x86_64 -f Dockerfile -t smartir/smart-ir-builder:v0.1.0
docker build . --platform linux/x86_64 -f Dockerfile -t smartir/smart-ir-builder:latest
cd ../../

# 3. clean tmp files
Expand Down
2 changes: 1 addition & 1 deletion ir_cli/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Introduction

This crate introduces a default command line tool with pre-defined mock runtime(wasm runtime and HOSTAPI) of Smart Intermediate Representation.
This crate introduces a default command line tool with pre-defined mock runtime(wasm runtime and HostAPI) of Smart Intermediate Representation.

## How to Use

Expand Down
2 changes: 1 addition & 1 deletion ir_cli/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ run-debug:

test:
cargo test -r
cd ../smart_ir && ./run_cclib_tests.sh
# cd ../smart_ir && ./run_cclib_tests.sh

install-rustc-wasm:
rustup target add wasm32-unknown-unknown
Expand Down
8 changes: 4 additions & 4 deletions ir_cli/src/vm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use inkwell::values::IntValue;
use inkwell::values::{BasicValueEnum, FunctionValue};
use smart_ir::integration::intrinsic::IrHostapiIntrinsic;
use smart_ir::integration::intrinsic::IrHostAPIIntrinsic;
use smart_ir::ir::cfg::Type;
use smart_ir::ir::interface_type::IntrinsicFuncName;
use smart_ir::ir_codegen::common::global::ExtendContext;
Expand Down Expand Up @@ -149,21 +149,21 @@ impl ExtendContext for MockExtendContext {
vec![]
}

fn get_ir_func_intrinsics(&self) -> &[&IrHostapiIntrinsic] {
fn get_ir_func_intrinsics(&self) -> &[&IrHostAPIIntrinsic] {
&[]
}

fn find_ir_func_intrinsic_by_func_name(
&self,
_func_name: &IntrinsicFuncName,
) -> Option<&IrHostapiIntrinsic> {
) -> Option<&IrHostAPIIntrinsic> {
None
}

fn add_or_get_intrinsic_function<'ctx>(
&self,
_context: &IR2LLVMCodeGenContext<'ctx>,
_intrinsic_info: &IrHostapiIntrinsic,
_intrinsic_info: &IrHostAPIIntrinsic,
_params: &[Type],
_ret: &Type,
) -> FunctionValue<'ctx> {
Expand Down
6 changes: 3 additions & 3 deletions ir_cli/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,17 @@ impl Externals for MockRuntime {
};
self.events.push(event.clone());

// 如果 log name MyCoverage, 则导出log内容
// If the log name is MyCoverage, export the log content.
let my_coverage_event_name = "MyCoverage";
let first_topic = event.topics[0].clone();

// 第一个字节是event字符串长度
// The first byte is the length of the event string.
if String::from_utf8(first_topic[1..].to_vec()).unwrap() == *my_coverage_event_name
{
let file_name = "out.mygcna";
let mut file =
File::create(file_name).expect("mygcna coverage file create failed");
// desc_o 是datastream编码后的长度,头部需要读取leb128长度
// `desc_o` is the length encoded by the data stream, and the header needs to read the length of leb128.
let coverage_file_bytes = match nano_leb128::SLEB128::read_from(&desc_o) {
Ok((_, len_bytes_len)) => &desc_o[len_bytes_len..],
Err(_) => unreachable!(
Expand Down
40 changes: 0 additions & 40 deletions smart_ir/src/encoding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,3 @@

pub mod datastream;
pub mod ssz;

pub trait Serialize {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer;
}

pub trait Serializer: Sized {
type Ok;
type Error: std::error::Error;
type SerializeBool;
type SerializeInt;
type SerializeUInt;
type SerializeStr;
type SerializeArray;
type SerializeTuple;
type SerializeTupleStruct;
type SerializeMap;
type SerializeStruct;
type SerializeStructVariant;

fn serialize_bool(self, v: Self::SerializeStr) -> Result<Self::Ok, Self::Error>;
fn serialize_int(self, v: Self::SerializeInt) -> Result<Self::Ok, Self::Error>;
fn serialize_uint(self, v: Self::SerializeUInt) -> Result<Self::Ok, Self::Error>;
fn serialize_str(self, v: Self::SerializeStr) -> Result<Self::Ok, Self::Error>;
fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error>;
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error>;
fn serialize_tuple_struct(
self,
name: &'static str,
len: usize,
) -> Result<Self::SerializeTupleStruct, Self::Error>;
fn serialize_array(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error>;
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error>;
fn serialize_struct(
self,
name: &'static str,
len: usize,
) -> Result<Self::SerializeStruct, Self::Error>;
}
2 changes: 1 addition & 1 deletion smart_ir/src/integration/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::ir::interface_type::IntrinsicFuncName;

pub struct IrHostapiIntrinsic {
pub struct IrHostAPIIntrinsic {
// enum name as key
pub func_name: IntrinsicFuncName,
pub ir_func_name: &'static str,
Expand Down
8 changes: 4 additions & 4 deletions smart_ir/src/ir/interface_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ impl PartialFuncNameBehavior for () {
pub enum PartialFuncNameKind<T: PartialFuncNameBehavior, U: PartialFuncNameBehavior> {
UserDefFunc(String),
Intrinsic(T),
HOSTAPI(U),
HostAPI(U),
Otherwise,
}

/// Specify the specification of HOSTAPI here
/// Specify the specification of HostAPI here
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum DefaultHOSTAPI {}
pub enum DefaultHostAPI {}

/// Specify the specification of Intrinsic functions here
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -525,7 +525,7 @@ impl PartialFuncName {
match &self.kind {
PartialFuncNameKind::UserDefFunc(str) => str.clone(),
PartialFuncNameKind::Intrinsic(intrinsic) => intrinsic.apply_name(),
PartialFuncNameKind::HOSTAPI(_) => unimplemented!(),
PartialFuncNameKind::HostAPI(_) => unimplemented!(),
PartialFuncNameKind::Otherwise => unreachable!(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions smart_ir/src/ir/metadata/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::ir::cfg::Literal;
use crate::ir::cfg::MetaData;
use crate::ir::cfg::MetaDataNode;
use crate::ir::context::IRContext;
use smart_ir_macro::MetadataDefination;
use smart_ir_macro::MetadataDefinition;

#[derive(Clone, Debug, PartialEq, Eq, MetadataDefination, Default)]
#[derive(Clone, Debug, PartialEq, Eq, MetadataDefinition, Default)]
#[MetaDataKey(asset)]
pub struct Asset {
// 1: fungible
Expand Down
4 changes: 2 additions & 2 deletions smart_ir/src/ir/metadata/debug_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use crate::ir::cfg::Literal;
use crate::ir::cfg::MetaData;
use crate::ir::cfg::MetaDataNode;
use crate::ir::context::IRContext;
use smart_ir_macro::MetadataDefination;
use smart_ir_macro::MetadataDefinition;

/// debug location metadata
/// !{ {line}: u64, {column}: u64, {file}: str}
/// e.g. %0 = add(1, 2) !ir_debug_location !0
/// !0 = !{2: u64, 5: u64, "/Users/admin/ir/test.ir": str}
#[derive(Clone, Debug, PartialEq, Eq, MetadataDefination, Default)]
#[derive(Clone, Debug, PartialEq, Eq, MetadataDefinition, Default)]
#[MetaDataKey(ir_debug_location)]
pub struct DebugLocation {
start_line: u32,
Expand Down
4 changes: 2 additions & 2 deletions smart_ir/src/ir/metadata/extend_hostapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::ir::cfg::Literal;
use crate::ir::cfg::MetaData;
use crate::ir::cfg::MetaDataNode;
use crate::ir::context::IRContext;
use smart_ir_macro::MetadataDefination;
use smart_ir_macro::MetadataDefinition;

#[derive(Clone, Debug, PartialEq, Eq, MetadataDefination, Default)]
#[derive(Clone, Debug, PartialEq, Eq, MetadataDefinition, Default)]
#[MetaDataKey(extend_hostapi)]
pub struct ExtendHostAPI {
name: String,
Expand Down
4 changes: 2 additions & 2 deletions smart_ir/src/ir/metadata/ssz_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::ir::cfg::Literal;
use crate::ir::cfg::MetaData;
use crate::ir::cfg::MetaDataNode;
use crate::ir::context::IRContext;
use smart_ir_macro::MetadataDefination;
use smart_ir_macro::MetadataDefinition;

#[derive(Clone, Debug, PartialEq, Eq, MetadataDefination, Default)]
#[derive(Clone, Debug, PartialEq, Eq, MetadataDefinition, Default)]
#[MetaDataKey(type_ssz_info)]
pub struct SSZInfo {
versioned: bool,
Expand Down
8 changes: 4 additions & 4 deletions smart_ir/src/ir_codegen/common/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
// Copyright (c) The Smart Intermediate Representation Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::integration::intrinsic::IrHostapiIntrinsic;
use crate::integration::intrinsic::IrHostAPIIntrinsic;
use crate::ir::cfg::Type;
use crate::ir::interface_type::IntrinsicFuncName;
use crate::ir_codegen::context::IR2LLVMCodeGenContext;
use inkwell::values::{BasicValueEnum, FunctionValue};

pub trait ExtendContext {
fn get_ir_func_intrinsics(&self) -> &[&IrHostapiIntrinsic];
fn get_ir_func_intrinsics(&self) -> &[&IrHostAPIIntrinsic];

fn find_ir_func_intrinsic_by_func_name(
&self,
func_name: &IntrinsicFuncName,
) -> Option<&IrHostapiIntrinsic>;
) -> Option<&IrHostAPIIntrinsic>;

fn add_or_get_intrinsic_function<'ctx>(
&self,
context: &IR2LLVMCodeGenContext<'ctx>,
intrinsic_info: &IrHostapiIntrinsic,
intrinsic_info: &IrHostAPIIntrinsic,
params_ty: &[Type],
ret: &Type,
) -> FunctionValue<'ctx>;
Expand Down
Loading